]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/Library/CbParseLib/CbParseLib.c
CorebootPayloadPkg: Make EFI shell the last boot option.
[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
2d90b74d 5 Copyright (c) 2014 - 2016, 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
2d90b74d 36UINT64\r
63bdd27a
GD
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
2d90b74d 219 DEBUG ((EFI_D_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",\r
220 TableId, *pMemTable, Entries[Idx].size));\r
11e058ec 221 return RETURN_SUCCESS;\r
fce4ecd9
MM
222 }\r
223 }\r
11e058ec
GD
224\r
225 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
226}\r
227\r
228\r
229/**\r
230 Acquire the memory information from the coreboot table in memory.\r
231\r
2d90b74d 232 @param MemInfoCallback The callback routine\r
233 @param pParam Pointer to the callback routine parameter\r
fce4ecd9
MM
234\r
235 @retval RETURN_SUCCESS Successfully find out the memory information.\r
fce4ecd9
MM
236 @retval RETURN_NOT_FOUND Failed to find the memory information.\r
237\r
238**/\r
239RETURN_STATUS\r
240CbParseMemoryInfo (\r
2d90b74d 241 IN CB_MEM_INFO_CALLBACK MemInfoCallback,\r
242 IN VOID *pParam\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
11e058ec
GD
251 //\r
252 // Get the coreboot memory table\r
253 //\r
254 rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
63bdd27a 255 if (rec == NULL) {\r
11e058ec 256 rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
63bdd27a 257 }\r
11e058ec 258\r
63bdd27a 259 if (rec == NULL) {\r
11e058ec 260 return RETURN_NOT_FOUND;\r
63bdd27a 261 }\r
11e058ec 262\r
11e058ec
GD
263 for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
264 Range = MEM_RANGE_PTR(rec, Index);\r
fce4ecd9
MM
265 Start = cb_unpack64(Range->start);\r
266 Size = cb_unpack64(Range->size);\r
63bdd27a 267 DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",\r
11e058ec
GD
268 Index, Start, Start + Size - 1, Range->type));\r
269\r
2d90b74d 270 MemInfoCallback (Start, Size, Range->type, pParam);\r
fce4ecd9 271 }\r
11e058ec 272\r
11e058ec 273 return RETURN_SUCCESS;\r
fce4ecd9
MM
274}\r
275\r
276\r
277/**\r
278 Acquire the coreboot memory table with the given table id\r
279\r
280 @param TableId Table id to be searched\r
281 @param pMemTable Pointer to the base address of the memory table\r
282 @param pMemTableSize Pointer to the size of the memory table\r
283\r
284 @retval RETURN_SUCCESS Successfully find out the memory table.\r
285 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
286 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
287\r
288**/\r
289RETURN_STATUS\r
290CbParseCbMemTable (\r
63bdd27a
GD
291 IN UINT32 TableId,\r
292 OUT VOID **pMemTable,\r
293 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
294 )\r
295{\r
63bdd27a
GD
296 struct cb_memory *rec;\r
297 struct cb_memory_range *Range;\r
fce4ecd9
MM
298 UINT64 Start;\r
299 UINT64 Size;\r
11e058ec
GD
300 UINTN Index;\r
301\r
63bdd27a 302 if (pMemTable == NULL) {\r
11e058ec 303 return RETURN_INVALID_PARAMETER;\r
63bdd27a 304 }\r
11e058ec
GD
305 *pMemTable = NULL;\r
306\r
307 //\r
308 // Get the coreboot memory table\r
309 //\r
310 rec = (struct cb_memory *)FindCbTag (0, CB_TAG_MEMORY);\r
63bdd27a 311 if (rec == NULL) {\r
11e058ec 312 rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r
63bdd27a 313 }\r
11e058ec 314\r
63bdd27a 315 if (rec == NULL) {\r
11e058ec 316 return RETURN_NOT_FOUND;\r
63bdd27a 317 }\r
11e058ec
GD
318\r
319 for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
320 Range = MEM_RANGE_PTR(rec, Index);\r
fce4ecd9
MM
321 Start = cb_unpack64(Range->start);\r
322 Size = cb_unpack64(Range->size);\r
11e058ec 323\r
fce4ecd9 324 if ((Range->type == CB_MEM_TABLE) && (Start > 0x1000)) {\r
11e058ec
GD
325 if (FindCbMemTable ((struct cbmem_root *)(UINTN)(Start + Size - DYN_CBMEM_ALIGN_SIZE), TableId, pMemTable, pMemTableSize) == RETURN_SUCCESS)\r
326 return RETURN_SUCCESS;\r
fce4ecd9
MM
327 }\r
328 }\r
11e058ec
GD
329\r
330 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
331}\r
332\r
333\r
334/**\r
335 Acquire the acpi table from coreboot\r
336\r
337 @param pMemTable Pointer to the base address of the memory table\r
338 @param pMemTableSize Pointer to the size of the memory table\r
339\r
340 @retval RETURN_SUCCESS Successfully find out the memory table.\r
341 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
342 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
343\r
344**/\r
345RETURN_STATUS\r
346CbParseAcpiTable (\r
63bdd27a
GD
347 OUT VOID **pMemTable,\r
348 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
349 )\r
350{\r
1e6c931b 351 return CbParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), pMemTable, pMemTableSize);\r
fce4ecd9
MM
352}\r
353\r
354/**\r
355 Acquire the smbios table from coreboot\r
356\r
357 @param pMemTable Pointer to the base address of the memory table\r
358 @param pMemTableSize Pointer to the size of the memory table\r
359\r
360 @retval RETURN_SUCCESS Successfully find out the memory table.\r
361 @retval RETURN_INVALID_PARAMETER Invalid input parameters.\r
362 @retval RETURN_NOT_FOUND Failed to find the memory table.\r
363\r
364**/\r
365RETURN_STATUS\r
366CbParseSmbiosTable (\r
63bdd27a
GD
367 OUT VOID **pMemTable,\r
368 OUT UINT32 *pMemTableSize\r
fce4ecd9
MM
369 )\r
370{\r
11e058ec 371 return CbParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), pMemTable, pMemTableSize);\r
fce4ecd9
MM
372}\r
373\r
374/**\r
375 Find the required fadt information\r
376\r
377 @param pPmCtrlReg Pointer to the address of power management control register\r
378 @param pPmTimerReg Pointer to the address of power management timer register\r
379 @param pResetReg Pointer to the address of system reset register\r
380 @param pResetValue Pointer to the value to be writen to the system reset register\r
05de9ab2
GD
381 @param pPmEvtReg Pointer to the address of power management event register\r
382 @param pPmGpeEnReg Pointer to the address of power management GPE enable register\r
fce4ecd9
MM
383\r
384 @retval RETURN_SUCCESS Successfully find out all the required fadt information.\r
385 @retval RETURN_NOT_FOUND Failed to find the fadt table.\r
386\r
387**/\r
388RETURN_STATUS\r
389CbParseFadtInfo (\r
63bdd27a
GD
390 OUT UINTN *pPmCtrlReg,\r
391 OUT UINTN *pPmTimerReg,\r
392 OUT UINTN *pResetReg,\r
05de9ab2
GD
393 OUT UINTN *pResetValue,\r
394 OUT UINTN *pPmEvtReg,\r
395 OUT UINTN *pPmGpeEnReg\r
fce4ecd9
MM
396 )\r
397{\r
63bdd27a
GD
398 EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;\r
399 EFI_ACPI_DESCRIPTION_HEADER *Rsdt;\r
400 UINT32 *Entry32;\r
fce4ecd9 401 UINTN Entry32Num;\r
63bdd27a
GD
402 EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;\r
403 EFI_ACPI_DESCRIPTION_HEADER *Xsdt;\r
404 UINT64 *Entry64;\r
fce4ecd9 405 UINTN Entry64Num;\r
11e058ec
GD
406 UINTN Idx;\r
407 RETURN_STATUS Status;\r
408\r
409 Rsdp = NULL;\r
410 Status = RETURN_SUCCESS;\r
411\r
2e1fffce 412 Status = CbParseAcpiTable ((VOID **)&Rsdp, NULL);\r
63bdd27a 413 if (RETURN_ERROR(Status)) {\r
11e058ec 414 return Status;\r
63bdd27a 415 }\r
11e058ec 416\r
63bdd27a 417 if (Rsdp == NULL) {\r
11e058ec 418 return RETURN_NOT_FOUND;\r
63bdd27a 419 }\r
11e058ec 420\r
63bdd27a
GD
421 DEBUG ((EFI_D_INFO, "Find Rsdp at %p\n", Rsdp));\r
422 DEBUG ((EFI_D_INFO, "Find Rsdt 0x%x, Xsdt 0x%lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress));\r
11e058ec
GD
423\r
424 //\r
425 // Search Rsdt First\r
426 //\r
427 Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->RsdtAddress);\r
428 if (Rsdt != NULL) {\r
429 Entry32 = (UINT32 *)(Rsdt + 1);\r
430 Entry32Num = (Rsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 2;\r
431 for (Idx = 0; Idx < Entry32Num; Idx++) {\r
432 if (*(UINT32 *)(UINTN)(Entry32[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
433 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry32[Idx]);\r
63bdd27a 434 if (pPmCtrlReg != NULL) {\r
11e058ec 435 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
63bdd27a
GD
436 }\r
437 DEBUG ((EFI_D_INFO, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
11e058ec 438\r
63bdd27a 439 if (pPmTimerReg != NULL) {\r
11e058ec 440 *pPmTimerReg = Fadt->PmTmrBlk;\r
63bdd27a
GD
441 }\r
442 DEBUG ((EFI_D_INFO, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
11e058ec 443\r
63bdd27a 444 if (pResetReg != NULL) {\r
11e058ec 445 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
63bdd27a
GD
446 }\r
447 DEBUG ((EFI_D_INFO, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
11e058ec 448\r
63bdd27a 449 if (pResetValue != NULL) {\r
11e058ec 450 *pResetValue = Fadt->ResetValue;\r
63bdd27a
GD
451 }\r
452 DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r
11e058ec 453\r
2d90b74d 454 if (pPmEvtReg != NULL) {\r
05de9ab2
GD
455 *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
456 DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
457 }\r
458\r
2d90b74d 459 if (pPmGpeEnReg != NULL) {\r
05de9ab2
GD
460 *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
461 DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
462 }\r
463\r
2d90b74d 464 //\r
465 // Verify values for proper operation\r
466 //\r
467 ASSERT(Fadt->Pm1aCntBlk != 0);\r
468 ASSERT(Fadt->PmTmrBlk != 0);\r
469 ASSERT(Fadt->ResetReg.Address != 0);\r
470 ASSERT(Fadt->Pm1aEvtBlk != 0);\r
471 ASSERT(Fadt->Gpe0Blk != 0);\r
472\r
11e058ec
GD
473 return RETURN_SUCCESS;\r
474 }\r
475 }\r
476 }\r
477\r
478 //\r
479 // Search Xsdt Second\r
480 //\r
481 Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->XsdtAddress);\r
482 if (Xsdt != NULL) {\r
483 Entry64 = (UINT64 *)(Xsdt + 1);\r
484 Entry64Num = (Xsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 3;\r
485 for (Idx = 0; Idx < Entry64Num; Idx++) {\r
486 if (*(UINT32 *)(UINTN)(Entry64[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
487 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry64[Idx]);\r
488 if (pPmCtrlReg)\r
489 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
490 DEBUG ((EFI_D_ERROR, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
491\r
492 if (pPmTimerReg)\r
493 *pPmTimerReg = Fadt->PmTmrBlk;\r
494 DEBUG ((EFI_D_ERROR, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
495\r
496 if (pResetReg)\r
497 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
498 DEBUG ((EFI_D_ERROR, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
499\r
500 if (pResetValue)\r
501 *pResetValue = Fadt->ResetValue;\r
502 DEBUG ((EFI_D_ERROR, "Reset Value 0x%x\n", Fadt->ResetValue));\r
503\r
2d90b74d 504 if (pPmEvtReg != NULL) {\r
05de9ab2
GD
505 *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
506 DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
507 }\r
508\r
2d90b74d 509 if (pPmGpeEnReg != NULL) {\r
05de9ab2
GD
510 *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
511 DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
2d90b74d 512 }\r
11e058ec
GD
513 return RETURN_SUCCESS;\r
514 }\r
515 }\r
516 }\r
517\r
518 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
519}\r
520\r
521/**\r
522 Find the serial port information\r
523\r
524 @param pRegBase Pointer to the base address of serial port registers\r
525 @param pRegAccessType Pointer to the access type of serial port registers\r
2d90b74d 526 @param pRegWidth Pointer to the register width in bytes\r
fce4ecd9 527 @param pBaudrate Pointer to the serial port baudrate\r
2d90b74d 528 @param pInputHertz Pointer to the input clock frequency\r
529 @param pUartPciAddr Pointer to the UART PCI bus, dev and func address\r
fce4ecd9
MM
530\r
531 @retval RETURN_SUCCESS Successfully find the serial port information.\r
532 @retval RETURN_NOT_FOUND Failed to find the serial port information .\r
533\r
534**/\r
535RETURN_STATUS\r
536CbParseSerialInfo (\r
63bdd27a
GD
537 OUT UINT32 *pRegBase,\r
538 OUT UINT32 *pRegAccessType,\r
2d90b74d 539 OUT UINT32 *pRegWidth,\r
540 OUT UINT32 *pBaudrate,\r
541 OUT UINT32 *pInputHertz,\r
542 OUT UINT32 *pUartPciAddr\r
fce4ecd9
MM
543 )\r
544{\r
63bdd27a 545 struct cb_serial *CbSerial;\r
11e058ec
GD
546\r
547 CbSerial = FindCbTag (0, CB_TAG_SERIAL);\r
63bdd27a 548 if (CbSerial == NULL) {\r
11e058ec 549 CbSerial = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_SERIAL);\r
63bdd27a 550 }\r
11e058ec 551\r
63bdd27a 552 if (CbSerial == NULL) {\r
11e058ec 553 return RETURN_NOT_FOUND;\r
63bdd27a 554 }\r
11e058ec 555\r
63bdd27a 556 if (pRegBase != NULL) {\r
11e058ec 557 *pRegBase = CbSerial->baseaddr;\r
63bdd27a 558 }\r
11e058ec 559\r
2d90b74d 560 if (pRegWidth != NULL) {\r
561 *pRegWidth = CbSerial->regwidth;\r
562 }\r
563\r
63bdd27a 564 if (pRegAccessType != NULL) {\r
11e058ec 565 *pRegAccessType = CbSerial->type;\r
63bdd27a 566 }\r
11e058ec 567\r
63bdd27a 568 if (pBaudrate != NULL) {\r
11e058ec 569 *pBaudrate = CbSerial->baud;\r
63bdd27a 570 }\r
11e058ec 571\r
2d90b74d 572 if (pInputHertz != NULL) {\r
573 *pInputHertz = CbSerial->input_hertz;\r
574 }\r
575\r
576 if (pUartPciAddr != NULL) {\r
577 *pUartPciAddr = CbSerial->uart_pci_addr;\r
578 }\r
579\r
11e058ec 580 return RETURN_SUCCESS;\r
fce4ecd9
MM
581}\r
582\r
583/**\r
584 Search for the coreboot table header\r
585\r
586 @param Level Level of the search depth\r
587 @param HeaderPtr Pointer to the pointer of coreboot table header\r
588\r
589 @retval RETURN_SUCCESS Successfully find the coreboot table header .\r
590 @retval RETURN_NOT_FOUND Failed to find the coreboot table header .\r
591\r
592**/\r
593RETURN_STATUS\r
594CbParseGetCbHeader (\r
63bdd27a
GD
595 IN UINTN Level,\r
596 OUT VOID **HeaderPtr\r
fce4ecd9
MM
597 )\r
598{\r
11e058ec 599 UINTN Index;\r
63bdd27a 600 VOID *TempPtr;\r
11e058ec 601\r
63bdd27a 602 if (HeaderPtr == NULL) {\r
11e058ec 603 return RETURN_NOT_FOUND;\r
63bdd27a 604 }\r
11e058ec
GD
605\r
606 TempPtr = NULL;\r
607 for (Index = 0; Index < Level; Index++) {\r
608 TempPtr = FindCbTag (TempPtr, CB_TAG_FORWARD);\r
63bdd27a 609 if (TempPtr == NULL) {\r
11e058ec 610 break;\r
63bdd27a 611 }\r
11e058ec
GD
612 }\r
613\r
614 if ((Index >= Level) && (TempPtr != NULL)) {\r
615 *HeaderPtr = TempPtr;\r
616 return RETURN_SUCCESS;\r
617 }\r
618\r
619 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
620}\r
621\r
622/**\r
623 Find the video frame buffer information\r
624\r
625 @param pFbInfo Pointer to the FRAME_BUFFER_INFO structure\r
626\r
627 @retval RETURN_SUCCESS Successfully find the video frame buffer information.\r
628 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information .\r
629\r
630**/\r
631RETURN_STATUS\r
632CbParseFbInfo (\r
63bdd27a 633 OUT FRAME_BUFFER_INFO *pFbInfo\r
fce4ecd9
MM
634 )\r
635{\r
63bdd27a 636 struct cb_framebuffer *CbFbRec;\r
11e058ec 637\r
63bdd27a 638 if (pFbInfo == NULL) {\r
11e058ec 639 return RETURN_INVALID_PARAMETER;\r
63bdd27a 640 }\r
11e058ec
GD
641\r
642 CbFbRec = FindCbTag (0, CB_TAG_FRAMEBUFFER);\r
63bdd27a 643 if (CbFbRec == NULL) {\r
11e058ec 644 CbFbRec = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_FRAMEBUFFER);\r
63bdd27a 645 }\r
11e058ec 646\r
63bdd27a 647 if (CbFbRec == NULL) {\r
11e058ec 648 return RETURN_NOT_FOUND;\r
63bdd27a 649 }\r
11e058ec 650\r
63bdd27a
GD
651 DEBUG ((EFI_D_INFO, "Found coreboot video frame buffer information\n"));\r
652 DEBUG ((EFI_D_INFO, "physical_address: 0x%lx\n", CbFbRec->physical_address));\r
653 DEBUG ((EFI_D_INFO, "x_resolution: 0x%x\n", CbFbRec->x_resolution));\r
654 DEBUG ((EFI_D_INFO, "y_resolution: 0x%x\n", CbFbRec->y_resolution));\r
655 DEBUG ((EFI_D_INFO, "bits_per_pixel: 0x%x\n", CbFbRec->bits_per_pixel));\r
656 DEBUG ((EFI_D_INFO, "bytes_per_line: 0x%x\n", CbFbRec->bytes_per_line));\r
657\r
658 DEBUG ((EFI_D_INFO, "red_mask_size: 0x%x\n", CbFbRec->red_mask_size));\r
659 DEBUG ((EFI_D_INFO, "red_mask_pos: 0x%x\n", CbFbRec->red_mask_pos));\r
660 DEBUG ((EFI_D_INFO, "green_mask_size: 0x%x\n", CbFbRec->green_mask_size));\r
661 DEBUG ((EFI_D_INFO, "green_mask_pos: 0x%x\n", CbFbRec->green_mask_pos));\r
662 DEBUG ((EFI_D_INFO, "blue_mask_size: 0x%x\n", CbFbRec->blue_mask_size));\r
663 DEBUG ((EFI_D_INFO, "blue_mask_pos: 0x%x\n", CbFbRec->blue_mask_pos));\r
664 DEBUG ((EFI_D_INFO, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));\r
665 DEBUG ((EFI_D_INFO, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));\r
11e058ec
GD
666\r
667 pFbInfo->LinearFrameBuffer = CbFbRec->physical_address;\r
fce4ecd9
MM
668 pFbInfo->HorizontalResolution = CbFbRec->x_resolution;\r
669 pFbInfo->VerticalResolution = CbFbRec->y_resolution;\r
670 pFbInfo->BitsPerPixel = CbFbRec->bits_per_pixel;\r
671 pFbInfo->BytesPerScanLine = (UINT16)CbFbRec->bytes_per_line;\r
672 pFbInfo->Red.Mask = (1 << CbFbRec->red_mask_size) - 1;\r
673 pFbInfo->Red.Position = CbFbRec->red_mask_pos;\r
674 pFbInfo->Green.Mask = (1 << CbFbRec->green_mask_size) - 1;\r
675 pFbInfo->Green.Position = CbFbRec->green_mask_pos;\r
676 pFbInfo->Blue.Mask = (1 << CbFbRec->blue_mask_size) - 1;\r
677 pFbInfo->Blue.Position = CbFbRec->blue_mask_pos;\r
678 pFbInfo->Reserved.Mask = (1 << CbFbRec->reserved_mask_size) - 1;\r
11e058ec 679 pFbInfo->Reserved.Position = CbFbRec->reserved_mask_pos;\r
fce4ecd9 680\r
11e058ec
GD
681 return RETURN_SUCCESS;\r
682}\r
fce4ecd9 683\r