[edk2-devel] [edk2-platforms][PATCH 4/5] Platform/RPi4: Update ACPI tables for the new platform

Pete Batard posted 5 patches 4 years, 11 months ago
[edk2-devel] [edk2-platforms][PATCH 4/5] Platform/RPi4: Update ACPI tables for the new platform
Posted by Pete Batard 4 years, 11 months ago
From: Andrei Warkentin <andrey.warkentin@gmail.com>

Update CSRT, DSDT, GTDT, MADT, SDHC and serial tables for the new
base addresses and switch ACPI to GIC.

We use ACPI 5.1 for MADT because older versions of the Linux kernel
can be finicky when it comes to checking the size of the GICC entries
the table: depending on the FADT version (either 5, or 6 or later),
the size must be exactly 76 or 80 bytes, respectively. However, using
the ACPI 6.0 or 6.1 GICC macros results in 80 byte entries, which
triggers a mismatch error since the FADT we are exposing is 5.1.

Since GICv2 doesn't care about any of the fields that were added
after ACPI 5.1, we can simply use that version to keep Linux happy.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.h   |  26 ++++-
 Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf |  12 ++-
 Platform/RaspberryPi/RPi4/AcpiTables/Csrt.aslc      |  25 ++---
 Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc      |   2 +-
 Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl       |  40 ++++----
 Platform/RaspberryPi/RPi4/AcpiTables/Gtdt.aslc      |  69 +++++++++----
 Platform/RaspberryPi/RPi4/AcpiTables/Madt.aslc      | 102 +++++++++++---------
 Platform/RaspberryPi/RPi4/AcpiTables/Pep.asl        |   5 +-
 Platform/RaspberryPi/RPi4/AcpiTables/Pep.c          |   7 +-
 Platform/RaspberryPi/RPi4/AcpiTables/Pep.h          |   7 +-
 Platform/RaspberryPi/RPi4/AcpiTables/Sdhc.asl       |   4 +-
 Platform/RaspberryPi/RPi4/AcpiTables/Spcr.asl       |  15 +--
 Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl       |  12 +--
 13 files changed, 197 insertions(+), 129 deletions(-)

diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.h b/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.h
index 958af026c8a3..e61f3fa0bcfa 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.h
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.h
@@ -1,7 +1,8 @@
 /** @file
  *
- *  RPi3 defines for constructing ACPI tables
+ *  RPi4 defines for constructing ACPI tables
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
@@ -15,18 +16,33 @@
 #include <IndustryStandard/Acpi50.h>
 
 #define EFI_ACPI_OEM_ID                       {'M','C','R','S','F','T'} // OEMID 6 bytes long
-#define EFI_ACPI_OEM_TABLE_ID                 SIGNATURE_64 ('R','P','I','3','E','D','K','2') // OEM table id 8 bytes long
+#define EFI_ACPI_OEM_TABLE_ID                 SIGNATURE_64 ('R','P','I','4','E','D','K','2') // OEM table id 8 bytes long
 #define EFI_ACPI_OEM_REVISION                 0x02000820
-#define EFI_ACPI_CREATOR_ID                   SIGNATURE_32 ('R','P','I','3')
+#define EFI_ACPI_CREATOR_ID                   SIGNATURE_32 ('R','P','I','4')
 #define EFI_ACPI_CREATOR_REVISION             0x00000097
 
 #define EFI_ACPI_VENDOR_ID                    SIGNATURE_32 ('M','S','F','T')
+
+// A macro to initialise the common header part of EFI ACPI tables as defined by
+// EFI_ACPI_DESCRIPTION_HEADER structure.
+#define ACPI_HEADER(Signature, Type, Revision) {                  \
+    Signature,                      /* UINT32  Signature */       \
+    sizeof (Type),                  /* UINT32  Length */          \
+    Revision,                       /* UINT8   Revision */        \
+    0,                              /* UINT8   Checksum */        \
+    EFI_ACPI_OEM_ID,                /* UINT8   OemId[6] */        \
+    EFI_ACPI_OEM_TABLE_ID,          /* UINT64  OemTableId */      \
+    EFI_ACPI_OEM_REVISION,          /* UINT32  OemRevision */     \
+    EFI_ACPI_CREATOR_ID,            /* UINT32  CreatorId */       \
+    EFI_ACPI_CREATOR_REVISION       /* UINT32  CreatorRevision */ \
+  }
+
 #define EFI_ACPI_CSRT_REVISION                0x00000005
 #define EFI_ACPI_CSRT_DEVICE_ID_DMA           0x00000009 // Fixed id
 #define EFI_ACPI_CSRT_RESOURCE_ID_IN_DMA_GRP  0x0 // Count up from 0
 
