Skip to content

Commit

Permalink
RPi: allow selecting DT-only mode
Browse files Browse the repository at this point in the history
Today the Pies can be booted in a way where only ACPI is exposed,
or both ACPI and DT are exposed.

This adds one more mode - DT only, no ACPI. The target audience
is developers. When both are exposed, it's up to the OS to decide
which gets used, and that choice can differ between OSes,

Note: this does _not_ change defaults. Pi 3 still defaults to
ACPI + DT, while Pi 4 still defaults to ACPI only.

We don't really want to remove DT + ACPI mode - it is the default
on Pi 3, and removing it is bound to just annoy users - WoA and
NetBSD (voa UEFI) on Pi 3 only work with ACPI, while everything
else (Linux, FreeBSD) only work with DT. I'd make an analogy of
MPS and ACPI being exposed for the longest time ever together on
PCs.

Testing: OpenBSD on Pi 4 with DT-only and ACPI-only boots.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
Reviewed-by: Pete Batard <pete@akeo.ie>
  • Loading branch information
andreiw authored and Ard Biesheuvel committed May 11, 2020
1 parent e52345a commit d492639
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 29 deletions.
11 changes: 7 additions & 4 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ SetupVariables (
}

Size = sizeof (UINT32);
Status = gRT->GetVariable (L"OptDeviceTree",
Status = gRT->GetVariable (L"SystemTableMode",
&gConfigDxeFormSetGuid,
NULL, &Size, &Var32);
if (EFI_ERROR (Status)) {
PcdSet32 (PcdOptDeviceTree, PcdGet32 (PcdOptDeviceTree));
PcdSet32 (PcdSystemTableMode, PcdGet32 (PcdSystemTableMode));
}

Size = sizeof (UINT32);
Expand Down Expand Up @@ -488,8 +488,11 @@ ConfigInitialize (
DEBUG ((DEBUG_ERROR, "Couldn't install ConfigDxe configuration pages: %r\n", Status));
}

Status = LocateAndInstallAcpiFromFv (&mAcpiTableFile);
ASSERT_EFI_ERROR (Status);
if (PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_ACPI ||
PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_BOTH) {
Status = LocateAndInstallAcpiFromFv (&mAcpiTableFile);
ASSERT_EFI_ERROR (Status);
}

return EFI_SUCCESS;
}
2 changes: 1 addition & 1 deletion Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree
gRaspberryPiTokenSpaceGuid.PcdSystemTableMode
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB

Expand Down
9 changes: 5 additions & 4 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
#string STR_ADVANCED_3GB_OFF #language en-US "Disabled"
#string STR_ADVANCED_3GB_ON #language en-US "Enabled"

#string STR_ADVANCED_DT_PROMPT #language en-US "Device Tree"
#string STR_ADVANCED_DT_HELP #language en-US "Disable this option to force OSes such as GNU/Linux to use ACPI"
#string STR_ADVANCED_DT_OFF #language en-US "Disabled (Force ACPI)"
#string STR_ADVANCED_DT_ON #language en-US "Enabled"
#string STR_ADVANCED_SYSTAB_PROMPT #language en-US "System Table Selection"
#string STR_ADVANCED_SYSTAB_HELP #language en-US "ACPI/DT choice for specific OSes"
#string STR_ADVANCED_SYSTAB_ACPI #language en-US "ACPI"
#string STR_ADVANCED_SYSTAB_BOTH #language en-US "ACPI + Devicetree"
#string STR_ADVANCED_SYSTAB_DT #language en-US "Devicetree"

