]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/Library/CbParseLib/CbParseLib.c
Fixed a couple of typos of 'Configuration' ('Congfiguration') in Vlv2TbltDevicePkg.
[mirror_edk2.git] / CorebootModulePkg / Library / CbParseLib / CbParseLib.c
CommitLineData
fce4ecd9
MM
1/** @file\r
2 This library will parse the coreboot table in memory and extract those required\r
3 information.\r
4\r
165c0059 5 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
fce4ecd9
MM
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Uefi/UefiBaseType.h>\r
17#include <Library/BaseLib.h>\r
18#include <Library/BaseMemoryLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/PcdLib.h>\r
21#include <Library/CbParseLib.h>\r
22\r
23#include <IndustryStandard/Acpi.h>\r
24\r
25#include "Coreboot.h"\r
26\r
fce4ecd9 27\r
63bdd27a
GD
28/**\r
29 Convert a packed value from cbuint64 to a UINT64 value.\r
30\r
31 @param val The pointer to packed data.\r
32\r
33 @return the UNIT64 value after convertion.\r
34\r
35**/\r
36UINT64 \r
37cb_unpack64 (\r
38 IN struct cbuint64 val\r
39 )\r
fce4ecd9 40{\r
5451fff4 41 return LShiftU64 (val.hi, 32) | val.lo;\r
fce4ecd9
MM
42}\r
43\r
63bdd27a
GD
44\r
45/**\r
46 Returns the sum of all elements in a buffer of 16-bit values. During\r
47 calculation, the carry bits are also been added.\r
48\r
49 @param Buffer The pointer to the buffer to carry out the sum operation.\r
50 @param Length The size, in bytes, of Buffer.\r
51\r
52 @return Sum The sum of Buffer with carry bits included during additions.\r
53\r
54**/\r
fce4ecd9
MM
55UINT16\r
56CbCheckSum16 (\r
57 IN UINT16 *Buffer,\r
58 IN UINTN Length\r
59 )\r
60{\r
11e058ec
GD
61 UINT32 Sum, TmpValue;\r
62 UINTN Idx;\r
63 UINT8 *TmpPtr;\r
64\r
65 Sum = 0;\r
66 TmpPtr = (UINT8 *)Buffer;\r
67 for(Idx = 0; Idx < Length; Idx++) {\r
68 TmpValue = TmpPtr[Idx];\r
69 if (Idx % 2 == 1) {\r
70 TmpValue <<= 8;\r
71 }\r
72\r
73 Sum += TmpValue;\r
74\r
75 // Wrap\r
76 if (Sum >= 0x10000) {\r
77 Sum = (Sum + (Sum >> 16)) & 0xFFFF;\r
78 }\r
79 }\r
80\r
81 return (UINT16)((~Sum) & 0xFFFF);\r
fce4ecd9
MM
82}\r
83\r
63bdd27a
GD
84\r
85/**\r
86 Find coreboot record with given Tag from the memory Start in 4096\r
87 bytes range.\r
88\r
89 @param Start The start memory to be searched in\r
90 @param Tag The tag id to be found\r
91\r
92 @retval NULL The Tag is not found.\r
93 @retval Others The poiter to the record found.\r
94\r
95**/\r
fce4ecd9
MM
96VOID *\r
97FindCbTag (\r
63bdd27a 98 IN VOID *Start,\r
fce4ecd9
MM
99 IN UINT32 Tag\r
100 )\r
101{\r
102 struct cb_header *Header;\r
103 struct cb_record *Record;\r
11e058ec
GD
104 UINT8 *TmpPtr;\r
105 UINT8 *TagPtr;\r
106 UINTN Idx;\r
fce4ecd9 107 UINT16 CheckSum;\r
11e058ec 108\r
fce4ecd9
MM
109 Header = NULL;\r
110 TmpPtr = (UINT8 *)Start;\r
111 for (Idx = 0; Idx < 4096; Idx += 16, TmpPtr += 16) {\r
63bdd27a 112 Header = (struct cb_header *)TmpPtr;\r
fce4ecd9
MM
113 if (Header->signature == CB_HEADER_SIGNATURE) {\r
114 break;\r
115 }\r
116 }\r
11e058ec 117\r
63bdd27a 118 if (Idx >= 4096) {\r
11e058ec 119 return NULL;\r
63bdd27a 120 }\r
11e058ec 121\r
63bdd27a 122 if ((Header == NULL) || (Header->table_bytes == 0)) {\r
fce4ecd9 123 return NULL;\r
63bdd27a 124 }\r
11e058ec 125\r
fce4ecd9
MM
126 //\r
127 // Check the checksum of the coreboot table header\r
128 //\r
129 CheckSum = CbCheckSum16 ((UINT16 *)Header, sizeof (*Header));\r
130 if (CheckSum != 0) {\r
11e058ec
GD
131 DEBUG ((EFI_D_ERROR, "Invalid coreboot table header checksum\n"));\r
132 return NULL;\r
133 }\r
134\r
fce4ecd9
MM
135 CheckSum = CbCheckSum16 ((UINT16 *)(TmpPtr + sizeof (*Header)), Header->table_bytes);\r
136 if (CheckSum != Header->table_checksum) {\r
11e058ec
GD
137 DEBUG ((EFI_D_ERROR, "Incorrect checksum of all the coreboot table entries\n"));\r
138 return NULL;\r
fce4ecd9 139 }\r
11e058ec 140\r
fce4ecd9
MM
141 TagPtr = NULL;\r
142 TmpPtr += Header->header_bytes;\r
143 for (Idx = 0; Idx < Header->table_entries; Idx++) {\r
11e058ec 144 Record = (struct cb_record *)TmpPtr;\r
fce4ecd9
MM
145 if (Record->tag == CB_TAG_FORWARD) {\r
146 TmpPtr = (VOID *)(UINTN)((struct cb_forward *)(UINTN)Record)->forward;\r
63bdd27a 147 if (Tag == CB_TAG_FORWARD) {\r
fce4ecd9 148 return TmpPtr;\r
63bdd27a 149 } else {\r
fce4ecd9 150 return FindCbTag (TmpPtr, Tag);\r
63bdd27a 151 }\r
11e058ec 152 }\r
fce4ecd9
MM
153 if (Record->tag == Tag) {\r
154 TagPtr = TmpPtr;\r
155 break;\r
156 }\r
11e058ec 157 TmpPtr += Record->size;\r
fce4ecd9 158 }\r
11e058ec 159\r
fce4ecd9
MM
160 return TagPtr;\r
161}\r
162\r
63bdd27a
GD
163\r
164/**\r
165 Find the given table with TableId from the given coreboot memory Root.\r
166\r
167 @param Root The coreboot memory table to be searched in\r
168 @param TableId Table id to be found\r
169 @param pMemTable To save the base address of the memory table found\r
170 @param pMemTableSize To save the size of memory table found\r
171\r
172 @retval RETURN_SUCCESS Successfully find out the memory table.\r
173 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
174 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
175\r
176**/\r
fce4ecd9 177RETURN_STATUS\r
11e058ec 178FindCbMemTable (\r
165c0059
GD
179 IN struct cbmem_root *Root,\r
180 IN UINT32 TableId,\r
181 OUT VOID **pMemTable,\r
182 OUT UINT32 *pMemTableSize\r
11e058ec
GD
183 )\r
184{\r
165c0059
GD
185 UINTN Idx;\r
186 BOOLEAN IsImdEntry;\r
187 struct cbmem_entry *Entries;\r
11e058ec 188\r
165c0059
GD
189 if ((Root == NULL) || (pMemTable == NULL)) {\r
190 return RETURN_INVALID_PARAMETER;\r
191 }\r
165c0059
GD
192 //\r
193 // Check if the entry is CBMEM or IMD\r
194 // and handle them separately\r
195 //\r
63bdd27a 196 Entries = Root->entries;\r
165c0059
GD
197 if (Entries[0].magic == CBMEM_ENTRY_MAGIC) {\r
198 IsImdEntry = FALSE;\r
199 } else {\r
63bdd27a 200 Entries = (struct cbmem_entry *)((struct imd_root *)Root)->entries;\r
165c0059
GD
201 if (Entries[0].magic == IMD_ENTRY_MAGIC) {\r
202 IsImdEntry = TRUE;\r
203 } else {\r
204 return RETURN_NOT_FOUND;\r
205 }\r
206 }\r
207\r
208 for (Idx = 0; Idx < Root->num_entries; Idx++) {\r
209 if (Entries[Idx].id == TableId) {\r
210 if (IsImdEntry) {\r
211 *pMemTable = (VOID *) ((UINTN)Entries[Idx].start + (UINTN)Root);\r
212 } else {\r
213 *pMemTable = (VOID *) (UINTN)Entries[Idx].start;\r
214 }\r
215 if (pMemTableSize != NULL) {\r
216 *pMemTableSize = Entries[Idx].size;\r
217 }\r
11e058ec 218\r
165c0059 219 DEBUG ((EFI_D_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n", TableId, *pMemTable, *pMemTableSize));\r
11e058ec 220 return RETURN_SUCCESS;\r
fce4ecd9
MM
221 }\r
222 }\r
11e058ec
GD
223\r
224 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
225}\r
226\r
227\r
228/**\r
229 Acquire the memory information from the coreboot table in memory.\r
230\r
231 @param pLowMemorySize Pointer to the variable of low memory size\r
232 @param pHighMemorySize Pointer to the variable of high memory size\r
233\r
234 @retval RETURN_SUCCESS Successfully find out the memory information.\r
235 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
236 @retval RETURN_NOT_FOUND Failed to find the memory information.\r
237\r
238**/\r
239RETURN_STATUS\r
240CbParseMemoryInfo (\r
63bdd27a
GD
241 OUT UINT64 *pLowMemorySize,\r
242 OUT UINT64 *pHighMemorySize\r
fce4ecd9
MM
243 )\r
244{\r
63bdd27a
GD
245 struct cb_memory *rec;\r
246 struct cb_memory_range *Range;\r
fce4ecd9
MM
247 UINT64 Start;\r
248 UINT64 Size;\r
11e058ec
GD
249 UINTN Index;\r
250\r
63bdd27a 251 if ((pLowMemorySize == NULL) || (pHighMemorySize == NULL)) {\r
11e058ec 252 return RETURN_INVALID_PARAMETER;\r
63bdd27a 253 }\r
11e058ec
GD
254\r
255 //\r
256 // Get the coreboot memory table\r
257 //\r
258 rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
63bdd27a 259 if (rec == NULL) {\r
11e058ec 260 rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
63bdd27a 261 }\r
11e058ec 262\r
63bdd27a 263 if (rec == NULL) {\r
11e058ec 264 return RETURN_NOT_FOUND;\r
63bdd27a 265 }\r
11e058ec
GD
266\r
267 *pLowMemorySize = 0;\r
268 *pHighMemorySize = 0;\r
269\r
270 for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
271 Range = MEM_RANGE_PTR(rec, Index);\r
fce4ecd9
MM
272 Start = cb_unpack64(Range->start);\r
273 Size = cb_unpack64(Range->size);\r
63bdd27a 274 DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",\r
11e058ec
GD
275 Index, Start, Start + Size - 1, Range->type));\r
276\r
fce4ecd9
MM
277 if (Range->type != CB_MEM_RAM) {\r
278 continue;\r
279 }\r
11e058ec 280\r
fce4ecd9
MM
281 if (Start + Size < 0x100000000ULL) {\r
282 *pLowMemorySize = Start + Size;\r
11e058ec 283 } else {\r
fce4ecd9
MM
284 *pHighMemorySize = Start + Size - 0x100000000ULL;\r
285 }\r
286 }\r
11e058ec 287\r
63bdd27a 288 DEBUG ((EFI_D_INFO, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemorySize, *pHighMemorySize));\r
11e058ec
GD
289\r
290 return RETURN_SUCCESS;\r
fce4ecd9
MM
291}\r
292\r
293\r
294/**\r
295 Acquire the coreboot memory table with the given table id\r
296\r
297 @param TableId Table id to be searched\r
298 @param pMemTable Pointer to the base address of the memory table\r
299 @param pMemTableSize Pointer to the size of the memory table\r
300\r
301 @retval RETURN_SUCCESS Successfully find out the memory table.\r
302 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
303 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
304\r
305**/\r
306RETURN_STATUS\r
307CbParseCbMemTable (\r
63bdd27a
GD
308 IN UINT32 TableId,\r
309 OUT VOID **pMemTable,\r
310 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
311 )\r
312{\r
63bdd27a
GD
313 struct cb_memory *rec;\r
314 struct cb_memory_range *Range;\r
fce4ecd9
MM
315 UINT64 Start;\r
316 UINT64 Size;\r
11e058ec
GD
317 UINTN Index;\r
318\r
63bdd27a 319 if (pMemTable == NULL) {\r
11e058ec 320 return RETURN_INVALID_PARAMETER;\r
63bdd27a 321 }\r
11e058ec
GD
322 *pMemTable = NULL;\r
323\r
324 //\r
325 // Get the coreboot memory table\r
326 //\r
327 rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
63bdd27a 328 if (rec == NULL) {\r
11e058ec 329 rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
63bdd27a 330 }\r
11e058ec 331\r
63bdd27a 332 if (rec == NULL) {\r
11e058ec 333 return RETURN_NOT_FOUND;\r
63bdd27a 334 }\r
11e058ec
GD
335\r
336 for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
337 Range = MEM_RANGE_PTR(rec, Index);\r
fce4ecd9
MM
338 Start = cb_unpack64(Range->start);\r
339 Size = cb_unpack64(Range->size);\r
11e058ec 340\r
fce4ecd9 341 if ((Range->type == CB_MEM_TABLE) && (Start > 0x1000)) {\r
11e058ec
GD
342 if (FindCbMemTable ((struct cbmem_root *)(UINTN)(Start + Size - DYN_CBMEM_ALIGN_SIZE), TableId, pMemTable, pMemTableSize) == RETURN_SUCCESS)\r
343 return RETURN_SUCCESS;\r
fce4ecd9
MM
344 }\r
345 }\r
11e058ec
GD
346\r
347 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
348}\r
349\r
350\r
351/**\r
352 Acquire the acpi table from coreboot\r
353\r
354 @param pMemTable Pointer to the base address of the memory table\r
355 @param pMemTableSize Pointer to the size of the memory table\r
356\r
357 @retval RETURN_SUCCESS Successfully find out the memory table.\r
358 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
359 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
360\r
361**/\r
362RETURN_STATUS\r
363CbParseAcpiTable (\r
63bdd27a
GD
364 OUT VOID **pMemTable,\r
365 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
366 )\r
367{\r
1e6c931b 368 return CbParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), pMemTable, pMemTableSize);\r
fce4ecd9
MM
369}\r
370\r
371/**\r
372 Acquire the smbios table from coreboot\r
373\r
374 @param pMemTable Pointer to the base address of the memory table\r
375 @param pMemTableSize Pointer to the size of the memory table\r
376\r
377 @retval RETURN_SUCCESS Successfully find out the memory table.\r
378 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
379 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
380\r
381**/\r
382RETURN_STATUS\r
383CbParseSmbiosTable (\r
63bdd27a
GD
384 OUT VOID **pMemTable,\r
385 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
386 )\r
387{\r
11e058ec 388 return CbParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), pMemTable, pMemTableSize);\r
fce4ecd9
MM
389}\r
390\r
391/**\r
392 Find the required fadt information\r
393\r
394 @param pPmCtrlReg Pointer to the address of power management control register\r
395 @param pPmTimerReg Pointer to the address of power management timer register\r
396 @param pResetReg Pointer to the address of system reset register\r
397 @param pResetValue Pointer to the value to be writen to the system reset register\r
398\r
399 @retval RETURN_SUCCESS Successfully find out all the required fadt information.\r
400 @retval RETURN_NOT_FOUND Failed to find the fadt table.\r
401\r
402**/\r
403RETURN_STATUS\r
404CbParseFadtInfo (\r
63bdd27a
GD
405 OUT UINTN *pPmCtrlReg,\r
406 OUT UINTN *pPmTimerReg,\r
407 OUT UINTN *pResetReg,\r
408 OUT UINTN *pResetValue\r
fce4ecd9
MM
409 )\r
410{\r
63bdd27a
GD
411 EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;\r
412 EFI_ACPI_DESCRIPTION_HEADER *Rsdt;\r
413 UINT32 *Entry32;\r
fce4ecd9 414 UINTN Entry32Num;\r
63bdd27a
GD
415 EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;\r
416 EFI_ACPI_DESCRIPTION_HEADER *Xsdt;\r
417 UINT64 *Entry64;\r
fce4ecd9 418 UINTN Entry64Num;\r
11e058ec
GD
419 UINTN Idx;\r
420 RETURN_STATUS Status;\r
421\r
422 Rsdp = NULL;\r
423 Status = RETURN_SUCCESS;\r
424\r
2e1fffce 425 Status = CbParseAcpiTable ((VOID **)&Rsdp, NULL);\r
63bdd27a 426 if (RETURN_ERROR(Status)) {\r
11e058ec 427 return Status;\r
63bdd27a 428 }\r
11e058ec 429\r
63bdd27a 430 if (Rsdp == NULL) {\r
11e058ec 431 return RETURN_NOT_FOUND;\r
63bdd27a 432 }\r
11e058ec 433\r
63bdd27a
GD
434 DEBUG ((EFI_D_INFO, "Find Rsdp at %p\n", Rsdp));\r
435 DEBUG ((EFI_D_INFO, "Find Rsdt 0x%x, Xsdt 0x%lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress));\r
11e058ec
GD
436\r
437 //\r
438 // Search Rsdt First\r
439 //\r
440 Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->RsdtAddress);\r
441 if (Rsdt != NULL) {\r
442 Entry32 = (UINT32 *)(Rsdt + 1);\r
443 Entry32Num = (Rsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 2;\r
444 for (Idx = 0; Idx < Entry32Num; Idx++) {\r
445 if (*(UINT32 *)(UINTN)(Entry32[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
446 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry32[Idx]);\r
63bdd27a 447 if (pPmCtrlReg != NULL) {\r
11e058ec 448 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
63bdd27a
GD
449 }\r
450 DEBUG ((EFI_D_INFO, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
11e058ec 451\r
63bdd27a 452 if (pPmTimerReg != NULL) {\r
11e058ec 453 *pPmTimerReg = Fadt->PmTmrBlk;\r
63bdd27a
GD
454 }\r
455 DEBUG ((EFI_D_INFO, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
11e058ec 456\r
63bdd27a 457 if (pResetReg != NULL) {\r
11e058ec 458 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
63bdd27a
GD
459 }\r
460 DEBUG ((EFI_D_INFO, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
11e058ec 461\r
63bdd27a 462 if (pResetValue != NULL) {\r
11e058ec 463 *pResetValue = Fadt->ResetValue;\r
63bdd27a
GD
464 }\r
465 DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r
11e058ec
GD
466\r
467 return RETURN_SUCCESS;\r
468 }\r
469 }\r
470 }\r
471\r
472 //\r
473 // Search Xsdt Second\r
474 //\r
475 Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->XsdtAddress);\r
476 if (Xsdt != NULL) {\r
477 Entry64 = (UINT64 *)(Xsdt + 1);\r
478 Entry64Num = (Xsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 3;\r
479 for (Idx = 0; Idx < Entry64Num; Idx++) {\r
480 if (*(UINT32 *)(UINTN)(Entry64[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
481 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry64[Idx]);\r
482 if (pPmCtrlReg)\r
483 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
484 DEBUG ((EFI_D_ERROR, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
485\r
486 if (pPmTimerReg)\r
487 *pPmTimerReg = Fadt->PmTmrBlk;\r
488 DEBUG ((EFI_D_ERROR, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
489\r
490 if (pResetReg)\r
491 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
492 DEBUG ((EFI_D_ERROR, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
493\r
494 if (pResetValue)\r
495 *pResetValue = Fadt->ResetValue;\r
496 DEBUG ((EFI_D_ERROR, "Reset Value 0x%x\n", Fadt->ResetValue));\r
497\r
498 return RETURN_SUCCESS;\r
499 }\r
500 }\r
501 }\r
502\r
503 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
504}\r
505\r
506/**\r
507 Find the serial port information\r
508\r
509 @param pRegBase Pointer to the base address of serial port registers\r
510 @param pRegAccessType Pointer to the access type of serial port registers\r
511 @param pBaudrate Pointer to the serial port baudrate\r
512\r
513 @retval RETURN_SUCCESS Successfully find the serial port information.\r
514 @retval RETURN_NOT_FOUND Failed to find the serial port information .\r
515\r
516**/\r
517RETURN_STATUS\r
518CbParseSerialInfo (\r
63bdd27a
GD
519 OUT UINT32 *pRegBase,\r
520 OUT UINT32 *pRegAccessType,\r
521 OUT UINT32 *pBaudrate\r
fce4ecd9
MM
522 )\r
523{\r
63bdd27a 524 struct cb_serial *CbSerial;\r
11e058ec
GD
525\r
526 CbSerial = FindCbTag (0, CB_TAG_SERIAL);\r
63bdd27a 527 if (CbSerial == NULL) {\r
11e058ec 528 CbSerial = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_SERIAL);\r
63bdd27a 529 }\r
11e058ec 530\r
63bdd27a 531 if (CbSerial == NULL) {\r
11e058ec 532 return RETURN_NOT_FOUND;\r
63bdd27a 533 }\r
11e058ec 534\r
63bdd27a 535 if (pRegBase != NULL) {\r
11e058ec 536 *pRegBase = CbSerial->baseaddr;\r
63bdd27a 537 }\r
11e058ec 538\r
63bdd27a 539 if (pRegAccessType != NULL) {\r
11e058ec 540 *pRegAccessType = CbSerial->type;\r
63bdd27a 541 }\r
11e058ec 542\r
63bdd27a 543 if (pBaudrate != NULL) {\r
11e058ec 544 *pBaudrate = CbSerial->baud;\r
63bdd27a 545 }\r
11e058ec
GD
546\r
547 return RETURN_SUCCESS;\r
fce4ecd9
MM
548}\r
549\r
550/**\r
551 Search for the coreboot table header\r
552\r
553 @param Level Level of the search depth\r
554 @param HeaderPtr Pointer to the pointer of coreboot table header\r
555\r
556 @retval RETURN_SUCCESS Successfully find the coreboot table header .\r
557 @retval RETURN_NOT_FOUND Failed to find the coreboot table header .\r
558\r
559**/\r
560RETURN_STATUS\r
561CbParseGetCbHeader (\r
63bdd27a
GD
562 IN UINTN Level,\r
563 OUT VOID **HeaderPtr\r
fce4ecd9
MM
564 )\r
565{\r
11e058ec 566 UINTN Index;\r
63bdd27a 567 VOID *TempPtr;\r
11e058ec 568\r
63bdd27a 569 if (HeaderPtr == NULL) {\r
11e058ec 570 return RETURN_NOT_FOUND;\r
63bdd27a 571 }\r
11e058ec
GD
572\r
573 TempPtr = NULL;\r
574 for (Index = 0; Index < Level; Index++) {\r
575 TempPtr = FindCbTag (TempPtr, CB_TAG_FORWARD);\r
63bdd27a 576 if (TempPtr == NULL) {\r
11e058ec 577 break;\r
63bdd27a 578 }\r
11e058ec
GD
579 }\r
580\r
581 if ((Index >= Level) && (TempPtr != NULL)) {\r
582 *HeaderPtr = TempPtr;\r
583 return RETURN_SUCCESS;\r
584 }\r
585\r
586 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
587}\r
588\r
589/**\r
590 Find the video frame buffer information\r
591\r
592 @param pFbInfo Pointer to the FRAME_BUFFER_INFO structure\r
593\r
594 @retval RETURN_SUCCESS Successfully find the video frame buffer information.\r
595 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information .\r
596\r
597**/\r
598RETURN_STATUS\r
599CbParseFbInfo (\r
63bdd27a 600 OUT FRAME_BUFFER_INFO *pFbInfo\r
fce4ecd9
MM
601 )\r
602{\r
63bdd27a 603 struct cb_framebuffer *CbFbRec;\r
11e058ec 604\r
63bdd27a 605 if (pFbInfo == NULL) {\r
11e058ec 606 return RETURN_INVALID_PARAMETER;\r
63bdd27a 607 }\r
11e058ec
GD
608\r
609 CbFbRec = FindCbTag (0, CB_TAG_FRAMEBUFFER);\r
63bdd27a 610 if (CbFbRec == NULL) {\r
11e058ec 611 CbFbRec = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_FRAMEBUFFER);\r
63bdd27a 612 }\r
11e058ec 613\r
63bdd27a 614 if (CbFbRec == NULL) {\r
11e058ec 615 return RETURN_NOT_FOUND;\r
63bdd27a 616 }\r
11e058ec 617\r
63bdd27a
GD
618 DEBUG ((EFI_D_INFO, "Found coreboot video frame buffer information\n"));\r
619 DEBUG ((EFI_D_INFO, "physical_address: 0x%lx\n", CbFbRec->physical_address));\r
620 DEBUG ((EFI_D_INFO, "x_resolution: 0x%x\n", CbFbRec->x_resolution));\r
621 DEBUG ((EFI_D_INFO, "y_resolution: 0x%x\n", CbFbRec->y_resolution));\r
622 DEBUG ((EFI_D_INFO, "bits_per_pixel: 0x%x\n", CbFbRec->bits_per_pixel));\r
623 DEBUG ((EFI_D_INFO, "bytes_per_line: 0x%x\n", CbFbRec->bytes_per_line));\r
624\r
625 DEBUG ((EFI_D_INFO, "red_mask_size: 0x%x\n", CbFbRec->red_mask_size));\r
626 DEBUG ((EFI_D_INFO, "red_mask_pos: 0x%x\n", CbFbRec->red_mask_pos));\r
627 DEBUG ((EFI_D_INFO, "green_mask_size: 0x%x\n", CbFbRec->green_mask_size));\r
628 DEBUG ((EFI_D_INFO, "green_mask_pos: 0x%x\n", CbFbRec->green_mask_pos));\r
629 DEBUG ((EFI_D_INFO, "blue_mask_size: 0x%x\n", CbFbRec->blue_mask_size));\r
630 DEBUG ((EFI_D_INFO, "blue_mask_pos: 0x%x\n", CbFbRec->blue_mask_pos));\r
631 DEBUG ((EFI_D_INFO, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));\r
632 DEBUG ((EFI_D_INFO, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));\r
11e058ec
GD
633\r
634 pFbInfo->LinearFrameBuffer = CbFbRec->physical_address;\r
fce4ecd9
MM
635 pFbInfo->HorizontalResolution = CbFbRec->x_resolution;\r
636 pFbInfo->VerticalResolution = CbFbRec->y_resolution;\r
637 pFbInfo->BitsPerPixel = CbFbRec->bits_per_pixel;\r
638 pFbInfo->BytesPerScanLine = (UINT16)CbFbRec->bytes_per_line;\r
639 pFbInfo->Red.Mask = (1 << CbFbRec->red_mask_size) - 1;\r
640 pFbInfo->Red.Position = CbFbRec->red_mask_pos;\r
641 pFbInfo->Green.Mask = (1 << CbFbRec->green_mask_size) - 1;\r
642 pFbInfo->Green.Position = CbFbRec->green_mask_pos;\r
643 pFbInfo->Blue.Mask = (1 << CbFbRec->blue_mask_size) - 1;\r
644 pFbInfo->Blue.Position = CbFbRec->blue_mask_pos;\r
645 pFbInfo->Reserved.Mask = (1 << CbFbRec->reserved_mask_size) - 1;\r
11e058ec 646 pFbInfo->Reserved.Position = CbFbRec->reserved_mask_pos;\r
fce4ecd9 647\r
11e058ec
GD
648 return RETURN_SUCCESS;\r
649}\r
fce4ecd9 650\r