/**
* RegAccessDxe.c - Register Access DXE Driver
*
* Source: CpRcPkg\Universal\RegAccess\Dxe\RegAccessDxe.c
* Module: RegAccessDxe.efi
* PDB: RegAccessDxe.pdb
*
* This DXE driver provides:
* 1. PCIe/IIO register address translation for Intel Xeon Scalable CPUs
* 2. MMIO-based register read/write/modify operations
* 3. S3 boot script recording for register operations
* 4. SMM LockBox save/restore for boot scripts across S3
* 5. Runtime PCIE config space access (virtual address mapping)
*
* The driver initializes by:
* - Saving global boot/runtime service pointers
* - Registering virtual address change notification callbacks
* - Initializing the PCIe address library (HOB-based MMCFG table)
* - Setting up S3 boot script save context
* - Querying IIO topology protocol per socket
* - Enabling MCH (Memory Controller Hub) register access via PCD
* - Initializing the MMIO-based PCIe config access
*/
//=============================================================================
// Driver Entry Point: _ModuleEntryPoint (0x1114)
//=============================================================================
//
// Calls UefiBootServicesTableLib + UefiRuntimeServicesTableLib constructor
// (sub_113C), which:
// - Saves ImageHandle, gST, gBS, gRT
// - Registers SetVirtualAddressChange callback (sub_1D78)
// - Registers ExitBootServices callback (sub_1B18)
// - Locates HOB list (sub_1CF0)
// - Initializes RuntimeLib
// - Locates PCD protocol (sub_18E0)
// - Registers ReadyToBoot event (sub_1C04)
// - Registers PCIe VirtualAddressChange (sub_1D9C)
// - Enables MCH register access via PCD
// - Reads RDTSC for timing
// - Calls sub_265C to initialize S3 boot script context
//
// Then calls RegAccessInstallProtocol (sub_1734) which:
// - Installs the RegAccess protocol
// - Gets PCD data for IIO config (PCD token 6)
// - Allocates pages for PCIe MMIO base
// - Copies IIO config data to allocated buffer
//
// On failure, calls RegAccessUnload (sub_1584).
//
//=============================================================================
// _ModuleEntryPoint (0x1114)
//=============================================================================
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Initialize library constructors and install protocol
//
Status = UefiBootServicesTableLibConstructor (ImageHandle, SystemTable);
if (!EFI_ERROR (Status)) {
Status = RegAccessInstallProtocol ();
}
if (EFI_ERROR (Status)) {
RegAccessUnload ();
}
return Status;
}
//=============================================================================
// sub_1000 (0x1000) - CopyMem - optimized memory copy with overlap handling
//=============================================================================
//=============================================================================
// sub_1070 (0x1070) - ZeroMem - zero memory buffer (rep stos)
//=============================================================================
//=============================================================================
// sub_10D0 (0x10D0) - _mm_pause() - CPU spin-wait hint
//=============================================================================
//=============================================================================
// sub_10E0 (0x10E0) - ReadTSC - read time-stamp counter
//=============================================================================
//=============================================================================
// sub_10F0 (0x10F0) - _enable() - enable interrupts (STI)
//=============================================================================
//=============================================================================
// sub_1100 (0x1100) - _disable() - disable interrupts (CLI)
//=============================================================================
//=============================================================================
// sub_1110 (0x1110) - ReadEFlags - read EFLAGS register
//=============================================================================
//=============================================================================
// sub_113C (0x113C) - UefiBootServicesTableLib + UefiRuntimeServicesTableLib
// Constructor (AutoGen + library deps)
//=============================================================================
//=============================================================================
// sub_1584 (0x1584) - RegAccessUnload - driver unload handler
//=============================================================================
//=============================================================================
// sub_1734 (0x1734) - RegAccessInstallProtocol - installs the Register Access
// protocol and initializes IIO topology data
//=============================================================================
//=============================================================================
// sub_18AC (0x18AC) - AddressTranslateEx - dispatch-based PCIe address
// translation (uses funcs_18D0 jump table)
//=============================================================================
//=============================================================================
// sub_18E0 (0x18E0) - GetPcdProtocol - locate and cache PCD protocol
//=============================================================================
//=============================================================================
// sub_196C (0x196C) - PcdGet32(5) - get PCD token 5 as UINT32
//=============================================================================
//=============================================================================
// sub_1988 (0x1988) - PcdGetSize(6) - get PCD token 6 size
//=============================================================================
//=============================================================================
// sub_19A4 (0x19A4) - PcdGetSize(6) via offset 56 (alternative size func)
//=============================================================================
//=============================================================================
// sub_19C0 (0x19C0) - GetDebugProtocol - locate debug print protocol
//=============================================================================
//=============================================================================
// sub_1A48 (0x1A48) - DebugPrint - formatted debug output with CMOS level check
//=============================================================================
//=============================================================================
// sub_1AC8 (0x1AC8) - Assert - debug assertion handler
//=============================================================================
//=============================================================================
// sub_1B08 (0x1B08) - ReturnTrue - always returns TRUE (1)
//=============================================================================
//=============================================================================
// sub_1B0C (0x1B0C) - ClearBsBootServices - nulls gBS_Saved on BootScript
//=============================================================================
//=============================================================================
// sub_1B18 (0x1B18) - ExitBootServicesNotify - converts debug protocol ptr
//=============================================================================
//=============================================================================
// sub_1B40 (0x1B40) - GetSystemConfigurationTable - locate config table by GUID
//=============================================================================
//=============================================================================
// sub_1C04 (0x1C04) - EfiCreateEventReadyToBoot - register ReadyToBoot notify
//=============================================================================
//=============================================================================
// sub_1CF0 (0x1CF0) - GetHobList - locate HOB list from config table
//=============================================================================
//=============================================================================
// sub_1D78 (0x1D78) - VirtualAddressChangeNotify - runtime virtual addr change
//=============================================================================
//=============================================================================
// sub_1D9C (0x1D9C) - DxeRuntimePciExpressLibDestructor - PCIe cleanup
//=============================================================================
//=============================================================================
// sub_1E0C (0x1E0C) - PciExpressGetAddress - translate PCIe addr to virtual
//=============================================================================
//=============================================================================
// sub_1ED0 (0x1ED0) - BootScriptWriteTerminator - write entry in boot script
//=============================================================================
//=============================================================================
// sub_1F2C (0x1F2C) - BootScriptSaveExec - execute S3 boot script save sequence
//=============================================================================
//=============================================================================
// sub_244C (0x244C) - SmmReadyToLockNotify - transition to SMM ready-to-lock
//=============================================================================
//=============================================================================
// sub_2498 (0x2498) - BootScriptLockBoxBufferSwitch - switch to LockBox buffer
//=============================================================================
//=============================================================================
// sub_24F0 (0x24F0) - BootScriptLockBoxComplete - finalize LockBox save
//=============================================================================
//=============================================================================
// sub_2594 (0x2594) - BootScriptSaveNotify - S3 boot script save notification
//=============================================================================
//=============================================================================
// sub_265C (0x265C) - BootScriptContextInit - initialize S3 boot script context
//=============================================================================
//=============================================================================
// sub_295C (0x295C) - BootScriptContextDeinit - release boot script context
//=============================================================================
//=============================================================================
// sub_2BD8 (0x2BD8) - BootScriptAllocBuf - allocate space in boot script buffer
//=============================================================================
//=============================================================================
// sub_2D6C (0x2D6C) - BootScriptLockBoxRestore - restore script from LockBox
//=============================================================================
//=============================================================================
// sub_2E24 (0x2E24) - BootScriptGetEntry - get entry buffer for script write
//=============================================================================
//=============================================================================
// sub_2EB8 (0x2EB8) - BootScriptCommit - commit script entry via LockBox update
//=============================================================================
//=============================================================================
// sub_2F78 (0x2F78) - BootScriptIoWrite - write IO port entry to boot script
//=============================================================================
//=============================================================================
// sub_3028 (0x3028) - PciExpressRead - PCIe config space MMIO read
//=============================================================================
//=============================================================================
// sub_3070 (0x3070) - PciExpressWrite - PCIe config space MMIO write
//=============================================================================
//=============================================================================
// sub_30B4 (0x30B4) - CombineAndOrMask - AND+OR mask combination for reg modify
//=============================================================================
//=============================================================================
// sub_3150 (0x3150) - PcieTranslateAddress - core address translation engine
//=============================================================================
//=============================================================================
// sub_326C (0x326C) - PcieReadSingle - read a single PCIe register
//=============================================================================
//=============================================================================
// sub_3320 (0x3320) - PcieModifySingle - read-modify-write a PCIe register
//=============================================================================
//=============================================================================
// sub_33B4 (0x33B4) - AddressTranslate - translate PCIe addr with segment base
//=============================================================================
//=============================================================================
// sub_33E8 (0x33E8) - PcieReadFromTranslation - read via address translation
//=============================================================================
//=============================================================================
// sub_342C (0x342C) - ValidateRegisterAccess - validate register access params
//=============================================================================
//=============================================================================
// sub_3514 (0x3514) - PcieReadMulti - multi-register PCIe read (block read)
//=============================================================================
//=============================================================================
// sub_35CC (0x35CC) - PcieWriteSingle - write a single PCIe register
//=============================================================================
//=============================================================================
// sub_36FC (0x36FC) - PcieModifyWithMask - PCIe register modify with AND/OR
//=============================================================================
//=============================================================================
// sub_3764 (0x3764) - CopyMemSafe - safe memory copy (BaseMemoryLib wrapper)
//=============================================================================
//=============================================================================
// sub_3800 (0x3800) - CompareGuid - compare two EFI_GUIDs
//=============================================================================
//=============================================================================
// sub_3868 (0x3868) - ZeroMemSafe - safe zero memory wrapper
//=============================================================================
//=============================================================================
// sub_38CC (0x38CC) - ReadUnaligned64 - read unaligned UINT64
//=============================================================================
//=============================================================================
// sub_38FC (0x38FC) - RShiftU64 - 64-bit right shift
//=============================================================================
//=============================================================================
// sub_3940 (0x3940) - LShiftU64 - 64-bit left shift
//=============================================================================
//=============================================================================
// sub_3984 (0x3984) - IoRead16 - read 16-bit IO port
//=============================================================================
//=============================================================================
// sub_39B4 (0x39B4) - IoWrite16 - write 16-bit IO port
//=============================================================================
//=============================================================================
// sub_39F4 (0x39F4) - IoRead64 - read 64-bit memory-mapped IO
//=============================================================================
//=============================================================================
// sub_3A24 (0x3A24) - IoWrite64 - write 64-bit memory-mapped IO
//=============================================================================
//=============================================================================
// sub_3A64 (0x3A64) - IoRead32 - read 32-bit IO port
//=============================================================================
//=============================================================================
// sub_3A94 (0x3A94) - BootScriptFreePcieMapping - free PCIe mapping table
//=============================================================================
//=============================================================================
// sub_3AE0 (0x3AE0) - GetSmmBase2 - locate SmmBase2 protocol
//=============================================================================
//=============================================================================
// sub_3B30 (0x3B30) - GetLockBoxCommBuffer - locate SMM LockBox comm buffer
//=============================================================================
//=============================================================================
// sub_3BD0 (0x3BD0) - LockBoxSave - save data to SMM LockBox
//=============================================================================
//=============================================================================
// sub_3D14 (0x3D14) - LockBoxSetAttributes - set LockBox attributes
//=============================================================================
//=============================================================================
// sub_3E40 (0x3E40) - LockBoxUpdate - update LockBox entry data
//=============================================================================
//=============================================================================
// sub_3F88 (0x3F88) - LockBoxRestore - restore data from SMM LockBox
//=============================================================================
//=============================================================================
// sub_40E0 (0x40E0) - MmcfgTableInit - initialize MMCFG table
//=============================================================================
//=============================================================================
// sub_421C (0x421C) - IioGetPhysicalBase - get MMCFG base for PCI segment
//=============================================================================
//=============================================================================
// sub_4344 (0x4344) - IioTopologyInit - initialize IIO topology from protocol
//=============================================================================
//=============================================================================
// sub_4500 (0x4500) - FatalAssert - unrecoverable assertion (infinite loop)
//=============================================================================
//=============================================================================
// sub_4568 (0x4568) - IioGetBusFromSocket - get PCI bus for socket/box type
//=============================================================================
//=============================================================================
// sub_4784 (0x4784) - IioGetSegment - get PCIe segment for box/instance
//=============================================================================
//=============================================================================
// sub_4BBC (0x4BBC) - IioGetDevice - get PCI device for box/instance/block
//=============================================================================
//=============================================================================
// nullsub_1 (0x1D74) - no-op - Null event notification handler
//=============================================================================