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