-#define RPI3_DMA_CHANNEL_COUNT                10 // All 10 DMA channels are listed, including the reserved ones
-#define RPI3_DMA_USED_CHANNEL_COUNT           5  // Use 5 DMA channels
+#define RPI4_DMA_CHANNEL_COUNT                10 // All 10 DMA channels are listed, including the reserved ones
+#define RPI4_DMA_USED_CHANNEL_COUNT           5  // Use 5 DMA channels
 
 #define EFI_ACPI_5_0_CSRT_REVISION            0x00000000
 
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf b/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf
index 7ef41e79ad46..50c9f7694d84 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf
@@ -2,6 +2,7 @@
 #
 #  ACPI table data and ASL sources required to boot the platform.
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017, Andrey Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) Microsoft Corporation. All rights reserved.
 #
@@ -33,8 +34,17 @@ [Sources]
   Spcr.asl
 
 [Packages]
-  MdePkg/MdePkg.dec
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
   EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
 
 [FixedPcd]
+  gArmTokenSpaceGuid.PcdArmArchTimerIntrNum
+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum
+  gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum
+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
+  gArmTokenSpaceGuid.PcdGicDistributorBase
   gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Csrt.aslc b/Platform/RaspberryPi/RPi4/AcpiTables/Csrt.aslc
index 3b617c0a832b..22a370d04017 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Csrt.aslc
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Csrt.aslc
@@ -2,6 +2,7 @@
  *
  *  Core System Resource Table (CSRT)
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -15,7 +16,7 @@
 #pragma pack (push, 1)
 
 //------------------------------------------------------------------------
-// DMA Controller Vendor Data for RPi3
+// DMA Controller Vendor Data for RPi4
 //------------------------------------------------------------------------
 typedef struct
 {
@@ -33,7 +34,7 @@ typedef struct
 } DMA_CONTROLLER_VENDOR_DATA;
 
 //------------------------------------------------------------------------
-// DMA Controller on RPi3
+// DMA Controller on RPi4
 //------------------------------------------------------------------------
 typedef struct
 {
@@ -42,7 +43,7 @@ typedef struct
 } RD_DMA_CONTROLLER;
 
 //------------------------------------------------------------------------
-// DMA Channel Vendor Data for RPi3
+// DMA Channel Vendor Data for RPi4
 //------------------------------------------------------------------------
 typedef struct
 {
@@ -53,7 +54,7 @@ typedef struct
 } DMA_CHANNEL_VENDOR_DATA;
 
 //------------------------------------------------------------------------
-// DMA Channel on RPi3
+// DMA Channel on RPi4
 //------------------------------------------------------------------------
 typedef struct
 {
@@ -62,18 +63,18 @@ typedef struct
 } RD_DMA_CHANNEL;
 
 //------------------------------------------------------------------------
-// DMA Resource Group on RPi3
+// DMA Resource Group on RPi4
 //------------------------------------------------------------------------
 
 typedef struct
 {
   EFI_ACPI_5_0_CSRT_RESOURCE_GROUP_HEADER ResGroupHeader;
   RD_DMA_CONTROLLER DmaController;
-  RD_DMA_CHANNEL DmaChannels[RPI3_DMA_CHANNEL_COUNT];
+  RD_DMA_CHANNEL DmaChannels[RPI4_DMA_CHANNEL_COUNT];
 } RG_DMA;
 
 //----------------------------------------------------------------------------
