]>
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 | |
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 | |
271d8cd7 | 21 | #include <Library/IoLib.h>\r |
fce4ecd9 MM |
22 | #include <Library/CbParseLib.h>\r |
23 | \r | |
24 | #include <IndustryStandard/Acpi.h>\r | |
25 | \r | |
26 | #include "Coreboot.h"\r | |
27 | \r | |
fce4ecd9 | 28 | \r |
63bdd27a GD |
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 | |
2d90b74d | 37 | UINT64\r |
63bdd27a GD |
38 | cb_unpack64 (\r |
39 | IN struct cbuint64 val\r | |
40 | )\r | |
fce4ecd9 | 41 | {\r |
5451fff4 | 42 | return LShiftU64 (val.hi, 32) | val.lo;\r |
fce4ecd9 MM |
43 | }\r |
44 | \r | |
63bdd27a GD |
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 | |
fce4ecd9 MM |
56 | UINT16\r |
57 | CbCheckSum16 (\r | |
58 | IN UINT16 *Buffer,\r | |
59 | IN UINTN Length\r | |
60 | )\r | |
61 | {\r | |
11e058ec GD |
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 | |
fce4ecd9 MM |
83 | }\r |
84 | \r | |
63bdd27a GD |
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 | |
fce4ecd9 | 97 | VOID *\r |
3176d84f | 98 | EFIAPI\r |
fce4ecd9 | 99 | FindCbTag (\r |
63bdd27a | 100 | IN VOID *Start,\r |
fce4ecd9 MM |
101 | IN UINT32 Tag\r |
102 | )\r | |
103 | {\r | |
104 | struct cb_header *Header;\r | |
105 | struct cb_record *Record;\r | |
11e058ec GD |
106 | UINT8 *TmpPtr;\r |
107 | UINT8 *TagPtr;\r | |
108 | UINTN Idx;\r | |
fce4ecd9 | 109 | UINT16 CheckSum;\r |
11e058ec | 110 | \r |
fce4ecd9 MM |
111 | Header = NULL;\r |
112 | TmpPtr = (UINT8 *)Start;\r | |
113 | for (Idx = 0; Idx < 4096; Idx += 16, TmpPtr += 16) {\r | |
63bdd27a | 114 | Header = (struct cb_header *)TmpPtr;\r |
fce4ecd9 MM |
115 | if (Header->signature == CB_HEADER_SIGNATURE) {\r |
116 | break;\r | |
117 | }\r | |
118 | }\r | |
11e058ec | 119 | \r |
63bdd27a | 120 | if (Idx >= 4096) {\r |
11e058ec | 121 | return NULL;\r |
63bdd27a | 122 | }\r |
11e058ec | 123 | \r |
63bdd27a | 124 | if ((Header == NULL) || (Header->table_bytes == 0)) {\r |
fce4ecd9 | 125 | return NULL;\r |
63bdd27a | 126 | }\r |
11e058ec | 127 | \r |
fce4ecd9 MM |
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 | |
11e058ec GD |
133 | DEBUG ((EFI_D_ERROR, "Invalid coreboot table header checksum\n"));\r |
134 | return NULL;\r | |
135 | }\r | |
136 | \r | |
fce4ecd9 MM |
137 | CheckSum = CbCheckSum16 ((UINT16 *)(TmpPtr + sizeof (*Header)), Header->table_bytes);\r |
138 | if (CheckSum != Header->table_checksum) {\r | |
11e058ec GD |
139 | DEBUG ((EFI_D_ERROR, "Incorrect checksum of all the coreboot table entries\n"));\r |
140 | return NULL;\r | |
fce4ecd9 | 141 | }\r |
11e058ec | 142 | \r |
fce4ecd9 MM |
143 | TagPtr = NULL;\r |
144 | TmpPtr += Header->header_bytes;\r | |
145 | for (Idx = 0; Idx < Header->table_entries; Idx++) {\r | |
11e058ec | 146 | Record = (struct cb_record *)TmpPtr;\r |
fce4ecd9 MM |
147 | if (Record->tag == CB_TAG_FORWARD) {\r |
148 | TmpPtr = (VOID *)(UINTN)((struct cb_forward *)(UINTN)Record)->forward;\r | |
63bdd27a | 149 | if (Tag == CB_TAG_FORWARD) {\r |
fce4ecd9 | 150 | return TmpPtr;\r |
63bdd27a | 151 | } else {\r |
fce4ecd9 | 152 | return FindCbTag (TmpPtr, Tag);\r |
63bdd27a | 153 | }\r |
11e058ec | 154 | }\r |
fce4ecd9 MM |
155 | if (Record->tag == Tag) {\r |
156 | TagPtr = TmpPtr;\r | |
157 | break;\r | |
158 | }\r | |
11e058ec | 159 | TmpPtr += Record->size;\r |
fce4ecd9 | 160 | }\r |
11e058ec | 161 | \r |
fce4ecd9 MM |
162 | return TagPtr;\r |
163 | }\r | |
164 | \r | |
63bdd27a GD |
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 | |
fce4ecd9 | 179 | RETURN_STATUS\r |
3176d84f | 180 | EFIAPI\r |
11e058ec | 181 | FindCbMemTable (\r |
165c0059 GD |
182 | IN struct cbmem_root *Root,\r |
183 | IN UINT32 TableId,\r | |
184 | OUT VOID **pMemTable,\r | |
185 | OUT UINT32 *pMemTableSize\r | |
11e058ec GD |
186 | )\r |
187 | {\r | |
165c0059 GD |
188 | UINTN Idx;\r |
189 | BOOLEAN IsImdEntry;\r | |
190 | struct cbmem_entry *Entries;\r | |
11e058ec | 191 | \r |
165c0059 GD |
192 | if ((Root == NULL) || (pMemTable == NULL)) {\r |
193 | return RETURN_INVALID_PARAMETER;\r | |
194 | }\r | |
165c0059 GD |
195 | //\r |
196 | // Check if the entry is CBMEM or IMD\r | |
197 | // and handle them separately\r | |
198 | //\r | |
63bdd27a | 199 | Entries = Root->entries;\r |
165c0059 GD |
200 | if (Entries[0].magic == CBMEM_ENTRY_MAGIC) {\r |
201 | IsImdEntry = FALSE;\r | |
202 | } else {\r | |
63bdd27a | 203 | Entries = (struct cbmem_entry *)((struct imd_root *)Root)->entries;\r |
165c0059 GD |
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 | |
11e058ec | 221 | \r |
2d90b74d | 222 | DEBUG ((EFI_D_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",\r |
223 | TableId, *pMemTable, Entries[Idx].size));\r | |
11e058ec | 224 | return RETURN_SUCCESS;\r |
fce4ecd9 MM |
225 | }\r |
226 | }\r | |
11e058ec GD |
227 | \r |
228 | return RETURN_NOT_FOUND;\r | |
fce4ecd9 MM |
229 | }\r |
230 | \r | |
231 | \r | |
232 | /**\r | |
233 | Acquire the memory information from the coreboot table in memory.\r | |
234 | \r | |
2d90b74d | 235 | @param MemInfoCallback The callback routine\r |
236 | @param pParam Pointer to the callback routine parameter\r | |
fce4ecd9 MM |
237 | \r |
238 | @retval RETURN_SUCCESS Successfully find out the memory information.\r | |
fce4ecd9 MM |
239 | @retval RETURN_NOT_FOUND Failed to find the memory information.\r |
240 | \r | |
241 | **/\r | |
242 | RETURN_STATUS\r | |
3176d84f | 243 | EFIAPI\r |
fce4ecd9 | 244 | CbParseMemoryInfo (\r |
2d90b74d | 245 | IN CB_MEM_INFO_CALLBACK MemInfoCallback,\r |
246 | IN VOID *pParam\r | |
fce4ecd9 MM |
247 | )\r |
248 | {\r | |
63bdd27a GD |
249 | struct cb_memory *rec;\r |
250 | struct cb_memory_range *Range;\r | |
fce4ecd9 MM |
251 | UINT64 Start;\r |
252 | UINT64 Size;\r | |
11e058ec GD |
253 | UINTN Index;\r |
254 | \r | |
11e058ec GD |
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 | 266 | \r |
11e058ec GD |
267 | for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r |
268 | Range = MEM_RANGE_PTR(rec, Index);\r | |
fce4ecd9 MM |
269 | Start = cb_unpack64(Range->start);\r |
270 | Size = cb_unpack64(Range->size);\r | |
63bdd27a | 271 | DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",\r |
11e058ec GD |
272 | Index, Start, Start + Size - 1, Range->type));\r |
273 | \r | |
2d90b74d | 274 | MemInfoCallback (Start, Size, Range->type, pParam);\r |
fce4ecd9 | 275 | }\r |
11e058ec | 276 | \r |
11e058ec | 277 | return RETURN_SUCCESS;\r |
fce4ecd9 MM |
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 | |
293 | RETURN_STATUS\r | |
3176d84f | 294 | EFIAPI\r |
fce4ecd9 | 295 | CbParseCbMemTable (\r |
63bdd27a GD |
296 | IN UINT32 TableId,\r |
297 | OUT VOID **pMemTable,\r | |
298 | OUT UINT32 *pMemTableSize\r | |
fce4ecd9 MM |
299 | )\r |
300 | {\r | |
63bdd27a GD |
301 | struct cb_memory *rec;\r |
302 | struct cb_memory_range *Range;\r | |
fce4ecd9 MM |
303 | UINT64 Start;\r |
304 | UINT64 Size;\r | |
11e058ec GD |
305 | UINTN Index;\r |
306 | \r | |
63bdd27a | 307 | if (pMemTable == NULL) {\r |
11e058ec | 308 | return RETURN_INVALID_PARAMETER;\r |
63bdd27a | 309 | }\r |
11e058ec GD |
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 | |
63bdd27a | 316 | if (rec == NULL) {\r |
11e058ec | 317 | rec = (struct cb_memory *)FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_MEMORY);\r |
63bdd27a | 318 | }\r |
11e058ec | 319 | \r |
63bdd27a | 320 | if (rec == NULL) {\r |
11e058ec | 321 | return RETURN_NOT_FOUND;\r |
63bdd27a | 322 | }\r |
11e058ec GD |
323 | \r |
324 | for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r | |
325 | Range = MEM_RANGE_PTR(rec, Index);\r | |
fce4ecd9 MM |
326 | Start = cb_unpack64(Range->start);\r |
327 | Size = cb_unpack64(Range->size);\r | |
11e058ec | 328 | \r |
fce4ecd9 | 329 | if ((Range->type == CB_MEM_TABLE) && (Start > 0x1000)) {\r |
11e058ec GD |
330 | if (FindCbMemTable ((struct cbmem_root *)(UINTN)(Start + Size - DYN_CBMEM_ALIGN_SIZE), TableId, pMemTable, pMemTableSize) == RETURN_SUCCESS)\r |
331 | return RETURN_SUCCESS;\r | |
fce4ecd9 MM |
332 | }\r |
333 | }\r | |
11e058ec GD |
334 | \r |
335 | return RETURN_NOT_FOUND;\r | |
fce4ecd9 MM |
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 | |
350 | RETURN_STATUS\r | |
3176d84f | 351 | EFIAPI\r |
fce4ecd9 | 352 | CbParseAcpiTable (\r |
63bdd27a GD |
353 | OUT VOID **pMemTable,\r |
354 | OUT UINT32 *pMemTableSize\r | |
fce4ecd9 MM |
355 | )\r |
356 | {\r | |
1e6c931b | 357 | return CbParseCbMemTable (SIGNATURE_32 ('I', 'P', 'C', 'A'), pMemTable, pMemTableSize);\r |
fce4ecd9 MM |
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 | |
371 | RETURN_STATUS\r | |
3176d84f | 372 | EFIAPI\r |
fce4ecd9 | 373 | CbParseSmbiosTable (\r |
63bdd27a GD |
374 | OUT VOID **pMemTable,\r |
375 | OUT UINT32 *pMemTableSize\r | |
fce4ecd9 MM |
376 | )\r |
377 | {\r | |
11e058ec | 378 | return CbParseCbMemTable (SIGNATURE_32 ('T', 'B', 'M', 'S'), pMemTable, pMemTableSize);\r |
fce4ecd9 MM |
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 | |
05de9ab2 GD |
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 | |
fce4ecd9 MM |
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 | |
395 | RETURN_STATUS\r | |
3176d84f | 396 | EFIAPI\r |
fce4ecd9 | 397 | CbParseFadtInfo (\r |
63bdd27a GD |
398 | OUT UINTN *pPmCtrlReg,\r |
399 | OUT UINTN *pPmTimerReg,\r | |
400 | OUT UINTN *pResetReg,\r | |
05de9ab2 GD |
401 | OUT UINTN *pResetValue,\r |
402 | OUT UINTN *pPmEvtReg,\r | |
403 | OUT UINTN *pPmGpeEnReg\r | |
fce4ecd9 MM |
404 | )\r |
405 | {\r | |
63bdd27a GD |
406 | EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;\r |
407 | EFI_ACPI_DESCRIPTION_HEADER *Rsdt;\r | |
408 | UINT32 *Entry32;\r | |
fce4ecd9 | 409 | UINTN Entry32Num;\r |
63bdd27a GD |
410 | EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;\r |
411 | EFI_ACPI_DESCRIPTION_HEADER *Xsdt;\r | |
412 | UINT64 *Entry64;\r | |
fce4ecd9 | 413 | UINTN Entry64Num;\r |
11e058ec GD |
414 | UINTN Idx;\r |
415 | RETURN_STATUS Status;\r | |
416 | \r | |
417 | Rsdp = NULL;\r | |
418 | Status = RETURN_SUCCESS;\r | |
419 | \r | |
2e1fffce | 420 | Status = CbParseAcpiTable ((VOID **)&Rsdp, NULL);\r |
63bdd27a | 421 | if (RETURN_ERROR(Status)) {\r |
11e058ec | 422 | return Status;\r |
63bdd27a | 423 | }\r |
11e058ec | 424 | \r |
63bdd27a | 425 | if (Rsdp == NULL) {\r |
11e058ec | 426 | return RETURN_NOT_FOUND;\r |
63bdd27a | 427 | }\r |
11e058ec | 428 | \r |
63bdd27a GD |
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 | |
11e058ec GD |
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 | |
63bdd27a | 442 | if (pPmCtrlReg != NULL) {\r |
11e058ec | 443 | *pPmCtrlReg = Fadt->Pm1aCntBlk;\r |
63bdd27a GD |
444 | }\r |
445 | DEBUG ((EFI_D_INFO, "PmCtrl Reg 0x%x\n", Fadt->Pm1aCntBlk));\r | |
11e058ec | 446 | \r |
63bdd27a | 447 | if (pPmTimerReg != NULL) {\r |
11e058ec | 448 | *pPmTimerReg = Fadt->PmTmrBlk;\r |
63bdd27a GD |
449 | }\r |
450 | DEBUG ((EFI_D_INFO, "PmTimer Reg 0x%x\n", Fadt->PmTmrBlk));\r | |
11e058ec | 451 | \r |
63bdd27a | 452 | if (pResetReg != NULL) {\r |
11e058ec | 453 | *pResetReg = (UINTN)Fadt->ResetReg.Address;\r |
63bdd27a GD |
454 | }\r |
455 | DEBUG ((EFI_D_INFO, "Reset Reg 0x%lx\n", Fadt->ResetReg.Address));\r | |
11e058ec | 456 | \r |
63bdd27a | 457 | if (pResetValue != NULL) {\r |
11e058ec | 458 | *pResetValue = Fadt->ResetValue;\r |
63bdd27a GD |
459 | }\r |
460 | DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r | |
11e058ec | 461 | \r |
2d90b74d | 462 | if (pPmEvtReg != NULL) {\r |
05de9ab2 GD |
463 | *pPmEvtReg = Fadt->Pm1aEvtBlk;\r |
464 | DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r | |
465 | }\r | |
466 | \r | |
2d90b74d | 467 | if (pPmGpeEnReg != NULL) {\r |
05de9ab2 GD |
468 | *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r |
469 | DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r | |
470 | }\r | |
471 | \r | |
2d90b74d | 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 | |
271d8cd7 BY |
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 | |
11e058ec GD |
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 | |
2d90b74d | 545 | if (pPmEvtReg != NULL) {\r |
05de9ab2 GD |
546 | *pPmEvtReg = Fadt->Pm1aEvtBlk;\r |
547 | DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r | |
548 | }\r | |
549 | \r | |
2d90b74d | 550 | if (pPmGpeEnReg != NULL) {\r |
05de9ab2 GD |
551 | *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r |
552 | DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r | |
2d90b74d | 553 | }\r |
11e058ec GD |
554 | return RETURN_SUCCESS;\r |
555 | }\r | |
556 | }\r | |
557 | }\r | |
558 | \r | |
559 | return RETURN_NOT_FOUND;\r | |
fce4ecd9 MM |
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 | |
2d90b74d | 567 | @param pRegWidth Pointer to the register width in bytes\r |
fce4ecd9 | 568 | @param pBaudrate Pointer to the serial port baudrate\r |
2d90b74d | 569 | @param pInputHertz Pointer to the input clock frequency\r |
570 | @param pUartPciAddr Pointer to the UART PCI bus, dev and func address\r | |
fce4ecd9 MM |
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 | |
576 | RETURN_STATUS\r | |
3176d84f | 577 | EFIAPI\r |
fce4ecd9 | 578 | CbParseSerialInfo (\r |
63bdd27a GD |
579 | OUT UINT32 *pRegBase,\r |
580 | OUT UINT32 *pRegAccessType,\r | |
2d90b74d | 581 | OUT UINT32 *pRegWidth,\r |
582 | OUT UINT32 *pBaudrate,\r | |
583 | OUT UINT32 *pInputHertz,\r | |
584 | OUT UINT32 *pUartPciAddr\r | |
fce4ecd9 MM |
585 | )\r |
586 | {\r | |
63bdd27a | 587 | struct cb_serial *CbSerial;\r |
11e058ec GD |
588 | \r |
589 | CbSerial = FindCbTag (0, CB_TAG_SERIAL);\r | |
63bdd27a | 590 | if (CbSerial == NULL) {\r |
11e058ec | 591 | CbSerial = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_SERIAL);\r |
63bdd27a | 592 | }\r |
11e058ec | 593 | \r |
63bdd27a | 594 | if (CbSerial == NULL) {\r |
11e058ec | 595 | return RETURN_NOT_FOUND;\r |
63bdd27a | 596 | }\r |
11e058ec | 597 | \r |
63bdd27a | 598 | if (pRegBase != NULL) {\r |
11e058ec | 599 | *pRegBase = CbSerial->baseaddr;\r |
63bdd27a | 600 | }\r |
11e058ec | 601 | \r |
2d90b74d | 602 | if (pRegWidth != NULL) {\r |
603 | *pRegWidth = CbSerial->regwidth;\r | |
604 | }\r | |
605 | \r | |
63bdd27a | 606 | if (pRegAccessType != NULL) {\r |
11e058ec | 607 | *pRegAccessType = CbSerial->type;\r |
63bdd27a | 608 | }\r |
11e058ec | 609 | \r |
63bdd27a | 610 | if (pBaudrate != NULL) {\r |
11e058ec | 611 | *pBaudrate = CbSerial->baud;\r |
63bdd27a | 612 | }\r |
11e058ec | 613 | \r |
2d90b74d | 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 | |
11e058ec | 622 | return RETURN_SUCCESS;\r |
fce4ecd9 MM |
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 | |
635 | RETURN_STATUS\r | |
3176d84f | 636 | EFIAPI\r |
fce4ecd9 | 637 | CbParseGetCbHeader (\r |
63bdd27a GD |
638 | IN UINTN Level,\r |
639 | OUT VOID **HeaderPtr\r | |
fce4ecd9 MM |
640 | )\r |
641 | {\r | |
11e058ec | 642 | UINTN Index;\r |
63bdd27a | 643 | VOID *TempPtr;\r |
11e058ec | 644 | \r |
63bdd27a | 645 | if (HeaderPtr == NULL) {\r |
11e058ec | 646 | return RETURN_NOT_FOUND;\r |
63bdd27a | 647 | }\r |
11e058ec GD |
648 | \r |
649 | TempPtr = NULL;\r | |
650 | for (Index = 0; Index < Level; Index++) {\r | |
651 | TempPtr = FindCbTag (TempPtr, CB_TAG_FORWARD);\r | |
63bdd27a | 652 | if (TempPtr == NULL) {\r |
11e058ec | 653 | break;\r |
63bdd27a | 654 | }\r |
11e058ec GD |
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 | |
fce4ecd9 MM |
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 | |
674 | RETURN_STATUS\r | |
3176d84f | 675 | EFIAPI\r |
fce4ecd9 | 676 | CbParseFbInfo (\r |
63bdd27a | 677 | OUT FRAME_BUFFER_INFO *pFbInfo\r |
fce4ecd9 MM |
678 | )\r |
679 | {\r | |
63bdd27a | 680 | struct cb_framebuffer *CbFbRec;\r |
11e058ec | 681 | \r |
63bdd27a | 682 | if (pFbInfo == NULL) {\r |
11e058ec | 683 | return RETURN_INVALID_PARAMETER;\r |
63bdd27a | 684 | }\r |
11e058ec GD |
685 | \r |
686 | CbFbRec = FindCbTag (0, CB_TAG_FRAMEBUFFER);\r | |
63bdd27a | 687 | if (CbFbRec == NULL) {\r |
11e058ec | 688 | CbFbRec = FindCbTag ((VOID *)(UINTN)PcdGet32 (PcdCbHeaderPointer), CB_TAG_FRAMEBUFFER);\r |
63bdd27a | 689 | }\r |
11e058ec | 690 | \r |
63bdd27a | 691 | if (CbFbRec == NULL) {\r |
11e058ec | 692 | return RETURN_NOT_FOUND;\r |
63bdd27a | 693 | }\r |
11e058ec | 694 | \r |
63bdd27a GD |
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 | |
11e058ec GD |
710 | \r |
711 | pFbInfo->LinearFrameBuffer = CbFbRec->physical_address;\r | |
fce4ecd9 MM |
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 | |
11e058ec | 723 | pFbInfo->Reserved.Position = CbFbRec->reserved_mask_pos;\r |
fce4ecd9 | 724 | \r |
11e058ec GD |
725 | return RETURN_SUCCESS;\r |
726 | }\r | |
fce4ecd9 | 727 | \r |