# UsbOcUpdateDxeLightningRidgeEXRP

## Function Table

| Address | Name | Description |
|---------|------|-------------|
|  | **_ModuleEntryPoint** |  |
|  | **UsbOcGetConfig** |  |
|  | **IsHobListGuid** |  |
|  | **DebugPrint** |  |
|  | **DebugAssert** |  |
|  | **ReadUnaligned64** |  |
| Static | **(Module-Level) Global Variables** |  |
| Cached | **pointer to the DebugLib protocol interface.** |  |
| Initialized | **lazily by GetDebugProtocol(). Located via gBS->LocateProtocol()** |  |
| against | **the DebugLib protocol GUID. Stored at address 0xC70.** |  |
| STATIC | **VOID  *mDebugProtocol;     // qword_C70 at 0xC70** |  |
| Cached | **pointer to the HOB list.** |  |
| Initialized | **lazily by GetHobList() by searching the system configuration** |  |
| table | **for the EFI_HOB_LIST_GUID entry. Stored at address 0xC78.** |  |
| STATIC | **VOID  *mHobList;           // qword_C78 at 0xC78** |  |
| Cached | **CMOS debug level byte (at 0xC80).** |  |
| Read | **from CMOS register 0x4B during debug output filtering.** |  |
| STATIC | **UINT8  mCmosDebugLevel;    // n3 at 0xC80** |  |
| Constant | **Data (in .data section)** |  |
| These | **are located in the .data section of the binary. They are referenced** |  |
| by | **absolute address in the compiled code and are provided here for reference.** |  |
| EFI_GUID | **mUbaProtocolGuid         @ 0xB70 = E03E0D46-5263-4845-B0A4-58D57B3177E2** |  |
| EFI_GUID | **mUsbOcConfigGuid         @ 0xB80 = 2638009E-3850-4E4B-B05D-042A32DBB9D1** |  |
| EFI_GUID | **mEfiHobListGuid          @ 0xB90 = 7739F24C-93D7-11D4-9A3A-0090273FC14D** |  |
| UBA_USBOC_PORT_MAP_ENTRY | **mUsbOcPortMap[4] @ 0xBA0** |  |
| UBA_USBOC_CONFIG_DATA | **mUsbOcConfigHdr @ 0xBE0** |  |
| Additional | **USB OC config data @ 0xBF0:** |  |
| Additional | **USB OC config data @ 0xC00:** |  |
| USB | **OC port descriptor array @ 0xC18:** |  |
| Repeated | **bytes: 07 00 02 01 (USB port descriptors)** |  |
| Local | **(Forward) Function Declarations** |  |
| Function | **Implementations** |  |
| Cache | **ImageHandle with assertion check.** |  |
| gImageHandle | **= ImageHandle;** |  |
| Cache | **SystemTable with assertion check.** |  |
| gST | **= SystemTable;** |  |
| Cache | **BootServices from SystemTable with assertion check.** |  |
| gBS | **= SystemTable->BootServices;** |  |
| Cache | **RuntimeServices from SystemTable with assertion check.** |  |
| gRT | **= SystemTable->RuntimeServices;** |  |
| Locate | **the HOB list from the system configuration table.** |  |
| This | **is required for HOB-based drivers that follow.** |  |
| GetHobList | **(ImageHandle);** |  |
| Print | **debug banner indicating this driver is executing.** |  |
| Interface | **= NULL;** |  |
| Locate | **the UBA board-type protocol.** |  |
| Status | **= gBS->LocateProtocol (** |  |
| Call | **the board-type protocol's RegisterUsbOcConfig function at offset 0x10.** |  |
| This | **registers the USB OC configuration protocol for LightningRidgeEXRP.** |  |
| return | **((UBA_BOARD_TYPE_PROTOCOL *)Interface)->RegisterUsbOcConfig (** |  |
| Return | **cached value if already resolved.** |  |
| if | **(mHobList != NULL) {** |  |
| Initialize | **HOB list pointer to NULL.** |  |
| Get | **the number of configuration table entries.** |  |
| gST | **+ 0x68 = SystemTable->NumberOfTableEntries** |  |
| TableCount | **= gST->NumberOfTableEntries;** |  |
| If | **there are entries, scan them for EFI_HOB_LIST_GUID.** |  |
| if | **(TableCount > 0) {** |  |
| Get | **pointer to the configuration table array.** |  |
| gST | **+ 0x70 = SystemTable->ConfigurationTable** |  |
| ConfigTable | **= gST->ConfigurationTable;** |  |
| Compare | **current entry's VendorGuid against EFI_HOB_LIST_GUID.** |  |
| The | **comparison splits the 16-byte GUID into two 8-byte halves:** |  |
| This | **matches the EFI_HOB_LIST_GUID: 7739F24C-93D7-11D4-9A3A-0090273FC14D** |  |
| if | **(IsHobListGuid (ImageHandle, &ConfigTable[Index].VendorGuid)) {** |  |
| Found | **the HOB list entry. Extract the VendorTable pointer.** |  |
| Each | **configuration table entry is 0x18 bytes:** |  |
| mHobList | **= ConfigTable[Index].VendorTable;** |  |
| HOB | **list GUID not found in configuration table.** |  |
| Raise | **ASSERT_EFI_ERROR with EFI_NOT_FOUND (0x800000000000000E).** |  |
| DebugPrint | **(EFI_NOT_FOUND, "\nASSERT_EFI_ERROR (Status = %r)\n");** |  |
| If | **mHobList is still NULL after the search, raise another assertion.** |  |
| if | **(mHobList == NULL) {** |  |
| Compare | **first 8 bytes of the GUID.** |  |
| These | **are at unk_B90 in the .data section (offset 0xB90).** |  |
| if | **(ReadUnaligned64 (&mUsbOcHobListFirstHalf) != ReadUnaligned64 (GuidPtr)) {** |  |
| Compare | **second 8 bytes of the GUID.** |  |
| These | **are at unk_B98 in the .data section (offset 0xB98).** |  |
| In | **the context of the SystemTable configuration table array, each entry** |  |
| is | **24 bytes: 16 for GUID + 8 for pointer.** |  |
| return | **ReadUnaligned64 (&mUsbOcHobListSecondHalf) == ReadUnaligned64 ((UINT8 *)GuidPtr + 8);** |  |
| Get | **the DebugLib protocol interface (cached).** |  |
| DebugProtocol | **= GetDebugProtocol ();** |  |
| Read | **debug level from CMOS register 0x4B.** |  |
| Access | **RTC CMOS ports 0x70/0x71:** |  |
| Port | **0x70 = CMOS index/address register** |  |
| Port | **0x71 = CMOS data register** |  |
| Step | **1: Read current CMOS index register value.** |  |
| Step | **2: Mask off bits to preserve NMI enable (bit 7 = 0x80)** |  |
| and | **set the register address to 0x4B.** |  |
| and | **al, 0xCB means:** |  |
| CmosValue | **= IoRead8 (RTC_INDEX_PORT);** |  |
| Read | **the debug level value from CMOS data port.** |  |
| DebugLevel | **= IoRead8 (RTC_DATA_PORT);** |  |
| Determine | **the debug mask based on the CMOS value.** |  |
| if | **(DebugLevel > 3) {** |  |
| For | **values > 3, check the cached CMOS debug level.** |  |
| If | **the cached level is 0, fall through to the board config check.** |  |
| DebugLevel | **= mCmosDebugLevel;** |  |
| Read | **board configuration from MMIO register 0xFDAF0490.** |  |
| This | **is a platform-specific register that indicates the board type** |  |
| or | **configuration variant.** |  |
| The | **low byte is read: bit 1 indicates some board variant** |  |
| and | **bit 0 is always set. Result = (register & 2) | 1.** |  |
| DebugLevel | **= (*(volatile UINT32 *)BOARD_CONFIG_MMIO_ADDR & 2) | 1;** |  |
| Calculate | **the debug mask from the debug level.** |  |
| level | **- 1 must be <= 0xFD (i.e., level >= 1 and level < 0xFF)** |  |
| to | **enter the mask calculation block.** |  |
| if | **((DebugLevel > 0) && ((DebugLevel - 1) <= 0xFD)) {** |  |
| Level | **1 -> mask = 0x80000004 (DEBUG_INIT | DEBUG_INFO)** |  |
| Level | **>1 -> mask = 0x80000046 (multiple debug flags)** |  |
| if | **(DebugLevel == 1) {** |  |
| Check | **if the requested ErrorLevel is enabled by the mask.** |  |
| if | **((DebugMask & ErrorLevel) != 0) {** |  |
| Call | **the DebugLib protocol's output function.** |  |
| Protocol | **interface layout:** |  |
| The | **output function takes:** |  |
| rcx | **= ErrorLevel** |  |
| rdx | **= Format string** |  |
| r8 | **= VA_LIST (variable arguments)** |  |
| ReturnValue | **= ((DEBUGLIB_PROTOCOL *)DebugProtocol)->DebugPrint (** |  |
| Call | **the DebugLib protocol's assertion handler at offset 0x08.** |  |
| Result | **= ((DEBUGLIB_PROTOCOL *)DebugProtocol)->DebugAssert (** |  |
| if | **(mDebugProtocol != NULL) {** |  |
| Allocate | **a small pool buffer (EfiBootServicesData = 31) and free it.** |  |
| This | **is a UEFI environment validation check: if the allocation succeeds** |  |
| and | **the buffer address is within a reasonable range (<= 0x10), proceed.** |  |
| On | **minimal or non-UEFI environments, the allocation may behave differently.** |  |
| The | **buffer size check suggests we are in a valid UEFI environment with** |  |
| properly | **functioning boot services.** |  |
| Locate | **the DebugLib protocol.** |  |
| the | **data at 0xB60 is NOT a standard DebugLib GUID.** |  |
| This | **may be handled differently or the GUID is encoded** |  |
| at | **a different offset.** |  |
| Encoded | **differently in this module** |  |

---
*Generated by HR650X BIOS Decompilation Project*