]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/IOKit/IONVRAM.h
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / iokit / IOKit / IONVRAM.h
index ef2e533e8ba6c9a02beba7a3c2e17da9b5c1c0eb..91336d2a70050f5b5c5a09b2ea9516977d44228a 100644 (file)
 #define _IOKIT_IONVRAM_H
 
 #ifdef __cplusplus
+#include <libkern/c++/OSPtr.h>
 #include <IOKit/IOKitKeys.h>
 #include <IOKit/IOService.h>
 #include <IOKit/IODeviceTreeSupport.h>
 #include <IOKit/nvram/IONVRAMController.h>
 #endif /* __cplusplus */
+#include <uuid/uuid.h>
 
 #define kIODTNVRAMOFPartitionName       "common"
 #define kIODTNVRAMXPRAMPartitionName    "APL,MacOS75"
 #define kIODTNVRAMPanicInfoPartitonName "APL,OSXPanic"
 #define kIODTNVRAMFreePartitionName     "wwwwwwwwwwww"
+#define kIODTNVRAMSystemPartitionName   "secure"
 
 #define MIN_SYNC_NOW_INTERVAL 15*60 /* Minimum 15 Minutes interval mandated */
 
-enum {
-       kIODTNVRAMImageSize        = 0x2000,
-       kIODTNVRAMXPRAMSize        = 0x0100,
-       kIODTNVRAMNameRegistrySize = 0x0400
-};
-
-enum {
+enum IONVRAMVariableType {
        kOFVariableTypeBoolean = 1,
        kOFVariableTypeNumber,
        kOFVariableTypeString,
        kOFVariableTypeData
 };
 
+enum IONVRAMOperation {
+       kIONVRAMOperationRead,
+       kIONVRAMOperationWrite,
+       kIONVRAMOperationDelete,
+       kIONVRAMOperationObliterate,
+       kIONVRAMOperationReset
+};
+
 enum {
+       // Deprecated but still used in AppleEFIRuntime for now
        kOFVariablePermRootOnly = 0,
        kOFVariablePermUserRead,
        kOFVariablePermUserWrite,
@@ -66,42 +72,40 @@ enum {
 
 #ifdef __cplusplus
 
+class IODTNVRAMVariables;
+
 class IODTNVRAM : public IOService
 {
        OSDeclareDefaultStructors(IODTNVRAM);
 
 private:
-       IONVRAMController *_nvramController;
-       const OSSymbol    *_registryPropertiesKey;
-       UInt8             *_nvramImage;
-       __unused bool     _nvramImageDirty;
-       UInt32            _ofPartitionOffset;
-       UInt32            _ofPartitionSize;
-       UInt8             *_ofImage;
-       __unused bool     _ofImageDirty;
-       OSDictionary      *_ofDict;
-       OSDictionary      *_nvramPartitionOffsets;
-       OSDictionary      *_nvramPartitionLengths;
-       UInt32            _resv0 __unused;
-       UInt32            _resv1 __unused;
-       IOLock            *_ofLock;
-       UInt32            _resv2 __unused;
-       UInt32            _resv3 __unused;
-       UInt8             *_resv4 __unused;
-       UInt32            _piPartitionOffset;
-       UInt32            _piPartitionSize;
-       UInt8             *_piImage;
-       bool              _systemPaniced;
-       SInt32            _lastDeviceSync;
-       bool              _freshInterval;
-       bool              _isProxied;
+       IONVRAMController      *_nvramController;
+       OSPtr<const OSSymbol>  _registryPropertiesKey;
+       UInt8                  *_nvramImage;
+       IOLock                 *_variableLock;
+       UInt32                 _commonPartitionOffset;
+       UInt32                 _commonPartitionSize;
+       UInt8                  *_commonImage;
+       IODTNVRAMVariables     *_commonService;
+       OSPtr<OSDictionary>    _commonDict;
+       UInt32                 _systemPartitionOffset;
+       UInt32                 _systemPartitionSize;
+       UInt8                  *_systemImage;
+       IODTNVRAMVariables     *_systemService;
+       OSPtr<OSDictionary>    _systemDict;
+       OSPtr<OSDictionary>    _nvramPartitionOffsets;
+       OSPtr<OSDictionary>    _nvramPartitionLengths;
+       bool                   _systemPanicked;
+       SInt32                 _lastDeviceSync;
+       bool                   _freshInterval;
+       bool                   _isProxied;
+       UInt32                 _nvramSize;
 
        virtual UInt8 calculatePartitionChecksum(UInt8 *partitionHeader);
-       virtual IOReturn initOFVariables(void);
-public:
-       virtual IOReturn syncOFVariables(void);
-private:
+       virtual IOReturn initVariables(void);
+       virtual UInt32 getOFVariableType(const char *propName) const;
        virtual UInt32 getOFVariableType(const OSSymbol *propSymbol) const;
+       virtual UInt32 getOFVariablePerm(const char *propName) const;
        virtual UInt32 getOFVariablePerm(const OSSymbol *propSymbol) const;
        virtual bool getOWVariableInfo(UInt32 variableNumber, const OSSymbol **propSymbol,
            UInt32 *propType, UInt32 *propOffset);
@@ -109,6 +113,10 @@ private:
            UInt8 *propData, UInt32 propDataLength,
            LIBKERN_RETURNS_RETAINED const OSSymbol **propSymbol,
            LIBKERN_RETURNS_RETAINED OSObject **propObject);
+       bool convertPropToObject(UInt8 *propName, UInt32 propNameLength,
+           UInt8 *propData, UInt32 propDataLength,
+           OSSharedPtr<const OSSymbol>& propSymbol,
+           OSSharedPtr<OSObject>& propObject);
        virtual bool convertObjectToProp(UInt8 *buffer, UInt32 *length,
            const OSSymbol *propSymbol, OSObject *propObject);
        virtual UInt16 generateOWChecksum(UInt8 *buffer);
@@ -124,8 +132,8 @@ private:
            const OSSymbol *name,
            OSData * value);
 
-       virtual OSData *unescapeBytesToData(const UInt8 *bytes, UInt32 length);
-       virtual OSData *escapeDataToData(OSData * value);
+       virtual OSPtr<OSData> unescapeBytesToData(const UInt8 *bytes, UInt32 length);
+       virtual OSPtr<OSData> escapeDataToData(OSData * value);
 
        virtual IOReturn readNVRAMPropertyType1(IORegistryEntry *entry,
            const OSSymbol **name,
@@ -134,11 +142,15 @@ private:
            const OSSymbol *name,
            OSData *value);
 
+       UInt32 getNVRAMSize(void);
        void initNVRAMImage(void);
        void initProxyData(void);
        IOReturn syncVariables(void);
        IOReturn setPropertyInternal(const OSSymbol *aKey, OSObject *anObject);
-
+       IOReturn removePropertyInternal(const OSSymbol *aKey);
+       IOReturn chooseDictionary(IONVRAMOperation operation, const uuid_t *varGuid,
+           const char *variableName, OSDictionary **dict) const;
+       bool handleSpecialVariables(const char *name, uuid_t *guid, OSObject *obj, IOReturn *error);
 
 public:
        virtual bool init(IORegistryEntry *old, const IORegistryPlane *plane) APPLE_KEXT_OVERRIDE;
@@ -146,10 +158,11 @@ public:
        virtual void registerNVRAMController(IONVRAMController *nvram);
 
        virtual void sync(void);
+       virtual IOReturn syncOFVariables(void);
 
        virtual bool serializeProperties(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
-       virtual OSObject *copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE;
-       virtual OSObject *copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE;
+       virtual OSPtr<OSObject> copyProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE;
+       virtual OSPtr<OSObject> copyProperty(const char *aKey) const APPLE_KEXT_OVERRIDE;
        virtual OSObject *getProperty(const OSSymbol *aKey) const APPLE_KEXT_OVERRIDE;
        virtual OSObject *getProperty(const char *aKey) const APPLE_KEXT_OVERRIDE;
        virtual bool setProperty(const OSSymbol *aKey, OSObject *anObject) APPLE_KEXT_OVERRIDE;