1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Copyright (c) 1998 Apple Computer, Inc.  All rights reserved.
30 *
31 * HISTORY
32 *
33 */
34
35
36#ifndef _IOKIT_IOPLATFORMEXPERT_H
37#define _IOKIT_IOPLATFORMEXPERT_H
38
39#ifdef __cplusplus
40#include <IOKit/IOLib.h>
41#include <IOKit/IOService.h>
42#include <IOKit/IOInterrupts.h>
43#include <IOKit/IOInterruptController.h>
44
45extern "C" {
46#endif
47
48#include <libkern/OSTypes.h>
49
50extern boolean_t PEGetMachineName( char * name, int maxLength );
51extern boolean_t PEGetModelName( char * name, int maxLength );
52extern int PEGetPlatformEpoch( void );
53
54enum {
55  kPEHaltCPU,
56  kPERestartCPU,
57  kPEHangCPU,
58  kPEUPSDelayHaltCPU,
59  kPEPanicRestartCPU,
60  kPEPanicSync,
61  kPEPagingOff
62};
63extern int (*PE_halt_restart)(unsigned int type);
64extern int PEHaltRestart(unsigned int type);
65
66// Save the Panic Info.  Returns the number of bytes saved.
67extern UInt32 PESavePanicInfo(UInt8 *buffer, UInt32 length);
68
69extern long PEGetGMTTimeOfDay( void );
70extern void PESetGMTTimeOfDay( long secs );
71extern void PEGetUTCTimeOfDay( clock_sec_t * secs, clock_usec_t * usecs );
72extern void PESetUTCTimeOfDay( clock_sec_t secs, clock_usec_t usecs );
73
74/* unless it's a "well-known" property, these will read/write out the value as raw data */
75
76extern boolean_t PEWriteNVRAMProperty(const char *symbol, const void *value, const unsigned int len);
77
78extern boolean_t PEReadNVRAMProperty(const char *symbol, void *value, unsigned int *len);
79
80extern boolean_t PERemoveNVRAMProperty(const char *symbol);
81
82#ifdef __cplusplus
83} /* extern "C" */
84
85#define kIOPlatformMapperPresentKey "IOPlatformMapperPresent"
86
87
88extern OSSymbol *               gPlatformInterruptControllerName;
89
90extern const OSSymbol *		gIOPlatformSleepActionKey;
91extern const OSSymbol *		gIOPlatformWakeActionKey;
92extern const OSSymbol *		gIOPlatformQuiesceActionKey;
93extern const OSSymbol *		gIOPlatformActiveActionKey;
94extern const OSSymbol *		gIOPlatformHaltRestartActionKey;
95
96class IORangeAllocator;
97class IONVRAMController;
98class IOPMrootDomain;
99
100class IOPlatformExpert : public IOService
101{
102    OSDeclareDefaultStructors(IOPlatformExpert);
103
104private:
105    long _peBootROMType;
106    long _peChipSetType;
107    long _peMachineType;
108
109protected:
110    IOPMrootDomain * root;
111    int _pePMFeatures;
112    int _pePrivPMFeatures;
113    int _peNumBatteriesSupported;
114    OSArray  * thePowerTree;
115
116    bool       searchingForAdditionalParents;
117    OSNumber * multipleParentKeyValue;
118    int        numInstancesRegistered;
119
120    struct ExpansionData { };
121    ExpansionData *reserved;
122
123    virtual void setBootROMType(long peBootROMType);
124    virtual void setChipSetType(long peChipSetType);
125    virtual void setMachineType(long peMachineType);
126
127    virtual bool CheckSubTree (OSArray * inSubTree, IOService * theNub, IOService * theDevice, OSDictionary * theParent);
128    virtual bool RegisterServiceInTree (IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider);
129
130    virtual void PMInstantiatePowerDomains ( void );
131
132public:
133    virtual bool attach( IOService * provider );
134    virtual bool start( IOService * provider );
135    virtual bool configure( IOService * provider );
136    virtual IOService * createNub( OSDictionary * from );
137
138    virtual bool compareNubName( const IOService * nub, OSString * name,
139				 OSString ** matched = 0 ) const;
140    virtual IOReturn getNubResources( IOService * nub );
141
142    virtual long getBootROMType(void);
143    virtual long getChipSetType(void);
144    virtual long getMachineType(void);
145
146    virtual bool getModelName( char * name, int maxLength );
147    virtual bool getMachineName( char * name, int maxLength );
148
149    virtual int haltRestart(unsigned int type);
150    virtual void sleepKernel(void);
151
152    virtual long getGMTTimeOfDay( void );
153    virtual void setGMTTimeOfDay( long secs );
154
155    virtual IOReturn getConsoleInfo( PE_Video * consoleInfo );
156    virtual IOReturn setConsoleInfo( PE_Video * consoleInfo, unsigned int op );
157
158    virtual void registerNVRAMController( IONVRAMController * nvram );
159
160    virtual IOReturn registerInterruptController(OSSymbol *name, IOInterruptController *interruptController);
161    virtual IOInterruptController *lookUpInterruptController(OSSymbol *name);
162    virtual void setCPUInterruptProperties(IOService *service);
163    virtual bool atInterruptLevel(void);
164
165    virtual IOReturn callPlatformFunction(const OSSymbol *functionName,
166					  bool waitForFunction,
167					  void *param1, void *param2,
168					  void *param3, void *param4);
169
170    virtual IORangeAllocator * getPhysicalRangeAllocator(void);
171
172    virtual bool platformAdjustService(IOService *service);
173
174    virtual void PMRegisterDevice(IOService * theNub, IOService * theDevice);
175    virtual void PMLog ( const char *,unsigned long, unsigned long, unsigned long );
176
177    virtual bool hasPMFeature (unsigned long featureMask);
178    virtual bool hasPrivPMFeature (unsigned long privFeatureMask);
179    virtual int  numBatteriesSupported (void);
180
181    virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
182
183    virtual OSString* createSystemSerialNumberString(OSData* myProperty);
184
185    virtual IOReturn deregisterInterruptController(OSSymbol *name);
186
187    virtual void getUTCTimeOfDay( clock_sec_t * secs, clock_nsec_t * nsecs );
188    virtual void setUTCTimeOfDay( clock_sec_t secs, clock_nsec_t nsecs );
189
190    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  0);
191    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  1);
192    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  2);
193    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  3);
194    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  4);
195    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  5);
196    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  6);
197    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  7);
198    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  8);
199    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  9);
200    OSMetaClassDeclareReservedUnused(IOPlatformExpert, 10);
201    OSMetaClassDeclareReservedUnused(IOPlatformExpert, 11);
202};
203
204/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
205
206class IODTNVRAM;
207
208class IODTPlatformExpert : public IOPlatformExpert
209{
210    OSDeclareAbstractStructors(IODTPlatformExpert);
211
212private:
213    IODTNVRAM *dtNVRAM;
214
215    struct ExpansionData { };
216    ExpansionData *reserved;
217
218public:
219    virtual IOService * probe(	IOService * 	provider,
220				SInt32 	  *	score );
221    virtual bool configure( IOService * provider );
222
223    virtual void processTopLevel( IORegistryEntry * root );
224    virtual const char * deleteList( void ) = 0;
225    virtual const char * excludeList( void ) = 0;
226    virtual IOService * createNub( IORegistryEntry * from );
227    virtual bool createNubs( IOService * parent, OSIterator * iter );
228
229    virtual bool compareNubName( const IOService * nub, OSString * name,
230				 OSString ** matched = 0 ) const;
231
232    virtual IOReturn getNubResources( IOService * nub );
233
234    virtual bool getModelName( char * name, int maxLength );
235    virtual bool getMachineName( char * name, int maxLength );
236
237    virtual void registerNVRAMController( IONVRAMController * nvram );
238
239    virtual int haltRestart(unsigned int type);
240
241    /* virtual */ IOReturn readXPRAM(IOByteCount offset, UInt8 * buffer,
242				     IOByteCount length);
243
244    /* virtual */ IOReturn writeXPRAM(IOByteCount offset, UInt8 * buffer,
245				      IOByteCount length);
246
247    virtual IOReturn readNVRAMProperty(
248	IORegistryEntry * entry,
249	const OSSymbol ** name, OSData ** value );
250
251    virtual IOReturn writeNVRAMProperty(
252	IORegistryEntry * entry,
253	const OSSymbol * name, OSData * value );
254
255    // This returns a dictionary describing all the NVRAM partitions.
256    // The keys will be the partitionIDs of the form "0x52,nvram".
257    // The values will be OSNumbers of the partition's byte count.
258    /* virtual */ OSDictionary *getNVRAMPartitions(void);
259
260    /* virtual */ IOReturn readNVRAMPartition(const OSSymbol * partitionID,
261					      IOByteCount offset, UInt8 * buffer,
262					      IOByteCount length);
263
264    /* virtual */ IOReturn writeNVRAMPartition(const OSSymbol * partitionID,
265					       IOByteCount offset, UInt8 * buffer,
266					       IOByteCount length);
267
268    virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
269    virtual OSString* createSystemSerialNumberString(OSData* myProperty);
270
271    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  0);
272    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  1);
273    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  2);
274    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  3);
275    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  4);
276    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  5);
277    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  6);
278    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  7);
279};
280
281/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
282
283/* generic root nub of service tree */
284
285class IOPlatformExpertDevice : public IOService
286{
287    OSDeclareDefaultStructors(IOPlatformExpertDevice)
288
289private:
290    IOWorkLoop *workLoop;
291
292    struct ExpansionData { };
293    ExpansionData *reserved;
294
295public:
296    virtual bool initWithArgs( void * p1, void * p2,
297					void * p3, void *p4 );
298    virtual bool compareName( OSString * name, OSString ** matched = 0 ) const;
299
300    virtual IOWorkLoop *getWorkLoop() const;
301    virtual IOReturn setProperties( OSObject * properties );
302
303    virtual void free();
304
305    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  0);
306    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  1);
307    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  2);
308    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  3);
309};
310
311/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
312
313/* generic nub for motherboard devices */
314
315class IOPlatformDevice : public IOService
316{
317    OSDeclareDefaultStructors(IOPlatformDevice)
318
319    struct ExpansionData { };
320    ExpansionData *reserved;
321
322public:
323    virtual bool compareName( OSString * name, OSString ** matched = 0 ) const;
324    virtual IOService * matchLocation( IOService * client );
325    virtual IOReturn getResources( void );
326
327    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  0);
328    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  1);
329    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  2);
330    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  3);
331};
332
333#endif /* __cplusplus */
334
335#endif /* ! _IOKIT_IOPLATFORMEXPERT_H */
336