3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include "HobGeneration.h"
25 #define ACPI_RSD_PTR 0x2052545020445352LL
26 #define MPS_PTR SIGNATURE_32('_','M','P','_')
27 #define SMBIOS_PTR SIGNATURE_32('_','S','M','_')
29 #define EBDA_BASE_ADDRESS 0x40E
40 // First Seach 0x0e0000 - 0x0fffff for RSD Ptr
42 for (Address
= 0xe0000; Address
< 0xfffff; Address
+= 0x10) {
43 if (*(UINT64
*)(Address
) == ACPI_RSD_PTR
) {
44 return (VOID
*)Address
;
52 Address
= (*(UINT16
*)(UINTN
)(EBDA_BASE_ADDRESS
)) << 4;
53 for (Index
= 0; Index
< 0x400 ; Index
+= 16) {
54 if (*(UINT64
*)(Address
+ Index
) == ACPI_RSD_PTR
) {
55 return (VOID
*)Address
;
69 // First Seach 0x0f0000 - 0x0fffff for SMBIOS Ptr
71 for (Address
= 0xf0000; Address
< 0xfffff; Address
+= 0x10) {
72 if (*(UINT32
*)(Address
) == SMBIOS_PTR
) {
73 return (VOID
*)Address
;
88 // First Seach 0x0e0000 - 0x0fffff for MPS Ptr
90 for (Address
= 0xe0000; Address
< 0xfffff; Address
+= 0x10) {
91 if (*(UINT32
*)(Address
) == MPS_PTR
) {
92 return (VOID
*)Address
;
100 Address
= (*(UINT16
*)(UINTN
)(EBDA_BASE_ADDRESS
)) << 4;
101 for (Index
= 0; Index
< 0x400 ; Index
+= 16) {
102 if (*(UINT32
*)(Address
+ Index
) == MPS_PTR
) {
103 return (VOID
*)Address
;
118 UINT8 ExtendedChecksum
;
131 UINT32 CreatorRevision
;
132 } DESCRIPTION_HEADER
;
135 DESCRIPTION_HEADER Header
;
140 DESCRIPTION_HEADER Header
;
145 UINT8 Address_Space_ID
;
146 UINT8 Register_Bit_Width
;
147 UINT8 Register_Bit_Offset
;
150 } GADDRESS_STRUCTURE
;
158 DESCRIPTION_HEADER
**FoundTable
164 DESCRIPTION_HEADER
*Table
;
168 EntryCount
= (Rsdt
->Header
.Length
- sizeof (DESCRIPTION_HEADER
)) / sizeof(UINT32
);
170 EntryPtr
= &Rsdt
->Entry
;
171 for (Index
= 0; Index
< EntryCount
; Index
++, EntryPtr
++) {
172 Table
= (DESCRIPTION_HEADER
*)((UINTN
)(*EntryPtr
));
173 if (Table
->Signature
== Signature
) {
186 DESCRIPTION_HEADER
**FoundTable
194 DESCRIPTION_HEADER
*Table
;
198 EntryCount
= (Xsdt
->Header
.Length
- sizeof (DESCRIPTION_HEADER
)) / sizeof(UINT64
);
200 BasePtr
= (UINTN
)(&(Xsdt
->Entry
));
201 for (Index
= 0; Index
< EntryCount
; Index
++) {
202 CopyMem (&EntryPtr
, (VOID
*)(BasePtr
+ Index
* sizeof(UINT64
)), sizeof(UINT64
));
203 Table
= (DESCRIPTION_HEADER
*)((UINTN
)(EntryPtr
));
204 if (Table
->Signature
== Signature
) {
215 IN HOB_TEMPLATE
*Hob
,
219 DESCRIPTION_HEADER
*AcpiTable
;
227 // Check ACPI2.0 table
229 if ((int)Hob
->Acpi20
.Table
!= -1) {
230 Rsdp
= (RSDP_TABLE
*)(UINTN
)Hob
->Acpi20
.Table
;
231 Rsdt
= (RSDT_TABLE
*)(UINTN
)Rsdp
->RsdtAddress
;
233 if ((Rsdp
->Revision
>= 2) && (Rsdp
->XsdtAddress
< (UINT64
)(UINTN
)-1)) {
234 Xsdt
= (XSDT_TABLE
*)(UINTN
)Rsdp
->XsdtAddress
;
240 ScanTableInXSDT (Xsdt
, Signature
, &AcpiTable
);
245 if ((AcpiTable
== NULL
) && (Rsdt
!= NULL
)) {
246 ScanTableInRSDT (Rsdt
, Signature
, &AcpiTable
);
251 // Check ACPI1.0 table
253 if ((AcpiTable
== NULL
) && ((int)Hob
->Acpi
.Table
!= -1)) {
254 Rsdp
= (RSDP_TABLE
*)(UINTN
)Hob
->Acpi
.Table
;
255 Rsdt
= (RSDT_TABLE
*)(UINTN
)Rsdp
->RsdtAddress
;
260 ScanTableInRSDT (Rsdt
, Signature
, &AcpiTable
);
268 //#define MCFG_SIGNATURE 0x4746434D
269 #define MCFG_SIGNATURE SIGNATURE_32 ('M', 'C', 'F', 'G')
272 UINT16 PciSegmentGroupNumber
;
273 UINT8 StartBusNumber
;
278 #define FADT_SIGNATURE SIGNATURE_32 ('F', 'A', 'C', 'P')
280 DESCRIPTION_HEADER Header
;
281 UINT32 FIRMWARE_CTRL
;
284 UINT8 Preferred_PM_Profile
;
316 UINT16 IAPC_BOOT_ARCH
;
319 GADDRESS_STRUCTURE RESET_REG
;
321 UINT8 Reserved_129
[3];
322 UINT64 X_FIRMWARE_CTRL
;
324 GADDRESS_STRUCTURE X_PM1a_EVT_BLK
;
325 GADDRESS_STRUCTURE X_PM1b_EVT_BLK
;
326 GADDRESS_STRUCTURE X_PM1a_CNT_BLK
;
327 GADDRESS_STRUCTURE X_PM1b_CNT_BLK
;
328 GADDRESS_STRUCTURE X_PM2_CNT_BLK
;
329 GADDRESS_STRUCTURE X_PM_TMR_BLK
;
330 GADDRESS_STRUCTURE X_GPE0_BLK
;
331 GADDRESS_STRUCTURE X_GPE1_BLK
;
341 DESCRIPTION_HEADER
*McfgTable
;
342 MCFG_STRUCTURE
*Mcfg
;
346 McfgTable
= FindAcpiPtr (Hob
, MCFG_SIGNATURE
);
347 if (McfgTable
== NULL
) {
351 Mcfg
= (MCFG_STRUCTURE
*)((UINTN
)McfgTable
+ sizeof(DESCRIPTION_HEADER
) + sizeof(UINT64
));
352 McfgCount
= (McfgTable
->Length
- sizeof(DESCRIPTION_HEADER
) - sizeof(UINT64
)) / sizeof(MCFG_STRUCTURE
);
355 // Fill PciExpress info on Hob
356 // Note: Only for 1st segment
358 for (Index
= 0; Index
< McfgCount
; Index
++) {
359 if (Mcfg
[Index
].PciSegmentGroupNumber
== 0) {
360 Hob
->PciExpress
.PciExpressBaseAddressInfo
.PciExpressBaseAddress
= Mcfg
[Index
].BaseAddress
;
374 EFI_ACPI_DESCRIPTION
*AcpiDescription
;
376 Fadt
= FindAcpiPtr (Hob
, FADT_SIGNATURE
);
381 AcpiDescription
= &Hob
->AcpiInfo
.AcpiDescription
;
383 // Fill AcpiDescription according to FADT
384 // Currently, only for PM_TMR
386 AcpiDescription
->PM_TMR_LEN
= Fadt
->PM_TMR_LEN
;
387 AcpiDescription
->TMR_VAL_EXT
= (UINT8
)((Fadt
->Flags
& 0x100) != 0);
388 if ((Fadt
->Header
.Revision
>= 3) && (Fadt
->Header
.Length
>= sizeof(FADT_TABLE
))) {
390 &AcpiDescription
->PM_TMR_BLK
,
392 sizeof(GADDRESS_STRUCTURE
)
395 &AcpiDescription
->RESET_REG
,
397 sizeof(GADDRESS_STRUCTURE
)
399 AcpiDescription
->RESET_VALUE
= Fadt
->RESET_VALUE
;
401 if (AcpiDescription
->PM_TMR_BLK
.Address
== 0) {
402 AcpiDescription
->PM_TMR_BLK
.Address
= Fadt
->PM_TMR_BLK
;
403 AcpiDescription
->PM_TMR_BLK
.AddressSpaceId
= ACPI_ADDRESS_ID_IO
;
404 AcpiDescription
->PM_TMR_BLK
.RegisterBitWidth
= (UINT8
) ((AcpiDescription
->TMR_VAL_EXT
== 0) ? 24 : 32);
411 PrepareHobLegacyTable (
415 CHAR8 PrintBuffer
[256];
417 Hob
->Acpi
.Table
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)FindAcpiRsdPtr ();
418 AsciiSPrint (PrintBuffer
, 256, "\nAcpiTable=0x%x ", (UINT32
)(UINTN
)Hob
->Acpi
.Table
);
419 PrintString (PrintBuffer
);
420 Hob
->Acpi20
.Table
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)FindAcpiRsdPtr ();
421 Hob
->Smbios
.Table
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)FindSMBIOSPtr ();
422 AsciiSPrint (PrintBuffer
, 256, "SMBIOS Table=0x%x ", (UINT32
)(UINTN
)Hob
->Smbios
.Table
);
423 PrintString (PrintBuffer
);
424 Hob
->Mps
.Table
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)FindMPSPtr ();
425 AsciiSPrint (PrintBuffer
, 256, "MPS Table=0x%x\n", (UINT32
)(UINTN
)Hob
->Mps
.Table
);
426 PrintString (PrintBuffer
);
428 PrepareMcfgTable (Hob
);
430 PrepareFadtTable (Hob
);