[edk2-devel] [PATCH V2 03/10] Platform/RaspberryPi: Move GPIO/SPI/I2C to SSDT

Jeremy Linton jeremy.linton at arm.com
Sun Jan 2 05:49:17 UTC 2022


The UEFI firmware uses the GPIO port for the fan and
real soon now the runtime SPI variable store. As such
we need to be able to either isolate those devices from
the OS or we risk clashing with OS's that reconfigure
the GPIO pins. Ideally we would just rip this out
and use _DSM() or just individual device power
on/off methods to adjust the GPIO pins when needed.

For now, lets leave it since windows at least knows
about it. In the future we will decide whether the
firmware is controlling something (SPI!) based on
whether the user has enabled the GPIO block.

Tested-by: Ard Biesheuvel <ardb at kernel.org>
Signed-off-by: Jeremy Linton <jeremy.linton at arm.com>
---
 Platform/RaspberryPi/AcpiTables/AcpiTables.inf     |   1 +
 Platform/RaspberryPi/AcpiTables/Dsdt.asl           |   7 -
 Platform/RaspberryPi/AcpiTables/GpuDevs.asl        | 126 ----------------
 Platform/RaspberryPi/AcpiTables/SsdtGpio.asl       | 159 +++++++++++++++++++++
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c |   6 +
 5 files changed, 166 insertions(+), 133 deletions(-)
 create mode 100644 Platform/RaspberryPi/AcpiTables/SsdtGpio.asl

diff --git a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
index da2a6db85f..3894d00565 100644
--- a/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
+++ b/Platform/RaspberryPi/AcpiTables/AcpiTables.inf
@@ -40,6 +40,7 @@
   SsdtThermal.asl
   Xhci.asl
   Pci.asl
+  SsdtGpio.asl
 
 [Packages]
   ArmPkg/ArmPkg.dec
diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
index b594d50bdf..08acc81d57 100644
--- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl
+++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl
@@ -21,13 +21,6 @@
 
 #include "AcpiTables.h"
 
-#define BCM_ALT0 0x4
-#define BCM_ALT1 0x5
-#define BCM_ALT2 0x6
-#define BCM_ALT3 0x7
-#define BCM_ALT4 0x3
-#define BCM_ALT5 0x2
-
 //
 // The ASL compiler does not support argument arithmetic in functions
 // like QWordMemory (). So we need to instantiate dummy qword regions
diff --git a/Platform/RaspberryPi/AcpiTables/GpuDevs.asl b/Platform/RaspberryPi/AcpiTables/GpuDevs.asl
index 9750dc25c0..3399f0fc9a 100644
--- a/Platform/RaspberryPi/AcpiTables/GpuDevs.asl
+++ b/Platform/RaspberryPi/AcpiTables/GpuDevs.asl
@@ -203,56 +203,6 @@ Device (VCSM)
   }
 }
 
-// Description: GPIO
-Device (GPI0)
-{
-  Name (_HID, "BCM2845")
-  Name (_CID, "BCM2845")
-  Name (_UID, 0x0)
-  Name (_CCA, 0x0)
-  Method (_STA)
-  {
-    Return(0xf)
-  }
-  Name (RBUF, ResourceTemplate ()
-  {
-    MEMORY32FIXED (ReadWrite, 0, GPIO_LENGTH, RMEM)
-    Interrupt (ResourceConsumer, Level, ActiveHigh, Shared)
-    {
-      BCM2386_GPIO_INTERRUPT0, BCM2386_GPIO_INTERRUPT1,
-      BCM2386_GPIO_INTERRUPT2, BCM2386_GPIO_INTERRUPT3
-    }
-  })
-  Method (_CRS, 0x0, Serialized)
-  {
-    MEMORY32SETBASE (RBUF, RMEM, RBAS, GPIO_OFFSET)
-    Return (^RBUF)
-  }
-}
-
-// Description: I2C
-Device (I2C1)
-{
-  Name (_HID, "BCM2841")
-  Name (_CID, "BCM2841")
-  Name (_UID, 0x1)
-  Name (_CCA, 0x0)
-  Method (_STA)
-  {
-    Return(0xf)
-  }
-  Name (RBUF, ResourceTemplate ()
-  {
-    MEMORY32FIXED (ReadWrite, 0, BCM2836_I2C1_LENGTH, RMEM)
-    Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_I2C1_INTERRUPT }
-    PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 2, 3 }
-  })
-  Method (_CRS, 0x0, Serialized)
-  {
-    MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_I2C1_OFFSET)
-    Return (^RBUF)
-  }
-}
 
 // I2C2 is the HDMI DDC connection
 Device (I2C2)
