]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/Library/CbParseLib/CbParseLib.c
CorebootModulePkg: Get power management register addresses.
[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
05de9ab2
GD
398 @param pPmEvtReg Pointer to the address of power management event register\r
399 @param pPmGpeEnReg Pointer to the address of power management GPE enable register\r
fce4ecd9
MM
400\r
401 @retval RETURN_SUCCESS Successfully find out all the required fadt information.\r
402 @retval RETURN_NOT_FOUND Failed to find the fadt table.\r
403\r
404**/\r
405RETURN_STATUS\r
406CbParseFadtInfo (\r
63bdd27a
GD
407 OUT UINTN *pPmCtrlReg,\r
408 OUT UINTN *pPmTimerReg,\r
409 OUT UINTN *pResetReg,\r
05de9ab2
GD
410 OUT UINTN *pResetValue,\r
411 OUT UINTN *pPmEvtReg,\r
412 OUT UINTN *pPmGpeEnReg\r
fce4ecd9
MM
413 )\r
414{\r
63bdd27a
GD
415 EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;\r
416 EFI_ACPI_DESCRIPTION_HEADER *Rsdt;\r
417 UINT32 *Entry32;\r
fce4ecd9 418 UINTN Entry32Num;\r
63bdd27a
GD
419 EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;\r
420 EFI_ACPI_DESCRIPTION_HEADER *Xsdt;\r
421 UINT64 *Entry64;\r
fce4ecd9 422 UINTN Entry64Num;\r
11e058ec
GD
423 UINTN Idx;\r
424 RETURN_STATUS Status;\r
425\r
426 Rsdp = NULL;\r
427 Status = RETURN_SUCCESS;\r
428\r
2e1fffce 429 Status = CbParseAcpiTable ((VOID **)&Rsdp, NULL);\r
63bdd27a 430 if (RETURN_ERROR(Status)) {\r
11e058ec 431 return Status;\r
63bdd27a 432 }\r
11e058ec 433\r
63bdd27a 434 if (Rsdp == NULL) {\r
11e058ec 435 return RETURN_NOT_FOUND;\r
63bdd27a 436 }\r
11e058ec 437\r
63bdd27a
GD
438 DEBUG ((EFI_D_INFO, "Find Rsdp at %p\n", Rsdp));\r
439 DEBUG ((EFI_D_INFO, "Find Rsdt 0x%x, Xsdt 0x%lx\n", Rsdp->RsdtAddress, Rsdp->XsdtAddress));\r
11e058ec
GD
440\r
441 //\r
442 // Search Rsdt First\r
443 //\r
444 Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->RsdtAddress);\r
445 if (Rsdt != NULL) {\r
446 Entry32 = (UINT32 *)(Rsdt + 1);\r
447 Entry32Num = (Rsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 2;\r
448 for (Idx = 0; Idx < Entry32Num; Idx++) {\r
449 if (*(UINT32 *)(UINTN)(Entry32[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
450 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry32[Idx]);\r
63bdd27a 451 if (pPmCtrlReg != NULL) {\r
11e058ec 452 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
63bdd27a
GD
453 }\r
454 DEBUG ((EFI_D_INFO, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
11e058ec 455\r
63bdd27a 456 if (pPmTimerReg != NULL) {\r
11e058ec 457 *pPmTimerReg = Fadt->PmTmrBlk;\r
63bdd27a
GD
458 }\r
459 DEBUG ((EFI_D_INFO, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
11e058ec 460\r
63bdd27a 461 if (pResetReg != NULL) {\r
11e058ec 462 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
63bdd27a
GD
463 }\r
464 DEBUG ((EFI_D_INFO, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
11e058ec 465\r
63bdd27a 466 if (pResetValue != NULL) {\r
11e058ec 467 *pResetValue = Fadt->ResetValue;\r
63bdd27a
GD
468 }\r
469 DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r
11e058ec 470\r
05de9ab2
GD
471 if (pPmEvtReg != NULL) { \r
472 *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
473 DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
474 }\r
475\r
476 if (pPmGpeEnReg != NULL) { \r
477 *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
478 DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
479 }\r
480\r
11e058ec
GD
481 return RETURN_SUCCESS;\r
482 }\r
483 }\r
484 }\r
485\r
486 //\r
487 // Search Xsdt Second\r
488 //\r
489 Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)(Rsdp->XsdtAddress);\r
490 if (Xsdt != NULL) {\r
491 Entry64 = (UINT64 *)(Xsdt + 1);\r
492 Entry64Num = (Xsdt->Length - sizeof(EFI_ACPI_DESCRIPTION_HEADER)) >> 3;\r
493 for (Idx = 0; Idx < Entry64Num; Idx++) {\r
494 if (*(UINT32 *)(UINTN)(Entry64[Idx]) == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {\r
495 Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)(Entry64[Idx]);\r
496 if (pPmCtrlReg)\r
497 *pPmCtrlReg = Fadt->Pm1aCntBlk;\r
498 DEBUG ((EFI_D_ERROR, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r
499\r
500 if (pPmTimerReg)\r
501 *pPmTimerReg = Fadt->PmTmrBlk;\r
502 DEBUG ((EFI_D_ERROR, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r
503\r
504 if (pResetReg)\r
505 *pResetReg = (UINTN)Fadt->ResetReg.Address;\r
506 DEBUG ((EFI_D_ERROR, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r
507\r
508 if (pResetValue)\r
509 *pResetValue = Fadt->ResetValue;\r
510 DEBUG ((EFI_D_ERROR, "Reset Value 0x%x\n", Fadt->ResetValue));\r
511\r
05de9ab2
GD
512 if (pPmEvtReg != NULL) { \r
513 *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
514 DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
515 }\r
516\r
517 if (pPmGpeEnReg != NULL) { \r
518 *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
519 DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
520 } \r
11e058ec
GD
521 return RETURN_SUCCESS;\r
522 }\r
523 }\r
524 }\r
525\r
526 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
527}\r
528\r
529/**\r
530 Find the serial port information\r
531\r
532 @param pRegBase Pointer to the base address of serial port registers\r
533 @param pRegAccessType Pointer to the access type of serial port registers\r
534 @param pBaudrate Pointer to the serial port baudrate\r
535\r
536 @retval RETURN_SUCCESS Successfully find the serial port information.\r
537 @retval RETURN_NOT_FOUND Failed to find the serial port information .\r
538\r
539**/\r
540RETURN_STATUS\r
541CbParseSerialInfo (\r
63bdd27a
GD
542 OUT UINT32 *pRegBase,\r
543 OUT UINT32 *pRegAccessType,\r
544 OUT UINT32 *pBaudrate\r
fce4ecd9
MM
545 )\r
546{\r
63bdd27a 547 struct cb_serial *CbSerial;\r
11e058ec
GD
548\r
549 CbSerial = FindCbTag (0, CB_TAG_SERIAL);\r
63bdd27a 550 if (CbSerial == NULL) {\r
11e058ec 551 CbSerial = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_SERIAL);\r
63bdd27a 552 }\r
11e058ec 553\r
63bdd27a 554 if (CbSerial == NULL) {\r
11e058ec 555 return RETURN_NOT_FOUND;\r
63bdd27a 556 }\r
11e058ec 557\r
63bdd27a 558 if (pRegBase != NULL) {\r
11e058ec 559 *pRegBase = CbSerial->baseaddr;\r
63bdd27a 560 }\r
11e058ec 561\r
63bdd27a 562 if (pRegAccessType != NULL) {\r
11e058ec 563 *pRegAccessType = CbSerial->type;\r
63bdd27a 564 }\r
11e058ec 565\r
63bdd27a 566 if (pBaudrate != NULL) {\r
11e058ec 567 *pBaudrate = CbSerial->baud;\r
63bdd27a 568 }\r
11e058ec
GD
569\r
570 return RETURN_SUCCESS;\r
fce4ecd9
MM
571}\r
572\r
573/**\r
574 Search for the coreboot table header\r
575\r
576 @param Level Level of the search depth\r
577 @param HeaderPtr Pointer to the pointer of coreboot table header\r
578\r
579 @retval RETURN_SUCCESS Successfully find the coreboot table header .\r
580 @retval RETURN_NOT_FOUND Failed to find the coreboot table header .\r
581\r
582**/\r
583RETURN_STATUS\r
584CbParseGetCbHeader (\r
63bdd27a
GD
585 IN UINTN Level,\r
586 OUT VOID **HeaderPtr\r
fce4ecd9
MM
587 )\r
588{\r
11e058ec 589 UINTN Index;\r
63bdd27a 590 VOID *TempPtr;\r
11e058ec 591\r
63bdd27a 592 if (HeaderPtr == NULL) {\r
11e058ec 593 return RETURN_NOT_FOUND;\r
63bdd27a 594 }\r
11e058ec
GD
595\r
596 TempPtr = NULL;\r
597 for (Index = 0; Index < Level; Index++) {\r
598 TempPtr = FindCbTag (TempPtr, CB_TAG_FORWARD);\r
63bdd27a 599 if (TempPtr == NULL) {\r
11e058ec 600 break;\r
63bdd27a 601 }\r
11e058ec
GD
602 }\r
603\r
604 if ((Index >= Level) && (TempPtr != NULL)) {\r
605 *HeaderPtr = TempPtr;\r
606 return RETURN_SUCCESS;\r
607 }\r
608\r
609 return RETURN_NOT_FOUND;\r
fce4ecd9
MM
610}\r
611\r
612/**\r
613 Find the video frame buffer information\r
614\r
615 @param pFbInfo Pointer to the FRAME_BUFFER_INFO structure\r
616\r
617 @retval RETURN_SUCCESS Successfully find the video frame buffer information.\r
618 @retval RETURN_NOT_FOUND Failed to find the video frame buffer information .\r
619\r
620**/\r
621RETURN_STATUS\r
622CbParseFbInfo (\r
63bdd27a 623 OUT FRAME_BUFFER_INFO *pFbInfo\r
fce4ecd9
MM
624 )\r
625{\r
63bdd27a 626 struct cb_framebuffer *CbFbRec;\r
11e058ec 627\r
63bdd27a 628 if (pFbInfo == NULL) {\r
11e058ec 629 return RETURN_INVALID_PARAMETER;\r
63bdd27a 630 }\r
11e058ec
GD
631\r
632 CbFbRec = FindCbTag (0, CB_TAG_FRAMEBUFFER);\r
63bdd27a 633 if (CbFbRec == NULL) {\r
11e058ec 634 CbFbRec = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_FRAMEBUFFER);\r
63bdd27a 635 }\r
11e058ec 636\r
63bdd27a 637 if (CbFbRec == NULL) {\r
11e058ec 638 return RETURN_NOT_FOUND;\r
63bdd27a 639 }\r
11e058ec 640\r
63bdd27a
GD
641 DEBUG ((EFI_D_INFO, "Found coreboot video frame buffer information\n"));\r
642 DEBUG ((EFI_D_INFO, "physical_address: 0x%lx\n", CbFbRec->physical_address));\r
643 DEBUG ((EFI_D_INFO, "x_resolution: 0x%x\n", CbFbRec->x_resolution));\r
644 DEBUG ((EFI_D_INFO, "y_resolution: 0x%x\n", CbFbRec->y_resolution));\r
645 DEBUG ((EFI_D_INFO, "bits_per_pixel: 0x%x\n", CbFbRec->bits_per_pixel));\r
646 DEBUG ((EFI_D_INFO, "bytes_per_line: 0x%x\n", CbFbRec->bytes_per_line));\r
647\r
648 DEBUG ((EFI_D_INFO, "red_mask_size: 0x%x\n", CbFbRec->red_mask_size));\r
649 DEBUG ((EFI_D_INFO, "red_mask_pos: 0x%x\n", CbFbRec->red_mask_pos));\r
650 DEBUG ((EFI_D_INFO, "green_mask_size: 0x%x\n", CbFbRec->green_mask_size));\r
651 DEBUG ((EFI_D_INFO, "green_mask_pos: 0x%x\n", CbFbRec->green_mask_pos));\r
652 DEBUG ((EFI_D_INFO, "blue_mask_size: 0x%x\n", CbFbRec->blue_mask_size));\r
653 DEBUG ((EFI_D_INFO, "blue_mask_pos: 0x%x\n", CbFbRec->blue_mask_pos));\r
654 DEBUG ((EFI_D_INFO, "reserved_mask_size: 0x%x\n", CbFbRec->reserved_mask_size));\r
655 DEBUG ((EFI_D_INFO, "reserved_mask_pos: 0x%x\n", CbFbRec->reserved_mask_pos));\r
11e058ec
GD
656\r
657 pFbInfo->LinearFrameBuffer = CbFbRec->physical_address;\r
fce4ecd9
MM
658 pFbInfo->HorizontalResolution = CbFbRec->x_resolution;\r
659 pFbInfo->VerticalResolution = CbFbRec->y_resolution;\r
660 pFbInfo->BitsPerPixel = CbFbRec->bits_per_pixel;\r
661 pFbInfo->BytesPerScanLine = (UINT16)CbFbRec->bytes_per_line;\r
662 pFbInfo->Red.Mask = (1 << CbFbRec->red_mask_size) - 1;\r
663 pFbInfo->Red.Position = CbFbRec->red_mask_pos;\r
664 pFbInfo->Green.Mask = (1 << CbFbRec->green_mask_size) - 1;\r
665 pFbInfo->Green.Position = CbFbRec->green_mask_pos;\r
666 pFbInfo->Blue.Mask = (1 << CbFbRec->blue_mask_size) - 1;\r
667 pFbInfo->Blue.Position = CbFbRec->blue_mask_pos;\r
668 pFbInfo->Reserved.Mask = (1 << CbFbRec->reserved_mask_size) - 1;\r
11e058ec 669 pFbInfo->Reserved.Position = CbFbRec->reserved_mask_pos;\r
fce4ecd9 670\r
11e058ec
GD
671 return RETURN_SUCCESS;\r
672}\r
fce4ecd9 673\r