/*
* MMC/SD configuration.
Expand Down
15 changes: 8 additions & 7 deletions Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ formset
name = RamLimitTo3GB,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore ADVANCED_DEVICE_TREE_VARSTORE_DATA,
efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
name = OptDeviceTree,
name = SystemTableMode,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore MMC_SD_VARSTORE_DATA,
Expand Down Expand Up @@ -164,12 +164,13 @@ formset
endoneof;
endif;

oneof varid = OptDeviceTree.Enabled,
prompt = STRING_TOKEN(STR_ADVANCED_DT_PROMPT),
help = STRING_TOKEN(STR_ADVANCED_DT_HELP),
oneof varid = SystemTableMode.Mode,
prompt = STRING_TOKEN(STR_ADVANCED_SYSTAB_PROMPT),
help = STRING_TOKEN(STR_ADVANCED_SYSTAB_HELP),
flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
option text = STRING_TOKEN(STR_ADVANCED_DT_OFF), value = 0, flags = 0;
option text = STRING_TOKEN(STR_ADVANCED_DT_ON), value = 1, flags = DEFAULT;
option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_ACPI), value = SYSTEM_TABLE_MODE_ACPI, flags = 0;
option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_BOTH), value = SYSTEM_TABLE_MODE_BOTH, flags = DEFAULT;
option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = SYSTEM_TABLE_MODE_DT, flags = DEFAULT;
endoneof;
endform;

Expand Down
3 changes: 2 additions & 1 deletion Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ FdtDxeInitialize (
UINTN FdtSize;
VOID *FdtImage = NULL;

if (PcdGet32 (PcdOptDeviceTree) == 0) {
if (PcdGet32 (PcdSystemTableMode) != SYSTEM_TABLE_MODE_BOTH &&
PcdGet32 (PcdSystemTableMode) != SYSTEM_TABLE_MODE_DT) {
DEBUG ((DEBUG_INFO, "Device Tree disabled per user configuration\n"));
return EFI_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion Platform/RaspberryPi/Drivers/FdtDxe/FdtDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
gRaspberryPiTokenSpaceGuid.PcdFdtBaseAddress

[Pcd]
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree
gRaspberryPiTokenSpaceGuid.PcdSystemTableMode
11 changes: 5 additions & 6 deletions Platform/RaspberryPi/Include/ConfigVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ typedef struct {
} ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA;

typedef struct {
/*
* 0 - Do not provide a Device Tree to the OS
* 1 - Provide a Device Tree to the OS
*/
UINT32 Enabled;
} ADVANCED_DEVICE_TREE_VARSTORE_DATA;
#define SYSTEM_TABLE_MODE_ACPI 0
#define SYSTEM_TABLE_MODE_BOTH 1
#define SYSTEM_TABLE_MODE_DT 2
UINT32 Mode;
} SYSTEM_TABLE_MODE_VARSTORE_DATA;

typedef struct {
/*
Expand Down
8 changes: 6 additions & 2 deletions Platform/RaspberryPi/RPi3/RPi3.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,13 @@
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|0

#
# Device Tree
# Device Tree and ACPI selection.
#
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|L"OptDeviceTree"|gConfigDxeFormSetGuid|0x0|1
# 0 - SYSTEM_TABLE_MODE_ACPI
# 1 - SYSTEM_TABLE_MODE_BOTH (default)
# 2 - SYSTEM_TABLE_MODE_DT
#
gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfigDxeFormSetGuid|0x0|1

#
# Common UEFI ones.
Expand Down
8 changes: 6 additions & 2 deletions Platform/RaspberryPi/RPi4/RPi4.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,13 @@
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeFormSetGuid|0x0|1

#
# Device Tree
# Device Tree and ACPI selection.
#
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|L"OptDeviceTree"|gConfigDxeFormSetGuid|0x0|0
# 0 - SYSTEM_TABLE_MODE_ACPI (default)
# 1 - SYSTEM_TABLE_MODE_BOTH
# 2 - SYSTEM_TABLE_MODE_DT
#
gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfigDxeFormSetGuid|0x0|0

#
# Common UEFI ones.
Expand Down
2 changes: 1 addition & 1 deletion Platform/RaspberryPi/RaspberryPi.dec
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|0|UINT32|0x00000016
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|0x3F|UINT8|0x00000017
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x00000018
gRaspberryPiTokenSpaceGuid.PcdOptDeviceTree|1|UINT32|0x0000001B
gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|1|UINT32|0x0000001B
gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019
gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A

0 comments on commit d492639

Please # to comment.