/**
 * @file SetupPlatform.h
 * @brief Header for Platform DXE Setup Driver (Purley Refresh / HR650X)
 *
 * Module: Platform (index 0340)
 * Image: Platform.efi
 * Arch:  x86-64 (UEFI DXE driver)
 * Size:  0x405a0 bytes
 * IDA Port: 13345
 */

#ifndef __PLATFORM_SETUP_H__
#define __

#include "../uefi_headers/Uefi.h"
PLATFORM_SETUP_H__

// ============================================================================
// Module Information
// ============================================================================

#define MODULE_NAME          "Platform"
#define MODULE_INDEX         "0340"
#define MODULE_GUID          "FE4CD1CF-7297-A610-19BE-51319F9498AE"
#define MODULE_SIZE          0x405a0
#define MODULE_ARCH          "x86-64"
#define MODULE_TYPE          "DXE Driver"
#define MODULE_SOURCE        "PurleyRpPkg/Platform/Dxe/Setup/"
#define MODULE_TOTAL_FUNCS   144

// ============================================================================
// Source Files
// ============================================================================

#define SRC_SETUPPPLATFORM   "PurleyRpPkg/Platform/Dxe/Setup/SetupPlatform.c"
#define SRC_SETUPINFORECORDS "PurleyRpPkg/Platform/Dxe/Setup/SetupInfoRecords.c"
#define SRC_MESPSETUP        "PurleyRpPkg/Platform/Dxe/Setup/MeSpsSetup.c"
#define SRC_DXESETUPLIB      "PurleyRpPkg/Library/SetupLib/DxeSetupLib.c"

// ============================================================================
// Segment Layout
// ============================================================================

#define SEG_HEADER   0x00000  // size 0x2E0
#define SEG_TEXT     0x002E0  // size 0xB1E0 (code)
#define SEG_RDATA    0x0B4C0  // size 0x4480 (strings)
#define SEG_DATA     0x0F940  // size 0x83C0 (globals)
#define SEG_SEG004   0x17D00  // size 0x620
#define SEG_XDATA    0x18320  // size 0x500
#define SEG_RSRC     0x18820  // size 0x27CE0 (HII resources)
#define SEG_RELOC    0x40500  // size 0xA0
#define SEG_GAP      0x405A0  // size 0xA60

// ============================================================================
// Key String Addresses
// ============================================================================

#define STR_ASSERT_EFI_ERROR        0xB4C0  // "\nASSERT_EFI_ERROR (Status = %r)\n"
#define STR_NOT_EFI_ERROR_STATUS    0xB4E8  // "!EFI_ERROR (Status)"
#define STR_SETUPPPLATFORM_PATH     0xB598  // "e:\hs\PurleyRpPkg\Platform\Dxe\Setup\SetupPlatform.c"
#define STR_UEFI_OPTIMIZED_BOOT     0xB600  // "UEFI Optimized Boot toggled to Enabled!\n"
#define STR_DXESETUPLIB_PATH        0xE708  // "e:\hs\PurleyRpPkg\Library\SetupLib\DxeSetupLib.c"
#define STR_SETUPINFORECORDS_PATH   0xC0E0  // "e:\hs\PurleyRpPkg\Platform\Dxe\Setup\SetupInfoRecords.c"
#define STR_MESPSETUP_PATH          0xCC78  // "e:\hs\PurleyRpPkg\Platform\Dxe\Setup\MeSpsSetup.c"
#define STR_INTELSETUP             0xFC50  // "IntelSetup"

// ============================================================================
// Known Protocol GUIDs (stored in .rdata)
// ============================================================================

#define GUID_HII_DATABASE          0xFB30
#define GUID_HII_STRING            0xFB10
#define GUID_HII_PACKAGE_LIST      0xFAC0
#define GUID_HII_CONFIG_ROUTING    0xFC30
#define GUID_HII_CONFIG_ACCESS     0xFAE0
#define GUID_MM_PCI_BASE           0xFA00
#define GUID_PROTOCOL_GEN          0xFA90
#define GUID_HII_CONFIG_ACCESS_INSTALL 0xFBA0

// ============================================================================
// Global Variable Addresses
// ============================================================================

#define VAR_IMAGEHANDLE            0xFED8
#define VAR_SYSTEMTABLE            0xFEC8
#define VAR_BOOTSERVICES           0xFED0
#define VAR_RUNTIMESERVICES        0xFEE0
#define VAR_DXESERVICES            0xFEF8
#define VAR_HII_DATABASE           0xFF68
#define VAR_HII_STRING             0xFF88
#define VAR_HII_PACKAGE_LIST       0xFF78
#define VAR_HII_CONFIG_ROUTING     0xFF70
#define VAR_HII_CONFIG_ACCESS      0xFF80
#define VAR_USRA                   0xFFA0
#define VAR_PCI_USRA               0xFF00
#define VAR_QWORD_FEA8             0xFEA8
#define VAR_QWORD_FE70             0xFE70
#define VAR_WORD_FCBC              0xFCBC

// ============================================================================
// Function Table
// ============================================================================

// --- Entry Point ---
// 0x464  _ModuleEntryPoint          Entry point (calls DriverInit + DriverEntryMain)

// --- Driver Init ---
// 0x490  DriverInit                 Driver initialization (globals, protocols)
// 0x8F8  GetAndSetSocketIioConfig   Read/write "SocketIioConfig" UEFI var
// 0x9EC  DriverEntryMain            Main driver logic entry
// 0x13A4 LocateHiiSetup             Locate HII setup protocol
// 0x14B4 DxePlatformDriverEntry     Main entry: register HII ConfigAccess + callbacks
// 0x18A8 HiiSubCallback             Sub-callback for HII operations
// 0x198C HiiRouteConfig             HII RouteConfig handler
// 0x1B18 HiiExtractConfig           HII ExtractConfig handler
// 0x1D58 HiiCallbackHelper          HII callback helper
// 0x1E00 HiiFormActions             HII form action handler
// 0x1EEC HiiConfigRouting           HII ConfigRouting handler

// --- Setup Form Callbacks ---
// 0x20C0 SetupFormCallback          Main HII Form Callback (Browser callback)
// 0x28C0 SetupActionHandler         Handle setup form actions (Socket configs)
// 0x2A50 SetupValueChangeHandler    Handle value change events
// 0x2BA8 SetupRouteHandler          Main route handler for setup
// 0x32CC SetupIfrNavigator          Navigate IFR elements
// 0x3398 SetupActionDispatcher      Dispatch setup actions
// 0x3478 SetupValueSetter           Set setup values
// 0x35EC SetupValueFormatter        Format values for display
// 0x3BE0 SetupBootOptionMaint       Boot option maintenance

// --- ME (Management Engine) ---
// 0x3E14 MeInitSpsInfo              ME SPS info initialization
// 0x47F0 MeExtractSpsConfigOnSetupEnter  ME config extraction
// 0x4970 MeSetupConfiguration       ME setup configuration
// 0x4BE8 ExtractMeSpsConfig         Extract ME SPS config data
// 0x4CA4 MeFirmwareUpdateHandler    ME firmware update handling

// --- Setup Info Records (SetupInfoRecords.c) ---
// 0x36A0 PopulateDiskInfoRecords    Populate disk info for setup display
// 0xA194 SetupRecordsGetSet         Get/set setup info records
// 0xA2B0 SetupRecordsList           List setup records
// 0xA370 SetupInfoRecordsDisplay    Display info records
// 0xA440 SetupRecordsNavigate       Navigate info records
// 0xA588 SetupInfoRecordsWriter     Write info record to HII

// --- Setup Display & Processing ---
// 0x5044 SetupDisplayStrings        Display setup strings
// 0x5370 SetupOptionProcessor       Process setup options
// 0x5594 SetupOptionQuery           Query setup options
// 0x5628 SetupValueCheck            Check setup values
// 0x5710 PlatformSetupPolicy        Platform setup policy
// 0x5808 ProcessSetupConfig         Process full setup config
// 0x7E20 SetupPolicyInit            Initialize setup policy