-// CSRT table structure for RPi3 platform - current revision only includes DMA
+// CSRT table structure for RPi4 platform - current revision only includes DMA
 //----------------------------------------------------------------------------
 typedef struct
 {
@@ -96,7 +97,7 @@ EFI_ACPI_5_0_CSRT_TABLE Csrt =
     EFI_ACPI_5_0_CSRT_REVISION,     // Revision
     0x00,                           // Checksum calculated at runtime.
     EFI_ACPI_OEM_ID,                // OEMID is a 6 bytes long field "BC2836"
-    EFI_ACPI_OEM_TABLE_ID,          // OEM table identification(8 bytes long) "RPI3EDK2"
+    EFI_ACPI_OEM_TABLE_ID,          // OEM table identification(8 bytes long) "RPI4EDK2"
     EFI_ACPI_OEM_REVISION,          // OEM revision number.
     EFI_ACPI_CREATOR_ID,            // ASL compiler vendor ID.
     EFI_ACPI_CREATOR_REVISION       // ASL compiler revision number.
@@ -134,11 +135,11 @@ EFI_ACPI_5_0_CSRT_TABLE Csrt =
       {
         sizeof (DMA_CONTROLLER_VENDOR_DATA),  // Controller vendor data here
         1,
-        0x3F007000,                   // Base address for channels
-        RPI3_DMA_CHANNEL_COUNT * 0x100, // Base size = Number of channels x 0x100 size for each channel
-        0x3F007FE0,                   // Base address for controller
+        0xFE007000,                   // Base address for channels
+        RPI4_DMA_CHANNEL_COUNT * 0x100, // Base size = Number of channels x 0x100 size for each channel
+        0xFE007FE0,                   // Base address for controller
         8,                            // Base size = two registers
-        RPI3_DMA_USED_CHANNEL_COUNT,
+        RPI4_DMA_USED_CHANNEL_COUNT,
         0,                            // cannot use controller interrupt
         0,                            // Minimum Request Line
         DMA_MAX_REQ_LINES - 1,          // Maximum Request Line
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc b/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc
index 9315f23e0d2d..849cf5134793 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Dbg2.aslc
@@ -16,7 +16,7 @@ UINT8 Dbg2[92] = {
   0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x01, 0x0A, 0x00,
   0x26, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x80, 0x10, 0x00,
   0x00, 0x00, 0x16, 0x00, 0x22, 0x00, 0x00, 0x20, 0x00, 0x10,
-  0x00, 0x50, 0x21, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00,
+  0x00, 0x50, 0x21, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00,
   0x00, 0x00, '\\',  '_',  'S',  'B',  '.',  'U',  'R',  'T',
   'M', 0x00,
 };
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
index ab4d4bf4851f..42e650a3ef29 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Dsdt.asl
@@ -78,8 +78,8 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          MEMORY32FIXED(ReadWrite, 0x3F980000, 0x10000,)
-          Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x29 }
+          MEMORY32FIXED(ReadWrite, 0xFE980000, 0x10000,)
+          Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x69 }
         })
         Return(RBUF)
       }
@@ -101,29 +101,29 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
         Name (RBUF, ResourceTemplate ()
         {
           // Memory and interrupt for the GPU
-          MEMORY32FIXED(ReadWrite, 0x3FC00000, 0x1000,)
+          MEMORY32FIXED(ReadWrite, 0xFEC00000, 0x1000,)
           Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x2A }
 
           // HVS - Hardware Video Scalar
-          MEMORY32FIXED (ReadWrite, 0x3F400000, 0x6000,)
+          MEMORY32FIXED (ReadWrite, 0xFE400000, 0x6000,)
           // The HVS interrupt is reserved by the VPU
           // Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x41 }
 
           // PixelValve0 - DSI0 or DPI
-          // MEMORY32FIXED (ReadWrite, 0x3F206000, 0x100,)
+          // MEMORY32FIXED (ReadWrite, 0xFE206000, 0x100,)
           // Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x4D }
 
           // PixelValve1 - DS1 or SMI
-          // MEMORY32FIXED (ReadWrite, 0x73F207000, 0x100,)
+          // MEMORY32FIXED (ReadWrite, 0xFE207000, 0x100,)
           // Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x4E }
 
           // PixelValve2 - HDMI output - connected to HVS display FIFO 1
-          MEMORY32FIXED (ReadWrite, 0x3F807000, 0x100,)
+          MEMORY32FIXED (ReadWrite, 0xFE807000, 0x100,)
           Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x4A }
 
           // HDMI registers
