From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7240.1597359703014590567 for ; Thu, 13 Aug 2020 16:01:43 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jeremy.linton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AEC0B12FC; Thu, 13 Aug 2020 16:01:42 -0700 (PDT) Received: from u200856.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 587153F73D; Thu, 13 Aug 2020 16:01:42 -0700 (PDT) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: Jeremy Linton , Leif Lindholm , Pete Batard , Andrei Warkentin , Ard Biesheuvel , Samer El-Haj-Mahmoud Subject: [PATCH 3/3] Platform/RaspberryPi: Add entry for user fan control Date: Thu, 13 Aug 2020 18:00:56 -0500 Message-Id: <20200813230056.40526-4-jeremy.linton@arm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200813230056.40526-1-jeremy.linton@arm.com> References: <20200813230056.40526-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add a menu item that allows the user to enable GPIO based fan control via SSDT. This should only be seen/enabled on RPI4 because that is what its been tested with. As of this commit its currently limited to only operating on a single GPIO pin (19). Given GPIO pin current limitations its likely that a bit of additional circuitry is required to drive a fan, and the GPIO high/low signal can only be used as a enable/disable signal. A search for "rpi npn gpio fan" or similar should turn up some hits for how to do this simply. It appears there are a couple boards (fan SHIM) which operate this way, and probably should have custom menu items/SSDT edits as people acquire the boards and test them. Cc: Leif Lindholm Cc: Pete Batard Cc: Andrei Warkentin Cc: Ard Biesheuvel Cc: Samer El-Haj-Mahmoud Signed-off-by: Jeremy Linton --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 55 ++++++++++++++++++= ++++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 3 ++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 5 ++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 17 +++++++ Platform/RaspberryPi/Include/ConfigVars.h | 4 ++ Platform/RaspberryPi/RPi3/RPi3.dsc | 5 ++ Platform/RaspberryPi/RPi4/RPi4.dsc | 8 ++++ Platform/RaspberryPi/RaspberryPi.dec | 1 + .../Bcm27xx/Include/IndustryStandard/Bcm2711.h | 2 + 9 files changed, 100 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index af54136ade..f10347be64 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -15,6 +15,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -22,6 +23,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -246,6 +248,14 @@ SetupVariables ( ASSERT_EFI_ERROR (Status);=0D }=0D =0D + Size =3D sizeof (UINT32);=0D + Status =3D gRT->GetVariable (L"FanOnGpio",=0D + &gConfigDxeFormSetGuid,=0D + NULL, &Size, &Var32);=0D + if (EFI_ERROR (Status)) {=0D + PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));=0D + }=0D +=0D Size =3D sizeof(AssetTagVar);=0D =0D Status =3D gRT->GetVariable(L"AssetTag",=0D @@ -368,6 +378,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock);=0D UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock);=0D UINT32 Rate =3D 0;=0D + UINT32 FanOnGpio =3D PcdGet32 (PcdFanOnGpio);=0D =0D switch (CpuClock) {=0D case CHIPSET_CPU_CLOCK_LOW:=0D @@ -565,8 +576,49 @@ ApplyVariables ( GpioPinFuncSet (23, GPIO_FSEL_INPUT);=0D GpioPinFuncSet (24, GPIO_FSEL_INPUT);=0D }=0D +=0D + if (FanOnGpio) {=0D + DEBUG ((DEBUG_INFO, "Fan enabled on GPIO %d\n", FanOnGpio));=0D + GpioPinFuncSet(FanOnGpio, GPIO_FSEL_OUTPUT);=0D + }=0D }=0D =0D +EFI_STATUS=0D +FindInstallSsdt(UINT64 OemTableId)=0D +{=0D + EFI_ACPI_TABLE_PROTOCOL *AcpiTable;=0D + UINTN Index;=0D + EFI_ACPI_DESCRIPTION_HEADER *Ssdt;=0D + UINTN SsdtSize;=0D + EFI_STATUS Status;=0D + UINTN TableKey;=0D +=0D +=0D + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL,=0D + (VOID **)&AcpiTable);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + for (Index =3D 0; !EFI_ERROR(Status); Index++) {=0D + Status =3D GetSectionFromFv (&gEfiCallerIdGuid, EFI_SECTION_RAW, Index= ,=0D + (VOID **)&Ssdt, &SsdtSize);=0D + if (Ssdt->OemTableId =3D=3D OemTableId)=0D + break;=0D + SsdtSize =3D 0;=0D + }=0D +=0D + if (SsdtSize > 0) {=0D + Status =3D AcpiTable->InstallAcpiTable (AcpiTable, Ssdt, SsdtSize,=0D + &TableKey);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_WARN, "%a: failed to install SSDT table %r\n",=0D + __FUNCTION__, Status));=0D + }=0D + }=0D +=0D + return Status;=0D +}=0D =0D EFI_STATUS=0D EFIAPI=0D @@ -620,6 +672,9 @@ ConfigInitialize ( PcdGet32 (PcdSystemTableMode) =3D=3D SYSTEM_TABLE_MODE_BOTH) {=0D Status =3D LocateAndInstallAcpiFromFv (&mAcpiTableFile);=0D ASSERT_EFI_ERROR (Status);=0D + if (PcdGet32 (PcdFanOnGpio)) {=0D + FindInstallSsdt(SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', = 'N'));=0D + }=0D }=0D =0D Status =3D gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RegisterDe= vices,=0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf index cdce35bc74..fe3a01a570 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf @@ -28,6 +28,7 @@ ConfigDxeFormSetGuid.h=0D ConfigDxeHii.vfr=0D ConfigDxeHii.uni=0D + SsdtThermal.asl=0D XhciQuirk.c=0D =0D [Packages]=0D @@ -46,6 +47,7 @@ AcpiLib=0D BaseLib=0D DebugLib=0D + DxeServicesLib=0D DxeServicesTableLib=0D GpioLib=0D HiiLib=0D @@ -89,6 +91,7 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode=0D gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB=0D gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio=0D =0D [Depex]=0D gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid=0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 03763710a1..491d022fff 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -48,6 +48,11 @@ #string STR_ADVANCED_SYSTAB_BOTH #language en-US "ACPI + Devicetree"=0D #string STR_ADVANCED_SYSTAB_DT #language en-US "Devicetree"=0D =0D +#string STR_ADVANCED_FANONGPIO_PROMPT #language en-US "ACPI fan control"=0D +#string STR_ADVANCED_FANONGPIO_HELP #language en-US "Cycle a fan via GPI= O-19 if temp exceeds 60C"=0D +#string STR_ADVANCED_FANONGPIO_OFF #language en-US "Disabled"=0D +#string STR_ADVANCED_FANONGPIO_ON #language en-US "Enabled"=0D +=0D #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag"=0D #string STR_ADVANCED_ASSET_TAG_HELP #language en-US "Set the system Asse= t Tag"=0D =0D diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index d5615d7af0..0a5e4163e8 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -10,6 +10,7 @@ #include =0D #include "ConfigDxeFormSetGuid.h"=0D #include =0D +#include =0D =0D //=0D // EFI Variable attributes=0D @@ -45,6 +46,11 @@ formset name =3D RamLimitTo3GB,=0D guid =3D CONFIGDXE_FORM_SET_GUID;=0D =0D + efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,=0D + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE,=0D + name =3D FanOnGpio,=0D + guid =3D CONFIGDXE_FORM_SET_GUID;=0D +=0D efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,=0D attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE,=0D name =3D SystemTableMode,=0D @@ -174,6 +180,17 @@ formset option text =3D STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = =3D SYSTEM_TABLE_MODE_DT, flags =3D DEFAULT;=0D endoneof;=0D =0D +#if (RPI_MODEL =3D=3D 4)=0D + grayoutif NOT ideqval SystemTableMode.Mode =3D=3D SYSTEM_TABLE_MOD= E_ACPI;=0D + oneof varid =3D FanOnGpio.Enabled,=0D + prompt =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT),= =0D + help =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP),=0D + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D,=0D + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), va= lue =3D 0, flags =3D DEFAULT;=0D + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_ON), val= ue =3D GPIO_FAN_PIN, flags =3D 0;=0D + endoneof;=0D + endif;=0D +#endif=0D string varid =3D AssetTag.AssetTag,=0D prompt =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),=0D help =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),=0D diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/Raspberry= Pi/Include/ConfigVars.h index b1689b004d..1a40469bfa 100644 --- a/Platform/RaspberryPi/Include/ConfigVars.h +++ b/Platform/RaspberryPi/Include/ConfigVars.h @@ -69,6 +69,10 @@ typedef struct { } ADVANCED_RAM_LIMIT_TO_3GB_VARSTORE_DATA;=0D =0D typedef struct {=0D + UINT32 Enabled;=0D +} ADVANCED_FAN_ON_GPIO_VARSTORE_DATA;=0D +=0D +typedef struct {=0D #define SYSTEM_TABLE_MODE_ACPI 0=0D #define SYSTEM_TABLE_MODE_BOTH 1=0D #define SYSTEM_TABLE_MODE_DT 2=0D diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 0998d8366c..cef8932ca2 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -499,6 +499,11 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfig= DxeFormSetGuid|0x0|1=0D =0D #=0D + # Enable a fan in the ACPI thermal zone on GPIO pin #=0D + #=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0=0D +=0D + #=0D # Common UEFI ones.=0D #=0D =0D diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index baa7e63483..9d0eaf10a1 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -510,6 +510,14 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|L"SystemTableMode"|gConfig= DxeFormSetGuid|0x0|0=0D =0D #=0D + # Enable a fan in the ACPI thermal zone on GPIO pin #=0D + #=0D + # 0 - DISABLED=0D + # 19 - Enabled on pin 19=0D + #=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0=0D +=0D + #=0D # Common UEFI ones.=0D #=0D =0D diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index c71177a2f7..a73650f2c3 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -66,3 +66,4 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode|1|UINT32|0x0000001B=0D gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019=0D gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A=0D + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C=0D diff --git a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h b/= Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h index e9c81cafa1..7d9ea5d35c 100644 --- a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h +++ b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h @@ -86,4 +86,6 @@ #define GENET_BASE_ADDRESS FixedPcdGet64 (PcdBcmGenetRegistersAddr= ess)=0D #define GENET_LENGTH 0x00010000=0D =0D +#define GPIO_FAN_PIN 19 // fan shim uses GPIO 18=0D +=0D #endif /* BCM2711_H__ */=0D --=20 2.13.7