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