88 Commits

Author SHA1 Message Date
Adrien Thierry
ad00518399 Platform/RaspberryPi: fix pci DT node address in SyncPcie()
To make sure the XHCI controller does not get reset by Linux in DT mode,
we remove its pci parent node from the device tree. However, the pci
node address has been updated in the Raspberry Pi 4 device tree [1] and
no longer matches the one we are trying to remove in SyncPcie(). This
results in the XHCI controller actually being reset by Linux, which
leads to errors during USB initialization:

[    3.563963] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    3.569538] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 1
[    3.577452] xhci_hcd 0000:01:00.0: hcc params 0x002841eb hci version 0x100 quirks 0x0000040000000890
[    3.587725] xhci_hcd 0000:01:00.0: xHCI Host Controller
[    3.593115] xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 2
[    3.600693] xhci_hcd 0000:01:00.0: Host supports USB 3.0 SuperSpeed
[    3.608106] hub 1-0:1.0: USB hub found
[    3.612026] hub 1-0:1.0: 1 port detected
[    3.616819] hub 2-0:1.0: USB hub found
[    3.620726] hub 2-0:1.0: 4 ports detected
[    3.875902] usb 1-1: new high-speed USB device number 2 using xhci_hcd
[    4.008123] usb 1-1: device descriptor read/64, error -71
[    4.256088] usb 1-1: device descriptor read/64, error -71
[    4.495882] usb 1-1: new high-speed USB device number 3 using xhci_hcd
[    4.628111] usb 1-1: device descriptor read/64, error -71
[    4.872083] usb 1-1: device descriptor read/64, error -71
[    5.407888] usb 1-1: new high-speed USB device number 4 using xhci_hcd
[    6.023964] xhci_hcd 0000:01:00.0: Setup ERROR: setup address command for slot 1.
[    6.239977] xhci_hcd 0000:01:00.0: Setup ERROR: setup address command for slot 1.

This patch allows matching any address for the pci node, thus working
with both legacy and new device trees.

[1] https://lore.kernel.org/all/20210831125843.1233488-1-nsaenzju@redhat.com/

Fixes: efff29cdcd ("Platform/RaspberryPi: Always use non translating DMA in DT mode")
Signed-off-by: Adrien Thierry <athierry@redhat.com>
Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>
Tested-by: Jeremy Linton <jeremy.linton@arm.com>
2022-10-10 11:14:17 +02:00
Adrien Thierry
b0f3f90372 Platform/RaspberryPi: Add 'clock-frequency' property for miniuart
Describe the miniuart clock frequency in a _DSD property, so that it can
be read from the Linux driver [1]

The miniuart clock frequency is the core clock frequency on the
Raspberry Pi. It can be modified by the user using the 'core_freq'
property in the config.txt file. So, we fetch it from the underlying
Raspberry Pi firmware.

[1] https://lore.kernel.org/all/20220207232129.402882-1-athierry@redhat.com/

Signed-off-by: Adrien Thierry <athierry@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2022-02-08 17:54:47 +01:00
Jeremy Linton
af649f800e Platform/RaspberryPi: Normal memory should not be marked as uncached
The EFI spec seems to indicate that the EFI uncacheable attribute
should be mapped to device memory rather than normal-nc. This means
that the UEFI mem attribute for the >3G ram doesn't match the remainder
of the RAM in the machine.

So, lets remove the uncacheable attribute to make it more consistent.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2021-10-19 09:22:17 +02:00
Jeremy Linton
fd988a9e4e Platform/RaspberryPi: Expand locking to cover return data
It appears that the locking for many of the mailbox commands is
incorrect. All UEFI firmware calls to the RPi mailbox share a single
mDmaBuffer. That buffer is used to fill out the command passed to the
vc firmware, and record its response. The buffer is protected by
mMailboxLock, yet in many cases the mailbox response is copied from
the buffer after the lock has been released. This doesn't currently
appear to be causing any problems, but should be fixed anyway.

