summaryrefslogtreecommitdiffstats
path: root/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'UefiPayloadPkg/Library/CbParseLib/CbParseLib.c')
-rw-r--r--UefiPayloadPkg/Library/CbParseLib/CbParseLib.c177
1 files changed, 92 insertions, 85 deletions
diff --git a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
index f73fcd8823..8a353f77f6 100644
--- a/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
+++ b/UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
@@ -17,7 +17,6 @@
#include <IndustryStandard/Acpi.h>
#include <Coreboot.h>
-
/**
Convert a packed value from cbuint64 to a UINT64 value.
@@ -28,13 +27,12 @@
**/
UINT64
cb_unpack64 (
- IN struct cbuint64 val
+ IN struct cbuint64 val
)
{
return LShiftU64 (val.hi, 32) | val.lo;
}
-
/**
Returns the sum of all elements in a buffer of 16-bit values. During
calculation, the carry bits are also been added.
@@ -47,19 +45,19 @@ cb_unpack64 (
**/
UINT16
CbCheckSum16 (
- IN UINT16 *Buffer,
- IN UINTN Length
+ IN UINT16 *Buffer,
+ IN UINTN Length
)
{
- UINT32 Sum;
- UINT32 TmpValue;
- UINTN Idx;
- UINT8 *TmpPtr;
+ UINT32 Sum;
+ UINT32 TmpValue;
+ UINTN Idx;
+ UINT8 *TmpPtr;
- Sum = 0;
+ Sum = 0;
TmpPtr = (UINT8 *)Buffer;
- for(Idx = 0; Idx < Length; Idx++) {
- TmpValue = TmpPtr[Idx];
+ for (Idx = 0; Idx < Length; Idx++) {
+ TmpValue = TmpPtr[Idx];
if (Idx % 2 == 1) {
TmpValue <<= 8;
}
@@ -75,7 +73,6 @@ CbCheckSum16 (
return (UINT16)((~Sum) & 0xFFFF);
}
-
/**
Check the coreboot table if it is valid.
@@ -87,10 +84,10 @@ CbCheckSum16 (
**/
BOOLEAN
IsValidCbTable (
- IN struct cb_header *Header
+ IN struct cb_header *Header
)
{
- UINT16 CheckSum;
+ UINT16 CheckSum;
if ((Header == NULL) || (Header->table_bytes == 0)) {
return FALSE;
@@ -118,7 +115,6 @@ IsValidCbTable (
return TRUE;
}
-
/**
This function retrieves the parameter base address from boot loader.
@@ -135,12 +131,12 @@ GetParameterBase (
VOID
)
{
- struct cb_header *Header;
- struct cb_record *Record;
- UINT8 *TmpPtr;
- UINT8 *CbTablePtr;
- UINTN Idx;
- EFI_STATUS Status;
+ struct cb_header *Header;
+ struct cb_record *Record;
+ UINT8 *TmpPtr;
+ UINT8 *CbTablePtr;
+ UINTN Idx;
+ EFI_STATUS Status;
//
// coreboot could pass coreboot table to UEFI payload
@@ -177,13 +173,14 @@ GetParameterBase (
// Find full coreboot table in high memory
//
CbTablePtr = NULL;
- TmpPtr = (UINT8 *)Header + Header->header_bytes;
+ TmpPtr = (UINT8 *)Header + Header->header_bytes;
for (Idx = 0; Idx < Header->table_entries; Idx++) {
Record = (struct cb_record *)TmpPtr;
if (Record->tag == CB_TAG_FORWARD) {
CbTablePtr = (VOID *)(UINTN)((struct cb_forward *)(UINTN)Record)->forward;
break;
}
+
TmpPtr += Record->size;
}
@@ -200,7 +197,6 @@ GetParameterBase (
return CbTablePtr;
}
-
/**
Find coreboot record with given Tag.
@@ -212,16 +208,16 @@ GetParameterBase (
**/
VOID *
FindCbTag (
- IN UINT32 Tag
+ IN UINT32 Tag
)
{
- struct cb_header *Header;
- struct cb_record *Record;
- UINT8 *TmpPtr;
- UINT8 *TagPtr;
- UINTN Idx;
+ struct cb_header *Header;
+ struct cb_record *Record;
+ UINT8 *TmpPtr;
+ UINT8 *TagPtr;
+ UINTN Idx;
- Header = (struct cb_header *) GetParameterBase ();
+ Header = (struct cb_header *)GetParameterBase ();
TagPtr = NULL;
TmpPtr = (UINT8 *)Header + Header->header_bytes;
@@ -231,13 +227,13 @@ FindCbTag (
TagPtr = TmpPtr;
break;
}
+
TmpPtr += Record->size;
}
return TagPtr;
}
-
/**
Find the given table with TableId from the given coreboot memory Root.
@@ -259,13 +255,14 @@ FindCbMemTable (
OUT UINT32 *MemTableSize
)
{
- UINTN Idx;
- BOOLEAN IsImdEntry;
- struct cbmem_entry *Entries;
+ UINTN Idx;
+ BOOLEAN IsImdEntry;
+ struct cbmem_entry *Entries;
if ((Root == NULL) || (MemTable == NULL)) {
return RETURN_INVALID_PARAMETER;
}
+
//
// Check if the entry is CBMEM or IMD
// and handle them separately
@@ -285,16 +282,22 @@ FindCbMemTable (
for (Idx = 0; Idx < Root->num_entries; Idx++) {
if (Entries[Idx].id == TableId) {
if (IsImdEntry) {
- *MemTable = (VOID *) ((UINTN)Entries[Idx].start + (UINTN)Root);
+ *MemTable = (VOID *)((UINTN)Entries[Idx].start + (UINTN)Root);
} else {
- *MemTable = (VOID *) (UINTN)Entries[Idx].start;
+ *MemTable = (VOID *)(UINTN)Entries[Idx].start;
}
+
if (MemTableSize != NULL) {
*MemTableSize = Entries[Idx].size;
}
- DEBUG ((DEBUG_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",
- TableId, *MemTable, Entries[Idx].size));
+ DEBUG ((
+ DEBUG_INFO,
+ "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",
+ TableId,
+ *MemTable,
+ Entries[Idx].size
+ ));
return RETURN_SUCCESS;
}
}
@@ -316,18 +319,18 @@ FindCbMemTable (
**/
RETURN_STATUS
ParseCbMemTable (
- IN UINT32 TableId,
- OUT VOID **MemTable,
- OUT UINT32 *MemTableSize
+ IN UINT32 TableId,
+ OUT VOID **MemTable,
+ OUT UINT32 *MemTableSize
)
{
- EFI_STATUS Status;
- CB_MEMORY *Rec;
- struct cb_memory_range *Range;
- UINT64 Start;
- UINT64 Size;
- UINTN Index;
- struct cbmem_root *CbMemRoot;
+ EFI_STATUS Status;
+ CB_MEMORY *Rec;
+ struct cb_memory_range *Range;
+ UINT64 Start;
+ UINT64 Size;
+ UINTN Index;
+ struct cbmem_root *CbMemRoot;
if (MemTable == NULL) {
return RETURN_INVALID_PARAMETER;
@@ -344,14 +347,14 @@ ParseCbMemTable (
return Status;
}
- for (Index = 0; Index < MEM_RANGE_COUNT(Rec); Index++) {
- Range = MEM_RANGE_PTR(Rec, Index);
- Start = cb_unpack64(Range->start);
- Size = cb_unpack64(Range->size);
+ for (Index = 0; Index < MEM_RANGE_COUNT (Rec); Index++) {
+ Range = MEM_RANGE_PTR (Rec, Index);
+ Start = cb_unpack64 (Range->start);
+ Size = cb_unpack64 (Range->size);
if ((Range->type == CB_MEM_TABLE) && (Start > 0x1000)) {
CbMemRoot = (struct cbmem_root *)(UINTN)(Start + Size - DYN_CBMEM_ALIGN_SIZE);
- Status = FindCbMemTable (CbMemRoot, TableId, MemTable, MemTableSize);
+ Status = FindCbMemTable (CbMemRoot, TableId, MemTable, MemTableSize);
if (!EFI_ERROR (Status)) {
break;
}
@@ -361,8 +364,6 @@ ParseCbMemTable (
return Status;
}
-
-
/**
Acquire the memory information from the coreboot table in memory.
@@ -380,10 +381,10 @@ ParseMemoryInfo (
IN VOID *Params
)
{
- CB_MEMORY *Rec;
- struct cb_memory_range *Range;
- UINTN Index;
- MEMORY_MAP_ENTRY MemoryMap;
+ CB_MEMORY *Rec;
+ struct cb_memory_range *Range;
+ UINTN Index;
+ MEMORY_MAP_ENTRY MemoryMap;
//
// Get the coreboot memory table
@@ -393,14 +394,20 @@ ParseMemoryInfo (
return RETURN_NOT_FOUND;
}
- for (Index = 0; Index < MEM_RANGE_COUNT(Rec); Index++) {
- Range = MEM_RANGE_PTR(Rec, Index);
- MemoryMap.Base = cb_unpack64(Range->start);
- MemoryMap.Size = cb_unpack64(Range->size);
+ for (Index = 0; Index < MEM_RANGE_COUNT (Rec); Index++) {
+ Range = MEM_RANGE_PTR (Rec, Index);
+ MemoryMap.Base = cb_unpack64 (Range->start);
+ MemoryMap.Size = cb_unpack64 (Range->size);
MemoryMap.Type = (UINT8)Range->type;
MemoryMap.Flag = 0;
- DEBUG ((DEBUG_INFO, "%d. %016lx - %016lx [%02x]\n",
- Index, MemoryMap.Base, MemoryMap.Base + MemoryMap.Size - 1, MemoryMap.Type));
+ DEBUG ((
+ DEBUG_INFO,
+ "%d. %016lx - %016lx [%02x]\n",
+ Index,
+ MemoryMap.Base,
+ MemoryMap.Base + MemoryMap.Size - 1,
+ MemoryMap.Type
+ ));
MemInfoCallback (&MemoryMap, Params);
}
@@ -408,7 +415,6 @@ ParseMemoryInfo (
return RETURN_SUCCESS;
}
-
/**
Acquire SMBIOS table from coreboot.
@@ -421,23 +427,23 @@ ParseMemoryInfo (
RETURN_STATUS
EFIAPI
ParseSmbiosTable (
- OUT UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmbiosTable
+ OUT UNIVERSAL_PAYLOAD_SMBIOS_TABLE *SmbiosTable
)
{
- EFI_STATUS Status;
- VOID *MemTable;
- UINT32 MemTableSize;
+ EFI_STATUS Status;
+ VOID *MemTable;
+ UINT32 MemTableSize;
Status = ParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), &MemTable, &MemTableSize);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
- SmbiosTable->SmBiosEntryPoint = (UINT64) (UINTN)MemTable;
+
+ SmbiosTable->SmBiosEntryPoint = (UINT64)(UINTN)MemTable;
return RETURN_SUCCESS;
}
-
/**
Acquire ACPI table from coreboot.
@@ -450,23 +456,23 @@ ParseSmbiosTable (
RETURN_STATUS
EFIAPI
ParseAcpiTableInfo (
- OUT UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableHob
+ OUT UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableHob
)
{
- EFI_STATUS Status;
- VOID *MemTable;
- UINT32 MemTableSize;
+ EFI_STATUS Status;
+ VOID *MemTable;
+ UINT32 MemTableSize;
Status = ParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), &MemTable, &MemTableSize);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
- AcpiTableHob->Rsdp = (UINT64) (UINTN)MemTable;
+
+ AcpiTableHob->Rsdp = (UINT64)(UINTN)MemTable;
return RETURN_SUCCESS;
}
-
/**
Find the serial port information
@@ -479,10 +485,10 @@ ParseAcpiTableInfo (
RETURN_STATUS
EFIAPI
ParseSerialInfo (
- OUT SERIAL_PORT_INFO *SerialPortInfo
+ OUT SERIAL_PORT_INFO *SerialPortInfo
)
{
- struct cb_serial *CbSerial;
+ struct cb_serial *CbSerial;
CbSerial = FindCbTag (CB_TAG_SERIAL);
if (CbSerial == NULL) {
@@ -511,7 +517,7 @@ ParseSerialInfo (
RETURN_STATUS
EFIAPI
ParseGfxInfo (
- OUT EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo
+ OUT EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo
)
{
struct cb_framebuffer *CbFbRec;
@@ -542,7 +548,7 @@ ParseGfxInfo (
DEBUG ((DEBUG_INFO, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));
DEBUG ((DEBUG_INFO, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));
- GfxMode = &GfxInfo->GraphicsMode;
+ GfxMode = &GfxInfo->GraphicsMode;
GfxMode->Version = 0;
GfxMode->HorizontalResolution = CbFbRec->x_resolution;
GfxMode->VerticalResolution = CbFbRec->y_resolution;
@@ -550,8 +556,9 @@ ParseGfxInfo (
if ((CbFbRec->red_mask_pos == 0) && (CbFbRec->green_mask_pos == 8) && (CbFbRec->blue_mask_pos == 16)) {
GfxMode->PixelFormat = PixelRedGreenBlueReserved8BitPerColor;
} else if ((CbFbRec->blue_mask_pos == 0) && (CbFbRec->green_mask_pos == 8) && (CbFbRec->red_mask_pos == 16)) {
- GfxMode->PixelFormat = PixelBlueGreenRedReserved8BitPerColor;
+ GfxMode->PixelFormat = PixelBlueGreenRedReserved8BitPerColor;
}
+
GfxMode->PixelInformation.RedMask = ((1 << CbFbRec->red_mask_size) - 1) << CbFbRec->red_mask_pos;
GfxMode->PixelInformation.GreenMask = ((1 << CbFbRec->green_mask_size) - 1) << CbFbRec->green_mask_pos;
GfxMode->PixelInformation.BlueMask = ((1 << CbFbRec->blue_mask_size) - 1) << CbFbRec->blue_mask_pos;
@@ -575,7 +582,7 @@ ParseGfxInfo (
RETURN_STATUS
EFIAPI
ParseGfxDeviceInfo (
- OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *GfxDeviceInfo
+ OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *GfxDeviceInfo
)
{
return RETURN_NOT_FOUND;