1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _IOKIT_IONVRAM_H
30#define _IOKIT_IONVRAM_H
31
32#ifdef __cplusplus
33#include <IOKit/IOKitKeys.h>
34#include <IOKit/IOService.h>
35#include <IOKit/IODeviceTreeSupport.h>
36#include <IOKit/nvram/IONVRAMController.h>
37#endif /* __cplusplus */
38
39#define kIODTNVRAMOFPartitionName       "common"
40#define kIODTNVRAMXPRAMPartitionName    "APL,MacOS75"
41#define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic"
42#define kIODTNVRAMFreePartitionName     "wwwwwwwwwwww"
43
44#define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */
45
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,
62  kOFVariablePermUserWrite,
63  kOFVariablePermKernelOnly
64};
65
66#ifdef __cplusplus
67
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;
82  OSDictionary      *_nvramPartitionOffsets;
83  OSDictionary      *_nvramPartitionLengths;
84  UInt32            _xpramPartitionOffset;
85  UInt32            _xpramPartitionSize;
86  UInt8             *_xpramImage;
87  UInt32            _nrPartitionOffset;
88  UInt32            _nrPartitionSize;
89  UInt8             *_nrImage;
90  UInt32            _piPartitionOffset;
91  UInt32            _piPartitionSize;
92  UInt8             *_piImage;
93  bool              _systemPaniced;
94  SInt32            _lastDeviceSync;
95  bool              _freshInterval;
96
97  virtual UInt8 calculatePartitionChecksum(UInt8 *partitionHeader);
98  virtual IOReturn initOFVariables(void);
99public:
100  virtual IOReturn syncOFVariables(void);
101private:
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
125  virtual OSData *unescapeBytesToData(const UInt8 *bytes, UInt32 length);
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
142  virtual bool serializeProperties(OSSerialize *s) const;
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);
146  virtual void removeProperty(const OSSymbol *aKey);
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);
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);
170
171  virtual IOByteCount savePanicInfo(UInt8 *buffer, IOByteCount length);
172  virtual bool safeToSync(void);
173};
174
175#endif /* __cplusplus */
176
177#endif /* !_IOKIT_IONVRAM_H */
178