# MrcOemHooksPeim - Module Analysis

## Overview

**Module:** MrcOemHooksPeim.efi (index 0372)
**Hash:** ec5c461bc56ce7ac930e64fcb6aea6e956b9a6985d0434fae2ef7c066cfc4f64
**Source Path:** HR650X_3647_AJAX_BIOS_ORIGINAL.pe_structured/pe_files/0372_MrcOemHooksPeim_ec5c461bc56c
**Architecture:** IA32 (32-bit)
**Base Address:** 0xffdb79f4
**Image Size:** 0x182e0 (99,040 bytes)

## Binary Statistics

- Total Functions: 201
- Named Functions (after rename): 103
- Library Functions: 0
- Unnamed Functions: 98
- Total Strings: 491
- Total Segments: 6

## Source Files

This module is compiled from the following source paths:

1. `PurleyPlatPkg\Platform\Pei\MrcOemHooksPeim\MrcOemHooksPeim.c`
2. `PurleyPlatPkg\Library\OemProcMemInitLib\OemProcMemInit.c`
3. `PurleyPlatPkg\Library\OemProcMemInitLib\EdkProcMemInit.c`
4. `PurleyPlatPkg\Library\OemIioInit\OemIioInitPei.c`

## Module Capabilities

### 1. OEM Memory Initialization (MRC)
The core function `OemProcessMrcResult()` handles MRC initialization results:
- `OemInitSysHostMem()` allocates system host memory via `AllocSysHostMemory()`
- `ConfigSysHostMem()` configures system host memory controller registers
- `OemConfigDdrMem()` performs DDR memory training and configuration
- `OemInstallEfiMemory()` installs EFI memory map after MRC

### 2. IIO/UPI Port Bifurcation
Configuration of IIO (Integrated I/O) ports via:
- `OemGetIioPortBifurcation()` - queries and applies bifurcation settings
- `SetIioPortBifurcation()` - writes the actual register values
- `GetIioPortBifurcationCfg()` - looks up configuration per socket/channel
- `SetIioPortBifurcationInit()` - initializes the DQ/DQS pin mapping
- `InitMemConfigData()` - sets up all memory config data structures

### 3. PCIe Topology
- `ConfigPcieTopology()` - enumerates and configures PCIe topology
- `GetPciExpressBar()` - obtains PCIe configuration base address
- `PciReadConfig32()` / `PciWriteConfig32()` - PCI config space access

### 4. OEM Hook System
The module provides a callback/hook dispatch framework:
- `RegisterOemCallbacks()` - registers platform-specific callbacks
- `OemHookDispatch2Arg()` / `OemHookDispatch3Arg()` / `OemHookDispatch4Arg()` / `OemHookDispatch7Arg()` - dispatchers
- `DispatchMemInitHooks()` - dispatches memory init hooks
- `CollectOemCallbacks()` - collects all callbacks from tables

### 5. Soft SKU Licensing
- `OemGetIioSoftSkuInfo()` - reads SocketLicense0/SocketCapability0/ForceProvisioning NVRAM variables
- Applies capability/license data to sockets based on provisioning
- Handles force provisioning override

### 6. TPM Save State
- `OemTpmSaveState()` - runs TPM1.2 or TPM2.0 save state on reset/suspend
- `Tpm2SaveStateRun()` / `Tpm12SaveStateRun()` - actual TPM commands

### 7. ME (Management Engine) Communication
- `MeSendHostResetWarning()` - notifies ME before system reset
- Uses `PeiServicesInstallPpi()` for PPI installation

### 8. NVRAM Save/Restore
- `OemSaveMemNvram()` - saves memory training data via decompression
- `OemLoadSetupData()` - loads setup configuration (IntelSetup variable)
- `ApplySetupDataToConfig()` - applies setup data to memory config

### 9. Board Detection
- `CheckBoardVsCpuConflict()` - detects board vs CPU incompatible configuration
- `GetPchStepping()` - reads PCH stepping
- `GetIioCpuPackageType()` - identifies CPU package type

### 10. Debug & Assert Framework
- `DebugPrint()` / `DbgPrintMemInit()` - platform debug output with severity levels
- `IsDebugEnabled()` / `IsDebugLevelEnabled()` - debug enablement checks
- `AssertEfiError()` - EFI_STATUS check macro