-          MEMORY32FIXED (ReadWrite, 0x3F902000, 0x600,)   // HDMI registers
-          MEMORY32FIXED (ReadWrite, 0x3F808000, 0x100,)   // HD registers
+          MEMORY32FIXED (ReadWrite, 0xFE902000, 0x600,)   // HDMI registers
+          MEMORY32FIXED (ReadWrite, 0xFE808000, 0x100,)   // HD registers
           // hdmi_int[0]
           // Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x48 }
           // hdmi_int[1]
@@ -199,7 +199,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          Memory32Fixed (ReadWrite, 0x3F00B880, 0x00000024,)
+          Memory32Fixed (ReadWrite, 0xFE00B880, 0x00000024,)
           Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x61 }
         })
         Return (RBUF)
@@ -222,7 +222,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          Memory32Fixed (ReadWrite, 0x3F00B840, 0x00000010,)
+          Memory32Fixed (ReadWrite, 0xFE00B840, 0x00000010,)
           Interrupt(ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x62 }
         })
         Return (RBUF)
@@ -258,7 +258,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          MEMORY32FIXED (ReadWrite, 0x3F200000, 0xB4, )
+          MEMORY32FIXED (ReadWrite, 0xFE200000, 0xB4, )
           Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { 0x51 }
           Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { 0x53 }
         })
@@ -281,7 +281,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          Memory32Fixed(ReadWrite, 0x3F804000, 0x20)
+          Memory32Fixed(ReadWrite, 0xFE804000, 0x20)
           Interrupt(ResourceConsumer, Level, ActiveHigh, Shared) {0x55}
 
           //
@@ -319,7 +319,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate()
         {
-          Memory32Fixed (ReadWrite, 0x3F805000, 0x20)
+          Memory32Fixed (ReadWrite, 0xFE805000, 0x20)
           Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) {0x55}
         })
         Return (RBUF)
@@ -341,7 +341,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          MEMORY32FIXED (ReadWrite, 0x3F204000, 0x20,)
+          MEMORY32FIXED (ReadWrite, 0xFE204000, 0x20,)
           Interrupt(ResourceConsumer, Level, ActiveHigh, Shared) {0x56}
 
           //
