From cc780563b58b849e002358eaccf4afabcc6065da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20B=C4=83l=C4=83nic=C4=83?= Date: Fri, 5 Jan 2024 19:30:54 +0200 Subject: [PATCH 13/16] =?UTF-8?q?=EF=BB=BFPlatform/RPi5:=20Add=20FDT=20sys?= =?UTF-8?q?tem=20table=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mario Bălănică --- Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c | 62 +++++++++------- .../RaspberryPi/Drivers/FdtDxe/FdtDxe.inf | 4 +- .../RPi5/Drivers/RpiPlatformDxe/ConfigTable.c | 17 +++++ .../Drivers/RpiPlatformDxe/RpiPlatformDxe.inf | 3 + .../RpiPlatformDxe/RpiPlatformDxeHii.uni | 12 +++- .../RpiPlatformDxe/RpiPlatformDxeHii.vfr | 71 ++++++++++++------- Platform/RaspberryPi/RPi5/RPi5.dsc | 11 ++- Platform/RaspberryPi/RPi5/RPi5.fdf | 2 +- 8 files changed, 125 insertions(+), 57 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c index fadf262f..5ad3c708 100644 --- a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c +++ b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c @@ -9,8 +9,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -22,6 +25,7 @@ STATIC VOID *mFdtImage; STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; +STATIC UINT32 mBoardRevision; STATIC EFI_STATUS @@ -461,9 +465,15 @@ FdtDxeInitialize ( (VOID**)&mFwProtocol); ASSERT_EFI_ERROR (Status); - FdtImage = (VOID*)(UINTN)PcdGet32 (PcdFdtBaseAddress); - Retval = fdt_check_header (FdtImage); - if (Retval != 0) { + Status = BoardInfoGetRevisionCode (&mBoardRevision); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Failed to get board revision code. Status=%r\n", + __func__, Status)); + } + + FdtImage = FdtPlatformGetBase (); + if (FdtImage == NULL) { /* * Any one of: * - Invalid config.txt device_tree_address (not PcdFdtBaseAddress) @@ -497,39 +507,41 @@ FdtDxeInitialize ( * These are all best-effort. */ - Status = SanitizePSCI (); - if (EFI_ERROR (Status)) { - Print (L"Failed to sanitize PSCI: %r\n", Status); - } - Status = CleanMemoryNodes (); if (EFI_ERROR (Status)) { - Print (L"Failed to clean memory nodes: %r\n", Status); + DEBUG ((DEBUG_ERROR, "Failed to clean memory nodes: %r\n", Status)); } Status = CleanSimpleFramebuffer (); if (EFI_ERROR (Status)) { - Print (L"Failed to clean frame buffer: %r\n", Status); + DEBUG ((DEBUG_ERROR, "Failed to clean frame buffer: %r\n", Status)); } - Status = FixEthernetAliases (); - if (EFI_ERROR (Status)) { - Print (L"Failed to fix ethernet aliases: %r\n", Status); - } + if (BoardRevisionGetModelFamily (mBoardRevision) < 5) { + Status = SanitizePSCI (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to sanitize PSCI: %r\n", Status)); + } - Status = UpdateMacAddress (); - if (EFI_ERROR (Status)) { - Print (L"Failed to update MAC address: %r\n", Status); - } + Status = FixEthernetAliases (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to fix ethernet aliases: %r\n", Status)); + } - Status = AddUsbCompatibleProperty (); - if (EFI_ERROR (Status)) { - Print (L"Failed to update USB compatible properties: %r\n", Status); - } + Status = UpdateMacAddress (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to update MAC address: %r\n", Status)); + } - SyncPcie (); - if (EFI_ERROR (Status)) { - Print (L"Failed to update PCIe address ranges: %r\n", Status); + Status = AddUsbCompatibleProperty (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to update USB compatible properties: %r\n", Status)); + } + + Status = SyncPcie (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to update PCIe address ranges: %r\n", Status)); + } } DEBUG ((DEBUG_INFO, "Installed devicetree at address %p\n", mFdtImage)); diff --git a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf index 90e138af..1ea2fe40 100644 --- a/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf +++ b/Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf @@ -27,9 +27,12 @@ [LibraryClasses] BaseLib + BoardInfoLib + BoardRevisionHelperLib DebugLib DxeServicesLib FdtLib + FdtPlatformLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint @@ -50,7 +53,6 @@ gBcm27xxTokenSpaceGuid.PcdBcm27xxPciBusMmioLen gBcm27xxTokenSpaceGuid.PcdBcm27xxPciCpuMmioAdr - [Pcd] gRaspberryPiTokenSpaceGuid.PcdSystemTableMode gRaspberryPiTokenSpaceGuid.PcdXhciReload diff --git a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/ConfigTable.c b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/ConfigTable.c index da86e2e0..9aadb325 100644 --- a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/ConfigTable.c +++ b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/ConfigTable.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "ConfigTable.h" @@ -108,6 +109,12 @@ ApplyConfigTableVariables ( { EFI_STATUS Status; + if (PcdGet32 (PcdSystemTableMode) != SYSTEM_TABLE_MODE_ACPI + && PcdGet32 (PcdSystemTableMode) != SYSTEM_TABLE_MODE_BOTH) { + // FDT is taken care of by FdtDxe. + return; + } + Status = LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile, NULL); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: Failed to install ACPI tables!\n")); @@ -128,6 +135,7 @@ SetupConfigTableVariables ( { EFI_STATUS Status; UINTN Size; + UINT32 Var32; AcpiSdCompatMode.Value = ACPI_SD_COMPAT_MODE_DEFAULT; AcpiSdLimitUhs.Value = ACPI_SD_LIMIT_UHS_DEFAULT; @@ -159,4 +167,13 @@ SetupConfigTableVariables ( &AcpiSdLimitUhs); ASSERT_EFI_ERROR (Status); } + + Size = sizeof (UINT32); + Status = gRT->GetVariable (L"SystemTableMode", + &gRpiPlatformFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + Status = PcdSet32S (PcdSystemTableMode, PcdGet32 (PcdSystemTableMode)); + ASSERT_EFI_ERROR (Status); + } } diff --git a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf index b1cb4303..6bb48c3f 100644 --- a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf +++ b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf @@ -48,6 +48,9 @@ gEfiAcpiSdtProtocolGuid ## CONSUMES gBrcmStbSdhciDeviceProtocolGuid ## PRODUCES +[Pcd] + gRaspberryPiTokenSpaceGuid.PcdSystemTableMode + [Depex] gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid diff --git a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.uni b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.uni index 7f362922..5cb460f6 100644 --- a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.uni +++ b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.uni @@ -17,10 +17,16 @@ /* * ACPI / Device Tree configuration */ -#string STR_CONFIG_TABLE_FORM_TITLE #language en-US "ACPI / Device Tree" -#string STR_CONFIG_TABLE_FORM_HELP #language en-US "Configure the ACPI and Device Tree system tables support." +#string STR_SYSTEM_TABLE_FORM_TITLE #language en-US "ACPI / Device Tree" +#string STR_SYSTEM_TABLE_FORM_HELP #language en-US "Configure the ACPI and Device Tree system tables support." -#string STR_CONFIG_TABLE_ACPI_SUBTITLE #language en-US "ACPI Configuration" +#string STR_SYSTEM_TABLE_MODE_PROMPT #language en-US "System Table Mode" +#string STR_SYSTEM_TABLE_MODE_HELP #language en-US "Choose what system tables to expose to the OS.\n\nACPI - provides basic hardware support (USB, SD) for most OS/kernel versions.\n\nDevice Tree - provides extensive hardware support specific to a kernel version.\nUEFI hands over the DTB and overlays passed by the VPU firmware, which reside in the boot partition.\n\nIf both are exposed, the OS will decide which one to use." +#string STR_SYSTEM_TABLE_MODE_ACPI #language en-US "ACPI" +#string STR_SYSTEM_TABLE_MODE_FDT #language en-US "Device Tree" +#string STR_SYSTEM_TABLE_MODE_ACPI_FDT #language en-US "Both" + +#string STR_SYSTEM_TABLE_ACPI_SUBTITLE #language en-US "ACPI Configuration" #string STR_ACPI_SD_SUBTITLE #language en-US "Broadcom SD Host Controller" diff --git a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.vfr b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.vfr index 65163f10..e5ee4b3e 100644 --- a/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.vfr +++ b/Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxeHii.vfr @@ -10,6 +10,7 @@ #include #include #include +#include #include "ConfigTable.h" @@ -19,15 +20,20 @@ formset help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP), classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID, + efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = SystemTableMode, + guid = RPI_PLATFORM_FORMSET_GUID; + efivarstore ACPI_SD_COMPAT_MODE_VARSTORE_DATA, - attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - name = AcpiSdCompatMode, - guid = RPI_PLATFORM_FORMSET_GUID; + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = AcpiSdCompatMode, + guid = RPI_PLATFORM_FORMSET_GUID; efivarstore ACPI_SD_LIMIT_UHS_VARSTORE_DATA, - attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - name = AcpiSdLimitUhs, - guid = RPI_PLATFORM_FORMSET_GUID; + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = AcpiSdLimitUhs, + guid = RPI_PLATFORM_FORMSET_GUID; form formid = 1, title = STRING_TOKEN(STR_FORM_SET_TITLE); @@ -36,32 +42,45 @@ formset subtitle text = STRING_TOKEN(STR_NULL_STRING); goto 0x1000, - prompt = STRING_TOKEN(STR_CONFIG_TABLE_FORM_TITLE), - help = STRING_TOKEN(STR_CONFIG_TABLE_FORM_HELP); + prompt = STRING_TOKEN(STR_SYSTEM_TABLE_FORM_TITLE), + help = STRING_TOKEN(STR_SYSTEM_TABLE_FORM_HELP); endform; form formid = 0x1000, - title = STRING_TOKEN(STR_CONFIG_TABLE_FORM_TITLE); + title = STRING_TOKEN(STR_SYSTEM_TABLE_FORM_TITLE); + + oneof varid = SystemTableMode.Mode, + prompt = STRING_TOKEN(STR_SYSTEM_TABLE_MODE_PROMPT), + help = STRING_TOKEN(STR_SYSTEM_TABLE_MODE_HELP), + flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, + default = SYSTEM_TABLE_MODE_ACPI, + option text = STRING_TOKEN(STR_SYSTEM_TABLE_MODE_ACPI), value = SYSTEM_TABLE_MODE_ACPI, flags = 0; + option text = STRING_TOKEN(STR_SYSTEM_TABLE_MODE_FDT), value = SYSTEM_TABLE_MODE_DT, flags = 0; + option text = STRING_TOKEN(STR_SYSTEM_TABLE_MODE_ACPI_FDT), value = SYSTEM_TABLE_MODE_BOTH, flags = 0; + endoneof; - subtitle text = STRING_TOKEN(STR_CONFIG_TABLE_ACPI_SUBTITLE); + suppressif (get(SystemTableMode.Mode) != SYSTEM_TABLE_MODE_ACPI AND get(SystemTableMode.Mode) != SYSTEM_TABLE_MODE_BOTH); + subtitle text = STRING_TOKEN(STR_NULL_STRING); + subtitle text = STRING_TOKEN(STR_SYSTEM_TABLE_ACPI_SUBTITLE); - subtitle text = STRING_TOKEN(STR_NULL_STRING); - subtitle text = STRING_TOKEN(STR_ACPI_SD_SUBTITLE); + subtitle text = STRING_TOKEN(STR_NULL_STRING); + subtitle text = STRING_TOKEN(STR_ACPI_SD_SUBTITLE); - oneof varid = AcpiSdCompatMode.Value, - prompt = STRING_TOKEN(STR_ACPI_SD_COMPAT_MODE_PROMPT), - help = STRING_TOKEN(STR_ACPI_SD_COMPAT_MODE_HELP), - flags = NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED, - default = ACPI_SD_COMPAT_MODE_DEFAULT, - option text = STRING_TOKEN(STR_ACPI_SD_COMPAT_BRCMSTB_BAYTRAIL), value = ACPI_SD_COMPAT_MODE_BRCMSTB_BAYTRAIL, flags = 0; - option text = STRING_TOKEN(STR_ACPI_SD_COMPAT_FULL_BAYTRAIL), value = ACPI_SD_COMPAT_MODE_FULL_BAYTRAIL, flags = 0; - endoneof; + oneof varid = AcpiSdCompatMode.Value, + prompt = STRING_TOKEN(STR_ACPI_SD_COMPAT_MODE_PROMPT), + help = STRING_TOKEN(STR_ACPI_SD_COMPAT_MODE_HELP), + flags = NUMERIC_SIZE_1 | INTERACTIVE | RESET_REQUIRED, + default = ACPI_SD_COMPAT_MODE_DEFAULT, + option text = STRING_TOKEN(STR_ACPI_SD_COMPAT_BRCMSTB_BAYTRAIL), value = ACPI_SD_COMPAT_MODE_BRCMSTB_BAYTRAIL, flags = 0; + option text = STRING_TOKEN(STR_ACPI_SD_COMPAT_FULL_BAYTRAIL), value = ACPI_SD_COMPAT_MODE_FULL_BAYTRAIL, flags = 0; + endoneof; - checkbox varid = AcpiSdLimitUhs.Value, - prompt = STRING_TOKEN(STR_ACPI_SD_LIMIT_UHS_PROMPT), - help = STRING_TOKEN(STR_ACPI_SD_LIMIT_UHS_HELP), - flags = CHECKBOX_DEFAULT | CHECKBOX_DEFAULT_MFG | RESET_REQUIRED, - default = ACPI_SD_LIMIT_UHS_DEFAULT, - endcheckbox; + checkbox varid = AcpiSdLimitUhs.Value, + prompt = STRING_TOKEN(STR_ACPI_SD_LIMIT_UHS_PROMPT), + help = STRING_TOKEN(STR_ACPI_SD_LIMIT_UHS_HELP), + flags = CHECKBOX_DEFAULT | CHECKBOX_DEFAULT_MFG | RESET_REQUIRED, + default = ACPI_SD_LIMIT_UHS_DEFAULT, + endcheckbox; + endif; endform; endformset; diff --git a/Platform/RaspberryPi/RPi5/RPi5.dsc b/Platform/RaspberryPi/RPi5/RPi5.dsc index 4f128fe0..63e86be3 100644 --- a/Platform/RaspberryPi/RPi5/RPi5.dsc +++ b/Platform/RaspberryPi/RPi5/RPi5.dsc @@ -474,6 +474,15 @@ # gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberryPiTokenSpaceGuid|0x0|0 + # + # Device Tree and ACPI selection. + # + # 0 - SYSTEM_TABLE_MODE_ACPI (default) + # 1 - SYSTEM_TABLE_MODE_BOTH + # 2 - SYSTEM_TABLE_MODE_DT + # + gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gRpiPlatformFormSetGuid|0x0|0 + # # Common UEFI ones. # @@ -569,7 +578,7 @@ ArmPkg/Drivers/ArmGic/ArmGicDxe.inf Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf - # Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf + Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf ArmPkg/Drivers/TimerDxe/TimerDxe.inf MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf MdeModulePkg/Universal/EbcDxe/EbcDxe.inf diff --git a/Platform/RaspberryPi/RPi5/RPi5.fdf b/Platform/RaspberryPi/RPi5/RPi5.fdf index 4a5a05f6..a00b3d98 100644 --- a/Platform/RaspberryPi/RPi5/RPi5.fdf +++ b/Platform/RaspberryPi/RPi5/RPi5.fdf @@ -215,7 +215,7 @@ READ_LOCK_STATUS = TRUE INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf INF Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf INF Platform/RaspberryPi/RPi5/Drivers/RpiPlatformDxe/RpiPlatformDxe.inf - # INF Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf + INF Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf -- 2.51.2