There are a couple other minor tweaks in this patch that are hard to
justify on their own, one is a bit of whitespace cleanup, and the
other is the addition of a debug message to print the returned clock
rate for the requested clock. This latter print would have immediatly
shown that the vc firmware was returning 0 as the emmc clock rate
rather than something reasonable.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-10-19 09:22:17 +02:00
Jeremy Linton
ee4be44e01 Platform/RaspberryPi: Fix vfr warning caused by two defaults
The build has been tossing a warning about having two defaults
for a while now, lets fix it.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-10-19 09:22:17 +02:00
Jeremy Linton
efff29cdcd Platform/RaspberryPi: Always use non translating DMA in DT mode
One of the many issues with the PCIe on this platform is its inbound
DMA is either constrained to the lower 3G, or on later SOC's a
translation may be used. That translation is problematic with some of
the OS's expected to boot on this platform. So, across the board a 3G
DMA limit is enforced during boot when in ACPI mode. This itself
causes problems because the later boards removed the SPI EEPROM used
by the onboard XHCI controller, instead favoring using a block of RAM
to load its firmware. Hence it is the lower level firmware's
responsibility via a mailbox call, to read the bridge
translation/configuration before telling the XHCI controller where it
can find its firmware.

Everything is great in ACPI land. Now it appears that Linux after
reprogramming the bridge to match the DT (when using a translation)
can't actually get the XHCI/quirk/reset to function. Apparently,
because the firmware only reads the bridge configuration the first
time its called(?), or the kernel reset sequence isn't correct. Worse,
with just the DMA ranges corrected, the XHCI/QUIRK itself then causes
the controller to start having what appear to be DMA issues.

Lets simplify the situation and make all DT's provided by this
firmware have a 3G DMA limit on the PCIe bus. Then remove the ability
for Linux/etc to trigger the quirk by remove the DT node attaching the
reset controller to the XHCI. The latter seems somewhat questionable,
since the DT/PCIe host bridge driver is doing what appears to be a
PERST which might then require a firmware reload, but at the
moment seems to work without.

The first part of this patch also appears to fix a problem with
OpenBSD which interprets the DT as describing how the firmware
has configured the device, and makes no attempt to reconfigure it.
Hence the newer SOC's implementing a translation fail to boot
since the DT being passed to the OS doesn't match the translation
the firmware has setup.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
2021-10-19 09:22:05 +02:00
Jeremy Linton
fc4eb72f88 Platform/RaspberryPi: Add PCIe SSDT
Since we plan on toggling between XHCI and PCI the PCI
root needs to be in its own SSDT. This is all thats needed
of UEFI. The SMC conduit is provided directly to the running
OS. When the OS detects this PCIe port on a machine without
a MCFG it attempts to connect to the SMC conduit. The RPi
definition doesn't have any power mgmt, and only provides
a description of the root port.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Tested-by: Jared McNeill <jmcneill@invisible.ca>
2021-08-22 15:54:45 +02:00
Jeremy Linton
5cf33c71cb Platform/RaspberryPi: Break XHCI into its own SSDT
Lets prepare to switch between XHCI and PCI by moving
the XHCI definition into its own SSDT. That way we can
select it based on the menu settings. The resource
producer/consumer flag is also corrected.

Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Tested-by: Jared McNeill <jmcneill@invisible.ca>
2021-08-22 15:54:38 +02:00
Jeremy Linton
63a54c6f40 Platform/RaspberryPi: Add XHCI/PCI selection menu
Arm has standardized a PCI SMC conduit that can be used
to access the PCI config space in a standardized way. This
functionality doesn't yet exist in many OS/Distro's. Lets
add another advanced config item that allows the user
to toggle between presenting the XHCI on the base RPi4
as a platform device, or presenting this newer PCIe
conduit. The CM4 doesn't have an attached XHCI controller
soldered to the PCIe, so PCIe mode is the default.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-By: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Tested-by: Jared McNeill <jmcneill@invisible.ca>
2021-08-22 15:54:28 +02:00
Grzegorz Bernacki
2f0188b56e Revert "Platform/RaspberryPi: Setup option for disabling Fast Boot"
This reverts commit efdc159ef7.

This commit is not longer required as Boot Discovery Policy has been
implemented for Raspberry Pi.

