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 <IOKit/IOKitKeys.h>
35 #include <IOKit/IOService.h>
36 #include <IOKit/IODeviceTreeSupport.h>
37 #include <IOKit/nvram/IONVRAMController.h>
38 #endif /* __cplusplus */
40 #define kIODTNVRAMOFPartitionName "common"
41 #define kIODTNVRAMXPRAMPartitionName "APL,MacOS75"
42 #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic"
43 #define kIODTNVRAMFreePartitionName "wwwwwwwwwwww"
45 #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */
48 kIODTNVRAMImageSize
= 0x2000,
49 kIODTNVRAMXPRAMSize
= 0x0100,
50 kIODTNVRAMNameRegistrySize
= 0x0400
54 kOFVariableTypeBoolean
= 1,
55 kOFVariableTypeNumber
,
56 kOFVariableTypeString
,
61 kOFVariablePermRootOnly
= 0,
62 kOFVariablePermUserRead
,
63 kOFVariablePermUserWrite
,
64 kOFVariablePermKernelOnly
69 class IODTNVRAM
: public IOService
71 OSDeclareDefaultStructors(IODTNVRAM
);
74 IONVRAMController
*_nvramController
;
75 const OSSymbol
*_registryPropertiesKey
;
77 __unused
bool _nvramImageDirty
;
78 UInt32 _ofPartitionOffset
;
79 UInt32 _ofPartitionSize
;
81 __unused
bool _ofImageDirty
;
82 OSDictionary
*_ofDict
;
83 OSDictionary
*_nvramPartitionOffsets
;
84 OSDictionary
*_nvramPartitionLengths
;
85 UInt32 _resv0 __unused
;
86 UInt32 _resv1 __unused
;
88 UInt32 _resv2 __unused
;
89 UInt32 _resv3 __unused
;
90 UInt8
*_resv4 __unused
;
91 UInt32 _piPartitionOffset
;
92 UInt32 _piPartitionSize
;
95 SInt32 _lastDeviceSync
;
99 virtual UInt8
calculatePartitionChecksum(UInt8
*partitionHeader
);
100 virtual IOReturn
initOFVariables(void);
102 virtual IOReturn
syncOFVariables(void);
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
,
120 virtual IOReturn
readNVRAMPropertyType0(IORegistryEntry
*entry
,
121 const OSSymbol
**name
,
123 virtual IOReturn
writeNVRAMPropertyType0(IORegistryEntry
*entry
,
124 const OSSymbol
*name
,
127 virtual OSData
*unescapeBytesToData(const UInt8
*bytes
, UInt32 length
);
128 virtual OSData
*escapeDataToData(OSData
* value
);
130 virtual IOReturn
readNVRAMPropertyType1(IORegistryEntry
*entry
,
131 const OSSymbol
**name
,
133 virtual IOReturn
writeNVRAMPropertyType1(IORegistryEntry
*entry
,
134 const OSSymbol
*name
,
137 void initNVRAMImage(void);
138 void initProxyData(void);
141 virtual bool init(IORegistryEntry
*old
, const IORegistryPlane
*plane
) APPLE_KEXT_OVERRIDE
;
143 virtual void registerNVRAMController(IONVRAMController
*nvram
);
145 virtual void sync(void);
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
;
156 virtual IOReturn
readXPRAM(IOByteCount offset
, UInt8
*buffer
,
158 virtual IOReturn
writeXPRAM(IOByteCount offset
, UInt8
*buffer
,
161 virtual IOReturn
readNVRAMProperty(IORegistryEntry
*entry
,
162 const OSSymbol
**name
,
164 virtual IOReturn
writeNVRAMProperty(IORegistryEntry
*entry
,
165 const OSSymbol
*name
,
168 virtual OSDictionary
*getNVRAMPartitions(void);
170 virtual IOReturn
readNVRAMPartition(const OSSymbol
*partitionID
,
171 IOByteCount offset
, UInt8
*buffer
,
174 virtual IOReturn
writeNVRAMPartition(const OSSymbol
*partitionID
,
175 IOByteCount offset
, UInt8
*buffer
,
178 virtual IOByteCount
savePanicInfo(UInt8
*buffer
, IOByteCount length
);
179 virtual bool safeToSync(void);
180 void syncInternal(bool rateLimit
);
183 #endif /* __cplusplus */
185 #endif /* !_IOKIT_IONVRAM_H */