]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e A |
2 | * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved. |
3 | * Copyright (c) 2007-2012 Apple Inc. All rights reserved. | |
1c79356b | 4 | * |
2d21ac55 | 5 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 6 | * |
2d21ac55 A |
7 | * This file contains Original Code and/or Modifications of Original Code |
8 | * as defined in and that are subject to the Apple Public Source License | |
9 | * Version 2.0 (the 'License'). You may not use this file except in | |
10 | * compliance with the License. The rights granted to you under the License | |
11 | * may not be used to create, or enable the creation or redistribution of, | |
12 | * unlawful or unlicensed copies of an Apple operating system, or to | |
13 | * circumvent, violate, or enable the circumvention or violation of, any | |
14 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 15 | * |
2d21ac55 A |
16 | * Please obtain a copy of the License at |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
18 | * | |
19 | * The Original Code and all software distributed under the License are | |
20 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
21 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
22 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
23 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
24 | * Please see the License for the specific language governing rights and | |
25 | * limitations under the License. | |
8f6c56a5 | 26 | * |
2d21ac55 | 27 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
28 | */ |
29 | ||
30 | #ifndef _IOKIT_IONVRAM_H | |
31 | #define _IOKIT_IONVRAM_H | |
32 | ||
6d2010ae | 33 | #ifdef __cplusplus |
91447636 | 34 | #include <IOKit/IOKitKeys.h> |
1c79356b A |
35 | #include <IOKit/IOService.h> |
36 | #include <IOKit/IODeviceTreeSupport.h> | |
37 | #include <IOKit/nvram/IONVRAMController.h> | |
6d2010ae | 38 | #endif /* __cplusplus */ |
d52fe63f A |
39 | |
40 | #define kIODTNVRAMOFPartitionName "common" | |
41 | #define kIODTNVRAMXPRAMPartitionName "APL,MacOS75" | |
9bccf70c | 42 | #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic" |
d52fe63f A |
43 | #define kIODTNVRAMFreePartitionName "wwwwwwwwwwww" |
44 | ||
6d2010ae A |
45 | #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */ |
46 | ||
1c79356b A |
47 | enum { |
48 | kIODTNVRAMImageSize = 0x2000, | |
49 | kIODTNVRAMXPRAMSize = 0x0100, | |
50 | kIODTNVRAMNameRegistrySize = 0x0400 | |
51 | }; | |
52 | ||
53 | enum { | |
54 | kOFVariableTypeBoolean = 1, | |
55 | kOFVariableTypeNumber, | |
56 | kOFVariableTypeString, | |
57 | kOFVariableTypeData | |
58 | }; | |
59 | ||
60 | enum { | |
61 | kOFVariablePermRootOnly = 0, | |
62 | kOFVariablePermUserRead, | |
cf7d32b8 A |
63 | kOFVariablePermUserWrite, |
64 | kOFVariablePermKernelOnly | |
1c79356b A |
65 | }; |
66 | ||
6d2010ae A |
67 | #ifdef __cplusplus |
68 | ||
1c79356b A |
69 | class IODTNVRAM : public IOService |
70 | { | |
71 | OSDeclareDefaultStructors(IODTNVRAM); | |
72 | ||
73 | private: | |
74 | IONVRAMController *_nvramController; | |
75 | const OSSymbol *_registryPropertiesKey; | |
76 | UInt8 *_nvramImage; | |
3e170ce0 | 77 | __unused bool _nvramImageDirty; |
1c79356b A |
78 | UInt32 _ofPartitionOffset; |
79 | UInt32 _ofPartitionSize; | |
80 | UInt8 *_ofImage; | |
3e170ce0 | 81 | __unused bool _ofImageDirty; |
1c79356b | 82 | OSDictionary *_ofDict; |
d52fe63f A |
83 | OSDictionary *_nvramPartitionOffsets; |
84 | OSDictionary *_nvramPartitionLengths; | |
fe8ab488 A |
85 | UInt32 _resv0 __unused; |
86 | UInt32 _resv1 __unused; | |
87 | IOLock *_ofLock; | |
88 | UInt32 _resv2 __unused; | |
89 | UInt32 _resv3 __unused; | |
90 | UInt8 *_resv4 __unused; | |
9bccf70c A |
91 | UInt32 _piPartitionOffset; |
92 | UInt32 _piPartitionSize; | |
93 | UInt8 *_piImage; | |
94 | bool _systemPaniced; | |
6d2010ae A |
95 | SInt32 _lastDeviceSync; |
96 | bool _freshInterval; | |
39236c6e | 97 | bool _isProxied; |
1c79356b | 98 | |
9bccf70c | 99 | virtual UInt8 calculatePartitionChecksum(UInt8 *partitionHeader); |
1c79356b | 100 | virtual IOReturn initOFVariables(void); |
91447636 | 101 | public: |
1c79356b | 102 | virtual IOReturn syncOFVariables(void); |
91447636 | 103 | private: |
1c79356b A |
104 | virtual UInt32 getOFVariableType(const OSSymbol *propSymbol) const; |
105 | virtual UInt32 getOFVariablePerm(const OSSymbol *propSymbol) const; | |
106 | virtual bool getOWVariableInfo(UInt32 variableNumber, const OSSymbol **propSymbol, | |
107 | UInt32 *propType, UInt32 *propOffset); | |
108 | virtual bool convertPropToObject(UInt8 *propName, UInt32 propNameLength, | |
109 | UInt8 *propData, UInt32 propDataLength, | |
110 | const OSSymbol **propSymbol, | |
111 | OSObject **propObject); | |
112 | virtual bool convertObjectToProp(UInt8 *buffer, UInt32 *length, | |
113 | const OSSymbol *propSymbol, OSObject *propObject); | |
114 | virtual UInt16 generateOWChecksum(UInt8 *buffer); | |
115 | virtual bool validateOWChecksum(UInt8 *buffer); | |
116 | virtual void updateOWBootArgs(const OSSymbol *key, OSObject *value); | |
117 | virtual bool searchNVRAMProperty(struct IONVRAMDescriptor *hdr, | |
118 | UInt32 *where); | |
119 | ||
120 | virtual IOReturn readNVRAMPropertyType0(IORegistryEntry *entry, | |
121 | const OSSymbol **name, | |
122 | OSData **value); | |
123 | virtual IOReturn writeNVRAMPropertyType0(IORegistryEntry *entry, | |
124 | const OSSymbol *name, | |
125 | OSData * value); | |
126 | ||
91447636 | 127 | virtual OSData *unescapeBytesToData(const UInt8 *bytes, UInt32 length); |
1c79356b A |
128 | virtual OSData *escapeDataToData(OSData * value); |
129 | ||
130 | virtual IOReturn readNVRAMPropertyType1(IORegistryEntry *entry, | |
131 | const OSSymbol **name, | |
132 | OSData **value); | |
133 | virtual IOReturn writeNVRAMPropertyType1(IORegistryEntry *entry, | |
134 | const OSSymbol *name, | |
135 | OSData *value); | |
136 | ||
39236c6e A |
137 | void initNVRAMImage(void); |
138 | void initProxyData(void); | |
139 | ||
1c79356b | 140 | public: |
3e170ce0 | 141 | virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE; |
1c79356b A |
142 | |
143 | virtual void registerNVRAMController(IONVRAMController *nvram); | |
144 | ||
145 | virtual void sync(void); | |
146 | ||
3e170ce0 A |
147 | virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE; |
148 | virtual OSObject *copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; | |
149 | virtual OSObject *copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; | |
150 | virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; | |
151 | virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; | |
152 | virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE; | |
153 | virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE; | |
154 | virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE; | |
1c79356b A |
155 | |
156 | virtual IOReturn readXPRAM(IOByteCount offset, UInt8 *buffer, | |
157 | IOByteCount length); | |
158 | virtual IOReturn writeXPRAM(IOByteCount offset, UInt8 *buffer, | |
159 | IOByteCount length); | |
160 | ||
161 | virtual IOReturn readNVRAMProperty(IORegistryEntry *entry, | |
162 | const OSSymbol **name, | |
163 | OSData **value); | |
164 | virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry, | |
165 | const OSSymbol *name, | |
166 | OSData *value); | |
d52fe63f A |
167 | |
168 | virtual OSDictionary *getNVRAMPartitions(void); | |
169 | ||
170 | virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID, | |
171 | IOByteCount offset, UInt8 *buffer, | |
172 | IOByteCount length); | |
173 | ||
174 | virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID, | |
175 | IOByteCount offset, UInt8 *buffer, | |
176 | IOByteCount length); | |
9bccf70c A |
177 | |
178 | virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length); | |
6d2010ae | 179 | virtual bool safeToSync(void); |
3e170ce0 | 180 | void syncInternal(bool rateLimit); |
1c79356b A |
181 | }; |
182 | ||
6d2010ae A |
183 | #endif /* __cplusplus */ |
184 | ||
1c79356b | 185 | #endif /* !_IOKIT_IONVRAM_H */ |