2 This library will parse the coreboot table in memory and extract those required
5 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Uefi/UefiBaseType.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/CbParseLib.h>
23 #include <IndustryStandard/Acpi.h>
29 static UINT64
cb_unpack64(struct cbuint64 val
)
31 return (((UINT64
) val
.hi
) << 32) | val
.lo
;
34 static const char *cb_mb_vendor_string(const struct cb_mainboard
*cbm
)
36 return (char *)(cbm
->strings
+ cbm
->vendor_idx
);
39 static const char *cb_mb_part_string(const struct cb_mainboard
*cbm
)
41 return (char *)(cbm
->strings
+ cbm
->part_number_idx
);
55 TmpPtr
= (UINT8
*)Buffer
;
56 for(Idx
= 0; Idx
< Length
; Idx
++) {
57 TmpValue
= TmpPtr
[Idx
];
66 Sum
= (Sum
+ (Sum
>> 16)) & 0xFFFF;
70 return (UINT16
)((~Sum
) & 0xFFFF);
79 struct cb_header
*Header
;
80 struct cb_record
*Record
;
87 TmpPtr
= (UINT8
*)Start
;
88 for (Idx
= 0; Idx
< 4096; Idx
+= 16, TmpPtr
+= 16) {
89 Header
= (struct cb_header
*)TmpPtr
;
90 if (Header
->signature
== CB_HEADER_SIGNATURE
) {
98 if (Header
== NULL
|| !Header
->table_bytes
)
102 // Check the checksum of the coreboot table header
104 CheckSum
= CbCheckSum16 ((UINT16
*)Header
, sizeof (*Header
));
106 DEBUG ((EFI_D_ERROR
, "Invalid coreboot table header checksum\n"));
110 CheckSum
= CbCheckSum16 ((UINT16
*)(TmpPtr
+ sizeof (*Header
)), Header
->table_bytes
);
111 if (CheckSum
!= Header
->table_checksum
) {
112 DEBUG ((EFI_D_ERROR
, "Incorrect checksum of all the coreboot table entries\n"));
117 TmpPtr
+= Header
->header_bytes
;
118 for (Idx
= 0; Idx
< Header
->table_entries
; Idx
++) {
119 Record
= (struct cb_record
*)TmpPtr
;
120 if (Record
->tag
== CB_TAG_FORWARD
) {
121 TmpPtr
= (VOID
*)(UINTN
)((struct cb_forward
*)(UINTN
)Record
)->forward
;
122 if (Tag
== CB_TAG_FORWARD
)
125 return FindCbTag (TmpPtr
, Tag
);
127 if (Record
->tag
== Tag
) {
131 TmpPtr
+= Record
->size
;
139 struct cbmem_root
*root
,
142 IN UINT32
* pMemTableSize
147 if ((!root
) || (!pMemTable
))
148 return RETURN_INVALID_PARAMETER
;
150 for (Idx
= 0; Idx
< root
->num_entries
; Idx
++) {
151 if (root
->entries
[Idx
].id
== TableId
) {
152 *pMemTable
= (VOID
*) (UINTN
)root
->entries
[Idx
].start
;
154 *pMemTableSize
= root
->entries
[Idx
].size
;
156 DEBUG ((EFI_D_ERROR
, "Find CbMemTable Id 0x%x, base 0x%x, size 0x%x\n", TableId
, *pMemTable
, *pMemTableSize
));
157 return RETURN_SUCCESS
;
161 return RETURN_NOT_FOUND
;
166 Acquire the memory information from the coreboot table in memory.
168 @param pLowMemorySize Pointer to the variable of low memory size
169 @param pHighMemorySize Pointer to the variable of high memory size
171 @retval RETURN_SUCCESS Successfully find out the memory information.
172 @retval RETURN_INVALID_PARAMETER Invalid input parameters.
173 @retval RETURN_NOT_FOUND Failed to find the memory information.
178 IN UINT64
* pLowMemorySize
,
179 IN UINT64
* pHighMemorySize
182 struct cb_memory
* rec
;
183 struct cb_memory_range
* Range
;
188 if ((!pLowMemorySize
) || (!pHighMemorySize
))
189 return RETURN_INVALID_PARAMETER
;
192 // Get the coreboot memory table
194 rec
= (struct cb_memory
*)FindCbTag (0, CB_TAG_MEMORY
);
196 rec
= (struct cb_memory
*)FindCbTag ((VOID
*)(UINTN
)PcdGet32 (PcdCbHeaderPointer
), CB_TAG_MEMORY
);
199 return RETURN_NOT_FOUND
;
202 *pHighMemorySize
= 0;
204 for (Index
= 0; Index
< MEM_RANGE_COUNT(rec
); Index
++) {
205 Range
= MEM_RANGE_PTR(rec
, Index
);
206 Start
= cb_unpack64(Range
->start
);
207 Size
= cb_unpack64(Range
->size
);
208 DEBUG ((EFI_D_ERROR
, "%d. %016lx - %016lx [%02x]\n",
209 Index
, Start
, Start
+ Size
- 1, Range
->type
));
211 if (Range
->type
!= CB_MEM_RAM
) {
215 if (Start
+ Size
< 0x100000000ULL
) {
216 *pLowMemorySize
= Start
+ Size
;
218 *pHighMemorySize
= Start
+ Size
- 0x100000000ULL
;
222 DEBUG ((EFI_D_ERROR
, "Low memory 0x%x, High Memory 0x%x\n", *pLowMemorySize
, *pHighMemorySize
));
224 return RETURN_SUCCESS
;
229 Acquire the coreboot memory table with the given table id
231 @param TableId Table id to be searched
232 @param pMemTable Pointer to the base address of the memory table
233 @param pMemTableSize Pointer to the size of the memory table
235 @retval RETURN_SUCCESS Successfully find out the memory table.
236 @retval RETURN_INVALID_PARAMETER Invalid input parameters.
237 @retval RETURN_NOT_FOUND Failed to find the memory table.
244 IN UINT32
* pMemTableSize
247 struct cb_memory
* rec
;
248 struct cb_memory_range
* Range
;
254 return RETURN_INVALID_PARAMETER
;
259 // Get the coreboot memory table
261 rec
= (struct cb_memory
*)FindCbTag (0, CB_TAG_MEMORY
);
263 rec
= (struct cb_memory
*)FindCbTag ((VOID
*)(UINTN
)PcdGet32 (PcdCbHeaderPointer
), CB_TAG_MEMORY
);
266 return RETURN_NOT_FOUND
;
268 for (Index
= 0; Index
< MEM_RANGE_COUNT(rec
); Index
++) {
269 Range
= MEM_RANGE_PTR(rec
, Index
);
270 Start
= cb_unpack64(Range
->start
);
271 Size
= cb_unpack64(Range
->size
);
273 if ((Range
->type
== CB_MEM_TABLE
) && (Start
> 0x1000)) {
274 if (FindCbMemTable ((struct cbmem_root
*)(UINTN
)(Start
+ Size
- DYN_CBMEM_ALIGN_SIZE
), TableId
, pMemTable
, pMemTableSize
) == RETURN_SUCCESS
)
275 return RETURN_SUCCESS
;
279 return RETURN_NOT_FOUND
;
284 Acquire the acpi table from coreboot
286 @param pMemTable Pointer to the base address of the memory table
287 @param pMemTableSize Pointer to the size of the memory table
289 @retval RETURN_SUCCESS Successfully find out the memory table.
290 @retval RETURN_INVALID_PARAMETER Invalid input parameters.
291 @retval RETURN_NOT_FOUND Failed to find the memory table.
297 IN UINT32
* pMemTableSize
300 return CbParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), pMemTable
, pMemTableSize
);
304 Acquire the smbios table from coreboot
306 @param pMemTable Pointer to the base address of the memory table
307 @param pMemTableSize Pointer to the size of the memory table
309 @retval RETURN_SUCCESS Successfully find out the memory table.
310 @retval RETURN_INVALID_PARAMETER Invalid input parameters.
311 @retval RETURN_NOT_FOUND Failed to find the memory table.
317 IN UINT32
* pMemTableSize
320 return CbParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), pMemTable
, pMemTableSize
);
324 Find the required fadt information
326 @param pPmCtrlReg Pointer to the address of power management control register
327 @param pPmTimerReg Pointer to the address of power management timer register
328 @param pResetReg Pointer to the address of system reset register
329 @param pResetValue Pointer to the value to be writen to the system reset register
331 @retval RETURN_SUCCESS Successfully find out all the required fadt information.
332 @retval RETURN_NOT_FOUND Failed to find the fadt table.
337 IN UINTN
* pPmCtrlReg
,
338 IN UINTN
* pPmTimerReg
,
340 IN UINTN
* pResetValue
343 EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
* Rsdp
;
344 EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
;
347 EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
* Fadt
;
348 EFI_ACPI_DESCRIPTION_HEADER
* Xsdt
;
352 RETURN_STATUS Status
;
355 Status
= RETURN_SUCCESS
;
357 Status
= CbParseAcpiTable (&Rsdp
, NULL
);
358 if (RETURN_ERROR(Status
))
362 return RETURN_NOT_FOUND
;
364 DEBUG ((EFI_D_ERROR
, "Find Rsdp at 0x%x\n", Rsdp
));
365 DEBUG ((EFI_D_ERROR
, "Find Rsdt 0x%x, Xsdt 0x%x\n", Rsdp
->RsdtAddress
, Rsdp
->XsdtAddress
));
370 Rsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*)(UINTN
)(Rsdp
->RsdtAddress
);
372 Entry32
= (UINT32
*)(Rsdt
+ 1);
373 Entry32Num
= (Rsdt
->Length
- sizeof(EFI_ACPI_DESCRIPTION_HEADER
)) >> 2;
374 for (Idx
= 0; Idx
< Entry32Num
; Idx
++) {
375 if (*(UINT32
*)(UINTN
)(Entry32
[Idx
]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
376 Fadt
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*)(UINTN
)(Entry32
[Idx
]);
378 *pPmCtrlReg
= Fadt
->Pm1aCntBlk
;
379 DEBUG ((EFI_D_ERROR
, "PmCtrl Reg 0x%x\n", Fadt
->Pm1aCntBlk
));
382 *pPmTimerReg
= Fadt
->PmTmrBlk
;
383 DEBUG ((EFI_D_ERROR
, "PmTimer Reg 0x%x\n", Fadt
->PmTmrBlk
));
386 *pResetReg
= (UINTN
)Fadt
->ResetReg
.Address
;
387 DEBUG ((EFI_D_ERROR
, "Reset Reg 0x%x\n", Fadt
->ResetReg
.Address
));
390 *pResetValue
= Fadt
->ResetValue
;
391 DEBUG ((EFI_D_ERROR
, "Reset Value 0x%x\n", Fadt
->ResetValue
));
393 return RETURN_SUCCESS
;
399 // Search Xsdt Second
401 Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*)(UINTN
)(Rsdp
->XsdtAddress
);
403 Entry64
= (UINT64
*)(Xsdt
+ 1);
404 Entry64Num
= (Xsdt
->Length
- sizeof(EFI_ACPI_DESCRIPTION_HEADER
)) >> 3;
405 for (Idx
= 0; Idx
< Entry64Num
; Idx
++) {
406 if (*(UINT32
*)(UINTN
)(Entry64
[Idx
]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
407 Fadt
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*)(UINTN
)(Entry64
[Idx
]);
409 *pPmCtrlReg
= Fadt
->Pm1aCntBlk
;
410 DEBUG ((EFI_D_ERROR
, "PmCtrl Reg 0x%x\n", Fadt
->Pm1aCntBlk
));
413 *pPmTimerReg
= Fadt
->PmTmrBlk
;
414 DEBUG ((EFI_D_ERROR
, "PmTimer Reg 0x%x\n", Fadt
->PmTmrBlk
));
417 *pResetReg
= (UINTN
)Fadt
->ResetReg
.Address
;
418 DEBUG ((EFI_D_ERROR
, "Reset Reg 0x%x\n", Fadt
->ResetReg
.Address
));
421 *pResetValue
= Fadt
->ResetValue
;
422 DEBUG ((EFI_D_ERROR
, "Reset Value 0x%x\n", Fadt
->ResetValue
));
424 return RETURN_SUCCESS
;
429 return RETURN_NOT_FOUND
;
433 Find the serial port information
435 @param pRegBase Pointer to the base address of serial port registers
436 @param pRegAccessType Pointer to the access type of serial port registers
437 @param pBaudrate Pointer to the serial port baudrate
439 @retval RETURN_SUCCESS Successfully find the serial port information.
440 @retval RETURN_NOT_FOUND Failed to find the serial port information .
446 IN UINT32
* pRegAccessType
,
450 struct cb_serial
* CbSerial
;
452 CbSerial
= FindCbTag (0, CB_TAG_SERIAL
);
454 CbSerial
= FindCbTag ((VOID
*)(UINTN
)PcdGet32 (PcdCbHeaderPointer
), CB_TAG_SERIAL
);
457 return RETURN_NOT_FOUND
;
460 *pRegBase
= CbSerial
->baseaddr
;
463 *pRegAccessType
= CbSerial
->type
;
466 *pBaudrate
= CbSerial
->baud
;
468 return RETURN_SUCCESS
;
472 Search for the coreboot table header
474 @param Level Level of the search depth
475 @param HeaderPtr Pointer to the pointer of coreboot table header
477 @retval RETURN_SUCCESS Successfully find the coreboot table header .
478 @retval RETURN_NOT_FOUND Failed to find the coreboot table header .
491 return RETURN_NOT_FOUND
;
494 for (Index
= 0; Index
< Level
; Index
++) {
495 TempPtr
= FindCbTag (TempPtr
, CB_TAG_FORWARD
);
500 if ((Index
>= Level
) && (TempPtr
!= NULL
)) {
501 *HeaderPtr
= TempPtr
;
502 return RETURN_SUCCESS
;
505 return RETURN_NOT_FOUND
;
509 Find the video frame buffer information
511 @param pFbInfo Pointer to the FRAME_BUFFER_INFO structure
513 @retval RETURN_SUCCESS Successfully find the video frame buffer information.
514 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information .
519 IN FRAME_BUFFER_INFO
* pFbInfo
522 struct cb_framebuffer
* CbFbRec
;
525 return RETURN_INVALID_PARAMETER
;
527 CbFbRec
= FindCbTag (0, CB_TAG_FRAMEBUFFER
);
529 CbFbRec
= FindCbTag ((VOID
*)(UINTN
)PcdGet32 (PcdCbHeaderPointer
), CB_TAG_FRAMEBUFFER
);
532 return RETURN_NOT_FOUND
;
534 DEBUG ((EFI_D_ERROR
, "Found coreboot video frame buffer information\n"));
535 DEBUG ((EFI_D_ERROR
, "physical_address: 0x%x\n", CbFbRec
->physical_address
));
536 DEBUG ((EFI_D_ERROR
, "x_resolution: 0x%x\n", CbFbRec
->x_resolution
));
537 DEBUG ((EFI_D_ERROR
, "y_resolution: 0x%x\n", CbFbRec
->y_resolution
));
538 DEBUG ((EFI_D_ERROR
, "bits_per_pixel: 0x%x\n", CbFbRec
->bits_per_pixel
));
539 DEBUG ((EFI_D_ERROR
, "bytes_per_line: 0x%x\n", CbFbRec
->bytes_per_line
));
541 DEBUG ((EFI_D_ERROR
, "red_mask_size: 0x%x\n", CbFbRec
->red_mask_size
));
542 DEBUG ((EFI_D_ERROR
, "red_mask_pos: 0x%x\n", CbFbRec
->red_mask_pos
));
543 DEBUG ((EFI_D_ERROR
, "green_mask_size: 0x%x\n", CbFbRec
->green_mask_size
));
544 DEBUG ((EFI_D_ERROR
, "green_mask_pos: 0x%x\n", CbFbRec
->green_mask_pos
));
545 DEBUG ((EFI_D_ERROR
, "blue_mask_size: 0x%x\n", CbFbRec
->blue_mask_size
));
546 DEBUG ((EFI_D_ERROR
, "blue_mask_pos: 0x%x\n", CbFbRec
->blue_mask_pos
));
547 DEBUG ((EFI_D_ERROR
, "reserved_mask_size: 0x%x\n", CbFbRec
->reserved_mask_size
));
548 DEBUG ((EFI_D_ERROR
, "reserved_mask_pos: 0x%x\n", CbFbRec
->reserved_mask_pos
));
550 pFbInfo
->LinearFrameBuffer
= CbFbRec
->physical_address
;
551 pFbInfo
->HorizontalResolution
= CbFbRec
->x_resolution
;
552 pFbInfo
->VerticalResolution
= CbFbRec
->y_resolution
;
553 pFbInfo
->BitsPerPixel
= CbFbRec
->bits_per_pixel
;
554 pFbInfo
->BytesPerScanLine
= (UINT16
)CbFbRec
->bytes_per_line
;
555 pFbInfo
->Red
.Mask
= (1 << CbFbRec
->red_mask_size
) - 1;
556 pFbInfo
->Red
.Position
= CbFbRec
->red_mask_pos
;
557 pFbInfo
->Green
.Mask
= (1 << CbFbRec
->green_mask_size
) - 1;
558 pFbInfo
->Green
.Position
= CbFbRec
->green_mask_pos
;
559 pFbInfo
->Blue
.Mask
= (1 << CbFbRec
->blue_mask_size
) - 1;
560 pFbInfo
->Blue
.Position
= CbFbRec
->blue_mask_pos
;
561 pFbInfo
->Reserved
.Mask
= (1 << CbFbRec
->reserved_mask_size
) - 1;
562 pFbInfo
->Reserved
.Position
= CbFbRec
->reserved_mask_pos
;
564 return RETURN_SUCCESS
;