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