]>
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@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 18 | * |
2d21ac55 A |
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. | |
0a7de745 | 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 |
f427ee49 | 34 | #include <libkern/c++/OSPtr.h> |
91447636 | 35 | #include <IOKit/IOKitKeys.h> |
1c79356b A |
36 | #include <IOKit/IOService.h> |
37 | #include <IOKit/IODeviceTreeSupport.h> | |
38 | #include <IOKit/nvram/IONVRAMController.h> | |
6d2010ae | 39 | #endif /* __cplusplus */ |
f427ee49 | 40 | #include <uuid/uuid.h> |
d52fe63f A |
41 | |
42 | #define kIODTNVRAMOFPartitionName "common" | |
43 | #define kIODTNVRAMXPRAMPartitionName "APL,MacOS75" | |
9bccf70c | 44 | #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic" |
d52fe63f | 45 | #define kIODTNVRAMFreePartitionName "wwwwwwwwwwww" |
f427ee49 | 46 | #define kIODTNVRAMSystemPartitionName "secure" |
d52fe63f | 47 | |
6d2010ae A |
48 | #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */ |
49 | ||
f427ee49 | 50 | enum IONVRAMVariableType { |
0a7de745 A |
51 | kOFVariableTypeBoolean = 1, |
52 | kOFVariableTypeNumber, | |
53 | kOFVariableTypeString, | |
54 | kOFVariableTypeData | |
1c79356b A |
55 | }; |
56 | ||
f427ee49 A |
57 | enum IONVRAMOperation { |
58 | kIONVRAMOperationRead, | |
59 | kIONVRAMOperationWrite, | |
60 | kIONVRAMOperationDelete, | |
61 | kIONVRAMOperationObliterate, | |
62 | kIONVRAMOperationReset | |
63 | }; | |
64 | ||
1c79356b | 65 | enum { |
f427ee49 | 66 | // Deprecated but still used in AppleEFIRuntime for now |
0a7de745 A |
67 | kOFVariablePermRootOnly = 0, |
68 | kOFVariablePermUserRead, | |
69 | kOFVariablePermUserWrite, | |
70 | kOFVariablePermKernelOnly | |
1c79356b A |
71 | }; |
72 | ||
6d2010ae A |
73 | #ifdef __cplusplus |
74 | ||
f427ee49 A |
75 | class IODTNVRAMVariables; |
76 | ||
1c79356b A |
77 | class IODTNVRAM : public IOService |
78 | { | |
0a7de745 A |
79 | OSDeclareDefaultStructors(IODTNVRAM); |
80 | ||
1c79356b | 81 | private: |
c3c9b80d A |
82 | friend class IODTNVRAMVariables; |
83 | ||
f427ee49 A |
84 | IONVRAMController *_nvramController; |
85 | OSPtr<const OSSymbol> _registryPropertiesKey; | |
86 | UInt8 *_nvramImage; | |
c3c9b80d | 87 | IORWLock *_variableLock; |
2a1bd2d3 | 88 | IOLock *_controllerLock; |
f427ee49 A |
89 | UInt32 _commonPartitionOffset; |
90 | UInt32 _commonPartitionSize; | |
91 | UInt8 *_commonImage; | |
92 | IODTNVRAMVariables *_commonService; | |
93 | OSPtr<OSDictionary> _commonDict; | |
94 | UInt32 _systemPartitionOffset; | |
95 | UInt32 _systemPartitionSize; | |
96 | UInt8 *_systemImage; | |
97 | IODTNVRAMVariables *_systemService; | |
98 | OSPtr<OSDictionary> _systemDict; | |
99 | OSPtr<OSDictionary> _nvramPartitionOffsets; | |
100 | OSPtr<OSDictionary> _nvramPartitionLengths; | |
101 | bool _systemPanicked; | |
102 | SInt32 _lastDeviceSync; | |
103 | bool _freshInterval; | |
104 | bool _isProxied; | |
105 | UInt32 _nvramSize; | |
0a7de745 A |
106 | |
107 | virtual UInt8 calculatePartitionChecksum(UInt8 *partitionHeader); | |
f427ee49 A |
108 | virtual IOReturn initVariables(void); |
109 | virtual UInt32 getOFVariableType(const char *propName) const; | |
0a7de745 | 110 | virtual UInt32 getOFVariableType(const OSSymbol *propSymbol) const; |
f427ee49 | 111 | virtual UInt32 getOFVariablePerm(const char *propName) const; |
0a7de745 A |
112 | virtual UInt32 getOFVariablePerm(const OSSymbol *propSymbol) const; |
113 | virtual bool getOWVariableInfo(UInt32 variableNumber, const OSSymbol **propSymbol, | |
114 | UInt32 *propType, UInt32 *propOffset); | |
115 | virtual bool convertPropToObject(UInt8 *propName, UInt32 propNameLength, | |
116 | UInt8 *propData, UInt32 propDataLength, | |
cb323159 A |
117 | LIBKERN_RETURNS_RETAINED const OSSymbol **propSymbol, |
118 | LIBKERN_RETURNS_RETAINED OSObject **propObject); | |
f427ee49 A |
119 | bool convertPropToObject(UInt8 *propName, UInt32 propNameLength, |
120 | UInt8 *propData, UInt32 propDataLength, | |
121 | OSSharedPtr<const OSSymbol>& propSymbol, | |
122 | OSSharedPtr<OSObject>& propObject); | |
0a7de745 A |
123 | virtual bool convertObjectToProp(UInt8 *buffer, UInt32 *length, |
124 | const OSSymbol *propSymbol, OSObject *propObject); | |
125 | virtual UInt16 generateOWChecksum(UInt8 *buffer); | |
126 | virtual bool validateOWChecksum(UInt8 *buffer); | |
127 | virtual void updateOWBootArgs(const OSSymbol *key, OSObject *value); | |
128 | virtual bool searchNVRAMProperty(struct IONVRAMDescriptor *hdr, | |
129 | UInt32 *where); | |
130 | ||
131 | virtual IOReturn readNVRAMPropertyType0(IORegistryEntry *entry, | |
132 | const OSSymbol **name, | |
133 | OSData **value); | |
134 | virtual IOReturn writeNVRAMPropertyType0(IORegistryEntry *entry, | |
135 | const OSSymbol *name, | |
136 | OSData * value); | |
137 | ||
f427ee49 A |
138 | virtual OSPtr<OSData> unescapeBytesToData(const UInt8 *bytes, UInt32 length); |
139 | virtual OSPtr<OSData> escapeDataToData(OSData * value); | |
0a7de745 A |
140 | |
141 | virtual IOReturn readNVRAMPropertyType1(IORegistryEntry *entry, | |
142 | const OSSymbol **name, | |
143 | OSData **value); | |
144 | virtual IOReturn writeNVRAMPropertyType1(IORegistryEntry *entry, | |
145 | const OSSymbol *name, | |
146 | OSData *value); | |
147 | ||
f427ee49 | 148 | UInt32 getNVRAMSize(void); |
0a7de745 A |
149 | void initNVRAMImage(void); |
150 | void initProxyData(void); | |
2a1bd2d3 | 151 | IOReturn serializeVariables(void); |
cb323159 | 152 | IOReturn setPropertyInternal(const OSSymbol *aKey, OSObject *anObject); |
f427ee49 A |
153 | IOReturn removePropertyInternal(const OSSymbol *aKey); |
154 | IOReturn chooseDictionary(IONVRAMOperation operation, const uuid_t *varGuid, | |
155 | const char *variableName, OSDictionary **dict) const; | |
c3c9b80d A |
156 | IOReturn flushDict(const uuid_t *guid, IONVRAMOperation op); |
157 | bool handleSpecialVariables(const char *name, const uuid_t *guid, const OSObject *obj, IOReturn *error); | |
158 | OSSharedPtr<OSObject> copyPropertyWithGUIDAndName(const uuid_t *guid, const char *name) const; | |
159 | IOReturn removePropertyWithGUIDAndName(const uuid_t *guid, const char *name); | |
160 | IOReturn setPropertyWithGUIDAndName(const uuid_t *guid, const char *name, OSObject *anObject); | |
0a7de745 | 161 | |
1c79356b | 162 | public: |
0a7de745 A |
163 | virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE; |
164 | ||
165 | virtual void registerNVRAMController(IONVRAMController *nvram); | |
166 | ||
167 | virtual void sync(void); | |
f427ee49 | 168 | virtual IOReturn syncOFVariables(void); |
0a7de745 A |
169 | |
170 | virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE; | |
f427ee49 A |
171 | virtual OSPtr<OSObject> copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
172 | virtual OSPtr<OSObject> copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; | |
0a7de745 A |
173 | virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
174 | virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; | |
175 | virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE; | |
176 | virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE; | |
177 | virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE; | |
178 | ||
179 | virtual IOReturn readXPRAM(IOByteCount offset, UInt8 *buffer, | |
180 | IOByteCount length); | |
181 | virtual IOReturn writeXPRAM(IOByteCount offset, UInt8 *buffer, | |
182 | IOByteCount length); | |
183 | ||
184 | virtual IOReturn readNVRAMProperty(IORegistryEntry *entry, | |
185 | const OSSymbol **name, | |
186 | OSData **value); | |
187 | virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry, | |
188 | const OSSymbol *name, | |
189 | OSData *value); | |
190 | ||
191 | virtual OSDictionary *getNVRAMPartitions(void); | |
192 | ||
193 | virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID, | |
194 | IOByteCount offset, UInt8 *buffer, | |
195 | IOByteCount length); | |
196 | ||
197 | virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID, | |
198 | IOByteCount offset, UInt8 *buffer, | |
199 | IOByteCount length); | |
200 | ||
201 | virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length); | |
202 | virtual bool safeToSync(void); | |
203 | void syncInternal(bool rateLimit); | |
1c79356b A |
204 | }; |
205 | ||
6d2010ae A |
206 | #endif /* __cplusplus */ |
207 | ||
1c79356b | 208 | #endif /* !_IOKIT_IONVRAM_H */ |