From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.73]) by mx.groups.io with SMTP id smtpd.web12.113412.1597940145836249758 for ; Thu, 20 Aug 2020 09:15:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@vmware.com header.s=selector2 header.b=0Ps/azlw; spf=pass (domain: vmware.com, ip: 40.107.220.73, mailfrom: awarkentin@vmware.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NozyLfCl43PtT6CPKWW3+hfhIOp0E46FlhOWDPuNEO+39eMS5hDRKMYTnrfwAnbgWne8xo7J/m8l9l6ByuKJZ4YsDgq7of3JeCCRzUblfdq3e/PM68xg1/dAt8tRxoz0zPOvbwvAS0c0lgxaNa1ELU/s2KvGD+9anjuPNA+/Ed2GhzgbuhVm+LZ69XqJOqOWqrEbu1RUi/ndrkCY8knLy7XSmiVzXsGYFMkQNliKz5e949U8qRWi932RcwB+EOIUa464yYo5LSVI9LcJiD0kovBz8J5l3dBqeXfzGsz5tdX2Qo0xaRbvu0sZ6VCLbVnvXQR528N72l+K60AvvAgTIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5Wqo8ryxZ0SRiyd5nXaBXQBQokqZyt5AHtG4NQGWakg=; b=nWs8hiMjOm5bgUH9vMIT9l2qWMoS+dYk9z3PMnP4Ax6t6qzFW2u6oYLcreyIX2YKEPeCw5PHzDXx4wVz56V/d8OViHAoyiTSR+ZsCHdNz1JHZoV1y7WBV8J7h+oHxQ3F9Ijg3Qd4XFhRUHuXGSubf21EMyZW5W493msc+7opVQvZYJ6exoN9CqaBI5TsUNePT3u27dVd+Dsc6RkklSN5pcgwM7kYPc39H+ky+mR5VtPadMncoLwwznnl18mK+o6s6QCbg4SFpnHL5bvrfaTCwNWe4/3Y/8lRJYRiS9zm7U1L2KSqkQWMGtF0e6nG4EvP4a+6SHpTkAKp4Yj6Hyz67Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5Wqo8ryxZ0SRiyd5nXaBXQBQokqZyt5AHtG4NQGWakg=; b=0Ps/azlwRQjPnuArUQrvRk6kvU5Lba7TDaYzNxaLkktODrVPGbMdBd3Y8YwVx8qTYSPe8Spgpbw8zYNyThpCWyUQtTbZffAuKOPmzzqWiM1Yina1SQfX2wq/G50hahhous29W+NF73nr3+kazbx+30oK4UWCXu1k/cbQLgf0Kh4= Received: from BN6PR05MB3411.namprd05.prod.outlook.com (2603:10b6:405:43::23) by BN7PR05MB5827.namprd05.prod.outlook.com (2603:10b6:408:3d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.10; Thu, 20 Aug 2020 16:15:44 +0000 Received: from BN6PR05MB3411.namprd05.prod.outlook.com ([fe80::79d1:7b4a:fbda:c003]) by BN6PR05MB3411.namprd05.prod.outlook.com ([fe80::79d1:7b4a:fbda:c003%7]) with mapi id 15.20.3305.021; Thu, 20 Aug 2020 16:15:44 +0000 From: "Andrei Warkentin" To: Jeremy Linton , "devel@edk2.groups.io" CC: Leif Lindholm , Pete Batard , Ard Biesheuvel , Samer El-Haj-Mahmoud Subject: Re: [PATCH v2 3/4] Platform/RaspberryPi: Add entry for user fan control Thread-Topic: [PATCH v2 3/4] Platform/RaspberryPi: Add entry for user fan control Thread-Index: AQHWdqxhmDz+a8xyAE60SDsK+vZV7alBLJJ0 Date: Thu, 20 Aug 2020 16:15:43 +0000 Message-ID: References: <20200820044217.39839-1-jeremy.linton@arm.com>,<20200820044217.39839-4-jeremy.linton@arm.com> In-Reply-To: <20200820044217.39839-4-jeremy.linton@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=vmware.com; x-originating-ip: [98.214.99.181] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 944162f6-53b1-48c5-12bc-08d845244a55 x-ms-traffictypediagnostic: BN7PR05MB5827: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: he5YibtuejeQapPD4ZTha3wQ585cOM1fkYDM+9hdwQLP92rO0x+55s/1p4nebsgByz5pzbBfLPnzsQqDCrMkE4N8lzryhT0XRE4L5fzgjwKV8LMgvEY23Nn3nuj9BIJhXRu8lDVyza/I7prRdyrmQwrymR+435JUnuHAXTwKKb1Bj7PM0iC5KWsWCQotg13AV6SDFFYlYC9C8JLgkZBuO76Tx5U6xL3Q8Scxrj4UhMon2P+OnkeHtrXITvPf3uJ9KPW97n9lZzQWdocSE/RJwNgh1NZQMjQDtw0Dw7H5OC73KY92IryfnXqVnu31Xj84KDJ3ofMCxjcWff1MCtPKhw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR05MB3411.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(376002)(346002)(396003)(39860400002)(136003)(186003)(4326008)(26005)(19627405001)(478600001)(9686003)(2906002)(8936002)(7696005)(76116006)(54906003)(8676002)(71200400001)(53546011)(30864003)(110136005)(6506007)(55016002)(66446008)(66946007)(52536014)(91956017)(66556008)(316002)(66476007)(64756008)(19627235002)(5660300002)(86362001)(83380400001)(33656002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: kgtbVoIIkz209FVQ2kV21F4duoLYiTPsJ+ovc4rvOZdgmGfnruZ0N8fuQZbR0zp62KvHWEN904DSsIJhnWXJWPycSvnfMJ1tMT6iYSAX0pVBwqmk6ibk+vay3ofXh+Wxyam0LmsndE1bqWONUoh4rz/SDR23uLXxRCbuKtmTf2fEv5V1ZiZFANWaCUMQEvHq/93UqF29bxfO9WGomkgVa+hAcIrJIhPdFHGB67jTNkZWZfVpG8B1I0nclZK7+NJSIz9v65jD+QbP0k/iJJE5uuFGVqvZ9IObXndn1D2MQv5JYIi4p8wq1N2G3C36CrdPSh0sVpAf6ms9qo8jOIsFOVCWIloZVheG/Uv7fBDdziP1SazoKBrdJXD+XjosUK9B7OM5LiCwXkxOo6O10w5adTT7ioevxCrJH9EKBXfuG3NfXPsgOpdNyCqxefIsJI3oSJRArQVQOeS/TZXNe6DnBlBa29Da3iLaxK1zdIS9A37lemh+b5AvjdkUswlpyRDc1chsg8CS91QjXoyD3LovHMQJX8yUruSwrFSf1IwzcDQcxvyCnXiEjhHAdb17Szqo2y5FYIY46EHCtc3USTS+zTW0guOP5ZymPtVkezczKiAs2ANX4FA8K5XhKtOD3vK+x/nHKdSmx6YLuOSTcprTww== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN6PR05MB3411.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 944162f6-53b1-48c5-12bc-08d845244a55 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2020 16:15:43.9784 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DBOqANp1UYKY3oBBNPOVpWKm8RiNvGI4nTkmPGLvB67TEaVEcUXRG3kFd1eyqVAsw0TOU9Ilf2czaSpKb3S9ig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR05MB5827 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_BN6PR05MB341184F799120CC1E644F0A1B95A0BN6PR05MB3411namp_" --_000_BN6PR05MB341184F799120CC1E644F0A1B95A0BN6PR05MB3411namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Jeremy, Overall, great idea. An improvement on your implementation would be to use = LocateAndInstallAcpiFromFvConditional (which will call your call back on ev= ery table, so you can allow/disallow/patch) instead of calling LocateAndIns= tallAcpiFromFv and the locating the SSDT manually. A ________________________________ From: Jeremy Linton Sent: Wednesday, August 19, 2020 11:42 PM To: devel@edk2.groups.io Cc: Jeremy Linton ; Leif Lindholm ; Pete Batard ; Andrei Warkentin ; Ar= d Biesheuvel ; Samer El-Haj-Mahmoud Subject: [PATCH v2 3/4] Platform/RaspberryPi: Add entry for user fan contro= l 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 Reviewed-by: Pete Batard <@pbatard> --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 78 ++++++++++++++++++= ++++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 3 + .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 6 ++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 18 +++++ Platform/RaspberryPi/Include/ConfigVars.h | 4 ++ Platform/RaspberryPi/RPi3/RPi3.dsc | 5 ++ Platform/RaspberryPi/RPi4/RPi4.dsc | 8 +++ Platform/RaspberryPi/RaspberryPi.dec | 1 + 8 files changed, 123 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index af54136ade..24e65eeb5e 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -246,6 +248,14 @@ SetupVariables ( ASSERT_EFI_ERROR (Status); } + Size =3D sizeof (UINT32); + Status =3D gRT->GetVariable (L"FanOnGpio", + &gConfigDxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status)) { + PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio)); + } + Size =3D sizeof(AssetTagVar); Status =3D gRT->GetVariable(L"AssetTag", @@ -368,6 +378,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock); UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock); UINT32 Rate =3D 0; + UINT32 FanOnGpio =3D PcdGet32 (PcdFanOnGpio); switch (CpuClock) { case CHIPSET_CPU_CLOCK_LOW: @@ -565,8 +576,71 @@ ApplyVariables ( GpioPinFuncSet (23, GPIO_FSEL_INPUT); GpioPinFuncSet (24, GPIO_FSEL_INPUT); } + + if (FanOnGpio) { + DEBUG ((DEBUG_INFO, "Fan enabled on GPIO %d\n", FanOnGpio)); + GpioPinFuncSet (FanOnGpio, GPIO_FSEL_OUTPUT); + } } +#define SSDT_PATTERN_LEN 6 + +EFI_STATUS +FindInstallSsdt (UINT64 OemTableId, CHAR8 *Name, UINT8 Value) +{ + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN Index; + EFI_ACPI_DESCRIPTION_HEADER *Ssdt; + UINTN SsdtSize; + EFI_STATUS Status; + UINTN TableKey; + CHAR8 Pattern[SSDT_PATTERN_LEN]; + + + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, + (VOID **)&AcpiTable); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index =3D 0; !EFI_ERROR (Status); Index++) { + Status =3D GetSectionFromFv (&gEfiCallerIdGuid, EFI_SECTION_RAW, Index= , + (VOID **)&Ssdt, &SsdtSize); + if (Ssdt->OemTableId =3D=3D OemTableId) + break; + SsdtSize =3D 0; + } + + if (SsdtSize > 0) { + /* + * Do a single 8 bit NameOp variable replacement these are of the + * form 08 XXXX SIZE VAL, where SIZE is 0A=3Dbyte, 0B=3Dword, 0C=3Ddwo= rd + * and XXXX is the name and VAL is the value + */ + Pattern[0] =3D 0x08; //NameOp + Pattern[1] =3D Name[0]; //Name + Pattern[2] =3D Name[1]; + Pattern[3] =3D Name[2]; + Pattern[4] =3D Name[3]; + Pattern[5] =3D 0x0A; //Size + + for (Index =3D 0; Index < (SsdtSize - SSDT_PATTERN_LEN); Index++) { + if (CompareMem ((UINT8*)Ssdt + Index, Pattern, SSDT_PATTERN_LEN) =3D= =3D 0) { + *((UINT8 *)Ssdt + Index + SSDT_PATTERN_LEN) =3D Value; + break; + } + } + + Status =3D AcpiTable->InstallAcpiTable (AcpiTable, Ssdt, SsdtSize, + &TableKey); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "%a: failed to install SSDT table %r\n", + __FUNCTION__, Status)); + } + } + + return Status; +} EFI_STATUS EFIAPI @@ -620,6 +694,10 @@ ConfigInitialize ( PcdGet32 (PcdSystemTableMode) =3D=3D SYSTEM_TABLE_MODE_BOTH) { Status =3D LocateAndInstallAcpiFromFv (&mAcpiTableFile); ASSERT_EFI_ERROR (Status); + if (PcdGet32 (PcdFanOnGpio)) { + FindInstallSsdt (SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', '= N'), + "GIOP", (UINT8)PcdGet32 (PcdFanOnGpio)); + } } Status =3D gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RegisterDe= vices, 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 ConfigDxeHii.vfr ConfigDxeHii.uni + SsdtThermal.asl XhciQuirk.c [Packages] @@ -46,6 +47,7 @@ AcpiLib BaseLib DebugLib + DxeServicesLib DxeServicesTableLib GpioLib HiiLib @@ -89,6 +91,7 @@ gRaspberryPiTokenSpaceGuid.PcdSystemTableMode gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio [Depex] gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 03763710a1..e2d1bb4b39 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -48,6 +48,12 @@ #string STR_ADVANCED_SYSTAB_BOTH #language en-US "ACPI + Devicetree" #string STR_ADVANCED_SYSTAB_DT #language en-US "Devicetree" +#string STR_ADVANCED_FANONGPIO_PROMPT #language en-US "ACPI fan control" +#string STR_ADVANCED_FANONGPIO_HELP #language en-US "Cycle a fan via GPI= O if temp exceeds 60C" +#string STR_ADVANCED_FANONGPIO_OFF #language en-US "Disabled" +#string STR_ADVANCED_FANONGPIO_18 #language en-US "Fan Shim/GPIO-18" +#string STR_ADVANCED_FANONGPIO_19 #language en-US "GPIO-19" + #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag" #string STR_ADVANCED_ASSET_TAG_HELP #language en-US "Set the system Asse= t Tag" diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index d5615d7af0..94332caab3 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -10,6 +10,7 @@ #include #include "ConfigDxeFormSetGuid.h" #include +#include // // EFI Variable attributes @@ -45,6 +46,11 @@ formset name =3D RamLimitTo3GB, guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, + name =3D FanOnGpio, + guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA, attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, name =3D SystemTableMode, @@ -174,6 +180,18 @@ formset option text =3D STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = =3D SYSTEM_TABLE_MODE_DT, flags =3D DEFAULT; endoneof; +#if (RPI_MODEL =3D=3D 4) + grayoutif NOT ideqval SystemTableMode.Mode =3D=3D SYSTEM_TABLE_MOD= E_ACPI; + oneof varid =3D FanOnGpio.Enabled, + prompt =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT), + help =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP), + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D, + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), va= lue =3D 0, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), val= ue =3D 18, flags =3D 0; + option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), val= ue =3D 19, flags =3D 0; + endoneof; + endif; +#endif string varid =3D AssetTag.AssetTag, prompt =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT), help =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP), 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; typedef struct { + UINT32 Enabled; +} ADVANCED_FAN_ON_GPIO_VARSTORE_DATA; + +typedef struct { #define SYSTEM_TABLE_MODE_ACPI 0 #define SYSTEM_TABLE_MODE_BOTH 1 #define SYSTEM_TABLE_MODE_DT 2 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 # + # Enable a fan in the ACPI thermal zone on GPIO pin # + # + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0 + + # # Common UEFI ones. # 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 # + # Enable a fan in the ACPI thermal zone on GPIO pin # + # + # 0 - DISABLED + # 19 - Enabled on pin 19 + # + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0 + + # # Common UEFI ones. # 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 gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x00000019 gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A + gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C -- 2.13.7 --_000_BN6PR05MB341184F799120CC1E644F0A1B95A0BN6PR05MB3411namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi Jeremy,

Overall, great idea. An improvement on your implementation would be to use&= nbsp;LocateAndInstallAcpiFromFvConditional (which will call your call back = on every table, so you can allow/disallow/patch) instead of calling Lo= cateAndInstallAcpiFromFv and the locating the SSDT manually.

A

From: Jeremy Linton <jer= emy.linton@arm.com>
Sent: Wednesday, August 19, 2020 11:42 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Jeremy Linton <jeremy.linton@arm.com>; Leif Lindholm <l= eif@nuviainc.com>; Pete Batard <pete@akeo.ie>; Andrei Warkentin &l= t;awarkentin@vmware.com>; Ard Biesheuvel <ard.biesheuvel@arm.com>;= Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Subject: [PATCH v2 3/4] Platform/RaspberryPi: Add entry for user fan= control
 
Add a menu item that allows the user to enable GPI= O 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 <leif@nuviainc.com>
Cc: Pete Batard <pete@akeo.ie>
Cc: Andrei Warkentin <awarkentin@vmware.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Pete Batard <@pbatard>
---
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 78 +++++++++++++= +++++++++
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf    |&n= bsp; 3 +
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni |  6 ++
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 18 +++++
 Platform/RaspberryPi/Include/ConfigVars.h    &nbs= p;     |  4 ++
 Platform/RaspberryPi/RPi3/RPi3.dsc      = ;           |  5 ++<= br>  Platform/RaspberryPi/RPi4/RPi4.dsc      = ;           |  8 +++=
 Platform/RaspberryPi/RaspberryPi.dec     &nb= sp;         |  1 +
 8 files changed, 123 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index af54136ade..24e65eeb5e 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -15,6 +15,7 @@
 #include <Library/AcpiLib.h>

 #include <Library/DebugLib.h>

 #include <Library/DevicePathLib.h>

+#include <Library/DxeServicesLib.h>

 #include <Library/DxeServicesTableLib.h>

 #include <Library/GpioLib.h>

 #include <Library/HiiLib.h>

@@ -22,6 +23,7 @@
 #include <Library/NetLib.h>

 #include <Library/UefiBootServicesTableLib.h>

 #include <Library/UefiRuntimeServicesTableLib.h>

+#include <Protocol/AcpiTable.h>

 #include <Protocol/BcmGenetPlatformDevice.h>

 #include <Protocol/RpiFirmware.h>

 #include <ConfigVars.h>

@@ -246,6 +248,14 @@ SetupVariables (
     ASSERT_EFI_ERROR (Status);

   }

 

+  Size =3D sizeof (UINT32);

+  Status =3D gRT->GetVariable (L"FanOnGpio",

+            &n= bsp;     &gConfigDxeFormSetGuid,

+            &n= bsp;     NULL, &Size, &Var32);

+  if (EFI_ERROR (Status)) {

+    PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));

+  }

+

   Size =3D sizeof(AssetTagVar);

 

   Status =3D gRT->GetVariable(L"AssetTag",

@@ -368,6 +378,7 @@ ApplyVariables (
   UINT32 CpuClock =3D PcdGet32 (PcdCpuClock);

   UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock);

   UINT32 Rate =3D 0;

+  UINT32 FanOnGpio =3D PcdGet32 (PcdFanOnGpio);

 

   switch (CpuClock) {

   case CHIPSET_CPU_CLOCK_LOW:

@@ -565,8 +576,71 @@ ApplyVariables (
     GpioPinFuncSet (23, GPIO_FSEL_INPUT);

     GpioPinFuncSet (24, GPIO_FSEL_INPUT);

   }

+

+  if (FanOnGpio) {

+    DEBUG ((DEBUG_INFO, "Fan enabled on GPIO %d\n"= ;, FanOnGpio));

+    GpioPinFuncSet (FanOnGpio, GPIO_FSEL_OUTPUT);

+  }

 }

 

+#define SSDT_PATTERN_LEN 6

+

+EFI_STATUS

+FindInstallSsdt (UINT64 OemTableId, CHAR8 *Name, UINT8 Value)

+{

+  EFI_ACPI_TABLE_PROTOCOL       &n= bsp; *AcpiTable;

+  UINTN          &n= bsp;            = ;    Index;

+  EFI_ACPI_DESCRIPTION_HEADER     *Ssdt;

+  UINTN          &n= bsp;            = ;    SsdtSize;

+  EFI_STATUS         &nb= sp;            Statu= s;

+  UINTN          &n= bsp;            = ;    TableKey;

+  CHAR8          &n= bsp;            = ;    Pattern[SSDT_PATTERN_LEN];

+

+

+  Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, = NULL,

+            &n= bsp;            = ;       (VOID **)&AcpiTable);

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

+  for (Index =3D 0; !EFI_ERROR (Status); Index++) {

+    Status =3D GetSectionFromFv (&gEfiCallerIdGuid, EFI= _SECTION_RAW, Index,

+            &n= bsp;            = ;      (VOID **)&Ssdt, &SsdtSize);

+    if (Ssdt->OemTableId =3D=3D OemTableId)

+      break;

+    SsdtSize =3D 0;

+  }

+

+  if (SsdtSize > 0) {

+    /*

+     * Do a single 8 bit NameOp variable replacement t= hese are of the

+     * form 08 XXXX SIZE VAL, where SIZE is 0A=3Dbyte,= 0B=3Dword, 0C=3Ddword

+     * and XXXX is the name and VAL is the value

+    */

+    Pattern[0] =3D 0x08;    //NameOp

+    Pattern[1] =3D Name[0]; //Name

+    Pattern[2] =3D Name[1];

+    Pattern[3] =3D Name[2];

+    Pattern[4] =3D Name[3];

+    Pattern[5] =3D 0x0A;    //Size

+

+    for (Index =3D 0; Index < (SsdtSize - SSDT_PATTERN_L= EN); Index++) {

+      if (CompareMem ((UINT8*)Ssdt + Index, Patte= rn, SSDT_PATTERN_LEN) =3D=3D 0) {

+        *((UINT8 *)Ssdt + Index + SSDT_= PATTERN_LEN) =3D Value;

+        break;

+      }

+    }

+

+    Status =3D AcpiTable->InstallAcpiTable (AcpiTable, S= sdt, SsdtSize,

+            &n= bsp;            = ;            &n= bsp;    &TableKey);

+    if (EFI_ERROR (Status)) {

+      DEBUG ((DEBUG_WARN, "%a: failed to ins= tall SSDT table %r\n",

+            &n= bsp; __FUNCTION__, Status));

+    }

+  }

+

+  return Status;

+}

 

 EFI_STATUS

 EFIAPI

@@ -620,6 +694,10 @@ ConfigInitialize (
       PcdGet32 (PcdSystemTableMode) =3D=3D S= YSTEM_TABLE_MODE_BOTH) {

      Status =3D LocateAndInstallAcpiFromFv (&= mAcpiTableFile);

      ASSERT_EFI_ERROR (Status);

+     if (PcdGet32 (PcdFanOnGpio)) {

+       FindInstallSsdt (SIGNATURE_64 ('R', '= P', 'I', 'T', 'H', 'F', 'A', 'N'),

+            &n= bsp;           "GIOP= ", (UINT8)PcdGet32 (PcdFanOnGpio));

+     }

   }

 

   Status =3D gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIF= Y, RegisterDevices,

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

   ConfigDxeHii.vfr

   ConfigDxeHii.uni

+  SsdtThermal.asl

   XhciQuirk.c

 

 [Packages]

@@ -46,6 +47,7 @@
   AcpiLib

   BaseLib

   DebugLib

+  DxeServicesLib

   DxeServicesTableLib

   GpioLib

   HiiLib

@@ -89,6 +91,7 @@
   gRaspberryPiTokenSpaceGuid.PcdSystemTableMode

   gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB

   gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB

+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio

 

 [Depex]

   gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
index 03763710a1..e2d1bb4b39 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
@@ -48,6 +48,12 @@
 #string STR_ADVANCED_SYSTAB_BOTH     #language en= -US "ACPI + Devicetree"

 #string STR_ADVANCED_SYSTAB_DT       #l= anguage en-US "Devicetree"

 

+#string STR_ADVANCED_FANONGPIO_PROMPT #language en-US "ACPI fan contr= ol"

+#string STR_ADVANCED_FANONGPIO_HELP   #language en-US "Cycl= e a fan via GPIO if temp exceeds 60C"

+#string STR_ADVANCED_FANONGPIO_OFF    #language en-US "= ;Disabled"

+#string STR_ADVANCED_FANONGPIO_18     #language en-US = "Fan Shim/GPIO-18"

+#string STR_ADVANCED_FANONGPIO_19     #language en-US = "GPIO-19"

+

 #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag= "

 #string STR_ADVANCED_ASSET_TAG_HELP   #language en-US "= ;Set the system Asset Tag"

 

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
index d5615d7af0..94332caab3 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
@@ -10,6 +10,7 @@
 #include <Guid/HiiPlatformSetupFormset.h>

 #include "ConfigDxeFormSetGuid.h"

 #include <ConfigVars.h>

+#include <IndustryStandard/Bcm2711.h>

 

 //

 // EFI Variable attributes

@@ -45,6 +46,11 @@ formset
       name  =3D RamLimitTo3GB,

       guid  =3D CONFIGDXE_FORM_SET_GUID= ;

 

+    efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,

+      attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCE= SS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,

+      name  =3D FanOnGpio,

+      guid  =3D CONFIGDXE_FORM_SET_GUID;

+

     efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,

       attribute =3D EFI_VARIABLE_BOOTSERVICE= _ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,

       name  =3D SystemTableMode,

@@ -174,6 +180,18 @@ formset
             op= tion text =3D STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value =3D SYSTEM_TABLE_= MODE_DT, flags =3D DEFAULT;

         endoneof;

 

+#if (RPI_MODEL =3D=3D 4)

+        grayoutif NOT ideqval SystemTab= leMode.Mode =3D=3D SYSTEM_TABLE_MODE_ACPI;

+          oneof varid =3D Fan= OnGpio.Enabled,

+            &n= bsp; prompt      =3D STRING_TOKEN(STR_ADVANCED_FAN= ONGPIO_PROMPT),

+            &n= bsp; help        =3D STRING_TOKEN(STR_AD= VANCED_FANONGPIO_HELP),

+            &n= bsp; flags       =3D NUMERIC_SIZE_4 | INTERAC= TIVE | RESET_REQUIRED,

+            &n= bsp; option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), value =3D 0,= flags =3D DEFAULT;

