diff mbox series

[edk2,edk2-platforms,v2,40/43] Silicon/Hisilicon/setup: Support SMMU switch

Message ID 20180814080903.50466-41-ming.huang@linaro.org
State Superseded
Headers show
Series Upload for D06 platform | expand

Commit Message

Ming Huang Aug. 14, 2018, 8:09 a.m. UTC
Select without SMMU iort while SMMU item is disable,
Select with SMMU iort while SMMU item is enable.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang <ming.huang@linaro.org>

---
 Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 88 ++++++++++++++++++++
 1 file changed, 88 insertions(+)

-- 
2.17.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Leif Lindholm Aug. 22, 2018, 6:42 p.m. UTC | #1
Please correct the subject as per my prevoious comments on this.

On the whole, I think the enable/disable SMMU is a likely enough
scenario that we should probably have some core functionality for it
like for SPCR. For now I'm OK with this.

On Tue, Aug 14, 2018 at 04:09:00PM +0800, Ming Huang wrote:
> Select without SMMU iort while SMMU item is disable,

> Select with SMMU iort while SMMU item is enable.

> 

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ming Huang <ming.huang@linaro.org>

> ---

>  Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 88 ++++++++++++++++++++

>  1 file changed, 88 insertions(+)

> 

> diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c

> index 32878ca4f9..e0c29e0f57 100644

> --- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c

> +++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c

> @@ -24,6 +24,90 @@

>  

>  #define CORECOUNT(X) ((X) * CORE_NUM_PER_SOCKET)

>  

> +#define FIELD_IORT_NODE_OFFSET     40

> +

> +typedef enum {

> +  NodeTypeIts = 0,

> +  NodeTypeNameComponent,

> +  NodeTypePciRC,

> +  NodeTypeSmmuV1,

> +  NodeTypeSmmuV3,

> +  NodeTypePMCG

> +} IORT_NODE_TYPE;

> +

> +#pragma pack(1)

> +typedef struct {

> +  UINT8   Type;

> +  UINT16  Length;

> +  UINT8   Revision;

> +  UINT32  Reserved;

> +  UINT32  IdMapNumber;

> +  UINT32  IdArrayOffset;

> +} IORT_NODE_HEAD;

> +#pragma pack()

> +

> +BOOLEAN

> +IsIortWithSmmu (

> +  IN EFI_ACPI_DESCRIPTION_HEADER      *TableHeader

> +  )

> +{

> +  UINT32           *NodeOffset;

> +  UINT32           NextOffset;

> +  IORT_NODE_HEAD   *Node;

> +

> +  NodeOffset = (UINT32 *)((UINT8 *)TableHeader + FIELD_IORT_NODE_OFFSET);

> +  NextOffset = *NodeOffset;

> +

> +  while (NextOffset < TableHeader->Length) {

> +    Node = (IORT_NODE_HEAD *)((UINT8 *)TableHeader + NextOffset);

> +    NextOffset += Node->Length;

> +

> +    if ((Node->Type == NodeTypeSmmuV1) || (Node->Type == NodeTypeSmmuV3)) {

> +      return TRUE;

> +    }

> +  }

> +

> +  return FALSE;

> +}

> +

> +EFI_STATUS

> +SelectIort (

> +  IN EFI_ACPI_DESCRIPTION_HEADER      *TableHeader

> +  )

> +{

> +  EFI_STATUS          Status;

> +  UINTN               Size;

> +  OEM_CONFIG_DATA     Configuration;

> +

> +  Configuration.EnableSmmu = 0;

> +  Size = sizeof (OEM_CONFIG_DATA);

> +  Status = gRT->GetVariable (

> +                  OEM_CONFIG_NAME,

> +                  &gOemConfigGuid,

> +                  NULL,

> +                  &Size,

> +                  &Configuration

> +                  );

> +  if (EFI_ERROR (Status)) {

> +    DEBUG ((DEBUG_ERROR, "Get OemConfig variable (%r).\n", Status));

> +  }

> +

> +  Status =  EFI_SUCCESS;

> +  if (IsIortWithSmmu (TableHeader)) {

> +    if (!Configuration.EnableSmmu) {

> +      Status = EFI_ABORTED;

> +    }

> +  } else {

> +    if (Configuration.EnableSmmu) {

> +      Status = EFI_ABORTED;

> +    }

> +  }

> +  DEBUG ((DEBUG_INFO, "SmmuEnable=%x, return %r for Iort table.\n",

> +          Configuration.EnableSmmu, Status));

> +

> +  return Status;

> +}

