public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Platform/RasberryPi: Thermal zone
@ 2020-08-28 22:02 Jeremy Linton
  2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

This set creates a basic thermal zone, which reads the
SOC temp via a direct register read in AML. It also
adds an active cooling policy using a GPIO pin for fan
control that can optionally be enabled/disabled on either
GPIO18 (commercial fan shim board) or GPIO19 by the
user from the BDS.

it should now be possible when booted in ACPI mode to:

# sensors
acpitz-acpi-0
Adapter: ACPI interface
temp1:        +57.6C  (crit = +90.0C)

and the fan state, if enabled may be read with:

/sys/bus/acpi/devices/PNP0C06:00/PNP0C0B:00/physical_node/thermal_cooling/cur_state

while the kernel will automatically cycle the fan if the SoC
temp exceeds 60C.

Included as a byproduct of this set is a generic method
for updating values in ACPI DSDT/SSDT tables as they
are installed.

v2->v3:
  Make DSDT/SSDT PCD->Nameop update code generic
  Move the fan SSDT code back into the AcpiTable directory

v1->v2:
  Add choice of GPIO pins to the BDS menu
  Correct whitespace/etc issues from v1 review
  Add an additional cleanup patch for contextual whitespace issues

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>

Jeremy Linton (5):
  Platform/RaspberryPi4: Add a basic thermal zone
  Platform/RaspberryPi: Monitor ACPI Table installs
  Platform/RaspberryPi: Add entry for user fan control
  Platform/RaspberryPi4: Create ACPI fan object
  Platform/RaspberryPi: Trivial whitespace cleanup

 Platform/RaspberryPi/AcpiTables/AcpiTables.inf     |   1 +
 Platform/RaspberryPi/AcpiTables/Dsdt.asl           |  31 ++++
 Platform/RaspberryPi/AcpiTables/SsdtThermal.asl    |  76 ++++++++
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 205 +++++++++++++++++++--
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf    |   2 +
 .../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 +
 .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |   2 +
 12 files changed, 345 insertions(+), 14 deletions(-)
 create mode 100644 Platform/RaspberryPi/AcpiTables/SsdtThermal.asl

-- 
2.13.7


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone
  2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
