1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1997-1998 Apple Computer, Inc.
24 *
25 *
26 * HISTORY
27 *
28 * sdouglas  22 Oct 97 - first checked in.
29 * sdouglas  24 Jul 98 - start IOKit.
30 * sdouglas  15 Dec 98 - cpp.
31 *
32 */
33
34#ifndef _IOKIT_IONDRVFRAMEBUFFER_H
35#define _IOKIT_IONDRVFRAMEBUFFER_H
36
37#include <IOKit/graphics/IOFramebuffer.h>
38#include <IOKit/ndrvsupport/IOMacOSVideo.h>
39#include <IOKit/ndrvsupport/IONDRVSupport.h>
40
41#define kIONDRVDisableKey       "AAPL,disable-ndrv"
42
43class IONDRVFramebuffer : public IOFramebuffer
44{
45    OSDeclareDefaultStructors(IONDRVFramebuffer)
46
47protected:
48/*    Reserved for future use.  (Internal use only)  */
49    struct ExpansionData { };
50    ExpansionData * reserved;
51
52protected:
53
54    IOService *                 nub;
55    class IONDRV *              ndrv;
56
57    // current configuration
58    IODisplayModeID             currentDisplayMode;
59    IOIndex                     currentDepth;
60    IOIndex                     currentPage;
61    UInt8                       __reservedE;
62
63    IOPhysicalAddress           __resv_was_physicalFramebuffer;
64    IOMemoryDescriptor *        vramRange;
65
66    UInt8                       gammaWidth;
67    UInt8                       __reservedD;
68    UInt8                       lastGrayMode;
69    VDClutBehavior              lastClutSetting;
70    UInt8                       __reservedC;
71
72    bool                        consoleDevice;
73    UInt32                      powerState;
74    UInt32                      ndrvState;
75    SInt32                      ndrvEnter;
76    OSArray *                   detailedTimings;
77    UInt32                      detailedTimingsSeed;
78    UInt32 *                    detailedTimingsCurrent;
79
80    IODeviceMemory *            vramMemory;
81
82    VDResolutionInfoRec         cachedVDResolution;
83
84    struct _VSLService *        vslServices;
85
86    UInt32                      accessFlags;
87    unsigned int                shouldDoI2CPower:1;
88    unsigned int                online:1;
89    unsigned int                avJackState:1;
90    unsigned int                grayMode:1;
91    unsigned int                platformSleep:1;
92    unsigned int                forceReadEDID:1;
93    unsigned int                supportsProbe:1;
94    unsigned int                __reservedB:25;
95
96    IOService *                 device;
97
98    UInt32                      __reservedA[29];
99
100private:
101    struct IONDRVFramebufferPrivate * __private;
102
103public:
104    virtual IOReturn doDriverIO( UInt32 commandID, void * contents,
105                                 UInt32 commandCode, UInt32 commandKind );
106private:
107    OSMetaClassDeclareReservedUsed(IONDRVFramebuffer, 0);
108
109    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 1);
110    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 2);
111    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 3);
112    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 4);
113    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 5);
114    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 6);
115    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 7);
116    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 8);
117    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 9);
118    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 10);
119    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 11);
120    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 12);
121    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 13);
122    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 14);
123    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 15);
124    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 16);
125    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 17);
126    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 18);
127    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 19);
128    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 20);
129    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 21);
130    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 22);
131    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 23);
132    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 24);
133    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 25);
134    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 26);
135    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 27);
136    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 28);
137    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 29);
138    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 30);
139    OSMetaClassDeclareReservedUnused(IONDRVFramebuffer, 31);
140
141private:
142
143    void initForPM ( void );
144
145    virtual unsigned long maxCapabilityForDomainState( IOPMPowerFlags domainState );
146    virtual unsigned long initialPowerStateForDomainState( IOPMPowerFlags domainState );
147    virtual unsigned long powerStateForDomainState( IOPMPowerFlags domainState );
148
149    virtual IOReturn checkDriver( void );
150    virtual UInt32 iterateAllModes( IODisplayModeID * displayModeIDs );
151    virtual IOReturn getResInfoForMode( IODisplayModeID modeID,
152                                    IODisplayModeInformation * theInfo );
153    virtual IOReturn getResInfoForArbMode( IODisplayModeID modeID,
154                                    IODisplayModeInformation * theInfo );
155    IOReturn getResInfoForDetailed( IODisplayModeID modeID,
156                                    VDDetailedTimingRec * detailed,
157                                    IODisplayModeInformation * info );
158    IOIndex mapDepthIndex( IODisplayModeID modeID, IOIndex depth, bool fromDepthMode );
159    virtual IOReturn validateDisplayMode(
160            IODisplayModeID mode, IOOptionBits flags,
161            VDDetailedTimingRec ** detailed );
162    virtual IOReturn setDetailedTiming(
163            IODisplayModeID mode, IOOptionBits options,
164            void * description, IOByteCount descripSize );
165    virtual void getCurrentConfiguration( void );
166    static const IOTVector * _undefinedSymbolHandler( void * self,
167                            const char * libraryName, const char * symbolName );
168    static bool _videoJackStateChangeHandler( void * target, void * ref,
169                            IOService * newService, IONotifier * notifier );
170    static void _avProbeAction( OSObject * p0, IOTimerEventSource * evtSrc );
171    void displayI2CPower( bool enable );
172    IOReturn ndrvSetPowerState( UInt32 newState );
173    IOReturn ndrvUpdatePowerState( void );
174    IOReturn ndrvSetDisplayPowerState( UInt32 newState );
175    static IOReturn _probeAction( IONDRVFramebuffer * self, IOOptionBits options );
176    bool searchOfflineMode( IODisplayModeID * offlineMode );
177    IOReturn processConnectChange( uintptr_t * value );
178    IOReturn setMirror( IONDRVFramebuffer * other );
179    IOReturn setConnectionFlags( void );
180    bool getOnlineState( void );
181    IOReturn ndrvGetSetFeature( UInt32 feature, uintptr_t newValue, uintptr_t * currentValue );
182    static IOReturn _doControl( IONDRVFramebuffer * self, UInt32 code, void * params );
183    static IOReturn _doStatus( IONDRVFramebuffer * self, UInt32 code, void * params );
184    static IOReturn extControl( OSObject * owner, void * code, void * params );
185    static IOReturn extStatus( OSObject * owner, void * code, void * params );
186    IOReturn createI2C( void );
187    void setInfoProperties( void );
188
189public:
190    virtual IOReturn doControl( UInt32 code, void * params );
191    virtual IOReturn doStatus( UInt32 code, void * params );
192
193public:
194
195    virtual IOService * probe(  IOService *     provider,
196                                SInt32 *        score );
197
198    virtual bool start( IOService * provider );
199
200    virtual void stop( IOService * provider );
201
202    virtual void free( void );
203
204    virtual IOReturn setProperties( OSObject * properties );
205
206    virtual IOReturn requestProbe( IOOptionBits options );
207
208    virtual IOReturn enableController( void );
209
210    virtual IODeviceMemory * makeSubRange( IOPhysicalAddress64 start,
211                                           IOPhysicalLength64  length );
212    virtual IODeviceMemory * getApertureRange( IOPixelAperture aperture );
213    virtual IODeviceMemory * getVRAMRange( void );
214
215    virtual IODeviceMemory * findVRAM( void );
216
217    virtual bool isConsoleDevice( void );
218
219    virtual const IOTVector * undefinedSymbolHandler( const char * libraryName,
220                                                      const char * symbolName );
221
222    virtual const char * getPixelFormats( void );
223
224    // Array of supported display modes
225    virtual IOItemCount getDisplayModeCount( void );
226    virtual IOReturn getDisplayModes( IODisplayModeID * allDisplayModes );
227
228    // Info about a display mode
229    virtual IOReturn getInformationForDisplayMode( IODisplayModeID displayMode,
230                    IODisplayModeInformation * info );
231
232    // Mask of pixel formats available in mode and depth
233    virtual UInt64  getPixelFormatsForDisplayMode( IODisplayModeID displayMode,
234                    IOIndex depth );
235
236    virtual IOReturn getPixelInformation(
237        IODisplayModeID displayMode, IOIndex depth,
238        IOPixelAperture aperture, IOPixelInformation * pixelInfo );
239
240    // Framebuffer info
241
242    virtual IOReturn setupForCurrentConfig( void );
243
244    // Current display mode and depth
245    virtual IOReturn getCurrentDisplayMode( IODisplayModeID * displayMode,
246                            IOIndex * depth );
247
248    // Set display mode and depth
249    virtual IOReturn setDisplayMode( IODisplayModeID displayMode,
250                            IOIndex depth );
251
252    // For pages
253    virtual IOReturn setApertureEnable( IOPixelAperture aperture,
254                    IOOptionBits enable );
255
256    virtual IOReturn setStartupDisplayMode( IODisplayModeID displayMode,
257                            IOIndex depth );
258    virtual IOReturn getStartupDisplayMode( IODisplayModeID * displayMode,
259                            IOIndex * depth );
260
261    //// CLUTs
262
263    virtual IOReturn setCLUTWithEntries( IOColorEntry * colors, UInt32 index,
264                UInt32 numEntries, IOOptionBits options );
265
266    //// Gamma
267
268    virtual IOReturn setGammaTable( UInt32 channelCount, UInt32 dataCount,
269                    UInt32 dataWidth, void * data );
270
271    //// Display mode timing information
272
273    virtual IOReturn getTimingInfoForDisplayMode( IODisplayModeID displayMode,
274                IOTimingInformation * info );
275
276    //// Detailed timing information
277
278    virtual IOReturn validateDetailedTiming(
279                    void * description, IOByteCount descripSize );
280
281    virtual IOReturn setDetailedTimings( OSArray * array );
282
283    //// Controller attributes
284
285    virtual IOReturn setAttribute( IOSelect attribute, uintptr_t value );
286    virtual IOReturn getAttribute( IOSelect attribute, uintptr_t * value );
287
288    //// Connections
289
290    virtual IOItemCount getConnectionCount( void );
291
292    virtual IOReturn getAttributeForConnection( IOIndex connectIndex,
293                    IOSelect attribute, uintptr_t  * value );
294
295    virtual IOReturn setAttributeForConnection( IOIndex connectIndex,
296                    IOSelect attribute, uintptr_t  info );
297
298    // Apple sensing
299
300    virtual IOReturn getAppleSense( IOIndex connectIndex,
301            UInt32 * senseType,
302            UInt32 * primary,
303            UInt32 * extended,
304            UInt32 * displayType );
305
306    virtual IOReturn connectFlags( IOIndex connectIndex,
307                    IODisplayModeID displayMode, IOOptionBits * flags );
308
309    //// IOHighLevelDDCSense
310
311    virtual bool hasDDCConnect( IOIndex connectIndex );
312    virtual IOReturn getDDCBlock( IOIndex connectIndex, UInt32 blockNumber,
313                    IOSelect blockType, IOOptionBits options,
314                    UInt8 * data, IOByteCount * length );
315
316    //// Interrupts
317
318    virtual IOReturn registerForInterruptType( IOSelect interruptType,
319                        IOFBInterruptProc proc, OSObject * target, void * ref,
320                        void ** interruptRef );
321    virtual IOReturn unregisterInterrupt( void * interruptRef );
322    virtual IOReturn setInterruptState( void * interruptRef, UInt32 state );
323
324    //// HW Cursors
325
326    virtual IOReturn setCursorImage( void * cursorImage );
327    virtual IOReturn setCursorState( SInt32 x, SInt32 y, bool visible );
328
329    //// I2C calls
330
331    virtual IOReturn doI2CRequest( UInt32 bus, IOI2CBusTiming * timing, IOI2CRequest * request );
332
333    //// VSL calls
334
335    static OSStatus VSLNewInterruptService(
336                            void * entryID,
337                            UInt32 serviceType,
338                            _VSLService ** serviceID );
339    static OSStatus VSLDisposeInterruptService( _VSLService * serviceID );
340    static OSStatus VSLDoInterruptService( _VSLService * serviceID );
341    static Boolean  VSLPrepareCursorForHardwareCursor(
342                            void * cursorRef,
343                            IOHardwareCursorDescriptor * hwDesc,
344                            IOHardwareCursorInfo * hwCursorInfo );
345};
346
347#endif /* ! _IOKIT_IONDRVFRAMEBUFFER_H */
348
349
350