1 | /* |
2 | * Copyright (c) 1998-2019 Apple 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 | #include <libkern/c++/OSPtr.h> |
45 | |
46 | extern "C" { |
47 | #else |
48 | #include <kern/clock.h> |
49 | #endif |
50 | |
51 | #include <libkern/OSTypes.h> |
52 | |
53 | typedef enum { |
54 | kCoprocessorVersionNone = 0x00000000, |
55 | kCoprocessorVersion1 = 0x00010000, |
56 | kCoprocessorVersion2 = 0x00020000, |
57 | } coprocessor_type_t; |
58 | |
59 | |
60 | /* |
61 | * PEGetMachineName() and PEGetModelName() are inconsistent across |
62 | * architectures, and considered deprecated. |
63 | * PEGetTargetName() and PEGetProductName() instead. |
64 | */ |
65 | extern boolean_t PEGetMachineName( char * name, int maxLength ); |
66 | extern boolean_t PEGetModelName( char * name, int maxLength ); |
67 | |
68 | extern boolean_t PEGetTargetName( char * name, int maxLength ); |
69 | extern boolean_t PEGetProductName( char * name, int maxLength ); |
70 | extern int PEGetPlatformEpoch( void ); |
71 | |
72 | enum { |
73 | kPEHaltCPU, |
74 | kPERestartCPU, |
75 | kPEHangCPU, |
76 | kPEUPSDelayHaltCPU, |
77 | kPEPanicRestartCPU, |
78 | kPEPanicSync, |
79 | kPEPagingOff, |
80 | kPEPanicBegin, |
81 | kPEPanicEnd, |
82 | kPEPanicRestartCPUNoCallouts, |
83 | kPEPanicDiagnosticsDone, |
84 | kPEPanicDiagnosticsInProgress, |
85 | }; |
86 | |
87 | /* Bitmask of details related to panic callouts */ |
88 | #define kPanicDetailsForcePowerOff 0x1 |
89 | |
90 | extern int (*PE_halt_restart)(unsigned int type); |
91 | extern int PEHaltRestart(unsigned int type); |
92 | |
93 | #ifdef XNU_KERNEL_PRIVATE |
94 | |
95 | extern int PEHaltRestartInternal(unsigned int type, uint32_t details); |
96 | |
97 | enum { |
98 | kIOSystemShutdownNotificationStageProcessExit = 0, |
99 | kIOSystemShutdownNotificationStageRootUnmount = 1, |
100 | kIOSystemShutdownNotificationTerminateDEXTs = 2, |
101 | }; |
102 | extern void IOSystemShutdownNotification(int howto, int stage); |
103 | |
104 | extern uint32_t gEnforcePlatformActionSafety; |
105 | #endif /* XNU_KERNEL_PRIVATE */ |
106 | |
107 | #ifdef KERNEL_PRIVATE |
108 | extern boolean_t IOPMRootDomainGetWillShutdown(void); |
109 | extern void PEInitiatePanic(void); |
110 | #endif /* KERNEL_PRIVATE */ |
111 | |
112 | // Save the Panic Info. Returns the number of bytes saved. |
113 | extern UInt32 PESavePanicInfo(UInt8 *buffer, UInt32 length); |
114 | extern void PESavePanicInfoAction(void *buffer, UInt32 offset, UInt32 length); |
115 | |
116 | /* |
117 | * SMC requires that all data is flushed in multiples of 16 bytes at 16 byte |
118 | * boundaries. |
119 | */ |
120 | #define PANIC_FLUSH_BOUNDARY 16 |
121 | |
122 | extern long PEGetGMTTimeOfDay( void ); |
123 | extern void PESetGMTTimeOfDay( long secs ); |
124 | extern void PEGetUTCTimeOfDay( clock_sec_t * secs, clock_usec_t * usecs ); |
125 | extern void PESetUTCTimeOfDay( clock_sec_t secs, clock_usec_t usecs ); |
126 | |
127 | /* unless it's a "well-known" property, these will read/write out the value as raw data */ |
128 | |
129 | extern boolean_t PEWriteNVRAMBooleanProperty(const char *symbol, boolean_t value); |
130 | extern boolean_t PEWriteNVRAMProperty(const char *symbol, const void *value, const unsigned int len); |
131 | extern boolean_t PEWriteNVRAMPropertyWithCopy(const char *symbol, const void *value, const unsigned int len); |
132 | extern boolean_t PEReadNVRAMProperty(const char *symbol, void *value, unsigned int *len); |
133 | extern boolean_t PEReadNVRAMBooleanProperty(const char *symbol, boolean_t *value); |
134 | extern boolean_t PERemoveNVRAMProperty(const char *symbol); |
135 | extern boolean_t PESyncNVRAM(void); |
136 | |
137 | extern coprocessor_type_t PEGetCoprocessorVersion( void ); |
138 | |
139 | #ifdef __cplusplus |
140 | } /* extern "C" */ |
141 | |
142 | #define kIOPlatformMapperPresentKey "IOPlatformMapperPresent" |
143 | |
144 | |
145 | |
146 | |
147 | extern OSSymbol * gPlatformInterruptControllerName; |
148 | |
149 | /* |
150 | * IOPlatformSleepAction |
151 | * |
152 | * Sleep is called after power management has finished all of the power plane |
153 | * driver power management notifications and state transitions and has |
154 | * committed to sleep, but before the other CPUs are powered off. |
155 | * The scheduler is still active. |
156 | */ |
157 | extern const OSSymbol *gIOPlatformSleepActionKey; |
158 | |
159 | /* |
160 | * IOPlatformWakeAction |
161 | * |
162 | * Wake is called with the scheduler enabled, but before |
163 | * powering on other CPUs, so try to minimize work done in this path to speed |
164 | * up wake time. |
165 | */ |
166 | extern const OSSymbol *gIOPlatformWakeActionKey; |
167 | |
168 | /* |
169 | * IOPlatformQuiesceAction |
170 | * |
171 | * Quiesce is called after all CPUs are off, scheduling is disabled, |
172 | * and the boot CPU is about to pull the plug. |
173 | * Mutexes and blocking are disallowed in this context and will panic. |
174 | * Do not pass this action to super() (incl. IOService, IOPlatformExpert) |
175 | */ |
176 | extern const OSSymbol *gIOPlatformQuiesceActionKey; |
177 | |
178 | /* |
179 | * IOPlatformActiveAction |
180 | * |
181 | * Active is called very early in the wake path before enabling the scheduler |
182 | * on the boot CPU. |
183 | * Mutexes and blocking are disallowed in this context and will panic. |
184 | * Do not pass this action to super() (incl. IOService, IOPlatformExpert) |
185 | */ |
186 | extern const OSSymbol *gIOPlatformActiveActionKey; |
187 | |
188 | /* |
189 | * IOPlatformHaltRestartAction |
190 | * |
191 | * Halt/Restart is called after the kernel finishes shutting down the |
192 | * system and is ready to power off or reboot. |
193 | * |
194 | * It is not guaranteed to be called in non-graceful shutdown scenarios. |
195 | */ |
196 | extern const OSSymbol *gIOPlatformHaltRestartActionKey; |
197 | |
198 | /* |
199 | * IOPlatformPanicAction |
200 | * |
201 | * Panic is called when the system is panicking before it records a core file |
202 | * (if it is configured to do so) |
203 | * |
204 | * It can be called at any time, in any context, in any state. Don't depend |
205 | * on anything being powered on in a useful state. |
206 | * |
207 | * Mutexes and blocking are disallowed in this context and will fail. |
208 | * |
209 | * If you hang or panic again in this callout, the panic log may not be recorded, |
210 | * leading to the loss of field reports about customer issues. |
211 | */ |
212 | extern const OSSymbol *gIOPlatformPanicActionKey; |
213 | |
214 | class IORangeAllocator; |
215 | class IONVRAMController; |
216 | class IOPMrootDomain; |
217 | |
218 | class IOPlatformExpert : public IOService |
219 | { |
220 | OSDeclareDefaultStructors(IOPlatformExpert); |
221 | |
222 | private: |
223 | long _peBootROMType; |
224 | long _peChipSetType; |
225 | long _peMachineType; |
226 | |
227 | protected: |
228 | IOPMrootDomain * root; |
229 | int _pePMFeatures; |
230 | int _pePrivPMFeatures; |
231 | int _peNumBatteriesSupported; |
232 | OSArray * thePowerTree; |
233 | |
234 | bool searchingForAdditionalParents; |
235 | OSNumber * multipleParentKeyValue; |
236 | int numInstancesRegistered; |
237 | |
238 | struct ExpansionData { }; |
239 | ExpansionData *iope_reserved __unused; |
240 | |
241 | virtual void setBootROMType(long peBootROMType); |
242 | virtual void setChipSetType(long peChipSetType); |
243 | virtual void setMachineType(long peMachineType); |
244 | |
245 | virtual bool CheckSubTree(OSArray * inSubTree, IOService * theNub, IOService * theDevice, OSDictionary * theParent); |
246 | virtual bool RegisterServiceInTree(IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider); |
247 | |
248 | virtual void PMInstantiatePowerDomains( void ); |
249 | |
250 | public: |
251 | virtual bool attach( IOService * provider ) APPLE_KEXT_OVERRIDE; |
252 | virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE; |
253 | virtual bool configure( IOService * provider ); |
254 | virtual IOService * createNub( OSDictionary * from ); |
255 | |
256 | virtual bool compareNubName( const IOService * nub, OSString * name, |
257 | OSString ** matched = NULL ) const; |
258 | bool compareNubName( const IOService * nub, OSString * name, |
259 | OSSharedPtr<OSString>& matched ) const; |
260 | virtual IOReturn getNubResources( IOService * nub ); |
261 | |
262 | virtual long getBootROMType(void); |
263 | virtual long getChipSetType(void); |
264 | virtual long getMachineType(void); |
265 | |
266 | /* |
267 | * getModelName() and getMachineName() are deprecated for direct |
268 | * use. Use getTargetName() and getProductName() instead. |
269 | */ |
270 | virtual bool getModelName( char * name, int maxLength ); |
271 | virtual bool getMachineName( char * name, int maxLength ); |
272 | |
273 | virtual int haltRestart(unsigned int type); |
274 | virtual void sleepKernel(void); |
275 | |
276 | virtual long getGMTTimeOfDay( void ); |
277 | virtual void setGMTTimeOfDay( long secs ); |
278 | |
279 | virtual IOReturn getConsoleInfo( PE_Video * consoleInfo ); |
280 | virtual IOReturn setConsoleInfo( PE_Video * consoleInfo, unsigned int op ); |
281 | |
282 | virtual void registerNVRAMController( IONVRAMController * nvram ); |
283 | |
284 | virtual IOReturn registerInterruptController(OSSymbol *name, IOInterruptController *interruptController); |
285 | virtual LIBKERN_RETURNS_NOT_RETAINED IOInterruptController * |
286 | lookUpInterruptController(OSSymbol *name); |
287 | |
288 | virtual void setCPUInterruptProperties(IOService *service); |
289 | virtual bool atInterruptLevel(void); |
290 | |
291 | virtual IOReturn callPlatformFunction(const OSSymbol *functionName, |
292 | bool waitForFunction, |
293 | void *param1, void *param2, |
294 | void *param3, void *param4) APPLE_KEXT_OVERRIDE; |
295 | |
296 | virtual IORangeAllocator * getPhysicalRangeAllocator(void); |
297 | |
298 | virtual bool platformAdjustService(IOService *service); |
299 | |
300 | virtual void PMRegisterDevice(IOService * theNub, IOService * theDevice); |
301 | virtual void PMLog( const char *, unsigned long, unsigned long, unsigned long ); |
302 | |
303 | virtual bool hasPMFeature(unsigned long featureMask); |
304 | virtual bool hasPrivPMFeature(unsigned long privFeatureMask); |
305 | virtual int numBatteriesSupported(void); |
306 | |
307 | virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length); |
308 | |
309 | virtual OSString* createSystemSerialNumberString(OSData* myProperty); |
310 | |
311 | virtual IOReturn deregisterInterruptController(OSSymbol *name); |
312 | |
313 | virtual void getUTCTimeOfDay( clock_sec_t * secs, clock_nsec_t * nsecs ); |
314 | virtual void setUTCTimeOfDay( clock_sec_t secs, clock_nsec_t nsecs ); |
315 | void publishPlatformUUIDAndSerial( void ); |
316 | void publishNVRAM( void ); |
317 | |
318 | virtual bool getTargetName( char * name, int maxLength ); |
319 | virtual bool getProductName( char * name, int maxLength ); |
320 | |
321 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 0); |
322 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 1); |
323 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 2); |
324 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 3); |
325 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 4); |
326 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 5); |
327 | OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 6); |
328 | |
329 | OSMetaClassDeclareReservedUnused(IOPlatformExpert, 7); |
330 | OSMetaClassDeclareReservedUnused(IOPlatformExpert, 8); |
331 | OSMetaClassDeclareReservedUnused(IOPlatformExpert, 9); |
332 | OSMetaClassDeclareReservedUnused(IOPlatformExpert, 10); |
333 | OSMetaClassDeclareReservedUnused(IOPlatformExpert, 11); |
334 | }; |
335 | |
336 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
337 | |
338 | class IODTNVRAM; |
339 | |
340 | class IODTPlatformExpert : public IOPlatformExpert |
341 | { |
342 | OSDeclareAbstractStructors(IODTPlatformExpert); |
343 | |
344 | private: |
345 | IODTNVRAM *dtNVRAM; |
346 | |
347 | struct ExpansionData { }; |
348 | ExpansionData *iodtpe_reserved; |
349 | |
350 | public: |
351 | virtual IOService * probe( IOService * provider, |
352 | SInt32 * score ) APPLE_KEXT_OVERRIDE; |
353 | virtual bool configure( IOService * provider ) APPLE_KEXT_OVERRIDE; |
354 | |
355 | virtual void processTopLevel( IORegistryEntry * root ); |
356 | virtual const char * deleteList( void ) = 0; |
357 | virtual const char * excludeList( void ) = 0; |
358 | virtual IOService * createNub( IORegistryEntry * from ); |
359 | virtual bool createNubs( IOService * parent, LIBKERN_CONSUMED OSIterator * iter ); |
360 | |
361 | virtual bool compareNubName( const IOService * nub, OSString * name, |
362 | OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE; |
363 | |
364 | virtual IOReturn getNubResources( IOService * nub ) APPLE_KEXT_OVERRIDE; |
365 | |
366 | /* |
367 | * getModelName() and getMachineName() are deprecated. Use |
368 | * getTargetName() and getProductName() instead. |
369 | */ |
370 | virtual bool getModelName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE; |
371 | virtual bool getMachineName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE; |
372 | |
373 | virtual bool getTargetName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE; |
374 | virtual bool getProductName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE; |
375 | |
376 | virtual void registerNVRAMController( IONVRAMController * nvram ) APPLE_KEXT_OVERRIDE; |
377 | |
378 | virtual int haltRestart(unsigned int type) APPLE_KEXT_OVERRIDE; |
379 | |
380 | /* virtual */ IOReturn readXPRAM(IOByteCount offset, UInt8 * buffer, |
381 | IOByteCount length); |
382 | |
383 | /* virtual */ IOReturn writeXPRAM(IOByteCount offset, UInt8 * buffer, |
384 | IOByteCount length); |
385 | |
386 | virtual IOReturn readNVRAMProperty( |
387 | IORegistryEntry * entry, |
388 | const OSSymbol ** name, OSData ** value ); |
389 | |
390 | IOReturn readNVRAMProperty( |
391 | IORegistryEntry * entry, |
392 | OSSharedPtr<const OSSymbol>& name, OSSharedPtr<OSData>& value ); |
393 | |
394 | virtual IOReturn writeNVRAMProperty( |
395 | IORegistryEntry * entry, |
396 | const OSSymbol * name, OSData * value ); |
397 | |
398 | // This returns a dictionary describing all the NVRAM partitions. |
399 | // The keys will be the partitionIDs of the form "0x52,nvram". |
400 | // The values will be OSNumbers of the partition's byte count. |
401 | /* virtual */ OSDictionary *getNVRAMPartitions(void); |
402 | |
403 | /* virtual */ IOReturn readNVRAMPartition(const OSSymbol * partitionID, |
404 | IOByteCount offset, UInt8 * buffer, |
405 | IOByteCount length); |
406 | |
407 | /* virtual */ IOReturn writeNVRAMPartition(const OSSymbol * partitionID, |
408 | IOByteCount offset, UInt8 * buffer, |
409 | IOByteCount length); |
410 | |
411 | virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length) APPLE_KEXT_OVERRIDE; |
412 | virtual OSString* createSystemSerialNumberString(OSData* myProperty) APPLE_KEXT_OVERRIDE; |
413 | |
414 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 0); |
415 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 1); |
416 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 2); |
417 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 3); |
418 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 4); |
419 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 5); |
420 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 6); |
421 | OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 7); |
422 | }; |
423 | |
424 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
425 | |
426 | /* generic root nub of service tree */ |
427 | |
428 | class IOPlatformExpertDevice : public IOService |
429 | { |
430 | OSDeclareDefaultStructors(IOPlatformExpertDevice); |
431 | |
432 | private: |
433 | IOWorkLoop *workLoop; |
434 | |
435 | struct ExpansionData { }; |
436 | ExpansionData *ioped_reserved __unused; |
437 | |
438 | public: |
439 | virtual bool init(void *dtRoot); |
440 | virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE; |
441 | |
442 | virtual IOWorkLoop *getWorkLoop() const APPLE_KEXT_OVERRIDE; |
443 | virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE; |
444 | |
445 | virtual void free() APPLE_KEXT_OVERRIDE; |
446 | |
447 | virtual IOReturn newUserClient( task_t owningTask, void * securityID, |
448 | UInt32 type, OSDictionary * properties, |
449 | IOUserClient ** handler) APPLE_KEXT_OVERRIDE; |
450 | |
451 | bool startIOServiceMatching(void); |
452 | void createNVRAM(void); |
453 | void generatePlatformUUID(void); |
454 | void configureDefaults(void); |
455 | |
456 | OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 0); |
457 | OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 1); |
458 | OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 2); |
459 | OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 3); |
460 | }; |
461 | |
462 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
463 | |
464 | /* generic nub for motherboard devices */ |
465 | |
466 | class IOPlatformDevice : public IOService |
467 | { |
468 | OSDeclareDefaultStructors(IOPlatformDevice); |
469 | |
470 | struct ExpansionData { }; |
471 | ExpansionData *iopd_reserved; |
472 | |
473 | public: |
474 | virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE; |
475 | virtual IOService * matchLocation( IOService * client ) APPLE_KEXT_OVERRIDE; |
476 | virtual IOReturn getResources( void ) APPLE_KEXT_OVERRIDE; |
477 | |
478 | OSMetaClassDeclareReservedUnused(IOPlatformDevice, 0); |
479 | OSMetaClassDeclareReservedUnused(IOPlatformDevice, 1); |
480 | OSMetaClassDeclareReservedUnused(IOPlatformDevice, 2); |
481 | OSMetaClassDeclareReservedUnused(IOPlatformDevice, 3); |
482 | }; |
483 | |
484 | #endif /* __cplusplus */ |
485 | |
486 | #endif /* ! _IOKIT_IOPLATFORMEXPERT_H */ |
487 | |