@ 2020-08-28 22:02 ` Jeremy Linton
  2020-08-31 13:15   ` Pete Batard
  2020-08-28 22:02 ` [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Jeremy Linton
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

Rather than exporting the temp sensor or mailbox
in ACPI land we can wrap them in AML and use the default
ACPI drivers provided by the OS. This enables the use of
"sensors" in linux to report the SOC temp.

As a first pass add a basic passive cooling ACPI thermalzone
with trip points for passive cooling (throttling) handled
by the vc firmware, hibernate and critical shutdown. The
vc apparently kicks in at ~80C, so the hibernate and critical
set points are set at +5 and +10 of that. In the future
CPPC should be able to monitor the thermal throttling.

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/AcpiTables/Dsdt.asl           | 31 ++++++++++++++++++++++
 .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |  2 ++
 2 files changed, 33 insertions(+)

diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
index 353af2d876..73067aefd2 100644
--- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
+++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
@@ -252,6 +252,37 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", "RPI", 2)
         }
       })
     }
+
+    // Define a simple thermal zone. The idea here is we compute the SOC temp
+    // via a register we can read, and give it to the OS. This enables basic
+    // reports from the "sensors" utility, and the OS can then poll and take
+    // actions if that temp exceeds any of the given thresholds.
+    Device (EC0)
+    {
+      Name (_HID, EISAID ("PNP0C06"))
+      Name (_CCA, 0x0)
+
+      // all temps in are tenths of K (aka 2732 is the min temps in Linux (aka 0C))
+      ThermalZone (TZ0) {
+        Method (_TMP, 0, Serialized) {
+          OperationRegion (TEMS, SystemMemory, THERM_SENSOR, 0x8)
+          Field (TEMS, DWordAcc, NoLock, Preserve) {
+            TMPS, 32
+          }
+          return (((419949 - ((TMPS & 0x3ff) * 487)) / 100) + 2732);
+        }
+        Method (_SCP, 3) { }               // receive cooling policy from OS
+
+        Method (_CRT) { Return (3632) }    // (90C) Critical temp point (immediate power-off)
+        Method (_HOT) { Return (3582) }    // (85C) HOT state where OS should hibernate
+        Method (_PSV) { Return (3532) }    // (80C) Passive cooling (CPU throttling) trip point
+
+        // SSDT inserts _AC0/_AL0 @60C here, if a FAN is configured
+
+        Name (_TZP, 10)                   //The OSPM must poll this device every 1 seconds
+        Name (_PSL, Package () { \_SB_.CPU0, \_SB_.CPU1, \_SB_.CPU2, \_SB_.CPU3 })
+      }
+    }
 #endif
 
   }
diff --git a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
index e9c81cafa1..86906b2438 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 (PcdBcmGenetRegistersAddress)
 #define GENET_LENGTH               0x00010000
 
+#define THERM_SENSOR               0xfd5d2200
+
 #endif /* BCM2711_H__ */
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs
  2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
  2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
@ 2020-08-28 22:02 ` Jeremy Linton
  2020-08-31 13:17   ` Pete Batard
  2020-08-28 22:02 ` [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control Jeremy Linton
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

Hook the ACPI table install sequence and add some
basic conditional and AML NameOp update logic. If
a table has a non-zero PCD declared that pcd is
checked for a non-zero value before allowing the table
to be installed. We also add a table of NameOp to
PCD's which will be written into a DSDT/SSDT table
as part of its install process.

With this change we can declare something in
ASL like:

Name (VARN, 0x1234)

and then add a table entry like:

{"VARN", PcdToken(PcdVarn)}

and the value of PcdVarn will replace the
0x1234 declared in the ASL above.

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>
---
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 153 ++++++++++++++++++++-
 1 file changed, 152 insertions(+), 1 deletion(-)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index af54136ade..9e5d9734ca 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -568,6 +568,156 @@ ApplyVariables (
 }
 
 
+typedef struct {
+  CHAR8 Name[4];
+  UINTN PcdToken;
+} AML_NAME_OP_REPLACE;
+
+typedef struct {
+  UINT64              OemTableId;
+  UINTN               PcdToken;
+  AML_NAME_OP_REPLACE *SdtNameOpReplace;
+} NAMESPACE_TABLES;
+
+#define SSDT_PATTERN_LEN 5
+#define AML_NAMEOP_8   0x0A
+#define AML_NAMEOP_16  0x0B
+#define AML_NAMEOP_32  0x0C
+#define AML_NAMEOP_STR 0x0D
+/*
+ * Scan the given namespace table (DSDT/SSDT) for AML NameOps
+ * listed in the NameOpReplace structure. If one is found then
+ * update the value in the table from the specified Pcd
+ *
+ * This allows us to have conditionals in AML controlled
+ * by options in the BDS or detected during firmware bootstrap.
+ * We could extend this concept for strings/etc but due to len
+ * variations its probably easier to encode the strings
+ * in the ASL and pick the correct one based off a variable.
+ */
+STATIC VOID
+UpdateSdtNameOps(
+  EFI_ACPI_DESCRIPTION_HEADER  *AcpiTable,
+  AML_NAME_OP_REPLACE          *NameOpReplace
+  )
+{
+  UINTN  Idx;
+  UINTN  Index;
+  CHAR8  Pattern[SSDT_PATTERN_LEN];
+  UINTN  PcdVal;
+  UINT8  *SdtPtr;
+  UINT32 SdtSize;
+
+  SdtSize = AcpiTable->Length;
+
+  if (SdtSize > 0) {
+    SdtPtr = (UINT8*)AcpiTable;
+
+    for (Idx = 0; NameOpReplace && NameOpReplace[Idx].PcdToken; Idx++) {
+      /*
+       * Do a single NameOp variable replacement these are of the
+       * form 08 XXXX SIZE VAL, where SIZE is 0A=byte, 0B=word, 0C=dword
+       * and XXXX is the name and VAL is the value
+      */
+      Pattern[0] = 0x08;
+      Pattern[1] = NameOpReplace[Idx].Name[0];
+      Pattern[2] = NameOpReplace[Idx].Name[1];
+      Pattern[3] = NameOpReplace[Idx].Name[2];
+      Pattern[4] = NameOpReplace[Idx].Name[3];
+
+      for (Index = 0; Index < (SdtSize - SSDT_PATTERN_LEN); Index++) {
+        if (CompareMem (SdtPtr + Index, Pattern, SSDT_PATTERN_LEN) == 0) {
+          PcdVal = LibPcdGet32 (NameOpReplace[Idx].PcdToken);
+          switch (SdtPtr[Index + SSDT_PATTERN_LEN]) {
+          case AML_NAMEOP_32:
+            SdtPtr[Index + SSDT_PATTERN_LEN + 4] = (PcdVal >> 24) & 0xFF;
+            SdtPtr[Index + SSDT_PATTERN_LEN + 3] = (PcdVal >> 16) & 0xFF;
+            // Fallthrough
+          case AML_NAMEOP_16:
+            SdtPtr[Index + SSDT_PATTERN_LEN + 2] = (PcdVal >> 8) & 0xFF;
+            // Fallthrough
+          case AML_NAMEOP_8:
+            SdtPtr[Index + SSDT_PATTERN_LEN + 1] = PcdVal & 0xFF;
+            break;
+          case 0:
+          case 1:
+            SdtPtr[Index + SSDT_PATTERN_LEN + 1] = !!PcdVal;
+            break;
+          case AML_NAMEOP_STR:
+            /*
+             * If the string val is added to the NameOpReplace, we can
+             * dynamically update things like _HID too as long as the
+             * string length matches.
+             */
+            break;
+          }
+          break;
+        }
+      }
+    }
+  }
+}
+
+
+STATIC BOOLEAN
+VerifyUpdateTable(
+  IN  EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader,
+  IN  NAMESPACE_TABLES *SdtTable
+  )
+{
+  BOOLEAN ret;
+
+  ret = TRUE;
+  if (SdtTable->PcdToken && !LibPcdGet32 (SdtTable->PcdToken)) {
+    ret = FALSE;
+  }
+  if (ret && SdtTable->SdtNameOpReplace) {
+    UpdateSdtNameOps (AcpiHeader, SdtTable->SdtNameOpReplace);
+  }
+
+  return ret;
+}
+
+
+STATIC NAMESPACE_TABLES SdtTables[] = {
+  {
+    SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
+    0,
+    NULL
+  },
+  { }
+};
+
+/*
+ * Monitor the ACPI tables being installed and when
+ * a DSDT/SSDT is detected validate that we want to
+ * install it, and if so update any "NameOp" defined
+ * variables contained in the table from PCD values
+ */
+STATIC BOOLEAN
+HandleDynamicNamespace (
+  IN  EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader
+  )
+{
+  UINTN Tables;
+
+  switch (AcpiHeader->Signature) {
+  case SIGNATURE_32 ('D', 'S', 'D', 'T'):
+  case SIGNATURE_32 ('S', 'S', 'D', 'T'):
+    for (Tables = 0; SdtTables[Tables].OemTableId; Tables++) {
+      if (AcpiHeader->OemTableId == SdtTables[Tables].OemTableId) {
+        return VerifyUpdateTable (AcpiHeader, &SdtTables[Tables]);
+      }
+    }
+    DEBUG ((DEBUG_ERROR, "Found namespace table not in table list.\n"));
+
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+
 EFI_STATUS
 EFIAPI
 ConfigInitialize (
@@ -618,7 +768,8 @@ ConfigInitialize (
 
   if (PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_ACPI ||
       PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_BOTH) {
-     Status = LocateAndInstallAcpiFromFv (&mAcpiTableFile);
+     Status = LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile,
+                                                     &HandleDynamicNamespace);
      ASSERT_EFI_ERROR (Status);
   }
 
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control
  2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
  2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
  2020-08-28 22:02 ` [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Jeremy Linton
@ 2020-08-28 22:02 ` Jeremy Linton
  2020-08-31 13:17   ` Pete Batard
  2020-08-28 22:02 ` [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object Jeremy Linton
  2020-08-28 22:02 ` [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup Jeremy Linton
  4 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

Add a menu item that allows the user to enable GPIO based
fan control via SSDT and the previous NameObj replacement
commit. This should only be seen/enabled on RPI4
because that is what its been tested with.

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. Alternatively there are some commercial
boards (FAN SHIM) which operate via simple GPIO control.

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 | 26 ++++++++++++++++++++++
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf    |  2 ++
 .../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, 70 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index 9e5d9734ca..d58cbbdfe7 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 = sizeof (UINT32);
+  Status = gRT->GetVariable (L"FanOnGpio",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));
+  }
+
   Size = sizeof(AssetTagVar);
 
   Status = gRT->GetVariable(L"AssetTag",
@@ -368,6 +378,7 @@ ApplyVariables (
   UINT32 CpuClock = PcdGet32 (PcdCpuClock);
   UINT32 CustomCpuClock = PcdGet32 (PcdCustomCpuClock);
   UINT32 Rate = 0;
+  UINT32 FanOnGpio = PcdGet32 (PcdFanOnGpio);
 
   switch (CpuClock) {
   case CHIPSET_CPU_CLOCK_LOW:
@@ -565,6 +576,11 @@ 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);
+  }
 }
 
 
@@ -679,8 +695,18 @@ VerifyUpdateTable(
 }
 
 
+STATIC AML_NAME_OP_REPLACE SsdtNameOpReplace[] = {
+  {"GIOP", PcdToken(PcdFanOnGpio)},
+  {}
+};
+
 STATIC NAMESPACE_TABLES SdtTables[] = {
   {
+    SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', 'N'),
+    PcdToken(PcdFanOnGpio),
+    SsdtNameOpReplace
+  },
+  {
     SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
     0,
     NULL
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
index cdce35bc74..321e402e65 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
@@ -46,6 +46,7 @@
   AcpiLib
   BaseLib
   DebugLib
+  DxeServicesLib
   DxeServicesTableLib
   GpioLib
   HiiLib
@@ -89,6 +90,7 @@
   gRaspberryPiTokenSpaceGuid.PcdSystemTableMode
   gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB
   gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB
+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio
 
 [Depex]
   gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Platform/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 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/Platform/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  = RamLimitTo3GB,
       guid  = CONFIGDXE_FORM_SET_GUID;
 
+    efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = FanOnGpio,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
     efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
       attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
       name  = SystemTableMode,
@@ -174,6 +180,18 @@ formset
             option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = SYSTEM_TABLE_MODE_DT, flags = DEFAULT;
         endoneof;
 
+#if (RPI_MODEL == 4)
+        grayoutif NOT ideqval SystemTableMode.Mode == SYSTEM_TABLE_MODE_ACPI;
+          oneof varid = FanOnGpio.Enabled,
+              prompt      = STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT),
+              help        = STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP),
+              flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), value = 0, flags = DEFAULT;
+              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), value = 18, flags = 0;
+              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), value = 19, flags = 0;
+          endoneof;
+        endif;
+#endif
         string varid = AssetTag.AssetTag,
             prompt  = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
             help    = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),
diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/RaspberryPi/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"|gConfigDxeFormSetGuid|0x0|1
 
   #
+  # Enable a fan in the ACPI thermal zone on GPIO pin #
+  #
+  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGuid|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"|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"|gConfigDxeFormSetGuid|0x0|0
+
+  #
   # Common UEFI ones.
   #
 
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object
  2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
                   ` (2 preceding siblings ...)
  2020-08-28 22:02 ` [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control Jeremy Linton
@ 2020-08-28 22:02 ` Jeremy Linton
  2020-08-31 13:17   ` Pete Batard
  2020-08-28 22:02 ` [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup Jeremy Linton
  4 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

Now that we have a thermal zone we can add active cooling
by specifying active cooling points (_ACx) which can
be tied to fan objects that turn fans on/off using GPIO
pins.

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/AcpiTables/AcpiTables.inf  |  1 +
 Platform/RaspberryPi/AcpiTables/SsdtThermal.asl | 76 +++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 Platform/RaspberryPi/AcpiTables/SsdtThermal.asl

diff --git a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
index 28d2afe197..c40c32e16f 100644
--- a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
+++ b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
@@ -33,6 +33,7 @@
   Csrt.aslc
   Spcr.aslc
   Pptt.aslc
+  SsdtThermal.asl
 
 [Packages]
   ArmPkg/ArmPkg.dec
diff --git a/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl b/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl
new file mode 100644
index 0000000000..28c88cd640
--- /dev/null
+++ b/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl
@@ -0,0 +1,76 @@
+/** @file
+ *
+ *  Secondary System Description Table (SSDT) for active (fan) cooling
+ *
+ *  Copyright (c) 2020, Arm Ltd. All rights reserved.
+ *
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#include <IndustryStandard/Bcm2711.h>
+#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Gpio.h>
+
+#include <IndustryStandard/Acpi.h>
+
+DefinitionBlock (__FILE__, "SSDT", 5, "RPIFDN", "RPITHFAN", 2)
+{
+  External (\_SB_.EC0, DeviceObj)
+  External (\_SB_.EC0.TZ0, DeviceObj)
+
+  Scope (\_SB_.EC0)
+  {
+    // Define a NameOp we will modify during InstallTable
+    Name (GIOP, 0x2) //08 47 49 4f 50 0a 02 (value must be >1)
+    // Describe a fan
+    PowerResource (PFAN, 0, 0) {
+      OperationRegion (GPIO, SystemMemory, GPIO_BASE_ADDRESS, 0x1000)
+      Field (GPIO, DWordAcc, NoLock, Preserve) {
+        Offset (0x1C),
+        GPS0, 32,
+        GPS1, 32,
+        RES1, 32,
+        GPC0, 32,
+        GPC1, 32,
+        RES2, 32,
+        GPL1, 32,
+        GPL2, 32
+      }
+      // We are hitting a GPIO pin to on/off a fan.
+      // This assumes that UEFI has programmed the
+      // direction as OUT. Given the current limitations
+      // on the GPIO pins, its recommended to use
+      // the GPIO to switch a larger voltage/current
+      // for the fan rather than driving it directly.
+      Method (_STA) {
+        if (GPL1 & (1 << GIOP)) {
+          Return (1)                 // present and enabled
+        }
+        Return (0)
+      }
+      Method (_ON)  {                //turn fan on
+        Store (1 << GIOP, GPS0)
+      }
+      Method (_OFF) {                //turn fan off
+        Store (1 << GIOP, GPC0)
+      }
+    }
+    Device (FAN) {
+      // Note, not currently an ACPIv4 fan
+      // the latter adds speed control/detection
+      // but in the case of linux needs FIF, FPS, FSL, and FST
+      Name (_HID, EISAID ("PNP0C0B"))
+      Name (_PR0, Package () { PFAN })
+    }
+  }
+
+  // merge in an active cooling point.
+  Scope (\_SB_.EC0.TZ0)
+  {
+    Method (_AC0) { Return (3332) }        // (60C) active cooling trip point,
+                                           // if this is lower than PSV then we
+                                           // prefer active cooling
+    Name (_AL0, Package () { \_SB_.EC0.FAN }) // the fan used for AC0 above
+  }
+}
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup
  2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
                   ` (3 preceding siblings ...)
  2020-08-28 22:02 ` [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object Jeremy Linton
@ 2020-08-28 22:02 ` Jeremy Linton
  2020-08-31 13:17   ` Pete Batard
  4 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-28 22:02 UTC (permalink / raw)
  To: devel
  Cc: Jeremy Linton, Leif Lindholm, Pete Batard, Andrei Warkentin,
	Ard Biesheuvel, Samer El-Haj-Mahmoud

Pete's review pointed out some whitespace issues in the
context of a previous patch. Since there are a number of
similar errors in the file lets fix them separately.

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>
---
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index d58cbbdfe7..2712194d2b 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -209,9 +209,9 @@ SetupVariables (
   }
 
   Size = sizeof (UINT32);
-  Status = gRT->GetVariable(L"CustomCpuClock",
-                            &gConfigDxeFormSetGuid,
-                            NULL, &Size, &Var32);
+  Status = gRT->GetVariable (L"CustomCpuClock",
+                             &gConfigDxeFormSetGuid,
+                             NULL, &Size, &Var32);
   if (EFI_ERROR (Status)) {
     Status = PcdSet32S (PcdCustomCpuClock, PcdGet32 (PcdCustomCpuClock));
     ASSERT_EFI_ERROR (Status);
@@ -256,9 +256,9 @@ SetupVariables (
     PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));
   }
 
-  Size = sizeof(AssetTagVar);
+  Size = sizeof (AssetTagVar);
 
-  Status = gRT->GetVariable(L"AssetTag",
+  Status = gRT->GetVariable (L"AssetTag",
                   &gConfigDxeFormSetGuid,
                   NULL, &Size, AssetTagVar);
 
@@ -267,7 +267,7 @@ SetupVariables (
                     L"AssetTag",
                     &gConfigDxeFormSetGuid,
                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-                    sizeof(AssetTagVar),
+                    sizeof (AssetTagVar),
                     AssetTagVar
                     );
   }
@@ -433,9 +433,9 @@ ApplyVariables (
      * spaces. SystemMemorySizeBelow4GB tracks the maximum memory below 4GB
      * line, factoring in the limit imposed by the SoC register range.
      */
-    SystemMemorySizeBelow4GB = MIN(SystemMemorySize, 4UL * SIZE_1GB);
-    SystemMemorySizeBelow4GB = MIN(SystemMemorySizeBelow4GB, BCM2836_SOC_REGISTERS);
-    SystemMemorySizeBelow4GB = MIN(SystemMemorySizeBelow4GB, BCM2711_SOC_REGISTERS);
+    SystemMemorySizeBelow4GB = MIN (SystemMemorySize, 4UL * SIZE_1GB);
+    SystemMemorySizeBelow4GB = MIN (SystemMemorySizeBelow4GB, BCM2836_SOC_REGISTERS);
+    SystemMemorySizeBelow4GB = MIN (SystemMemorySizeBelow4GB, BCM2711_SOC_REGISTERS);
 
     ASSERT (SystemMemorySizeBelow4GB > 3UL * SIZE_1GB);
 
@@ -528,14 +528,14 @@ ApplyVariables (
       /*
        * SD card pins go to Arasan.
        */
-      MmioWrite32((GPIO_BASE_ADDRESS + 0xD0),
-                  MmioRead32(GPIO_BASE_ADDRESS + 0xD0) | 0x2);
+      MmioWrite32 ((GPIO_BASE_ADDRESS + 0xD0),
+                  MmioRead32 (GPIO_BASE_ADDRESS + 0xD0) | 0x2);
     } else {
       /*
        * SD card pins back to eMMC2.
        */
-      MmioWrite32((GPIO_BASE_ADDRESS + 0xD0),
-                  MmioRead32(GPIO_BASE_ADDRESS + 0xD0) & ~0x2);
+      MmioWrite32 ((GPIO_BASE_ADDRESS + 0xD0),
+                  MmioRead32 (GPIO_BASE_ADDRESS + 0xD0) & ~0x2);
       /*
        * WiFi back to Arasan.
        */
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone
  2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
@ 2020-08-31 13:15   ` Pete Batard
  2020-08-31 15:13     ` Jeremy Linton
  0 siblings, 1 reply; 14+ messages in thread
From: Pete Batard @ 2020-08-31 13:15 UTC (permalink / raw)
  To: Jeremy Linton, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

One general, non-blocking comment below:

On 2020.08.28 23:02, Jeremy Linton wrote:
> Rather than exporting the temp sensor or mailbox
> in ACPI land we can wrap them in AML and use the default
> ACPI drivers provided by the OS. This enables the use of
> "sensors" in linux to report the SOC temp.
> 
> As a first pass add a basic passive cooling ACPI thermalzone
> with trip points for passive cooling (throttling) handled
> by the vc firmware, hibernate and critical shutdown. The
> vc apparently kicks in at ~80C, so the hibernate and critical
> set points are set at +5 and +10 of that. In the future
> CPPC should be able to monitor the thermal throttling.
> 
> 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/AcpiTables/Dsdt.asl           | 31 ++++++++++++++++++++++
>   .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |  2 ++
>   2 files changed, 33 insertions(+)
> 
> diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
> index 353af2d876..73067aefd2 100644
> --- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
> +++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
> @@ -252,6 +252,37 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", "RPI", 2)
>           }
> 
>         })
> 
>       }
> 
> +
> 
> +    // Define a simple thermal zone. The idea here is we compute the SOC temp
> 
> +    // via a register we can read, and give it to the OS. This enables basic
> 
> +    // reports from the "sensors" utility, and the OS can then poll and take
> 
> +    // actions if that temp exceeds any of the given thresholds.
> 
> +    Device (EC0)

Just going to point out that all the other ACPI devices we seem to 
define have 4 characters, so I'm not sure if we're breaking a convention 
by introducing a 3 character one here...

> 
> +    {
> 
> +      Name (_HID, EISAID ("PNP0C06"))
> 
> +      Name (_CCA, 0x0)
> 
> +
> 
> +      // all temps in are tenths of K (aka 2732 is the min temps in Linux (aka 0C))
> 
> +      ThermalZone (TZ0) {

Likewise, what I'm seeing by googling around for ThermalZone () names 
would be 4 character ones such as "TZ00", "TZ01" or "TZS0" (For 'Thermal 
Zone Sensor 0') or "TMZN" for single entries.

> 
> +        Method (_TMP, 0, Serialized) {
> 
> +          OperationRegion (TEMS, SystemMemory, THERM_SENSOR, 0x8)
> 
> +          Field (TEMS, DWordAcc, NoLock, Preserve) {
> 
> +            TMPS, 32
> 
> +          }
> 
> +          return (((419949 - ((TMPS & 0x3ff) * 487)) / 100) + 2732);
> 
> +        }
> 
> +        Method (_SCP, 3) { }               // receive cooling policy from OS
> 
> +
> 
> +        Method (_CRT) { Return (3632) }    // (90C) Critical temp point (immediate power-off)
> 
> +        Method (_HOT) { Return (3582) }    // (85C) HOT state where OS should hibernate
> 
> +        Method (_PSV) { Return (3532) }    // (80C) Passive cooling (CPU throttling) trip point
> 
> +
> 
> +        // SSDT inserts _AC0/_AL0 @60C here, if a FAN is configured
> 
> +
> 
> +        Name (_TZP, 10)                   //The OSPM must poll this device every 1 seconds
> 
> +        Name (_PSL, Package () { \_SB_.CPU0, \_SB_.CPU1, \_SB_.CPU2, \_SB_.CPU3 })
> 
> +      }
> 
> +    }
> 
>   #endif
> 
>   
> 
>     }
> 
> diff --git a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
> index e9c81cafa1..86906b2438 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 (PcdBcmGenetRegistersAddress)
> 
>   #define GENET_LENGTH               0x00010000
> 
>   
> 
> +#define THERM_SENSOR               0xfd5d2200
> 
> +
> 
>   #endif /* BCM2711_H__ */
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs
  2020-08-28 22:02 ` [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Jeremy Linton
@ 2020-08-31 13:17   ` Pete Batard
  0 siblings, 0 replies; 14+ messages in thread
From: Pete Batard @ 2020-08-31 13:17 UTC (permalink / raw)
  To: Jeremy Linton, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

On 2020.08.28 23:02, Jeremy Linton wrote:
> Hook the ACPI table install sequence and add some
> basic conditional and AML NameOp update logic. If
> a table has a non-zero PCD declared that pcd is
> checked for a non-zero value before allowing the table
> to be installed. We also add a table of NameOp to
> PCD's which will be written into a DSDT/SSDT table
> as part of its install process.
> 
> With this change we can declare something in
> ASL like:
> 
> Name (VARN, 0x1234)
> 
> and then add a table entry like:
> 
> {"VARN", PcdToken(PcdVarn)}
> 
> and the value of PcdVarn will replace the
> 0x1234 declared in the ASL above.
> 
> 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>
> ---
>   Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 153 ++++++++++++++++++++-
>   1 file changed, 152 insertions(+), 1 deletion(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> index af54136ade..9e5d9734ca 100644
> --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> @@ -568,6 +568,156 @@ ApplyVariables (
>   }
> 
>   
> 
>   
> 
> +typedef struct {
> 
> +  CHAR8 Name[4];
> 
> +  UINTN PcdToken;
> 
> +} AML_NAME_OP_REPLACE;
> 
> +
> 
> +typedef struct {
> 
> +  UINT64              OemTableId;
> 
> +  UINTN               PcdToken;
> 
> +  AML_NAME_OP_REPLACE *SdtNameOpReplace;
> 
> +} NAMESPACE_TABLES;
> 
> +
> 
> +#define SSDT_PATTERN_LEN 5
> 
> +#define AML_NAMEOP_8   0x0A
> 
> +#define AML_NAMEOP_16  0x0B
> 
> +#define AML_NAMEOP_32  0x0C
> 
> +#define AML_NAMEOP_STR 0x0D
> 
> +/*
> 
> + * Scan the given namespace table (DSDT/SSDT) for AML NameOps
> 
> + * listed in the NameOpReplace structure. If one is found then
> 
> + * update the value in the table from the specified Pcd
> 
> + *
> 
> + * This allows us to have conditionals in AML controlled
> 
> + * by options in the BDS or detected during firmware bootstrap.
> 
> + * We could extend this concept for strings/etc but due to len
> 
> + * variations its probably easier to encode the strings
> 
> + * in the ASL and pick the correct one based off a variable.
> 
> + */
> 
> +STATIC VOID
> 
> +UpdateSdtNameOps(
> 
> +  EFI_ACPI_DESCRIPTION_HEADER  *AcpiTable,
> 
> +  AML_NAME_OP_REPLACE          *NameOpReplace
> 
> +  )
> 
> +{
> 
> +  UINTN  Idx;
> 
> +  UINTN  Index;
> 
> +  CHAR8  Pattern[SSDT_PATTERN_LEN];
> 
> +  UINTN  PcdVal;
> 
> +  UINT8  *SdtPtr;
> 
> +  UINT32 SdtSize;
> 
> +
> 
> +  SdtSize = AcpiTable->Length;
> 
> +
> 
> +  if (SdtSize > 0) {
> 
> +    SdtPtr = (UINT8*)AcpiTable;
> 
> +
> 
> +    for (Idx = 0; NameOpReplace && NameOpReplace[Idx].PcdToken; Idx++) {
> 
> +      /*
> 
> +       * Do a single NameOp variable replacement these are of the
> 
> +       * form 08 XXXX SIZE VAL, where SIZE is 0A=byte, 0B=word, 0C=dword
> 
> +       * and XXXX is the name and VAL is the value
> 
> +      */
> 
> +      Pattern[0] = 0x08;
> 
> +      Pattern[1] = NameOpReplace[Idx].Name[0];
> 
> +      Pattern[2] = NameOpReplace[Idx].Name[1];
> 
> +      Pattern[3] = NameOpReplace[Idx].Name[2];
> 
> +      Pattern[4] = NameOpReplace[Idx].Name[3];
> 
> +
> 
> +      for (Index = 0; Index < (SdtSize - SSDT_PATTERN_LEN); Index++) {
> 
> +        if (CompareMem (SdtPtr + Index, Pattern, SSDT_PATTERN_LEN) == 0) {
> 
> +          PcdVal = LibPcdGet32 (NameOpReplace[Idx].PcdToken);
> 
> +          switch (SdtPtr[Index + SSDT_PATTERN_LEN]) {
> 
> +          case AML_NAMEOP_32:
> 
> +            SdtPtr[Index + SSDT_PATTERN_LEN + 4] = (PcdVal >> 24) & 0xFF;
> 
> +            SdtPtr[Index + SSDT_PATTERN_LEN + 3] = (PcdVal >> 16) & 0xFF;
> 
> +            // Fallthrough
> 
> +          case AML_NAMEOP_16:
> 
> +            SdtPtr[Index + SSDT_PATTERN_LEN + 2] = (PcdVal >> 8) & 0xFF;
> 
> +            // Fallthrough
> 
> +          case AML_NAMEOP_8:
> 
> +            SdtPtr[Index + SSDT_PATTERN_LEN + 1] = PcdVal & 0xFF;
> 
> +            break;
> 
> +          case 0:
> 
> +          case 1:
> 
> +            SdtPtr[Index + SSDT_PATTERN_LEN + 1] = !!PcdVal;
> 
> +            break;
> 
> +          case AML_NAMEOP_STR:
> 
> +            /*
> 
> +             * If the string val is added to the NameOpReplace, we can
> 
> +             * dynamically update things like _HID too as long as the
> 
> +             * string length matches.
> 
> +             */
> 
> +            break;
> 
> +          }
> 
> +          break;
> 
> +        }
> 
> +      }
> 
> +    }
> 
> +  }
> 
> +}
> 
> +
> 
> +
> 
> +STATIC BOOLEAN
> 
> +VerifyUpdateTable(
> 
> +  IN  EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader,
> 
> +  IN  NAMESPACE_TABLES *SdtTable
> 
> +  )
> 
> +{
> 
> +  BOOLEAN ret;
> 
> +
> 
> +  ret = TRUE;
> 
> +  if (SdtTable->PcdToken && !LibPcdGet32 (SdtTable->PcdToken)) {
> 
> +    ret = FALSE;
> 
> +  }
> 
> +  if (ret && SdtTable->SdtNameOpReplace) {
> 
> +    UpdateSdtNameOps (AcpiHeader, SdtTable->SdtNameOpReplace);
> 
> +  }
> 
> +
> 
> +  return ret;
> 
> +}
> 
> +
> 
> +
> 
> +STATIC NAMESPACE_TABLES SdtTables[] = {
> 
> +  {
> 
> +    SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
> 
> +    0,
> 
> +    NULL
> 
> +  },
> 
> +  { }
> 
> +};
> 
> +
> 
> +/*
> 
> + * Monitor the ACPI tables being installed and when
> 
> + * a DSDT/SSDT is detected validate that we want to
> 
> + * install it, and if so update any "NameOp" defined
> 
> + * variables contained in the table from PCD values
> 
> + */
> 
> +STATIC BOOLEAN
> 
> +HandleDynamicNamespace (
> 
> +  IN  EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader
> 
> +  )
> 
> +{
> 
> +  UINTN Tables;
> 
> +
> 
> +  switch (AcpiHeader->Signature) {
> 
> +  case SIGNATURE_32 ('D', 'S', 'D', 'T'):
> 
> +  case SIGNATURE_32 ('S', 'S', 'D', 'T'):
> 
> +    for (Tables = 0; SdtTables[Tables].OemTableId; Tables++) {
> 
> +      if (AcpiHeader->OemTableId == SdtTables[Tables].OemTableId) {
> 
> +        return VerifyUpdateTable (AcpiHeader, &SdtTables[Tables]);
> 
> +      }
> 
> +    }
> 
> +    DEBUG ((DEBUG_ERROR, "Found namespace table not in table list.\n"));
> 
> +
> 
> +    return FALSE;
> 
> +  }
> 
> +
> 
> +  return TRUE;
> 
> +}
> 
> +
> 
> +
> 
>   EFI_STATUS
> 
>   EFIAPI
> 
>   ConfigInitialize (
> 
> @@ -618,7 +768,8 @@ ConfigInitialize (
>   
> 
>     if (PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_ACPI ||
> 
>         PcdGet32 (PcdSystemTableMode) == SYSTEM_TABLE_MODE_BOTH) {
> 
> -     Status = LocateAndInstallAcpiFromFv (&mAcpiTableFile);
> 
> +     Status = LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile,
> 
> +                                                     &HandleDynamicNamespace);
> 
>        ASSERT_EFI_ERROR (Status);
> 
>     }
> 
>   
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control
  2020-08-28 22:02 ` [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control Jeremy Linton
@ 2020-08-31 13:17   ` Pete Batard
  0 siblings, 0 replies; 14+ messages in thread
From: Pete Batard @ 2020-08-31 13:17 UTC (permalink / raw)
  To: Jeremy Linton, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

On 2020.08.28 23:02, Jeremy Linton wrote:
> Add a menu item that allows the user to enable GPIO based
> fan control via SSDT and the previous NameObj replacement
> commit. This should only be seen/enabled on RPI4
> because that is what its been tested with.
> 
> 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. Alternatively there are some commercial
> boards (FAN SHIM) which operate via simple GPIO control.
> 
> 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 | 26 ++++++++++++++++++++++
>   .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf    |  2 ++
>   .../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, 70 insertions(+)
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> index 9e5d9734ca..d58cbbdfe7 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 = sizeof (UINT32);
> 
> +  Status = gRT->GetVariable (L"FanOnGpio",
> 
> +                  &gConfigDxeFormSetGuid,
> 
> +                  NULL, &Size, &Var32);
> 
> +  if (EFI_ERROR (Status)) {
> 
> +    PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));
> 
> +  }
> 
> +
> 
>     Size = sizeof(AssetTagVar);
> 
>   
> 
>     Status = gRT->GetVariable(L"AssetTag",
> 
> @@ -368,6 +378,7 @@ ApplyVariables (
>     UINT32 CpuClock = PcdGet32 (PcdCpuClock);
> 
>     UINT32 CustomCpuClock = PcdGet32 (PcdCustomCpuClock);
> 
>     UINT32 Rate = 0;
> 
> +  UINT32 FanOnGpio = PcdGet32 (PcdFanOnGpio);
> 
>   
> 
>     switch (CpuClock) {
> 
>     case CHIPSET_CPU_CLOCK_LOW:
> 
> @@ -565,6 +576,11 @@ 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);
> 
> +  }
> 
>   }
> 
>   
> 
>   
> 
> @@ -679,8 +695,18 @@ VerifyUpdateTable(
>   }
> 
>   
> 
>   
> 
> +STATIC AML_NAME_OP_REPLACE SsdtNameOpReplace[] = {
> 
> +  {"GIOP", PcdToken(PcdFanOnGpio)},
> 
> +  {}
> 
> +};
> 
> +
> 
>   STATIC NAMESPACE_TABLES SdtTables[] = {
> 
>     {
> 
> +    SIGNATURE_64 ('R', 'P', 'I', 'T', 'H', 'F', 'A', 'N'),
> 
> +    PcdToken(PcdFanOnGpio),
> 
> +    SsdtNameOpReplace
> 
> +  },
> 
> +  {
> 
>       SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
> 
>       0,
> 
>       NULL
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> index cdce35bc74..321e402e65 100644
> --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> @@ -46,6 +46,7 @@
>     AcpiLib
> 
>     BaseLib
> 
>     DebugLib
> 
> +  DxeServicesLib
> 
>     DxeServicesTableLib
> 
>     GpioLib
> 
>     HiiLib
> 
> @@ -89,6 +90,7 @@
>     gRaspberryPiTokenSpaceGuid.PcdSystemTableMode
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamMoreThan3GB
> 
>     gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio
> 
>   
> 
>   [Depex]
> 
>     gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Platform/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 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/Platform/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  = RamLimitTo3GB,
> 
>         guid  = CONFIGDXE_FORM_SET_GUID;
> 
>   
> 
> +    efivarstore ADVANCED_FAN_ON_GPIO_VARSTORE_DATA,
> 
> +      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
> 
> +      name  = FanOnGpio,
> 
> +      guid  = CONFIGDXE_FORM_SET_GUID;
> 
> +
> 
>       efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
> 
>         attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
> 
>         name  = SystemTableMode,
> 
> @@ -174,6 +180,18 @@ formset
>               option text = STRING_TOKEN(STR_ADVANCED_SYSTAB_DT), value = SYSTEM_TABLE_MODE_DT, flags = DEFAULT;
> 
>           endoneof;
> 
>   
> 
> +#if (RPI_MODEL == 4)
> 
> +        grayoutif NOT ideqval SystemTableMode.Mode == SYSTEM_TABLE_MODE_ACPI;
> 
> +          oneof varid = FanOnGpio.Enabled,
> 
> +              prompt      = STRING_TOKEN(STR_ADVANCED_FANONGPIO_PROMPT),
> 
> +              help        = STRING_TOKEN(STR_ADVANCED_FANONGPIO_HELP),
> 
> +              flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_OFF), value = 0, flags = DEFAULT;
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_18), value = 18, flags = 0;
> 
> +              option text = STRING_TOKEN(STR_ADVANCED_FANONGPIO_19), value = 19, flags = 0;
> 
> +          endoneof;
> 
> +        endif;
> 
> +#endif
> 
>           string varid = AssetTag.AssetTag,
> 
>               prompt  = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
> 
>               help    = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_HELP),
> 
> diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/RaspberryPi/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"|gConfigDxeFormSetGuid|0x0|1
> 
>   
> 
>     #
> 
> +  # Enable a fan in the ACPI thermal zone on GPIO pin #
> 
> +  #
> 
> +  gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGuid|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"|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"|gConfigDxeFormSetGuid|0x0|0
> 
> +
> 
> +  #
> 
>     # Common UEFI ones.
> 
>     #
> 
>   
> 
> diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.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
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object
  2020-08-28 22:02 ` [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object Jeremy Linton
@ 2020-08-31 13:17   ` Pete Batard
  0 siblings, 0 replies; 14+ messages in thread
From: Pete Batard @ 2020-08-31 13:17 UTC (permalink / raw)
  To: Jeremy Linton, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

3 non-blocking whitespace in comments remarks, for consistency.

And of course, same non blocking general remark as 1/5 of whether we may 
ultimately prefer to go with 4-char names for EC0/TZ0...

On 2020.08.28 23:02, Jeremy Linton wrote:
> Now that we have a thermal zone we can add active cooling
> by specifying active cooling points (_ACx) which can
> be tied to fan objects that turn fans on/off using GPIO
> pins.
> 
> 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/AcpiTables/AcpiTables.inf  |  1 +
>   Platform/RaspberryPi/AcpiTables/SsdtThermal.asl | 76 +++++++++++++++++++++++++
>   2 files changed, 77 insertions(+)
>   create mode 100644 Platform/RaspberryPi/AcpiTables/SsdtThermal.asl
> 
> diff --git a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
> index 28d2afe197..c40c32e16f 100644
> --- a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
> +++ b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
> @@ -33,6 +33,7 @@
>     Csrt.aslc
> 
>     Spcr.aslc
> 
>     Pptt.aslc
> 
> +  SsdtThermal.asl
> 
>   
> 
>   [Packages]
> 
>     ArmPkg/ArmPkg.dec
> 
> diff --git a/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl b/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl
> new file mode 100644
> index 0000000000..28c88cd640
> --- /dev/null
> +++ b/Platform/RaspberryPi/AcpiTables/SsdtThermal.asl
> @@ -0,0 +1,76 @@
> +/** @file
> + *
> + *  Secondary System Description Table (SSDT) for active (fan) cooling
> + *
> + *  Copyright (c) 2020, Arm Ltd. All rights reserved.
> + *
> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
> + *
> + **/
> +
> +#include <IndustryStandard/Bcm2711.h>
> +#include <IndustryStandard/Bcm2836.h>
> +#include <IndustryStandard/Bcm2836Gpio.h>
> +
> +#include <IndustryStandard/Acpi.h>
> +
> +DefinitionBlock (__FILE__, "SSDT", 5, "RPIFDN", "RPITHFAN", 2)
> +{
> +  External (\_SB_.EC0, DeviceObj)
> +  External (\_SB_.EC0.TZ0, DeviceObj)
> +
> +  Scope (\_SB_.EC0)
> +  {
> +    // Define a NameOp we will modify during InstallTable
> +    Name (GIOP, 0x2) //08 47 49 4f 50 0a 02 (value must be >1)

To be consistent with the other comments I'd put a space after //

> +    // Describe a fan
> +    PowerResource (PFAN, 0, 0) {
> +      OperationRegion (GPIO, SystemMemory, GPIO_BASE_ADDRESS, 0x1000)
> +      Field (GPIO, DWordAcc, NoLock, Preserve) {
> +        Offset (0x1C),
> +        GPS0, 32,
> +        GPS1, 32,
> +        RES1, 32,
> +        GPC0, 32,
> +        GPC1, 32,
> +        RES2, 32,
> +        GPL1, 32,
> +        GPL2, 32
> +      }
> +      // We are hitting a GPIO pin to on/off a fan.
> +      // This assumes that UEFI has programmed the
> +      // direction as OUT. Given the current limitations
> +      // on the GPIO pins, its recommended to use
> +      // the GPIO to switch a larger voltage/current
> +      // for the fan rather than driving it directly.
> +      Method (_STA) {
> +        if (GPL1 & (1 << GIOP)) {
> +          Return (1)                 // present and enabled
> +        }
> +        Return (0)
> +      }
> +      Method (_ON)  {                //turn fan on

Space after //

> +        Store (1 << GIOP, GPS0)
> +      }
> +      Method (_OFF) {                //turn fan off

Space after //

> +        Store (1 << GIOP, GPC0)
> +      }
> +    }
> +    Device (FAN) {
> +      // Note, not currently an ACPIv4 fan
> +      // the latter adds speed control/detection
> +      // but in the case of linux needs FIF, FPS, FSL, and FST
> +      Name (_HID, EISAID ("PNP0C0B"))
> +      Name (_PR0, Package () { PFAN })
> +    }
> +  }
> +
> +  // merge in an active cooling point.
> +  Scope (\_SB_.EC0.TZ0)
> +  {
> +    Method (_AC0) { Return (3332) }        // (60C) active cooling trip point,
> +                                           // if this is lower than PSV then we
> +                                           // prefer active cooling
> +    Name (_AL0, Package () { \_SB_.EC0.FAN }) // the fan used for AC0 above
> +  }
> +}
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup
  2020-08-28 22:02 ` [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup Jeremy Linton
@ 2020-08-31 13:17   ` Pete Batard
  0 siblings, 0 replies; 14+ messages in thread
From: Pete Batard @ 2020-08-31 13:17 UTC (permalink / raw)
  To: Jeremy Linton, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

Thanks for this.

On 2020.08.28 23:02, Jeremy Linton wrote:
> Pete's review pointed out some whitespace issues in the
> context of a previous patch. Since there are a number of
> similar errors in the file lets fix them separately.
> 
> 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>
> ---
>   Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 26 +++++++++++-----------
>   1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> index d58cbbdfe7..2712194d2b 100644
> --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
> @@ -209,9 +209,9 @@ SetupVariables (
>     }
> 
>   
> 
>     Size = sizeof (UINT32);
> 
> -  Status = gRT->GetVariable(L"CustomCpuClock",
> 
> -                            &gConfigDxeFormSetGuid,
> 
> -                            NULL, &Size, &Var32);
> 
> +  Status = gRT->GetVariable (L"CustomCpuClock",
> 
> +                             &gConfigDxeFormSetGuid,
> 
> +                             NULL, &Size, &Var32);
> 
>     if (EFI_ERROR (Status)) {
> 
>       Status = PcdSet32S (PcdCustomCpuClock, PcdGet32 (PcdCustomCpuClock));
> 
>       ASSERT_EFI_ERROR (Status);
> 
> @@ -256,9 +256,9 @@ SetupVariables (
>       PcdSet32 (PcdFanOnGpio, PcdGet32 (PcdFanOnGpio));
> 
>     }
> 
>   
> 
> -  Size = sizeof(AssetTagVar);
> 
> +  Size = sizeof (AssetTagVar);
> 
>   
> 
> -  Status = gRT->GetVariable(L"AssetTag",
> 
> +  Status = gRT->GetVariable (L"AssetTag",
> 
>                     &gConfigDxeFormSetGuid,
> 
>                     NULL, &Size, AssetTagVar);
> 
>   
> 
> @@ -267,7 +267,7 @@ SetupVariables (
>                       L"AssetTag",
> 
>                       &gConfigDxeFormSetGuid,
> 
>                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
> 
> -                    sizeof(AssetTagVar),
> 
> +                    sizeof (AssetTagVar),
> 
>                       AssetTagVar
> 
>                       );
> 
>     }
> 
> @@ -433,9 +433,9 @@ ApplyVariables (
>        * spaces. SystemMemorySizeBelow4GB tracks the maximum memory below 4GB
> 
>        * line, factoring in the limit imposed by the SoC register range.
> 
>        */
> 
> -    SystemMemorySizeBelow4GB = MIN(SystemMemorySize, 4UL * SIZE_1GB);
> 
> -    SystemMemorySizeBelow4GB = MIN(SystemMemorySizeBelow4GB, BCM2836_SOC_REGISTERS);
> 
> -    SystemMemorySizeBelow4GB = MIN(SystemMemorySizeBelow4GB, BCM2711_SOC_REGISTERS);
> 
> +    SystemMemorySizeBelow4GB = MIN (SystemMemorySize, 4UL * SIZE_1GB);
> 
> +    SystemMemorySizeBelow4GB = MIN (SystemMemorySizeBelow4GB, BCM2836_SOC_REGISTERS);
> 
> +    SystemMemorySizeBelow4GB = MIN (SystemMemorySizeBelow4GB, BCM2711_SOC_REGISTERS);
> 
>   
> 
>       ASSERT (SystemMemorySizeBelow4GB > 3UL * SIZE_1GB);
> 
>   
> 
> @@ -528,14 +528,14 @@ ApplyVariables (
>         /*
> 
>          * SD card pins go to Arasan.
> 
>          */
> 
> -      MmioWrite32((GPIO_BASE_ADDRESS + 0xD0),
> 
> -                  MmioRead32(GPIO_BASE_ADDRESS + 0xD0) | 0x2);
> 
> +      MmioWrite32 ((GPIO_BASE_ADDRESS + 0xD0),
> 
> +                  MmioRead32 (GPIO_BASE_ADDRESS + 0xD0) | 0x2);
> 
>       } else {
> 
>         /*
> 
>          * SD card pins back to eMMC2.
> 
>          */
> 
> -      MmioWrite32((GPIO_BASE_ADDRESS + 0xD0),
> 
> -                  MmioRead32(GPIO_BASE_ADDRESS + 0xD0) & ~0x2);
> 
> +      MmioWrite32 ((GPIO_BASE_ADDRESS + 0xD0),
> 
> +                  MmioRead32 (GPIO_BASE_ADDRESS + 0xD0) & ~0x2);
> 
>         /*
> 
>          * WiFi back to Arasan.
> 
>          */
> 

Reviewed-by: Pete Batard <pete@akeo.ie>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone
  2020-08-31 13:15   ` Pete Batard
@ 2020-08-31 15:13     ` Jeremy Linton
  2020-08-31 15:33       ` Ard Biesheuvel
  0 siblings, 1 reply; 14+ messages in thread
From: Jeremy Linton @ 2020-08-31 15:13 UTC (permalink / raw)
  To: Pete Batard, devel
  Cc: Leif Lindholm, Andrei Warkentin, Ard Biesheuvel,
	Samer El-Haj-Mahmoud

Hi,

On 8/31/20 8:15 AM, Pete Batard wrote:
> One general, non-blocking comment below:
> 
> On 2020.08.28 23:02, Jeremy Linton wrote:
>> Rather than exporting the temp sensor or mailbox
>> in ACPI land we can wrap them in AML and use the default
>> ACPI drivers provided by the OS. This enables the use of
>> "sensors" in linux to report the SOC temp.
>>
>> As a first pass add a basic passive cooling ACPI thermalzone
>> with trip points for passive cooling (throttling) handled
>> by the vc firmware, hibernate and critical shutdown. The
>> vc apparently kicks in at ~80C, so the hibernate and critical
>> set points are set at +5 and +10 of that. In the future
>> CPPC should be able to monitor the thermal throttling.
>>
>> 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/AcpiTables/Dsdt.asl           | 31 
>> ++++++++++++++++++++++
>>   .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |  2 ++
>>   2 files changed, 33 insertions(+)
>>
>> diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl 
>> b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>> index 353af2d876..73067aefd2 100644
>> --- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>> +++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>> @@ -252,6 +252,37 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", 
>> "RPI", 2)
>>           }
>>
>>         })
>>
>>       }
>>
>> +
>>
>> +    // Define a simple thermal zone. The idea here is we compute the 
>> SOC temp
>>
>> +    // via a register we can read, and give it to the OS. This 
>> enables basic
>>
>> +    // reports from the "sensors" utility, and the OS can then poll 
>> and take
>>
>> +    // actions if that temp exceeds any of the given thresholds.
>>
>> +    Device (EC0)
> 
> Just going to point out that all the other ACPI devices we seem to 
> define have 4 characters, so I'm not sure if we're breaking a convention 
> by introducing a 3 character one here...

Well not an ACPI spec convention, because it seems the spec examples are 
mostly 3 characters. EDK2 OTOH, seems to be largely 4 but there are a 
fair number of 3 character device/etc methods around

I'm not sure it matters, unless there is a edk2 convention I'm unaware of.

> 
>>
>> +    {
>>
>> +      Name (_HID, EISAID ("PNP0C06"))
>>
>> +      Name (_CCA, 0x0)
>>
>> +
>>
>> +      // all temps in are tenths of K (aka 2732 is the min temps in 
>> Linux (aka 0C))
>>
>> +      ThermalZone (TZ0) {
> 
> Likewise, what I'm seeing by googling around for ThermalZone () names 
> would be 4 character ones such as "TZ00", "TZ01" or "TZS0" (For 'Thermal 
> Zone Sensor 0') or "TMZN" for single entries.
> 
>>
>> +        Method (_TMP, 0, Serialized) {
>>
>> +          OperationRegion (TEMS, SystemMemory, THERM_SENSOR, 0x8)
>>
>> +          Field (TEMS, DWordAcc, NoLock, Preserve) {
>>
>> +            TMPS, 32
>>
>> +          }
>>
>> +          return (((419949 - ((TMPS & 0x3ff) * 487)) / 100) + 2732);
>>
>> +        }
>>
>> +        Method (_SCP, 3) { }               // receive cooling policy 
>> from OS
>>
>> +
>>
>> +        Method (_CRT) { Return (3632) }    // (90C) Critical temp 
>> point (immediate power-off)
>>
>> +        Method (_HOT) { Return (3582) }    // (85C) HOT state where 
>> OS should hibernate
>>
>> +        Method (_PSV) { Return (3532) }    // (80C) Passive cooling 
>> (CPU throttling) trip point
>>
>> +
>>
>> +        // SSDT inserts _AC0/_AL0 @60C here, if a FAN is configured
>>
>> +
>>
>> +        Name (_TZP, 10)                   //The OSPM must poll this 
>> device every 1 seconds
>>
>> +        Name (_PSL, Package () { \_SB_.CPU0, \_SB_.CPU1, \_SB_.CPU2, 
>> \_SB_.CPU3 })
>>
>> +      }
>>
>> +    }
>>
>>   #endif
>>
>>
>>     }
>>
>> diff --git 
>> a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h 
>> b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
>> index e9c81cafa1..86906b2438 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 
>> (PcdBcmGenetRegistersAddress)
>>
>>   #define GENET_LENGTH               0x00010000
>>
>>
>> +#define THERM_SENSOR               0xfd5d2200
>>
>> +
>>
>>   #endif /* BCM2711_H__ */
>>
> 
> Reviewed-by: Pete Batard <pete@akeo.ie>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone
  2020-08-31 15:13     ` Jeremy Linton
@ 2020-08-31 15:33       ` Ard Biesheuvel
  2020-08-31 15:49         ` Jeremy Linton
  0 siblings, 1 reply; 14+ messages in thread
From: Ard Biesheuvel @ 2020-08-31 15:33 UTC (permalink / raw)
  To: Jeremy Linton, Pete Batard, devel
  Cc: Leif Lindholm, Andrei Warkentin, Samer El-Haj-Mahmoud

On 8/31/20 5:13 PM, Jeremy Linton wrote:
> Hi,
> 
> On 8/31/20 8:15 AM, Pete Batard wrote:
>> One general, non-blocking comment below:
>>
>> On 2020.08.28 23:02, Jeremy Linton wrote:
>>> Rather than exporting the temp sensor or mailbox
>>> in ACPI land we can wrap them in AML and use the default
>>> ACPI drivers provided by the OS. This enables the use of
>>> "sensors" in linux to report the SOC temp.
>>>
>>> As a first pass add a basic passive cooling ACPI thermalzone
>>> with trip points for passive cooling (throttling) handled
>>> by the vc firmware, hibernate and critical shutdown. The
>>> vc apparently kicks in at ~80C, so the hibernate and critical
>>> set points are set at +5 and +10 of that. In the future
>>> CPPC should be able to monitor the thermal throttling.
>>>
>>> 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/AcpiTables/Dsdt.asl           | 31 
>>> ++++++++++++++++++++++
>>>   .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |  2 ++
>>>   2 files changed, 33 insertions(+)
>>>
>>> diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl 
>>> b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>> index 353af2d876..73067aefd2 100644
>>> --- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>> +++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>> @@ -252,6 +252,37 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, 
>>> "RPIFDN", "RPI", 2)
>>>           }
>>>
>>>         })
>>>
>>>       }
>>>
>>> +
>>>
>>> +    // Define a simple thermal zone. The idea here is we compute the 
>>> SOC temp
>>>
>>> +    // via a register we can read, and give it to the OS. This 
>>> enables basic
>>>
>>> +    // reports from the "sensors" utility, and the OS can then poll 
>>> and take
>>>
>>> +    // actions if that temp exceeds any of the given thresholds.
>>>
>>> +    Device (EC0)
>>
>> Just going to point out that all the other ACPI devices we seem to 
>> define have 4 characters, so I'm not sure if we're breaking a 
>> convention by introducing a 3 character one here...
> 
> Well not an ACPI spec convention, because it seems the spec examples are 
> mostly 3 characters. EDK2 OTOH, seems to be largely 4 but there are a 
> fair number of 3 character device/etc methods around
> 
> I'm not sure it matters, unless there is a edk2 convention I'm unaware of.
> 