@@ -406,7 +406,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
       {
         Name (RBUF, ResourceTemplate ()
         {
-          MEMORY32FIXED (ReadWrite, 0x3F215080, 0x40,)
+          MEMORY32FIXED (ReadWrite, 0xFE215080, 0x40,)
           Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) {0x3D}
 
           //
@@ -458,7 +458,7 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
     //   {
     //     Name (RBUF, ResourceTemplate ()
     //     {
-    //       MEMORY32FIXED (ReadWrite, 0x3F2150C0, 0x40,)
+    //       MEMORY32FIXED (ReadWrite, 0xFE2150C0, 0x40,)
     //       Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) {0x3D}
     //     })
     //     Return (RBUF)
@@ -481,15 +481,15 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "MSFT", "EDK2", 2)
         Name (RBUF, ResourceTemplate ()
         {
           // DMA channel 11 control
-          Memory32Fixed (ReadWrite, 0x3F007B00, 0x00000100,)
+          Memory32Fixed (ReadWrite, 0xFE007B00, 0x00000100,)
           // PWM control
-          Memory32Fixed (ReadWrite, 0x3F20C000, 0x00000028,)
+          Memory32Fixed (ReadWrite, 0xFE20C000, 0x00000028,)
           // PWM control bus
           Memory32Fixed (ReadWrite, 0x7E20C000, 0x00000028,)
           // PWM control uncached
           Memory32Fixed (ReadWrite, 0xFF20C000, 0x00000028,)
           // PWM clock control
-          Memory32Fixed (ReadWrite, 0x3F1010A0, 0x00000008,)
+          Memory32Fixed (ReadWrite, 0xFE1010A0, 0x00000008,)
           // Interrupt DMA channel 11
           Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x3B }
           // DMA channel 11, DREQ 5 for PWM
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Gtdt.aslc b/Platform/RaspberryPi/RPi4/AcpiTables/Gtdt.aslc
index 6551315a5502..293c6022d258 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Gtdt.aslc
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Gtdt.aslc
@@ -1,27 +1,56 @@
 /** @file
- *
- *  Generic Timer Description Table (GTDT)
- *  Automatically generated by AutoAcpi
- *
- *  Copyright (c) Microsoft Corporation. All rights reserved.
- *
- *  SPDX-License-Identifier: BSD-2-Clause-Patent
- *
- **/
+*  Generic Timer Description Table (GTDT)
+*
+*  Copyright (c) 2018, Linaro Limited. All rights reserved.
+*  Copyright (c) 2012 - 2016, ARM Limited. All rights reserved.
+*
+*  SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
 
-UINT8 Gtdt[80] = {
-  0x47, 0x54, 0x44, 0x54, 0x50, 0x00, 0x00, 0x00, 0x01, 0x00,
-  0x4D, 0x53, 0x46, 0x54, 0x20, 0x20, 0x45, 0x44, 0x4B, 0x32,
-  0x20, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x00, 0x4D, 0x53,
-  0x46, 0x54, 0x01, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x40,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#include <Library/AcpiLib.h>
+#include <Library/PcdLib.h>
+#include <IndustryStandard/Acpi.h>
+
+#include "AcpiTables.h"
+
+#define SYSTEM_TIMER_BASE_ADDRESS   0xFF80001C
+#define GTDT_GLOBAL_FLAGS           0
+#define GTDT_GTIMER_FLAGS           EFI_ACPI_6_0_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY
+
+#pragma pack (1)
+
+typedef struct {
+  EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE Gtdt;
+} EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLES;
+
+#pragma pack ()
+
+EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLES Gtdt = {
+  {
+    ACPI_HEADER(
+      EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
+      EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLES,
+      EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION
+    ),
+    SYSTEM_TIMER_BASE_ADDRESS,                    // UINT64  PhysicalAddress
+    0,                                            // UINT32  Reserved
+    FixedPcdGet32 (PcdArmArchTimerSecIntrNum),    // UINT32  SecurePL1TimerGSIV
+    GTDT_GTIMER_FLAGS,                            // UINT32  SecurePL1TimerFlags
+    FixedPcdGet32 (PcdArmArchTimerIntrNum),       // UINT32  NonSecurePL1TimerGSIV
+    GTDT_GTIMER_FLAGS,                            // UINT32  NonSecurePL1TimerFlags
+    FixedPcdGet32 (PcdArmArchTimerVirtIntrNum),   // UINT32  VirtualTimerGSIV
+    GTDT_GTIMER_FLAGS,                            // UINT32  VirtualTimerFlags
+    FixedPcdGet32 (PcdArmArchTimerHypIntrNum),    // UINT32  NonSecurePL2TimerGSIV
+    GTDT_GTIMER_FLAGS,                            // UINT32  NonSecurePL2TimerFlags
+    0xFFFFFFFFFFFFFFFF,                           // UINT64  CntReadBasePhysicalAddress
+    0,                                            // UINT32  PlatformTimerCount
+    0                                             // UINT32 PlatfromTimerOffset
+  },
 };
 
 //
-// Reference the table being generated to prevent the optimizer from removing the
-// data structure from the executable
+// Reference the table being generated to prevent the optimizer
+// from removing the data structure from the executable
 //
 VOID* CONST ReferenceAcpiTable = &Gtdt;
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Madt.aslc b/Platform/RaspberryPi/RPi4/AcpiTables/Madt.aslc
index 39cd4c5cee6c..0027cb9fe8bb 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Madt.aslc
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Madt.aslc
@@ -1,52 +1,60 @@
 /** @file
- *
- *  Multiple APIC Description Table (MADT)
- *
- *  Copyright (c) 2018, Andrey Warkentin <andrey.warkentin@gmail.com>
- *  Copyright (c) Microsoft Corporation. All rights reserved.
- *
- *  SPDX-License-Identifier: BSD-2-Clause-Patent
- *
- **/
+*  Multiple APIC Description Table (MADT)
+*
+*  Copyright (c) 2016 Linaro Ltd. All rights reserved.
+*  Copyright (c) 2012 - 2015, ARM Limited. All rights reserved.
+*
+*  SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
 
-/*
- * Even though the BCM283x don't contain a GIC, these
- * GICC definitions enable multi-core support (with PSCI).
- *
- * Mind the signatures in the header, they must be kept.
- */
-UINT8 Madt[] = {
-  0x41, 0x50, 0x49, 0x43, 0x6c, 0x01, 0x00, 0x00, 0x03, 0xaf, 0x42, 0x43,
-  0x32, 0x38, 0x33, 0x36, 0x45, 0x44, 0x4b, 0x32, 0x20, 0x20, 0x20, 0x20,
-  0x01, 0x00, 0x00, 0x00, 0x4d, 0x53, 0x46, 0x54, 0x01, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x50, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x01, 0x00, 0x00, 0x00, 0x0b, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x0b, 0x50, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x50, 0x00, 0x00,
-  0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x01, 0x00, 0x00, 0x00
+#include "AcpiTables.h"
+#include <Library/AcpiLib.h>
+#include <Library/ArmLib.h>
+#include <Library/PcdLib.h>
+#include <IndustryStandard/Acpi51.h>
+
+//
+// Multiple APIC Description Table
+//
+#pragma pack (1)
+
+typedef struct {
+  EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER   Header;
+  EFI_ACPI_5_1_GIC_STRUCTURE                            GicInterfaces[4];
+  EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE                GicDistributor;
+} PI_MULTIPLE_APIC_DESCRIPTION_TABLE;
+
+#pragma pack ()
+
+PI_MULTIPLE_APIC_DESCRIPTION_TABLE Madt = {
+  {
+    ACPI_HEADER (
+      EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
+      PI_MULTIPLE_APIC_DESCRIPTION_TABLE,
+      EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION
+    ),
+    //
+    // MADT specific fields
+    //
+    0, // LocalApicAddress
+    0, // Flags
+  },
+  {
+    EFI_ACPI_5_1_GICC_STRUCTURE_INIT(
+        0, 0, GET_MPID(0, 0), EFI_ACPI_5_1_GIC_ENABLED, 48, FixedPcdGet64 (PcdGicInterruptInterfaceBase),
+        0xFF846000, 0xFF844000, 0x19, 0),
+    EFI_ACPI_5_1_GICC_STRUCTURE_INIT(
+        1, 1, GET_MPID(0, 1),  EFI_ACPI_5_1_GIC_ENABLED, 49, FixedPcdGet64 (PcdGicInterruptInterfaceBase),
+        0xFF846000, 0xFF844000, 0x19, 0),
+    EFI_ACPI_5_1_GICC_STRUCTURE_INIT(
+        2, 2, GET_MPID(0, 2),  EFI_ACPI_5_1_GIC_ENABLED, 50, FixedPcdGet64 (PcdGicInterruptInterfaceBase),
+        0xFF846000, 0xFF844000, 0x19, 0),
+    EFI_ACPI_5_1_GICC_STRUCTURE_INIT(
+        3, 3, GET_MPID(0, 3),  EFI_ACPI_5_1_GIC_ENABLED, 51, FixedPcdGet64 (PcdGicInterruptInterfaceBase),
+        0xFF846000, 0xFF844000, 0x19, 0),
+  },
+  EFI_ACPI_5_0_GIC_DISTRIBUTOR_INIT(0, FixedPcdGet64 (PcdGicDistributorBase), 0)
 };
 
 //
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.asl
index 2ddb27bcdbb3..7096109f8819 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.asl
@@ -2,6 +2,7 @@
  *
  *  Platform Extension Plugin (PEP).
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) 2018, Andrey Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
@@ -12,9 +13,9 @@
 Device(PEPD)
 {
   //
-  // RPI3 PEP virtual device.
+  // RPI4 PEP virtual device.
   //
-  Name (_HID, "BCM2854") // Note: since pep on rpi3 is virtual device,
+  Name (_HID, "BCM2854") // Note: since pep on rpi4 is virtual device,
   Name (_CID, "BCM2854") // its device id needs to be generated by Microsoft
   Name (_UID, 0x0)
   Name (_CRS, ResourceTemplate ()
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.c b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.c
index 51db779d7976..1a78392f05a0 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.c
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.c
@@ -2,6 +2,7 @@
  *
  *  PEP device tables
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
@@ -11,7 +12,7 @@
 
 #include "Pep.h"
 
-PEP_PROCESSOR_TABLE_PLAT RPI3Processors = {
+PEP_PROCESSOR_TABLE_PLAT RPI4Processors = {
   1, // Version
   1, // NumberProcessors
   {  // ProcessorInfo
@@ -29,7 +30,7 @@ PEP_PROCESSOR_TABLE_PLAT RPI3Processors = {
   }
 };
 
-PEP_COORDINATED_STATE_TABLE_PLAT RPI3CoordinatedStates = {
+PEP_COORDINATED_STATE_TABLE_PLAT RPI4CoordinatedStates = {
   1, // Version
   1, // CoordinatedStateCount
   { // CordinatedStates[]
@@ -51,7 +52,7 @@ PEP_COORDINATED_STATE_TABLE_PLAT RPI3CoordinatedStates = {
   }
 };
 
-PEP_DEVICE_TABLE_PLAT RPI3Devices = {
+PEP_DEVICE_TABLE_PLAT RPI4Devices = {
   1, // Version
   1, // NumberDevices
   { // DeviceInfo
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.h b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.h
index f5f04518dec6..19b801caf783 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Pep.h
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Pep.h
@@ -2,6 +2,7 @@
  *
  *  PEP device defines
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
@@ -13,8 +14,8 @@
  * Note: Not everything is here. At least SOC_STATE_TYPE is missing.
  */
 
-#ifndef _RPI3PEP_H_INCLUDED_
-#define _RPI3PEP_H_INCLUDED_
+#ifndef _RPI4PEP_H_INCLUDED_
+#define _RPI4PEP_H_INCLUDED_
 
 #include <IndustryStandard/Acpi50.h>
 
@@ -117,4 +118,4 @@ typedef struct _PEP_DEVICE_TABLE_PLAT {
   PEP_DEVICE_INFO_PLAT DeviceInfo[P_NUMBER_DEVICES];
 } PEP_DEVICE_TABLE_PLAT, *PPEP_DEVICE_TABLE_PLAT;
 
-#endif // _RPI3PEP_H_INCLUDED_
+#endif // _RPI4PEP_H_INCLUDED_
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Sdhc.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Sdhc.asl
index 0d42db30ae22..57ee411a6157 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Sdhc.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Sdhc.asl
@@ -32,7 +32,7 @@ Device (SDC1)
   {
     Name (RBUF, ResourceTemplate ()
     {
-      MEMORY32FIXED (ReadWrite, 0x3F300000, 0x100,)
+      MEMORY32FIXED (ReadWrite, 0xFE300000, 0x100,)
       Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x5E }
     })
     Return (RBUF)
@@ -75,7 +75,7 @@ Device (SDC2)
   {
     Name (RBUF, ResourceTemplate ()
     {
-      MEMORY32FIXED (ReadWrite, 0x3F202000, 0x100,)
+      MEMORY32FIXED (ReadWrite, 0xFE202000, 0x100,)
       Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x58 }
     })
     Return (RBUF)
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.asl
index 2e6a37323794..4632a4f193e7 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Spcr.asl
@@ -2,6 +2,7 @@
  *
  *  Serial Port Console Redirection Table (SPCR)
  *
+ *  Copyright (c) 2019, ARM Ltd. All rights reserved.
  *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -13,12 +14,12 @@
 [008h 0008   1]                     Revision : 02
 [009h 0009   1]                     Checksum : 00
 [00Ah 0010   6]                       Oem ID : "RPiEFI"
-[010h 0016   8]                 Oem Table ID : "RPi3UEFI"
+[010h 0016   8]                 Oem Table ID : "RPi4UEFI"
 [018h 0024   4]                 Oem Revision : 00000001
 [01Ch 0028   4]              Asl Compiler ID : "----"
 [020h 0032   4]        Asl Compiler Revision : 00000000
 
-[024h 0036   1]               Interface Type : 10
+[024h 0036   1]               Interface Type : 10     // 0x03 = PL011, 0x10 = BCM2835
 [025h 0037   3]                     Reserved : 000000
 
 [028h 0040  12]         Serial Port Register : [Generic Address Structure]
@@ -26,16 +27,16 @@
 [029h 0041   1]                    Bit Width : 20
 [02Ah 0042   1]                   Bit Offset : 00
 [02Bh 0043   1]         Encoded Access Width : 03 [DWord Access:32]
-[02Ch 0044   8]                      Address : 000000003f215000
+[02Ch 0044   8]                      Address : FE215000
 
-[034h 0052   1]               Interrupt Type : 0E
+[034h 0052   1]               Interrupt Type : 08     // ARMH GIC interrupt
 [035h 0053   1]          PCAT-compatible IRQ : 00
-[036h 0054   4]                    Interrupt : 3D
-[03Ah 0058   1]                    Baud Rate : 07
+[036h 0054   4]                    Interrupt : 7D
+[03Ah 0058   1]                    Baud Rate : 07     // 115200
 [03Bh 0059   1]                       Parity : 00
 [03Ch 0060   1]                    Stop Bits : 01
 [03Dh 0061   1]                 Flow Control : 00
-[03Eh 0062   1]                Terminal Type : 00
+[03Eh 0062   1]                Terminal Type : 02     // VT-UTF8
 [04Ch 0076   1]                     Reserved : 00
 [040h 0064   2]                PCI Device ID : FFFF
 [042h 0066   2]                PCI Vendor ID : FFFF
diff --git a/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl b/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl
index a0067c82c661..15149892f3b0 100644
--- a/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl
+++ b/Platform/RaspberryPi/RPi4/AcpiTables/Uart.asl
@@ -13,7 +13,7 @@
 Device (URT0)
 {
   Name (_HID, "BCM2837")
-  Name (_CID, "HID3123")
+  Name (_CID, "ARMH0011")
   Name (_UID, 0x4)
   Name (_CCA, 0x0)
   Method (_STA)
@@ -24,13 +24,13 @@ Device (URT0)
   {
     Name (RBUF, ResourceTemplate ()
     {
-      MEMORY32FIXED (ReadWrite, 0x3F201000, 0x1000,)
-      Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x59 }
+      MEMORY32FIXED (ReadWrite, 0xFE201000, 0x1000,)
+      Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { 0x99 }
     })
     Return (RBUF)
   }
 
-  Name (CLCK, 3000000)
+  Name (CLCK, 48000000)
 
   Name (_DSD, Package ()
   {
@@ -63,8 +63,8 @@ Device (URTM)
   {
     Name (RBUF, ResourceTemplate ()
     {
-      MEMORY32FIXED (ReadWrite, 0x3F215000, 0x70,)
-      Interrupt(ResourceConsumer, Level, ActiveHigh, Shared) {0x3D}
+      MEMORY32FIXED (ReadWrite, 0xFE215000, 0x70,)
+      Interrupt(ResourceConsumer, Level, ActiveHigh, Shared) { 0x7D }
 
       // NTRAID#MSFT-7141401-2016/04/7-jordanrh - disable UART muxing
       // until a proper solution can be created for the dmap conflict.
-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#52117): https://edk2.groups.io/g/devel/message/52117
Mute This Topic: https://groups.io/mt/68147487/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-