home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Examples / DriverKit / S3 / S3_reloc.tproj / S3.m < prev    next >
Encoding:
Text File  |  1993-08-11  |  4.9 KB  |  179 lines

  1. /* Copyright (c) 1993 by NeXT Computer, Inc.
  2.  * All rights reserved.
  3.  *
  4.  * S3.m -- driver for S3 86C805 and 86C928 Graphics Accelerators
  5.  *
  6.  * Created by Peter Graffagnino 1/31/93
  7.  * Modified by Derek B Clegg    21 May 1993
  8.  */
  9. #import <driverkit/i386/IOEISADeviceDescription.h>
  10. #import "S3.h"
  11.  
  12. @implementation S3
  13.  
  14. /* Put the display into linear framebuffer mode. This typically happens
  15.  * when the window server starts running.
  16.  */
  17. - (void)enterLinearMode
  18. {
  19.     /* Set up the chip to use the selected mode. */
  20.     [self initializeMode];
  21.  
  22.     /* Set the gamma-corrected gray-scale palette if necessary. */
  23.     [self setGammaTable];
  24.  
  25.     /* Enter linear mode. */
  26.     if ([self enableLinearFrameBuffer] == nil) {
  27.     IOLog("%s: Failed to enter linear mode.\n", [self name]);
  28.     return;
  29.     }
  30. }
  31.  
  32. /* Get the device out of whatever advanced linear mode it was using and back
  33.  * into a state where it can be used as a standard VGA device.
  34.  */
  35. - (void)revertToVGAMode
  36. {
  37.     /* Reset the VGA parameters. */
  38.     [self resetVGA];
  39.  
  40.     /* Let the superclass do whatever work it needs to do. */
  41.     [super revertToVGAMode];
  42. }
  43.  
  44. /* Set the brightness to `level'.
  45.  */
  46. - setBrightness:(int)level token:(int)t
  47. {
  48.     if (level < EV_SCREEN_MIN_BRIGHTNESS || level > EV_SCREEN_MAX_BRIGHTNESS) {
  49.     IOLog("QVision: Invalid brightness level `%d'.\n", level);
  50.     return nil;
  51.     }
  52.     brightnessLevel = level;
  53.     [self setGammaTable];
  54.     return self;
  55. }
  56.  
  57. /* Set the transfer tables.
  58.  */
  59. - setTransferTable:(const unsigned int *)table count:(int)numEntries
  60. {
  61.     int k;
  62.  
  63.     if (redTransferTable != 0)
  64.     IOFree(redTransferTable, 3 * transferTableCount);
  65.  
  66.     transferTableCount = numEntries;
  67.  
  68.     redTransferTable = IOMalloc(3 * numEntries);
  69.     greenTransferTable = redTransferTable + numEntries;
  70.     blueTransferTable = greenTransferTable + numEntries;
  71.  
  72.     switch ([self displayInfo]->bitsPerPixel) {
  73.     case IO_8BitsPerPixel:
  74.     for (k = 0; k < numEntries; k++) {
  75.         redTransferTable[k] = greenTransferTable[k] =
  76.         blueTransferTable[k] = table[k] & 0xFF;
  77.     }
  78.     break;
  79.  
  80.     case IO_15BitsPerPixel:
  81.     case IO_24BitsPerPixel:
  82.     for (k = 0; k < numEntries; k++) {
  83.         redTransferTable[k] = (table[k] >> 24) & 0xFF;
  84.         greenTransferTable[k] = (table[k] >> 16) & 0xFF;
  85.         blueTransferTable[k] = (table[k] >> 8) & 0xFF;
  86.     }
  87.     break;
  88.  
  89.     default:
  90.     IOFree(redTransferTable, 3 * numEntries);
  91.     redTransferTable = 0;
  92.     break;
  93.     }
  94.     [self setGammaTable];
  95.     return self;
  96. }
  97.  
  98. - initFromDeviceDescription:deviceDescription
  99. {
  100.     IODisplayInfo *displayInfo;
  101.     const IORange *range;
  102.     const S3Mode *s3mode;
  103.     const char *s;
  104.  
  105.     if ([super initFromDeviceDescription:deviceDescription] == nil)
  106.     return [super free];
  107.  
  108.     if ([self determineConfiguration] == nil)
  109.     return [super free];
  110.  
  111.     if ([self selectMode] == nil)
  112.     return [super free];
  113.  
  114.     range = [deviceDescription memoryRangeList];
  115.     if (range == 0) {
  116.     IOLog("%s: No memory range set.\n", [self name]);
  117.     return [super free];
  118.     }
  119.     videoRamAddress = range[0].start;
  120.  
  121.     redTransferTable = greenTransferTable = blueTransferTable = 0;
  122.     transferTableCount = 0;
  123.     brightnessLevel = EV_SCREEN_MAX_BRIGHTNESS;
  124.  
  125.     displayInfo = [self displayInfo];
  126.     s3mode = displayInfo->parameters;
  127.     displayInfo->flags = 0;
  128.  
  129.     /* Some S3 805 cards have a lot of flicker when write-posting or
  130.      * read-ahead is enabled.  We disable both, but provide a way to
  131.      * turn them on from the config table.  It's a good idea to enable
  132.      * both if possible, since it speeds up the display a good deal.
  133.      */
  134.  
  135.     writePostingEnabled = [self booleanForStringKey:"WritePostingEnabled"
  136.                withDefault:(adapter == S3_805 ? NO : YES)];
  137.     readAheadCacheEnabled = [self booleanForStringKey:"ReadAheadCacheEnabled"
  138.              withDefault:(adapter == S3_805 ? NO : YES)];
  139.  
  140.     /* Turn on s/w gamma correction.  (This is only necessary for the 555/16
  141.      * modes.) */
  142.  
  143.     if ([self hasTransferTable])
  144.     displayInfo->flags |= IO_DISPLAY_HAS_TRANSFER_TABLE;
  145.  
  146.     if ([self needsSoftwareGammaCorrection])
  147.     displayInfo->flags |= IO_DISPLAY_NEEDS_SOFTWARE_GAMMA_CORRECTION;
  148.  
  149.     if (adapter == S3_805) {
  150.     /* On the 805, always turn the cache off. */
  151.     displayInfo->flags |= IO_DISPLAY_CACHE_OFF;
  152.     } else {
  153.     s = [self valueForStringKey:"DisplayCacheMode"];
  154.     if (s != 0) {
  155.         if (strcmp(s, "Off") == 0)
  156.         displayInfo->flags |= IO_DISPLAY_CACHE_OFF;
  157.         else if (strcmp(s, "WriteThrough") == 0)
  158.         displayInfo->flags |= IO_DISPLAY_CACHE_WRITETHROUGH;
  159.         else if (strcmp(s, "CopyBack") == 0)
  160.         displayInfo->flags |= IO_DISPLAY_CACHE_COPYBACK;
  161.         else
  162.         IOLog("%s: Unrecognized value for key `DisplayCacheMode': "
  163.               "`%s'.\n", [self name], s);
  164.     }
  165.     }
  166.  
  167.     displayInfo->frameBuffer =
  168.         (void *)[self mapFrameBufferAtPhysicalAddress:videoRamAddress
  169.          length:s3mode->memSize];
  170.     if (displayInfo->frameBuffer == 0)
  171.     return [super free];
  172.  
  173.     IOLog("%s: Initialized `%s' @ %d Hz.\n", [self name], s3mode->name, 
  174.       displayInfo->refreshRate);
  175.  
  176.     return self;
  177. }
  178. @end
  179.