@@ -278,81 +228,6 @@ Device (I2C2)
   }
 }
 
-// SPI
-Device (SPI0)
-{
-  Name (_HID, "BCM2838")
-  Name (_CID, "BCM2838")
-  Name (_UID, 0x0)
-  Name (_CCA, 0x0)
-  Method (_STA)
-  {
-    Return (0xf)
-  }
-  Name (RBUF, ResourceTemplate ()
-  {
-    MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI0_LENGTH, RMEM)
-    Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_SPI0_INTERRUPT }
-    PinFunction (Exclusive, PullDown, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 9, 10, 11 } // MISO, MOSI, SCLK
-    PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 8 } // CE0
-    PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 7 } // CE1
-  })
-
-  Method (_CRS, 0x0, Serialized)
-  {
-    MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_SPI0_OFFSET)
-    Return (^RBUF)
-  }
-}
-
-Device (SPI1)
-{
-  Name (_HID, "BCM2839")
-  Name (_CID, "BCM2839")
-  Name (_UID, 0x1)
-  Name (_CCA, 0x0)
-  Name (_DEP, Package() { \_SB.GDV0.RPIQ })
-  Method (_STA)
-  {
-    Return (0xf)
-  }
-  Name (RBUF, ResourceTemplate ()
-  {
-    MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI1_LENGTH, RMEM)
-    Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) { BCM2836_SPI1_INTERRUPT }
-    PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 19, 20, 21 } // MISO, MOSI, SCLK
-    PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 16 } // CE2
-  })
-
-  Method (_CRS, 0x0, Serialized)
-  {
-    MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_SPI1_OFFSET)
-    Return (^RBUF)
-  }
-}
-
-// SPI2 has no pins on GPIO header
-// Device (SPI2)
-// {
-//   Name (_HID, "BCM2839")
-//   Name (_CID, "BCM2839")
-//   Name (_UID, 0x2)
-//   Name (_CCA, 0x0)
-//   Name (_DEP, Package() { \_SB.GDV0.RPIQ })
-//   Method (_STA)
-//   {
-//     Return (0xf)     // Disabled
-//   }
-//   Method (_CRS, 0x0, Serialized)
-//   {
-//     Name (RBUF, ResourceTemplate ()
-//     {
-//       MEMORY32FIXED (ReadWrite, BCM2836_SPI2_BASE_ADDRESS, BCM2836_SPI2_LENGTH, RMEM)
-//       Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) { BCM2836_SPI2_INTERRUPT }
-//     })
-//     Return (RBUF)
-//   }
-// }
 
 // PWM Driver
 Device (PWM0)
@@ -393,5 +268,4 @@ Device (PWM0)
 }
 
 include ("Uart.asl")
-include ("Rhpx.asl")
 include ("Sdhc.asl")
