2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 * 01 Sep 92 Portions from Joe Pasqua, Created.
31 #include <IOKit/IOLib.h>
32 #include <libkern/c++/OSContainers.h>
34 #include <IOKit/IOWorkLoop.h>
35 #include <IOKit/IOInterruptEventSource.h>
36 #include <IOKit/IOPlatformExpert.h>
37 #include <IOKit/IOBufferMemoryDescriptor.h>
39 #define IOFRAMEBUFFER_PRIVATE
40 #include <IOKit/graphics/IOFramebuffer.h>
41 #include <IOKit/graphics/IODisplay.h>
43 #include "IOFramebufferUserClient.h"
44 #include "IODisplayWrangler.h"
45 #include "IOFramebufferReallyPrivate.h"
46 #include <IOKit/pwr_mgt/RootDomain.h>
49 #include <IOKit/assert.h>
50 #include <sys/kdebug.h>
52 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
55 #define super IOGraphicsDevice
57 OSDefineMetaClass( IOFramebuffer
, IOGraphicsDevice
)
58 OSDefineAbstractStructors( IOFramebuffer
, IOGraphicsDevice
)
60 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
62 #define GetShmem(instance) ((StdFBShmem_t *)(instance->priv))
64 #define CLEARSEMA(shmem) ev_unlock(&shmem->cursorSema)
65 #define SETSEMA(shmem) \
66 if (!ev_try_lock(&shmem->cursorSema)) return;
67 #define TOUCHBOUNDS(one, two) \
68 (((one.minx < two.maxx) && (two.minx < one.maxx)) && \
69 ((one.miny < two.maxy) && (two.miny < one.maxy)))
75 #include "IOCursorBlits.h"
77 inline void IOFramebuffer::StdFBDisplayCursor( IOFramebuffer
* inst
)
81 volatile unsigned char *vramPtr
; /* screen data pointer */
82 unsigned int cursStart
;
83 unsigned int cursorWidth
;
87 shmem
= GetShmem(inst
);
88 saveRect
= shmem
->cursorRect
;
89 /* Clip saveRect vertical within screen bounds */
90 if (saveRect
.miny
< shmem
->screenBounds
.miny
)
91 saveRect
.miny
= shmem
->screenBounds
.miny
;
92 if (saveRect
.maxy
> shmem
->screenBounds
.maxy
)
93 saveRect
.maxy
= shmem
->screenBounds
.maxy
;
94 if (saveRect
.minx
< shmem
->screenBounds
.minx
)
95 saveRect
.minx
= shmem
->screenBounds
.minx
;
96 if (saveRect
.maxx
> shmem
->screenBounds
.maxx
)
97 saveRect
.maxx
= shmem
->screenBounds
.maxx
;
98 shmem
->saveRect
= saveRect
; /* Remember save rect for RemoveCursor */
100 vramPtr
= inst
->frameBuffer
+
101 (inst
->rowBytes
* (saveRect
.miny
- shmem
->screenBounds
.miny
)) +
102 (inst
->bytesPerPixel
* (saveRect
.minx
- shmem
->screenBounds
.minx
));
104 width
= saveRect
.maxx
- saveRect
.minx
;
105 height
= saveRect
.maxy
- saveRect
.miny
;
106 cursorWidth
= shmem
->cursorSize
[shmem
->frame
].width
;
108 cursStart
= (saveRect
.miny
- shmem
->cursorRect
.miny
) * cursorWidth
+
109 (saveRect
.minx
- shmem
->cursorRect
.minx
);
111 if( inst
->cursorBlitProc
)
112 inst
->cursorBlitProc( inst
,
116 inst
->totalWidth
- width
, /* vramRow */
117 cursorWidth
- width
, /* cursRow */
122 // Description: RemoveCursor erases the cursor by replacing the background
123 // image that was saved by the previous call to DisplayCursor.
124 // If the frame buffer is cacheable, flush at the end of the
125 // drawing operation.
127 inline void IOFramebuffer::StdFBRemoveCursor( IOFramebuffer
* inst
)
130 volatile unsigned char *vramPtr
; /* screen data pointer */
131 unsigned int vramRow
;
135 shmem
= GetShmem(inst
);
137 vramRow
= inst
->totalWidth
; /* Scanline width in pixels */
139 vramPtr
= inst
->frameBuffer
+
140 (inst
->rowBytes
* (shmem
->saveRect
.miny
- shmem
->screenBounds
.miny
))
141 + (inst
->bytesPerPixel
*
142 (shmem
->saveRect
.minx
- shmem
->screenBounds
.minx
));
144 width
= shmem
->saveRect
.maxx
- shmem
->saveRect
.minx
;
145 height
= shmem
->saveRect
.maxy
- shmem
->saveRect
.miny
;
148 if( inst
->cursorRemoveProc
)
149 inst
->cursorRemoveProc( inst
, (void *)shmem
,
150 vramPtr
, vramRow
, width
, height
);
153 inline void IOFramebuffer::RemoveCursor( IOFramebuffer
* inst
)
155 StdFBShmem_t
* shmem
= GetShmem(inst
);
157 if( shmem
->hardwareCursorActive
) {
160 hs
= &shmem
->hotSpot
[shmem
->frame
];
161 inst
->setCursorState(
162 shmem
->cursorLoc
.x
- hs
->x
- shmem
->screenBounds
.minx
,
163 shmem
->cursorLoc
.y
- hs
->y
- shmem
->screenBounds
.miny
, false );
165 StdFBRemoveCursor(inst
);
168 inline void IOFramebuffer::DisplayCursor( IOFramebuffer
* inst
)
171 StdFBShmem_t
* shmem
= GetShmem(inst
);
174 hs
= &shmem
->hotSpot
[shmem
->frame
];
175 x
= shmem
->cursorLoc
.x
- hs
->x
;
176 y
= shmem
->cursorLoc
.y
- hs
->y
;
178 if( shmem
->hardwareCursorActive
)
179 inst
->setCursorState( x
- shmem
->screenBounds
.minx
,
180 y
- shmem
->screenBounds
.miny
, true );
182 shmem
->cursorRect
.maxx
= (shmem
->cursorRect
.minx
= x
)
183 + shmem
->cursorSize
[shmem
->frame
].width
;
184 shmem
->cursorRect
.maxy
= (shmem
->cursorRect
.miny
= y
)
185 + shmem
->cursorSize
[shmem
->frame
].height
;
186 StdFBDisplayCursor(inst
);
187 shmem
->oldCursorRect
= shmem
->cursorRect
;
191 inline void IOFramebuffer::SysHideCursor( IOFramebuffer
* inst
)
193 if (!GetShmem(inst
)->cursorShow
++)
197 inline void IOFramebuffer::SysShowCursor( IOFramebuffer
* inst
)
201 shmem
= GetShmem(inst
);
203 if (shmem
->cursorShow
)
204 if (!--(shmem
->cursorShow
))
208 inline void IOFramebuffer::CheckShield( IOFramebuffer
* inst
)
213 StdFBShmem_t
* shmem
= GetShmem(inst
);
215 /* Calculate temp cursorRect */
216 hs
= &shmem
->hotSpot
[shmem
->frame
];
217 tempRect
.maxx
= (tempRect
.minx
= (shmem
->cursorLoc
).x
- hs
->x
)
218 + shmem
->cursorSize
[shmem
->frame
].width
;
219 tempRect
.maxy
= (tempRect
.miny
= (shmem
->cursorLoc
).y
- hs
->y
)
220 + shmem
->cursorSize
[shmem
->frame
].height
;
222 intersect
= TOUCHBOUNDS(tempRect
, shmem
->shieldRect
);
223 if (intersect
!= shmem
->shielded
)
224 (shmem
->shielded
= intersect
) ?
225 SysHideCursor(inst
) : SysShowCursor(inst
);
232 void IOFramebuffer::setupCursor( IOPixelInformation
* info
)
234 StdFBShmem_t
* shmem
= GetShmem(this);
235 volatile unsigned char * bits
;
236 IOByteCount cursorImageBytes
;
238 rowBytes
= info
->bytesPerRow
;
239 totalWidth
= (rowBytes
* 8) / info
->bitsPerPixel
;
240 bytesPerPixel
= info
->bitsPerPixel
/ 8;
241 frameBuffer
= (volatile unsigned char *) vramMap
->getVirtualAddress();
244 if( (shmem
->screenBounds
.maxx
== shmem
->screenBounds
.minx
)
245 || (shmem
->screenBounds
.maxy
== shmem
->screenBounds
.miny
)) {
246 // a default if no one calls IOFBSetBounds()
247 shmem
->screenBounds
.minx
= 0;
248 shmem
->screenBounds
.miny
= 0;
249 shmem
->screenBounds
.maxx
= info
->activeWidth
;
250 shmem
->screenBounds
.maxy
= info
->activeHeight
;
253 cursorImageBytes
= maxCursorSize
.width
* maxCursorSize
.height
255 bits
= shmem
->cursor
;
256 for( int i
= 0; i
< kIOFBNumCursorFrames
; i
++ ) {
257 cursorImages
[i
] = bits
;
258 bits
+= cursorImageBytes
;
259 shmem
->cursorSize
[i
] = maxCursorSize
;
261 if( info
->bitsPerPixel
<= 8) {
262 for( int i
= 0; i
< kIOFBNumCursorFrames
; i
++ ) {
263 cursorMasks
[i
] = bits
;
264 bits
+= cursorImageBytes
;
270 switch( info
->bitsPerPixel
) {
272 if( colorConvert
.t
._bm256To38SampleTable
273 && colorConvert
.t
._bm38To256SampleTable
) {
274 cursorBlitProc
= (CursorBlitProc
) StdFBDisplayCursor8P
;
275 cursorRemoveProc
= (CursorRemoveProc
) StdFBRemoveCursor8
;
279 if( colorConvert
.t
._bm34To35SampleTable
280 && colorConvert
.t
._bm35To34SampleTable
) {
281 cursorBlitProc
= (CursorBlitProc
) StdFBDisplayCursor555
;
282 cursorRemoveProc
= (CursorRemoveProc
) StdFBRemoveCursor16
;
286 if( colorConvert
.t
._bm256To38SampleTable
287 && colorConvert
.t
._bm38To256SampleTable
) {
288 cursorBlitProc
= (CursorBlitProc
) StdFBDisplayCursor32Axxx
;
289 cursorRemoveProc
= (CursorRemoveProc
) StdFBRemoveCursor32
;
293 IOLog("%s: can't do cursor at depth %ld\n",
294 getName(), info
->bitsPerPixel
);
295 cursorBlitProc
= (CursorBlitProc
) NULL
;
296 cursorRemoveProc
= (CursorRemoveProc
) NULL
;
301 void IOFramebuffer::stopCursor( void )
303 cursorBlitProc
= (CursorBlitProc
) NULL
;
304 cursorRemoveProc
= (CursorRemoveProc
) NULL
;
307 IOReturn
IOFramebuffer::createSharedCursor(
308 int shmemVersion
, int maxWidth
, int maxHeight
)
310 StdFBShmem_t
* shmem
;
311 IOByteCount size
, maxImageSize
;
313 kprintf("createSharedCursor vers = %d, %d x %d\n",
314 shmemVersion
, maxWidth
, maxHeight
);
316 if( shmemVersion
!= kIOFBCurrentShmemVersion
)
317 return( kIOReturnUnsupported
);
319 shmemClientVersion
= shmemVersion
;
320 maxImageSize
= (maxWidth
* maxHeight
* kIOFBMaxCursorDepth
) / 8;
322 size
= sizeof( StdFBShmem_t
)
323 + ((kIOFBNumCursorFrames
+ 1) * maxImageSize
);
325 if( !sharedCursor
|| (size
!= sharedCursor
->getLength())) {
326 IOBufferMemoryDescriptor
* newDesc
;
329 newDesc
= IOBufferMemoryDescriptor::withOptions(
330 kIODirectionNone
| kIOMemoryKernelUserShared
, size
);
332 return( kIOReturnNoMemory
);
335 sharedCursor
->release();
336 sharedCursor
= newDesc
;
338 shmem
= (StdFBShmem_t
*) sharedCursor
->getBytesNoCopy();
341 // Init shared memory area
342 bzero( shmem
, size
);
343 shmem
->version
= kIOFBCurrentShmemVersion
;
344 shmem
->structSize
= size
;
345 shmem
->cursorShow
= 1;
346 shmem
->hardwareCursorCapable
= haveHWCursor
;
348 maxCursorSize
.width
= maxWidth
;
349 maxCursorSize
.height
= maxHeight
;
353 return( kIOReturnSuccess
);
356 IOReturn
IOFramebuffer::setBoundingRect( Bounds
* bounds
)
360 shmem
= GetShmem(this);
362 return( kIOReturnUnsupported
);
364 shmem
->screenBounds
= *bounds
;
366 return( kIOReturnSuccess
);
370 ** IOUserClient methods
373 IOReturn
IOFramebuffer::newUserClient( task_t owningTask
,
376 IOUserClient
** handler
)
380 static UInt8 data
[] = { 0x00, 0x03, 0x04, 0x07, 0x08, 0x0b, 0x0c, 0x0f,
381 0x10, 0x13, 0x14, 0x17, 0x18, 0x1b, 0x1c, 0x1f,
383 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03,
384 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07, 0x07,
385 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, 0x0b, 0x0b,
386 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0f, 0x0f };
387 colorConvert
.t
._bm34To35SampleTable
= data
;
388 colorConvert
.t
._bm35To34SampleTable
= data
+ 16;
391 IOReturn err
= kIOReturnSuccess
;
392 IOUserClient
* newConnect
= 0;
393 IOUserClient
* theConnect
= 0;
397 case kIOFBServerConnectType
:
399 err
= kIOReturnExclusiveAccess
;
402 if( isConsoleDevice())
403 getPlatform()->setConsoleInfo( 0, kPEReleaseScreen
);
405 err
= IODisplayWrangler::clientStart( this );
406 if( kIOReturnSuccess
== err
)
407 newConnect
= IOFramebufferUserClient::withTask(owningTask
);
411 case kIOFBSharedConnectType
:
413 theConnect
= sharedConnect
;
414 theConnect
->retain();
415 } else if( serverConnect
)
416 newConnect
= IOFramebufferSharedUserClient::withTask(owningTask
);
418 err
= kIOReturnNotOpen
;
421 case kIOFBEngineControllerConnectType
:
422 case kIOFBEngineConnectType
:
423 newConnect
= IOGraphicsEngineClient::withTask(owningTask
);
427 err
= kIOReturnBadArgument
;
431 if( (false == newConnect
->attach( this ))
432 || (false == newConnect
->start( this ))) {
433 newConnect
->detach( this );
434 newConnect
->release();
436 theConnect
= newConnect
;
439 *handler
= theConnect
;
443 IOReturn
IOFramebuffer::extGetDisplayModeCount( IOItemCount
* count
)
445 *count
= getDisplayModeCount();
446 return( kIOReturnSuccess
);
449 IOReturn
IOFramebuffer::extGetDisplayModes( IODisplayModeID
* allModes
, IOByteCount
* size
)
454 outSize
= getDisplayModeCount() * sizeof( IODisplayModeID
);
457 return( kIOReturnBadArgument
);
460 err
= getDisplayModes( allModes
);
465 IOReturn
IOFramebuffer::extGetVRAMMapOffset( IOPixelAperture
/* aperture */,
466 IOByteCount
* offset
)
468 *offset
= vramMapOffset
;
470 return( kIOReturnSuccess
);
473 IOReturn
IOFramebuffer::extSetBounds( Bounds
* bounds
)
477 shmem
= GetShmem(this);
479 shmem
->screenBounds
= *bounds
;
481 return( kIOReturnSuccess
);
484 IOReturn
IOFramebuffer::extValidateDetailedTiming(
485 void * description
, void * outDescription
,
486 IOByteCount inSize
, IOByteCount
* outSize
)
490 if( *outSize
!= inSize
)
491 return( kIOReturnBadArgument
);
493 err
= validateDetailedTiming( description
, inSize
);
495 if( kIOReturnSuccess
== err
)
496 bcopy( description
, outDescription
, inSize
);
502 IOReturn
IOFramebuffer::extSetColorConvertTable( UInt32 select
,
503 UInt8
* data
, IOByteCount length
)
505 static const IOByteCount checkLength
[] = {
508 256 * sizeof( UInt32
),
509 5 * 256 * sizeof( UInt8
) };
512 IODisplayModeID mode
;
514 IOPixelInformation info
;
517 return( kIOReturnBadArgument
);
519 if( length
!= checkLength
[select
])
520 return( kIOReturnBadArgument
);
522 table
= colorConvert
.tables
[select
];
524 table
= (UInt8
*) IOMalloc( length
);
525 colorConvert
.tables
[select
] = table
;
528 return( kIOReturnNoMemory
);
530 bcopy( data
, table
, length
);
532 white
= data
[data
[255] + data
[511] + data
[767] + 1024];
534 if( (NULL
== cursorBlitProc
)
535 && colorConvert
.tables
[0] && colorConvert
.tables
[1]
536 && colorConvert
.tables
[2] && colorConvert
.tables
[3]
538 && (kIOReturnSuccess
== getCurrentDisplayMode( &mode
, &depth
))
539 && (kIOReturnSuccess
== getPixelInformation( mode
, depth
, kIOFBSystemAperture
, &info
)))
540 setupCursor( &info
);
542 return( kIOReturnSuccess
);
545 IOReturn
IOFramebuffer::extSetCLUTWithEntries( UInt32 index
, IOOptionBits options
,
546 IOColorEntry
* colors
, IOByteCount inputCount
)
550 kr
= setCLUTWithEntries( colors
, index
,
551 inputCount
/ sizeof( IOColorEntry
),
557 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
560 // BEGIN: Implementation of the evScreen protocol
563 void IOFramebuffer::hideCursor( void )
565 StdFBShmem_t
*shmem
= GetShmem(this);
573 void IOFramebuffer::free()
576 semaphore_destroy(kernel_task
, vblSemaphore
);
581 void IOFramebuffer::deferredMoveCursor( IOFramebuffer
* inst
)
583 StdFBShmem_t
* shmem
= GetShmem(inst
);
584 IOReturn err
= kIOReturnSuccess
;
586 if( shmem
->hardwareCursorActive
&& (0 == shmem
->frame
) ) {
588 if (shmem
->cursorObscured
) {
589 shmem
->cursorObscured
= 0;
590 if (shmem
->cursorShow
)
593 if (!shmem
->cursorShow
) {
595 hs
= &shmem
->hotSpot
[shmem
->frame
];
596 err
= inst
->setCursorState(
597 shmem
->cursorLoc
.x
- hs
->x
- shmem
->screenBounds
.minx
,
598 shmem
->cursorLoc
.y
- hs
->y
- shmem
->screenBounds
.miny
, true );
603 if (!shmem
->cursorShow
++)
605 if (shmem
->cursorObscured
) {
606 shmem
->cursorObscured
= 0;
607 if (shmem
->cursorShow
)
610 if (shmem
->shieldFlag
) CheckShield(inst
);
611 if (shmem
->cursorShow
)
612 if (!--shmem
->cursorShow
)
617 inst
->needCursorService
= (kIOReturnBusy
== err
);
620 void IOFramebuffer::moveCursor( Point
* cursorLoc
, int frame
)
622 nextCursorLoc
= *cursorLoc
;
623 nextCursorFrame
= frame
;
624 needCursorService
= true;
626 StdFBShmem_t
*shmem
= GetShmem(this);
630 if( !haveVBLService
) {
631 shmem
->cursorLoc
= *cursorLoc
;
632 shmem
->frame
= frame
;
633 deferredMoveCursor( this );
639 void IOFramebuffer::handleVBL( IOFramebuffer
* inst
, void * ref
)
641 StdFBShmem_t
* shmem
= GetShmem(inst
);
647 clock_get_uptime( &now
);
648 shmem
->vblDelta
= now
;
649 SUB_ABSOLUTETIME( &shmem
->vblDelta
, &shmem
->vblTime
);
650 shmem
->vblTime
= now
;
652 KERNEL_DEBUG(0xc000030 | DBG_FUNC_NONE
,
653 shmem
->vblDelta
.hi
, shmem
->vblDelta
.lo
, 0, 0, 0);
655 if( inst
->vblSemaphore
)
656 semaphore_signal_all(inst
->vblSemaphore
);
660 if( inst
->needCursorService
) {
661 shmem
->cursorLoc
= inst
->nextCursorLoc
;
662 shmem
->frame
= inst
->nextCursorFrame
;
663 deferredMoveCursor( inst
);
669 void IOFramebuffer::showCursor( Point
* cursorLoc
, int frame
)
673 shmem
= GetShmem(this);
675 shmem
->frame
= frame
;
676 shmem
->hardwareCursorActive
= hwCursorLoaded
&& (frame
== 0);
677 shmem
->cursorLoc
= *cursorLoc
;
678 if (shmem
->shieldFlag
) CheckShield(this);
683 void IOFramebuffer::resetCursor( void )
687 shmem
= GetShmem(this);
688 hwCursorLoaded
= false;
692 shmem
->hardwareCursorActive
= false;
693 showCursor( &shmem
->cursorLoc
, shmem
->frame
);
696 void IOFramebuffer::getVBLTime( AbsoluteTime
* time
, AbsoluteTime
* delta
)
700 shmem
= GetShmem(this);
702 *time
= shmem
->vblTime
;
703 *delta
= shmem
->vblDelta
;
705 time
->hi
= time
->lo
= 0;
708 void IOFramebuffer::getBoundingRect( Bounds
** bounds
)
712 shmem
= GetShmem(this);
716 *bounds
= &shmem
->screenBounds
;
720 // END: Implementation of the evScreen protocol
723 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
725 IOReturn
IOFramebuffer::getNotificationSemaphore(
726 IOSelect interruptType
, semaphore_t
* semaphore
)
731 if( interruptType
!= kIOFBVBLInterruptType
)
732 return( kIOReturnUnsupported
);
735 return( kIOReturnNoResources
);
737 if( MACH_PORT_NULL
== vblSemaphore
) {
738 kr
= semaphore_create(kernel_task
, &sema
, SYNC_POLICY_FIFO
, 0);
739 if( kr
== KERN_SUCCESS
)
744 if( kr
== KERN_SUCCESS
)
745 *semaphore
= vblSemaphore
;
750 IOReturn
IOFramebuffer::extSetCursorVisible( bool visible
)
754 StdFBShmem_t
* shmem
= GetShmem(this);
756 if( shmem
->hardwareCursorActive
) {
757 hs
= &shmem
->hotSpot
[shmem
->frame
];
758 err
= setCursorState(
759 shmem
->cursorLoc
.x
- hs
->x
- shmem
->screenBounds
.minx
,
760 shmem
->cursorLoc
.y
- hs
->y
- shmem
->screenBounds
.miny
,
763 err
= kIOReturnBadArgument
;
768 IOReturn
IOFramebuffer::extSetCursorPosition( SInt32 x
, SInt32 y
)
770 return( kIOReturnUnsupported
);
773 IOReturn
IOFramebuffer::extSetNewCursor( void * cursor
, IOIndex frame
,
774 IOOptionBits options
)
776 StdFBShmem_t
* shmem
= GetShmem(this);
779 if( cursor
|| options
|| frame
)
780 err
= kIOReturnBadArgument
;
783 if( (shmem
->cursorSize
[frame
].width
> maxCursorSize
.width
)
784 || (shmem
->cursorSize
[frame
].height
> maxCursorSize
.height
))
785 err
= kIOReturnBadArgument
;
787 else if( haveHWCursor
)
788 err
= setCursorImage( (void *) frame
);
790 err
= kIOReturnUnsupported
;
793 hwCursorLoaded
= (kIOReturnSuccess
== err
);
794 shmem
->hardwareCursorActive
= hwCursorLoaded
&& (shmem
->frame
== 0);
799 bool IOFramebuffer::convertCursorImage( void * cursorImage
,
800 IOHardwareCursorDescriptor
* hwDesc
,
801 IOHardwareCursorInfo
* hwCursorInfo
)
803 StdFBShmem_t
* shmem
= GetShmem(this);
804 UInt8
* dataOut
= hwCursorInfo
->hardwareCursorData
;
805 IOColorEntry
* clut
= hwCursorInfo
->colorMap
;
806 UInt32 maxColors
= hwDesc
->numColors
;
807 int frame
= (int) cursorImage
;
809 volatile unsigned short * cursPtr16
;
810 volatile unsigned int * cursPtr32
;
812 UInt32 index
, numColors
= 0;
813 UInt16 alpha
, red
, green
, blue
;
820 assert( frame
< kIOFBNumCursorFrames
);
822 if( bytesPerPixel
== 4) {
823 cursPtr32
= (volatile unsigned int *) cursorImages
[ frame
];
825 } else if( bytesPerPixel
== 2) {
827 cursPtr16
= (volatile unsigned short *) cursorImages
[ frame
];
831 x
= shmem
->cursorSize
[frame
].width
;
832 y
= shmem
->cursorSize
[frame
].height
;
834 if( (x
> (SInt32
) hwDesc
->width
) || (y
> (SInt32
) hwDesc
->height
))
837 hwCursorInfo
->cursorWidth
= x
;
838 hwCursorInfo
->cursorHeight
= y
;
839 while( (--y
!= -1) ) {
840 x
= shmem
->cursorSize
[frame
].width
;
841 while( (--x
!= -1) ) {
844 s32
= *(cursPtr32
++);
845 alpha
= (s32
>> 28) & 0xf;
846 if( alpha
&& (alpha
!= 0xf))
847 *(cursPtr32
- 1) = 0x00ffffff;
850 s16
= *(cursPtr16
++);
851 alpha
= s16
& 0x000F;
852 if( alpha
&& (alpha
!= 0xf))
853 *(cursPtr16
- 1) = 0xfff0;
859 hwCursorInfo
->cursorWidth
= x
;
860 hwCursorInfo
->cursorHeight
= y
;
862 while( ok
&& (--y
!= -1) ) {
863 x
= shmem
->cursorSize
[frame
].width
;
864 while( ok
&& (--x
!= -1) ) {
867 s32
= *(cursPtr32
++);
868 alpha
= (s32
>> 28) & 0xf;
869 red
= (s32
>> 16) & 0xff;
871 green
= (s32
>> 8) & 0xff;
872 green
|= (green
<< 8);
877 #define RMASK16 0xF000
878 #define GMASK16 0x0F00
879 #define BMASK16 0x00F0
880 #define AMASK16 0x000F
881 s16
= *(cursPtr16
++);
882 alpha
= s16
& AMASK16
;
884 red
|= (red
>> 4) | (red
>> 8) | (red
>> 12);
885 green
= s16
& GMASK16
;
886 green
|= (green
<< 4) | (green
>> 4) | (green
>> 8);
887 blue
= s16
& BMASK16
;
888 blue
|= (blue
<< 8) | (blue
<< 4) | (blue
>> 4);
893 if( 0 == (red
| green
| blue
)) {
894 /* Transparent black area. Leave dst as is. */
895 if( kTransparentEncodedPixel
896 & hwDesc
->supportedSpecialEncodings
)
897 pixel
= hwDesc
->specialEncodings
[kTransparentEncoding
];
900 } else if (0xffff == (red
& green
& blue
)) {
901 /* Transparent white area. Invert dst. */
902 if( kInvertingEncodedPixel
903 & hwDesc
->supportedSpecialEncodings
)
904 pixel
= hwDesc
->specialEncodings
[kInvertingEncoding
];
910 } else if( alpha
== 0xf ) {
912 /* Opaque cursor pixel. Mark it. */
913 for( index
= 0; index
< numColors
; index
++ ) {
914 if( (red
== clut
[ index
].red
)
915 && (green
== clut
[ index
].green
)
916 && (blue
== clut
[ index
].blue
) ) {
918 pixel
= clut
[ index
].index
;
922 if( index
== numColors
) {
923 ok
= (numColors
< maxColors
);
925 pixel
= hwDesc
->colorEncodings
[ numColors
++ ];
926 clut
[ index
].red
= red
;
927 clut
[ index
].green
= green
;
928 clut
[ index
].blue
= blue
;
929 clut
[ index
].index
= pixel
;
934 /* Alpha is not 0 or 1.0. Sover the cursor. */
939 data
<<= hwDesc
->bitDepth
;
942 if( 0 == (x
& ((8 / hwDesc
->bitDepth
) - 1)))
947 // if( !ok) kprintf("Couldnt do a hw curs\n");
952 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
954 void IOFramebuffer::initialize()
957 static IOWorkLoop
* gIOFramebufferWorkloop
;
958 static IOLock
* gIOFramebufferLock
;
960 gIOFramebufferLock
= IOLockAlloc();
962 gIOFramebufferWorkloop
= IOWorkLoop::workLoop();
964 assert( gIOFramebufferLock
&& gIOFramebufferWorkloop
);
969 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
972 static bool serializeInfoCB( void * target
, void * ref
, OSSerialize
* s
)
974 return( ((IOFramebuffer
*)target
)->serializeInfo(s
) );
978 static IOPMrootDomain
* gIOPMRootDomain
;
980 bool IOFramebuffer::start( IOService
* provider
)
983 if( ! super::start( provider
))
986 userAccessRanges
= OSArray::withCapacity( 1 );
987 engineAccessRanges
= OSArray::withCapacity( 1 );
990 OSSerializer
* infoSerializer
= OSSerializer::forTarget( (void *) this, &serializeInfoCB
);
994 setProperty( kIOFramebufferInfoKey
, infoSerializer
);
995 infoSerializer
->release();
998 IOInterruptEventSource
* eventSrc
;
1000 eventSrc
= IOInterruptEventSource::interruptEventSource(
1001 this, autopollArrived
);
1003 kIOReturnSuccess
!= workLoop
->addEventSource(eventSrc
) ) {
1004 kprintf("Start is bailing\n");
1012 // initialize superclass power management variables
1014 // attach into the power management hierarchy
1015 provider
->joinPMtree(this);
1016 // clamp power on (the user client will change that when appropriate)
1019 if( !gIOPMRootDomain
)
1020 gIOPMRootDomain
= (IOPMrootDomain
*)
1021 IORegistryEntry::fromPath("/IOPowerConnection/IOPMrootDomain", gIOPowerPlane
);
1022 if( gIOPMRootDomain
)
1023 gIOPMRootDomain
->registerInterestedDriver(this);
1028 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1030 // Apple standard 8-bit CLUT
1032 UInt8 appleClut8
[ 256 * 3 ] = {
1034 0xFF,0xFF,0xFF, 0xFF,0xFF,0xCC, 0xFF,0xFF,0x99, 0xFF,0xFF,0x66,
1035 0xFF,0xFF,0x33, 0xFF,0xFF,0x00, 0xFF,0xCC,0xFF, 0xFF,0xCC,0xCC,
1036 0xFF,0xCC,0x99, 0xFF,0xCC,0x66, 0xFF,0xCC,0x33, 0xFF,0xCC,0x00,
1037 0xFF,0x99,0xFF, 0xFF,0x99,0xCC, 0xFF,0x99,0x99, 0xFF,0x99,0x66,
1039 0xFF,0x99,0x33, 0xFF,0x99,0x00, 0xFF,0x66,0xFF, 0xFF,0x66,0xCC,
1040 0xFF,0x66,0x99, 0xFF,0x66,0x66, 0xFF,0x66,0x33, 0xFF,0x66,0x00,
1041 0xFF,0x33,0xFF, 0xFF,0x33,0xCC, 0xFF,0x33,0x99, 0xFF,0x33,0x66,
1042 0xFF,0x33,0x33, 0xFF,0x33,0x00, 0xFF,0x00,0xFF, 0xFF,0x00,0xCC,
1044 0xFF,0x00,0x99, 0xFF,0x00,0x66, 0xFF,0x00,0x33, 0xFF,0x00,0x00,
1045 0xCC,0xFF,0xFF, 0xCC,0xFF,0xCC, 0xCC,0xFF,0x99, 0xCC,0xFF,0x66,
1046 0xCC,0xFF,0x33, 0xCC,0xFF,0x00, 0xCC,0xCC,0xFF, 0xCC,0xCC,0xCC,
1047 0xCC,0xCC,0x99, 0xCC,0xCC,0x66, 0xCC,0xCC,0x33, 0xCC,0xCC,0x00,
1049 0xCC,0x99,0xFF, 0xCC,0x99,0xCC, 0xCC,0x99,0x99, 0xCC,0x99,0x66,
1050 0xCC,0x99,0x33, 0xCC,0x99,0x00, 0xCC,0x66,0xFF, 0xCC,0x66,0xCC,
1051 0xCC,0x66,0x99, 0xCC,0x66,0x66, 0xCC,0x66,0x33, 0xCC,0x66,0x00,
1052 0xCC,0x33,0xFF, 0xCC,0x33,0xCC, 0xCC,0x33,0x99, 0xCC,0x33,0x66,
1054 0xCC,0x33,0x33, 0xCC,0x33,0x00, 0xCC,0x00,0xFF, 0xCC,0x00,0xCC,
1055 0xCC,0x00,0x99, 0xCC,0x00,0x66, 0xCC,0x00,0x33, 0xCC,0x00,0x00,
1056 0x99,0xFF,0xFF, 0x99,0xFF,0xCC, 0x99,0xFF,0x99, 0x99,0xFF,0x66,
1057 0x99,0xFF,0x33, 0x99,0xFF,0x00, 0x99,0xCC,0xFF, 0x99,0xCC,0xCC,
1059 0x99,0xCC,0x99, 0x99,0xCC,0x66, 0x99,0xCC,0x33, 0x99,0xCC,0x00,
1060 0x99,0x99,0xFF, 0x99,0x99,0xCC, 0x99,0x99,0x99, 0x99,0x99,0x66,
1061 0x99,0x99,0x33, 0x99,0x99,0x00, 0x99,0x66,0xFF, 0x99,0x66,0xCC,
1062 0x99,0x66,0x99, 0x99,0x66,0x66, 0x99,0x66,0x33, 0x99,0x66,0x00,
1064 0x99,0x33,0xFF, 0x99,0x33,0xCC, 0x99,0x33,0x99, 0x99,0x33,0x66,
1065 0x99,0x33,0x33, 0x99,0x33,0x00, 0x99,0x00,0xFF, 0x99,0x00,0xCC,
1066 0x99,0x00,0x99, 0x99,0x00,0x66, 0x99,0x00,0x33, 0x99,0x00,0x00,
1067 0x66,0xFF,0xFF, 0x66,0xFF,0xCC, 0x66,0xFF,0x99, 0x66,0xFF,0x66,
1069 0x66,0xFF,0x33, 0x66,0xFF,0x00, 0x66,0xCC,0xFF, 0x66,0xCC,0xCC,
1070 0x66,0xCC,0x99, 0x66,0xCC,0x66, 0x66,0xCC,0x33, 0x66,0xCC,0x00,
1071 0x66,0x99,0xFF, 0x66,0x99,0xCC, 0x66,0x99,0x99, 0x66,0x99,0x66,
1072 0x66,0x99,0x33, 0x66,0x99,0x00, 0x66,0x66,0xFF, 0x66,0x66,0xCC,
1074 0x66,0x66,0x99, 0x66,0x66,0x66, 0x66,0x66,0x33, 0x66,0x66,0x00,
1075 0x66,0x33,0xFF, 0x66,0x33,0xCC, 0x66,0x33,0x99, 0x66,0x33,0x66,
1076 0x66,0x33,0x33, 0x66,0x33,0x00, 0x66,0x00,0xFF, 0x66,0x00,0xCC,
1077 0x66,0x00,0x99, 0x66,0x00,0x66, 0x66,0x00,0x33, 0x66,0x00,0x00,
1079 0x33,0xFF,0xFF, 0x33,0xFF,0xCC, 0x33,0xFF,0x99, 0x33,0xFF,0x66,
1080 0x33,0xFF,0x33, 0x33,0xFF,0x00, 0x33,0xCC,0xFF, 0x33,0xCC,0xCC,
1081 0x33,0xCC,0x99, 0x33,0xCC,0x66, 0x33,0xCC,0x33, 0x33,0xCC,0x00,
1082 0x33,0x99,0xFF, 0x33,0x99,0xCC, 0x33,0x99,0x99, 0x33,0x99,0x66,
1084 0x33,0x99,0x33, 0x33,0x99,0x00, 0x33,0x66,0xFF, 0x33,0x66,0xCC,
1085 0x33,0x66,0x99, 0x33,0x66,0x66, 0x33,0x66,0x33, 0x33,0x66,0x00,
1086 0x33,0x33,0xFF, 0x33,0x33,0xCC, 0x33,0x33,0x99, 0x33,0x33,0x66,
1087 0x33,0x33,0x33, 0x33,0x33,0x00, 0x33,0x00,0xFF, 0x33,0x00,0xCC,
1089 0x33,0x00,0x99, 0x33,0x00,0x66, 0x33,0x00,0x33, 0x33,0x00,0x00,
1090 0x00,0xFF,0xFF, 0x00,0xFF,0xCC, 0x00,0xFF,0x99, 0x00,0xFF,0x66,
1091 0x00,0xFF,0x33, 0x00,0xFF,0x00, 0x00,0xCC,0xFF, 0x00,0xCC,0xCC,
1092 0x00,0xCC,0x99, 0x00,0xCC,0x66, 0x00,0xCC,0x33, 0x00,0xCC,0x00,
1094 0x00,0x99,0xFF, 0x00,0x99,0xCC, 0x00,0x99,0x99, 0x00,0x99,0x66,
1095 0x00,0x99,0x33, 0x00,0x99,0x00, 0x00,0x66,0xFF, 0x00,0x66,0xCC,
1096 0x00,0x66,0x99, 0x00,0x66,0x66, 0x00,0x66,0x33, 0x00,0x66,0x00,
1097 0x00,0x33,0xFF, 0x00,0x33,0xCC, 0x00,0x33,0x99, 0x00,0x33,0x66,
1099 0x00,0x33,0x33, 0x00,0x33,0x00, 0x00,0x00,0xFF, 0x00,0x00,0xCC,
1100 0x00,0x00,0x99, 0x00,0x00,0x66, 0x00,0x00,0x33, 0xEE,0x00,0x00,
1101 0xDD,0x00,0x00, 0xBB,0x00,0x00, 0xAA,0x00,0x00, 0x88,0x00,0x00,
1102 0x77,0x00,0x00, 0x55,0x00,0x00, 0x44,0x00,0x00, 0x22,0x00,0x00,
1104 0x11,0x00,0x00, 0x00,0xEE,0x00, 0x00,0xDD,0x00, 0x00,0xBB,0x00,
1105 0x00,0xAA,0x00, 0x00,0x88,0x00, 0x00,0x77,0x00, 0x00,0x55,0x00,
1106 0x00,0x44,0x00, 0x00,0x22,0x00, 0x00,0x11,0x00, 0x00,0x00,0xEE,
1107 0x00,0x00,0xDD, 0x00,0x00,0xBB, 0x00,0x00,0xAA, 0x00,0x00,0x88,
1109 0x00,0x00,0x77, 0x00,0x00,0x55, 0x00,0x00,0x44, 0x00,0x00,0x22,
1110 0x00,0x00,0x11, 0xEE,0xEE,0xEE, 0xDD,0xDD,0xDD, 0xBB,0xBB,0xBB,
1111 0xAA,0xAA,0xAA, 0x88,0x88,0x88, 0x77,0x77,0x77, 0x55,0x55,0x55,
1112 0x44,0x44,0x44, 0x22,0x22,0x22, 0x11,0x11,0x11, 0x00,0x00,0x00
1116 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1122 extern "C" { int kmputc( int c
); }
1124 IOReturn
IOFramebuffer::setPowerState( unsigned long powerStateOrdinal
,
1125 IOService
* whichDevice
)
1127 if( 0 == powerStateOrdinal
) {
1128 if( isConsoleDevice())
1130 deliverFramebufferNotification( kIOFBNotifyWillSleep
);
1134 if( isConsoleDevice()) {
1139 deliverFramebufferNotification( kIOFBNotifyDidWake
);
1142 return( IOPMAckImplied
);
1145 IOReturn
IOFramebuffer::beginSystemSleep( void * ackRef
)
1148 powerOverrideOnPriv();
1149 changePowerStateToPriv(0);
1151 return( kIOReturnSuccess
);
1154 IOReturn
IOFramebuffer::powerStateWillChangeTo( IOPMPowerFlags flags
,
1155 unsigned long, IOService
* whatDevice
)
1157 if( (whatDevice
== gIOPMRootDomain
) && (IOPMPowerOn
& flags
))
1159 powerOverrideOffPriv();
1161 return( IOPMAckImplied
);
1164 IOReturn
IOFramebuffer::powerStateDidChangeTo( IOPMPowerFlags flags
,
1165 unsigned long, IOService
* whatDevice
)
1167 if( (whatDevice
== this) && pmRef
&& (0 == (IOPMDeviceUsable
& flags
))) {
1169 acknowledgeSleepWakeNotification(pmRef
);
1173 return( IOPMAckImplied
);
1176 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1178 IODeviceMemory
* IOFramebuffer::getVRAMRange( void )
1180 return( getApertureRange( kIOFBSystemAperture
));
1183 void IOFramebuffer::close( void ) // called by the user client when
1184 { // the window server exits
1190 IOReturn
IOFramebuffer::open( void )
1192 IOReturn err
= kIOReturnSuccess
;
1199 // tell the console if it's on this display, it's going away
1200 if( isConsoleDevice())
1201 getPlatform()->setConsoleInfo( 0, kPEDisableScreen
);
1203 deliverFramebufferNotification( kIOFBNotifyDisplayModeWillChange
);
1205 err
= enableController();
1206 if( kIOReturnSuccess
!= err
) {
1207 deliverFramebufferNotification( kIOFBNotifyDisplayModeDidChange
);
1210 err
= registerForInterruptType( kIOFBVBLInterruptType
,
1211 (IOFBInterruptProc
) &handleVBL
,
1212 this, priv
, &vblInterrupt
);
1213 haveVBLService
= (err
== kIOReturnSuccess
);
1215 err
= getAttribute( kIOHardwareCursorAttribute
, &value
);
1216 haveHWCursor
= ((err
== kIOReturnSuccess
) && value
);
1218 err
= kIOReturnSuccess
;
1226 IOReturn
IOFramebuffer::setUserRanges( void )
1228 #if 1 /* print ranges */
1230 UInt32 i
, numRanges
;
1231 IODeviceMemory
* mem
;
1233 numRanges
= userAccessRanges
->getCount();
1234 IOLog("%s: user ranges num:%ld", getName(), numRanges
);
1235 for( i
= 0; i
< numRanges
; i
++) {
1236 mem
= (IODeviceMemory
*) userAccessRanges
->getObject( i
);
1239 IOLog(" start:%lx size:%lx",
1240 mem
->getPhysicalAddress(), mem
->getLength() );
1245 return( kIOReturnSuccess
);
1248 IOReturn
IOFramebuffer::setupForCurrentConfig( void )
1250 return( doSetup( true ));
1253 IOReturn
IOFramebuffer::doSetup( bool full
)
1256 IODisplayModeID mode
;
1258 IOPixelInformation info
;
1259 IODisplayModeInformation dmInfo
;
1260 IODeviceMemory
* mem
;
1261 IODeviceMemory
* fbRange
;
1262 IOPhysicalAddress base
;
1263 PE_Video newConsole
;
1265 err
= getCurrentDisplayMode( &mode
, &depth
);
1267 IOLog("%s: getCurrentDisplayMode %d\n", getName(), err
);
1269 err
= getPixelInformation( mode
, depth
, kIOFBSystemAperture
, &info
);
1271 IOLog("%s: getPixelInformation %d\n", getName(), err
);
1273 if( full
&& (clutValid
== false) && (info
.pixelType
== kIOCLUTPixels
)) {
1275 IOColorEntry
* tempTable
;
1278 tempTable
= (IOColorEntry
*) IOMalloc( 256 * sizeof( *tempTable
));
1281 for( i
= 0; i
< 256; i
++) {
1286 tempTable
[ i
].red
= lum
;
1287 tempTable
[ i
].green
= lum
;
1288 tempTable
[ i
].blue
= lum
;
1290 tempTable
[ i
].red
= (appleClut8
[ i
* 3 + 0 ] << 8)
1291 | appleClut8
[ i
* 3 + 0 ];
1292 tempTable
[ i
].green
= (appleClut8
[ i
* 3 + 1 ] << 8)
1293 | appleClut8
[ i
* 3 + 1 ];
1294 tempTable
[ i
].blue
= (appleClut8
[ i
* 3 + 2 ] << 8)
1295 | appleClut8
[ i
* 3 + 2 ];
1298 setCLUTWithEntries( tempTable
, 0, 256, 1 * kSetCLUTImmediately
);
1299 IOFree( tempTable
, 256 * sizeof( *tempTable
));
1304 fbRange
= getApertureRange( kIOFBSystemAperture
);
1306 if( full
&& fbRange
) {
1308 userAccessRanges
->removeObject( kIOFBSystemAperture
);
1309 userAccessRanges
->setObject( kIOFBSystemAperture
, fbRange
);
1310 err
= setUserRanges();
1312 base
= fbRange
->getPhysicalAddress();
1313 if( (mem
= getVRAMRange())) {
1314 vramMapOffset
= base
- mem
->getPhysicalAddress();
1320 vramMap
= fbRange
->map();
1323 base
= vramMap
->getVirtualAddress();
1325 // console now available
1326 if( info
.activeWidth
>= 128) {
1327 newConsole
.v_baseAddr
= base
;
1328 newConsole
.v_rowBytes
= info
.bytesPerRow
;
1329 newConsole
.v_width
= info
.activeWidth
;
1330 newConsole
.v_height
= info
.activeHeight
;
1331 newConsole
.v_depth
= info
.bitsPerPixel
;
1332 // strcpy( consoleInfo->v_pixelFormat, "PPPPPPPP");
1333 getPlatform()->setConsoleInfo( &newConsole
, kPEEnableScreen
);
1336 deliverFramebufferNotification( kIOFBNotifyDisplayModeDidChange
, 0 );
1338 (void) getInformationForDisplayMode( mode
, &dmInfo
);
1339 IOLog( "%s: using (%ldx%ld@%ldHz,%ld bpp)\n", getName(),
1340 info
.activeWidth
, info
.activeHeight
,
1341 (dmInfo
.refreshRate
+ 0x8000) >> 16, info
.bitsPerPixel
);
1347 setupCursor( &info
);
1349 return( kIOReturnSuccess
);
1352 IOReturn
IOFramebuffer::extSetDisplayMode( IODisplayModeID displayMode
,
1359 if( isConsoleDevice())
1360 getPlatform()->setConsoleInfo( 0, kPEDisableScreen
);
1362 deliverFramebufferNotification( kIOFBNotifyDisplayModeWillChange
);
1364 err
= setDisplayMode( displayMode
, depth
);
1368 setupForCurrentConfig();
1373 IOReturn
IOFramebuffer::extGetInformationForDisplayMode(
1374 IODisplayModeID mode
, IODisplayModeInformation
* info
)
1378 IOTimingInformation timingInfo
;
1380 err
= getInformationForDisplayMode( mode
, info
);
1381 if( kIOReturnSuccess
== err
) {
1382 err
= IODisplayWrangler::getFlagsForDisplayMode( this, mode
, &flags
);
1383 if( kIOReturnSuccess
== err
) {
1384 info
->flags
&= ~kDisplayModeSafetyFlags
;
1385 info
->flags
|= flags
;
1387 if( kIOReturnSuccess
== getTimingInfoForDisplayMode( mode
, &timingInfo
))
1388 info
->reserved
[0] = timingInfo
.appleTimingID
;
1395 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1397 bool IOFramebuffer::setNumber( OSDictionary
* dict
, const char * key
,
1403 num
= OSNumber::withNumber( value
, 32 );
1407 ok
= dict
->setObject( key
, num
);
1413 bool IOFramebuffer::serializeInfo( OSSerialize
* s
)
1416 IODisplayModeInformation info
;
1417 IOPixelInformation pixelInfo
;
1418 IODisplayModeID
* modeIDs
;
1419 IOItemCount modeCount
, modeNum
, aperture
;
1421 OSDictionary
* infoDict
;
1422 OSDictionary
* modeDict
;
1423 OSDictionary
* pixelDict
;
1427 modeCount
= getDisplayModeCount();
1428 modeIDs
= IONew( IODisplayModeID
, modeCount
);
1432 err
= getDisplayModes( modeIDs
);
1436 infoDict
= OSDictionary::withCapacity( 10 );
1440 for( modeNum
= 0; modeNum
< modeCount
; modeNum
++ ) {
1442 err
= getInformationForDisplayMode( modeIDs
[ modeNum
], &info
);
1446 modeDict
= OSDictionary::withCapacity( 10 );
1450 ok
= setNumber( modeDict
, kIOFBWidthKey
,
1452 && setNumber( modeDict
, kIOFBHeightKey
,
1453 info
.nominalHeight
)
1454 && setNumber( modeDict
, kIOFBRefreshRateKey
,
1456 && setNumber( modeDict
, kIOFBFlagsKey
,
1461 for( depthNum
= 0; depthNum
< info
.maxDepthIndex
; depthNum
++ ) {
1463 for( aperture
= 0; ; aperture
++ ) {
1465 err
= getPixelInformation( modeIDs
[ modeNum
], depthNum
,
1466 aperture
, &pixelInfo
);
1470 pixelDict
= OSDictionary::withCapacity( 10 );
1474 ok
= setNumber( pixelDict
, kIOFBBytesPerRowKey
,
1475 pixelInfo
.bytesPerRow
)
1476 && setNumber( pixelDict
, kIOFBBytesPerPlaneKey
,
1477 pixelInfo
.bytesPerPlane
)
1478 && setNumber( pixelDict
, kIOFBBitsPerPixelKey
,
1479 pixelInfo
.bitsPerPixel
)
1480 && setNumber( pixelDict
, kIOFBComponentCountKey
,
1481 pixelInfo
.componentCount
)
1482 && setNumber( pixelDict
, kIOFBBitsPerComponentKey
,
1483 pixelInfo
.bitsPerComponent
)
1484 && setNumber( pixelDict
, kIOFBFlagsKey
,
1486 && setNumber( pixelDict
, kIOFBWidthKey
,
1487 pixelInfo
.activeWidth
)
1488 && setNumber( pixelDict
, kIOFBHeightKey
,
1489 pixelInfo
.activeHeight
);
1493 sprintf( keyBuf
, "%lx", depthNum
+ (aperture
<< 16) );
1494 modeDict
->setObject( keyBuf
, pixelDict
);
1495 pixelDict
->release();
1499 sprintf( keyBuf
, "%lx", modeIDs
[ modeNum
] );
1500 infoDict
->setObject( keyBuf
, modeDict
);
1501 modeDict
->release();
1504 IODelete( modeIDs
, IODisplayModeID
, modeCount
);
1506 ok
&= infoDict
->serialize( s
);
1507 infoDict
->release();
1512 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1514 OSDefineMetaClassAndStructors(_IOFramebufferNotifier
, IONotifier
)
1515 #define LOCKNOTIFY()
1516 #define UNLOCKNOTIFY()
1518 void _IOFramebufferNotifier::remove()
1523 whence
->removeObject( (OSObject
*) this );
1534 bool _IOFramebufferNotifier::disable()
1546 void _IOFramebufferNotifier::enable( bool was
)
1553 IONotifier
* IOFramebuffer::addFramebufferNotification(
1554 IOFramebufferNotificationHandler handler
,
1555 OSObject
* self
, void * ref
)
1557 _IOFramebufferNotifier
* notify
= 0;
1559 notify
= new _IOFramebufferNotifier
;
1560 if( notify
&& !notify
->init()) {
1566 notify
->handler
= handler
;
1567 notify
->self
= self
;
1569 notify
->fEnable
= true;
1571 if( 0 == fbNotifications
)
1572 fbNotifications
= OSSet::withCapacity(1);
1574 notify
->whence
= fbNotifications
;
1575 if( fbNotifications
)
1576 fbNotifications
->setObject( notify
);
1582 IOReturn
IOFramebuffer::deliverFramebufferNotification(
1583 IOIndex event
, void * info
= 0 )
1586 _IOFramebufferNotifier
* notify
;
1587 IOReturn ret
= kIOReturnSuccess
;
1592 iter
= OSCollectionIterator::withCollection( fbNotifications
);
1595 while( (notify
= (_IOFramebufferNotifier
*) iter
->getNextObject())) {
1597 if( notify
->fEnable
) {
1598 r
= (*notify
->handler
)( notify
->self
, notify
->ref
, this,
1600 if( kIOReturnSuccess
!= ret
)
1612 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1616 IOReturn
IOFramebuffer::enableController ( void )
1618 return( kIOReturnSuccess
);
1621 bool IOFramebuffer::isConsoleDevice( void )
1626 // Set display mode and depth
1627 IOReturn
IOFramebuffer::setDisplayMode( IODisplayModeID
/* displayMode */,
1628 IOIndex
/* depth */ )
1630 return( kIOReturnUnsupported
);
1634 IOReturn
IOFramebuffer::setApertureEnable(
1635 IOPixelAperture
/* aperture */, IOOptionBits
/* enable */ )
1637 return( kIOReturnUnsupported
);
1640 // Display mode and depth for startup
1641 IOReturn
IOFramebuffer::setStartupDisplayMode(
1642 IODisplayModeID
/* displayMode */, IOIndex
/* depth */ )
1644 return( kIOReturnUnsupported
);
1647 IOReturn
IOFramebuffer::getStartupDisplayMode(
1648 IODisplayModeID
* /* displayMode */, IOIndex
* /* depth */ )
1650 return( kIOReturnUnsupported
);
1655 IOReturn
IOFramebuffer::setCLUTWithEntries(
1656 IOColorEntry
* /* colors */, UInt32
/* index */,
1657 UInt32
/* numEntries */, IOOptionBits
/* options */ )
1659 return( kIOReturnUnsupported
);
1664 IOReturn
IOFramebuffer::setGammaTable( UInt32
/* channelCount */,
1665 UInt32
/* dataCount */, UInt32
/* dataWidth */, void * /* data */ )
1667 return( kIOReturnUnsupported
);
1670 //// Controller attributes
1672 IOReturn
IOFramebuffer::setAttribute( IOSelect
/* attribute */, UInt32
/* value */ )
1674 return( kIOReturnUnsupported
);
1677 IOReturn
IOFramebuffer::getAttribute( IOSelect
/* attribute */,
1678 UInt32
* /* value */ )
1680 return( kIOReturnUnsupported
);
1683 //// Display mode timing information
1685 IOReturn
IOFramebuffer::getTimingInfoForDisplayMode(
1686 IODisplayModeID
/* displayMode */,
1687 IOTimingInformation
* /* info */ )
1689 return( kIOReturnUnsupported
);
1692 IOReturn
IOFramebuffer::validateDetailedTiming(
1693 void * description
, IOByteCount descripSize
)
1695 return( kIOReturnUnsupported
);
1698 IOReturn
IOFramebuffer::setDetailedTimings( OSArray
* array
)
1700 return( kIOReturnUnsupported
);
1705 IOItemCount
IOFramebuffer::getConnectionCount( void )
1710 IOReturn
IOFramebuffer::setAttributeForConnection( IOIndex
/* connectIndex */,
1711 IOSelect
/* attribute */, UInt32
/* value */ )
1713 return( kIOReturnUnsupported
);
1716 IOReturn
IOFramebuffer::getAttributeForConnection( IOIndex
/* connectIndex */,
1717 IOSelect
/* attribute */, UInt32
* /* value */ )
1719 return( kIOReturnUnsupported
);
1724 IOReturn
IOFramebuffer::setCursorImage( void * cursorImage
)
1726 return( kIOReturnUnsupported
);
1729 IOReturn
IOFramebuffer::setCursorState( SInt32 x
, SInt32 y
, bool visible
)
1731 return( kIOReturnUnsupported
);
1734 void IOFramebuffer::flushCursor( void )
1740 IOReturn
IOFramebuffer::registerForInterruptType( IOSelect interruptType
,
1741 IOFBInterruptProc proc
, OSObject
* target
, void * ref
,
1742 void ** interruptRef
)
1744 return( kIOReturnUnsupported
);
1747 IOReturn
IOFramebuffer::unregisterInterrupt( void * interruptRef
)
1749 return( kIOReturnUnsupported
);
1752 IOReturn
IOFramebuffer::setInterruptState( void * interruptRef
, UInt32 state
)
1754 return( kIOReturnUnsupported
);
1759 IOReturn
IOFramebuffer::getAppleSense(
1760 IOIndex
/* connectIndex */,
1761 UInt32
* /* senseType */,
1762 UInt32
* /* primary */,
1763 UInt32
* /* extended */,
1764 UInt32
* /* displayType */ )
1766 return( kIOReturnUnsupported
);
1769 IOReturn
IOFramebuffer::connectFlags( IOIndex
/* connectIndex */,
1770 IODisplayModeID
/* displayMode */, IOOptionBits
* /* flags */ )
1772 return( kIOReturnUnsupported
);
1775 //// IOLowLevelDDCSense
1777 void IOFramebuffer::setDDCClock( IOIndex
/* connectIndex */, UInt32
/* value */ )
1781 void IOFramebuffer::setDDCData( IOIndex
/* connectIndex */, UInt32
/* value */ )
1785 bool IOFramebuffer::readDDCClock( IOIndex
/* connectIndex */ )
1790 bool IOFramebuffer::readDDCData( IOIndex
/* connectIndex */ )
1795 IOReturn
IOFramebuffer::enableDDCRaster( bool /* enable */ )
1797 return( kIOReturnUnsupported
);
1801 //// IOHighLevelDDCSense
1803 bool IOFramebuffer::hasDDCConnect( IOIndex
/* connectIndex */ )
1805 return( kIOReturnUnsupported
);
1808 IOReturn
IOFramebuffer::getDDCBlock( IOIndex
/* connectIndex */, UInt32
/* blockNumber */,
1809 IOSelect
/* blockType */, IOOptionBits
/* options */,
1810 UInt8
* /* data */, IOByteCount
* /* length */ )
1812 return( kIOReturnUnsupported
);
1815 OSMetaClassDefineReservedUnused(IOFramebuffer
, 0);
1816 OSMetaClassDefineReservedUnused(IOFramebuffer
, 1);
1817 OSMetaClassDefineReservedUnused(IOFramebuffer
, 2);
1818 OSMetaClassDefineReservedUnused(IOFramebuffer
, 3);
1819 OSMetaClassDefineReservedUnused(IOFramebuffer
, 4);
1820 OSMetaClassDefineReservedUnused(IOFramebuffer
, 5);
1821 OSMetaClassDefineReservedUnused(IOFramebuffer
, 6);
1822 OSMetaClassDefineReservedUnused(IOFramebuffer
, 7);
1823 OSMetaClassDefineReservedUnused(IOFramebuffer
, 8);
1824 OSMetaClassDefineReservedUnused(IOFramebuffer
, 9);
1825 OSMetaClassDefineReservedUnused(IOFramebuffer
, 10);
1826 OSMetaClassDefineReservedUnused(IOFramebuffer
, 11);
1827 OSMetaClassDefineReservedUnused(IOFramebuffer
, 12);
1828 OSMetaClassDefineReservedUnused(IOFramebuffer
, 13);
1829 OSMetaClassDefineReservedUnused(IOFramebuffer
, 14);
1830 OSMetaClassDefineReservedUnused(IOFramebuffer
, 15);
1831 OSMetaClassDefineReservedUnused(IOFramebuffer
, 16);
1832 OSMetaClassDefineReservedUnused(IOFramebuffer
, 17);
1833 OSMetaClassDefineReservedUnused(IOFramebuffer
, 18);
1834 OSMetaClassDefineReservedUnused(IOFramebuffer
, 19);
1835 OSMetaClassDefineReservedUnused(IOFramebuffer
, 20);
1836 OSMetaClassDefineReservedUnused(IOFramebuffer
, 21);
1837 OSMetaClassDefineReservedUnused(IOFramebuffer
, 22);
1838 OSMetaClassDefineReservedUnused(IOFramebuffer
, 23);
1839 OSMetaClassDefineReservedUnused(IOFramebuffer
, 24);
1840 OSMetaClassDefineReservedUnused(IOFramebuffer
, 25);
1841 OSMetaClassDefineReservedUnused(IOFramebuffer
, 26);
1842 OSMetaClassDefineReservedUnused(IOFramebuffer
, 27);
1843 OSMetaClassDefineReservedUnused(IOFramebuffer
, 28);
1844 OSMetaClassDefineReservedUnused(IOFramebuffer
, 29);
1845 OSMetaClassDefineReservedUnused(IOFramebuffer
, 30);
1846 OSMetaClassDefineReservedUnused(IOFramebuffer
, 31);