xref: /xnu-8796.141.3/iokit/IOKit/IOPlatformExpert.h (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
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 PERemoveNVRAMProperty(const char *symbol);
134 extern boolean_t PESyncNVRAM(void);
135 
136 extern coprocessor_type_t PEGetCoprocessorVersion( void );
137 
138 #ifdef __cplusplus
139 } /* extern "C" */
140 
141 #define kIOPlatformMapperPresentKey "IOPlatformMapperPresent"
142 
143 
144 
145 
146 extern OSSymbol *               gPlatformInterruptControllerName;
147 
148 /*
149  * IOPlatformSleepAction
150  *
151  * Sleep is called after power management has finished all of the power plane
152  * driver power management notifications and state transitions and has
153  * committed to sleep, but before the other CPUs are powered off.
154  * The scheduler is still active.
155  */
156 extern const OSSymbol *gIOPlatformSleepActionKey;
157 
158 /*
159  * IOPlatformWakeAction
160  *
161  * Wake is called with the scheduler enabled, but before
162  * powering on other CPUs, so try to minimize work done in this path to speed
163  * up wake time.
164  */
165 extern const OSSymbol *gIOPlatformWakeActionKey;
166 
167 /*
168  * IOPlatformQuiesceAction
169  *
170  * Quiesce is called after all CPUs are off, scheduling is disabled,
171  * and the boot CPU is about to pull the plug.
172  * Mutexes and blocking are disallowed in this context and will panic.
173  * Do not pass this action to super() (incl. IOService, IOPlatformExpert)
174  */
175 extern const OSSymbol *gIOPlatformQuiesceActionKey;
176 
177 /*
178  * IOPlatformActiveAction
179  *
180  * Active is called very early in the wake path before enabling the scheduler
181  * on the boot CPU.
182  * Mutexes and blocking are disallowed in this context and will panic.
183  * Do not pass this action to super() (incl. IOService, IOPlatformExpert)
184  */
185 extern const OSSymbol *gIOPlatformActiveActionKey;
186 
187 /*
188  * IOPlatformHaltRestartAction
189  *
190  * Halt/Restart is called after the kernel finishes shutting down the
191  * system and is ready to power off or reboot.
192  *
193  * It is not guaranteed to be called in non-graceful shutdown scenarios.
194  */
195 extern const OSSymbol *gIOPlatformHaltRestartActionKey;
196 
197 /*
198  * IOPlatformPanicAction
199  *
200  * Panic is called when the system is panicking before it records a core file
201  * (if it is configured to do so)
202  *
203  * It can be called at any time, in any context, in any state.  Don't depend
204  * on anything being powered on in a useful state.
205  *
206  * Mutexes and blocking are disallowed in this context and will fail.
207  *
208  * If you hang or panic again in this callout, the panic log may not be recorded,
209  * leading to the loss of field reports about customer issues.
210  */
211 extern const OSSymbol *gIOPlatformPanicActionKey;
212 
213 class IORangeAllocator;
214 class IONVRAMController;
215 class IOPMrootDomain;
216 
217 class IOPlatformExpert : public IOService
218 {
219 	OSDeclareDefaultStructors(IOPlatformExpert);
220 
221 private:
222 	long _peBootROMType;
223 	long _peChipSetType;
224 	long _peMachineType;
225 
226 protected:
227 	IOPMrootDomain * root;
228 	int _pePMFeatures;
229 	int _pePrivPMFeatures;
230 	int _peNumBatteriesSupported;
231 	OSArray  * thePowerTree;
232 
233 	bool       searchingForAdditionalParents;
234 	OSNumber * multipleParentKeyValue;
235 	int        numInstancesRegistered;
236 
237 	struct ExpansionData { };
238 	ExpansionData *iope_reserved __unused;
239 
240 	virtual void setBootROMType(long peBootROMType);
241 	virtual void setChipSetType(long peChipSetType);
242 	virtual void setMachineType(long peMachineType);
243 
244 	virtual bool CheckSubTree(OSArray * inSubTree, IOService * theNub, IOService * theDevice, OSDictionary * theParent);
245 	virtual bool RegisterServiceInTree(IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider);
246 
247 	virtual void PMInstantiatePowerDomains( void );
248 
249 public:
250 	virtual bool attach( IOService * provider ) APPLE_KEXT_OVERRIDE;
251 	virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE;
252 	virtual bool configure( IOService * provider );
253 	virtual IOService * createNub( OSDictionary * from );
254 
255 	virtual bool compareNubName( const IOService * nub, OSString * name,
256 	    OSString ** matched = NULL ) const;
257 	bool compareNubName( const IOService * nub, OSString * name,
258 	    OSSharedPtr<OSString>& matched ) const;
259 	virtual IOReturn getNubResources( IOService * nub );
260 
261 	virtual long getBootROMType(void);
262 	virtual long getChipSetType(void);
263 	virtual long getMachineType(void);
264 
265 	/*
266 	 * getModelName() and getMachineName() are deprecated for direct
267 	 * use. Use getTargetName() and getProductName() instead.
268 	 */
269 	virtual bool getModelName( char * name, int maxLength );
270 	virtual bool getMachineName( char * name, int maxLength );
271 
272 	virtual int haltRestart(unsigned int type);
273 	virtual void sleepKernel(void);
274 
275 	virtual long getGMTTimeOfDay( void );
276 	virtual void setGMTTimeOfDay( long secs );
277 
278 	virtual IOReturn getConsoleInfo( PE_Video * consoleInfo );
279 	virtual IOReturn setConsoleInfo( PE_Video * consoleInfo, unsigned int op );
280 
281 	virtual void registerNVRAMController( IONVRAMController * nvram );
282 
283 	virtual IOReturn registerInterruptController(OSSymbol *name, IOInterruptController *interruptController);
284 	virtual LIBKERN_RETURNS_NOT_RETAINED IOInterruptController *
285 	lookUpInterruptController(OSSymbol *name);
286 
287 	virtual void setCPUInterruptProperties(IOService *service);
288 	virtual bool atInterruptLevel(void);
289 
290 	virtual IOReturn callPlatformFunction(const OSSymbol *functionName,
291 	    bool waitForFunction,
292 	    void *param1, void *param2,
293 	    void *param3, void *param4) APPLE_KEXT_OVERRIDE;
294 
295 	virtual IORangeAllocator * getPhysicalRangeAllocator(void);
296 
297 	virtual bool platformAdjustService(IOService *service);
298 
299 	virtual void PMRegisterDevice(IOService * theNub, IOService * theDevice);
300 	virtual void PMLog( const char *, unsigned long, unsigned long, unsigned long );
301 
302 	virtual bool hasPMFeature(unsigned long featureMask);
303 	virtual bool hasPrivPMFeature(unsigned long privFeatureMask);
304 	virtual int  numBatteriesSupported(void);
305 
306 	virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
307 
308 	virtual OSString* createSystemSerialNumberString(OSData* myProperty);
309 
310 	virtual IOReturn deregisterInterruptController(OSSymbol *name);
311 
312 	virtual void getUTCTimeOfDay( clock_sec_t * secs, clock_nsec_t * nsecs );
313 	virtual void setUTCTimeOfDay( clock_sec_t secs, clock_nsec_t nsecs );
314 	void publishPlatformUUIDAndSerial( void );
315 	void publishNVRAM( void );
316 
317 	virtual bool getTargetName( char * name, int maxLength );
318 	virtual bool getProductName( char * name, int maxLength );
319 
320 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 0);
321 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 1);
322 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 2);
323 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 3);
324 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 4);
325 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 5);
326 	OSMetaClassDeclareReservedUsedX86(IOPlatformExpert, 6);
327 
328 	OSMetaClassDeclareReservedUnused(IOPlatformExpert, 7);
329 	OSMetaClassDeclareReservedUnused(IOPlatformExpert, 8);
330 	OSMetaClassDeclareReservedUnused(IOPlatformExpert, 9);
331 	OSMetaClassDeclareReservedUnused(IOPlatformExpert, 10);
332 	OSMetaClassDeclareReservedUnused(IOPlatformExpert, 11);
333 };
334 
335 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
336 
337 class IODTNVRAM;
338 
339 class IODTPlatformExpert : public IOPlatformExpert
340 {
341 	OSDeclareAbstractStructors(IODTPlatformExpert);
342 
343 private:
344 	IODTNVRAM *dtNVRAM;
345 
346 	struct ExpansionData { };
347 	ExpansionData *iodtpe_reserved;
348 
349 public:
350 	virtual IOService * probe(  IOService *     provider,
351 	    SInt32    *     score ) APPLE_KEXT_OVERRIDE;
352 	virtual bool configure( IOService * provider ) APPLE_KEXT_OVERRIDE;
353 
354 	virtual void processTopLevel( IORegistryEntry * root );
355 	virtual const char * deleteList( void ) = 0;
356 	virtual const char * excludeList( void ) = 0;
357 	virtual IOService * createNub( IORegistryEntry * from );
358 	virtual bool createNubs( IOService * parent, LIBKERN_CONSUMED OSIterator * iter );
359 
360 	virtual bool compareNubName( const IOService * nub, OSString * name,
361 	    OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
362 
363 	virtual IOReturn getNubResources( IOService * nub ) APPLE_KEXT_OVERRIDE;
364 
365 	/*
366 	 * getModelName() and getMachineName() are deprecated. Use
367 	 * getTargetName() and getProductName() instead.
368 	 */
369 	virtual bool getModelName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
370 	virtual bool getMachineName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
371 
372 	virtual bool getTargetName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
373 	virtual bool getProductName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
374 
375 	virtual void registerNVRAMController( IONVRAMController * nvram ) APPLE_KEXT_OVERRIDE;
376 
377 	virtual int haltRestart(unsigned int type) APPLE_KEXT_OVERRIDE;
378 
379 /* virtual */ IOReturn readXPRAM(IOByteCount offset, UInt8 * buffer,
380 	    IOByteCount length);
381 
382 /* virtual */ IOReturn writeXPRAM(IOByteCount offset, UInt8 * buffer,
383 	    IOByteCount length);
384 
385 	virtual IOReturn readNVRAMProperty(
386 		IORegistryEntry * entry,
387 		const OSSymbol ** name, OSData ** value );
388 
389 	IOReturn readNVRAMProperty(
390 		IORegistryEntry * entry,
391 		OSSharedPtr<const OSSymbol>& name, OSSharedPtr<OSData>& value );
392 
393 	virtual IOReturn writeNVRAMProperty(
394 		IORegistryEntry * entry,
395 		const OSSymbol * name, OSData * value );
396 
397 // This returns a dictionary describing all the NVRAM partitions.
398 // The keys will be the partitionIDs of the form "0x52,nvram".
399 // The values will be OSNumbers of the partition's byte count.
400 /* virtual */ OSDictionary *getNVRAMPartitions(void);
401 
402 /* virtual */ IOReturn readNVRAMPartition(const OSSymbol * partitionID,
403 	    IOByteCount offset, UInt8 * buffer,
404 	    IOByteCount length);
405 
406 /* virtual */ IOReturn writeNVRAMPartition(const OSSymbol * partitionID,
407 	    IOByteCount offset, UInt8 * buffer,
408 	    IOByteCount length);
409 
410 	virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length) APPLE_KEXT_OVERRIDE;
411 	virtual OSString* createSystemSerialNumberString(OSData* myProperty) APPLE_KEXT_OVERRIDE;
412 
413 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 0);
414 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 1);
415 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 2);
416 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 3);
417 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 4);
418 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 5);
419 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 6);
420 	OSMetaClassDeclareReservedUnused(IODTPlatformExpert, 7);
421 };
422 
423 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
424 
425 /* generic root nub of service tree */
426 
427 class IOPlatformExpertDevice : public IOService
428 {
429 	OSDeclareDefaultStructors(IOPlatformExpertDevice);
430 
431 private:
432 	IOWorkLoop *workLoop;
433 
434 	struct ExpansionData { };
435 	ExpansionData *ioped_reserved __unused;
436 
437 public:
438 	virtual bool init(void *dtRoot);
439 	virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
440 
441 	virtual IOWorkLoop *getWorkLoop() const APPLE_KEXT_OVERRIDE;
442 	virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE;
443 
444 	virtual void free() APPLE_KEXT_OVERRIDE;
445 
446 	virtual IOReturn newUserClient( task_t owningTask, void * securityID,
447 	    UInt32 type, OSDictionary * properties,
448 	    IOUserClient ** handler) APPLE_KEXT_OVERRIDE;
449 
450 	bool startIOServiceMatching(void);
451 	void createNVRAM(void);
452 	void generatePlatformUUID(void);
453 	void configureDefaults(void);
454 
455 	OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 0);
456 	OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 1);
457 	OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 2);
458 	OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 3);
459 };
460 
461 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
462 
463 /* generic nub for motherboard devices */
464 
465 class IOPlatformDevice : public IOService
466 {
467 	OSDeclareDefaultStructors(IOPlatformDevice);
468 
469 	struct ExpansionData { };
470 	ExpansionData *iopd_reserved;
471 
472 public:
473 	virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
474 	virtual IOService * matchLocation( IOService * client ) APPLE_KEXT_OVERRIDE;
475 	virtual IOReturn getResources( void ) APPLE_KEXT_OVERRIDE;
476 
477 	OSMetaClassDeclareReservedUnused(IOPlatformDevice, 0);
478 	OSMetaClassDeclareReservedUnused(IOPlatformDevice, 1);
479 	OSMetaClassDeclareReservedUnused(IOPlatformDevice, 2);
480 	OSMetaClassDeclareReservedUnused(IOPlatformDevice, 3);
481 };
482 
483 #endif /* __cplusplus */
484 
485 #endif /* ! _IOKIT_IOPLATFORMEXPERT_H */
486