|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * Copyright (c) 1997 Apple Computer, Inc.
26: *
27: *
28: * HISTORY
29: *
30: * Simon Douglas 22 Oct 97
31: * - first checked in.
32: */
33:
34:
35: #define KERNOBJC 1 // remove
36: #define KERNEL_PRIVATE 1
37: #define DRIVER_PRIVATE 1
38:
39: #import <driverkit/generalFuncs.h>
40: #import <driverkit/IODisplay.h>
41: #import <driverkit/IODisplayPrivate.h>
42: #import <driverkit/IOFrameBufferShared.h>
43: #import <bsd/dev/kmreg_com.h>
44: #import <bsd/dev/ppc/kmDevice.h>
45:
46: #import <mach/vm_param.h> /* for round_page() */
47: #import <machdep/ppc/proc_reg.h>
48: #import <string.h>
49:
50: #import <driverkit/ppc/IOFramebuffer.h>
51: #import "IONDRVFramebuffer.h"
52:
53: extern IODisplayInfo bootDisplayInfo;
54:
55: @implementation IONDRVFramebuffer
56:
57: //=======================================================================
58:
59: - (IOReturn)doControl:(UInt32)code params:(void *)params
60: {
61: IOReturn err;
62: CntrlParam pb;
63:
64: pb.qLink = 0;
65: pb.csCode = code;
66: pb.csParams = params;
67:
68: err = NDRVDoDriverIO( doDriverIO, /*ID*/ (UInt32) &pb, &pb,
69: kControlCommand, kImmediateIOCommandKind );
70:
71: return( err);
72: }
73:
74: - (IOReturn)doStatus:(UInt32)code params:(void *)params
75: {
76: IOReturn err;
77: CntrlParam pb;
78:
79: pb.qLink = 0;
80: pb.csCode = code;
81: pb.csParams = params;
82:
83: err = NDRVDoDriverIO( doDriverIO, /*ID*/ (UInt32) &pb, &pb,
84: kStatusCommand, kImmediateIOCommandKind );
85:
86: return( err);
87: }
88:
89: //=======================================================================
90:
91: + (BOOL)probe:device
92: {
93: id inst;
94: Class newClass = self;
95: char * name;
96:
97: if( NDRVForDevice( device)) {
1.1.1.2 ! root 98: // temporary for in-kernel acceleration
1.1 root 99: name = [device nodeName];
100: if( 0 == strncmp("ATY,", name, strlen("ATY,")))
101: newClass = [IOATINDRV class];
102: } else
103: newClass = [IOOFFramebuffer class];
104:
105: // Create an instance and initialize
106: inst = [[newClass alloc] initFromDeviceDescription:device];
107: if (inst == nil)
108: return NO;
109:
110: [inst setDeviceKind:"Linear Framebuffer"];
111:
112: [inst registerDevice];
113:
114: return YES;
115: }
116:
117: - initFromDeviceDescription:(IOPCIDevice *) deviceDescription
118: {
119: id me = nil;
120: kern_return_t err = 0;
121: UInt32 i, propSize;
122: UInt32 numMaps = 8;
123: IOApertureInfo maps[ numMaps ]; // FIX
124: IOLogicalAddress aaplAddress[ 8 ]; // FIX
125: IOApertureInfo * map;
126: IOPropertyTable * propTable;
127: void * prop;
128: char * logname;
129: InterruptSetMember intsProperty[ 3 ];
130:
131: do {
132: ioDevice = deviceDescription;
133: logname = [ioDevice nodeName];
134: propTable = [ioDevice propertyTable];
135:
136: prop = &ndrvInst;
137: propSize = sizeof( NDRVInstance);
138: err = [propTable getProperty:"AAPL,ndrvInst" flags:0 value:&prop length:&propSize];
139: if( err)
140: continue;
141: err = NDRVGetSymbol( ndrvInst, "DoDriverIO", &doDriverIO );
142: if( err)
143: continue;
144: err = NDRVGetSymbol( ndrvInst, "TheDriverDescription", (void **)&theDriverDesc );
145: if( err)
146: continue;
147:
148: transferTable = IOMalloc(sizeof( ColorSpec) * 256); // Initialize transfer table variables.
149: brightnessLevel = EV_SCREEN_MAX_BRIGHTNESS;
150: scaledTable = 0;
151: cachedModeIndex = 0x7fffffff;
152:
153: numMaps = 8;
154: err = [ioDevice getApertures:maps items:&numMaps];
155: if( err)
156: continue;
157:
158: for( i = 0, map = maps; i < numMaps; i++, map++) {
159:
160: if( (((UInt32)bootDisplayInfo.frameBuffer) >= ((UInt32)map->physical))
161: && (((UInt32)bootDisplayInfo.frameBuffer) < (map->length + (UInt32)map->physical)) )
162: consoleDevice = YES;
163:
164: // this means any graphics card grabs a BAT for the segment.
165: aaplAddress[ i ] = PEMapSegment( map->physical, 0x10000000);
166: if( aaplAddress[ i ] != map->physical) {
167: IOLog("%s: NDRV needs 1-1 mapping\n", logname);
168: err = IO_R_VM_FAILURE;
169: break;
170: }
171:
172: #if 0
173: // Declare range for pmap'ing into user space
174: // Shouldn't be here but it's too expensive to do it for all devices
175: if( map->length > 0x01000000)
176: map->length = 0x01000000; // greed hack
177: err = pmap_add_physical_memory( map->physical,
178: map->physical + map->length, FALSE, PTE_WIMG_IO);
179: if(err)
180: kprintf("%s: pmap_add_physical_memory: %d for 0x%08x - 0x%08x\n",
181: logname, err, map->physical, map->physical + map->length);
182: #endif
183: }
184: if( err)
185: continue;
186:
187: // NDRV aperture vectors
188: [propTable deleteProperty:"AAPL,address"];
189: err = [propTable createProperty:"AAPL,address" flags:0
190: value:aaplAddress length:(numMaps * sizeof( IOLogicalAddress))];
191: if( err)
192: continue;
193:
194: // interrupt tree for NDRVs - not really
195: err = [propTable createProperty:"driver-ist" flags:0
196: value:intsProperty length:sizeof( intsProperty)];
197:
198: // tell kmDevice if it's on the boot console, it's going away
199: if( consoleDevice)
200: [kmId unregisterDisplay:nil];
201:
202: err = [self checkDriver];
203: if( err) {
204: kprintf("%s: Not usable\n", logname );
205: if( err == -999)
206: IOLog("%s: Driver is incompatible.\n", logname );
207: continue;
208: }
209:
210: if (nil == [super initFromDeviceDescription:deviceDescription])
211: continue;
212: err = [self open];
213: if( err)
214: continue;
215:
216: #if 0
217: if ([self startIOThread] != IO_R_SUCCESS)
218: kprintf("startIOThread FAIL\n");
219: [self enableAllInterrupts];
220: #endif
221:
222: me = self; // Success
223:
224: } while( false);
225:
226: if( me == nil)
227: [super free];
228:
229: return( me);
230: }
231:
232:
233: - free
234: {
235: if (transferTable != 0) {
236: IOFree(transferTable, 256 * sizeof( ColorSpec));
237: }
238: return [super free];
239: }
240:
241:
242: - (IOReturn)
243: getDisplayModeTiming:(IOFBIndex)connectIndex mode:(IOFBDisplayModeID)modeID
244: timingInfo:(IOFBTimingInformation *)info connectFlags:(UInt32 *)flags
245: {
246: VDTimingInfoRec timingInfo;
247: OSStatus err;
248:
249: timingInfo.csTimingMode = modeID;
250: timingInfo.csTimingFormat = kDeclROMtables; // in case the driver doesn't do it
251: err = [self doStatus:cscGetModeTiming params:&timingInfo];
252: if( err == noErr) {
253: if( timingInfo.csTimingFormat == kDeclROMtables)
254: info->standardTimingID = timingInfo.csTimingData;
255: else
256: info->standardTimingID = timingInvalid;
257: *flags = timingInfo.csTimingFlags;
258: return( [super getDisplayModeTiming:connectIndex mode:modeID timingInfo:info connectFlags:flags]);
259: }
260: *flags = 0;
261: return( IO_R_UNDEFINED_MODE);
262: }
263:
264: - (IOReturn)
265: getDisplayModeByIndex:(IOFBIndex)modeIndex displayMode:(IOFBDisplayModeID *)displayModeID
266: {
267:
268: // unfortunately, there is no "kDisplayModeIDFindSpecific"
269: if( modeIndex <= cachedModeIndex) {
270: cachedModeID = kDisplayModeIDFindFirstResolution;
271: cachedModeIndex = -1;
272: }
273:
274: cachedVDResolution.csPreviousDisplayModeID = cachedModeID;
275:
276: while(
277: (noErr == [self doStatus:cscGetNextResolution params:&cachedVDResolution])
278: && ((SInt32) cachedVDResolution.csDisplayModeID > 0) ) {
279:
280: cachedVDResolution.csPreviousDisplayModeID = cachedVDResolution.csDisplayModeID;
281:
282: if( modeIndex == ++cachedModeIndex) {
283: cachedModeID = cachedVDResolution.csDisplayModeID;
284: *displayModeID = cachedModeID;
285: return( noErr);
286: }
287: }
288: cachedModeIndex = 0x7fffffff;
289: return( IO_R_UNDEFINED_MODE);
290: }
291:
292:
293: - (IOReturn)
294: getResInfoForMode:(IOFBDisplayModeID)modeID info:(VDResolutionInfoRec **)theInfo
295: {
296:
297: *theInfo = &cachedVDResolution;
298:
299: if( cachedVDResolution.csDisplayModeID == modeID)
300: return( noErr);
301:
302: cachedVDResolution.csPreviousDisplayModeID = kDisplayModeIDFindFirstResolution;
303:
304: while(
305: (noErr == [self doStatus:cscGetNextResolution params:&cachedVDResolution])
306: && ((SInt32) cachedVDResolution.csDisplayModeID > 0) )
307: {
308: cachedVDResolution.csPreviousDisplayModeID = cachedVDResolution.csDisplayModeID;
309: if( cachedVDResolution.csDisplayModeID == modeID)
310: return( noErr);
311: }
312: cachedVDResolution.csDisplayModeID = -1;
313: return( IO_R_UNDEFINED_MODE);
314: }
315:
316: - (IOReturn)
317: getDisplayModeInformation:(IOFBDisplayModeID)modeID info:(IOFBDisplayModeInformation *)info
318: {
319: IOReturn err;
320: VDResolutionInfoRec * resInfo;
321:
322: do {
323: err = [self getResInfoForMode:modeID info:&resInfo];
324: if( err)
325: continue;
326: info->displayModeID = resInfo->csDisplayModeID;
327: info->maxDepthIndex = resInfo->csMaxDepthMode - kDepthMode1;
328: info->nominalWidth = resInfo->csHorizontalPixels;
329: info->nominalHeight = resInfo->csVerticalLines;
330: info->refreshRate = resInfo->csRefreshRate;
331: return( noErr);
332: } while( false);
333:
334: return( IO_R_UNDEFINED_MODE);
335: }
336:
337:
338: - (IOReturn)
339: getPixelInformationForDisplayMode:(IOFBDisplayModeID)modeID andDepthIndex:(IOFBIndex)depthIndex
340: pixelInfo:(IOFBPixelInformation *)info
341: {
342: SInt32 err;
343:
344: VDVideoParametersInfoRec pixelParams;
345: VPBlock pixelInfo;
346: VDResolutionInfoRec * resInfo;
347:
348: do {
349: err = [self getResInfoForMode:modeID info:&resInfo];
350: if( err)
351: continue;
352: pixelParams.csDisplayModeID = modeID;
353: pixelParams.csDepthMode = depthIndex + kDepthMode1;
354: pixelParams.csVPBlockPtr = &pixelInfo;
355: err = [self doStatus:cscGetVideoParameters params:&pixelParams];
356: if( err)
357: continue;
358:
359: info->flags = 0;
360: info->rowBytes = pixelInfo.vpRowBytes & 0x7fff;
361: info->width = pixelInfo.vpBounds.right;
362: info->height = pixelInfo.vpBounds.bottom;
363: info->refreshRate = resInfo->csRefreshRate;
364: info->pageCount = 1;
365: info->pixelType = (pixelInfo.vpPixelSize <= 8) ?
366: kIOFBRGBCLUTPixelType : kIOFBDirectRGBPixelType;
367: info->bitsPerPixel = pixelInfo.vpPixelSize;
368: // info->channelMasks =
369:
370: } while( false);
371:
372: return( err);
373: }
374:
375: - (IOReturn) open
376: {
377: IOReturn err;
378:
379: do {
380: err = [self checkDriver];
381: if( err)
382: continue;
383: err = [super open];
384:
385: } while( false);
386:
387: return( err);
388: }
389:
390: - (IOReturn) checkDriver
391: {
392: OSStatus err = noErr;
393: struct DriverInitInfo initInfo;
394: CntrlParam pb;
395: IOFBConfiguration config;
396: VDClutBehavior clutSetting = kSetClutAtSetEntries;
397:
398: if( ndrvState == 0) {
399: do {
400: initInfo.refNum = 0xffcd; // ...sure.
401: MAKE_REG_ENTRY(initInfo.deviceEntry, ioDevice)
402:
403: err = NDRVDoDriverIO( doDriverIO, 0, &initInfo, kInitializeCommand, kImmediateIOCommandKind );
404: if( err) continue;
405:
406: err = NDRVDoDriverIO( doDriverIO, 0, &pb, kOpenCommand, kImmediateIOCommandKind );
407: if( err) continue;
408:
409: } while( false);
410: if( err)
411: return( err);
412:
413: {
414: VDVideoParametersInfoRec pixelParams;
415: VPBlock pixelInfo;
416: VDResolutionInfoRec vdRes;
417: UInt32 size;
418:
419: vramLength = 0;
420: vdRes.csPreviousDisplayModeID = kDisplayModeIDFindFirstResolution;
421: while(
422: (noErr == [self doStatus:cscGetNextResolution params:&vdRes])
423: && ((SInt32) vdRes.csDisplayModeID > 0) )
424: {
425:
426: pixelParams.csDisplayModeID = vdRes.csDisplayModeID;
427: pixelParams.csDepthMode = vdRes.csMaxDepthMode;
428: pixelParams.csVPBlockPtr = &pixelInfo;
429: err = [self doStatus:cscGetVideoParameters params:&pixelParams];
430: if( err)
431: continue;
432:
433: // Control hangs its framebuffer off the end of the aperture to support
434: // 832 x 624 @ 32bpp. The commented out version will correctly calculate
435: // the vram length, but DPS needs the full extent to be mapped, so we'll
436: // end up mapping an extra page that will address vram through the little
437: // endian aperture. No other drivers like this known.
438: #if 1
439: size = 0x40 + pixelInfo.vpBounds.bottom * (pixelInfo.vpRowBytes & 0x7fff);
440: #else
441: size = ( (pixelInfo.vpBounds.right * pixelInfo.vpPixelSize) / 8) // last line
442: + (pixelInfo.vpBounds.bottom - 1) * (pixelInfo.vpRowBytes & 0x7fff);
443: #endif
444: if( size > vramLength)
445: vramLength = size;
446:
447: vdRes.csPreviousDisplayModeID = vdRes.csDisplayModeID;
448: }
449:
450: err = [self getConfiguration:&config];
451: vramBase = config.physicalFramebuffer;
452: vramLength = (vramLength + (vramBase & 0xffff) + 0xffff) & 0xffff0000;
453: vramBase &= 0xffff0000;
454:
455: #if 1
456: // Declare range for pmap'ing into user space
457: // Shouldn't be here but it's too expensive to do it for all devices
458: err = pmap_add_physical_memory( vramBase,
459: vramBase + vramLength, FALSE, PTE_WIMG_IO);
460: if(err)
461: kprintf("%s: pmap_add_physical_memory: %d for 0x%08x - 0x%08x\n",
462: [self name], err, vramBase, vramBase + vramLength );
463: #endif
464: }
465:
466: // Set CLUT immediately since there's no VBL.
467: [self doControl:cscSetClutBehavior params:&clutSetting];
468:
469: ndrvState = 1;
470: }
471: return( noErr);
472: }
473:
474:
475: - (IOReturn)
476: setDisplayMode:(IOFBDisplayModeID)modeID depth:(IOFBIndex)depthIndex page:(IOFBIndex)pageIndex;
477: {
478: SInt32 err;
479: VDSwitchInfoRec switchInfo;
480: VDPageInfo pageInfo;
481:
482: switchInfo.csData = modeID;
483: switchInfo.csMode = depthIndex + kDepthMode1;
484: switchInfo.csPage = pageIndex;
485: err = [self doControl:cscSwitchMode params:&switchInfo];
486: if(err)
487: IOLog("%s: cscSwitchMode:%d\n",[self name],(int)err);
488:
489: // duplicate QD InitGDevice
490: pageInfo.csMode = switchInfo.csMode;
491: pageInfo.csData = 0;
492: pageInfo.csPage = pageIndex;
493: [self doControl:cscSetMode params:&pageInfo];
494: [self doControl:cscGrayPage params:&pageInfo];
495:
496: return( err);
497: }
498:
499: - (IOReturn)
500: setStartupMode:(IOFBDisplayModeID)modeID depth:(IOFBIndex)depthIndex;
501: {
502: SInt32 err;
503: VDSwitchInfoRec switchInfo;
504:
505: switchInfo.csData = modeID;
506: switchInfo.csMode = depthIndex + kDepthMode1;
507: err = [self doControl:cscSavePreferredConfiguration params:&switchInfo];
508: return( err);
509: }
510:
511: - (IOReturn)
512: getStartupMode:(IOFBDisplayModeID *)modeID depth:(IOFBIndex *)depthIndex
513: {
514: SInt32 err;
515: VDSwitchInfoRec switchInfo;
516:
517: err = [self doStatus:cscGetPreferredConfiguration params:&switchInfo];
518: if( err == noErr) {
519: *modeID = switchInfo.csData;
520: *depthIndex = switchInfo.csMode - kDepthMode1;
521: }
522: return( err);
523: }
524:
525:
526: - (IOReturn)
527: getConfiguration:(IOFBConfiguration *)config;
528: {
529: IOReturn err;
530: VDSwitchInfoRec switchInfo;
531: VDGrayRecord grayRec;
532:
533: bzero( config, sizeof( IOFBConfiguration));
534:
535: grayRec.csMode = 0; // turn off luminance map
536: err = [self doControl:cscSetGray params:&grayRec];
537: if( (noErr == err) && (0 != grayRec.csMode))
538: // driver refused => mono display
539: config->flags |= kFBLuminanceMapped;
540:
541: err = [self doStatus:cscGetCurMode params:&switchInfo];
542: config->displayMode = switchInfo.csData;
543: config->depth = switchInfo.csMode - kDepthMode1;
544: config->page = switchInfo.csPage;
545: config->physicalFramebuffer = ((UInt32) switchInfo.csBaseAddr);
546: config->mappedFramebuffer = config->physicalFramebuffer; // assuming 1-1
547:
548: return( err);
549: }
550:
551: - (IOReturn)
552: getApertureInformationByIndex:(IOFBIndex)apertureIndex
553: apertureInfo:(IOFBApertureInformation *)apertureInfo
554: {
555: IOReturn err;
556:
557: if( apertureIndex == 0) {
558: apertureInfo->physicalAddress = vramBase;
559: apertureInfo->mappedAddress = vramBase;
560: apertureInfo->length = vramLength;
561: apertureInfo->cacheMode = 0;
562: apertureInfo->type = kIOFBGraphicsMemory;
563: err = noErr;
564: } else
565: err = IO_R_UNDEFINED_MODE;
566:
567: return( err);
568: }
569:
570: #if 0
571:
572: - (IOReturn) getInterruptFunctionsTV:(UInt32)member
573: refCon:(void **)refCon,
574: handler:(TVector *) handler,
575: enabler:(TVector *) enabler,
576: disabler:(TVector *) disabler
577:
578: {
579: OSStatus err;
580:
581: err = [interrupt getInterruptFunctionsTV:member refCon:refCon handler:handler
582: enabler:enabler disabler:disabler];
583: return( err);
584: }
585:
586:
587: SInt32 StdIntHandler( InterruptSetMember setMember, void *refCon, UInt32 theIntCount)
588: {
589: return( kIsrIsComplete);
590: }
591: void StdIntEnabler( InterruptSetMember setMember, void *refCon)
592: {
593: return;
594: }
595: Boolean StdIntDisabler( InterruptSetMember setMember, void *refCon)
596: {
597: return( false);
598: }
599:
600:
601: - (IOReturn) setInterruptFunctionsTV:(UInt32)member
602: refCon:(void *)refCon,
603: handler:(TVector *) handler,
604: enabler:(TVector *) enabler,
605: disabler:(TVector *) disabler
606: {
607:
608: if( handler != NULL)
609: currentIntHandler = handler;
610: if( enabler != NULL)
611: currentIntEnabler = enabler;
612: if( disabler != NULL)
613: currentIntDisabler = disabler;
614:
615: err = [interrupt setInterruptFunctions:member refCon:refCon handler:currentIntHandler
616: enabler:enabler disabler:disabler];
617:
618: }
619:
620: - (IOReturn) setInterruptFunctions:(UInt32)member
621: refCon:(void *)refCon,
622: handler:(InterruptHandler) handler,
623: enabler:(InterruptEnabler) enabler,
624: disabler:(InterruptDisabler) disabler
625:
626:
627:
628: - (IOReturn) getInterruptFunctions:(UInt32)member
629: refCon:(void **)refCon,
630: handler:(InterruptHandler *) handler,
631: enabler:(InterruptEnabler *) enabler,
632: disabler:(InterruptDisabler *) disabler
633:
634: #endif
635:
636: //////////////////////////////////////////////////////////////////////////////////////////
637:
638: - (IOReturn) getAppleSense:(IOFBIndex)connectIndex info:(IOFBAppleSenseInfo *)info;
639: {
640: OSStatus err;
641: VDDisplayConnectInfoRec displayConnect;
642:
643: err = [self doStatus:cscGetConnection params:&displayConnect];
644: if( err)
645: return( err);
646:
647: if( displayConnect.csConnectFlags & ((1<<kReportsTagging) | (1<<kTaggingInfoNonStandard))
648: != ((1<<kReportsTagging)) )
649:
650: err = IO_R_UNSUPPORTED;
651:
652: else {
653: // info->standardDisplayType = displayConnect.csDisplayType;
654: info->primarySense = displayConnect.csConnectTaggedType;
655: info->extendedSense = displayConnect.csConnectTaggedData;
656: if( (info->primarySense == 0) && (info->extendedSense == 6)) {
657: info->primarySense = kRSCSix;
658: info->extendedSense = kESCSixStandard;
659: }
660: if( (info->primarySense == 0) && (info->extendedSense == 4)) {
661: info->primarySense = kRSCFour;
662: info->extendedSense = kESCFourNTSC;
663: }
664: }
665: return( err);
666: }
667:
668: - (BOOL) hasDDCConnect:(IOFBIndex)connectIndex
669: {
670: OSStatus err;
671: VDDisplayConnectInfoRec displayConnect;
672: enum { kNeedFlags = (1<<kReportsDDCConnection) | (1<<kHasDDCConnection) };
673:
674: err = [self doStatus:cscGetConnection params:&displayConnect];
675: if( err)
676: return( NO);
677:
678: return( (displayConnect.csConnectFlags & kNeedFlags) == kNeedFlags );
679: }
680:
681: - (IOReturn) getDDCBlock:(IOFBIndex)connectIndex blockNumber:(UInt32)num blockType:(OSType)type
682: options:(UInt32)options data:(UInt8 *)data length:(ByteCount *)length
683: {
684: OSStatus err = 0;
685: VDDDCBlockRec ddcRec;
686: ByteCount actualLength = *length;
687:
688: ddcRec.ddcBlockNumber = num;
689: ddcRec.ddcBlockType = type;
690: ddcRec.ddcFlags = options;
691:
692: err = [self doStatus:cscGetDDCBlock params:&ddcRec];
693:
694: if( err == noErr) {
695:
696: actualLength = (actualLength < kDDCBlockSize) ? actualLength : kDDCBlockSize;
697: bcopy( ddcRec.ddcBlockData, data, actualLength);
698: *length = actualLength;
699: }
700: return( err);
701: }
702:
703: //////////////////////////////////////////////////////////////////////////////////////////
704:
705: - (IOReturn)getIntValues:(unsigned *)parameterArray
706: forParameter:(IOParameterName)parameterName
707: count:(unsigned int *)count
708: {
709:
710: if (strcmp(parameterName, "IOGetTransferTable") == 0) {
711: return( [self getTransferTable:¶meterArray[0] count:count] );
712:
713: } else
714: return [super getIntValues:parameterArray
715: forParameter:parameterName
716: count:count];
717: }
718:
719:
720:
721: //////////////////////////////////////////////////////////////////////////////////////////
722: // IOCallDeviceMethods:
723:
724: // Should be in NDRV class?
725: - (IOReturn) IONDRVGetDriverName:(char *)outputParams size:(unsigned *) outputCount
726: {
727: char * name;
728: UInt32 len, plen;
729:
730: name = theDriverDesc->driverOSRuntimeInfo.driverName;
731:
732: plen = *(name++);
733: len = *outputCount - 1;
734: *outputCount = plen + 1;
735: if( plen < len)
736: len = plen;
737: strncpy( outputParams, name, len);
738: outputParams[ len ] = 0;
739:
740: return( noErr);
741: }
742:
743: - (IOReturn) IONDRVDoControl:(UInt32 *)inputParams inputSize:(unsigned) inputCount
744: params:(void *)outputParams outputSize:(unsigned *) outputCount
745: privileged:(host_priv_t *)privileged
746: {
747: IOReturn err = noErr;
748: UInt32 callSelect;
749:
750: if( privileged == NULL)
751: err = IO_R_PRIVILEGE;
752: else {
753: callSelect = *inputParams;
754: err = [self doControl:callSelect params:(inputParams + 1 )];
755: bcopy( inputParams, outputParams, *outputCount);
756: }
757: return( err);
758: }
759:
760: //////////////////////////////////////////////////////////////////////////////////////////
761:
762: - (IOReturn) IONDRVDoStatus:(UInt32 *)inputParams inputSize:(unsigned) inputCount
763: params:(void *)outputParams outputSize:(unsigned *) outputCount
764: {
765: IOReturn err = noErr;
766: UInt32 callSelect;
767:
768: callSelect = *inputParams;
769: err = [self doStatus:callSelect params:(inputParams + 1 )];
770: bcopy( inputParams, outputParams, *outputCount);
771: return( err);
772:
773: }
774:
775: @end
776:
777: //////////////////////////////////////////////////////////////////////////////////////////
778: // DACrap
779:
780: @implementation IONDRVFramebuffer (ProgramDAC)
781:
782: - setTheTable
783: {
784: IOReturn err;
785: ColorSpec * table = transferTable;
786: VDSetEntryRecord setEntryRec;
787: int i, code;
788:
789: if( transferTableCount != 0) {
790: if( brightnessLevel != EV_SCREEN_MAX_BRIGHTNESS) {
791: if( !scaledTable)
792: scaledTable = IOMalloc( 256 * sizeof( ColorSpec));
793: if( scaledTable) {
794: for( i = 0; i < transferTableCount; i++ ) {
795: scaledTable[ i ].rgb.red = EV_SCALE_BRIGHTNESS( brightnessLevel, table[ i ].rgb.red);
796: scaledTable[ i ].rgb.green = EV_SCALE_BRIGHTNESS( brightnessLevel, table[ i ].rgb.green);
797: scaledTable[ i ].rgb.blue = EV_SCALE_BRIGHTNESS( brightnessLevel, table[ i ].rgb.blue);
798: }
799: table = scaledTable;
800: }
801: } else {
802: if( scaledTable) {
803: IOFree( scaledTable, transferTableCount * sizeof( ColorSpec));
804: scaledTable = 0;
805: }
806: }
807:
808: setEntryRec.csTable = table;
809: setEntryRec.csStart = 0;
810: setEntryRec.csCount = transferTableCount - 1;
811: if( [self displayInfo]->bitsPerPixel == IO_8BitsPerPixel)
812: code = cscSetEntries;
813: else
814: code = cscDirectSetEntries;
815: err = [self doControl:code params:&setEntryRec];
816: }
817: return self;
818: }
819:
820: - setBrightness:(int)level token:(int)t
821: {
822: if ((level < EV_SCREEN_MIN_BRIGHTNESS) ||
823: (level > EV_SCREEN_MAX_BRIGHTNESS)){
824: IOLog("Display: Invalid arg to setBrightness: %d\n",
825: level);
826: return nil;
827: }
828: brightnessLevel = level;
829: [self setTheTable];
830: return self;
831: }
832:
833: #define Expand8To16(x) (((x) << 8) | (x))
834:
835:
836: - setTransferTable:(const unsigned int *)table count:(int)count
837: {
838:
839: // no checking table count vs. depth ??
840:
841: int k;
842: IOBitsPerPixel bpp;
843: IOColorSpace cspace;
844: VDGammaRecord gammaRec;
845:
846: bpp = [self displayInfo]->bitsPerPixel;
847: cspace = [self displayInfo]->colorSpace;
848:
849: if( table) {
850: transferTableCount = count;
851: if (bpp == IO_8BitsPerPixel && cspace == IO_OneIsWhiteColorSpace) {
852: for (k = 0; k < count; k++) {
853: transferTable[k].rgb.red = transferTable[k].rgb.green = transferTable[k].rgb.blue
854: = Expand8To16(table[k] & 0xFF);
855: }
856: } else if (cspace == IO_RGBColorSpace &&
857: ((bpp == IO_8BitsPerPixel) ||
858: (bpp == IO_15BitsPerPixel) ||
859: (bpp == IO_24BitsPerPixel))) {
860: for (k = 0; k < count; k++) {
861: transferTable[k].rgb.red = Expand8To16((table[k] >> 24) & 0xFF);
862: transferTable[k].rgb.green = Expand8To16((table[k] >> 16) & 0xFF);
863: transferTable[k].rgb.blue = Expand8To16((table[k] >> 8) & 0xFF);
864: }
865: } else {
866: transferTableCount = 0;
867: }
868: }
869:
870: if( NO == gammaKilled) {
871: gammaRec.csGTable = 0;
872: [self doControl:cscSetGamma params:&gammaRec];
873: gammaKilled = YES;
874: }
875:
876: [self setTheTable];
877: return self;
878: }
879:
880: - (IOReturn)getTransferTable:(unsigned int *)table count:(int *)count
881: {
882: int k;
883:
884: if( *count != transferTableCount)
885: return( IO_R_INVALID_ARG);
886:
887: for (k = 0; k < transferTableCount; k++) {
888: table[k] = ((transferTable[k].rgb.red << 16) & 0xff000000)
889: | ((transferTable[k].rgb.green << 8) & 0xff0000)
890: | ((transferTable[k].rgb.blue) & 0xff00)
891: | ((transferTable[k].rgb.blue >> 8) & 0xff);
892: }
893: return( IO_R_SUCCESS);
894: }
895:
896: // Apple style CLUT - pass thru gamma table
897:
898: - (IOReturn)
899: setCLUT:(IOFBColorEntry *) colors index:(UInt32)index numEntries:(UInt32)numEntries
900: brightness:(IOFixed)brightness options:(IOOptionBits)options
901: {
902: IOReturn err;
903: VDSetEntryRecord setEntryRec;
904: int code;
905:
906: setEntryRec.csTable = (ColorSpec *)colors;
907: setEntryRec.csStart = index;
908: setEntryRec.csCount = numEntries - 1;
909: if( [self displayInfo]->bitsPerPixel == IO_8BitsPerPixel)
910: code = cscSetEntries;
911: else
912: code = cscDirectSetEntries;
913: err = [self doControl:code params:&setEntryRec];
914:
915: return( err);
916:
917: }
918:
919: #if 0
920: - (void) interruptOccurred
921: {
922: kprintf("\n[%s]\n", [self name]);
923: [self enableAllInterrupts];
924: }
925: #endif
926:
927: @end
928:
929: //////////////////////////////////////////////////////////////////////////////////////////
930:
931: // OpenFirmware shim
932:
933: enum { kTheDisplayMode = 10 };
934:
935: @implementation IOOFFramebuffer
936:
937: //=======================================================================
938:
939: - initFromDeviceDescription:(IOPCIDevice *) ioDevice
940: {
941: id me = nil;
942: kern_return_t err = 0;
943: UInt32 i;
944: UInt32 numMaps = 8;
945: IOApertureInfo maps[ numMaps ]; // FIX
946: IOApertureInfo * map;
947:
948: do {
949: numMaps = 8;
950: err = [ioDevice getApertures:maps items:&numMaps];
951: if( err)
952: continue;
953:
954: err = -1;
955: for( i = 0, map = maps; i < numMaps; i++, map++) {
956:
957: if( (((UInt32)bootDisplayInfo.frameBuffer) >= ((UInt32)map->physical))
958: && (((UInt32)bootDisplayInfo.frameBuffer) < (map->length + (UInt32)map->physical)) ) {
959:
960: // Declare range for pmap'ing into user space
961: // Shouldn't be here but it's too expensive to do it for all devices
962: err = pmap_add_physical_memory( map->physical,
963: map->physical + map->length, FALSE, PTE_WIMG_IO);
964: if(err)
965: kprintf("%s: pmap_add_physical_memory:%d for 0x%08x - 0x%08x\n",
966: [self name], err, map->physical, map->physical + map->length);
967: }
968: }
969: if( err)
970: continue;
971:
972: if (nil == [super initFromDeviceDescription:ioDevice])
973: continue;
974: err = [self open];
975: if( err)
976: continue;
977:
978: me = self; // Success
979:
980: } while( false);
981:
982: if( me == nil)
983: [super free];
984:
985: return( me);
986: }
987:
988: - (IOReturn)
989: getDisplayModeByIndex:(IOFBIndex)modeIndex displayMode:(IOFBDisplayModeID *)displayModeID
990: {
991: if( modeIndex)
992: return( IO_R_UNDEFINED_MODE);
993: *displayModeID = kTheDisplayMode;
994: return( noErr);
995: }
996:
997: - (IOReturn)
998: getDisplayModeInformation:(IOFBDisplayModeID)modeID info:(IOFBDisplayModeInformation *)info
999: {
1000: if( modeID == kTheDisplayMode) {
1001: info->displayModeID = modeID;
1002: info->maxDepthIndex = 0;
1003: info->nominalWidth = bootDisplayInfo.width;
1004: info->nominalHeight = bootDisplayInfo.height;
1005: info->refreshRate = bootDisplayInfo.refreshRate << 16;
1006: return( noErr);
1007: }
1008: return( IO_R_UNDEFINED_MODE);
1009: }
1010:
1011:
1012: - (IOReturn)
1013: getPixelInformationForDisplayMode:(IOFBDisplayModeID)modeID andDepthIndex:(IOFBIndex)depthIndex
1014: pixelInfo:(IOFBPixelInformation *)info
1015: {
1016:
1017: if( (modeID == kTheDisplayMode) && (depthIndex == 0)) {
1018:
1019: info->flags = 0;
1020: info->rowBytes = bootDisplayInfo.rowBytes;
1021: info->width = bootDisplayInfo.width;
1022: info->height = bootDisplayInfo.height;
1023: info->refreshRate = bootDisplayInfo.refreshRate << 16;
1024: info->pageCount = 1;
1025: info->pixelType = kIOFBRGBCLUTPixelType;
1026: info->bitsPerPixel = 8;
1027: // info->channelMasks =
1028: return( noErr);
1029: }
1030: return( IO_R_UNDEFINED_MODE);
1031: }
1032:
1033: - (IOReturn)
1034: setDisplayMode:(IOFBDisplayModeID)modeID depth:(IOFBIndex)depthIndex page:(IOFBIndex)pageIndex
1035: {
1036: if( (modeID == kTheDisplayMode) && (depthIndex == 0) && (pageIndex == 0) )
1037: return( noErr);
1038: else
1039: return( IO_R_UNDEFINED_MODE);
1040: }
1041:
1042:
1043: - (IOReturn)
1044: getStartupMode:(IOFBDisplayModeID *)modeID depth:(IOFBIndex *)depthIndex
1045: {
1046: *modeID = kTheDisplayMode;
1047: *depthIndex = 0;
1048:
1049: return( noErr);
1050: }
1051:
1052:
1053: - (IOReturn)
1054: getConfiguration:(IOFBConfiguration *)config
1055: {
1056: bzero( config, sizeof( IOFBConfiguration));
1057:
1058: config->displayMode = kTheDisplayMode;
1059: config->depth = 0;
1060: config->page = 0;
1061: config->physicalFramebuffer = (IOPhysicalAddress) bootDisplayInfo.frameBuffer;
1062: config->mappedFramebuffer = (IOVirtualAddress) bootDisplayInfo.frameBuffer; // assuming 1-1
1063:
1064: return( noErr);
1065: }
1066:
1067: - (IOReturn)
1068: getDisplayModeTiming:(IOFBIndex)connectIndex mode:(IOFBDisplayModeID)modeID
1069: timingInfo:(IOFBTimingInformation *)info connectFlags:(UInt32 *)flags
1070: {
1071:
1072: info->standardTimingID = timingInvalid;
1073: if( modeID == kTheDisplayMode) {
1074: *flags = kDisplayModeValidFlag | kDisplayModeSafeFlag | kDisplayModeDefaultFlag;
1075: return( noErr);
1076: } else {
1077: *flags = 0;
1078: return( IO_R_UNDEFINED_MODE);
1079: }
1080: }
1081:
1082:
1083: - setBrightness:(int)level token:(int)t
1084: {
1085: return self;
1086: }
1087:
1088: - setTransferTable:(const unsigned int *)table count:(int)count
1089: {
1090: return self;
1091: }
1092:
1093: - (IOReturn)getIntValues:(unsigned *)parameterArray
1094: forParameter:(IOParameterName)parameterName
1095: count:(unsigned int *)count
1096: {
1097: const UInt8 * clut;
1098: int i;
1099: extern const UInt8 appleClut8[ 256 * 3 ];
1100:
1101: if( (0 == strcmp(parameterName, "IOGetTransferTable"))
1102: && (*count == 256)) {
1103: for( clut = appleClut8, i = 0; i < 256; i++, clut += 3)
1104: *(parameterArray++) = (clut[0] << 24) | (clut[1] << 16) | (clut[3] << 8) | 0xff;
1105: return( noErr);
1106:
1107: } else
1108: return [super getIntValues:parameterArray
1109: forParameter:parameterName
1110: count:count];
1111: }
1112:
1113: @end
1114:
1115: //////////////////////////////////////////////////////////////////////////////////////////
1116:
1.1.1.2 ! root 1117: // ATI patches. Acceleration to be removed when user level blitting is in.
! 1118: // Real problem : getStartupMode doesn't.
1.1 root 1119:
1120: @implementation IOATINDRV
1121:
1122: - (IOReturn)
1123: getStartupMode:(IOFBDisplayModeID *)modeID depth:(IOFBIndex *)depthIndex
1124: {
1125:
1126: IOReturn err;
1127: UInt16 * nvram;
1128: ByteCount propSize = 8;
1129:
1130: err = [[ioDevice propertyTable] getProperty:"Sime" flags:kReferenceProperty
1131: value:(void *)&nvram length:&propSize];
1132: if( err == noErr) {
1133: *modeID = nvram[ 0 ]; // 1 is physDisplayMode
1134: *depthIndex = nvram[ 2 ] - kDepthMode1;
1135: }
1136: return( err);
1137: }
1138:
1139: @end
1140:
1141:
1142:
1143:
1144:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.