2 * Copyright (c) 1998-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
36 #ifndef _IOKIT_IOPLATFORMEXPERT_H
37 #define _IOKIT_IOPLATFORMEXPERT_H
40 #include <IOKit/IOLib.h>
41 #include <IOKit/IOService.h>
42 #include <IOKit/IOInterrupts.h>
43 #include <IOKit/IOInterruptController.h>
44 #include <libkern/c++/OSPtr.h>
48 #include <kern/clock.h>
51 #include <libkern/OSTypes.h>
54 kCoprocessorVersionNone
= 0x00000000,
55 kCoprocessorVersion1
= 0x00010000,
56 kCoprocessorVersion2
= 0x00020000,
61 * PEGetMachineName() and PEGetModelName() are inconsistent across
62 * architectures, and considered deprecated.
63 * PEGetTargetName() and PEGetProductName() instead.
65 extern boolean_t
PEGetMachineName( char * name
, int maxLength
);
66 extern boolean_t
PEGetModelName( char * name
, int maxLength
);
68 extern boolean_t
PEGetTargetName( char * name
, int maxLength
);
69 extern boolean_t
PEGetProductName( char * name
, int maxLength
);
70 extern int PEGetPlatformEpoch( void );
82 kPEPanicRestartCPUNoCallouts
85 /* Bitmask of details related to panic callouts */
86 #define kPanicDetailsForcePowerOff 0x1
88 extern int (*PE_halt_restart
)(unsigned int type
);
89 extern int PEHaltRestart(unsigned int type
);
91 #ifdef XNU_KERNEL_PRIVATE
93 extern int PEHaltRestartInternal(unsigned int type
, uint32_t details
);
96 kIOSystemShutdownNotificationStageProcessExit
= 0,
97 kIOSystemShutdownNotificationStageRootUnmount
= 1,
99 extern void IOSystemShutdownNotification(int stage
);
101 extern uint32_t gEnforceQuiesceSafety
;
102 #endif /* XNU_KERNEL_PRIVATE */
104 #ifdef KERNEL_PRIVATE
105 extern boolean_t
IOPMRootDomainGetWillShutdown(void);
106 extern void PEInitiatePanic(void);
107 #endif /* KERNEL_PRIVATE */
109 // Save the Panic Info. Returns the number of bytes saved.
110 extern UInt32
PESavePanicInfo(UInt8
*buffer
, UInt32 length
);
111 extern void PESavePanicInfoAction(void *buffer
, UInt32 offset
, UInt32 length
);
114 * SMC requires that all data is flushed in multiples of 16 bytes at 16 byte
117 #define PANIC_FLUSH_BOUNDARY 16
119 extern long PEGetGMTTimeOfDay( void );
120 extern void PESetGMTTimeOfDay( long secs
);
121 extern void PEGetUTCTimeOfDay( clock_sec_t
* secs
, clock_usec_t
* usecs
);
122 extern void PESetUTCTimeOfDay( clock_sec_t secs
, clock_usec_t usecs
);
124 /* unless it's a "well-known" property, these will read/write out the value as raw data */
126 extern boolean_t
PEWriteNVRAMBooleanProperty(const char *symbol
, boolean_t value
);
127 extern boolean_t
PEWriteNVRAMProperty(const char *symbol
, const void *value
, const unsigned int len
);
128 extern boolean_t
PEWriteNVRAMPropertyWithCopy(const char *symbol
, const void *value
, const unsigned int len
);
130 extern boolean_t
PEReadNVRAMProperty(const char *symbol
, void *value
, unsigned int *len
);
132 extern boolean_t
PERemoveNVRAMProperty(const char *symbol
);
134 extern coprocessor_type_t
PEGetCoprocessorVersion( void );
139 #define kIOPlatformMapperPresentKey "IOPlatformMapperPresent"
144 extern OSSymbol
* gPlatformInterruptControllerName
;
147 * IOPlatformSleepAction
149 * Sleep is called after power management has finished all of the power plane
150 * driver power management notifications and state transitions and has
151 * committed to sleep, but before the other CPUs are powered off.
152 * The scheduler is still active.
154 extern const OSSymbol
*gIOPlatformSleepActionKey
;
157 * IOPlatformWakeAction
159 * Wake is called with the scheduler enabled, but before
160 * powering on other CPUs, so try to minimize work done in this path to speed
163 extern const OSSymbol
*gIOPlatformWakeActionKey
;
166 * IOPlatformQuiesceAction
168 * Quiesce is called after all CPUs are off, scheduling is disabled,
169 * and the boot CPU is about to pull the plug.
170 * Mutexes and blocking are disallowed in this context and will panic.
171 * Do not pass this action to super() (incl. IOService, IOPlatformExpert)
173 extern const OSSymbol
*gIOPlatformQuiesceActionKey
;
176 * IOPlatformActiveAction
178 * Active is called very early in the wake path before enabling the scheduler
180 * Mutexes and blocking are disallowed in this context and will panic.
181 * Do not pass this action to super() (incl. IOService, IOPlatformExpert)
183 extern const OSSymbol
*gIOPlatformActiveActionKey
;
186 * IOPlatformHaltRestartAction
188 * Halt/Restart is called after the kernel finishes shutting down the
189 * system and is ready to power off or reboot.
191 * It is not guaranteed to be called in non-graceful shutdown scenarios.
193 extern const OSSymbol
*gIOPlatformHaltRestartActionKey
;
196 * IOPlatformPanicAction
198 * Panic is called when the system is panicking before it records a core file
199 * (if it is configured to do so)
201 * It can be called at any time, in any context, in any state. Don't depend
202 * on anything being powered on in a useful state.
204 * Mutexes and blocking are disallowed in this context and will fail.
206 * If you hang or panic again in this callout, the panic log may not be recorded,
207 * leading to the loss of field reports about customer issues.
209 extern const OSSymbol
*gIOPlatformPanicActionKey
;
211 class IORangeAllocator
;
212 class IONVRAMController
;
213 class IOPMrootDomain
;
215 class IOPlatformExpert
: public IOService
217 OSDeclareDefaultStructors(IOPlatformExpert
);
225 IOPMrootDomain
* root
;
227 int _pePrivPMFeatures
;
228 int _peNumBatteriesSupported
;
229 OSArray
* thePowerTree
;
231 bool searchingForAdditionalParents
;
232 OSNumber
* multipleParentKeyValue
;
233 int numInstancesRegistered
;
235 struct ExpansionData
{ };
236 ExpansionData
*iope_reserved __unused
;
238 virtual void setBootROMType(long peBootROMType
);
239 virtual void setChipSetType(long peChipSetType
);
240 virtual void setMachineType(long peMachineType
);
242 virtual bool CheckSubTree(OSArray
* inSubTree
, IOService
* theNub
, IOService
* theDevice
, OSDictionary
* theParent
);
243 virtual bool RegisterServiceInTree(IOService
* theService
, OSDictionary
* theTreeNode
, OSDictionary
* theTreeParentNode
, IOService
* theProvider
);
245 virtual void PMInstantiatePowerDomains( void );
248 virtual bool attach( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
249 virtual bool start( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
250 virtual bool configure( IOService
* provider
);
251 virtual IOService
* createNub( OSDictionary
* from
);
253 virtual bool compareNubName( const IOService
* nub
, OSString
* name
,
254 OSString
** matched
= NULL
) const;
255 bool compareNubName( const IOService
* nub
, OSString
* name
,
256 OSSharedPtr
<OSString
>& matched
) const;
257 virtual IOReturn
getNubResources( IOService
* nub
);
259 virtual long getBootROMType(void);
260 virtual long getChipSetType(void);
261 virtual long getMachineType(void);
264 * getModelName() and getMachineName() are deprecated for direct
265 * use. Use getTargetName() and getProductName() instead.
267 virtual bool getModelName( char * name
, int maxLength
);
268 virtual bool getMachineName( char * name
, int maxLength
);
270 virtual int haltRestart(unsigned int type
);
271 virtual void sleepKernel(void);
273 virtual long getGMTTimeOfDay( void );
274 virtual void setGMTTimeOfDay( long secs
);
276 virtual IOReturn
getConsoleInfo( PE_Video
* consoleInfo
);
277 virtual IOReturn
setConsoleInfo( PE_Video
* consoleInfo
, unsigned int op
);
279 virtual void registerNVRAMController( IONVRAMController
* nvram
);
281 virtual IOReturn
registerInterruptController(OSSymbol
*name
, IOInterruptController
*interruptController
);
282 virtual LIBKERN_RETURNS_NOT_RETAINED IOInterruptController
*
283 lookUpInterruptController(OSSymbol
*name
);
285 virtual void setCPUInterruptProperties(IOService
*service
);
286 virtual bool atInterruptLevel(void);
288 virtual IOReturn
callPlatformFunction(const OSSymbol
*functionName
,
289 bool waitForFunction
,
290 void *param1
, void *param2
,
291 void *param3
, void *param4
) APPLE_KEXT_OVERRIDE
;
293 virtual IORangeAllocator
* getPhysicalRangeAllocator(void);
295 virtual bool platformAdjustService(IOService
*service
);
297 virtual void PMRegisterDevice(IOService
* theNub
, IOService
* theDevice
);
298 virtual void PMLog( const char *, unsigned long, unsigned long, unsigned long );
300 virtual bool hasPMFeature(unsigned long featureMask
);
301 virtual bool hasPrivPMFeature(unsigned long privFeatureMask
);
302 virtual int numBatteriesSupported(void);
304 virtual IOByteCount
savePanicInfo(UInt8
*buffer
, IOByteCount length
);
306 virtual OSString
* createSystemSerialNumberString(OSData
* myProperty
);
308 virtual IOReturn
deregisterInterruptController(OSSymbol
*name
);
310 virtual void getUTCTimeOfDay( clock_sec_t
* secs
, clock_nsec_t
* nsecs
);
311 virtual void setUTCTimeOfDay( clock_sec_t secs
, clock_nsec_t nsecs
);
312 void publishPlatformUUIDAndSerial( void );
313 void publishNVRAM( void );
315 virtual bool getTargetName( char * name
, int maxLength
);
316 virtual bool getProductName( char * name
, int maxLength
);
318 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 0);
319 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 1);
320 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 2);
321 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 3);
322 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 4);
323 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 5);
324 OSMetaClassDeclareReservedUsedX86(IOPlatformExpert
, 6);
326 OSMetaClassDeclareReservedUnused(IOPlatformExpert
, 7);
327 OSMetaClassDeclareReservedUnused(IOPlatformExpert
, 8);
328 OSMetaClassDeclareReservedUnused(IOPlatformExpert
, 9);
329 OSMetaClassDeclareReservedUnused(IOPlatformExpert
, 10);
330 OSMetaClassDeclareReservedUnused(IOPlatformExpert
, 11);
333 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
337 class IODTPlatformExpert
: public IOPlatformExpert
339 OSDeclareAbstractStructors(IODTPlatformExpert
);
344 struct ExpansionData
{ };
345 ExpansionData
*iodtpe_reserved
;
348 virtual IOService
* probe( IOService
* provider
,
349 SInt32
* score
) APPLE_KEXT_OVERRIDE
;
350 virtual bool configure( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
352 virtual void processTopLevel( IORegistryEntry
* root
);
353 virtual const char * deleteList( void ) = 0;
354 virtual const char * excludeList( void ) = 0;
355 virtual IOService
* createNub( IORegistryEntry
* from
);
356 virtual bool createNubs( IOService
* parent
, LIBKERN_CONSUMED OSIterator
* iter
);
358 virtual bool compareNubName( const IOService
* nub
, OSString
* name
,
359 OSString
** matched
= NULL
) const APPLE_KEXT_OVERRIDE
;
361 virtual IOReturn
getNubResources( IOService
* nub
) APPLE_KEXT_OVERRIDE
;
364 * getModelName() and getMachineName() are deprecated. Use
365 * getTargetName() and getProductName() instead.
367 virtual bool getModelName( char * name
, int maxLength
) APPLE_KEXT_OVERRIDE
;
368 virtual bool getMachineName( char * name
, int maxLength
) APPLE_KEXT_OVERRIDE
;
370 virtual bool getTargetName( char * name
, int maxLength
) APPLE_KEXT_OVERRIDE
;
371 virtual bool getProductName( char * name
, int maxLength
) APPLE_KEXT_OVERRIDE
;
373 virtual void registerNVRAMController( IONVRAMController
* nvram
) APPLE_KEXT_OVERRIDE
;
375 virtual int haltRestart(unsigned int type
) APPLE_KEXT_OVERRIDE
;
377 /* virtual */ IOReturn
readXPRAM(IOByteCount offset
, UInt8
* buffer
,
380 /* virtual */ IOReturn
writeXPRAM(IOByteCount offset
, UInt8
* buffer
,
383 virtual IOReturn
readNVRAMProperty(
384 IORegistryEntry
* entry
,
385 const OSSymbol
** name
, OSData
** value
);
387 IOReturn
readNVRAMProperty(
388 IORegistryEntry
* entry
,
389 OSSharedPtr
<const OSSymbol
>& name
, OSSharedPtr
<OSData
>& value
);
391 virtual IOReturn
writeNVRAMProperty(
392 IORegistryEntry
* entry
,
393 const OSSymbol
* name
, OSData
* value
);
395 // This returns a dictionary describing all the NVRAM partitions.
396 // The keys will be the partitionIDs of the form "0x52,nvram".
397 // The values will be OSNumbers of the partition's byte count.
398 /* virtual */ OSDictionary
*getNVRAMPartitions(void);
400 /* virtual */ IOReturn
readNVRAMPartition(const OSSymbol
* partitionID
,
401 IOByteCount offset
, UInt8
* buffer
,
404 /* virtual */ IOReturn
writeNVRAMPartition(const OSSymbol
* partitionID
,
405 IOByteCount offset
, UInt8
* buffer
,
408 virtual IOByteCount
savePanicInfo(UInt8
*buffer
, IOByteCount length
) APPLE_KEXT_OVERRIDE
;
409 virtual OSString
* createSystemSerialNumberString(OSData
* myProperty
) APPLE_KEXT_OVERRIDE
;
411 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 0);
412 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 1);
413 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 2);
414 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 3);
415 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 4);
416 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 5);
417 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 6);
418 OSMetaClassDeclareReservedUnused(IODTPlatformExpert
, 7);
421 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
423 /* generic root nub of service tree */
425 class IOPlatformExpertDevice
: public IOService
427 OSDeclareDefaultStructors(IOPlatformExpertDevice
);
430 IOWorkLoop
*workLoop
;
432 struct ExpansionData
{ };
433 ExpansionData
*ioped_reserved __unused
;
436 virtual bool init(void *dtRoot
);
437 virtual bool compareName( OSString
* name
, OSString
** matched
= NULL
) const APPLE_KEXT_OVERRIDE
;
439 virtual IOWorkLoop
*getWorkLoop() const APPLE_KEXT_OVERRIDE
;
440 virtual IOReturn
setProperties( OSObject
* properties
) APPLE_KEXT_OVERRIDE
;
442 virtual void free() APPLE_KEXT_OVERRIDE
;
444 virtual IOReturn
newUserClient( task_t owningTask
, void * securityID
,
445 UInt32 type
, OSDictionary
* properties
,
446 IOUserClient
** handler
) APPLE_KEXT_OVERRIDE
;
448 bool startIOServiceMatching(void);
449 void createNVRAM(void);
450 void generatePlatformUUID(void);
451 void configureDefaults(void);
453 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice
, 0);
454 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice
, 1);
455 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice
, 2);
456 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice
, 3);
459 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
461 /* generic nub for motherboard devices */
463 class IOPlatformDevice
: public IOService
465 OSDeclareDefaultStructors(IOPlatformDevice
);
467 struct ExpansionData
{ };
468 ExpansionData
*iopd_reserved
;
471 virtual bool compareName( OSString
* name
, OSString
** matched
= NULL
) const APPLE_KEXT_OVERRIDE
;
472 virtual IOService
* matchLocation( IOService
* client
) APPLE_KEXT_OVERRIDE
;
473 virtual IOReturn
getResources( void ) APPLE_KEXT_OVERRIDE
;
475 OSMetaClassDeclareReservedUnused(IOPlatformDevice
, 0);
476 OSMetaClassDeclareReservedUnused(IOPlatformDevice
, 1);
477 OSMetaClassDeclareReservedUnused(IOPlatformDevice
, 2);
478 OSMetaClassDeclareReservedUnused(IOPlatformDevice
, 3);
481 #endif /* __cplusplus */
483 #endif /* ! _IOKIT_IOPLATFORMEXPERT_H */