I don't think such a convention exists, although I never tried the MS 
iasl compiler, and the RPi asl code (which was contributed by MS) 
suspiciously uses 4 letter identifiers everywhere.

Samer, any clue?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone
  2020-08-31 15:33       ` Ard Biesheuvel
@ 2020-08-31 15:49         ` Jeremy Linton
  0 siblings, 0 replies; 14+ messages in thread
From: Jeremy Linton @ 2020-08-31 15:49 UTC (permalink / raw)
  To: Ard Biesheuvel, Pete Batard, devel
  Cc: Leif Lindholm, Andrei Warkentin, Samer El-Haj-Mahmoud

On 8/31/20 10:33 AM, Ard Biesheuvel wrote:
> On 8/31/20 5:13 PM, Jeremy Linton wrote:
>> Hi,
>>
>> On 8/31/20 8:15 AM, Pete Batard wrote:
>>> One general, non-blocking comment below:
>>>
>>> On 2020.08.28 23:02, Jeremy Linton wrote:
>>>> Rather than exporting the temp sensor or mailbox
>>>> in ACPI land we can wrap them in AML and use the default
>>>> ACPI drivers provided by the OS. This enables the use of
>>>> "sensors" in linux to report the SOC temp.
>>>>
>>>> As a first pass add a basic passive cooling ACPI thermalzone
>>>> with trip points for passive cooling (throttling) handled
>>>> by the vc firmware, hibernate and critical shutdown. The
>>>> vc apparently kicks in at ~80C, so the hibernate and critical
>>>> set points are set at +5 and +10 of that. In the future
>>>> CPPC should be able to monitor the thermal throttling.
>>>>
>>>> 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/AcpiTables/Dsdt.asl           | 31 
>>>> ++++++++++++++++++++++
>>>>   .../Bcm27xx/Include/IndustryStandard/Bcm2711.h     |  2 ++
>>>>   2 files changed, 33 insertions(+)
>>>>
>>>> diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl 
>>>> b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>>> index 353af2d876..73067aefd2 100644
>>>> --- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>>> +++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
>>>> @@ -252,6 +252,37 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, 
>>>> "RPIFDN", "RPI", 2)
>>>>           }
>>>>
>>>>         })
>>>>
>>>>       }
>>>>
>>>> +
>>>>
>>>> +    // Define a simple thermal zone. The idea here is we compute 
>>>> the SOC temp
>>>>
>>>> +    // via a register we can read, and give it to the OS. This 
>>>> enables basic
>>>>
>>>> +    // reports from the "sensors" utility, and the OS can then poll 
>>>> and take
>>>>
>>>> +    // actions if that temp exceeds any of the given thresholds.
>>>>
>>>> +    Device (EC0)
>>>
>>> Just going to point out that all the other ACPI devices we seem to 
>>> define have 4 characters, so I'm not sure if we're breaking a 
>>> convention by introducing a 3 character one here...
>>
>> Well not an ACPI spec convention, because it seems the spec examples 
>> are mostly 3 characters. EDK2 OTOH, seems to be largely 4 but there 
>> are a fair number of 3 character device/etc methods around
>>
>> I'm not sure it matters, unless there is a edk2 convention I'm unaware 
>> of.
>>
> 
> I don't think such a convention exists, although I never tried the MS 
> iasl compiler, and the RPi asl code (which was contributed by MS) 
> suspiciously uses 4 letter identifiers everywhere.
> 
> Samer, any clue?
> 

