public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Jeremy Linton" <jeremy.linton@arm.com>
To: devel@edk2.groups.io
Cc: pete@akeo.ie, ardb+tianocore@kernel.org, leif@nuviainc.com,
	awarkentin@vmware.com, Sunny.Wang@arm.com,
	samer.el-haj-mahmoud@arm.com, mariobalanica02@gmail.com,
	Jeremy Linton <jeremy.linton@arm.com>,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH V2 03/10] Platform/RaspberryPi: Move GPIO/SPI/I2C to SSDT
Date: Sat,  1 Jan 2022 23:49:17 -0600	[thread overview]
Message-ID: <20220102054924.1195762-4-jeremy.linton@arm.com> (raw)
In-Reply-To: <20220102054924.1195762-1-jeremy.linton@arm.com>

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@kernel.org>
Signed-off-by: Jeremy Linton <jeremy.linton@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


  parent reply	other threads:[~2022-01-02  5:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-02  5:49 [PATCH V2 00/10] Platform/RaspberryPi: Utilize SPI flash for EFI variables Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 01/10] Platform/RaspberryPi: Cleanup menu visibility Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 02/10] Platform/RaspberryPi: Give the user control over the XHCI mailbox Jeremy Linton
2022-01-02  5:49 ` Jeremy Linton [this message]
2022-01-02  5:49 ` [PATCH V2 04/10] Platform/RaspberryPi: Add menu item to enable/disable GPIO Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 05/10] Platform/RaspberryPi: Add constants for controlling SPI Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 06/10] Platform/RaspberryPi: Add mailbox cmd to control audio amp Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 07/10] Platform/RaspberryPi: Add SPI/GPIO to memory map Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 08/10] Platform/RaspberryPi: Allow pin function selection at runtime Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 09/10] Platform/RaspberryPi: Add SPI flash variable store Jeremy Linton
2022-01-02  5:49 ` [PATCH V2 10/10] Platform/RaspberryPi: Update RPi4 Readme Jeremy Linton
2022-02-01 18:03 ` [edk2-devel] [PATCH V2 00/10] Platform/RaspberryPi: Utilize SPI flash for EFI variables 0n0w1c
2022-02-10 16:38 ` Jeff Booher-Kaeding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220102054924.1195762-4-jeremy.linton@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox