# Platform DXE Setup Driver (0340_Platform)

## Module Identity
- **Binary name**: Platform.efi
- **Index**: 0340
- **SHA256**: fe4cd1cf7297a61019be51319f9498ae02e35a64fd7f23c4b593072a7eeee455
- **MD5**: 9b0999f73209d97ec9936f2ed566a57d
- **Image size**: 0x405a0 bytes (258.0 KB)
- **Architecture**: x86-64 (UEFI DXE driver)
- **Total functions**: 144 (all named)
- **Strings**: 382
- **IDA port**: 13345

## Overview
This is the **DxePlatform Setup driver** from the Purley Refresh (PurleyRpPkg) platform for the Lenovo ThinkSystem HR650X BIOS. It is one of the core platform setup configuration drivers, responsible for:

1. **HII Form Management**: Registering and managing BIOS setup forms via UEFI HII
2. **Setup Variable Handling**: Reading, writing, and migrating setup configuration variables
3. **ME (Management Engine) Configuration**: Setting up SPS (Server Platform Services) configuration
4. **Disk Information Display**: Enumerating ATA/ATAPI devices and displaying disk info in setup
5. **Boot Option Maintenance**: Handling boot configuration options
6. **S3 Resume Support**: Writing S3 boot script entries for resume

## Key Components

### Entry Point & Initialization
| Address | Name | Description |
|---------|------|-------------|
| 0x464 | `_ModuleEntryPoint` | Standard UEFI module entry point |
| 0x490 | `DriverInit` | Initializes gImageHandle, gST, gBS, gRT, gDS, looks up HII protocols, MM PCI, USRA |
| 0x9EC | `DriverEntryMain` | Main logic: calls GetAndSetSocketIioConfig, installs setup variables, HII protocols |
| 0x14B4 | `DxePlatformDriverEntry` | Registers HII ConfigAccess protocol with 3 callbacks (RouteConfig, ExtractConfig, Callback) |
| 0x13A4 | `LocateHiiSetup` | Locates HII setup protocol handles |

### HII Callbacks (EFI_HII_CONFIG_ACCESS_PROTOCOL)
The driver registers three standard HII ConfigAccess callbacks:

| Address | Name | Purpose |
|---------|------|---------|
| 0x198C | `HiiRouteConfig` | Routes configuration requests (Callback A) |
| 0x1B18 | `HiiExtractConfig` | Extracts configuration (Callback B) |
| 0x20C0 | `SetupFormCallback` | Main form callback - handles all browser actions |
| 0x1EEC | `HiiConfigRouting` | Configuration routing handler |
| 0x28C0 | `SetupActionHandler` | Handles SocketMPLink, SocketIOConfiguration, SocketProcessorConfiguration options |
| 0x2BA8 | `SetupRouteHandler` | Main setup configuration route handler |

### Setup Configuration
| Address | Name | Description |
|---------|------|-------------|
| 0x32CC | `SetupIfrNavigator` | Navigates IFR form elements |
| 0x3398 | `SetupActionDispatcher` | Dispatches setup actions to handlers |
| 0x3478 | `SetupValueSetter` | Sets setup values |
| 0x35EC | `SetupValueFormatter` | Formats values for display |
| 0x3BE0 | `SetupBootOptionMaint` | Boot option maintenance |
| 0x5370 | `SetupOptionProcessor` | Processes setup configuration options |
| 0x5594 | `SetupOptionQuery` | Queries option values |
| 0x5710 | `PlatformSetupPolicy` | Platform-level setup policy |
| 0x5808 | `ProcessSetupConfig` | Processes complete setup configuration |

### Management Engine (ME) Configuration
| Address | Name | Description |
|---------|------|-------------|
| 0x3E14 | `MeInitSpsInfo` | ME SPS info initialization - reads MEFS1/MEFS2 registers, configures ME subsystems |
| 0x47F0 | `MeExtractSpsConfigOnSetupEnter` | Extracts ME type (SPS/WS/DFX/DISABLED) and firmware mode on setup entry |
| 0x4970 | `MeSetupConfiguration` | Configures all ME-related setup options |
| 0x4BE8 | `ExtractMeSpsConfig` | Extracts ME SPS configuration data |
| 0x4CA4 | `MeFirmwareUpdateHandler` | Handles ME firmware update operations |

The ME subsystem options configured include:
- HECI protocol interface
- PECI (Platform Environment Control Interface)
- ASA (Auxiliary Security Agent)
- ME Shutdown
- Telemetry Hub
- Turbo State Limiting
- Flash Descriptor Region Verification
- CUPS (Converged Unified Platform Services)
- MCTP (Management Component Transport Protocol)
- Direct ME Update
- Dual ME Image
- DeepSx Power States
- PCH Thermal Sensor

### Disk Info Records (SetupInfoRecords.c)
| Address | Name | Description |
|---------|------|-------------|
| 0x36A0 | `PopulateDiskInfoRecords` | Enumerates ATA/ATAPI handles, reads IDENTIFY data, builds info strings |
| 0xA194 | `SetupRecordsGetSet` | Gets or sets info records |
| 0xA2B0 | `SetupRecordsList` | Lists info records |
| 0xA370 | `SetupInfoRecordsDisplay` | Displays records in setup form |
| 0xA440 | `SetupRecordsNavigate` | Navigates records |
| 0xA588 | `SetupInfoRecordsWriter` | Writes records to HII database |

This component enumerates all handles with ATA/ATAPI Block IO protocol, reads device IDENTIFY data, extracts:
- Model name
- Capacity in GB (with proper size calculation)
- ATAPI vs HDD detection
- Serial number

### Setup Variable Management
| Address | Name | Description |
|---------|------|-------------|
| 0x8E84 | `InstallSetupVariables` | Creates and sets all setup variables |
| 0x841C | `SetSetupVariable` | Sets a setup UEFI variable |
| 0x801C | `GetSetupString` | Gets a setup configuration string |
| 0x82D0 | `SetupVariableReadback` | Reads back setup variable for verification |
| 0x8DC8 | `SetupVarMigrate` | Migrates setup variables between versions |
| 0x8CCC | `SetupDataMigrate` | Migrates setup data between generations |
| 0x8C80 | `SetupVarSizeCheck` | Checks setup variable size |
| 0xAF68 | `SetupVariableGet` | Gets setup variable from UEFI variable store |
| 0xB094 | `SetupVariableSet` | Sets setup variable in UEFI variable store |

### S3 Boot Script Support
| Address | Name | Description |
|---------|------|-------------|
| 0x7B08 | `WriteS3BootScript` | Writes boot script entries for S3 resume |
| 0x8760 | `VariableServicesInit` | Initializes variable services for S3 path |

### Device Path Operations
| Address | Name | Description |
|---------|------|-------------|
| 0x60C8 | `CreateDevicePath` | Creates vendor device path node |
| 0x749C | `DevicePathNodeOps` | Device path node operations |
| 0x7524 | `DevicePathType` | Gets device path type |
| 0x7550 | `DevicePathSubType` | Gets device path subtype |
| 0x7580 | `DevicePathNodeLength` | Gets node length |
| 0x75B8 | `DevicePathNextNode` | Advances to next node |
| 0x75F0 | `DevicePathIsMultiInstance` | Checks multi-instance |
| 0x762C | `DevicePathIsEndInstance` | Checks end instance |
| 0x7680 | `DevicePathAppend` | Appends device paths |
| 0x77A4 | `DevicePathUtilities` | General device path utilities |

### Low-Level I/O Access
| Address | Name | Description |
|---------|------|-------------|
| 0x62A0 | `WritePciCfg` | Writes to PCI configuration space |
| 0x62D4 | `ReadPciCfg` | Reads from PCI configuration space |
| 0x7ACC | `ReadCpuPciCfg` | Reads CPU PCI config via MM PCI protocol |
| 0x7C28 | `ReadCpRcCfg` | Reads CpRc register |
| 0x7CE0 | `GetManufacturingMode` | Returns manufacturing mode flag |
| 0xABD0 | `IoRead8` | 8-bit I/O port read |
| 0xAC00 | `IoWrite8` | 8-bit I/O port write |
| 0xACDC | `IoRead16` | 16-bit I/O port read |
| 0xAD34 | `IoWrite16` | 16-bit I/O port write |
| 0xAD84 | `IoRead32` | 32-bit I/O port read |
| 0xAE24 | `IoWrite32` | 32-bit I/O port write |
| 0xAC30 | `MmIoRead32` | 32-bit MMIO read |
| 0xAC60 | `GetTimerValue` | Reads timer for delay calculation |

## Libraries Used
- **BaseLib** (Strings, SafeStrings) - String length, compare, copy
- **BasePrintLib** (PrintLibInternal) - SPrint/VSPrint formatting
- **UefiBootServicesTableLib** - gBS, gImageHandle
- **UefiRuntimeServicesTableLib** - gRT
- **DxeServicesTableLib** - gDS
- **UefiHiiServicesLib** - HII database/string/package list protocols
- **UefiHiiLib** - HII configuration utilities
- **DevicePathLib** - Device path construction/navigation
- **PiDxeS3BootScriptLib** - S3 boot script operations
- **DxeMmPciBaseLib** - MM PCI protocol
- **DxeUsraLib** - USRA protocol

## Protocols Interacted With
| Protocol GUID | Name | Variable |
|---------------|------|----------|
| HII Database | gEfiHiiDatabaseProtocolGuid | gHiiDatabase (0xFF68) |
| HII String | gEfiHiiStringProtocolGuid | gHiiString (0xFF88) |
| HII Package List | gEfiHiiPackageListProtocolGuid | gHiiPackageList (0xFF78) |
| HII Config Routing | gEfiHiiConfigRoutingProtocolGuid | gHiiConfigRouting (0xFF70) |
| HII Config Access | gEfiHiiConfigAccessProtocolGuid | gHiiConfigAccess (0xFF80) |
| MM PCI | gEfiMmPciBaseProtocolGuid | mPciUsra (0xFF00) |
| USRA | gUsraProtocolGuid | mUsra (0xFFA0) |

## UEFI Variables Managed
- `"SocketIioConfig"` - Socket IIO configuration
- `"IntelSetup"` - Main setup configuration (via HII ConfigAccess)
- Platform setup variables installed by `InstallSetupVariables` (0x8E84)

## Source File References
- `e:\hs\PurleyRpPkg\Platform\Dxe\Setup\SetupPlatform.c` (main, 23 refs)
- `e:\hs\PurleyRpPkg\Platform\Dxe\Setup\SetupInfoRecords.c` (10 refs)
- `e:\hs\PurleyRpPkg\Library\SetupLib\DxeSetupLib.c` (14 refs)
- `e:\hs\PurleyRpPkg\Platform\Dxe\Setup\MeSpsSetup.c` (3 refs)
- `e:\hs\MdePkg\Library\BaseLib\String.c` (13 refs)
- `e:\hs\MdePkg\Library\BaseLib\SafeString.c` (8 refs)
- `e:\hs\MdeModulePkg\Library\UefiHiiLib\HiiLib.c` (10 refs)
- `e:\hs\MdePkg\Library\BasePrintLib\PrintLibInternal.c` (8 refs)
- `e:\hs\MdeModulePkg\Library\PiDxeS3BootScriptLib\BootScriptSave.c` (7 refs)
- `e:\hs\Build\HR6N0XMLK\DEBUG_VS2015\X64\PurleyRpPkg\Platform\Dxe\Setup\DxePlatform\DEBUG\AutoGen.c` (3 refs, auto-generated)

## Build Info
- **Platform**: Purley Refresh (HR6N0XMLK)
- **Toolchain**: VS2015
- **Target**: DEBUG
- **Architecture**: X64
- **BIOS**: Lenovo HR650X (ThinkSystem)

## Function Count: 144
- Named: 144 (100%)
- Unnamed: 0