I have another patch to allow the user to set the temp trip point which 
IIRC Andrei had asked about months ago when I originally mentioned that 
I had hacked up a thermal zone.

I might as well roll a v4 with that, the whitespace, and "0"'s appended 
to EC0 and TZ0 just in case... I'm sanity checking right now that it 
still works.





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-08-31 15:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-28 22:02 [PATCH v3 0/5] Platform/RasberryPi: Thermal zone Jeremy Linton
2020-08-28 22:02 ` [PATCH v3 1/5] Platform/RaspberryPi4: Add a basic thermal zone Jeremy Linton
2020-08-31 13:15   ` Pete Batard
2020-08-31 15:13     ` Jeremy Linton
2020-08-31 15:33       ` Ard Biesheuvel
2020-08-31 15:49         ` Jeremy Linton
2020-08-28 22:02 ` [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Jeremy Linton
2020-08-31 13:17   ` Pete Batard
2020-08-28 22:02 ` [PATCH v3 3/5] Platform/RaspberryPi: Add entry for user fan control Jeremy Linton
2020-08-31 13:17   ` Pete Batard
2020-08-28 22:02 ` [PATCH v3 4/5] Platform/RaspberryPi4: Create ACPI fan object Jeremy Linton
2020-08-31 13:17   ` Pete Batard
2020-08-28 22:02 ` [PATCH v3 5/5] Platform/RaspberryPi: Trivial whitespace cleanup Jeremy Linton
2020-08-31 13:17   ` Pete Batard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox