]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IONVRAM.h
xnu-1699.32.7.tar.gz
[apple/xnu.git] / iokit / IOKit / IONVRAM.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28
29#ifndef _IOKIT_IONVRAM_H
30#define _IOKIT_IONVRAM_H
31
6d2010ae 32#ifdef __cplusplus
91447636 33#include <IOKit/IOKitKeys.h>
1c79356b
A
34#include <IOKit/IOService.h>
35#include <IOKit/IODeviceTreeSupport.h>
36#include <IOKit/nvram/IONVRAMController.h>
6d2010ae 37#endif /* __cplusplus */
d52fe63f
A
38
39#define kIODTNVRAMOFPartitionName "common"
40#define kIODTNVRAMXPRAMPartitionName "APL,MacOS75"
9bccf70c 41#define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic"
d52fe63f
A
42#define kIODTNVRAMFreePartitionName "wwwwwwwwwwww"
43
6d2010ae
A
44#define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */
45
1c79356b
A
46enum {
47 kIODTNVRAMImageSize = 0x2000,
48 kIODTNVRAMXPRAMSize = 0x0100,
49 kIODTNVRAMNameRegistrySize = 0x0400
50};
51
52enum {
53 kOFVariableTypeBoolean = 1,
54 kOFVariableTypeNumber,
55 kOFVariableTypeString,
56 kOFVariableTypeData
57};
58
59enum {
60 kOFVariablePermRootOnly = 0,
61 kOFVariablePermUserRead,
cf7d32b8
A
62 kOFVariablePermUserWrite,
63 kOFVariablePermKernelOnly
1c79356b
A
64};
65
6d2010ae
A
66#ifdef __cplusplus
67
1c79356b
A
68class IODTNVRAM : public IOService
69{
70 OSDeclareDefaultStructors(IODTNVRAM);
71
72private:
73 IONVRAMController *_nvramController;
74 const OSSymbol *_registryPropertiesKey;
75 UInt8 *_nvramImage;
76 bool _nvramImageDirty;
77 UInt32 _ofPartitionOffset;
78 UInt32 _ofPartitionSize;
79 UInt8 *_ofImage;
80 bool _ofImageDirty;
81 OSDictionary *_ofDict;
d52fe63f
A
82 OSDictionary *_nvramPartitionOffsets;
83 OSDictionary *_nvramPartitionLengths;
1c79356b
A
84 UInt32 _xpramPartitionOffset;
85 UInt32 _xpramPartitionSize;
86 UInt8 *_xpramImage;
87 UInt32 _nrPartitionOffset;
88 UInt32 _nrPartitionSize;
89 UInt8 *_nrImage;
9bccf70c
A
90 UInt32 _piPartitionOffset;
91 UInt32 _piPartitionSize;
92 UInt8 *_piImage;
93 bool _systemPaniced;
6d2010ae
A
94 SInt32 _lastDeviceSync;
95 bool _freshInterval;
1c79356b 96
9bccf70c 97 virtual UInt8 calculatePartitionChecksum(UInt8 *partitionHeader);
1c79356b 98 virtual IOReturn initOFVariables(void);
91447636 99public:
1c79356b 100 virtual IOReturn syncOFVariables(void);
91447636 101private:
1c79356b
A
102 virtual UInt32 getOFVariableType(const OSSymbol *propSymbol) const;
103 virtual UInt32 getOFVariablePerm(const OSSymbol *propSymbol) const;
104 virtual bool getOWVariableInfo(UInt32 variableNumber, const OSSymbol **propSymbol,
105 UInt32 *propType, UInt32 *propOffset);
106 virtual bool convertPropToObject(UInt8 *propName, UInt32 propNameLength,
107 UInt8 *propData, UInt32 propDataLength,
108 const OSSymbol **propSymbol,
109 OSObject **propObject);
110 virtual bool convertObjectToProp(UInt8 *buffer, UInt32 *length,
111 const OSSymbol *propSymbol, OSObject *propObject);
112 virtual UInt16 generateOWChecksum(UInt8 *buffer);
113 virtual bool validateOWChecksum(UInt8 *buffer);
114 virtual void updateOWBootArgs(const OSSymbol *key, OSObject *value);
115 virtual bool searchNVRAMProperty(struct IONVRAMDescriptor *hdr,
116 UInt32 *where);
117
118 virtual IOReturn readNVRAMPropertyType0(IORegistryEntry *entry,
119 const OSSymbol **name,
120 OSData **value);
121 virtual IOReturn writeNVRAMPropertyType0(IORegistryEntry *entry,
122 const OSSymbol *name,
123 OSData * value);
124
91447636 125 virtual OSData *unescapeBytesToData(const UInt8 *bytes, UInt32 length);
1c79356b
A
126 virtual OSData *escapeDataToData(OSData * value);
127
128 virtual IOReturn readNVRAMPropertyType1(IORegistryEntry *entry,
129 const OSSymbol **name,
130 OSData **value);
131 virtual IOReturn writeNVRAMPropertyType1(IORegistryEntry *entry,
132 const OSSymbol *name,
133 OSData *value);
134
135public:
136 virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane);
137
138 virtual void registerNVRAMController(IONVRAMController *nvram);
139
140 virtual void sync(void);
141
91447636 142 virtual bool serializeProperties(OSSerialize *s) const;
1c79356b
A
143 virtual OSObject *getProperty(const OSSymbol *aKey) const;
144 virtual OSObject *getProperty(const char *aKey) const;
145 virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject);
91447636 146 virtual void removeProperty(const OSSymbol *aKey);
1c79356b
A
147 virtual IOReturn setProperties(OSObject *properties);
148
149 virtual IOReturn readXPRAM(IOByteCount offset, UInt8 *buffer,
150 IOByteCount length);
151 virtual IOReturn writeXPRAM(IOByteCount offset, UInt8 *buffer,
152 IOByteCount length);
153
154 virtual IOReturn readNVRAMProperty(IORegistryEntry *entry,
155 const OSSymbol **name,
156 OSData **value);
157 virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry,
158 const OSSymbol *name,
159 OSData *value);
d52fe63f
A
160
161 virtual OSDictionary *getNVRAMPartitions(void);
162
163 virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID,
164 IOByteCount offset, UInt8 *buffer,
165 IOByteCount length);
166
167 virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID,
168 IOByteCount offset, UInt8 *buffer,
169 IOByteCount length);
9bccf70c
A
170
171 virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
6d2010ae 172 virtual bool safeToSync(void);
1c79356b
A
173};
174
6d2010ae
A
175#endif /* __cplusplus */
176
1c79356b 177#endif /* !_IOKIT_IONVRAM_H */