Signed-off-by: Grzegorz Bernacki <gjb@semihalf.com>
Reviewed-by: Sunny Wang <sunny.wang@arm.com>
Reviewed-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
2021-08-03 18:37:04 +02:00
Sunny Wang
086a3a3ce6 Platform/RaspberryPi: Enable Bluetooth and UART in Windows OS
This change is based on edk2-platforms-raspberrypi-pl011-bth-noflow.diff
in https://github.com/worproject/RPi-Bluetooth-Testing/ with the
modifications and additional changes below for enabling Bluetooth
and serial port (Mini UART) in Windows IOT.
  - Remove RPIQ connection for BT_ON/OFF in Uart.asl because it is
    useless. The firmware already turns on the Bluetooth by default.
  - Move the GPIO pin muxing stuff from Uart.asl to ConfigDxe driver.

Testing Done:
  - Successfully booted Windows Windows 10 IOT (20279.1) on SD (made by
    WOR) with the RPi-Windows-Drivers release ver 0.5 downloaded from
    https://github.com/worproject/RPi-Windows-Drivers/releases
    and checked that both Bluetooth and serial port (Mini UART) can
    work fine.
  - Successfully booted VMware ESXi-Arm Fling v1.3 with only serial
    console connection (PL011 UART).

Signed-off-by: Sunny Wang <sunny.wang@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
2021-06-12 22:04:08 +02:00
Sunny Wang
ea709f165d Platform/RaspberryPi: Dynamically build UARTs info in ACPI
Changes:
  1. Add code to ConfigDxe driver and AcpiTables module to dynamically
     build either Mini UART or PL011 UART info in ACPI. This also fixes
     the issue discussed in https://github.com/pftf/RPi4/issues/118.
  2. Cleanup by moving duplicate Debug Port 2 table related defines and
     structures to a newly created header file (RpiDebugPort2Table.h).

Testing Done:
  - Booted to UEFI shell and use acpiview command to check the result of
    the different UART settings in config.txt (enabling either Mini UART
    or PL011) and SPCR, DBG2 tables and device BTH0 are dynamically
    changed as expected.

Signed-off-by: Sunny Wang <sunny.wang@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Tested-by: Pete Batard <pete@akeo.ie>
2021-06-12 22:02:25 +02:00
Jeremy Linton
09c5ab125b Platform/RaspberryPi: Invert emmc PIO/DMA selection
Now that we are doing SoC detection and adjusting the DMA
window it should be safe to turn DMA on by default.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
2021-05-12 14:21:02 +02:00
Sunny Wang
efdc159ef7 Platform/RaspberryPi: Setup option for disabling Fast Boot
This is a fix for https://github.com/pftf/RPi4/issues/114.

Changes:
  1. Add a setup option called BootPolicy and consume the setting
     during boot to decide whether to perform or skip ConnectAll.
  2. The Default setting is set to Full discovery because it is not
     worth enabling Fast boot by default on RaspberryPi systems.
     Enabling it just saves boot time about 1 second, but caused a
     lot of issues.

Testing Done:
  - Booted to Standalone UEFI shell on SD card and use drivers
    command to check the result with Fast Boot and Full discovery
    settings. Then, child/device handles are created as expected.

Note and to-do items:
  - The root cause looks like that boot loaders and some tools like
    grub and iPXE haven't supported selective connect/Fast boot.
    However, system firmware should still provide a setup option for
    user to enable Fast boot with old version boot loaders and tools,
    which is why we proposed this change. We will also report this
    issue to boot loader and tool vendors/open source GitHubs.
  - We will add more options for connecting specific type devices so
    that we can still have the shortest boot time for all use cases.

Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Link: https://github.com/pftf/RPi4/issues/144
Link: https://github.com/pftf/RPi4/issues/114
Signed-off-by: Sunny Wang <sunny.wang@arm.com>
Acked-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
2021-04-15 20:48:51 +02:00
René Treffer
2620e05c6f Platform/RaspberryPi: Fix dwc2 reset on raspberry pi boards
DwHcReset expects attributes as the second argument. A reset is
performed if the passed attribute is valued. However 0 is not a valid
attribute and will thus never cause a controller reset.

Passing EFI_USB_HC_RESET_HOST_CONTROLLER will reset the dwc2 controller
as expected.

This enables the USB 2.0 port of the raspberry compute module 4.

