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 77 class IODTNVRAMFormatHandler 78 { 79 public: 80 virtual 81 ~IODTNVRAMFormatHandler(); 82 virtual IOReturn setVariable(const uuid_t varGuid, const char *variableName, OSObject *object) = 0; 83 virtual bool setController(IONVRAMController *_nvramController) = 0; 84 virtual bool sync(void) = 0; 85 virtual IOReturn flush(const uuid_t guid, IONVRAMOperation op) = 0; 86 virtual uint32_t getGeneration(void) const = 0; 87 virtual uint32_t getVersion(void) const = 0; 88 virtual uint32_t getSystemUsed(void) const = 0; 89 virtual uint32_t getCommonUsed(void) const = 0; 90 }; 91 92 class IODTNVRAM : public IOService 93 { 94 OSDeclareDefaultStructors(IODTNVRAM); 95 96 private: 97 friend class IODTNVRAMVariables; 98 friend class IONVRAMCHRPHandler; 99 friend class IONVRAMV3Handler; 100 101 IODTNVRAMDiags *_diags; 102 IODTNVRAMFormatHandler *_format; 103 104 IORWLock *_variableLock; 105 IOLock *_controllerLock; 106 107 IODTNVRAMVariables *_commonService; 108 IODTNVRAMVariables *_systemService; 109 110 OSPtr<OSDictionary> _commonDict; 111 OSPtr<OSDictionary> _systemDict; 112 113 SInt32 _lastDeviceSync; 114 bool _freshInterval; 115 116 void initImageFormat(void); 117 118 uint32_t getNVRAMSize(void); 119 120 NVRAMPartitionType getDictionaryType(const OSDictionary *dict) const; 121 IOReturn chooseDictionary(IONVRAMOperation operation, const uuid_t varGuid, 122 const char *variableName, OSDictionary **dict) const; 123 IOReturn flushDict(const uuid_t guid, IONVRAMOperation op); 124 bool handleSpecialVariables(const char *name, const uuid_t guid, const OSObject *obj, IOReturn *error); 125 126 IOReturn setPropertyInternal(const OSSymbol *aKey, OSObject *anObject); 127 IOReturn removePropertyInternal(const OSSymbol *aKey); 128 OSSharedPtr<OSObject> copyPropertyWithGUIDAndName(const uuid_t guid, const char *name) const; 129 IOReturn removePropertyWithGUIDAndName(const uuid_t guid, const char *name); 130 IOReturn setPropertyWithGUIDAndName(const uuid_t guid, const char *name, OSObject *anObject); 131 132 void syncInternal(bool rateLimit); 133 bool safeToSync(void); 134 135 public: 136 virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE; 137 virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE; 138 139 virtual void registerNVRAMController(IONVRAMController *controller); 140 141 virtual void sync(void); 142 143 virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE; 144 virtual OSPtr<OSObject> copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; 145 virtual OSPtr<OSObject> copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; 146 virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE; 147 virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE; 148 virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE; 149 virtual void removeProperty(const OSSymbol *aKey) APPLE_KEXT_OVERRIDE; 150 virtual IOReturn setProperties(OSObject *properties) APPLE_KEXT_OVERRIDE; 151 152 virtual IOReturn readXPRAM(IOByteCount offset, uint8_t *buffer, 153 IOByteCount length); 154 virtual IOReturn writeXPRAM(IOByteCount offset, uint8_t *buffer, 155 IOByteCount length); 156 157 virtual IOReturn readNVRAMProperty(IORegistryEntry *entry, 158 const OSSymbol **name, 159 OSData **value); 160 virtual IOReturn writeNVRAMProperty(IORegistryEntry *entry, 161 const OSSymbol *name, 162 OSData *value); 163 164 virtual OSDictionary *getNVRAMPartitions(void); 165 166 virtual IOReturn readNVRAMPartition(const OSSymbol *partitionID, 167 IOByteCount offset, uint8_t *buffer, 168 IOByteCount length); 169 170 virtual IOReturn writeNVRAMPartition(const OSSymbol *partitionID, 171 IOByteCount offset, uint8_t *buffer, 172 IOByteCount length); 173 174 virtual IOByteCount savePanicInfo(uint8_t *buffer, IOByteCount length); 175 }; 176 177 #endif /* __cplusplus */ 178 179 #endif /* !_IOKIT_IONVRAM_H */ 180