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