// --- Setup IFR / Config Access ---
// 0x9170 SetupIfrExtractor          Extract IFR from HII
// 0x93E0 SetupIfrStringLoader       Load IFR strings
// 0x959C SetupIfrPackLoader         Load IFR pack
// 0x9650 SetupConfigRouting         Route config requests
// 0x9680 SetupConfigAccessExtract   ConfigAccess extract
// 0x970C SetupKeywordHandler        HII keyword handler
// 0x9A9C SetupIfrBuilder            Build IFR data
// 0xA6D8 SetupIfrConfigAccess       IFR ConfigAccess
// 0xA874 SetupIfrOptionLookup       Look up IFR option
// 0xA918 SetupIfrOptionValue        Get IFR option value
// 0xA9DC SetupIfrKeywordHandle      Handle IFR keyword
// 0xAA70 SetupIfrSupplement         Supplement IFR entries

// --- Setup Variable Operations ---
// 0x801C GetSetupString             Get setup config string
// 0x8258 SetupBufferOps             Buffer operations
// 0x82D0 SetupVariableReadback      Readback setup variable
// 0x841C SetSetupVariable           Set setup variable
// 0x8588 WriteProtocolVar           Write protocol variable
// 0x8C80 SetupVarSizeCheck          Check variable size
// 0x8CCC SetupDataMigrate           Migrate setup data
// 0x8D24 MigrateOldSetupVar         Migrate old var format
// 0x8DC8 SetupVarMigrate            Setup variable migration
// 0x8E84 InstallSetupVariables      Install all setup variables
// 0xAF68 SetupVariableGet           Get setup variable
// 0xB094 SetupVariableSet           Set setup variable
// 0xB1A4 SetupConfigExtract         Extract setup config
// 0xB2DC SetupConfigRoute           Route setup config
// 0xB418 SetupCallbackFinal         Final setup callback

// --- Variable Services / S3 ---
// 0x8760 VariableServicesInit       Variable services init (S3 paths)
// 0x8704 PublishInterface           Publish UEFI protocol interface
// 0x7B08 WriteS3BootScript          S3 boot script table write

// --- HII Infrastructure ---
// 0x4EB0 HiiStringPacker            Pack HII strings
// 0x59B8 LocateHiiSetupConfig       Locate HII setup config
// 0x7B8C HiiStringToToken           HII string to token
// 0x7BDC HiiStringToToken2          HII string to token (alt)
// 0x85F0 RegisterHiiPackage         Register HII package list
// 0x980C ConstructConfigHdr         Build config request header
// 0x9C04 CheckActionFlag            Check HII action flag
// 0x6140 ExtractConfig              Extract HII config

// --- String Operations ---
// 0x4E18 StrAppendInfo              Append info to string
// 0x4E48 StrLen                     Safe string length (wide)
// 0x519C StrCatS                    Safe string concat (wide)
// 0x5570 AsciiStrnLenS              Safe ASCII string length
// 0x594C BoolToString               Boolean to display string
// 0x5AC8 UnicodeStrToUpper          Unicode string to upper
// 0x5D50 StrCmpS                    Safe string compare (wide)
// 0x6184 UnicodeToString            Unicode to ASCII
// 0x6210 AsciiStrLen                ASCII string length
// 0x6230 Uint64ToStr                UINT64 to string
// 0x5A84 GetUint16AtIndex           Get UINT16 at byte index
// 0x2E0  AsciiStrCpyS               Safe ASCII string copy

// --- Memory Operations ---
// 0x310  CopyMemOverlap             Memcpy with overlap handling
// 0x360  ZeroMemFast                Fast zero memory
// 0x380  SetMem32                   Fill with 32-bit pattern
// 0x5BF8 GetUint32                  Get 32-bit value
// 0x5C24 SetUint8                   Set 8-bit value
// 0x5C50 CopyMem                    Memory copy (standard)
// 0x5CEC ZeroMem                    Zero memory (standard)
// 0x5E28 CompareMem                 Compare memory
// 0x5E90 AllocatePool               Allocate memory pool
// 0x5EC0 GetVariableSize            Get UEFI variable size
// 0x5EF0 SetMemRange                Set memory range
// 0x5F24 CalculateCrc               Calculate CRC
// 0x606C AllocateCopyPool           Allocate and copy
// 0x609C AllocateZeroPool           Allocate zeroed pool
// 0x5FA4 DebugPrint                 Debug print/log
// 0x602C Assert                     Assertion handler
// 0x8B8  CpuDeadLoop                CPU infinite halt loop

