From nobody Tue Feb 10 21:59:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55324+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55324+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1583240916; cv=none; d=zohomail.com; s=zohoarc; b=IEulItskeCH933cCFUCNVo3mB2xQGPHs3m8xobGczf/Jpmg56sdwlsSG/Q20+vEHy32W7zUtVEsLfgZde0WptxHIaE7voG//NiK6N0pLv3bFh17LqRq1doUDqfqW+ylPo4Rr+plWjoIAkdc9q46G0+6nK42nqHI8cD9etHMtn94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583240916; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WZYed1T8BraNKXvn/vmuopS8lVUU2gB1WP6hIM2aBWU=; b=lZoSyhZmIdCx7KEvFfbpaD8zp7CYf6m6hIVKxBxFU/L65PbneXYuihY7EEIAystvzLOjAbYEF0W7q5xdP1hRZ0u+y2Eb2bJ0fhWFaMJumAxGAQAgaiWYkrgrokxPR5q5YOpgwInHy/U33Oky65QZxAfkOh2G/YT0dNMG0sw5ZxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55324+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158324091683239.266767276587984; Tue, 3 Mar 2020 05:08:36 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AC9LYY1788612xil2hm8PV9v; Tue, 03 Mar 2020 05:08:35 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web11.3393.1583240914917316915 for ; Tue, 03 Mar 2020 05:08:35 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id h9so3293475wrr.10 for ; Tue, 03 Mar 2020 05:08:34 -0800 (PST) X-Gm-Message-State: HFKrq6SbfNCpPkV8ZN9W2FB7x1787277AA= X-Google-Smtp-Source: ADFU+vuUToZbGHUE9xj868QoQRPcJK9Hu21ZLHKviHGfSeFSu4D0VRR06c6feXA33X0fXUJ5JEuO0w== X-Received: by 2002:adf:f4c9:: with SMTP id h9mr5519500wrp.168.1583240912828; Tue, 03 Mar 2020 05:08:32 -0800 (PST) X-Received: from localhost.localdomain ([84.203.56.244]) by smtp.gmail.com with ESMTPSA id j5sm3907620wmi.33.2020.03.03.05.08.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2020 05:08:32 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com, awarkentin@vmware.com Subject: [edk2-devel][PATCH v2 4/6] Platform/RPi: Make 3GB/4GB a runtime (BIOS setup) choice Date: Tue, 3 Mar 2020 13:08:12 +0000 Message-Id: <20200303130814.3092-5-pete@akeo.ie> In-Reply-To: <20200303130814.3092-1-pete@akeo.ie> References: <20200303130814.3092-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583240915; bh=87lLjSRCn4qHNJhEHglDGTv8Gc+5fgU5afGSE9Q/jBI=; h=Cc:Date:From:Reply-To:Subject:To; b=mpwZ/i9B4/5jKr/JyynpDmJ1f68rGlZFo8GUTJPC4rwcTHFCigGjluHOTzD85RDeoO1 6UJNszlFKXfsurPXLzb1KVI6+ciGnro0kVEWKoOoDGoMSZyFMDf78ANDfCI6XKAR7VfWF UxTWI7AAwyygb+ALLvxk6ySV7yHS41o15To= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Andrei Warkentin Currently some OSes (e.g FreeBSD) can make full use of the maximum 4 GB of RAM a Raspberry Pi 4 can offer, whereas others (e.g. Linux) must be restricted to only the first 3 GB. Previously this was a compile-time choice chosen by PcdAcpiBasicMode, and now we make it user-selectable. The default is a 3 GB limit. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 72 +++++++++++++= ++++--- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 8 ++- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 11 +++ Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 41 +++++++++++ Platform/RaspberryPi/RPi3/RPi3.dsc | 6 ++ Platform/RaspberryPi/RPi4/RPi4.dsc | 6 ++ Platform/RaspberryPi/RaspberryPi.dec | 4 +- 7 files changed, 134 insertions(+), 14 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index 2f48ca0dd758..964ca6d369da 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -11,11 +11,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -26,6 +28,8 @@ extern UINT8 ConfigDxeHiiBin[]; extern UINT8 ConfigDxeStrings[]; =20 STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; +STATIC UINT32 mModelFamily =3D 0; +STATIC UINT32 mModelInstalledMB =3D 0; =20 /* * The GUID inside Platform/RaspberryPi/RPi3/AcpiTables/AcpiTables.inf and @@ -129,6 +133,24 @@ SetupVariables ( PcdSet32 (PcdCustomCpuClock, PcdGet32 (PcdCustomCpuClock)); } =20 + if (mModelFamily >=3D 4 && mModelInstalledMB > 3 * 1024) { + /* + * This allows changing PcdRamLimitTo3GB in forms. + */ + PcdSet32 (PcdRamMoreThan3GB, 1); + + Size =3D sizeof (UINT32); + Status =3D gRT->GetVariable (L"RamLimitTo3GB", + &gConfigDxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + PcdSet32 (PcdRamLimitTo3GB, PcdGet32 (PcdRamLimitTo3GB)); + } + } else { + PcdSet32 (PcdRamMoreThan3GB, 0); + PcdSet32 (PcdRamLimitTo3GB, 0); + } + Size =3D sizeof (UINT32); Status =3D gRT->GetVariable (L"SdIsArasan", &gConfigDxeFormSetGuid, @@ -224,7 +246,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock); UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock); UINT32 Rate =3D 0; - UINT32 ModelFamily =3D 0; + UINT64 SystemMemorySize; =20 if (CpuClock !=3D 0) { if (CpuClock =3D=3D 2) { @@ -258,15 +280,31 @@ ApplyVariables ( DEBUG ((DEBUG_INFO, "Current CPU speed is %uHz\n", Rate)); } =20 - Status =3D mFwProtocol->GetModelFamily (&ModelFamily); - if (Status !=3D EFI_SUCCESS) { - DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi model family: %r\n= ", Status)); - } else { - DEBUG ((DEBUG_INFO, "Current Raspberry Pi model family is 0x%x\n", Mod= elFamily)); + if (mModelFamily >=3D 4 && PcdGet32 (PcdRamLimitTo3GB) =3D=3D 0) { + /* + * Similar to how we compute the > 3 GB RAM segment's size in Platform= Lib/ + * RaspberryPiMem.c, with some overlap protection for the Bcm2xxx regi= ster + * spaces. This computation should also work for models with more than= 4 GB + * RAM, if there ever exist ones. + */ + SystemMemorySize =3D (UINT64)mModelInstalledMB * SIZE_1MB; + ASSERT (SystemMemorySize > 3UL * SIZE_1GB); + SystemMemorySize =3D MIN(SystemMemorySize, BCM2836_SOC_REGISTERS); + if (BCM2711_SOC_REGISTERS > 0) { + SystemMemorySize =3D MIN(SystemMemorySize, BCM2711_SOC_REGISTERS); + } + + Status =3D gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, 3UL * BA= SE_1GB, + SystemMemorySize - (3UL * SIZE_1GB), + EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_ME= MORY_WB); + ASSERT_EFI_ERROR (Status); + Status =3D gDS->SetMemorySpaceAttributes (3UL * BASE_1GB, + SystemMemorySize - (3UL * SIZE_1GB), + EFI_MEMORY_WB); + ASSERT_EFI_ERROR (Status); } =20 - - if (ModelFamily =3D=3D 3) { + if (mModelFamily =3D=3D 3) { /* * Pi 3: either Arasan or SdHost goes to SD card. * @@ -316,7 +354,7 @@ ApplyVariables ( GpioPinFuncSet (52, Gpio48Group); GpioPinFuncSet (53, Gpio48Group); =20 - } else if (ModelFamily =3D=3D 4) { + } else if (mModelFamily =3D=3D 4) { /* * Pi 4: either Arasan or eMMC2 goes to SD card. */ @@ -352,7 +390,7 @@ ApplyVariables ( GpioPinFuncSet (39, GPIO_FSEL_ALT3); } } else { - DEBUG ((DEBUG_ERROR, "Model Family %d not supported...\n", ModelFamily= )); + DEBUG ((DEBUG_ERROR, "Model Family %d not supported...\n", mModelFamil= y)); } =20 /* @@ -400,6 +438,20 @@ ConfigInitialize ( return Status; } =20 + Status =3D mFwProtocol->GetModelFamily (&mModelFamily); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi model family: %r\n= ", Status)); + } else { + DEBUG ((DEBUG_INFO, "Current Raspberry Pi model family is %d\n", mMode= lFamily)); + } + + Status =3D mFwProtocol->GetModelInstalledMB (&mModelInstalledMB); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi installed RAM size= : %r\n", Status)); + } else { + DEBUG ((DEBUG_INFO, "Current Raspberry Pi installed RAM size is %d MB\= n", mModelInstalledMB)); + } + Status =3D SetupVariables (); if (Status !=3D EFI_SUCCESS) { DEBUG ((DEBUG_ERROR, "Couldn't not setup NV vars: %r\n", Status)); diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf index dc726cc6d934..407aac89c7b3 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf @@ -33,6 +33,7 @@ [Packages] ArmPlatformPkg/ArmPlatformPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + Silicon/Broadcom/Bcm27xx/Bcm27xx.dec Silicon/Broadcom/Bcm283x/Bcm283x.dec Platform/RaspberryPi/RaspberryPi.dec EmbeddedPkg/EmbeddedPkg.dec @@ -53,10 +54,11 @@ [Guids] gConfigDxeFormSetGuid =20 [Protocols] - gRaspberryPiFirmwareProtocolGuid ## CONSUMES + gRaspberryPiFirmwareProtocolGuid ## CONSUMES gRaspberryPiConfigAppliedProtocolGuid ## PRODUCES =20 [Pcd] + gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress gRaspberryPiTokenSpaceGuid.PcdCpuClock gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock @@ -70,8 +72,8 @@ [Pcd] gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot - -[FeaturePcd] + gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB + gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB =20 [Depex] gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 9b4076635f05..830533a9dc49 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -35,6 +35,17 @@ #string STR_CHIPSET_SD_SDHOST #language en-US "Broadcom SDHOST" #string STR_CHIPSET_SD_ARASAN #language en-US "Arasan SDHCI" =20 +/* + * Advanced configuration. + */ + +#string STR_ADVANCED_FORM_TITLE #language en-US "Advanced Configurati= on" + +#string STR_ADVANCED_3GB_PROMPT #language en-US "Limit RAM to 3 GB" +#string STR_ADVANCED_3GB_HELP #language en-US "OSes not supporting = ACPI DMA constraints require a 3 GB limit or face broken xHCI USB" +#string STR_ADVANCED_3GB_OFF #language en-US "Disabled" +#string STR_ADVANCED_3GB_ON #language en-US "Enabled" + /* * MMC/SD configuration. */ diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index 60bfdbd4d17e..483edd7459c5 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -73,6 +73,18 @@ typedef struct { UINT32 Routing; } CHIPSET_SD_VARSTORE_DATA; =20 +typedef struct { + /* + * Always set by ConfigDxe prior to HII init to reflect + * platform capability. + */ + UINT32 Supported; +} ADVANCED_RAM_MORE_THAN_3GB_VARSTORE_DATA; + +typedef struct { + UINT32 Enabled; +} ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA; + typedef struct { /* * 0 - Don't disable multi-block. @@ -140,6 +152,16 @@ formset name =3D SdIsArasan, guid =3D CONFIGDXE_FORM_SET_GUID; =20 + efivarstore ADVANCED_RAM_MORE_THAN_3GB_VARSTORE_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, + name =3D RamMoreThan3GB, + guid =3D CONFIGDXE_FORM_SET_GUID; + + efivarstore ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, + name =3D RamLimitTo3GB, + guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore MMC_DISMULTI_VARSTORE_DATA, attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, name =3D MmcDisableMulti, @@ -193,6 +215,10 @@ formset prompt =3D STRING_TOKEN(STR_CHIPSET_FORM_TITLE), help =3D STRING_TOKEN(STR_NULL_STRING); =20 + goto 0x1006, + prompt =3D STRING_TOKEN(STR_ADVANCED_FORM_TITLE), + help =3D STRING_TOKEN(STR_NULL_STRING); + goto 0x1003, prompt =3D STRING_TOKEN(STR_MMC_FORM_TITLE), help =3D STRING_TOKEN(STR_NULL_STRING); @@ -240,6 +266,21 @@ formset endoneof; endform; =20 + form formid =3D 0x1006, + title =3D STRING_TOKEN(STR_ADVANCED_FORM_TITLE); + subtitle text =3D STRING_TOKEN(STR_NULL_STRING); + + grayoutif ideqval RamMoreThan3GB.Supported =3D=3D 0; + oneof varid =3D RamLimitTo3GB.Enabled, + prompt =3D STRING_TOKEN(STR_ADVANCED_3GB_PROMPT), + help =3D STRING_TOKEN(STR_ADVANCED_3GB_HELP), + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D, + option text =3D STRING_TOKEN(STR_ADVANCED_3GB_OFF), value = =3D 0, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_ADVANCED_3GB_ON), value =3D= 1, flags =3D 0; + endoneof; + endif; + endform; + form formid =3D 0x1003, title =3D STRING_TOKEN(STR_MMC_FORM_TITLE); subtitle text =3D STRING_TOKEN(STR_MMC_FORM_SUBTITLE); diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index df5b246af1f8..48e1a32e1d24 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -439,6 +439,12 @@ [PcdsDynamicHii.common.DEFAULT] gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|L"DisplayEnableS= caledVModes"|gConfigDxeFormSetGuid|0x0|0xff gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|L"DisplayEnableSShot"|g= ConfigDxeFormSetGuid|0x0|1 =20 + # + # Supporting > 3GB of memory. + # + gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|L"RamMoreThan3GB"|gConfigDx= eFormSetGuid|0x0|0 + gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeF= ormSetGuid|0x0|0 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index 60a5e38da778..3ce2c3e4d519 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -477,6 +477,12 @@ [PcdsDynamicHii.common.DEFAULT] gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|L"DisplayEnableS= caledVModes"|gConfigDxeFormSetGuid|0x0|0xff gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|L"DisplayEnableSShot"|g= ConfigDxeFormSetGuid|0x0|1 =20 + # + # Supporting > 3GB of memory. + # + gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|L"RamMoreThan3GB"|gConfigDx= eFormSetGuid|0x0|0 + gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|L"RamLimitTo3GB"|gConfigDxeF= ormSetGuid|0x0|1 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index bc378ffbfb8d..7f2c37ac9a7f 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -57,6 +57,8 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, Pc= dsDynamicEx] gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|0|UINT32|0x00000016 gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|0|UINT8|0x000000= 17 gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x00000018 + gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019 + gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A =20 [PcdsFeatureFlag.common] - gRaspberryPiTokenSpaceGuid.PcdAcpiBasicMode|FALSE|BOOLEAN|0x00000019 + gRaspberryPiTokenSpaceGuid.PcdAcpiBasicMode|FALSE|BOOLEAN|0x0000001B --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55324): https://edk2.groups.io/g/devel/message/55324 Mute This Topic: https://groups.io/mt/71699476/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-