2 * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
5 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
27 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #ifndef _IOKIT_IONVRAM_H
31 #define _IOKIT_IONVRAM_H
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>
42 #define kIODTNVRAMOFPartitionName "common"
43 #define kIODTNVRAMXPRAMPartitionName "APL,MacOS75"
44 #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic"
45 #define kIODTNVRAMFreePartitionName "wwwwwwwwwwww"
46 #define kIODTNVRAMSystemPartitionName "secure"
48 #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */
50 enum IONVRAMVariableType
{
51 kOFVariableTypeBoolean
= 1,
52 kOFVariableTypeNumber
,
53 kOFVariableTypeString
,
57 enum IONVRAMOperation
{
58 kIONVRAMOperationRead
,
59 kIONVRAMOperationWrite
,
60 kIONVRAMOperationDelete
,
61 kIONVRAMOperationObliterate
,
62 kIONVRAMOperationReset
66 // Deprecated but still used in AppleEFIRuntime for now
67 kOFVariablePermRootOnly
= 0,
68 kOFVariablePermUserRead
,
69 kOFVariablePermUserWrite
,
70 kOFVariablePermKernelOnly
75 class IODTNVRAMVariables
;
77 class IODTNVRAM
: public IOService
79 OSDeclareDefaultStructors(IODTNVRAM
);
82 IONVRAMController
*_nvramController
;
83 OSPtr
<const OSSymbol
> _registryPropertiesKey
;
85 IOLock
*_variableLock
;
86 UInt32 _commonPartitionOffset
;
87 UInt32 _commonPartitionSize
;
89 IODTNVRAMVariables
*_commonService
;
90 OSPtr
<OSDictionary
> _commonDict
;
91 UInt32 _systemPartitionOffset
;
92 UInt32 _systemPartitionSize
;
94 IODTNVRAMVariables
*_systemService
;
95 OSPtr
<OSDictionary
> _systemDict
;
96 OSPtr
<OSDictionary
> _nvramPartitionOffsets
;
97 OSPtr
<OSDictionary
> _nvramPartitionLengths
;
99 SInt32 _lastDeviceSync
;
104 virtual UInt8
calculatePartitionChecksum(UInt8
*partitionHeader
);
105 virtual IOReturn
initVariables(void);
106 virtual UInt32
getOFVariableType(const char *propName
) const;
107 virtual UInt32
getOFVariableType(const OSSymbol
*propSymbol
) const;
108 virtual UInt32
getOFVariablePerm(const char *propName
) const;
109 virtual UInt32
getOFVariablePerm(const OSSymbol
*propSymbol
) const;
110 virtual bool getOWVariableInfo(UInt32 variableNumber
, const OSSymbol
**propSymbol
,
111 UInt32
*propType
, UInt32
*propOffset
);
112 virtual bool convertPropToObject(UInt8
*propName
, UInt32 propNameLength
,
113 UInt8
*propData
, UInt32 propDataLength
,
114 LIBKERN_RETURNS_RETAINED
const OSSymbol
**propSymbol
,
115 LIBKERN_RETURNS_RETAINED OSObject
**propObject
);
116 bool convertPropToObject(UInt8
*propName
, UInt32 propNameLength
,
117 UInt8
*propData
, UInt32 propDataLength
,
118 OSSharedPtr
<const OSSymbol
>& propSymbol
,
119 OSSharedPtr
<OSObject
>& propObject
);
120 virtual bool convertObjectToProp(UInt8
*buffer
, UInt32
*length
,
121 const OSSymbol
*propSymbol
, OSObject
*propObject
);
122 virtual UInt16
generateOWChecksum(UInt8
*buffer
);
123 virtual bool validateOWChecksum(UInt8
*buffer
);
124 virtual void updateOWBootArgs(const OSSymbol
*key
, OSObject
*value
);
125 virtual bool searchNVRAMProperty(struct IONVRAMDescriptor
*hdr
,
128 virtual IOReturn
readNVRAMPropertyType0(IORegistryEntry
*entry
,
129 const OSSymbol
**name
,
131 virtual IOReturn
writeNVRAMPropertyType0(IORegistryEntry
*entry
,
132 const OSSymbol
*name
,
135 virtual OSPtr
<OSData
> unescapeBytesToData(const UInt8
*bytes
, UInt32 length
);
136 virtual OSPtr
<OSData
> escapeDataToData(OSData
* value
);
138 virtual IOReturn
readNVRAMPropertyType1(IORegistryEntry
*entry
,
139 const OSSymbol
**name
,
141 virtual IOReturn
writeNVRAMPropertyType1(IORegistryEntry
*entry
,
142 const OSSymbol
*name
,
145 UInt32
getNVRAMSize(void);
146 void initNVRAMImage(void);
147 void initProxyData(void);
148 IOReturn
syncVariables(void);
149 IOReturn
setPropertyInternal(const OSSymbol
*aKey
, OSObject
*anObject
);
150 IOReturn
removePropertyInternal(const OSSymbol
*aKey
);
151 IOReturn
chooseDictionary(IONVRAMOperation operation
, const uuid_t
*varGuid
,
152 const char *variableName
, OSDictionary
**dict
) const;
153 bool handleSpecialVariables(const char *name
, uuid_t
*guid
, OSObject
*obj
, IOReturn
*error
);
156 virtual bool init(IORegistryEntry
*old
, const IORegistryPlane
*plane
) APPLE_KEXT_OVERRIDE
;
158 virtual void registerNVRAMController(IONVRAMController
*nvram
);
160 virtual void sync(void);
161 virtual IOReturn
syncOFVariables(void);
163 virtual bool serializeProperties(OSSerialize
*s
) const APPLE_KEXT_OVERRIDE
;
164 virtual OSPtr
<OSObject
> copyProperty(const OSSymbol
*aKey
) const APPLE_KEXT_OVERRIDE
;
165 virtual OSPtr
<OSObject
> copyProperty(const char *aKey
) const APPLE_KEXT_OVERRIDE
;
166 virtual OSObject
*getProperty(const OSSymbol
*aKey
) const APPLE_KEXT_OVERRIDE
;
167 virtual OSObject
*getProperty(const char *aKey
) const APPLE_KEXT_OVERRIDE
;
168 virtual bool setProperty(const OSSymbol
*aKey
, OSObject
*anObject
) APPLE_KEXT_OVERRIDE
;
169 virtual void removeProperty(const OSSymbol
*aKey
) APPLE_KEXT_OVERRIDE
;
170 virtual IOReturn
setProperties(OSObject
*properties
) APPLE_KEXT_OVERRIDE
;
172 virtual IOReturn
readXPRAM(IOByteCount offset
, UInt8
*buffer
,
174 virtual IOReturn
writeXPRAM(IOByteCount offset
, UInt8
*buffer
,
177 virtual IOReturn
readNVRAMProperty(IORegistryEntry
*entry
,
178 const OSSymbol
**name
,
180 virtual IOReturn
writeNVRAMProperty(IORegistryEntry
*entry
,
181 const OSSymbol
*name
,
184 virtual OSDictionary
*getNVRAMPartitions(void);
186 virtual IOReturn
readNVRAMPartition(const OSSymbol
*partitionID
,
187 IOByteCount offset
, UInt8
*buffer
,
190 virtual IOReturn
writeNVRAMPartition(const OSSymbol
*partitionID
,
191 IOByteCount offset
, UInt8
*buffer
,
194 virtual IOByteCount
savePanicInfo(UInt8
*buffer
, IOByteCount length
);
195 virtual bool safeToSync(void);
196 void syncInternal(bool rateLimit
);
199 #endif /* __cplusplus */
201 #endif /* !_IOKIT_IONVRAM_H */