// --- Print Library ---
// 0x634C PrintLibInternalSPrint     Internal SPrint implementation
// 0x665C PrintLibUnicodeVSPrint     Unicode VSPrint

// --- Device Path ---
// 0x60C8 CreateDevicePath           Create vendor device path
// 0x7478 DevicePathIsEnd            Check if device path is end
// 0x749C DevicePathNodeOps          Device path node operations
// 0x7524 DevicePathType             Get device path type
// 0x7550 DevicePathSubType          Get device path subtype
// 0x7580 DevicePathNodeLength       Get device path node length
// 0x75B8 DevicePathNextNode         Get next device path node
// 0x75F0 DevicePathIsMultiInstance  Check multi-instance
// 0x762C DevicePathIsEndInstance    Check end instance
// 0x7680 DevicePathAppend           Append device path
// 0x77A4 DevicePathUtilities        Device path utilities

// --- Protocol Locators ---
// 0x5B6C LocateProtocol             Locate UEFI protocol
// 0x76E0 GetDxeServicesTable        Get DXE services table
// 0x7890 LocateHandleBuffer         Locate handle buffer
// 0x7988 GetAllHandlesByProtocol    Get all handles by protocol

// --- PCI / Register Access ---
// 0x62A0 WritePciCfg                Write PCI config
// 0x62D4 ReadPciCfg                 Read PCI config
// 0x7ACC ReadCpuPciCfg              Read CPU PCI config (MM PCI)
// 0x7C28 ReadCpRcCfg                Read CpRc config
// 0x7C64 ReadCpRcCfg2               Read CpRc config (alt)
// 0x7CE0 GetManufacturingMode       Get manufacturing mode

// --- I/O Access ---
// 0xABD0 IoRead8                    Read 8-bit I/O
// 0xAC00 IoWrite8                   Write 8-bit I/O
// 0xAC30 MmIoRead32                 Read 32-bit MMIO
// 0xAC60 GetTimerValue              Get timer value
// 0xACDC IoRead16                   Read 16-bit I/O
// 0xAD34 IoWrite16                  Write 16-bit I/O
// 0xAD84 IoRead32                   Read 32-bit I/O
// 0xAE24 IoWrite32                  Write 32-bit I/O

// --- CPU / Misc ---
// 0x3C0  IoRead32Stall              I/O read with stall
// 0x3D0  DisableInterrupts          CLI
// 0x3E0  EnableInterrupts           STI
// 0x3F0  DisableCache               Disable cache
// 0x400  CpuIdFeatureCheck          CPUID check
// 0x410  ReadMsr                    MSR read
// 0x57D8 GetSetupVarSize            Get setup variable size

// ============================================================================
// Statistics
// ============================================================================

// Total functions: 144
// Strings: 382
// Segments: 9
// Named functions: 144 (100%)
// Image size: 0x405a0 (258.0 KB)
// Text section: 0xB1E0 (45.5 KB)
// Resource section: 0x27CE0 (159.7 KB) - HII IFR data

// ============================================================================
// Source File Breakdown
// ============================================================================

// SetupPlatform.c:        ~23 refs  (main entry, HII callbacks, form actions)
// SetupInfoRecords.c:     ~10 refs  (disk info population + display)
// MeSpsSetup.c:           ~3 refs   (ME SPS configuration)
// DxeSetupLib.c:          ~14 refs  (setup library utilities)
// UefiBootServicesTableLib.c: ~3 refs
// UefiRuntimeServicesTableLib.c: ~1 ref
// DxeServicesTableLib.c:  ~3 refs
// UefiHiiServicesLib.c:   ~4 refs
// BasePrintLib:           ~8 refs
// BaseLib (String/SafeString): ~21 refs
// UefiHiiLib:             ~10 refs
// UefiDevicePathLib:      ~7 refs
// PiDxeS3BootScriptLib:   ~7 refs
// UefiLib:                ~8 refs
// DxeMmPciBaseLib:        ~2 refs
// DxeUsraLib:             ~3 refs
// UefiDevicePathLib:      ~7 refs
// PeiHobLib:              ~4 refs
// BootGuardTCG2.c:        ~3 refs (BootGuard TCG2 logging)

#endif // __PLATFORM_SETUP_H__