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 );
71
72/* unless it's a "well-known" property, these will read/write out the value as raw data */
73
74extern boolean_t PEWriteNVRAMProperty(const char *symbol, const void *value, const unsigned int len);
75
76extern boolean_t PEReadNVRAMProperty(const char *symbol, void *value, unsigned int *len);
77
78extern boolean_t PERemoveNVRAMProperty(const char *symbol);
79
80#ifdef __cplusplus
81} /* extern "C" */
82
83#define kIOPlatformMapperPresentKey "IOPlatformMapperPresent"
84
85
86extern OSSymbol *               gPlatformInterruptControllerName;
87
88extern const OSSymbol *		gIOPlatformSleepActionKey;
89extern const OSSymbol *		gIOPlatformWakeActionKey;
90extern const OSSymbol *		gIOPlatformQuiesceActionKey;
91extern const OSSymbol *		gIOPlatformActiveActionKey;
92
93class IORangeAllocator;
94class IONVRAMController;
95class IOPMrootDomain;
96
97class IOPlatformExpert : public IOService
98{
99    OSDeclareDefaultStructors(IOPlatformExpert);
100
101private:
102    long _peBootROMType;
103    long _peChipSetType;
104    long _peMachineType;
105
106protected:
107    IOPMrootDomain * root;
108    int _pePMFeatures;
109    int _pePrivPMFeatures;
110    int _peNumBatteriesSupported;
111    OSArray  * thePowerTree;
112
113    bool       searchingForAdditionalParents;
114    OSNumber * multipleParentKeyValue;
115    int        numInstancesRegistered;
116
117    struct ExpansionData { };
118    ExpansionData *reserved;
119
120    virtual void setBootROMType(long peBootROMType);
121    virtual void setChipSetType(long peChipSetType);
122    virtual void setMachineType(long peMachineType);
123
124    virtual bool CheckSubTree (OSArray * inSubTree, IOService * theNub, IOService * theDevice, OSDictionary * theParent);
125    virtual bool RegisterServiceInTree (IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider);
126
127    virtual void PMInstantiatePowerDomains ( void );
128
129public:
130    virtual bool attach( IOService * provider );
131    virtual bool start( IOService * provider );
132    virtual bool configure( IOService * provider );
133    virtual IOService * createNub( OSDictionary * from );
134
135    virtual bool compareNubName( const IOService * nub, OSString * name,
136				 OSString ** matched = 0 ) const;
137    virtual IOReturn getNubResources( IOService * nub );
138
139    virtual long getBootROMType(void);
140    virtual long getChipSetType(void);
141    virtual long getMachineType(void);
142
143    virtual bool getModelName( char * name, int maxLength );
144    virtual bool getMachineName( char * name, int maxLength );
145
146    virtual int haltRestart(unsigned int type);
147    virtual void sleepKernel(void);
148
149    virtual long getGMTTimeOfDay( void );
150    virtual void setGMTTimeOfDay( long secs );
151
152    virtual IOReturn getConsoleInfo( PE_Video * consoleInfo );
153    virtual IOReturn setConsoleInfo( PE_Video * consoleInfo, unsigned int op );
154
155    virtual void registerNVRAMController( IONVRAMController * nvram );
156
157    virtual IOReturn registerInterruptController(OSSymbol *name, IOInterruptController *interruptController);
158    virtual IOInterruptController *lookUpInterruptController(OSSymbol *name);
159    virtual void setCPUInterruptProperties(IOService *service);
160    virtual bool atInterruptLevel(void);
161
162    virtual IOReturn callPlatformFunction(const OSSymbol *functionName,
163					  bool waitForFunction,
164					  void *param1, void *param2,
165					  void *param3, void *param4);
166
167    virtual IORangeAllocator * getPhysicalRangeAllocator(void);
168
169    virtual bool platformAdjustService(IOService *service);
170
171    virtual void PMRegisterDevice(IOService * theNub, IOService * theDevice);
172    virtual void PMLog ( const char *,unsigned long, unsigned long, unsigned long );
173
174    virtual bool hasPMFeature (unsigned long featureMask);
175    virtual bool hasPrivPMFeature (unsigned long privFeatureMask);
176    virtual int  numBatteriesSupported (void);
177
178    virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
179
180    virtual OSString* createSystemSerialNumberString(OSData* myProperty);
181
182    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  0);
183    OSMetaClassDeclareReservedUsed(IOPlatformExpert,  1);
184    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  2);
185    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  3);
186    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  4);
187    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  5);
188    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  6);
189    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  7);
190    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  8);
191    OSMetaClassDeclareReservedUnused(IOPlatformExpert,  9);
192    OSMetaClassDeclareReservedUnused(IOPlatformExpert, 10);
193    OSMetaClassDeclareReservedUnused(IOPlatformExpert, 11);
194};
195
196/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
197
198class IODTNVRAM;
199
200class IODTPlatformExpert : public IOPlatformExpert
201{
202    OSDeclareAbstractStructors(IODTPlatformExpert);
203
204private:
205    IODTNVRAM *dtNVRAM;
206
207    struct ExpansionData { };
208    ExpansionData *reserved;
209
210public:
211    virtual IOService * probe(	IOService * 	provider,
212				SInt32 	  *	score );
213    virtual bool configure( IOService * provider );
214
215    virtual void processTopLevel( IORegistryEntry * root );
216    virtual const char * deleteList( void ) = 0;
217    virtual const char * excludeList( void ) = 0;
218    virtual IOService * createNub( IORegistryEntry * from );
219    virtual bool createNubs( IOService * parent, OSIterator * iter );
220
221    virtual bool compareNubName( const IOService * nub, OSString * name,
222				 OSString ** matched = 0 ) const;
223
224    virtual IOReturn getNubResources( IOService * nub );
225
226    virtual bool getModelName( char * name, int maxLength );
227    virtual bool getMachineName( char * name, int maxLength );
228
229    virtual void registerNVRAMController( IONVRAMController * nvram );
230
231    virtual int haltRestart(unsigned int type);
232
233    /* virtual */ IOReturn readXPRAM(IOByteCount offset, UInt8 * buffer,
234				     IOByteCount length);
235
236    /* virtual */ IOReturn writeXPRAM(IOByteCount offset, UInt8 * buffer,
237				      IOByteCount length);
238
239    virtual IOReturn readNVRAMProperty(
240	IORegistryEntry * entry,
241	const OSSymbol ** name, OSData ** value );
242
243    virtual IOReturn writeNVRAMProperty(
244	IORegistryEntry * entry,
245	const OSSymbol * name, OSData * value );
246
247    // This returns a dictionary describing all the NVRAM partitions.
248    // The keys will be the partitionIDs of the form "0x52,nvram".
249    // The values will be OSNumbers of the partition's byte count.
250    /* virtual */ OSDictionary *getNVRAMPartitions(void);
251
252    /* virtual */ IOReturn readNVRAMPartition(const OSSymbol * partitionID,
253					      IOByteCount offset, UInt8 * buffer,
254					      IOByteCount length);
255
256    /* virtual */ IOReturn writeNVRAMPartition(const OSSymbol * partitionID,
257					       IOByteCount offset, UInt8 * buffer,
258					       IOByteCount length);
259
260    virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
261    virtual OSString* createSystemSerialNumberString(OSData* myProperty);
262
263    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  0);
264    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  1);
265    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  2);
266    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  3);
267    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  4);
268    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  5);
269    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  6);
270    OSMetaClassDeclareReservedUnused(IODTPlatformExpert,  7);
271};
272
273/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
274
275/* generic root nub of service tree */
276
277class IOPlatformExpertDevice : public IOService
278{
279    OSDeclareDefaultStructors(IOPlatformExpertDevice)
280
281private:
282    IOWorkLoop *workLoop;
283
284    struct ExpansionData { };
285    ExpansionData *reserved;
286
287public:
288    virtual bool initWithArgs( void * p1, void * p2,
289					void * p3, void *p4 );
290    virtual bool compareName( OSString * name, OSString ** matched = 0 ) const;
291
292    virtual IOWorkLoop *getWorkLoop() const;
293    virtual IOReturn setProperties( OSObject * properties );
294
295    virtual void free();
296
297    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  0);
298    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  1);
299    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  2);
300    OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice,  3);
301};
302
303/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
304
305/* generic nub for motherboard devices */
306
307class IOPlatformDevice : public IOService
308{
309    OSDeclareDefaultStructors(IOPlatformDevice)
310
311    struct ExpansionData { };
312    ExpansionData *reserved;
313
314public:
315    virtual bool compareName( OSString * name, OSString ** matched = 0 ) const;
316    virtual IOService * matchLocation( IOService * client );
317    virtual IOReturn getResources( void );
318
319    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  0);
320    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  1);
321    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  2);
322    OSMetaClassDeclareReservedUnused(IOPlatformDevice,  3);
323};
324
325#endif /* __cplusplus */
326
327#endif /* ! _IOKIT_IOPLATFORMEXPERT_H */
328