]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOPlatformExpert.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / iokit / IOKit / IOPlatformExpert.h
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 1998-2019 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
0a7de745 29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
1c79356b
A
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>
f427ee49 44#include <libkern/c++/OSPtr.h>
1c79356b
A
45
46extern "C" {
f427ee49
A
47#else
48#include <kern/clock.h>
1c79356b
A
49#endif
50
b0d623f7
A
51#include <libkern/OSTypes.h>
52
5c9f4661 53typedef enum {
0a7de745
A
54 kCoprocessorVersionNone = 0x00000000,
55 kCoprocessorVersion1 = 0x00010000,
56 kCoprocessorVersion2 = 0x00020000,
5c9f4661
A
57} coprocessor_type_t;
58
59
f427ee49
A
60/*
61 * PEGetMachineName() and PEGetModelName() are inconsistent across
62 * architectures, and considered deprecated.
63 * PEGetTargetName() and PEGetProductName() instead.
64 */
1c79356b
A
65extern boolean_t PEGetMachineName( char * name, int maxLength );
66extern boolean_t PEGetModelName( char * name, int maxLength );
f427ee49
A
67
68extern boolean_t PEGetTargetName( char * name, int maxLength );
69extern boolean_t PEGetProductName( char * name, int maxLength );
1c79356b
A
70extern int PEGetPlatformEpoch( void );
71
72enum {
0a7de745
A
73 kPEHaltCPU,
74 kPERestartCPU,
75 kPEHangCPU,
76 kPEUPSDelayHaltCPU,
77 kPEPanicRestartCPU,
78 kPEPanicSync,
79 kPEPagingOff,
80 kPEPanicBegin,
81 kPEPanicEnd,
c3c9b80d
A
82 kPEPanicRestartCPUNoCallouts,
83 kPEPanicDiagnosticsDone,
1c79356b 84};
f427ee49
A
85
86/* Bitmask of details related to panic callouts */
87#define kPanicDetailsForcePowerOff 0x1
88
1c79356b
A
89extern int (*PE_halt_restart)(unsigned int type);
90extern int PEHaltRestart(unsigned int type);
91
a39ff7e2 92#ifdef XNU_KERNEL_PRIVATE
f427ee49
A
93
94extern int PEHaltRestartInternal(unsigned int type, uint32_t details);
95
a39ff7e2
A
96enum {
97 kIOSystemShutdownNotificationStageProcessExit = 0,
98 kIOSystemShutdownNotificationStageRootUnmount = 1,
c3c9b80d 99 kIOSystemShutdownNotificationTerminateDEXTs = 2,
a39ff7e2
A
100};
101extern void IOSystemShutdownNotification(int stage);
cb323159
A
102
103extern uint32_t gEnforceQuiesceSafety;
a39ff7e2
A
104#endif /* XNU_KERNEL_PRIVATE */
105
cb323159
A
106#ifdef KERNEL_PRIVATE
107extern boolean_t IOPMRootDomainGetWillShutdown(void);
f427ee49 108extern void PEInitiatePanic(void);
cb323159
A
109#endif /* KERNEL_PRIVATE */
110
9bccf70c 111// Save the Panic Info. Returns the number of bytes saved.
b0d623f7 112extern UInt32 PESavePanicInfo(UInt8 *buffer, UInt32 length);
5c9f4661
A
113extern void PESavePanicInfoAction(void *buffer, UInt32 offset, UInt32 length);
114
0a7de745 115/*
5c9f4661
A
116 * SMC requires that all data is flushed in multiples of 16 bytes at 16 byte
117 * boundaries.
118 */
119#define PANIC_FLUSH_BOUNDARY 16
9bccf70c 120
1c79356b
A
121extern long PEGetGMTTimeOfDay( void );
122extern void PESetGMTTimeOfDay( long secs );
fe8ab488
A
123extern void PEGetUTCTimeOfDay( clock_sec_t * secs, clock_usec_t * usecs );
124extern void PESetUTCTimeOfDay( clock_sec_t secs, clock_usec_t usecs );
125
6d2010ae
A
126/* unless it's a "well-known" property, these will read/write out the value as raw data */
127
3e170ce0 128extern boolean_t PEWriteNVRAMBooleanProperty(const char *symbol, boolean_t value);
6d2010ae 129extern boolean_t PEWriteNVRAMProperty(const char *symbol, const void *value, const unsigned int len);
0a7de745 130extern boolean_t PEWriteNVRAMPropertyWithCopy(const char *symbol, const void *value, const unsigned int len);
6d2010ae
A
131
132extern boolean_t PEReadNVRAMProperty(const char *symbol, void *value, unsigned int *len);
133
39236c6e
A
134extern boolean_t PERemoveNVRAMProperty(const char *symbol);
135
5c9f4661
A
136extern coprocessor_type_t PEGetCoprocessorVersion( void );
137
1c79356b
A
138#ifdef __cplusplus
139} /* extern "C" */
140
55e303ae
A
141#define kIOPlatformMapperPresentKey "IOPlatformMapperPresent"
142
2d21ac55 143
5c9f4661
A
144
145
2d21ac55
A
146extern OSSymbol * gPlatformInterruptControllerName;
147
cb323159
A
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 */
156extern 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 */
165extern 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 */
175extern 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 */
185extern 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 */
195extern 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 */
211extern const OSSymbol *gIOPlatformPanicActionKey;
1c79356b
A
212
213class IORangeAllocator;
214class IONVRAMController;
215class IOPMrootDomain;
216
217class IOPlatformExpert : public IOService
218{
0a7de745 219 OSDeclareDefaultStructors(IOPlatformExpert);
1c79356b
A
220
221private:
0a7de745
A
222 long _peBootROMType;
223 long _peChipSetType;
224 long _peMachineType;
1c79356b
A
225
226protected:
0a7de745
A
227 IOPMrootDomain * root;
228 int _pePMFeatures;
229 int _pePrivPMFeatures;
230 int _peNumBatteriesSupported;
231 OSArray * thePowerTree;
1c79356b 232
0a7de745
A
233 bool searchingForAdditionalParents;
234 OSNumber * multipleParentKeyValue;
235 int numInstancesRegistered;
1c79356b 236
0a7de745
A
237 struct ExpansionData { };
238 ExpansionData *iope_reserved __unused;
1c79356b 239
0a7de745
A
240 virtual void setBootROMType(long peBootROMType);
241 virtual void setChipSetType(long peChipSetType);
242 virtual void setMachineType(long peMachineType);
1c79356b 243
0a7de745
A
244 virtual bool CheckSubTree(OSArray * inSubTree, IOService * theNub, IOService * theDevice, OSDictionary * theParent);
245 virtual bool RegisterServiceInTree(IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider);
1c79356b 246
0a7de745 247 virtual void PMInstantiatePowerDomains( void );
1c79356b
A
248
249public:
0a7de745
A
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,
cb323159 256 OSString ** matched = NULL ) const;
f427ee49
A
257 bool compareNubName( const IOService * nub, OSString * name,
258 OSSharedPtr<OSString>& matched ) const;
0a7de745 259 virtual IOReturn getNubResources( IOService * nub );
1c79356b 260
0a7de745
A
261 virtual long getBootROMType(void);
262 virtual long getChipSetType(void);
263 virtual long getMachineType(void);
1c79356b 264
f427ee49
A
265 /*
266 * getModelName() and getMachineName() are deprecated for direct
267 * use. Use getTargetName() and getProductName() instead.
268 */
0a7de745
A
269 virtual bool getModelName( char * name, int maxLength );
270 virtual bool getMachineName( char * name, int maxLength );
1c79356b 271
0a7de745
A
272 virtual int haltRestart(unsigned int type);
273 virtual void sleepKernel(void);
1c79356b 274
0a7de745
A
275 virtual long getGMTTimeOfDay( void );
276 virtual void setGMTTimeOfDay( long secs );
1c79356b 277
0a7de745
A
278 virtual IOReturn getConsoleInfo( PE_Video * consoleInfo );
279 virtual IOReturn setConsoleInfo( PE_Video * consoleInfo, unsigned int op );
1c79356b 280
0a7de745 281 virtual void registerNVRAMController( IONVRAMController * nvram );
1c79356b 282
0a7de745
A
283 virtual IOReturn registerInterruptController(OSSymbol *name, IOInterruptController *interruptController);
284 virtual LIBKERN_RETURNS_NOT_RETAINED IOInterruptController *
285 lookUpInterruptController(OSSymbol *name);
1c79356b 286
0a7de745
A
287 virtual void setCPUInterruptProperties(IOService *service);
288 virtual bool atInterruptLevel(void);
1c79356b 289
0a7de745
A
290 virtual IOReturn callPlatformFunction(const OSSymbol *functionName,
291 bool waitForFunction,
292 void *param1, void *param2,
293 void *param3, void *param4) APPLE_KEXT_OVERRIDE;
1c79356b 294
0a7de745 295 virtual IORangeAllocator * getPhysicalRangeAllocator(void);
1c79356b 296
0a7de745 297 virtual bool platformAdjustService(IOService *service);
1c79356b 298
0a7de745
A
299 virtual void PMRegisterDevice(IOService * theNub, IOService * theDevice);
300 virtual void PMLog( const char *, unsigned long, unsigned long, unsigned long );
1c79356b 301
0a7de745
A
302 virtual bool hasPMFeature(unsigned long featureMask);
303 virtual bool hasPrivPMFeature(unsigned long privFeatureMask);
304 virtual int numBatteriesSupported(void);
1c79356b 305
0a7de745 306 virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
9bccf70c 307
0a7de745 308 virtual OSString* createSystemSerialNumberString(OSData* myProperty);
fe8ab488 309
0a7de745 310 virtual IOReturn deregisterInterruptController(OSSymbol *name);
fe8ab488 311
0a7de745
A
312 virtual void getUTCTimeOfDay( clock_sec_t * secs, clock_nsec_t * nsecs );
313 virtual void setUTCTimeOfDay( clock_sec_t secs, clock_nsec_t nsecs );
f427ee49
A
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);
fe8ab488 327
0a7de745
A
328 OSMetaClassDeclareReservedUnused(IOPlatformExpert, 7);
329 OSMetaClassDeclareReservedUnused(IOPlatformExpert, 8);
330 OSMetaClassDeclareReservedUnused(IOPlatformExpert, 9);
331 OSMetaClassDeclareReservedUnused(IOPlatformExpert, 10);
332 OSMetaClassDeclareReservedUnused(IOPlatformExpert, 11);
1c79356b
A
333};
334
335/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
336
337class IODTNVRAM;
338
339class IODTPlatformExpert : public IOPlatformExpert
340{
0a7de745 341 OSDeclareAbstractStructors(IODTPlatformExpert);
1c79356b
A
342
343private:
0a7de745 344 IODTNVRAM *dtNVRAM;
1c79356b 345
0a7de745
A
346 struct ExpansionData { };
347 ExpansionData *iodtpe_reserved;
1c79356b
A
348
349public:
0a7de745
A
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,
cb323159 361 OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
0a7de745
A
362
363 virtual IOReturn getNubResources( IOService * nub ) APPLE_KEXT_OVERRIDE;
364
f427ee49
A
365 /*
366 * getModelName() and getMachineName() are deprecated. Use
367 * getTargetName() and getProductName() instead.
368 */
0a7de745
A
369 virtual bool getModelName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
370 virtual bool getMachineName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
371
f427ee49
A
372 virtual bool getTargetName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
373 virtual bool getProductName( char * name, int maxLength ) APPLE_KEXT_OVERRIDE;
374
0a7de745
A
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
f427ee49
A
389 IOReturn readNVRAMProperty(
390 IORegistryEntry * entry,
391 OSSharedPtr<const OSSymbol>& name, OSSharedPtr<OSData>& value );
392
0a7de745
A
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);
1c79356b
A
421};
422
423/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
424
425/* generic root nub of service tree */
426
427class IOPlatformExpertDevice : public IOService
428{
cb323159 429 OSDeclareDefaultStructors(IOPlatformExpertDevice);
1c79356b
A
430
431private:
0a7de745 432 IOWorkLoop *workLoop;
1c79356b 433
0a7de745
A
434 struct ExpansionData { };
435 ExpansionData *ioped_reserved __unused;
1c79356b
A
436
437public:
f427ee49 438 virtual bool init(void *dtRoot);
cb323159 439 virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
3e170ce0 440
0a7de745
A
441 virtual IOWorkLoop *getWorkLoop() const APPLE_KEXT_OVERRIDE;
442 virtual IOReturn setProperties( OSObject * properties ) APPLE_KEXT_OVERRIDE;
3e170ce0 443
0a7de745 444 virtual void free() APPLE_KEXT_OVERRIDE;
1c79356b 445
0a7de745
A
446 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
447 UInt32 type, OSDictionary * properties,
448 IOUserClient ** handler) APPLE_KEXT_OVERRIDE;
1c79356b 449
f427ee49
A
450 bool startIOServiceMatching(void);
451 void createNVRAM(void);
452 void generatePlatformUUID(void);
453 void configureDefaults(void);
1c79356b 454
0a7de745
A
455 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 0);
456 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 1);
457 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 2);
458 OSMetaClassDeclareReservedUnused(IOPlatformExpertDevice, 3);
1c79356b
A
459};
460
461/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
462
463/* generic nub for motherboard devices */
464
465class IOPlatformDevice : public IOService
466{
cb323159 467 OSDeclareDefaultStructors(IOPlatformDevice);
1c79356b 468
0a7de745
A
469 struct ExpansionData { };
470 ExpansionData *iopd_reserved;
1c79356b
A
471
472public:
cb323159 473 virtual bool compareName( OSString * name, OSString ** matched = NULL ) const APPLE_KEXT_OVERRIDE;
0a7de745
A
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);
1c79356b
A
481};
482
483#endif /* __cplusplus */
484
485#endif /* ! _IOKIT_IOPLATFORMEXPERT_H */