Skip to content

Commit 5779a50

Browse files
andreiwpbatard
authored andcommitted
Platform/RPi4: Add XHCI and MCFG ACPI tables
Since the RPi4 PCIe host bridge is not ECAM compliant, we cannot expose it as a host bridge to the OS via ACPI, so we add a dummy MCFG table. However, given the hardwired nature of this platform, we can expose the xHCI controller that is guaranteed to live at the base of the MMIO32 BAR window as a platform device directly. It should be noted that the xHCI table is not finalized at this stage, as Windows xHCI support is still a major question mark. Signed-off-by: Pete Batard <pete@akeo.ie>
1 parent 62956e3 commit 5779a50

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Fadt.aslc
3030
Dbg2.aslc
3131
Gtdt.aslc
32+
Mcfg.aslc
3233
Dsdt.asl
3334
Csrt.aslc
3435
Spcr.aslc
@@ -39,6 +40,8 @@
3940
EmbeddedPkg/EmbeddedPkg.dec
4041
MdeModulePkg/MdeModulePkg.dec
4142
MdePkg/MdePkg.dec
43+
Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
44+
Silicon/Broadcom/Bcm283x/Bcm283x.dec
4245

4346
[FixedPcd]
4447
gArmTokenSpaceGuid.PcdArmArchTimerIntrNum
@@ -47,6 +50,8 @@
4750
gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum
4851
gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
4952
gArmTokenSpaceGuid.PcdGicDistributorBase
53+
gBcm27xxTokenSpaceGuid.PcdBcm27xxPciCpuMmioAdr
54+
gBcm27xxTokenSpaceGuid.PcdBcm27xxPciRegBase
5055
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
5156
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
5257
gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress

Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
2222
{
2323
include ("Sdhc.asl")
2424
include ("Pep.asl")
25+
include ("Xhci.asl")
2526

2627
Device (CPU0)
2728
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/** @file
2+
*
3+
* Memory Mapped Configuration Address Space table (MCFG)
4+
*
5+
* Copyright (c) 2019, Pete Batard <pete@akeo.ie>
6+
* Copyright (c) 2013-2015 Intel Corporation.
7+
*
8+
* SPDX-License-Identifier: BSD-2-Clause-Patent
9+
*
10+
**/
11+
12+
#include <IndustryStandard/Acpi.h>
13+
#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
14+
15+
#include "AcpiTables.h"
16+
17+
//
18+
// Multiple APIC Description Table
19+
//
20+
#pragma pack (1)
21+
22+
#define RPI_ACPI_OEM_MCFG_REVISION 0x00000001
23+
//
24+
// The Pi 4 is not ECAM compliant so, ideally, we would just skip populating
25+
// an allocation structure. However, GenFw throws 'MCFG length check failed'
26+
// when the number of allocation structures is zero, so we need at least one.
27+
//
28+
#define RPI_ACPI_ALLOCATION_STRUCTURE_COUNT 1
29+
30+
typedef struct {
31+
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER Header;
32+
EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE AllocationStructure[RPI_ACPI_ALLOCATION_STRUCTURE_COUNT];
33+
} EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE;
34+
35+
STATIC EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE Mcfg =
36+
{
37+
{
38+
//------------------------------------------------------------------------
39+
// ACPI Table Header
40+
//------------------------------------------------------------------------
41+
{
42+
EFI_ACPI_3_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
43+
sizeof (EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE),
44+
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION,
45+
0x00, // Checksum calculated at runtime.
46+
EFI_ACPI_OEM_ID, // OEMID is a 6 bytes long field "BC2836"
47+
EFI_ACPI_OEM_TABLE_ID, // OEM table identification(8 bytes long) "RPI4EDK2"
48+
EFI_ACPI_OEM_REVISION, // OEM revision number
49+
EFI_ACPI_CREATOR_ID, // ASL compiler vendor ID
50+
EFI_ACPI_CREATOR_REVISION // ASL compiler revision number
51+
},
52+
//------------------------------------------------------------------------
53+
// Reserved
54+
//------------------------------------------------------------------------
55+
0x0000000000000000, // Reserved
56+
},
57+
58+
//------------------------------------------------------------------------
59+
// MCFG specific fields
60+
//------------------------------------------------------------------------
61+
{
62+
{
63+
//
64+
// Using (-1) as the base address tells the OS to ignore it.
65+
//
66+
0xFFFFFFFFFFFFFFFFULL, // BaseAddress
67+
0x0000, // PciSegmentGroupNumber
68+
0x00, // StartBusNumber
69+
0x00, // EndBusNumber
70+
0x00000000 // Reserved
71+
}
72+
}
73+
};
74+
75+
#pragma pack()
76+
77+
//
78+
// Reference the table being generated to prevent the optimizer from removing
79+
// the data structure from the executable
80+
//
81+
VOID* CONST ReferenceAcpiTable = &Mcfg;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/** @file
2+
*
3+
* Copyright (c) 2019 Linaro, Limited. All rights reserved.
4+
* Copyright (c) 2019 Andrei Warkentin <andrey.warkentin@gmail.com>
5+
*
6+
* SPDX-License-Identifier: BSD-2-Clause-Patent
7+
*
8+
**/
9+
10+
#include <IndustryStandard/Bcm2711.h>
11+
12+
/*
13+
* The following can be used to remove parenthesis from
14+
* defined macros that the compiler complains about.
15+
*/
16+
#define _REMOVE_PAREN(...) __VA_ARGS__
17+
#define REMOVE_PAREN(x) _REMOVE_PAREN x
18+
19+
/*
20+
* According to UEFI boot log for the VLI device on Pi 4.
21+
*/
22+
#define XHCI_REG_LENGTH 0x1000
23+
24+
Device (SCB0) {
25+
Name (_HID, "ACPI0004")
26+
Name (_UID, 0x0)
27+
Name (_CCA, 0x0)
28+
29+
Method (_CRS, 0, Serialized) { // _CRS: Current Resource Settings
30+
/*
31+
* Container devices with _DMA must have _CRS, meaning SCB0
32+
* to provide all resources that XHC0 consumes (except
33+
* interrupts).
34+
*/
35+
Name (RBUF, ResourceTemplate () {
36+
QWordMemory(ResourceProducer,
37+
,
38+
MinFixed,
39+
MaxFixed,
40+
NonCacheable,
41+
ReadWrite,
42+
0x0,
43+
0xAAAA, // MIN
44+
0xBBBA, // MAX
45+
0x0,
46+
0x1111, // LEN
47+
,
48+
,
49+
MMIO
50+
)
51+
})
52+
CreateQwordField (RBUF, MMIO._MIN, MMBA)
53+
CreateQwordField (RBUF, MMIO._MAX, MMBE)
54+
CreateQwordField (RBUF, MMIO._LEN, MMLE)
55+
Store (REMOVE_PAREN(PCIE_CPU_MMIO_WINDOW), MMBA)
56+
Store (REMOVE_PAREN(PCIE_CPU_MMIO_WINDOW), MMBE)
57+
Store (XHCI_REG_LENGTH, MMLE)
58+
Add (MMBA, MMLE, MMBE)
59+
Return (RBUF)
60+
}
61+
62+
Name (_DMA, ResourceTemplate() {
63+
/*
64+
* XHC0 is limited to DMA to first 3GB. Note this
65+
* only applies to PCIe, not GENET or other devices
66+
* next to the A72.
67+
*/
68+
QWordMemory(ResourceConsumer,
69+
,
70+
MinFixed,
71+
MaxFixed,
72+
NonCacheable,
73+
ReadWrite,
74+
0x0,
75+
0x0, // MIN
76+
0xbfffffff, // MAX
77+
0x0, // TRA
78+
0xc0000000, // LEN
79+
,
80+
,
81+
)
82+
})
83+
84+
Device (XHC0)
85+
{
86+
Name (_HID, "11063483") // _HID: Hardware ID
87+
Name (_CID, "PNP0D10") // _CID: Hardware ID
88+
Name (_UID, 0x0) // _UID: Unique ID
89+
Name (_CCA, 0x0) // _CCA: Cache Coherency Attribute
90+
91+
Method (_CRS, 0, Serialized) { // _CRS: Current Resource Settings
92+
Name (RBUF, ResourceTemplate () {
93+
QWordMemory(ResourceConsumer,
94+
,
95+
MinFixed,
96+
MaxFixed,
97+
NonCacheable,
98+
ReadWrite,
99+
0x0,
100+
0xAAAA, // MIN
101+
0xBBBA, // MAX
102+
0x0,
103+
0x1111, // LEN
104+
,
105+
,
106+
MMIO
107+
)
108+
Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive, ,, ) {
109+
175
110+
}
111+
})
112+
CreateQwordField (RBUF, MMIO._MIN, MMBA)
113+
CreateQwordField (RBUF, MMIO._MAX, MMBE)
114+
CreateQwordField (RBUF, MMIO._LEN, MMLE)
115+
Store (REMOVE_PAREN(PCIE_CPU_MMIO_WINDOW), MMBA)
116+
Store (REMOVE_PAREN(PCIE_CPU_MMIO_WINDOW), MMBE)
117+
Store (XHCI_REG_LENGTH, MMLE)
118+
Add (MMBA, MMLE, MMBE)
119+
Return (RBUF)
120+
}
121+
122+
Method (_INI, 0, Serialized) {
123+
OperationRegion (PCFG, SystemMemory, REMOVE_PAREN(PCIE_REG_BASE) + PCIE_EXT_CFG_DATA, 0x1000)
124+
Field (PCFG, AnyAcc, NoLock, Preserve) {
125+
Offset (0),
126+
VNID, 16, // Vendor ID
127+
DVID, 16, // Device ID
128+
CMND, 16, // Command register
129+
STAT, 16, // Status register
130+
}
131+
132+
// Set command register to:
133+
// 1) decode MMIO (set bit 1)
134+
// 2) enable DMA (set bit 2)
135+
// 3) enable interrupts (clear bit 10)
136+
Debug = "xHCI enable"
137+
Store (0x6, CMND)
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)