diff mbox series

[edk2,edk2-platforms,v1,36/38] Silicon/Hisilicon/setup: Support SMMU switch

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

Commit Message

Ming Huang July 24, 2018, 7: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>

Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

---
 Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 81 ++++++++++++++++++++
 1 file changed, 81 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. 6, 2018, 9:59 a.m. UTC | #1
On Tue, Jul 24, 2018 at 03:09:20PM +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>

> Signed-off-by: Heyi Guo <heyi.guo@linaro.org>

> ---

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

>  1 file changed, 81 insertions(+)

> 

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

> index 32878ca4f9..4f0998dd24 100644

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

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

> @@ -24,6 +24,83 @@

>  

>  #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);


Wrap long line.

> +  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));


Wrap long line.

/
    Leif

> +

> +  return Status;

> +}

> +

>  STATIC

>  VOID

>  RemoveUnusedMemoryNode (

> @@ -151,6 +228,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;

> -- 

> 2.17.0

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ming Huang Aug. 9, 2018, 2:19 p.m. UTC | #2
在 8/6/2018 5:59 PM, Leif Lindholm 写道:
> On Tue, Jul 24, 2018 at 03:09:20PM +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>
>> Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
>> ---
>>  Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 81 ++++++++++++++++++++
>>  1 file changed, 81 insertions(+)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
>> index 32878ca4f9..4f0998dd24 100644
>> --- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
>> +++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
>> @@ -24,6 +24,83 @@
>>  
>>  #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);
> 
> Wrap long line.
> 
>> +  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));
> 
> Wrap long line.

Modify it in v2.
Thanks.

> 
> /
>     Leif
> 
>> +
>> +  return Status;
>> +}
>> +
>>  STATIC
>>  VOID
>>  RemoveUnusedMemoryNode (
>> @@ -151,6 +228,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;
>> -- 
>> 2.17.0
>>
diff mbox series

Patch

diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
index 32878ca4f9..4f0998dd24 100644
--- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
+++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c
@@ -24,6 +24,83 @@ 
 
 #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 +228,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;