> +

>  STATIC

>  VOID

>  RemoveUnusedMemoryNode (

> @@ -151,6 +235,10 @@ UpdateAcpiTable (

>    case EFI_ACPI_6_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE:

>      Status = UpdateSlit (TableHeader);

>      break;

> +


Drop this blank line.

/
    Leif

> +  case EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE:

> +    Status = SelectIort (TableHeader);

> +    break;

>    case EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE:

>      Status = IsNeedSpcr (TableHeader);

>      break;

> -- 

> 2.17.0

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
index 32878ca4f9..e0c29e0f57 100644
--- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
+++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
@@ -24,6 +24,90 @@ 
 
 #define CORECOUNT(X) ((X) * CORE_NUM_PER_SOCKET)
 
+#define FIELD_IORT_NODE_OFFSET     40
+
+typedef enum {
+  NodeTypeIts = 0,
+  NodeTypeNameComponent,
+  NodeTypePciRC,
+  NodeTypeSmmuV1,
+  NodeTypeSmmuV3,
+  NodeTypePMCG
+} IORT_NODE_TYPE;
+
+#pragma pack(1)
+typedef struct {
+  UINT8   Type;
+  UINT16  Length;
+  UINT8   Revision;
+  UINT32  Reserved;
+  UINT32  IdMapNumber;
+  UINT32  IdArrayOffset;
+} IORT_NODE_HEAD;
+#pragma pack()
+
+BOOLEAN
+IsIortWithSmmu (
+  IN EFI_ACPI_DESCRIPTION_HEADER      *TableHeader
+  )
+{
+  UINT32           *NodeOffset;
+  UINT32           NextOffset;
+  IORT_NODE_HEAD   *Node;
+
+  NodeOffset = (UINT32 *)((UINT8 *)TableHeader + FIELD_IORT_NODE_OFFSET);
+  NextOffset = *NodeOffset;
+
+  while (NextOffset < TableHeader->Length) {
+    Node = (IORT_NODE_HEAD *)((UINT8 *)TableHeader + NextOffset);
+    NextOffset += Node->Length;
+
+    if ((Node->Type == NodeTypeSmmuV1) || (Node->Type == NodeTypeSmmuV3)) {
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
+EFI_STATUS
+SelectIort (
+  IN EFI_ACPI_DESCRIPTION_HEADER      *TableHeader
+  )
+{
+  EFI_STATUS          Status;
+  UINTN               Size;
+  OEM_CONFIG_DATA     Configuration;
+
+  Configuration.EnableSmmu = 0;
+  Size = sizeof (OEM_CONFIG_DATA);
+  Status = gRT->GetVariable (
+                  OEM_CONFIG_NAME,
+                  &gOemConfigGuid,
+                  NULL,
+                  &Size,
+                  &Configuration
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Get OemConfig variable (%r).\n", Status));
+  }
+
+  Status =  EFI_SUCCESS;
+  if (IsIortWithSmmu (TableHeader)) {
+    if (!Configuration.EnableSmmu) {
+      Status = EFI_ABORTED;
+    }
+  } else {
+    if (Configuration.EnableSmmu) {
+      Status = EFI_ABORTED;
+    }
+  }
+  DEBUG ((DEBUG_INFO, "SmmuEnable=%x, return %r for Iort table.\n",
+          Configuration.EnableSmmu, Status));
+
+  return Status;
+}
+
 STATIC
 VOID
 RemoveUnusedMemoryNode (
@@ -151,6 +235,10 @@  UpdateAcpiTable (
   case EFI_ACPI_6_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE:
     Status = UpdateSlit (TableHeader);
     break;
+
+  case EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE:
+    Status = SelectIort (TableHeader);
+    break;
   case EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE:
     Status = IsNeedSpcr (TableHeader);
     break;