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> _varDict; |
99 | |
100 | SInt32 _lastDeviceSync; |
101 | bool _freshInterval; |
102 | |
103 | void initImageFormat(void); |
104 | |
105 | uint32_t getNVRAMSize(void); |
106 | |
107 | IOReturn flushGUID(const uuid_t guid, IONVRAMOperation op); |
108 | bool handleSpecialVariables(const char *name, const uuid_t guid, const OSObject *obj, IOReturn *error); |
109 | |
110 | IOReturn setPropertyInternal(const OSSymbol *aKey, OSObject *anObject); |
111 | IOReturn removePropertyInternal(const OSSymbol *aKey); |
112 | OSSharedPtr<OSObject> copyPropertyWithGUIDAndName(const uuid_t guid, const char *name) const; |
113 | IOReturn removePropertyWithGUIDAndName(const uuid_t guid, const char *name); |
114 | IOReturn setPropertyWithGUIDAndName(const uuid_t guid, const char *name, OSObject *anObject); |
115 | |
116 | IOReturn syncInternal(bool rateLimit); |
117 | bool safeToSync(void); |
118 | |
119 | public: |
120 | virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE; |
121 | virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE; |
122 | |
123 | virtual void registerNVRAMController(IONVRAMController *controller); |
124 | |
125 | virtual IOReturn sync(void); |
126 | virtual void reload(void); |
127 | |
128 | virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE; |
129 | virtual OSPtr<OSObject> copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
130 | virtual OSPtr<OSObject> copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; |
131 | virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; |
132 | virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; |
133 | virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE; |
134 | virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE; |
135 | virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE; |
136 | |
137 | virtual IOReturn readXPRAM(IOByteCount offset, uint8_t *buffer, |
138 | IOByteCount length); |
139 | virtual IOReturn writeXPRAM(IOByteCount offset, uint8_t *buffer, |
140 | IOByteCount length); |
141 | |
142 | virtual IOReturn readNVRAMProperty(IORegistryEntry *entry, |
143 | const OSSymbol **name, |
144 | OSData **value); |
145 | virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry, |
146 | const OSSymbol *name, |
147 | OSData *value); |
148 | |
149 | virtual OSDictionary *getNVRAMPartitions(void); |
150 | |
151 | virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID, |
152 | IOByteCount offset, uint8_t *buffer, |
153 | IOByteCount length); |
154 | |
155 | virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID, |
156 | IOByteCount offset, uint8_t *buffer, |
157 | IOByteCount length); |
158 | |
159 | virtual IOByteCount savePanicInfo(uint8_t *buffer, IOByteCount length); |
160 | }; |
161 | |
162 | #endif /* __cplusplus */ |
163 | |
164 | #endif /* !_IOKIT_IONVRAM_H */ |
165 | |