/**
* LnvOobDriverDxe.h
* HR650X BIOS - LnvOobDriver DXE Driver
*
* Source file: LnvOobDriverDxe.c (from LenovoPlatformPkg)
* Binary: LnvOobDriverDxe.efi (index 0103)
* SHA256: f28fabb95b4f8f6e806f006eaa7aed3ef38db282e2070ce4722ea8c22d9bc280
*
* This driver provides OOB (Out-of-Band) data store management for
* IPMI-based BMC communication. It manages synchronization of BIOS
* variables with BMC data stores, handles product ID detection, and
* supports data store mapping and reset-on-change logic.
*/
#ifndef __LNVOOBDRIVERDXE_H__
#define __LNVOOBDRIVERDXE_H__
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiHiiServicesLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
/* ===================================================================
* Global Data
* =================================================================== */
extern EFI_HANDLE ImageHandle;
extern EFI_SYSTEM_TABLE *SystemTable;
extern EFI_BOOT_SERVICES *BootServices;
extern EFI_RUNTIME_SERVICES_TABLE *RuntimeServices;
/** OOB Map Table - data from unk_5530..unk_5531+ 172*295 bytes */
#define OOB_MAP_TABLE_ENTRIES 295 /* 0x127 */
#define OOB_MAP_TABLE_ENTRY_SIZE 172
#define OOB_DATA_STORE_TYPES 32 /* 0x20 */
#define OOB_DATA_STORE_SIZE 128 /* 0x80 */
#define OOB_MAX_SUBTYPE 112 /* 0x70 */
/** IPMI transport protocol instance (gEfiDxeIpmiTransportProtocolGuid) */
extern void *gIpmiTransportProtocol; /* qword_11B70 */
/** gDsValidMap: bitmask of valid data store types from BMC */
extern UINT32 gDsValidMap; /* dword_11B78 */
/** gResetNeed flag - set when CPU config changes require a system reset */
extern UINT8 gResetNeed; /* byte_11B7C */
/** gIsDefault PID flag */
extern UINT8 gIsDefault; /* byte_5520 */
/** NVRAM variable GUIDs */
extern EFI_GUID gOobSetupVarGuid; /* unk_34D0 */
extern EFI_GUID gSocketPowerVarGuid; /* unk_34D0 */
extern EFI_GUID gSocketProcessorVarGuid; /* unk_34B0 */
extern EFI_GUID gIpmiProtocolGuid; /* unk_34F0 */
extern EFI_GUID gHiiDatabaseGuid; /* unk_34E0 */
extern EFI_GUID gHiiStringGuid; /* unk_34C0 */
extern EFI_GUID gHiiConfigRoutingGuid; /* unk_3490 */
extern EFI_GUID gHiiFontGuid; /* unk_3510 */
extern EFI_GUID gHiiImageGuid; /* unk_34A0 */
/** Debug print handler */
extern VOID *gDebugPrintProtocol; /* qword_35208 */
/** Global HOB list pointer */
extern VOID *gHobList; /* qword_35210 */
/** Working data store array (16 KB): gDsVar[0x2000] */
extern UINT8 gDsVar[0x2000]; /* byte_3520 */
/** Map table structures - array of 32 OOB map entries (128 bytes each) */
extern UINT16 gOobMapTable[32][64]; /* unk_3600 (32 * 128 bytes) */
/** OOB Map Table entry structure - unk_5530 area (172 bytes * 295 entries) */
typedef struct {
UINT8 Type; /* offset -1 from unk_5531, i.e. unk_5530[n*172] */
UINT8 SubType; /* offset 0 from unk_5531 */
UINT8 Reserved[143]; /* offsets 1..143 */
UINT8 ItemCount; /* offset 161 */
UINT16 ItemSize; /* WORD at offset 165: SubType + (Type << 8) ??? */
UINT8 Reserved2[3]; /* offsets 167..169 */
} OOB_MAP_TABLE_ENTRY;
/* ===================================================================
* Constants / Enums
* =================================================================== */
#define SYNC_FROM_DS 1
#define SYNC_WITH_DS 2
#define OOB_PID_UNKNOWN 0xFF
#define OOB_PID_DEFAULT 85 /* 0x55 */
#define MAX_OOB_DATA_STORE 127 /* 0x7F */
#define MAX_OOB_SUBTYPE 112 /* 0x70 */
#define OOB_STORE_INVALID 0x8000000000000002ULL
/* CMOS register addresses */
#define CMOS_ADDR_REG 0x70
#define CMOS_DATA_REG 0x71
#define CMOS_RESET_CTRL 0xCF9
/* CPUID leaf for GbE presence check */
#define CPUID_GBE_LEAF 0x40000000
/* Memory pool type for protocol allocation */
#define MEMORY_POOL_SIZE 31
/* ===================================================================
* Function Prototypes
* =================================================================== */
/**
* Entry point for LnvOobDriverDxe.
* Validates OOB map table, locates IPMI protocol, detects product ID,
* determines sync strategy, performs data synchronization, and optionally
* triggers system reset.
*
* @param[in] ImageHandle The firmware allocated handle for the EFI image.
* @param[in] SystemTable A pointer to the EFI System Table.
* @return EFI_STATUS
*/
EFI_STATUS
EFIAPI
ModuleEntryPoint(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/* ===================================================================
* Internal Functions
* =================================================================== */
/**
* Library constructor: save ImageHandle, SystemTable, BootServices,
* RuntimeServices, locate HII protocols, install IPMI protocol
* notification callback.
*/
__int64
sub_384(
__int64 ImageHandle,
EFI_SYSTEM_TABLE *SystemTable
);
/**
* Store a data entry (128 bytes + 16-byte name) into the global
* OOB data array at the first available slot.
*
* @param[in] Data 128-byte data payload.
* @param[in] Name 16-byte entry name.
* @return EFI_STATUS
*/
UINT64
sub_5A4(
__int64 Data,
__int64 Name
);
/**
* OOBGetDataStoreByType: Retrieve a single data store entry from BMC.
*
* @param[in] Type Data store type (0..0x1F).
* @param[in] SubType Sub-type index (0..0x7E or 0xFF for "all").
* @param[out] Data Output data buffer.
* @return EFI_STATUS
*/
UINT64
OOBGetDataStoreByType(
UINT8 Type,
UINT8 SubType,
UINT8 *Data
);
/**
* OOBGetAllDataStoreByType: Retrieve all data store entries for a type.
*
* @param[in] Type Data store type (0..0x1F).
* @param[out] Data 128-byte output buffer.
* @return EFI_STATUS
*/
UINT64
OOBGetAllDataStoreByType(
UINT8 Type,
UINT8 *Data
);
/**
* OOBGetDataStoreMap: Retrieve the data store valid bitmap from BMC.
*
* @param[in] Param Dummy parameter.
* @return EFI_STATUS (gDsValidMap populated on success)
*/
__int64
OOBGetDataStoreMap(
__int64 Param
);
/**
* OOBSetDataStoreByType: Write a single data store entry to BMC.
*
* @param[in] Type Data store type (0..0x1F).
* @param[in] SubType Sub-type index.
* @param[in] Data Pointer to 2-byte data (Valid, Value).
* @return EFI_STATUS
*/
__int64
OOBSetDataStoreByType(
UINT8 Type,
UINT8 SubType,
UINT8 *Data
);
/**
* BmcDsBitMapToDsVar / BiosVarToDsVar: Synchronize BIOS variables
* from BMC data store (read all OOB entries and populate gDsVar[]).
*
* @return EFI_STATUS (0 on success)
*/
__int64
BmcDsBitMapToDsVar(
__int64 Param
);
/**
* DsVarToBmcDs: Push gDsVar[] back to BMC data store for all 32 types.
*
* @return EFI_STATUS
*/
__int64
DsVarToBmcDs(
__int64 Param
);
/**
* Main synchronization engine: sync gDsVar[] based on gDsValidMap
* and sync type (SYNC_FROM_DS or SYNC_WITH_DS).
*
* @param[in] SyncType 1=SYNC_FROM_DS, 2=SYNC_WITH_DS
* @param[in] Param2 Unused
* @return EFI_STATUS
*/
UINT64
BmcDsBitMapToDsVarSync(
UINT8 SyncType,
__int64 Param2
);
/**
* CheckOobDataStoreValid: Verify OOB data store signature bytes
* (Type=0, SubType=0x7E should return 0x17, SubType=0x7F should return 0xAA).
*
* @return TRUE if valid, FALSE otherwise.
*/
BOOLEAN
CheckOobDataStoreValid(
VOID
);
/**
* LnvOOBSettingsDxeEntry: Main driver entry logic.
* Validates OOB map table, detects PID changes, decides sync strategy,
* performs BIOS<->BMC variable sync, updates CPU config, resets if needed.
*
* @return EFI_STATUS
*/
__int64
LnvOOBSettingsDxeEntry(
__int64 Param
);
/**
* LnvGetProductID: Detect the platform product ID.
* Tries IPMI first, falls back to NVRAM "Setup" variable byte[284].
* Stores result in "LnvOobSetup" NVRAM variable.
*
* @return EFI_STATUS
*/
__int64
LnvGetProductID(
__int64 a1,
__int64 a2,
__int64 a3,
__int64 a4
);
/**
* LnvUpdateOOBSettingsttoSetup: Push OOB settings into
* SocketPowerManagementConfig and SocketProcessorCoreConfig NVRAM variables.
* Compares current values and sets gResetNeed if changes detected.
*
* @return EFI_STATUS
*/
__int64
LnvUpdateOOBSettingsttoSetup(
VOID
);
/**
* IPMI protocol notification callback: locate IPMI protocol.
*/
__int64
sub_2240(
VOID
);
/**
* Debug print function: wraps gDebugPrintProtocol.
*/
UINT8
DebugPrint(
__int64 ErrorLevel,
const char *Format,
...
);
/**
* Assert function: wraps gDebugPrintProtocol AssertBreak.
*/
__int64
AssertBreak(
__int64 FileName,
__int64 LineNumber,
__int64 AssertString
);
/**
* Get HOB list from SystemTable.
*/
__int64
GetHobList(
__int64 Param
);
/**
* Memory compare function.
*/
__int64
MemoryCompare(
unsigned __int64 a1,
UINT8 *a2,
unsigned __int64 Length
);
/**
* Read unaligned 64-bit value (with assertion).
*/
__int64
ReadUnaligned64(
__int64 Buffer
);
/**
* HOB GUID comparison helper.
*/
BOOLEAN
CompareHobGuid(
__int64 a1,
__int64 a2
);
/**
* CPUID wrapper.
*/
__int64
Cpuid(
unsigned int Leaf,
UINT32 *Eax,
UINT32 *Ebx,
UINT32 *Ecx,
UINT32 *Edx
);
/**
* memset wrapper (sets each byte individually).
*/
INT32 *
InternalSetMem(
INT32 *Buffer,
INT32 Value,
UINT64 Length
);
/**
* memmove implementation (overlap-safe copy).
*/
char *
InternalCopyMem(
char *Destination,
const char *Source,
UINT64 Length
);
/**
* Locate debug print protocol singleton.
*/
__int64
GetDebugPrintProtocol(
VOID
);
#endif /* __LNVOOBDRIVERDXE_H__ */