\r
#include "Coreboot.h"\r
\r
-/* Helpful inlines */\r
\r
-static UINT64 cb_unpack64(struct cbuint64 val)\r
+/**\r
+ Convert a packed value from cbuint64 to a UINT64 value.\r
+\r
+ @param val The pointer to packed data.\r
+\r
+ @return the UNIT64 value after convertion.\r
+\r
+**/\r
+UINT64 \r
+cb_unpack64 (\r
+ IN struct cbuint64 val\r
+ )\r
{\r
return LShiftU64 (val.hi, 32) | val.lo;\r
}\r
\r
+\r
+/**\r
+ Returns the sum of all elements in a buffer of 16-bit values. During\r
+ calculation, the carry bits are also been added.\r
+\r
+ @param Buffer The pointer to the buffer to carry out the sum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
+\r
+ @return Sum The sum of Buffer with carry bits included during additions.\r
+\r
+**/\r
UINT16\r
CbCheckSum16 (\r
IN UINT16 *Buffer,\r
return (UINT16)((~Sum) & 0xFFFF);\r
}\r
\r
+\r
+/**\r
+ Find coreboot record with given Tag from the memory Start in 4096\r
+ bytes range.\r
+\r
+ @param Start The start memory to be searched in\r
+ @param Tag The tag id to be found\r
+\r
+ @retval NULL The Tag is not found.\r
+ @retval Others The poiter to the record found.\r
+\r
+**/\r
VOID *\r
FindCbTag (\r
- IN VOID *Start,\r
+ IN VOID *Start,\r
IN UINT32 Tag\r
)\r
{\r
Header = NULL;\r
TmpPtr = (UINT8 *)Start;\r
for (Idx = 0; Idx < 4096; Idx += 16, TmpPtr += 16) {\r
- Header = (struct cb_header *)TmpPtr;\r
+ Header = (struct cb_header *)TmpPtr;\r
if (Header->signature == CB_HEADER_SIGNATURE) {\r
break;\r
}\r
}\r
\r
- if (Idx >= 4096)\r
+ if (Idx >= 4096) {\r
return NULL;\r
+ }\r
\r
- if (Header == NULL || !Header->table_bytes)\r
+ if ((Header == NULL) || (Header->table_bytes == 0)) {\r
return NULL;\r
+ }\r
\r
//\r
// Check the checksum of the coreboot table header\r
Record = (struct cb_record *)TmpPtr;\r
if (Record->tag == CB_TAG_FORWARD) {\r
TmpPtr = (VOID *)(UINTN)((struct cb_forward *)(UINTN)Record)->forward;\r
- if (Tag == CB_TAG_FORWARD)\r
+ if (Tag == CB_TAG_FORWARD) {\r
return TmpPtr;\r
- else\r
+ } else {\r
return FindCbTag (TmpPtr, Tag);\r
+ }\r
}\r
if (Record->tag == Tag) {\r
TagPtr = TmpPtr;\r
return TagPtr;\r
}\r
\r
+\r
+/**\r
+ Find the given table with TableId from the given coreboot memory Root.\r
+\r
+ @param Root The coreboot memory table to be searched in\r
+ @param TableId Table id to be found\r
+ @param pMemTable To save the base address of the memory table found\r
+ @param pMemTableSize To save the size of memory table found\r
+\r
+ @retval RETURN_SUCCESS Successfully find out the memory table.\r
+ @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
+ @retval RETURN_NOT_FOUND Failed to find the memory table.\r
+\r
+**/\r
RETURN_STATUS\r
FindCbMemTable (\r
IN struct cbmem_root *Root,\r
// Check if the entry is CBMEM or IMD\r
// and handle them separately\r
//\r
- Entries = Root->entries;\r
+ Entries = Root->entries;\r
if (Entries[0].magic == CBMEM_ENTRY_MAGIC) {\r
IsImdEntry = FALSE;\r
} else {\r
- Entries = (struct cbmem_entry *)((struct imd_root *)Root)->entries;\r
+ Entries = (struct cbmem_entry *)((struct imd_root *)Root)->entries;\r
if (Entries[0].magic == IMD_ENTRY_MAGIC) {\r
IsImdEntry = TRUE;\r
} else {\r
**/\r
RETURN_STATUS\r
CbParseMemoryInfo (\r
- IN UINT64* pLowMemorySize,\r
- IN UINT64* pHighMemorySize\r
+ OUT UINT64 *pLowMemorySize,\r
+ OUT UINT64 *pHighMemorySize\r
)\r
{\r
- struct cb_memory* rec;\r
- struct cb_memory_range* Range;\r
+ struct cb_memory *rec;\r
+ struct cb_memory_range *Range;\r
UINT64 Start;\r
UINT64 Size;\r
UINTN Index;\r
\r
- if ((!pLowMemorySize) || (!pHighMemorySize))\r
+ if ((pLowMemorySize == NULL) || (pHighMemorySize == NULL)) {\r
return RETURN_INVALID_PARAMETER;\r
+ }\r
\r
//\r
// Get the coreboot memory table\r
//\r
rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
- if (!rec)\r
+ if (rec == NULL) {\r
rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
+ }\r
\r
- if (!rec)\r
+ if (rec == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
*pLowMemorySize = 0;\r
*pHighMemorySize = 0;\r
Range = MEM_RANGE_PTR(rec, Index);\r
Start = cb_unpack64(Range->start);\r
Size = cb_unpack64(Range->size);\r
- DEBUG ((EFI_D_ERROR, "%d. %016lx - %016lx [%02x]\n",\r
+ DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",\r
Index, Start, Start + Size - 1, Range->type));\r
\r
if (Range->type != CB_MEM_RAM) {\r
}\r
}\r
\r
- DEBUG ((EFI_D_ERROR, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemorySize, *pHighMemorySize));\r
+ DEBUG ((EFI_D_INFO, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemorySize, *pHighMemorySize));\r
\r
return RETURN_SUCCESS;\r
}\r
**/\r
RETURN_STATUS\r
CbParseCbMemTable (\r
- IN UINT32 TableId,\r
- IN VOID** pMemTable,\r
- IN UINT32* pMemTableSize\r
+ IN UINT32 TableId,\r
+ OUT VOID **pMemTable,\r
+ OUT UINT32 *pMemTableSize\r
)\r
{\r
- struct cb_memory* rec;\r
- struct cb_memory_range* Range;\r
+ struct cb_memory *rec;\r
+ struct cb_memory_range *Range;\r
UINT64 Start;\r
UINT64 Size;\r
UINTN Index;\r
\r
- if (!pMemTable)\r
+ if (pMemTable == NULL) {\r
return RETURN_INVALID_PARAMETER;\r
-\r
+ }\r
*pMemTable = NULL;\r
\r
//\r
// Get the coreboot memory table\r
//\r
rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
- if (!rec)\r
+ if (rec == NULL) {\r
rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
+ }\r
\r
- if (!rec)\r
+ if (rec == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
Range = MEM_RANGE_PTR(rec, Index);\r
**/\r
RETURN_STATUS\r
CbParseAcpiTable (\r
- IN VOID **pMemTable,\r
- IN UINT32 *pMemTableSize\r
+ OUT VOID **pMemTable,\r
+ OUT UINT32 *pMemTableSize\r
)\r
{\r
return CbParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), pMemTable, pMemTableSize);\r
**/\r
RETURN_STATUS\r
CbParseSmbiosTable (\r
- IN VOID** pMemTable,\r
- IN UINT32* pMemTableSize\r
+ OUT VOID **pMemTable,\r
+ OUT UINT32 *pMemTableSize\r
)\r
{\r
return CbParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), pMemTable, pMemTableSize);\r
**/\r
RETURN_STATUS\r
CbParseFadtInfo (\r
- IN UINTN* pPmCtrlReg,\r
- IN UINTN* pPmTimerReg,\r
- IN UINTN* pResetReg,\r
- IN UINTN* pResetValue\r
+ OUT UINTN *pPmCtrlReg,\r
+ OUT UINTN *pPmTimerReg,\r
+ OUT UINTN *pResetReg,\r
+ OUT UINTN *pResetValue\r
)\r
{\r
- EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER* Rsdp;\r
- EFI_ACPI_DESCRIPTION_HEADER* Rsdt;\r
- UINT32* Entry32;\r
+ EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;\r
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt;\r
+ UINT32 *Entry32;\r
UINTN Entry32Num;\r
- EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE* Fadt;\r
- EFI_ACPI_DESCRIPTION_HEADER* Xsdt;\r
- UINT64* Entry64;\r
+ EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;\r
+ EFI_ACPI_DESCRIPTION_HEADER *Xsdt;\r
+ UINT64 *Entry64;\r
UINTN Entry64Num;\r
UINTN Idx;\r
RETURN_STATUS Status;\r
Status = RETURN_SUCCESS;\r
\r
Status = CbParseAcpiTable (&Rsdp, NULL);\r
- if (RETURN_ERROR(Status))\r
+ if (RETURN_ERROR(Status)) {\r
return Status;\r
+ }\r
\r
- if (!Rsdp)\r
+ if (Rsdp == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
- DEBUG ((EFI_D_ERROR, "Find Rsdp at %p\n", Rsdp));\r
- DEBUG ((EFI_D_ERROR, "Find Rsdt 0x%x, Xsdt 0x%lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress));\r
+ DEBUG ((EFI_D_INFO, "Find Rsdp at %p\n", Rsdp));\r
+ DEBUG ((EFI_D_INFO, "Find Rsdt 0x%x, Xsdt 0x%lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress));\r
\r
//\r
// Search Rsdt First\r
for (Idx = 0; Idx < Entry32Num; Idx++) {\r
if (*(UINT32 *)(UINTN)(Entry32[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry32[Idx]);\r
- if (pPmCtrlReg)\r
+ if (pPmCtrlReg != NULL) {\r
*pPmCtrlReg = Fadt->Pm1aCntBlk;\r
- DEBUG ((EFI_D_ERROR, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
+ }\r
+ DEBUG ((EFI_D_INFO, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
\r
- if (pPmTimerReg)\r
+ if (pPmTimerReg != NULL) {\r
*pPmTimerReg = Fadt->PmTmrBlk;\r
- DEBUG ((EFI_D_ERROR, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
+ }\r
+ DEBUG ((EFI_D_INFO, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
\r
- if (pResetReg)\r
+ if (pResetReg != NULL) {\r
*pResetReg = (UINTN)Fadt->ResetReg.Address;\r
- DEBUG ((EFI_D_ERROR, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
+ }\r
+ DEBUG ((EFI_D_INFO, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
\r
- if (pResetValue)\r
+ if (pResetValue != NULL) {\r
*pResetValue = Fadt->ResetValue;\r
- DEBUG ((EFI_D_ERROR, "Reset Value 0x%x\n", Fadt->ResetValue));\r
+ }\r
+ DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r
\r
return RETURN_SUCCESS;\r
}\r
**/\r
RETURN_STATUS\r
CbParseSerialInfo (\r
- IN UINT32* pRegBase,\r
- IN UINT32* pRegAccessType,\r
- IN UINT32* pBaudrate\r
+ OUT UINT32 *pRegBase,\r
+ OUT UINT32 *pRegAccessType,\r
+ OUT UINT32 *pBaudrate\r
)\r
{\r
- struct cb_serial* CbSerial;\r
+ struct cb_serial *CbSerial;\r
\r
CbSerial = FindCbTag (0, CB_TAG_SERIAL);\r
- if (!CbSerial)\r
+ if (CbSerial == NULL) {\r
CbSerial = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_SERIAL);\r
+ }\r
\r
- if (!CbSerial)\r
+ if (CbSerial == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
- if (pRegBase)\r
+ if (pRegBase != NULL) {\r
*pRegBase = CbSerial->baseaddr;\r
+ }\r
\r
- if (pRegAccessType)\r
+ if (pRegAccessType != NULL) {\r
*pRegAccessType = CbSerial->type;\r
+ }\r
\r
- if (pBaudrate)\r
+ if (pBaudrate != NULL) {\r
*pBaudrate = CbSerial->baud;\r
+ }\r
\r
return RETURN_SUCCESS;\r
}\r
**/\r
RETURN_STATUS\r
CbParseGetCbHeader (\r
- IN UINTN Level,\r
- IN VOID** HeaderPtr\r
+ IN UINTN Level,\r
+ OUT VOID **HeaderPtr\r
)\r
{\r
UINTN Index;\r
- VOID* TempPtr;\r
+ VOID *TempPtr;\r
\r
- if (!HeaderPtr)\r
+ if (HeaderPtr == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
TempPtr = NULL;\r
for (Index = 0; Index < Level; Index++) {\r
TempPtr = FindCbTag (TempPtr, CB_TAG_FORWARD);\r
- if (!TempPtr)\r
+ if (TempPtr == NULL) {\r
break;\r
+ }\r
}\r
\r
if ((Index >= Level) && (TempPtr != NULL)) {\r
**/\r
RETURN_STATUS\r
CbParseFbInfo (\r
- IN FRAME_BUFFER_INFO* pFbInfo\r
+ OUT FRAME_BUFFER_INFO *pFbInfo\r
)\r
{\r
- struct cb_framebuffer* CbFbRec;\r
+ struct cb_framebuffer *CbFbRec;\r
\r
- if (!pFbInfo)\r
+ if (pFbInfo == NULL) {\r
return RETURN_INVALID_PARAMETER;\r
+ }\r
\r
CbFbRec = FindCbTag (0, CB_TAG_FRAMEBUFFER);\r
- if (!CbFbRec)\r
+ if (CbFbRec == NULL) {\r
CbFbRec = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_FRAMEBUFFER);\r
+ }\r
\r
- if (!CbFbRec)\r
+ if (CbFbRec == NULL) {\r
return RETURN_NOT_FOUND;\r
+ }\r
\r
- DEBUG ((EFI_D_ERROR, "Found coreboot video frame buffer information\n"));\r
- DEBUG ((EFI_D_ERROR, "physical_address: 0x%lx\n", CbFbRec->physical_address));\r
- DEBUG ((EFI_D_ERROR, "x_resolution: 0x%x\n", CbFbRec->x_resolution));\r
- DEBUG ((EFI_D_ERROR, "y_resolution: 0x%x\n", CbFbRec->y_resolution));\r
- DEBUG ((EFI_D_ERROR, "bits_per_pixel: 0x%x\n", CbFbRec->bits_per_pixel));\r
- DEBUG ((EFI_D_ERROR, "bytes_per_line: 0x%x\n", CbFbRec->bytes_per_line));\r
-\r
- DEBUG ((EFI_D_ERROR, "red_mask_size: 0x%x\n", CbFbRec->red_mask_size));\r
- DEBUG ((EFI_D_ERROR, "red_mask_pos: 0x%x\n", CbFbRec->red_mask_pos));\r
- DEBUG ((EFI_D_ERROR, "green_mask_size: 0x%x\n", CbFbRec->green_mask_size));\r
- DEBUG ((EFI_D_ERROR, "green_mask_pos: 0x%x\n", CbFbRec->green_mask_pos));\r
- DEBUG ((EFI_D_ERROR, "blue_mask_size: 0x%x\n", CbFbRec->blue_mask_size));\r
- DEBUG ((EFI_D_ERROR, "blue_mask_pos: 0x%x\n", CbFbRec->blue_mask_pos));\r
- DEBUG ((EFI_D_ERROR, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));\r
- DEBUG ((EFI_D_ERROR, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));\r
+ DEBUG ((EFI_D_INFO, "Found coreboot video frame buffer information\n"));\r
+ DEBUG ((EFI_D_INFO, "physical_address: 0x%lx\n", CbFbRec->physical_address));\r
+ DEBUG ((EFI_D_INFO, "x_resolution: 0x%x\n", CbFbRec->x_resolution));\r
+ DEBUG ((EFI_D_INFO, "y_resolution: 0x%x\n", CbFbRec->y_resolution));\r
+ DEBUG ((EFI_D_INFO, "bits_per_pixel: 0x%x\n", CbFbRec->bits_per_pixel));\r
+ DEBUG ((EFI_D_INFO, "bytes_per_line: 0x%x\n", CbFbRec->bytes_per_line));\r
+\r
+ DEBUG ((EFI_D_INFO, "red_mask_size: 0x%x\n", CbFbRec->red_mask_size));\r
+ DEBUG ((EFI_D_INFO, "red_mask_pos: 0x%x\n", CbFbRec->red_mask_pos));\r
+ DEBUG ((EFI_D_INFO, "green_mask_size: 0x%x\n", CbFbRec->green_mask_size));\r
+ DEBUG ((EFI_D_INFO, "green_mask_pos: 0x%x\n", CbFbRec->green_mask_pos));\r
+ DEBUG ((EFI_D_INFO, "blue_mask_size: 0x%x\n", CbFbRec->blue_mask_size));\r
+ DEBUG ((EFI_D_INFO, "blue_mask_pos: 0x%x\n", CbFbRec->blue_mask_pos));\r
+ DEBUG ((EFI_D_INFO, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));\r
+ DEBUG ((EFI_D_INFO, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));\r
\r
pFbInfo->LinearFrameBuffer = CbFbRec->physical_address;\r
pFbInfo->HorizontalResolution = CbFbRec->x_resolution;\r