Reviewed-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Signed-off-by: René Treffer <treffer@measite.de>
2021-03-12 18:43:07 +01:00
Jeremy Linton
41b54dbb68 Platform/RaspberryPi: Only enable IORT when 3G limit is disabled.
The 3G limit, and the 2G IORT are intended to solve
the same linux problem. They limit PCI DMA operations
to the first 3G of RAM. Older linux kernels, as
used with RHEL/Centos, trigger an assertion*
when a DMA operation starts at a range that
doesn't fit within the 2G range specified by the IORT.

The simple solution is to only enable the IORT
when the 3G flag is disabled and there is more
than 3G installed.

* https://github.com/pftf/RPi4/issues/123

Fixes: dac891da5c ("Platform/RaspberryPi/AcpiTables: add a IORT ACPI table to limit XHCI DMA")
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-02-20 15:40:49 +01:00
Jeremy Linton
35f23fa784 Platform/RaspberryPi: User control of eMMC2 DMA
DMA translation on the eMMC2 vary based on SoC, and
this is made worse by the poor _DMA support in Linux.

For now the "safe" option is to simply run the eMMC2
controller in PIO mode. More advanced users or !Linux
operating systems may choose to enable this to gain
a perf boost.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-02-20 15:37:20 +01:00
Jeremy Linton
311ed3c790 Platform/RaspberryPi/Acpitables: Add eMMC2 device and tweak Arasan
The primary problem with the RPi's Arasan controller is
the lack of a meaningful capabilities register. With just
a sdhci-caps _DSD entry we can provide that information. It
can then be bound to the Linux sdhci_iproc driver which
already hardcodes the remaining controller bugs.

Further we have gotten BRCME88C approved as the HID
for the newer eMMC2 controller. So lets define an
ACPI object to describe it.

Of course both devices are sharing an interrupt so
we should also indicate that in the table as well.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-02-20 15:37:20 +01:00
Jeremy Linton
ac87b52041 Platform/RaspberryPi: Add Negative table check
Turns out its helpful to have a !PcdToken flag
that enables a DSDT/SSDT. That simplifies
both the emmc2 SSDT (it only installs when
!SdIsArasan) and later for the XHCI/PCIe switch
where we want to install one of two tables
depending on whether a single Pcd is set.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
2021-02-20 15:37:20 +01:00
Jeremy Linton
9dbca4ef91 Platform/RaspberryPi: Power up SD, and tweak GPIOs
It seems we should be powering up the SD cards, and possibly
the clocks as well to assure they are setup properly before
we attempt to access the controller.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
2021-01-08 10:43:19 +01:00
Jeremy Linton
a50f14a301 Platform/RaspberryPi/Arasan: Select the correct base frequency
The firmware reports the eMMC2 frequency with a slightly
different mailbox command, lets select the correct one
based on which controller we are binding to.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
2021-01-08 10:42:52 +01:00
Jeremy Linton
12bcc7f2c2 Platform/RaspberryPi/Arasan: Add write delay and voltage/clock config
The uboot and Linux drivers have notes that there is a clock domain crossing
problem that happens with back to back writes to the SD controllers on the
rpi. Its not clear if this is still applicable to the rpi4/eMMC2 but
it seems wise to add it.

Further, we need to assure that the card voltage is set to 3.3V, and
we should try and follow some of the SDHCI docs when it comes to
changing the clock.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
2021-01-08 10:42:45 +01:00
Jeremy Linton
d2e58540ad Platform/RaspberryPi: Split MMC register definitions
The current MMC (really SDHCI) definitions are tied to the
Arasan controller. As we intend to reuse the definitions lets
make the base address configurable when the driver loads.

This assumes we won't ever want to run both the eMMC2
and Arasan SDHCI controller at the same time.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
2021-01-08 10:42:36 +01:00
Jeremy Linton
fe59663f0a Platform/RaspberryPi: Add further mailbox helpers
Lets add some further mailbox helpers and convert the existing
RpiFirmwareSetLed into a generic SetGpio() function.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
2021-01-08 10:42:13 +01:00
Samer El-Haj-Mahmoud
f8958b86e8 Platform/RaspberryPi : Fix Usb2Hc SCT issues
REF: https://github.com/pftf/RPi4/issues/88

Fix SCT failures in the RPi USB2_HC_PROTOCOL by adding input parameter
validation in Reset(), SetState(), GetState(), and
SyncInterruptTransfer()

Signed-off-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
2021-01-06 14:38:01 +01:00