## Key Data Tables

| Address | Name | Size | Purpose |
|---------|------|------|---------|
| 0xffdcef68 | unk_FFDCEF68 | - | PPI descriptor table for module |
| 0xffdcef08 | unk_FFDCEF08 | GUID | gEfiPeiReadOnlyVariable2PpiGuid |
| 0xffdceed8 | unk_FFDCEED8 | GUID | Reset PPI GUID |
| 0xffdceea8 | unk_FFDCEEA8 | GUID | OPA Socket Map HOB GUID |
| 0xffdcec98 | unk_FFDCEC98 | GUID | Variable services PPI GUID |
| 0xffdced38 | unk_FFDCED38 | GUID | MeUma PPI GUID |
| 0xffdced68 | unk_FFDCED68 | GUID | Compress data HOB GUID |
| 0xffdcee58 | unk_FFDCEE58 | GUID | IntelSetup variable GUID |
| 0xffdcf508 | dword_FFDCF508 | 0x10 | 4-arg callback pointer table |
| 0xffdcf518 | dword_FFDCF518 | 0x10 | 2-arg callback pointer table |
| 0xffdcf4fc | dword_FFDCF4FC | 0x10 | 3-arg callback pointer table |
| 0xffdcf500 | dword_FFDCF500 | 0x10 | 7-arg callback pointer table (Set) |
| 0xffdcf51c | dword_FFDCF51C | 0x10 | 7-arg callback pointer table (B) |

## Named Functions Summary

Total named: 103 | Total unnamed remaining: 98 (mostly leaf helpers, small utilities)

### Entry and Init
- MrcOemHooksPeimEntryPoint - module entry point, main init dispatch
- MrcOemHooksPeimMainInit - calls PeiServices->InstallPpi, boots MRC

### Memory Initialization (19 functions)
OemInitSysHostMem, ConfigSysHostMem, ConfigPcieTopology, OemConfigDdrMem,
OemProcessMrcResult, OemInstallEfiMemory, OemSaveMemNvram, OemLoadSetupData,
OemFinalizeMemInit, OemIssueReset, OemGetIioProcMemInit, InstallEfiMemMap,
CheckNvramSanity, CheckNvramCrcSanity, InitMemDefaults, InitMemConfigData,
InitMemCtrlConfig, CalcDimmIndex, ReadDimmSpdData

### IIO/PCI (12 functions)
OemGetIioPortBifurcation, SetIioPortBifurcation, SetIioPortBifurcationInit,
GetIioPortBifurcationCfg, GetIioCpuPackageType, ConfigPcieTopology,
GetPciExpressBar, GetPciCfgBaseAddr, PciReadConfig32, PciWriteConfig32,
AllocSysHostMemory, IsIioInitRequired

### Callback System (10 functions)
RegisterOemCallbacks, CollectOemCallbacks, OemHookDispatch2Arg,
OemHookDispatch3Arg, OemHookDispatch3Arg_1, OemHookDispatch4Arg,
OemHookDispatch7Arg, OemHookDispatch7ArgB, DispatchMemInitHooks,
DispatchMemInitHooksCore

### Debug/Assert/Output (7 functions)
DebugPrint, IsDebugEnabled, IsDebugLevelEnabled, DbgPrintMemInit,
DbgPrintFormatted, DebugPrintBoardConflict, SetErrorStatus

### TPM (4 functions)
OemTpmSaveState, Tpm12SaveStateInit, Tpm12SaveStateRun, Tpm2SaveStateRun

### ME Management (1 function)
MeSendHostResetWarning

### Soft SKU (6 functions)
OemGetIioSoftSkuInfo, GetFullSpeedEparamEntry, SetDefaultTimeout,
ParseNvramVarData, ValidateVarData, GetPchStepping

### Utility (15 functions)
GetDebugInstance, AssertEfiError, GetBootMode, RegisterPeiNotifyCallback,
GetGuidHobData, SetupMrcHobs, PublishGuidHob, PublishOpaSocketMapHob,
GetPeiServicesPtr, SetStructPairs, Memset32Wrapper, NullCallback,
PeiInstallPpi, CalculateCrc16, GetFvFileInfo

