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 <IOKit/IOKitKeys.h> |
35 | #include <IOKit/IOService.h> |
36 | #include <IOKit/IODeviceTreeSupport.h> |
37 | #include <IOKit/nvram/IONVRAMController.h> |
38 | #endif /* __cplusplus */ |
39 | |
40 | #define kIODTNVRAMOFPartitionName "common" |
41 | #define kIODTNVRAMXPRAMPartitionName "APL,MacOS75" |
42 | #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic" |
43 | #define kIODTNVRAMFreePartitionName "wwwwwwwwwwww" |
44 | |
45 | #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */ |
46 | |
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, |
63 | kOFVariablePermUserWrite, |
64 | kOFVariablePermKernelOnly |
65 | }; |
66 | |
67 | #ifdef __cplusplus |
68 | |
69 | class IODTNVRAM : public IOService |
70 | { |
71 | OSDeclareDefaultStructors(IODTNVRAM); |
72 | |
73 | private: |
74 | IONVRAMController *_nvramController; |
75 | const OSSymbol *_registryPropertiesKey; |
76 | UInt8 *_nvramImage; |
77 | __unused bool _nvramImageDirty; |
78 | UInt32 _ofPartitionOffset; |
79 | UInt32 _ofPartitionSize; |
80 | UInt8 *_ofImage; |
81 | __unused bool _ofImageDirty; |
82 | OSDictionary *_ofDict; |
83 | OSDictionary *_nvramPartitionOffsets; |
84 | OSDictionary *_nvramPartitionLengths; |
85 | UInt32 _resv0 __unused; |
86 | UInt32 _resv1 __unused; |
87 | IOLock *_ofLock; |
88 | UInt32 _resv2 __unused; |
89 | UInt32 _resv3 __unused; |
90 | UInt8 *_resv4 __unused; |
91 | UInt32 _piPartitionOffset; |
92 | UInt32 _piPartitionSize; |
93 | UInt8 *_piImage; |
94 | bool _systemPaniced; |
95 | SInt32 _lastDeviceSync; |
96 | bool _freshInterval; |
97 | bool _isProxied; |
98 | |
99 | virtual UInt8 calculatePartitionChecksum(UInt8 *); |
100 | virtual IOReturn initOFVariables(void); |
101 | public: |
102 | virtual IOReturn syncOFVariables(void); |
103 | private: |
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 | |
127 | virtual OSData *unescapeBytesToData(const UInt8 *bytes, UInt32 length); |
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 | |
137 | void initNVRAMImage(void); |
138 | void initProxyData(void); |
139 | IOReturn syncVariables(void); |
140 | |
141 | public: |
142 | virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE; |
143 | |
144 | virtual void registerNVRAMController(IONVRAMController *nvram); |
145 | |
146 | virtual void sync(void); |
147 | |
148 | virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE; |
149 | virtual OSObject *copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
150 | virtual OSObject *copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; |
151 | virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
152 | virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; |
153 | virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE; |
154 | virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE; |
155 | virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE; |
156 | |
157 | virtual IOReturn readXPRAM(IOByteCount offset, UInt8 *buffer, |
158 | IOByteCount length); |
159 | virtual IOReturn writeXPRAM(IOByteCount offset, UInt8 *buffer, |
160 | IOByteCount length); |
161 | |
162 | virtual IOReturn readNVRAMProperty(IORegistryEntry *entry, |
163 | const OSSymbol **name, |
164 | OSData **value); |
165 | virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry, |
166 | const OSSymbol *name, |
167 | OSData *value); |
168 | |
169 | virtual OSDictionary *getNVRAMPartitions(void); |
170 | |
171 | virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID, |
172 | IOByteCount offset, UInt8 *buffer, |
173 | IOByteCount length); |
174 | |
175 | virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID, |
176 | IOByteCount offset, UInt8 *buffer, |
177 | IOByteCount length); |
178 | |
179 | virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length); |
180 | virtual bool safeToSync(void); |
181 | void syncInternal(bool rateLimit); |
182 | }; |
183 | |
184 | #endif /* __cplusplus */ |
185 | |
186 | #endif /* !_IOKIT_IONVRAM_H */ |
187 | |