# NvramSmm

## Function Table

| Address | Name | Description |
|---------|------|-------------|
|  | **ModuleEntryPoint** |  |
|  | **NvramCoreInit** |  |
|  | **SmiNvramCommHandler** |  |
|  | **SmiNvramUpdateHandler** |  |
|  | **RuntimeGetVariable** |  |
|  | **RuntimeSetVariable** |  |
|  | **RuntimeGetNextVariableName** |  |
|  | **RuntimeQueryVariableInfo** |  |
|  | **SecureBootSetVariable** |  |
|  | **SecureBootGetVariable** |  |
|  | **NvramSyncCallbackSetup** |  |
|  | **GetFvHeaderSize** |  |
|  | **VarStoreInit** |  |
|  | **NvramHobRetrieve** |  |
| Build | **path: e:\hs\Build\HR6N0XMLK\DEBUG_VS2015\X64\AmiModulePkg\NVRAM\NvramSmm\DEBUG** |  |
| Source | **files: NvramSmm.c, NvramDxeCommon.c, NvramSmi.c, AuthService.c** |  |
| Global | **State (from .data section)** |  |
| 0x11670 | **EFI_SYSTEM_TABLE               *gST = NULL;                         // 0x11660** |  |
| 0x11668 | **EFI_RUNTIME_SERVICES           *gRT = NULL;                         // 0x11678** |  |
| 0x11680 | **VOID                           *gDS = NULL;                         // 0x11758** |  |
| 0x116F8 | **VOID                           *gMmst;                              // 0x116F0** |  |
| 0x11690 | **VOID                           *gSmmBufferValidation = NULL;         // 0x11750** |  |
| 0x115D0 | **UINT64                          gNvramStoreSize = 0;                // 0x115D8** |  |
| 0x11C24 | **UINT8                           gVarStoreInitFlags = 0;             // 0x11C20** |  |
| 0x11C28 | **EFI_RUNTIME_SERVICES           *gRuntimeServicesOverride = NULL;    // 0x116E8** |  |
| 0x11F10 | **UINTN                           gDriverNvramBufferSize = 0;         // 0x11F18** |  |
| 0x11648 | **UINT64                          gMailboxNvramBase = 0;              // 0x11F28** |  |
| 0x11F30 | **UINT32                          gMailboxNvramFlags = 0;             // 0x11F38** |  |
| 0x11F40 | **UINT64                          gMailboxVarStoreSize = 0;           // 0x11F48** |  |
| 0x11609 | **BOOLEAN                         gSmiProcessing = FALSE;             // 0x11768** |  |
| 0x11894 | **VAR_STORE_INFO                  gVarStoreArray[?];                  // 0x11C38** |  |
| Module | **Entry Point** |  |
| Initialize | **all UEFI/SMM plumbing** |  |
| Global | **status variable** |  |
| Locate | **SmmBase2 protocol** |  |
| Get | **SMM System Table** |  |
| Locate | **SMM memory allocation protocol** |  |
| Get | **SMRAM ranges** |  |
| Initialize | **PCIE segment bus table** |  |
| Initialize | **AmiCryptoLib** |  |
| Initialize | **heap memory manager** |  |
| Locate | **SMM buffer validation protocol** |  |
| Locate | **DxeServicesTable** |  |
| Fall | **through to SMM protocol install / notification init (returned from Init)** |  |
| NVRAM | **Initialization (sub_10F8)** |  |
| Signal | **that NVRAM store size at least matches HOB pattern** |  |
| Get | **NVRAM HOB from HOB list** |  |
| Read | **NvramMailBox variable to get mailbox memory region info** |  |
| Extract | **mailbox NVRAM base/size details from the variable** |  |
| offset | **0** |  |
| offset | **8** |  |
| offset | **60** |  |
| offset | **736** |  |
| offset | **744** |  |
| Close | **the variable** |  |
| Validate | **that VarStoreInfo NVRAM sizes match mailbox** |  |
| Copy | **VarStoreInfo NVRAM data from mailbox into working buffer** |  |
| If | **simulation mode, also copy NvInfo data from mailbox** |  |
| Allocate | **DMA buffer for SMI communication (0x40000 bytes)** |  |
| Initialize | **buffer header** |  |
| data | **starts at +24** |  |
| usable | **size** |  |
| Register | **SMI handler for NVRAM variable access** |  |
| Register | **notification callback on SMM ReadyToLock** |  |
| Override | **runtime variable services** |  |
| Register | **variable change callbacks for variable sync** |  |
| Register | **additional callbacks for DmiArray variable change** |  |
| Register | **SMM communication protocol for variable sync** |  |
| SMI | **NVRAM Communication Handler (sub_6AE4)** |  |
| Validate | **buffer address with SMM buffer validation protocol** |  |
| Align | **the buffer pointer to 8-byte boundary** |  |
| Set | **SMI processing flag** |  |
| Read | **command code at offset 0** |  |
| Type | **0: GetVariable operation** |  |
| Buffer | **layout: +0x00: cmd, +0x08: NameSize, +0x10: DataSize** |  |
| Nested | **variable read with sub_5580** |  |
| Type | **1: SetVariable operation** |  |
| Buffer | **layout: +0x00: cmd, +0x08: NameLength, +0x10: DataSize** |  |
| sub_5654 | **handles the actual set** |  |
| Type | **2: GetNextVariableName** |  |
| Type | **3: QueryVariableInfo** |  |
| Type | **4: Variable write with auth** |  |
| Migration | **complete notification** |  |
| Write | **status back to command code location** |  |
| SMI | **NVRAM Update Handler (sub_5FAC and sub_5E44)** |  |
| qword_11F00 | **// Validate comm buffer** |  |
| Check | **size match** |  |
| Check | **that source buffer has a valid FV header** |  |
| Check | **if FV header size is consistent** |  |
| Validate | **the data aligns with store parameters** |  |
| Need | **to allocate bigger temp buffer (3x)** |  |
| Copy | **source NVRAM data** |  |
| Check | **that data is not all 0xFF (empty erased)** |  |
| Check | **for active NVRAM (FV header + GUID match)** |  |
| Check | **size matches the data in the FV** |  |
| Copy | **from temp to working store** |  |
| Set | **up store pointers for the migration** |  |
| source | **address** |  |
| Validate | **store parameters** |  |
| F | **Fill header calculation** |  |
| Set | **up the variable enumeration** |  |
| Try | **to find space and move** |  |
| Garbage | **collection / flush path** |  |
| Mark | **old store entries** |  |
| mark | **deleted** |  |
| Full | **GC path** |  |
| At | **this point the GC reclaimed space** |  |
| Runtime | **Variable Service Overrides** |  |
| Dispatches | **to SMI via SMI_NVRAM_CMD_GET_VARIABLE command** |  |
| For | **non-SMM context, sends SMI to enter SMM first.** |  |
| Forward | **declaration: actual implementation at sub_5580.** |  |
| Dispatches | **to SMI via SMI_NVRAM_CMD_SET_VARIABLE command** |  |
| Forward | **declaration: actual implementation at sub_5654.** |  |
| Dispatches | **via SMI_NVRAM_CMD_GET_NEXT_VARIABLE** |  |
| Forward | **declaration: actual implementation at sub_F54.** |  |
| Dispatches | **via SMI_NVRAM_CMD_QUERY_VARIABLE_INFO** |  |
| Forward | **declaration: actual implementation at sub_5D34.** |  |
| SecureBoot | **Aware Variable Services** |  |
| Determine | **variable type from vendor GUID** |  |
| Log | **DEBUG((** |  |
| Write | **the variable to the actual NVRAM store** |  |
| Handle | **SecureBootMode transitions** |  |
| First | **type: handle PK/KEK changes** |  |
| Setup | **mode -> set to secure boot mode 0** |  |
| Deployed | **mode -> set to 3** |  |
| Not | **physically present** |  |
| user | **mode** |  |
| For | **DeploymentModeNv and VendorKeysNv, reject access** |  |
| Variable | **Synchronization Callbacks** |  |
| Check | **disable flag variable** |  |
| Read | **disable flag** |  |
| Variable | **sync from Setup to other config variables** |  |
| Sync | **fields from Setup to variables** |  |
| Sync | **SocketIioConfig** |  |
| Sync | **SRIOVEnable between IntelSetup and Setup** |  |
| NVRAM | **Storage Helper Functions** |  |
| Check | **for FV header signature at offset 40** |  |
| FV | **header length at offset 48** |  |
| basic | **FV header only** |  |
| Extended | **header present at ExtHeaderOffset** |  |
| Return | **aligned total size** |  |
| start | **from end, working backwards** |  |
| aligned | **from flags field** |  |
| Attempt | **to locate existing variable data** |  |
| Check | **for valid flash store** |  |
| no | **existing data** |  |
| NVRAM | **HOB Retrieval (sub_644C)** |  |
| Search | **for NVRAM HOB** |  |
| No | **HOB found, run in simulation mode** |  |
| HOB | **+48 = NVRAM size** |  |
| HOB | **+24 = store address** |  |
| Validate | **that store fits in the GCD descriptor** |  |
| Allocate | **working buffer for NVRAM image** |  |
| If | **no real store, fill with 0xFF (simulation)** |  |
| Read | **store from actual flash** |  |
| First | **initialization: discover GCD descriptor** |  |
| Validate | **boundaries** |  |
| Setup | **variable store info from working buffer** |  |
| Store | **info pointer to the variable store array entry** |  |
| Set | **up callback table for for for for for for...** |  |
| Mark | **as initialized** |  |
| Allocate | **the driver's NVRAM working buffer (3x store size for GC)** |  |
| Process | **"StdDefaults" if present for first-boot defaults** |  |
| Load | **default variable values from HOB or FV** |  |
| clear | **defaults flag** |  |
| Apply | **defaults** |  |
| Determine | **actual maximum NVRAM size across all stores** |  |
| Re | **allocate driver buffer with larger size** |  |
| NVRAMAM | **Init (sub_68384)** |  |
| Find | **the NVRAM HOB from HOB list** |  |
| Walk | **HOB list looking for NVRAM HOB data structure** |  |
| Initialize | **driver's NVRAM working buffer** |  |
| Initialize | **the store from from HOB** |  |
| Set | **up VarStore array entry** |  |
| Allocate | **working comparison buffer** |  |
| Ensure | **all stores fit in the working buffer** |  |

---
*Generated by HR650X BIOS Decompilation Project*