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