+            &n= bsp; option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), value =3D 18,= flags =3D 0;

+            &n= bsp; option text =3D STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), value =3D 19,= flags =3D 0;

+          endoneof;

+        endif;

+#endif

         string varid =3D AssetTag.= AssetTag,

             pr= ompt  =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),

             he= lp    =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),

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;

 

 typedef struct {

+  UINT32 Enabled;

+} ADVANCED_FAN_ON_GPIO_VARSTORE_DATA;

+

+typedef struct {

 #define SYSTEM_TABLE_MODE_ACPI 0

 #define SYSTEM_TABLE_MODE_BOTH 1

 #define SYSTEM_TABLE_MODE_DT   2

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"SystemTab= leMode"|gConfigDxeFormSetGuid|0x0|1

 

   #

+  # Enable a fan in the ACPI thermal zone on GPIO pin #

+  #

+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gCon= figDxeFormSetGuid|0x0|0

+

+  #

   # Common UEFI ones.

   #

 

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"SystemTab= leMode"|gConfigDxeFormSetGuid|0x0|0

 

   #

+  # Enable a fan in the ACPI thermal zone on GPIO pin #

+  #

+  # 0  - DISABLED

+  # 19 - Enabled on pin 19

+  #

+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gCon= figDxeFormSetGuid|0x0|0

+

+  #

   # Common UEFI ones.

   #

 

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|0x00000= 01B

   gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB|0|UINT32|0x000000= 19

   gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001= A

+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C

--
2.13.7

--_000_BN6PR05MB341184F799120CC1E644F0A1B95A0BN6PR05MB3411namp_--