diff --git a/Platform/RaspberryPi/AcpiTables/SsdtGpio.asl b/Platform/RaspberryPi/AcpiTables/SsdtGpio.asl
new file mode 100644
index 0000000000..38e8a54a8f
--- /dev/null
+++ b/Platform/RaspberryPi/AcpiTables/SsdtGpio.asl
@@ -0,0 +1,159 @@
+/** @file
+ *
+ *  Secondary System Description Table (SSDT) for the GPIO port
+ *
+ *  Copyright (c) 2021, Arm Ltd. All rights reserved.
+ *
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/Bcm2711.h>
+#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Gpio.h>
+
+#include "AcpiTables.h"
+
+#define BCM_ALT0 0x4
+#define BCM_ALT1 0x5
+#define BCM_ALT2 0x6
+#define BCM_ALT3 0x7
+#define BCM_ALT4 0x3
+#define BCM_ALT5 0x2
+
+DefinitionBlock (__FILE__, "SSDT", 5, "RPIFDN", "RPI3GPIO", 2)
+{
+  External (\_SB_.GDV0, DeviceObj)
+  External (\_SB_.GDV0.RPIQ, DeviceObj)
+  Scope (\_SB_.GDV0)
+  {
+    include ("Rhpx.asl")
+
+    // Description: GPIO
+    Device (GPI0)
+    {
+      Name (_HID, "BCM2845")
+      Name (_CID, "BCM2845")
+      Name (_UID, 0x0)
+      Name (_CCA, 0x0)
+      Method (_STA)
+      {
+        Return(0xf)
+      }
+      Name (RBUF, ResourceTemplate ()
+      {
+        MEMORY32FIXED (ReadWrite, 0, GPIO_LENGTH, RMEM)
+        Interrupt (ResourceConsumer, Level, ActiveHigh, Shared)
+        {
+          BCM2386_GPIO_INTERRUPT0, BCM2386_GPIO_INTERRUPT1,
+          BCM2386_GPIO_INTERRUPT2, BCM2386_GPIO_INTERRUPT3
+        }
+      })
+      Method (_CRS, 0x0, Serialized)
+      {
+        MEMORY32SETBASE (RBUF, RMEM, RBAS, GPIO_OFFSET)
+        Return (^RBUF)
+      }
+    }
+
+    // SPI
+    Device (SPI0)
+    {
+      Name (_HID, "BCM2838")
+      Name (_CID, "BCM2838")
+      Name (_UID, 0x0)
+      Name (_CCA, 0x0)
+      Method (_STA)
+      {
+        Return (0xf)
+      }
+      Name (RBUF, ResourceTemplate ()
+      {
+        MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI0_LENGTH, RMEM)
+        Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_SPI0_INTERRUPT }
+        PinFunction (Exclusive, PullDown, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 9, 10, 11 } // MISO, MOSI, SCLK
+        PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 8 } // CE0
+        PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 7 } // CE1
+      })
+
+      Method (_CRS, 0x0, Serialized)
+      {
+        MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_SPI0_OFFSET)
+        Return (^RBUF)
+      }
+    }
+
+    Device (SPI1)
+    {
+      Name (_HID, "BCM2839")
+      Name (_CID, "BCM2839")
+      Name (_UID, 0x1)
+      Name (_CCA, 0x0)
+      Name (_DEP, Package() { \_SB.GDV0.RPIQ })
+      Method (_STA)
+      {
+        Return (0xf)
+      }
+      Name (RBUF, ResourceTemplate ()
+      {
+        MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI1_LENGTH, RMEM)
+        Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) { BCM2836_SPI1_INTERRUPT }
+        PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB_.GDV0.GPI0", 0, ResourceConsumer, , ) { 19, 20, 21 } // MISO, MOSI, SCLK
+        PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB_.GDV0.GPI0", 0, ResourceConsumer, , ) { 16 } // CE2
+      })
+
+      Method (_CRS, 0x0, Serialized)
+      {
+        MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_SPI1_OFFSET)
+        Return (^RBUF)
+      }
+    }
+
+  // SPI2 has no pins on GPIO header
+  // Device (SPI2)
+  // {
+  //   Name (_HID, "BCM2839")
+  //   Name (_CID, "BCM2839")
+  //   Name (_UID, 0x2)
+  //   Name (_CCA, 0x0)
+  //   Name (_DEP, Package() { \_SB.GDV0.RPIQ })
+  //   Method (_STA)
+  //   {
+  //     Return (0xf)     // Disabled
+  //   }
+  //   Method (_CRS, 0x0, Serialized)
+  //   {
+  //     Name (RBUF, ResourceTemplate ()
+  //     {
+  //       MEMORY32FIXED (ReadWrite, BCM2836_SPI2_BASE_ADDRESS, BCM2836_SPI2_LENGTH, RMEM)
+  //       Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) { BCM2836_SPI2_INTERRUPT }
+  //     })
+  //     Return (RBUF)
+  //   }
+  // }
+
+    Device (I2C1)
+    {
+      Name (_HID, "BCM2841")
+      Name (_CID, "BCM2841")
+      Name (_UID, 0x1)
+      Name (_CCA, 0x0)
+      Method (_STA)
+      {
+        Return(0xf)
+      }
+      Name (RBUF, ResourceTemplate ()
+      {
+        MEMORY32FIXED (ReadWrite, 0, BCM2836_I2C1_LENGTH, RMEM)
+        Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_I2C1_INTERRUPT }
+        PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB_.GDV0.GPI0", 0, ResourceConsumer, , ) { 2, 3 }
+      })
+      Method (_CRS, 0x0, Serialized)
+      {
+        MEMORY32SETBASE (RBUF, RMEM, RBAS, BCM2836_I2C1_OFFSET)
+        Return (^RBUF)
+      }
+    }
+  }
+}
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index bdabdec7a5..d22ecb3128 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -838,6 +838,12 @@ STATIC CONST NAMESPACE_TABLES SdtTables[] = {
     NULL
   },
 #endif
+  {
+    SIGNATURE_64 ('R', 'P', 'I', '3', 'G', 'P', 'I', 'O'),
+    0,
+    0,
+    NULL
+  },
   { // DSDT
     SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0),
     0,
-- 
2.13.7



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85251): https://edk2.groups.io/g/devel/message/85251
Mute This Topic: https://groups.io/mt/88087665/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list