xref: /xnu-8792.81.2/iokit/IOKit/IONVRAM.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1 /*
2  * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
3  * Copyright (c) 2007-2021 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 <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>
41 
42 enum NVRAMPartitionType {
43 	kIONVRAMPartitionTypeUnknown,
44 	kIONVRAMPartitionSystem,
45 	kIONVRAMPartitionCommon
46 };
47 
48 enum IONVRAMVariableType {
49 	kOFVariableTypeBoolean = 1,
50 	kOFVariableTypeNumber,
51 	kOFVariableTypeString,
52 	kOFVariableTypeData
53 };
54 
55 enum IONVRAMOperation {
56 	kIONVRAMOperationInit,
57 	kIONVRAMOperationRead,
58 	kIONVRAMOperationWrite,
59 	kIONVRAMOperationDelete,
60 	kIONVRAMOperationObliterate,
61 	kIONVRAMOperationReset
62 };
63 
64 enum {
65 	// Deprecated but still used in AppleEFIRuntime for now
66 	kOFVariablePermRootOnly = 0,
67 	kOFVariablePermUserRead,
68 	kOFVariablePermUserWrite,
69 	kOFVariablePermKernelOnly
70 };
71 
72 #ifdef __cplusplus
73 
74 class IODTNVRAMVariables;
75 class IODTNVRAMDiags;
76 class IODTNVRAMPlatformNotifier;
77 class IODTNVRAMFormatHandler;
78 
79 class IODTNVRAM : public IOService
80 {
81 	OSDeclareDefaultStructors(IODTNVRAM);
82 
83 private:
84 	friend class IODTNVRAMVariables;
85 	friend class IONVRAMCHRPHandler;
86 	friend class IONVRAMV3Handler;
87 
88 	IODTNVRAMPlatformNotifier *_notifier;
89 	IODTNVRAMDiags            *_diags;
90 	IODTNVRAMFormatHandler    *_format;
91 
92 	IORWLock               *_variableLock;
93 	IOLock                 *_controllerLock;
94 
95 	IODTNVRAMVariables     *_commonService;
96 	IODTNVRAMVariables     *_systemService;
97 
98 	OSPtr<OSDictionary>    _commonDict;
99 	OSPtr<OSDictionary>    _systemDict;
100 
101 	SInt32                 _lastDeviceSync;
102 	bool                   _freshInterval;
103 
104 	void initImageFormat(void);
105 
106 	uint32_t getNVRAMSize(void);
107 
108 	NVRAMPartitionType getDictionaryType(const OSDictionary *dict) const;
109 	IOReturn chooseDictionary(IONVRAMOperation operation, const uuid_t varGuid,
110 	    const char *variableName, OSDictionary **dict) const;
111 	IOReturn flushDict(const uuid_t guid, IONVRAMOperation op);
112 	bool handleSpecialVariables(const char *name, const uuid_t guid, const OSObject *obj, IOReturn *error);
113 
114 	IOReturn setPropertyInternal(const OSSymbol *aKey, OSObject *anObject);
115 	IOReturn removePropertyInternal(const OSSymbol *aKey);
116 	OSSharedPtr<OSObject> copyPropertyWithGUIDAndName(const uuid_t guid, const char *name) const;
117 	IOReturn removePropertyWithGUIDAndName(const uuid_t guid, const char *name);
118 	IOReturn setPropertyWithGUIDAndName(const uuid_t guid, const char *name, OSObject *anObject);
119 
120 	void syncInternal(bool rateLimit);
121 	bool safeToSync(void);
122 
123 public:
124 	virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE;
125 	virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE;
126 
127 	virtual void registerNVRAMController(IONVRAMController *controller);
128 
129 	virtual void sync(void);
130 	virtual void reload(void);
131 
132 	virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
133 	virtual OSPtr<OSObject> copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE;
134 	virtual OSPtr<OSObject> copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE;
135 	virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE;
136 	virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE;
137 	virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE;
138 	virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE;
139 	virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE;
140 
141 	virtual IOReturn readXPRAM(IOByteCount offset, uint8_t *buffer,
142 	    IOByteCount length);
143 	virtual IOReturn writeXPRAM(IOByteCount offset, uint8_t *buffer,
144 	    IOByteCount length);
145 
146 	virtual IOReturn readNVRAMProperty(IORegistryEntry *entry,
147 	    const OSSymbol **name,
148 	    OSData **value);
149 	virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry,
150 	    const OSSymbol *name,
151 	    OSData *value);
152 
153 	virtual OSDictionary *getNVRAMPartitions(void);
154 
155 	virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID,
156 	    IOByteCount offset, uint8_t *buffer,
157 	    IOByteCount length);
158 
159 	virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID,
160 	    IOByteCount offset, uint8_t *buffer,
161 	    IOByteCount length);
162 
163 	virtual IOByteCount savePanicInfo(uint8_t *buffer, IOByteCount length);
164 };
165 
166 #endif /* __cplusplus */
167 
168 #endif /* !_IOKIT_IONVRAM_H */
169