public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RFC edk2-platforms v1 0/3] Improve D0x
@ 2020-05-21 14:43 Ming Huang
  2020-05-21 14:43 ` [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event Ming Huang
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Ming Huang @ 2020-05-21 14:43 UTC (permalink / raw)
  To: devel, leif, ard.biesheuvel
  Cc: lidongzhan, huangming23, songdongkuang, wanghuiqiang, qiuliangen

Main Changes:
Add update sas address feature in AcpiPlatformDxe.

Ming Huang (3):
  Silicon/Hisilicon: Change updating dsdt in ready to boot event
  Silicon/Hisilicon/Acpi: Add update sas address feature
  Silicon/Hisilicon: Rename EthMac files

 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |  62 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 500 ----------------
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
 6 files changed, 689 insertions(+), 525 deletions(-)
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
 delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
 create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h

-- 
2.8.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event
  2020-05-21 14:43 [RFC edk2-platforms v1 0/3] Improve D0x Ming Huang
@ 2020-05-21 14:43 ` Ming Huang
  2020-05-26 17:40   ` Leif Lindholm
  2020-05-21 14:43 ` [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature Ming Huang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Ming Huang @ 2020-05-21 14:43 UTC (permalink / raw)
  To: devel, leif, ard.biesheuvel
  Cc: lidongzhan, huangming23, songdongkuang, wanghuiqiang, qiuliangen

The better time for updating dsdt is in ready to boot event,
so change the updating time.

Signed-off-by: Ming Huang <huangming23@huawei.com>
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c | 60 ++++++++++++++++++--
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index b888cb1..1ab55bc 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -1,8 +1,8 @@
 /** @file
 
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
-  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -23,6 +23,38 @@
 #include <IndustryStandard/AcpiAml.h>
 #include "EthMac.h"
 
+EFI_EVENT       mUpdateAcpiDsdtTableEvent;
+
+VOID
+EFIAPI
+UpdateAcpiDsdt (
+  IN EFI_EVENT         Event,
+  IN VOID              *Context
+  )
+{
+  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
+  EFI_STATUS              Status;
+
+  Status = gBS->LocateProtocol (
+                  &gEfiAcpiTableProtocolGuid,
+                  NULL,
+                  (VOID**)&AcpiTableProtocol
+                  );
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
+    return;
+  }
+
+  Status = EthMacInit ();
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
+  }
+
+  gBS->CloseEvent (Event);
+  return;
+}
+
 EFI_STATUS
 EFIAPI
 AcpiPlatformEntryPoint (
@@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  return EthMacInit();
+  EFI_STATUS Status;
+
+  //
+  // Register notify function
+  //
+  Status = gBS->CreateEventEx (
+                  EVT_NOTIFY_SIGNAL,
+                  TPL_CALLBACK,
+                  UpdateAcpiDsdt,
+                  NULL,
+                  &gEfiEventReadyToBootGuid,
+                  &mUpdateAcpiDsdtTableEvent
+                  );
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt failed.\n"));
+  } else {
+    DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt success.\n"));
+  }
+
+  return Status;
 }
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature
  2020-05-21 14:43 [RFC edk2-platforms v1 0/3] Improve D0x Ming Huang
  2020-05-21 14:43 ` [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event Ming Huang
@ 2020-05-21 14:43 ` Ming Huang
  2020-05-26 18:49   ` Leif Lindholm
  2020-05-21 14:43 ` [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files Ming Huang
  2020-05-26 18:09 ` [RFC edk2-platforms v1 0/3] Improve D0x Leif Lindholm
  3 siblings, 1 reply; 12+ messages in thread
From: Ming Huang @ 2020-05-21 14:43 UTC (permalink / raw)
  To: devel, leif, ard.biesheuvel
  Cc: lidongzhan, huangming23, songdongkuang, wanghuiqiang, qiuliangen

The updating sas address feature is similar with apdating mac address.
Modify updating dsdt flow for add this feature.

Signed-off-by: Ming Huang <huangming23@huawei.com>
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c       | 200 +++++++++++++++-----
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h       |   2 +-
 3 files changed, 158 insertions(+), 46 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index 1ab55bc..d3ea051 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -46,7 +46,7 @@ UpdateAcpiDsdt (
     return;
   }
 
-  Status = EthMacInit ();
+  Status = UpdateAcpiDsdtTable ();
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
   }
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
index cd98506..205f2f9 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
@@ -1,8 +1,8 @@
 /** @file
 
-  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
-  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
-  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   This driver is called to initialize the FW part of the PHY in preparation
@@ -30,6 +30,7 @@
 #include <Library/UefiRuntimeServicesTableLib.h>
 #include <IndustryStandard/Acpi.h>
 #include <IndustryStandard/AcpiAml.h>
+#include <Library/MemoryAllocationLib.h>
 
 #include <Protocol/HisiBoardNicProtocol.h>
 
@@ -45,13 +46,20 @@
 #define EFI_ACPI_MAX_NUM_TABLES         20
 #define DSDT_SIGNATURE                  0x54445344
 
-#define D03_ACPI_ETH_ID                     "HISI00C2"
-
 #define ACPI_ETH_MAC_KEY                "local-mac-address"
+#define ACPI_ETH_SAS_KEY                 "sas-addr"
 
 #define PREFIX_VARIABLE_NAME            L"MAC"
 #define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
-#define MAC_MAX_LEN                     30
+#define ADDRESS_MAX_LEN                     30
+
+CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
+
+typedef enum {
+  DsdtDeviceUnknown,
+  DsdtDeviceLan,
+  DsdtDeviceSas
+} DSDT_DEVICE_TYPE;
 
 EFI_STATUS GetEnvMac(
   IN          UINTN    MacNextID,
@@ -89,12 +97,35 @@ EFI_STATUS GetEnvMac(
   return EFI_SUCCESS;
 }
 
-EFI_STATUS _SearchReplacePackageMACAddress(
+EFI_STATUS GetSasAddress (
+  IN UINT8        Index,
+  IN OUT UINT8    *SasAddrBuffer
+  )
+{
+  if (SasAddrBuffer == NULL) {
+      return EFI_INVALID_PARAMETER;
+  }
+
+  SasAddrBuffer[0] = 0x50;
+  SasAddrBuffer[1] = 0x01;
+  SasAddrBuffer[2] = 0x88;
+  SasAddrBuffer[3] = 0x20;
+  SasAddrBuffer[4] = 0x16;
+  SasAddrBuffer[5] = 0x00;
+  SasAddrBuffer[6] = 0x00;
+  SasAddrBuffer[7] = Index;
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS _SearchReplacePackageAddress(
   IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
   IN EFI_ACPI_HANDLE        ChildHandle,
   IN UINTN                  Level,
   IN OUT BOOLEAN            *Found,
-  IN UINTN                  MacNextID)
+  IN UINTN                  DevNextID,
+  IN DSDT_DEVICE_TYPE       FoundDev
+  )
 {
   // ASL template for ethernet driver:
 /*
@@ -117,12 +148,18 @@ EFI_STATUS _SearchReplacePackageMACAddress(
   UINTN               Count;
   EFI_ACPI_HANDLE     CurrentHandle;
   EFI_ACPI_HANDLE     NextHandle;
-  UINT8               MACBuffer[MAC_MAX_LEN];
+  EFI_ACPI_HANDLE     Level1Handle;
+  UINT8               *AddressBuffer;
+  UINT8               AddressByte = 0;
 
   DBG("In Level:%d\n", Level);
+  Level1Handle = NULL;
   Status = EFI_SUCCESS;
   for (CurrentHandle = NULL; ;) {
     Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
+    if (Level == 1) {
+      Level1Handle = CurrentHandle;
+    }
     if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
        break;
 
@@ -143,11 +180,14 @@ EFI_STATUS _SearchReplacePackageMACAddress(
               DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
 
       Data = Buffer;
-      if (DataType != EFI_ACPI_DATA_TYPE_STRING
-              || AsciiStrCmp((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0)
+      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
+            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
+            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
+        ChildHandle = Level1Handle;
         continue;
+      }
 
-      DBG("_DSD Key Type %d. Found MAC address key\n", DataType);
+      DBG("_DSD Key Type %d. Found address key\n", DataType);
 
       //
       // We found the node.
@@ -157,13 +197,33 @@ EFI_STATUS _SearchReplacePackageMACAddress(
     }
 
     if (Level == 3 && *Found) {
+      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
+      if (AddressBuffer == NULL) {
+        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
+        return EFI_OUT_OF_RESOURCES;
+      }
 
-      //Update the MAC
-      Status = GetEnvMac(MacNextID, MACBuffer);
-      if (EFI_ERROR(Status))
+      switch (FoundDev) {
+        case DsdtDeviceLan:
+          //Update the MAC
+          Status = GetEnvMac (DevNextID, AddressBuffer);
+          AddressByte = 6;
+          break;
+        case DsdtDeviceSas:
+          //Update SAS Address.
+          Status = GetSasAddress (DevNextID, AddressBuffer);
+          AddressByte = 8;
+          break;
+        default:
+          Status = EFI_INVALID_PARAMETER;
+      }
+      if (EFI_ERROR (Status)) {
+        FreePool (AddressBuffer);
+        AddressBuffer = NULL;
         break;
+      }
 
-      for (Count = 0; Count < 6; Count++) {
+      for (Count = 0; Count < AddressByte; Count++) {
         Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
         if (EFI_ERROR(Status))
           break;
@@ -177,13 +237,15 @@ EFI_STATUS _SearchReplacePackageMACAddress(
 
         // only need one byte.
         // FIXME: Assume the CPU is little endian
-        Status = AcpiTableProtocol->SetOption(CurrentHandle, 1, (VOID *)&MACBuffer[Count], sizeof(UINT8));
+        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
         if (EFI_ERROR(Status))
           break;
         Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
         if (EFI_ERROR(Status) || CurrentHandle == NULL)
           break;
       }
+      FreePool (AddressBuffer);
+      AddressBuffer = NULL;
       break;
     }
 
@@ -192,7 +254,13 @@ EFI_STATUS _SearchReplacePackageMACAddress(
 
     //Search next package
     AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
-    Status = _SearchReplacePackageMACAddress(AcpiTableProtocol, NextHandle, Level + 1, Found, MacNextID);
+    Status = _SearchReplacePackageAddress(
+               AcpiTableProtocol,
+               NextHandle,
+               Level + 1,
+               Found,
+               DevNextID,
+               FoundDev);
     AcpiTableProtocol->Close(NextHandle);
     if (!EFI_ERROR(Status))
       break;
@@ -201,22 +269,26 @@ EFI_STATUS _SearchReplacePackageMACAddress(
   return Status;
 }
 
-EFI_STATUS SearchReplacePackageMACAddress(
+EFI_STATUS SearchReplacePackageAddress(
   IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
   IN EFI_ACPI_HANDLE        ChildHandle,
-  IN UINTN                  MacNextID)
+  IN UINTN                  DevNextID,
+  IN DSDT_DEVICE_TYPE       FoundDev
+  )
 {
   BOOLEAN Found = FALSE;
   UINTN Level = 0;
 
-  return _SearchReplacePackageMACAddress(AcpiTableProtocol, ChildHandle, Level, &Found, MacNextID);
+  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
+                                      &Found, DevNextID, FoundDev);
 }
 
 EFI_STATUS
-GetEthID (
+GetDeviceInfo (
   EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
   EFI_ACPI_HANDLE         ChildHandle,
-  UINTN                   *EthID
+  UINTN                   *DevID,
+  DSDT_DEVICE_TYPE        *FoundDev
   )
 {
   EFI_STATUS Status;
@@ -225,7 +297,7 @@ GetEthID (
   CONST VOID          *Buffer;
   UINTN               DataSize;
 
-  // Get NameString ETHx
+  // Get NameString
   Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
   if (EFI_ERROR (Status)) {
     DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
@@ -236,14 +308,23 @@ GetEthID (
   DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
 
   Data[4] = '\0';
-  if (DataSize != 4 ||
-      AsciiStrnCmp ("ETH", Data, 3) != 0 ||
-      Data[3] > '9' || Data[3] < '0') {
-    DEBUG ((EFI_D_ERROR, "[%a:%d] The NameString %a is not ETHn\n", __FUNCTION__, __LINE__, Data));
+  if ((DataSize != 4) ||
+    (Data[3] > '9' || Data[3] < '0')) {
+    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
     return EFI_INVALID_PARAMETER;
   }
 
-  *EthID = Data[3] - '0';
+  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
+    *FoundDev = DsdtDeviceLan;
+  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
+    *FoundDev = DsdtDeviceSas;
+  } else {
+    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
+            __FUNCTION__, __LINE__, Data));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *DevID = Data[3] - '0';
   return EFI_SUCCESS;
 }
 
@@ -257,8 +338,10 @@ EFI_STATUS ProcessDSDTDevice (
   CONST VOID          *Buffer;
   UINTN               DataSize;
   EFI_ACPI_HANDLE     DevHandle;
-  INTN                Found = 0;
-  UINTN               MacNextID;
+  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
+  UINTN               DevNextID;
+  BOOLEAN             HisiAcpiDevNotFound;
+  UINTN               Index;
 
   Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
   if (EFI_ERROR(Status))
@@ -280,7 +363,7 @@ EFI_STATUS ProcessDSDTDevice (
       break;
 
     //
-    // Search for _HID with Ethernet ID
+    // Search for _HID with Device ID
     //
     Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
     if (EFI_ERROR(Status))
@@ -312,23 +395,34 @@ EFI_STATUS ProcessDSDTDevice (
           DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
 
           if (EFI_ERROR(Status) ||
-              DataType != EFI_ACPI_DATA_TYPE_STRING ||
-              (AsciiStrCmp((CHAR8 *) Data, D03_ACPI_ETH_ID) != 0)) {
-            AcpiTableProtocol->Close(ValueHandle);
-            Found = 0;
+              DataType != EFI_ACPI_DATA_TYPE_STRING) {
+            AcpiTableProtocol->Close (ValueHandle);
+            FoundDev = DsdtDeviceUnknown;
+            continue;
+          }
+
+          HisiAcpiDevNotFound = TRUE;
+          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
+            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
+              HisiAcpiDevNotFound = FALSE;
+              break;
+            }
+          }
+          if (HisiAcpiDevNotFound) {
+            AcpiTableProtocol->Close (ValueHandle);
+            FoundDev = DsdtDeviceUnknown;
             continue;
           }
 
-          DBG("Found Ethernet device\n");
+          DBG("Found device\n");
           AcpiTableProtocol->Close(ValueHandle);
-          Status = GetEthID (AcpiTableProtocol, ChildHandle, &MacNextID);
+          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
           if (EFI_ERROR (Status)) {
             continue;
           }
-          Found = 1;
-        } else if (Found == 1 && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
+        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
           //
-          // Patch MAC address for open source kernel
+          // Patch DSD data
           //
           EFI_ACPI_HANDLE    PkgHandle;
           Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
@@ -351,12 +445,30 @@ EFI_STATUS ProcessDSDTDevice (
           //
           // Walk the _DSD node
           //
-          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP)
-            Status = SearchReplacePackageMACAddress(AcpiTableProtocol, PkgHandle, MacNextID);
+          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
+            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
+          }
 
           AcpiTableProtocol->Close(PkgHandle);
+        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
+          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
+          if (EFI_ERROR (Status)) {
+            break;
+          }
+
+          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
+            continue;
+          }
+
+          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
+
+          if (EFI_ERROR (Status)) {
+            continue;
+          }
         }
       }
+    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
+      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
     }
   }
 
@@ -457,7 +569,7 @@ AcpiCheckSum (
   Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
 }
 
-EFI_STATUS EthMacInit(void)
+EFI_STATUS UpdateAcpiDsdtTable(void)
 {
   EFI_STATUS              Status;
   EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
index 0a3e811..a7e1eed 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
@@ -10,7 +10,7 @@
 #ifndef _ETH_MAC_H_
 #define _ETH_MAC_H_
 
-EFI_STATUS EthMacInit(VOID);
+EFI_STATUS UpdateAcpiDsdtTable (VOID);
 
 #endif
 
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files
  2020-05-21 14:43 [RFC edk2-platforms v1 0/3] Improve D0x Ming Huang
  2020-05-21 14:43 ` [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event Ming Huang
  2020-05-21 14:43 ` [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature Ming Huang
@ 2020-05-21 14:43 ` Ming Huang
  2020-05-26 18:50   ` Leif Lindholm
  2020-05-26 18:09 ` [RFC edk2-platforms v1 0/3] Improve D0x Leif Lindholm
  3 siblings, 1 reply; 12+ messages in thread
From: Ming Huang @ 2020-05-21 14:43 UTC (permalink / raw)
  To: devel, leif, ard.biesheuvel
  Cc: lidongzhan, huangming23, songdongkuang, wanghuiqiang, qiuliangen

As not only update mac address feature in EthMac files, so rename
them to UpdateDsdt.

Signed-off-by: Ming Huang <huangming23@huawei.com>
---
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |   2 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 612 --------------------
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
 6 files changed, 633 insertions(+), 633 deletions(-)

diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index d3ea051..fd67677 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -21,7 +21,7 @@
 #include <Library/UefiRuntimeServicesTableLib.h>
 #include <IndustryStandard/Acpi.h>
 #include <IndustryStandard/AcpiAml.h>
-#include "EthMac.h"
+#include "UpdateDsdt.h"
 
 EFI_EVENT       mUpdateAcpiDsdtTableEvent;
 
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 53da731..a2b669d 100644
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -1,8 +1,8 @@
 ## @file
 #
-#  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.<BR>
-#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
-#  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+#  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights reserved.<BR>
+#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
+#  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -18,7 +18,7 @@
 
 [Sources]
   AcpiPlatform.c
-  EthMac.c
+  UpdateDsdt.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
deleted file mode 100644
index 205f2f9..0000000
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/** @file
-
-  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
-  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
-  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-
-  This driver is called to initialize the FW part of the PHY in preparation
-  for the OS.
-
-**/
-
-#include <Guid/ShellVariableGuid.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Library/TimerLib.h>
-
-#include <PiDxe.h>
-#include <Guid/EventGroup.h>
-#include <Protocol/AcpiTable.h>
-#include <Protocol/FirmwareVolume2.h>
-#include <Library/BaseLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Protocol/AcpiSystemDescriptionTable.h>
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/PrintLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <IndustryStandard/Acpi.h>
-#include <IndustryStandard/AcpiAml.h>
-#include <Library/MemoryAllocationLib.h>
-
-#include <Protocol/HisiBoardNicProtocol.h>
-
-// Turn on debug message by enabling below define
-//#define ACPI_DEBUG
-
-#ifdef ACPI_DEBUG
-#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
-#else
-#define DBG(arg...)
-#endif
-
-#define EFI_ACPI_MAX_NUM_TABLES         20
-#define DSDT_SIGNATURE                  0x54445344
-
-#define ACPI_ETH_MAC_KEY                "local-mac-address"
-#define ACPI_ETH_SAS_KEY                 "sas-addr"
-
-#define PREFIX_VARIABLE_NAME            L"MAC"
-#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
-#define ADDRESS_MAX_LEN                     30
-
-CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
-
-typedef enum {
-  DsdtDeviceUnknown,
-  DsdtDeviceLan,
-  DsdtDeviceSas
-} DSDT_DEVICE_TYPE;
-
-EFI_STATUS GetEnvMac(
-  IN          UINTN    MacNextID,
-  IN OUT      UINT8    *MacBuffer)
-{
-  EFI_MAC_ADDRESS Mac;
-  EFI_STATUS Status;
-  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
-
-  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
-  if(EFI_ERROR(Status))
-  {
-    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
-    return Status;
-  }
-
-  Status = OemNic->GetMac(&Mac, MacNextID);
-  if(EFI_ERROR(Status))
-  {
-    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
-    return Status;
-  }
-
-  CopyMem (MacBuffer, &Mac, 6);
-  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
-        MacNextID,
-        MacBuffer[0],
-        MacBuffer[1],
-        MacBuffer[2],
-        MacBuffer[3],
-        MacBuffer[4],
-        MacBuffer[5]
-        ));
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS GetSasAddress (
-  IN UINT8        Index,
-  IN OUT UINT8    *SasAddrBuffer
-  )
-{
-  if (SasAddrBuffer == NULL) {
-      return EFI_INVALID_PARAMETER;
-  }
-
-  SasAddrBuffer[0] = 0x50;
-  SasAddrBuffer[1] = 0x01;
-  SasAddrBuffer[2] = 0x88;
-  SasAddrBuffer[3] = 0x20;
-  SasAddrBuffer[4] = 0x16;
-  SasAddrBuffer[5] = 0x00;
-  SasAddrBuffer[6] = 0x00;
-  SasAddrBuffer[7] = Index;
-
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS _SearchReplacePackageAddress(
-  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
-  IN EFI_ACPI_HANDLE        ChildHandle,
-  IN UINTN                  Level,
-  IN OUT BOOLEAN            *Found,
-  IN UINTN                  DevNextID,
-  IN DSDT_DEVICE_TYPE       FoundDev
-  )
-{
-  // ASL template for ethernet driver:
-/*
- *   Name (_DSD, Package () {
- *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
- *   Package () {
- *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
- *     Package (2) {"phy-channel", 0},
- *     Package (2) {"phy-mode", "rgmii"},
- *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
- *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
- *   }
- * })
- */
-  EFI_STATUS          Status;
-  EFI_ACPI_DATA_TYPE  DataType;
-  CONST UINT8         *Data;
-  CONST VOID          *Buffer;
-  UINTN               DataSize;
-  UINTN               Count;
-  EFI_ACPI_HANDLE     CurrentHandle;
-  EFI_ACPI_HANDLE     NextHandle;
-  EFI_ACPI_HANDLE     Level1Handle;
-  UINT8               *AddressBuffer;
-  UINT8               AddressByte = 0;
-
-  DBG("In Level:%d\n", Level);
-  Level1Handle = NULL;
-  Status = EFI_SUCCESS;
-  for (CurrentHandle = NULL; ;) {
-    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
-    if (Level == 1) {
-      Level1Handle = CurrentHandle;
-    }
-    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
-       break;
-
-    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
-    Data = Buffer;
-    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
-        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
-
-    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
-      continue;
-
-    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
-      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
-      if (EFI_ERROR(Status))
-        break;
-
-      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
-              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
-
-      Data = Buffer;
-      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
-            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
-            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
-        ChildHandle = Level1Handle;
-        continue;
-      }
-
-      DBG("_DSD Key Type %d. Found address key\n", DataType);
-
-      //
-      // We found the node.
-      //
-      *Found = TRUE;
-      continue;
-    }
-
-    if (Level == 3 && *Found) {
-      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
-      if (AddressBuffer == NULL) {
-        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
-        return EFI_OUT_OF_RESOURCES;
-      }
-
-      switch (FoundDev) {
-        case DsdtDeviceLan:
-          //Update the MAC
-          Status = GetEnvMac (DevNextID, AddressBuffer);
-          AddressByte = 6;
-          break;
-        case DsdtDeviceSas:
-          //Update SAS Address.
-          Status = GetSasAddress (DevNextID, AddressBuffer);
-          AddressByte = 8;
-          break;
-        default:
-          Status = EFI_INVALID_PARAMETER;
-      }
-      if (EFI_ERROR (Status)) {
-        FreePool (AddressBuffer);
-        AddressBuffer = NULL;
-        break;
-      }
-
-      for (Count = 0; Count < AddressByte; Count++) {
-        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
-        if (EFI_ERROR(Status))
-          break;
-
-        Data = Buffer;
-        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
-            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
-
-        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
-          break;
-
-        // only need one byte.
-        // FIXME: Assume the CPU is little endian
-        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
-        if (EFI_ERROR(Status))
-          break;
-        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
-        if (EFI_ERROR(Status) || CurrentHandle == NULL)
-          break;
-      }
-      FreePool (AddressBuffer);
-      AddressBuffer = NULL;
-      break;
-    }
-
-    if (Level > 3)
-      break;
-
-    //Search next package
-    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
-    Status = _SearchReplacePackageAddress(
-               AcpiTableProtocol,
-               NextHandle,
-               Level + 1,
-               Found,
-               DevNextID,
-               FoundDev);
-    AcpiTableProtocol->Close(NextHandle);
-    if (!EFI_ERROR(Status))
-      break;
-  }
-
-  return Status;
-}
-
-EFI_STATUS SearchReplacePackageAddress(
-  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
-  IN EFI_ACPI_HANDLE        ChildHandle,
-  IN UINTN                  DevNextID,
-  IN DSDT_DEVICE_TYPE       FoundDev
-  )
-{
-  BOOLEAN Found = FALSE;
-  UINTN Level = 0;
-
-  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
-                                      &Found, DevNextID, FoundDev);
-}
-
-EFI_STATUS
-GetDeviceInfo (
-  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
-  EFI_ACPI_HANDLE         ChildHandle,
-  UINTN                   *DevID,
-  DSDT_DEVICE_TYPE        *FoundDev
-  )
-{
-  EFI_STATUS Status;
-  EFI_ACPI_DATA_TYPE  DataType;
-  CHAR8               Data[5];
-  CONST VOID          *Buffer;
-  UINTN               DataSize;
-
-  // Get NameString
-  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
-    return Status;
-  }
-
-  CopyMem (Data, Buffer, 4);
-  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
-
-  Data[4] = '\0';
-  if ((DataSize != 4) ||
-    (Data[3] > '9' || Data[3] < '0')) {
-    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
-    *FoundDev = DsdtDeviceLan;
-  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
-    *FoundDev = DsdtDeviceSas;
-  } else {
-    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
-            __FUNCTION__, __LINE__, Data));
-    return EFI_INVALID_PARAMETER;
-  }
-
-  *DevID = Data[3] - '0';
-  return EFI_SUCCESS;
-}
-
-EFI_STATUS ProcessDSDTDevice (
-  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
-  EFI_ACPI_HANDLE ChildHandle)
-{
-  EFI_STATUS          Status;
-  EFI_ACPI_DATA_TYPE  DataType;
-  CONST UINT8         *Data;
-  CONST VOID          *Buffer;
-  UINTN               DataSize;
-  EFI_ACPI_HANDLE     DevHandle;
-  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
-  UINTN               DevNextID;
-  BOOLEAN             HisiAcpiDevNotFound;
-  UINTN               Index;
-
-  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
-  if (EFI_ERROR(Status))
-    return EFI_SUCCESS;
-
-  Data = Buffer;
-  //
-  // Skip all non-device type
-  //
-  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
-    return EFI_SUCCESS;
-
-  //
-  // Walk the device type node
-  //
-  for (DevHandle = NULL; ; ) {
-    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
-    if (EFI_ERROR(Status) || DevHandle == NULL)
-      break;
-
-    //
-    // Search for _HID with Device ID
-    //
-    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
-    if (EFI_ERROR(Status))
-      break;
-
-    Data = Buffer;
-    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
-    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
-      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
-      if (EFI_ERROR(Status))
-        break;
-
-      Data = Buffer;
-      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
-        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
-          EFI_ACPI_HANDLE ValueHandle;
-
-          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
-          if (EFI_ERROR(Status))
-            break;
-
-          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
-            continue;
-
-          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
-          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
-
-          Data = Buffer;
-          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
-
-          if (EFI_ERROR(Status) ||
-              DataType != EFI_ACPI_DATA_TYPE_STRING) {
-            AcpiTableProtocol->Close (ValueHandle);
-            FoundDev = DsdtDeviceUnknown;
-            continue;
-          }
-
-          HisiAcpiDevNotFound = TRUE;
-          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
-            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
-              HisiAcpiDevNotFound = FALSE;
-              break;
-            }
-          }
-          if (HisiAcpiDevNotFound) {
-            AcpiTableProtocol->Close (ValueHandle);
-            FoundDev = DsdtDeviceUnknown;
-            continue;
-          }
-
-          DBG("Found device\n");
-          AcpiTableProtocol->Close(ValueHandle);
-          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
-          if (EFI_ERROR (Status)) {
-            continue;
-          }
-        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
-          //
-          // Patch DSD data
-          //
-          EFI_ACPI_HANDLE    PkgHandle;
-          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
-          if (EFI_ERROR(Status))
-            break;
-
-          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
-            continue;
-
-          //
-          // Open package data
-          //
-          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
-          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
-
-          Data = Buffer;
-          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
-                Data[0], DataSize > 1 ? Data[1] : 0);
-
-          //
-          // Walk the _DSD node
-          //
-          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
-            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
-          }
-
-          AcpiTableProtocol->Close(PkgHandle);
-        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
-          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
-          if (EFI_ERROR (Status)) {
-            break;
-          }
-
-          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
-            continue;
-          }
-
-          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
-
-          if (EFI_ERROR (Status)) {
-            continue;
-          }
-        }
-      }
-    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
-      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
-    }
-  }
-
-  return EFI_SUCCESS;
-}
-
-
-BOOLEAN
-IsSbScope (
-  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
-  EFI_ACPI_HANDLE         ChildHandle
-  )
-{
-  EFI_STATUS          Status;
-  EFI_ACPI_DATA_TYPE  DataType;
-  CONST UINT8         *Data;
-  CONST VOID          *Buffer;
-  UINTN               DataSize;
-
-  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
-  if (EFI_ERROR(Status)) return FALSE;
-
-  Data = Buffer;
-  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-
-EFI_STATUS ProcessDSDTChild(
-  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
-  EFI_ACPI_HANDLE ChildHandle)
-{
-  EFI_STATUS          Status;
-  EFI_ACPI_HANDLE     DevHandle;
-
-  // Check Scope(_SB) at first
-  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
-    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
-  }
-
-  for (DevHandle = NULL; ; ) {
-    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
-    if (EFI_ERROR(Status) || DevHandle == NULL) {
-      break;
-    }
-
-    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
-  }
-
-  return EFI_SUCCESS;
-}
-
-static EFI_STATUS ProcessDSDT(
-  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
-  EFI_ACPI_HANDLE TableHandle)
-{
-  EFI_STATUS              Status;
-  EFI_ACPI_HANDLE         ChildHandle;
-  //
-  // Parse table for device type
-  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
-  for (ChildHandle = NULL; ; ) {
-    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
-    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
-    if (EFI_ERROR(Status))
-      break;
-    if (ChildHandle == NULL)
-      break;
-
-    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
-  }
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-VOID
-AcpiCheckSum (
-  IN OUT  EFI_ACPI_SDT_HEADER *Table
-  )
-{
-  UINTN ChecksumOffset;
-  UINT8 *Buffer;
-
-  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
-  Buffer = (UINT8 *)Table;
-
-  //
-  // set checksum to 0 first
-  //
-  Buffer[ChecksumOffset] = 0;
-
-  //
-  // Update checksum value
-  //
-  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
-}
-
-EFI_STATUS UpdateAcpiDsdtTable(void)
-{
-  EFI_STATUS              Status;
-  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
-  EFI_ACPI_SDT_HEADER     *Table;
-  EFI_ACPI_TABLE_VERSION  TableVersion;
-  UINTN                   TableKey;
-  EFI_ACPI_HANDLE         TableHandle;
-  UINTN                   i;
-
-  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
-
-  //
-  // Find the AcpiTable protocol
-  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
-  if (EFI_ERROR(Status)) {
-    DBG("Unable to locate ACPI table protocol\n");
-    return EFI_SUCCESS;
-  }
-
-  //
-  // Search for DSDT Table
-  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
-    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
-    if (EFI_ERROR(Status))
-      break;
-    if (Table->Signature != DSDT_SIGNATURE)
-      continue;
-
-    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
-    if (EFI_ERROR(Status))
-      break;
-
-    ProcessDSDT(AcpiTableProtocol, TableHandle);
-
-    AcpiTableProtocol->Close(TableHandle);
-    AcpiCheckSum (Table);
-  }
-
-  return EFI_SUCCESS;
-}
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
deleted file mode 100644
index a7e1eed..0000000
--- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- *
- * Copyright (c) 2014, Applied Micro Circuits Corporation
- * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
- * Copyright (c) 2015, Linaro Limited. All rights reserved.
- * Author: Loc Ho <lho@apm.com>
- *
- * SPDX-License-Identifier: BSD-2-Clause-Patent
- */
-#ifndef _ETH_MAC_H_
-#define _ETH_MAC_H_
-
-EFI_STATUS UpdateAcpiDsdtTable (VOID);
-
-#endif
-
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
new file mode 100644
index 0000000..205f2f9
--- /dev/null
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
@@ -0,0 +1,612 @@
+/** @file
+
+  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  This driver is called to initialize the FW part of the PHY in preparation
+  for the OS.
+
+**/
+
+#include <Guid/ShellVariableGuid.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/TimerLib.h>
+
+#include <PiDxe.h>
+#include <Guid/EventGroup.h>
+#include <Protocol/AcpiTable.h>
+#include <Protocol/FirmwareVolume2.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/AcpiSystemDescriptionTable.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PrintLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <IndustryStandard/Acpi.h>
+#include <IndustryStandard/AcpiAml.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Protocol/HisiBoardNicProtocol.h>
+
+// Turn on debug message by enabling below define
+//#define ACPI_DEBUG
+
+#ifdef ACPI_DEBUG
+#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
+#else
+#define DBG(arg...)
+#endif
+
+#define EFI_ACPI_MAX_NUM_TABLES         20
+#define DSDT_SIGNATURE                  0x54445344
+
+#define ACPI_ETH_MAC_KEY                "local-mac-address"
+#define ACPI_ETH_SAS_KEY                 "sas-addr"
+
+#define PREFIX_VARIABLE_NAME            L"MAC"
+#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
+#define ADDRESS_MAX_LEN                     30
+
+CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
+
+typedef enum {
+  DsdtDeviceUnknown,
+  DsdtDeviceLan,
+  DsdtDeviceSas
+} DSDT_DEVICE_TYPE;
+
+EFI_STATUS GetEnvMac(
+  IN          UINTN    MacNextID,
+  IN OUT      UINT8    *MacBuffer)
+{
+  EFI_MAC_ADDRESS Mac;
+  EFI_STATUS Status;
+  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
+
+  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
+  if(EFI_ERROR(Status))
+  {
+    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
+    return Status;
+  }
+
+  Status = OemNic->GetMac(&Mac, MacNextID);
+  if(EFI_ERROR(Status))
+  {
+    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
+    return Status;
+  }
+
+  CopyMem (MacBuffer, &Mac, 6);
+  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
+        MacNextID,
+        MacBuffer[0],
+        MacBuffer[1],
+        MacBuffer[2],
+        MacBuffer[3],
+        MacBuffer[4],
+        MacBuffer[5]
+        ));
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS GetSasAddress (
+  IN UINT8        Index,
+  IN OUT UINT8    *SasAddrBuffer
+  )
+{
+  if (SasAddrBuffer == NULL) {
+      return EFI_INVALID_PARAMETER;
+  }
+
+  SasAddrBuffer[0] = 0x50;
+  SasAddrBuffer[1] = 0x01;
+  SasAddrBuffer[2] = 0x88;
+  SasAddrBuffer[3] = 0x20;
+  SasAddrBuffer[4] = 0x16;
+  SasAddrBuffer[5] = 0x00;
+  SasAddrBuffer[6] = 0x00;
+  SasAddrBuffer[7] = Index;
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS _SearchReplacePackageAddress(
+  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
+  IN EFI_ACPI_HANDLE        ChildHandle,
+  IN UINTN                  Level,
+  IN OUT BOOLEAN            *Found,
+  IN UINTN                  DevNextID,
+  IN DSDT_DEVICE_TYPE       FoundDev
+  )
+{
+  // ASL template for ethernet driver:
+/*
+ *   Name (_DSD, Package () {
+ *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ *   Package () {
+ *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
+ *     Package (2) {"phy-channel", 0},
+ *     Package (2) {"phy-mode", "rgmii"},
+ *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
+ *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
+ *   }
+ * })
+ */
+  EFI_STATUS          Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CONST UINT8         *Data;
+  CONST VOID          *Buffer;
+  UINTN               DataSize;
+  UINTN               Count;
+  EFI_ACPI_HANDLE     CurrentHandle;
+  EFI_ACPI_HANDLE     NextHandle;
+  EFI_ACPI_HANDLE     Level1Handle;
+  UINT8               *AddressBuffer;
+  UINT8               AddressByte = 0;
+
+  DBG("In Level:%d\n", Level);
+  Level1Handle = NULL;
+  Status = EFI_SUCCESS;
+  for (CurrentHandle = NULL; ;) {
+    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
+    if (Level == 1) {
+      Level1Handle = CurrentHandle;
+    }
+    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
+       break;
+
+    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
+    Data = Buffer;
+    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
+        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
+
+    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
+      continue;
+
+    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
+      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
+      if (EFI_ERROR(Status))
+        break;
+
+      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
+              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
+
+      Data = Buffer;
+      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
+            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
+            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
+        ChildHandle = Level1Handle;
+        continue;
+      }
+
+      DBG("_DSD Key Type %d. Found address key\n", DataType);
+
+      //
+      // We found the node.
+      //
+      *Found = TRUE;
+      continue;
+    }
+
+    if (Level == 3 && *Found) {
+      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
+      if (AddressBuffer == NULL) {
+        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
+        return EFI_OUT_OF_RESOURCES;
+      }
+
+      switch (FoundDev) {
+        case DsdtDeviceLan:
+          //Update the MAC
+          Status = GetEnvMac (DevNextID, AddressBuffer);
+          AddressByte = 6;
+          break;
+        case DsdtDeviceSas:
+          //Update SAS Address.
+          Status = GetSasAddress (DevNextID, AddressBuffer);
+          AddressByte = 8;
+          break;
+        default:
+          Status = EFI_INVALID_PARAMETER;
+      }
+      if (EFI_ERROR (Status)) {
+        FreePool (AddressBuffer);
+        AddressBuffer = NULL;
+        break;
+      }
+
+      for (Count = 0; Count < AddressByte; Count++) {
+        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
+        if (EFI_ERROR(Status))
+          break;
+
+        Data = Buffer;
+        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
+            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
+
+        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
+          break;
+
+        // only need one byte.
+        // FIXME: Assume the CPU is little endian
+        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
+        if (EFI_ERROR(Status))
+          break;
+        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
+        if (EFI_ERROR(Status) || CurrentHandle == NULL)
+          break;
+      }
+      FreePool (AddressBuffer);
+      AddressBuffer = NULL;
+      break;
+    }
+
+    if (Level > 3)
+      break;
+
+    //Search next package
+    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
+    Status = _SearchReplacePackageAddress(
+               AcpiTableProtocol,
+               NextHandle,
+               Level + 1,
+               Found,
+               DevNextID,
+               FoundDev);
+    AcpiTableProtocol->Close(NextHandle);
+    if (!EFI_ERROR(Status))
+      break;
+  }
+
+  return Status;
+}
+
+EFI_STATUS SearchReplacePackageAddress(
+  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
+  IN EFI_ACPI_HANDLE        ChildHandle,
+  IN UINTN                  DevNextID,
+  IN DSDT_DEVICE_TYPE       FoundDev
+  )
+{
+  BOOLEAN Found = FALSE;
+  UINTN Level = 0;
+
+  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
+                                      &Found, DevNextID, FoundDev);
+}
+
+EFI_STATUS
+GetDeviceInfo (
+  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
+  EFI_ACPI_HANDLE         ChildHandle,
+  UINTN                   *DevID,
+  DSDT_DEVICE_TYPE        *FoundDev
+  )
+{
+  EFI_STATUS Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CHAR8               Data[5];
+  CONST VOID          *Buffer;
+  UINTN               DataSize;
+
+  // Get NameString
+  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
+    return Status;
+  }
+
+  CopyMem (Data, Buffer, 4);
+  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
+
+  Data[4] = '\0';
+  if ((DataSize != 4) ||
+    (Data[3] > '9' || Data[3] < '0')) {
+    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
+    *FoundDev = DsdtDeviceLan;
+  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
+    *FoundDev = DsdtDeviceSas;
+  } else {
+    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
+            __FUNCTION__, __LINE__, Data));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *DevID = Data[3] - '0';
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS ProcessDSDTDevice (
+  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
+  EFI_ACPI_HANDLE ChildHandle)
+{
+  EFI_STATUS          Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CONST UINT8         *Data;
+  CONST VOID          *Buffer;
+  UINTN               DataSize;
+  EFI_ACPI_HANDLE     DevHandle;
+  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
+  UINTN               DevNextID;
+  BOOLEAN             HisiAcpiDevNotFound;
+  UINTN               Index;
+
+  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
+  if (EFI_ERROR(Status))
+    return EFI_SUCCESS;
+
+  Data = Buffer;
+  //
+  // Skip all non-device type
+  //
+  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
+    return EFI_SUCCESS;
+
+  //
+  // Walk the device type node
+  //
+  for (DevHandle = NULL; ; ) {
+    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
+    if (EFI_ERROR(Status) || DevHandle == NULL)
+      break;
+
+    //
+    // Search for _HID with Device ID
+    //
+    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
+    if (EFI_ERROR(Status))
+      break;
+
+    Data = Buffer;
+    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
+    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
+      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
+      if (EFI_ERROR(Status))
+        break;
+
+      Data = Buffer;
+      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
+        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
+          EFI_ACPI_HANDLE ValueHandle;
+
+          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
+          if (EFI_ERROR(Status))
+            break;
+
+          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
+            continue;
+
+          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
+          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
+
+          Data = Buffer;
+          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
+
+          if (EFI_ERROR(Status) ||
+              DataType != EFI_ACPI_DATA_TYPE_STRING) {
+            AcpiTableProtocol->Close (ValueHandle);
+            FoundDev = DsdtDeviceUnknown;
+            continue;
+          }
+
+          HisiAcpiDevNotFound = TRUE;
+          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
+            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
+              HisiAcpiDevNotFound = FALSE;
+              break;
+            }
+          }
+          if (HisiAcpiDevNotFound) {
+            AcpiTableProtocol->Close (ValueHandle);
+            FoundDev = DsdtDeviceUnknown;
+            continue;
+          }
+
+          DBG("Found device\n");
+          AcpiTableProtocol->Close(ValueHandle);
+          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
+          if (EFI_ERROR (Status)) {
+            continue;
+          }
+        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
+          //
+          // Patch DSD data
+          //
+          EFI_ACPI_HANDLE    PkgHandle;
+          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
+          if (EFI_ERROR(Status))
+            break;
+
+          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
+            continue;
+
+          //
+          // Open package data
+          //
+          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
+          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
+
+          Data = Buffer;
+          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
+                Data[0], DataSize > 1 ? Data[1] : 0);
+
+          //
+          // Walk the _DSD node
+          //
+          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
+            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
+          }
+
+          AcpiTableProtocol->Close(PkgHandle);
+        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
+          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
+          if (EFI_ERROR (Status)) {
+            break;
+          }
+
+          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
+            continue;
+          }
+
+          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
+
+          if (EFI_ERROR (Status)) {
+            continue;
+          }
+        }
+      }
+    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
+      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+BOOLEAN
+IsSbScope (
+  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
+  EFI_ACPI_HANDLE         ChildHandle
+  )
+{
+  EFI_STATUS          Status;
+  EFI_ACPI_DATA_TYPE  DataType;
+  CONST UINT8         *Data;
+  CONST VOID          *Buffer;
+  UINTN               DataSize;
+
+  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
+  if (EFI_ERROR(Status)) return FALSE;
+
+  Data = Buffer;
+  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+EFI_STATUS ProcessDSDTChild(
+  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
+  EFI_ACPI_HANDLE ChildHandle)
+{
+  EFI_STATUS          Status;
+  EFI_ACPI_HANDLE     DevHandle;
+
+  // Check Scope(_SB) at first
+  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
+    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
+  }
+
+  for (DevHandle = NULL; ; ) {
+    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
+    if (EFI_ERROR(Status) || DevHandle == NULL) {
+      break;
+    }
+
+    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
+  }
+
+  return EFI_SUCCESS;
+}
+
+static EFI_STATUS ProcessDSDT(
+  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
+  EFI_ACPI_HANDLE TableHandle)
+{
+  EFI_STATUS              Status;
+  EFI_ACPI_HANDLE         ChildHandle;
+  //
+  // Parse table for device type
+  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
+  for (ChildHandle = NULL; ; ) {
+    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
+    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
+    if (EFI_ERROR(Status))
+      break;
+    if (ChildHandle == NULL)
+      break;
+
+    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+AcpiCheckSum (
+  IN OUT  EFI_ACPI_SDT_HEADER *Table
+  )
+{
+  UINTN ChecksumOffset;
+  UINT8 *Buffer;
+
+  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
+  Buffer = (UINT8 *)Table;
+
+  //
+  // set checksum to 0 first
+  //
+  Buffer[ChecksumOffset] = 0;
+
+  //
+  // Update checksum value
+  //
+  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
+}
+
+EFI_STATUS UpdateAcpiDsdtTable(void)
+{
+  EFI_STATUS              Status;
+  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
+  EFI_ACPI_SDT_HEADER     *Table;
+  EFI_ACPI_TABLE_VERSION  TableVersion;
+  UINTN                   TableKey;
+  EFI_ACPI_HANDLE         TableHandle;
+  UINTN                   i;
+
+  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
+
+  //
+  // Find the AcpiTable protocol
+  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
+  if (EFI_ERROR(Status)) {
+    DBG("Unable to locate ACPI table protocol\n");
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Search for DSDT Table
+  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
+    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
+    if (EFI_ERROR(Status))
+      break;
+    if (Table->Signature != DSDT_SIGNATURE)
+      continue;
+
+    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
+    if (EFI_ERROR(Status))
+      break;
+
+    ProcessDSDT(AcpiTableProtocol, TableHandle);
+
+    AcpiTableProtocol->Close(TableHandle);
+    AcpiCheckSum (Table);
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
new file mode 100644
index 0000000..a7e1eed
--- /dev/null
+++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
@@ -0,0 +1,16 @@
+/*
+ *
+ * Copyright (c) 2014, Applied Micro Circuits Corporation
+ * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
+ * Copyright (c) 2015, Linaro Limited. All rights reserved.
+ * Author: Loc Ho <lho@apm.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause-Patent
+ */
+#ifndef _ETH_MAC_H_
+#define _ETH_MAC_H_
+
+EFI_STATUS UpdateAcpiDsdtTable (VOID);
+
+#endif
+
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event
  2020-05-21 14:43 ` [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event Ming Huang
@ 2020-05-26 17:40   ` Leif Lindholm
  2020-05-27 11:38     ` Ming Huang
  0 siblings, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2020-05-26 17:40 UTC (permalink / raw)
  To: Ming Huang
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen

Please call your patches PATCH. RFC is when a potential solution
is put up for discussion, not for changing platform code.

On Thu, May 21, 2020 at 22:43:02 +0800, Ming Huang wrote:
> The better time for updating dsdt is in ready to boot event,
> so change the updating time.

The commit message should explain *why* it is better.

> 
> Signed-off-by: Ming Huang <huangming23@huawei.com>
> ---
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c | 60 ++++++++++++++++++--
>  1 file changed, 56 insertions(+), 4 deletions(-)
> 
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> index b888cb1..1ab55bc 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> @@ -1,8 +1,8 @@
>  /** @file
>  
> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> -  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>

Only the Hisilicon copyright should be updated (or a Huawei one added,
given that this is the address used for submitting).

/
    Leif

>    SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
> @@ -23,6 +23,38 @@
>  #include <IndustryStandard/AcpiAml.h>
>  #include "EthMac.h"
>  
> +EFI_EVENT       mUpdateAcpiDsdtTableEvent;
> +
> +VOID
> +EFIAPI
> +UpdateAcpiDsdt (
> +  IN EFI_EVENT         Event,
> +  IN VOID              *Context
> +  )
> +{
> +  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
> +  EFI_STATUS              Status;
> +
> +  Status = gBS->LocateProtocol (
> +                  &gEfiAcpiTableProtocolGuid,
> +                  NULL,
> +                  (VOID**)&AcpiTableProtocol
> +                  );
> +
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
> +    return;
> +  }
> +
> +  Status = EthMacInit ();
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
> +  }
> +
> +  gBS->CloseEvent (Event);
> +  return;
> +}
> +
>  EFI_STATUS
>  EFIAPI
>  AcpiPlatformEntryPoint (
> @@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
>    IN EFI_SYSTEM_TABLE   *SystemTable
>    )
>  {
> -  return EthMacInit();
> +  EFI_STATUS Status;
> +
> +  //
> +  // Register notify function
> +  //
> +  Status = gBS->CreateEventEx (
> +                  EVT_NOTIFY_SIGNAL,
> +                  TPL_CALLBACK,
> +                  UpdateAcpiDsdt,
> +                  NULL,
> +                  &gEfiEventReadyToBootGuid,
> +                  &mUpdateAcpiDsdtTableEvent
> +                  );
> +
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt failed.\n"));
> +  } else {
> +    DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt success.\n"));
> +  }
> +
> +  return Status;
>  }
> -- 
> 2.8.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 0/3] Improve D0x
  2020-05-21 14:43 [RFC edk2-platforms v1 0/3] Improve D0x Ming Huang
                   ` (2 preceding siblings ...)
  2020-05-21 14:43 ` [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files Ming Huang
@ 2020-05-26 18:09 ` Leif Lindholm
  2020-05-27 14:31   ` Ming Huang
  3 siblings, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2020-05-26 18:09 UTC (permalink / raw)
  To: Ming Huang
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen

On trying to build the resulting output, I found the build breaks with
/work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:
In function ‘FlashFvbInitialize’:
/work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:1231:20:
error: ‘gEfiEventVirtualAddressChangeGuid’ undeclared (first use in
this function); did you mean ‘EfiSetVirtualAddressMap’?
                   &gEfiEventVirtualAddressChangeGuid,
		                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				                           EfiSetVirtualAddressMap

The error would appear identical to that resolved by
commit a327627dd3f9edc113b1de6d897222d0517834db

Could you please provide a corresponding fix?

Best Regards,

Leif

On Thu, May 21, 2020 at 22:43:01 +0800, Ming Huang wrote:
> Main Changes:
> Add update sas address feature in AcpiPlatformDxe.
> 
> Ming Huang (3):
>   Silicon/Hisilicon: Change updating dsdt in ready to boot event
>   Silicon/Hisilicon/Acpi: Add update sas address feature
>   Silicon/Hisilicon: Rename EthMac files
> 
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |  62 +-
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 500 ----------------
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
>  6 files changed, 689 insertions(+), 525 deletions(-)
>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
> 
> -- 
> 2.8.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature
  2020-05-21 14:43 ` [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature Ming Huang
@ 2020-05-26 18:49   ` Leif Lindholm
  2020-05-27 14:21     ` Ming Huang
  0 siblings, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2020-05-26 18:49 UTC (permalink / raw)
  To: Ming Huang
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen

On Thu, May 21, 2020 at 22:43:03 +0800, Ming Huang wrote:
> The updating sas address feature is similar with apdating mac address.
> Modify updating dsdt flow for add this feature.
> 
> Signed-off-by: Ming Huang <huangming23@huawei.com>
> ---
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c       | 200 +++++++++++++++-----
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h       |   2 +-
>  3 files changed, 158 insertions(+), 46 deletions(-)
> 
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> index 1ab55bc..d3ea051 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>      return;
>    }
>  
> -  Status = EthMacInit ();
> +  Status = UpdateAcpiDsdtTable ();
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
>    }
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
> index cd98506..205f2f9 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
> @@ -1,8 +1,8 @@
>  /** @file
>  
> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> -  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>

Same comment as for 1/3.

>    SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>    This driver is called to initialize the FW part of the PHY in preparation
> @@ -30,6 +30,7 @@
>  #include <Library/UefiRuntimeServicesTableLib.h>
>  #include <IndustryStandard/Acpi.h>
>  #include <IndustryStandard/AcpiAml.h>
> +#include <Library/MemoryAllocationLib.h>

Good lord this include block is a mess.
Nevertheless, a less offensive place to insert this new header would
be between
#include <Library/DebugLib.h>
and
#include <Library/PcdLib.h>
.

>  
>  #include <Protocol/HisiBoardNicProtocol.h>
>  
> @@ -45,13 +46,20 @@
>  #define EFI_ACPI_MAX_NUM_TABLES         20
>  #define DSDT_SIGNATURE                  0x54445344
>  
> -#define D03_ACPI_ETH_ID                     "HISI00C2"
> -
>  #define ACPI_ETH_MAC_KEY                "local-mac-address"
> +#define ACPI_ETH_SAS_KEY                 "sas-addr"

Please consider column alignment.

>  
>  #define PREFIX_VARIABLE_NAME            L"MAC"
>  #define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
> -#define MAC_MAX_LEN                     30
> +#define ADDRESS_MAX_LEN                     30

Please consider column alignment.

>
> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
> +
> +typedef enum {
> +  DsdtDeviceUnknown,
> +  DsdtDeviceLan,
> +  DsdtDeviceSas
> +} DSDT_DEVICE_TYPE;
>  
>  EFI_STATUS GetEnvMac(
>    IN          UINTN    MacNextID,
> @@ -89,12 +97,35 @@ EFI_STATUS GetEnvMac(
>    return EFI_SUCCESS;
>  }
>  
> -EFI_STATUS _SearchReplacePackageMACAddress(
> +EFI_STATUS GetSasAddress (

Function name should be on separate line.
If only used in this module, function should also be STATIC.

> +  IN UINT8        Index,
> +  IN OUT UINT8    *SasAddrBuffer
> +  )
> +{
> +  if (SasAddrBuffer == NULL) {
> +      return EFI_INVALID_PARAMETER;
> +  }
> +
> +  SasAddrBuffer[0] = 0x50;
> +  SasAddrBuffer[1] = 0x01;
> +  SasAddrBuffer[2] = 0x88;
> +  SasAddrBuffer[3] = 0x20;
> +  SasAddrBuffer[4] = 0x16;
> +  SasAddrBuffer[5] = 0x00;
> +  SasAddrBuffer[6] = 0x00;
> +  SasAddrBuffer[7] = Index;

What does the above do?
What are the hardcoded values?

> +
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS _SearchReplacePackageAddress(

Function name should be on separate line.
If only used in this module, function should also be STATIC.
Functions should not have names starting with _.

>    IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>    IN EFI_ACPI_HANDLE        ChildHandle,
>    IN UINTN                  Level,
>    IN OUT BOOLEAN            *Found,
> -  IN UINTN                  MacNextID)
> +  IN UINTN                  DevNextID,
> +  IN DSDT_DEVICE_TYPE       FoundDev
> +  )
>  {
>    // ASL template for ethernet driver:
>  /*
> @@ -117,12 +148,18 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>    UINTN               Count;
>    EFI_ACPI_HANDLE     CurrentHandle;
>    EFI_ACPI_HANDLE     NextHandle;
> -  UINT8               MACBuffer[MAC_MAX_LEN];
> +  EFI_ACPI_HANDLE     Level1Handle;
> +  UINT8               *AddressBuffer;
> +  UINT8               AddressByte = 0;
>  
>    DBG("In Level:%d\n", Level);
> +  Level1Handle = NULL;
>    Status = EFI_SUCCESS;
>    for (CurrentHandle = NULL; ;) {
>      Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
> +    if (Level == 1) {
> +      Level1Handle = CurrentHandle;
> +    }
>      if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
>         break;
>  
> @@ -143,11 +180,14 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>                DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>  
>        Data = Buffer;
> -      if (DataType != EFI_ACPI_DATA_TYPE_STRING
> -              || AsciiStrCmp((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0)
> +      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
> +            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
> +            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {

Indentation should help clarify the relationship between the differenc
comparison values:

      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
          ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
           (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {

> +        ChildHandle = Level1Handle;
>          continue;
> +      }
>  
> -      DBG("_DSD Key Type %d. Found MAC address key\n", DataType);
> +      DBG("_DSD Key Type %d. Found address key\n", DataType);
>  
>        //
>        // We found the node.
> @@ -157,13 +197,33 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>      }
>  
>      if (Level == 3 && *Found) {
> +      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
> +      if (AddressBuffer == NULL) {
> +        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
> +        return EFI_OUT_OF_RESOURCES;
> +      }
>  
> -      //Update the MAC
> -      Status = GetEnvMac(MacNextID, MACBuffer);
> -      if (EFI_ERROR(Status))
> +      switch (FoundDev) {
> +        case DsdtDeviceLan:
> +          //Update the MAC
> +          Status = GetEnvMac (DevNextID, AddressBuffer);
> +          AddressByte = 6;
> +          break;
> +        case DsdtDeviceSas:
> +          //Update SAS Address.
> +          Status = GetSasAddress (DevNextID, AddressBuffer);
> +          AddressByte = 8;
> +          break;
> +        default:
> +          Status = EFI_INVALID_PARAMETER;
> +      }
> +      if (EFI_ERROR (Status)) {
> +        FreePool (AddressBuffer);
> +        AddressBuffer = NULL;

These nested for loops could certainly benefit from having their
contents broken down into a few helper functions, but fundamentally -
this AddressBuffer is only used again on another time around the loop,
and if so, it is overwritten by the call to AllocateZeroPool. Why are
we rewriting the pointer?

>          break;
> +      }
>  
> -      for (Count = 0; Count < 6; Count++) {
> +      for (Count = 0; Count < AddressByte; Count++) {
>          Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>          if (EFI_ERROR(Status))
>            break;
> @@ -177,13 +237,15 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>  
>          // only need one byte.
>          // FIXME: Assume the CPU is little endian
> -        Status = AcpiTableProtocol->SetOption(CurrentHandle, 1, (VOID *)&MACBuffer[Count], sizeof(UINT8));
> +        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
>          if (EFI_ERROR(Status))
>            break;
>          Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>          if (EFI_ERROR(Status) || CurrentHandle == NULL)
>            break;
>        }
> +      FreePool (AddressBuffer);
> +      AddressBuffer = NULL;

Same thing again - why rewrite the pointer after free?

>        break;
>      }
>  
> @@ -192,7 +254,13 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>  
>      //Search next package
>      AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
> -    Status = _SearchReplacePackageMACAddress(AcpiTableProtocol, NextHandle, Level + 1, Found, MacNextID);
> +    Status = _SearchReplacePackageAddress(

Indentation looks wrong because of the function name. Drop the leading
_ and it will be fine.

> +               AcpiTableProtocol,
> +               NextHandle,
> +               Level + 1,
> +               Found,
> +               DevNextID,
> +               FoundDev);
>      AcpiTableProtocol->Close(NextHandle);
>      if (!EFI_ERROR(Status))
>        break;
> @@ -201,22 +269,26 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>    return Status;
>  }
>  
> -EFI_STATUS SearchReplacePackageMACAddress(
> +EFI_STATUS SearchReplacePackageAddress(
>    IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>    IN EFI_ACPI_HANDLE        ChildHandle,
> -  IN UINTN                  MacNextID)
> +  IN UINTN                  DevNextID,
> +  IN DSDT_DEVICE_TYPE       FoundDev
> +  )
>  {
>    BOOLEAN Found = FALSE;
>    UINTN Level = 0;
>  
> -  return _SearchReplacePackageMACAddress(AcpiTableProtocol, ChildHandle, Level, &Found, MacNextID);
> +  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
> +                                      &Found, DevNextID, FoundDev);
>  }
>  
>  EFI_STATUS
> -GetEthID (
> +GetDeviceInfo (
>    EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>    EFI_ACPI_HANDLE         ChildHandle,
> -  UINTN                   *EthID
> +  UINTN                   *DevID,
> +  DSDT_DEVICE_TYPE        *FoundDev
>    )
>  {
>    EFI_STATUS Status;
> @@ -225,7 +297,7 @@ GetEthID (
>    CONST VOID          *Buffer;
>    UINTN               DataSize;
>  
> -  // Get NameString ETHx
> +  // Get NameString
>    Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
> @@ -236,14 +308,23 @@ GetEthID (
>    DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
>  
>    Data[4] = '\0';
> -  if (DataSize != 4 ||
> -      AsciiStrnCmp ("ETH", Data, 3) != 0 ||
> -      Data[3] > '9' || Data[3] < '0') {
> -    DEBUG ((EFI_D_ERROR, "[%a:%d] The NameString %a is not ETHn\n", __FUNCTION__, __LINE__, Data));
> +  if ((DataSize != 4) ||
> +    (Data[3] > '9' || Data[3] < '0')) {
> +    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
>      return EFI_INVALID_PARAMETER;
>    }
>  
> -  *EthID = Data[3] - '0';
> +  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
> +    *FoundDev = DsdtDeviceLan;
> +  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
> +    *FoundDev = DsdtDeviceSas;
> +  } else {
> +    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
> +            __FUNCTION__, __LINE__, Data));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *DevID = Data[3] - '0';
>    return EFI_SUCCESS;
>  }
>  
> @@ -257,8 +338,10 @@ EFI_STATUS ProcessDSDTDevice (
>    CONST VOID          *Buffer;
>    UINTN               DataSize;
>    EFI_ACPI_HANDLE     DevHandle;
> -  INTN                Found = 0;
> -  UINTN               MacNextID;
> +  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
> +  UINTN               DevNextID;
> +  BOOLEAN             HisiAcpiDevNotFound;
> +  UINTN               Index;
>  
>    Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
>    if (EFI_ERROR(Status))
> @@ -280,7 +363,7 @@ EFI_STATUS ProcessDSDTDevice (
>        break;
>  
>      //
> -    // Search for _HID with Ethernet ID
> +    // Search for _HID with Device ID
>      //
>      Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
>      if (EFI_ERROR(Status))
> @@ -312,23 +395,34 @@ EFI_STATUS ProcessDSDTDevice (
>            DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
>  
>            if (EFI_ERROR(Status) ||
> -              DataType != EFI_ACPI_DATA_TYPE_STRING ||
> -              (AsciiStrCmp((CHAR8 *) Data, D03_ACPI_ETH_ID) != 0)) {
> -            AcpiTableProtocol->Close(ValueHandle);
> -            Found = 0;
> +              DataType != EFI_ACPI_DATA_TYPE_STRING) {
> +            AcpiTableProtocol->Close (ValueHandle);
> +            FoundDev = DsdtDeviceUnknown;
> +            continue;
> +          }
> +
> +          HisiAcpiDevNotFound = TRUE;
> +          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
> +            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
> +              HisiAcpiDevNotFound = FALSE;
> +              break;
> +            }
> +          }
> +          if (HisiAcpiDevNotFound) {
> +            AcpiTableProtocol->Close (ValueHandle);
> +            FoundDev = DsdtDeviceUnknown;
>              continue;
>            }
>  
> -          DBG("Found Ethernet device\n");
> +          DBG("Found device\n");
>            AcpiTableProtocol->Close(ValueHandle);
> -          Status = GetEthID (AcpiTableProtocol, ChildHandle, &MacNextID);
> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>            if (EFI_ERROR (Status)) {
>              continue;
>            }
> -          Found = 1;
> -        } else if (Found == 1 && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
> +        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
>            //
> -          // Patch MAC address for open source kernel
> +          // Patch DSD data
>            //
>            EFI_ACPI_HANDLE    PkgHandle;
>            Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
> @@ -351,12 +445,30 @@ EFI_STATUS ProcessDSDTDevice (
>            //
>            // Walk the _DSD node
>            //
> -          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP)
> -            Status = SearchReplacePackageMACAddress(AcpiTableProtocol, PkgHandle, MacNextID);
> +          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
> +            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
> +          }
>  
>            AcpiTableProtocol->Close(PkgHandle);
> +        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
> +          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
> +          if (EFI_ERROR (Status)) {
> +            break;
> +          }
> +
> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
> +            continue;
> +          }
> +
> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
> +
> +          if (EFI_ERROR (Status)) {
> +            continue;
> +          }
>          }
>        }
> +    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
> +      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>      }
>    }
>  
> @@ -457,7 +569,7 @@ AcpiCheckSum (
>    Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
>  }
>  
> -EFI_STATUS EthMacInit(void)
> +EFI_STATUS UpdateAcpiDsdtTable(void)

Function name on its own line.

/
    Leif

>  {
>    EFI_STATUS              Status;
>    EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
> index 0a3e811..a7e1eed 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
> @@ -10,7 +10,7 @@
>  #ifndef _ETH_MAC_H_
>  #define _ETH_MAC_H_
>  
> -EFI_STATUS EthMacInit(VOID);
> +EFI_STATUS UpdateAcpiDsdtTable (VOID);
>  
>  #endif
>  
> -- 
> 2.8.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files
  2020-05-21 14:43 ` [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files Ming Huang
@ 2020-05-26 18:50   ` Leif Lindholm
  2020-05-27 14:22     ` Ming Huang
  0 siblings, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2020-05-26 18:50 UTC (permalink / raw)
  To: Ming Huang
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen

On Thu, May 21, 2020 at 22:43:04 +0800, Ming Huang wrote:
> As not only update mac address feature in EthMac files, so rename
> them to UpdateDsdt.
> 
> Signed-off-by: Ming Huang <huangming23@huawei.com>
> ---
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |   2 +-
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 612 --------------------
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
>  6 files changed, 633 insertions(+), 633 deletions(-)
> 
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> index d3ea051..fd67677 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
> @@ -21,7 +21,7 @@
>  #include <Library/UefiRuntimeServicesTableLib.h>
>  #include <IndustryStandard/Acpi.h>
>  #include <IndustryStandard/AcpiAml.h>
> -#include "EthMac.h"
> +#include "UpdateDsdt.h"
>  
>  EFI_EVENT       mUpdateAcpiDsdtTableEvent;
>  
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
> index 53da731..a2b669d 100644
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
> @@ -1,8 +1,8 @@
>  ## @file
>  #
> -#  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.<BR>
> -#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> -#  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +#  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights reserved.<BR>
> +#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
> +#  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>

Same comment on copyright as on 1/3 and 2/3.

/
    Leif

>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> @@ -18,7 +18,7 @@
>  
>  [Sources]
>    AcpiPlatform.c
> -  EthMac.c
> +  UpdateDsdt.c
>  
>  [Packages]
>    MdePkg/MdePkg.dec
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
> deleted file mode 100644
> index 205f2f9..0000000
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
> +++ /dev/null
> @@ -1,612 +0,0 @@
> -/** @file
> -
> -  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> -  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
> -  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
> -  SPDX-License-Identifier: BSD-2-Clause-Patent
> -
> -  This driver is called to initialize the FW part of the PHY in preparation
> -  for the OS.
> -
> -**/
> -
> -#include <Guid/ShellVariableGuid.h>
> -#include <Library/UefiRuntimeServicesTableLib.h>
> -#include <Library/DebugLib.h>
> -#include <Library/TimerLib.h>
> -
> -#include <PiDxe.h>
> -#include <Guid/EventGroup.h>
> -#include <Protocol/AcpiTable.h>
> -#include <Protocol/FirmwareVolume2.h>
> -#include <Library/BaseLib.h>
> -#include <Library/UefiBootServicesTableLib.h>
> -#include <Protocol/AcpiSystemDescriptionTable.h>
> -#include <Library/DebugLib.h>
> -#include <Library/PcdLib.h>
> -#include <Library/PrintLib.h>
> -#include <Library/DebugLib.h>
> -#include <Library/BaseMemoryLib.h>
> -#include <Library/UefiRuntimeServicesTableLib.h>
> -#include <IndustryStandard/Acpi.h>
> -#include <IndustryStandard/AcpiAml.h>
> -#include <Library/MemoryAllocationLib.h>
> -
> -#include <Protocol/HisiBoardNicProtocol.h>
> -
> -// Turn on debug message by enabling below define
> -//#define ACPI_DEBUG
> -
> -#ifdef ACPI_DEBUG
> -#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
> -#else
> -#define DBG(arg...)
> -#endif
> -
> -#define EFI_ACPI_MAX_NUM_TABLES         20
> -#define DSDT_SIGNATURE                  0x54445344
> -
> -#define ACPI_ETH_MAC_KEY                "local-mac-address"
> -#define ACPI_ETH_SAS_KEY                 "sas-addr"
> -
> -#define PREFIX_VARIABLE_NAME            L"MAC"
> -#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
> -#define ADDRESS_MAX_LEN                     30
> -
> -CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
> -
> -typedef enum {
> -  DsdtDeviceUnknown,
> -  DsdtDeviceLan,
> -  DsdtDeviceSas
> -} DSDT_DEVICE_TYPE;
> -
> -EFI_STATUS GetEnvMac(
> -  IN          UINTN    MacNextID,
> -  IN OUT      UINT8    *MacBuffer)
> -{
> -  EFI_MAC_ADDRESS Mac;
> -  EFI_STATUS Status;
> -  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
> -
> -  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
> -  if(EFI_ERROR(Status))
> -  {
> -    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
> -    return Status;
> -  }
> -
> -  Status = OemNic->GetMac(&Mac, MacNextID);
> -  if(EFI_ERROR(Status))
> -  {
> -    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
> -    return Status;
> -  }
> -
> -  CopyMem (MacBuffer, &Mac, 6);
> -  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
> -        MacNextID,
> -        MacBuffer[0],
> -        MacBuffer[1],
> -        MacBuffer[2],
> -        MacBuffer[3],
> -        MacBuffer[4],
> -        MacBuffer[5]
> -        ));
> -
> -  return EFI_SUCCESS;
> -}
> -
> -EFI_STATUS GetSasAddress (
> -  IN UINT8        Index,
> -  IN OUT UINT8    *SasAddrBuffer
> -  )
> -{
> -  if (SasAddrBuffer == NULL) {
> -      return EFI_INVALID_PARAMETER;
> -  }
> -
> -  SasAddrBuffer[0] = 0x50;
> -  SasAddrBuffer[1] = 0x01;
> -  SasAddrBuffer[2] = 0x88;
> -  SasAddrBuffer[3] = 0x20;
> -  SasAddrBuffer[4] = 0x16;
> -  SasAddrBuffer[5] = 0x00;
> -  SasAddrBuffer[6] = 0x00;
> -  SasAddrBuffer[7] = Index;
> -
> -  return EFI_SUCCESS;
> -}
> -
> -EFI_STATUS _SearchReplacePackageAddress(
> -  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
> -  IN EFI_ACPI_HANDLE        ChildHandle,
> -  IN UINTN                  Level,
> -  IN OUT BOOLEAN            *Found,
> -  IN UINTN                  DevNextID,
> -  IN DSDT_DEVICE_TYPE       FoundDev
> -  )
> -{
> -  // ASL template for ethernet driver:
> -/*
> - *   Name (_DSD, Package () {
> - *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> - *   Package () {
> - *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
> - *     Package (2) {"phy-channel", 0},
> - *     Package (2) {"phy-mode", "rgmii"},
> - *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
> - *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
> - *   }
> - * })
> - */
> -  EFI_STATUS          Status;
> -  EFI_ACPI_DATA_TYPE  DataType;
> -  CONST UINT8         *Data;
> -  CONST VOID          *Buffer;
> -  UINTN               DataSize;
> -  UINTN               Count;
> -  EFI_ACPI_HANDLE     CurrentHandle;
> -  EFI_ACPI_HANDLE     NextHandle;
> -  EFI_ACPI_HANDLE     Level1Handle;
> -  UINT8               *AddressBuffer;
> -  UINT8               AddressByte = 0;
> -
> -  DBG("In Level:%d\n", Level);
> -  Level1Handle = NULL;
> -  Status = EFI_SUCCESS;
> -  for (CurrentHandle = NULL; ;) {
> -    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
> -    if (Level == 1) {
> -      Level1Handle = CurrentHandle;
> -    }
> -    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
> -       break;
> -
> -    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
> -    Data = Buffer;
> -    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
> -        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
> -
> -    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
> -      continue;
> -
> -    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
> -      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
> -      if (EFI_ERROR(Status))
> -        break;
> -
> -      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
> -              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
> -
> -      Data = Buffer;
> -      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
> -            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
> -            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
> -        ChildHandle = Level1Handle;
> -        continue;
> -      }
> -
> -      DBG("_DSD Key Type %d. Found address key\n", DataType);
> -
> -      //
> -      // We found the node.
> -      //
> -      *Found = TRUE;
> -      continue;
> -    }
> -
> -    if (Level == 3 && *Found) {
> -      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
> -      if (AddressBuffer == NULL) {
> -        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
> -        return EFI_OUT_OF_RESOURCES;
> -      }
> -
> -      switch (FoundDev) {
> -        case DsdtDeviceLan:
> -          //Update the MAC
> -          Status = GetEnvMac (DevNextID, AddressBuffer);
> -          AddressByte = 6;
> -          break;
> -        case DsdtDeviceSas:
> -          //Update SAS Address.
> -          Status = GetSasAddress (DevNextID, AddressBuffer);
> -          AddressByte = 8;
> -          break;
> -        default:
> -          Status = EFI_INVALID_PARAMETER;
> -      }
> -      if (EFI_ERROR (Status)) {
> -        FreePool (AddressBuffer);
> -        AddressBuffer = NULL;
> -        break;
> -      }
> -
> -      for (Count = 0; Count < AddressByte; Count++) {
> -        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
> -        if (EFI_ERROR(Status))
> -          break;
> -
> -        Data = Buffer;
> -        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
> -            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
> -
> -        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
> -          break;
> -
> -        // only need one byte.
> -        // FIXME: Assume the CPU is little endian
> -        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
> -        if (EFI_ERROR(Status))
> -          break;
> -        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
> -        if (EFI_ERROR(Status) || CurrentHandle == NULL)
> -          break;
> -      }
> -      FreePool (AddressBuffer);
> -      AddressBuffer = NULL;
> -      break;
> -    }
> -
> -    if (Level > 3)
> -      break;
> -
> -    //Search next package
> -    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
> -    Status = _SearchReplacePackageAddress(
> -               AcpiTableProtocol,
> -               NextHandle,
> -               Level + 1,
> -               Found,
> -               DevNextID,
> -               FoundDev);
> -    AcpiTableProtocol->Close(NextHandle);
> -    if (!EFI_ERROR(Status))
> -      break;
> -  }
> -
> -  return Status;
> -}
> -
> -EFI_STATUS SearchReplacePackageAddress(
> -  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
> -  IN EFI_ACPI_HANDLE        ChildHandle,
> -  IN UINTN                  DevNextID,
> -  IN DSDT_DEVICE_TYPE       FoundDev
> -  )
> -{
> -  BOOLEAN Found = FALSE;
> -  UINTN Level = 0;
> -
> -  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
> -                                      &Found, DevNextID, FoundDev);
> -}
> -
> -EFI_STATUS
> -GetDeviceInfo (
> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
> -  EFI_ACPI_HANDLE         ChildHandle,
> -  UINTN                   *DevID,
> -  DSDT_DEVICE_TYPE        *FoundDev
> -  )
> -{
> -  EFI_STATUS Status;
> -  EFI_ACPI_DATA_TYPE  DataType;
> -  CHAR8               Data[5];
> -  CONST VOID          *Buffer;
> -  UINTN               DataSize;
> -
> -  // Get NameString
> -  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
> -  if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
> -    return Status;
> -  }
> -
> -  CopyMem (Data, Buffer, 4);
> -  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
> -
> -  Data[4] = '\0';
> -  if ((DataSize != 4) ||
> -    (Data[3] > '9' || Data[3] < '0')) {
> -    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
> -    return EFI_INVALID_PARAMETER;
> -  }
> -
> -  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
> -    *FoundDev = DsdtDeviceLan;
> -  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
> -    *FoundDev = DsdtDeviceSas;
> -  } else {
> -    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
> -            __FUNCTION__, __LINE__, Data));
> -    return EFI_INVALID_PARAMETER;
> -  }
> -
> -  *DevID = Data[3] - '0';
> -  return EFI_SUCCESS;
> -}
> -
> -EFI_STATUS ProcessDSDTDevice (
> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> -  EFI_ACPI_HANDLE ChildHandle)
> -{
> -  EFI_STATUS          Status;
> -  EFI_ACPI_DATA_TYPE  DataType;
> -  CONST UINT8         *Data;
> -  CONST VOID          *Buffer;
> -  UINTN               DataSize;
> -  EFI_ACPI_HANDLE     DevHandle;
> -  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
> -  UINTN               DevNextID;
> -  BOOLEAN             HisiAcpiDevNotFound;
> -  UINTN               Index;
> -
> -  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
> -  if (EFI_ERROR(Status))
> -    return EFI_SUCCESS;
> -
> -  Data = Buffer;
> -  //
> -  // Skip all non-device type
> -  //
> -  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
> -    return EFI_SUCCESS;
> -
> -  //
> -  // Walk the device type node
> -  //
> -  for (DevHandle = NULL; ; ) {
> -    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
> -    if (EFI_ERROR(Status) || DevHandle == NULL)
> -      break;
> -
> -    //
> -    // Search for _HID with Device ID
> -    //
> -    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
> -    if (EFI_ERROR(Status))
> -      break;
> -
> -    Data = Buffer;
> -    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
> -    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
> -      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
> -      if (EFI_ERROR(Status))
> -        break;
> -
> -      Data = Buffer;
> -      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
> -        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
> -          EFI_ACPI_HANDLE ValueHandle;
> -
> -          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
> -          if (EFI_ERROR(Status))
> -            break;
> -
> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
> -            continue;
> -
> -          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
> -          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
> -
> -          Data = Buffer;
> -          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
> -
> -          if (EFI_ERROR(Status) ||
> -              DataType != EFI_ACPI_DATA_TYPE_STRING) {
> -            AcpiTableProtocol->Close (ValueHandle);
> -            FoundDev = DsdtDeviceUnknown;
> -            continue;
> -          }
> -
> -          HisiAcpiDevNotFound = TRUE;
> -          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
> -            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
> -              HisiAcpiDevNotFound = FALSE;
> -              break;
> -            }
> -          }
> -          if (HisiAcpiDevNotFound) {
> -            AcpiTableProtocol->Close (ValueHandle);
> -            FoundDev = DsdtDeviceUnknown;
> -            continue;
> -          }
> -
> -          DBG("Found device\n");
> -          AcpiTableProtocol->Close(ValueHandle);
> -          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
> -          if (EFI_ERROR (Status)) {
> -            continue;
> -          }
> -        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
> -          //
> -          // Patch DSD data
> -          //
> -          EFI_ACPI_HANDLE    PkgHandle;
> -          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
> -          if (EFI_ERROR(Status))
> -            break;
> -
> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
> -            continue;
> -
> -          //
> -          // Open package data
> -          //
> -          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
> -          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
> -
> -          Data = Buffer;
> -          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
> -                Data[0], DataSize > 1 ? Data[1] : 0);
> -
> -          //
> -          // Walk the _DSD node
> -          //
> -          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
> -            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
> -          }
> -
> -          AcpiTableProtocol->Close(PkgHandle);
> -        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
> -          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
> -          if (EFI_ERROR (Status)) {
> -            break;
> -          }
> -
> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
> -            continue;
> -          }
> -
> -          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
> -
> -          if (EFI_ERROR (Status)) {
> -            continue;
> -          }
> -        }
> -      }
> -    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
> -      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
> -    }
> -  }
> -
> -  return EFI_SUCCESS;
> -}
> -
> -
> -BOOLEAN
> -IsSbScope (
> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
> -  EFI_ACPI_HANDLE         ChildHandle
> -  )
> -{
> -  EFI_STATUS          Status;
> -  EFI_ACPI_DATA_TYPE  DataType;
> -  CONST UINT8         *Data;
> -  CONST VOID          *Buffer;
> -  UINTN               DataSize;
> -
> -  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
> -  if (EFI_ERROR(Status)) return FALSE;
> -
> -  Data = Buffer;
> -  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
> -    return FALSE;
> -  }
> -
> -  return TRUE;
> -}
> -
> -EFI_STATUS ProcessDSDTChild(
> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> -  EFI_ACPI_HANDLE ChildHandle)
> -{
> -  EFI_STATUS          Status;
> -  EFI_ACPI_HANDLE     DevHandle;
> -
> -  // Check Scope(_SB) at first
> -  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
> -    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
> -  }
> -
> -  for (DevHandle = NULL; ; ) {
> -    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
> -    if (EFI_ERROR(Status) || DevHandle == NULL) {
> -      break;
> -    }
> -
> -    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
> -  }
> -
> -  return EFI_SUCCESS;
> -}
> -
> -static EFI_STATUS ProcessDSDT(
> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> -  EFI_ACPI_HANDLE TableHandle)
> -{
> -  EFI_STATUS              Status;
> -  EFI_ACPI_HANDLE         ChildHandle;
> -  //
> -  // Parse table for device type
> -  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
> -  for (ChildHandle = NULL; ; ) {
> -    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
> -    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
> -    if (EFI_ERROR(Status))
> -      break;
> -    if (ChildHandle == NULL)
> -      break;
> -
> -    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
> -  }
> -
> -  return EFI_SUCCESS;
> -}
> -
> -STATIC
> -VOID
> -AcpiCheckSum (
> -  IN OUT  EFI_ACPI_SDT_HEADER *Table
> -  )
> -{
> -  UINTN ChecksumOffset;
> -  UINT8 *Buffer;
> -
> -  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
> -  Buffer = (UINT8 *)Table;
> -
> -  //
> -  // set checksum to 0 first
> -  //
> -  Buffer[ChecksumOffset] = 0;
> -
> -  //
> -  // Update checksum value
> -  //
> -  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
> -}
> -
> -EFI_STATUS UpdateAcpiDsdtTable(void)
> -{
> -  EFI_STATUS              Status;
> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
> -  EFI_ACPI_SDT_HEADER     *Table;
> -  EFI_ACPI_TABLE_VERSION  TableVersion;
> -  UINTN                   TableKey;
> -  EFI_ACPI_HANDLE         TableHandle;
> -  UINTN                   i;
> -
> -  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
> -
> -  //
> -  // Find the AcpiTable protocol
> -  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
> -  if (EFI_ERROR(Status)) {
> -    DBG("Unable to locate ACPI table protocol\n");
> -    return EFI_SUCCESS;
> -  }
> -
> -  //
> -  // Search for DSDT Table
> -  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
> -    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
> -    if (EFI_ERROR(Status))
> -      break;
> -    if (Table->Signature != DSDT_SIGNATURE)
> -      continue;
> -
> -    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
> -    if (EFI_ERROR(Status))
> -      break;
> -
> -    ProcessDSDT(AcpiTableProtocol, TableHandle);
> -
> -    AcpiTableProtocol->Close(TableHandle);
> -    AcpiCheckSum (Table);
> -  }
> -
> -  return EFI_SUCCESS;
> -}
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
> deleted file mode 100644
> index a7e1eed..0000000
> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
> +++ /dev/null
> @@ -1,16 +0,0 @@
> -/*
> - *
> - * Copyright (c) 2014, Applied Micro Circuits Corporation
> - * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
> - * Copyright (c) 2015, Linaro Limited. All rights reserved.
> - * Author: Loc Ho <lho@apm.com>
> - *
> - * SPDX-License-Identifier: BSD-2-Clause-Patent
> - */
> -#ifndef _ETH_MAC_H_
> -#define _ETH_MAC_H_
> -
> -EFI_STATUS UpdateAcpiDsdtTable (VOID);
> -
> -#endif
> -
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
> new file mode 100644
> index 0000000..205f2f9
> --- /dev/null
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
> @@ -0,0 +1,612 @@
> +/** @file
> +
> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +  This driver is called to initialize the FW part of the PHY in preparation
> +  for the OS.
> +
> +**/
> +
> +#include <Guid/ShellVariableGuid.h>
> +#include <Library/UefiRuntimeServicesTableLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/TimerLib.h>
> +
> +#include <PiDxe.h>
> +#include <Guid/EventGroup.h>
> +#include <Protocol/AcpiTable.h>
> +#include <Protocol/FirmwareVolume2.h>
> +#include <Library/BaseLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Protocol/AcpiSystemDescriptionTable.h>
> +#include <Library/DebugLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PrintLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/UefiRuntimeServicesTableLib.h>
> +#include <IndustryStandard/Acpi.h>
> +#include <IndustryStandard/AcpiAml.h>
> +#include <Library/MemoryAllocationLib.h>
> +
> +#include <Protocol/HisiBoardNicProtocol.h>
> +
> +// Turn on debug message by enabling below define
> +//#define ACPI_DEBUG
> +
> +#ifdef ACPI_DEBUG
> +#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
> +#else
> +#define DBG(arg...)
> +#endif
> +
> +#define EFI_ACPI_MAX_NUM_TABLES         20
> +#define DSDT_SIGNATURE                  0x54445344
> +
> +#define ACPI_ETH_MAC_KEY                "local-mac-address"
> +#define ACPI_ETH_SAS_KEY                 "sas-addr"
> +
> +#define PREFIX_VARIABLE_NAME            L"MAC"
> +#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
> +#define ADDRESS_MAX_LEN                     30
> +
> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
> +
> +typedef enum {
> +  DsdtDeviceUnknown,
> +  DsdtDeviceLan,
> +  DsdtDeviceSas
> +} DSDT_DEVICE_TYPE;
> +
> +EFI_STATUS GetEnvMac(
> +  IN          UINTN    MacNextID,
> +  IN OUT      UINT8    *MacBuffer)
> +{
> +  EFI_MAC_ADDRESS Mac;
> +  EFI_STATUS Status;
> +  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
> +
> +  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
> +  if(EFI_ERROR(Status))
> +  {
> +    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
> +    return Status;
> +  }
> +
> +  Status = OemNic->GetMac(&Mac, MacNextID);
> +  if(EFI_ERROR(Status))
> +  {
> +    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
> +    return Status;
> +  }
> +
> +  CopyMem (MacBuffer, &Mac, 6);
> +  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
> +        MacNextID,
> +        MacBuffer[0],
> +        MacBuffer[1],
> +        MacBuffer[2],
> +        MacBuffer[3],
> +        MacBuffer[4],
> +        MacBuffer[5]
> +        ));
> +
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS GetSasAddress (
> +  IN UINT8        Index,
> +  IN OUT UINT8    *SasAddrBuffer
> +  )
> +{
> +  if (SasAddrBuffer == NULL) {
> +      return EFI_INVALID_PARAMETER;
> +  }
> +
> +  SasAddrBuffer[0] = 0x50;
> +  SasAddrBuffer[1] = 0x01;
> +  SasAddrBuffer[2] = 0x88;
> +  SasAddrBuffer[3] = 0x20;
> +  SasAddrBuffer[4] = 0x16;
> +  SasAddrBuffer[5] = 0x00;
> +  SasAddrBuffer[6] = 0x00;
> +  SasAddrBuffer[7] = Index;
> +
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS _SearchReplacePackageAddress(
> +  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
> +  IN EFI_ACPI_HANDLE        ChildHandle,
> +  IN UINTN                  Level,
> +  IN OUT BOOLEAN            *Found,
> +  IN UINTN                  DevNextID,
> +  IN DSDT_DEVICE_TYPE       FoundDev
> +  )
> +{
> +  // ASL template for ethernet driver:
> +/*
> + *   Name (_DSD, Package () {
> + *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> + *   Package () {
> + *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
> + *     Package (2) {"phy-channel", 0},
> + *     Package (2) {"phy-mode", "rgmii"},
> + *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
> + *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
> + *   }
> + * })
> + */
> +  EFI_STATUS          Status;
> +  EFI_ACPI_DATA_TYPE  DataType;
> +  CONST UINT8         *Data;
> +  CONST VOID          *Buffer;
> +  UINTN               DataSize;
> +  UINTN               Count;
> +  EFI_ACPI_HANDLE     CurrentHandle;
> +  EFI_ACPI_HANDLE     NextHandle;
> +  EFI_ACPI_HANDLE     Level1Handle;
> +  UINT8               *AddressBuffer;
> +  UINT8               AddressByte = 0;
> +
> +  DBG("In Level:%d\n", Level);
> +  Level1Handle = NULL;
> +  Status = EFI_SUCCESS;
> +  for (CurrentHandle = NULL; ;) {
> +    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
> +    if (Level == 1) {
> +      Level1Handle = CurrentHandle;
> +    }
> +    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
> +       break;
> +
> +    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
> +    Data = Buffer;
> +    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
> +        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
> +
> +    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
> +      continue;
> +
> +    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
> +      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
> +      if (EFI_ERROR(Status))
> +        break;
> +
> +      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
> +              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
> +
> +      Data = Buffer;
> +      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
> +            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
> +            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
> +        ChildHandle = Level1Handle;
> +        continue;
> +      }
> +
> +      DBG("_DSD Key Type %d. Found address key\n", DataType);
> +
> +      //
> +      // We found the node.
> +      //
> +      *Found = TRUE;
> +      continue;
> +    }
> +
> +    if (Level == 3 && *Found) {
> +      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
> +      if (AddressBuffer == NULL) {
> +        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
> +        return EFI_OUT_OF_RESOURCES;
> +      }
> +
> +      switch (FoundDev) {
> +        case DsdtDeviceLan:
> +          //Update the MAC
> +          Status = GetEnvMac (DevNextID, AddressBuffer);
> +          AddressByte = 6;
> +          break;
> +        case DsdtDeviceSas:
> +          //Update SAS Address.
> +          Status = GetSasAddress (DevNextID, AddressBuffer);
> +          AddressByte = 8;
> +          break;
> +        default:
> +          Status = EFI_INVALID_PARAMETER;
> +      }
> +      if (EFI_ERROR (Status)) {
> +        FreePool (AddressBuffer);
> +        AddressBuffer = NULL;
> +        break;
> +      }
> +
> +      for (Count = 0; Count < AddressByte; Count++) {
> +        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
> +        if (EFI_ERROR(Status))
> +          break;
> +
> +        Data = Buffer;
> +        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
> +            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
> +
> +        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
> +          break;
> +
> +        // only need one byte.
> +        // FIXME: Assume the CPU is little endian
> +        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
> +        if (EFI_ERROR(Status))
> +          break;
> +        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
> +        if (EFI_ERROR(Status) || CurrentHandle == NULL)
> +          break;
> +      }
> +      FreePool (AddressBuffer);
> +      AddressBuffer = NULL;
> +      break;
> +    }
> +
> +    if (Level > 3)
> +      break;
> +
> +    //Search next package
> +    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
> +    Status = _SearchReplacePackageAddress(
> +               AcpiTableProtocol,
> +               NextHandle,
> +               Level + 1,
> +               Found,
> +               DevNextID,
> +               FoundDev);
> +    AcpiTableProtocol->Close(NextHandle);
> +    if (!EFI_ERROR(Status))
> +      break;
> +  }
> +
> +  return Status;
> +}
> +
> +EFI_STATUS SearchReplacePackageAddress(
> +  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
> +  IN EFI_ACPI_HANDLE        ChildHandle,
> +  IN UINTN                  DevNextID,
> +  IN DSDT_DEVICE_TYPE       FoundDev
> +  )
> +{
> +  BOOLEAN Found = FALSE;
> +  UINTN Level = 0;
> +
> +  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
> +                                      &Found, DevNextID, FoundDev);
> +}
> +
> +EFI_STATUS
> +GetDeviceInfo (
> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
> +  EFI_ACPI_HANDLE         ChildHandle,
> +  UINTN                   *DevID,
> +  DSDT_DEVICE_TYPE        *FoundDev
> +  )
> +{
> +  EFI_STATUS Status;
> +  EFI_ACPI_DATA_TYPE  DataType;
> +  CHAR8               Data[5];
> +  CONST VOID          *Buffer;
> +  UINTN               DataSize;
> +
> +  // Get NameString
> +  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
> +    return Status;
> +  }
> +
> +  CopyMem (Data, Buffer, 4);
> +  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
> +
> +  Data[4] = '\0';
> +  if ((DataSize != 4) ||
> +    (Data[3] > '9' || Data[3] < '0')) {
> +    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
> +    *FoundDev = DsdtDeviceLan;
> +  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
> +    *FoundDev = DsdtDeviceSas;
> +  } else {
> +    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
> +            __FUNCTION__, __LINE__, Data));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *DevID = Data[3] - '0';
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS ProcessDSDTDevice (
> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> +  EFI_ACPI_HANDLE ChildHandle)
> +{
> +  EFI_STATUS          Status;
> +  EFI_ACPI_DATA_TYPE  DataType;
> +  CONST UINT8         *Data;
> +  CONST VOID          *Buffer;
> +  UINTN               DataSize;
> +  EFI_ACPI_HANDLE     DevHandle;
> +  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
> +  UINTN               DevNextID;
> +  BOOLEAN             HisiAcpiDevNotFound;
> +  UINTN               Index;
> +
> +  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
> +  if (EFI_ERROR(Status))
> +    return EFI_SUCCESS;
> +
> +  Data = Buffer;
> +  //
> +  // Skip all non-device type
> +  //
> +  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
> +    return EFI_SUCCESS;
> +
> +  //
> +  // Walk the device type node
> +  //
> +  for (DevHandle = NULL; ; ) {
> +    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
> +    if (EFI_ERROR(Status) || DevHandle == NULL)
> +      break;
> +
> +    //
> +    // Search for _HID with Device ID
> +    //
> +    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
> +    if (EFI_ERROR(Status))
> +      break;
> +
> +    Data = Buffer;
> +    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
> +    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
> +      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
> +      if (EFI_ERROR(Status))
> +        break;
> +
> +      Data = Buffer;
> +      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
> +        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
> +          EFI_ACPI_HANDLE ValueHandle;
> +
> +          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
> +          if (EFI_ERROR(Status))
> +            break;
> +
> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
> +            continue;
> +
> +          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
> +          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
> +
> +          Data = Buffer;
> +          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
> +
> +          if (EFI_ERROR(Status) ||
> +              DataType != EFI_ACPI_DATA_TYPE_STRING) {
> +            AcpiTableProtocol->Close (ValueHandle);
> +            FoundDev = DsdtDeviceUnknown;
> +            continue;
> +          }
> +
> +          HisiAcpiDevNotFound = TRUE;
> +          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
> +            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
> +              HisiAcpiDevNotFound = FALSE;
> +              break;
> +            }
> +          }
> +          if (HisiAcpiDevNotFound) {
> +            AcpiTableProtocol->Close (ValueHandle);
> +            FoundDev = DsdtDeviceUnknown;
> +            continue;
> +          }
> +
> +          DBG("Found device\n");
> +          AcpiTableProtocol->Close(ValueHandle);
> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
> +          if (EFI_ERROR (Status)) {
> +            continue;
> +          }
> +        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
> +          //
> +          // Patch DSD data
> +          //
> +          EFI_ACPI_HANDLE    PkgHandle;
> +          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
> +          if (EFI_ERROR(Status))
> +            break;
> +
> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
> +            continue;
> +
> +          //
> +          // Open package data
> +          //
> +          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
> +          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
> +
> +          Data = Buffer;
> +          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
> +                Data[0], DataSize > 1 ? Data[1] : 0);
> +
> +          //
> +          // Walk the _DSD node
> +          //
> +          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
> +            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
> +          }
> +
> +          AcpiTableProtocol->Close(PkgHandle);
> +        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
> +          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
> +          if (EFI_ERROR (Status)) {
> +            break;
> +          }
> +
> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
> +            continue;
> +          }
> +
> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
> +
> +          if (EFI_ERROR (Status)) {
> +            continue;
> +          }
> +        }
> +      }
> +    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
> +      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
> +    }
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +
> +BOOLEAN
> +IsSbScope (
> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
> +  EFI_ACPI_HANDLE         ChildHandle
> +  )
> +{
> +  EFI_STATUS          Status;
> +  EFI_ACPI_DATA_TYPE  DataType;
> +  CONST UINT8         *Data;
> +  CONST VOID          *Buffer;
> +  UINTN               DataSize;
> +
> +  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
> +  if (EFI_ERROR(Status)) return FALSE;
> +
> +  Data = Buffer;
> +  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
> +    return FALSE;
> +  }
> +
> +  return TRUE;
> +}
> +
> +EFI_STATUS ProcessDSDTChild(
> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> +  EFI_ACPI_HANDLE ChildHandle)
> +{
> +  EFI_STATUS          Status;
> +  EFI_ACPI_HANDLE     DevHandle;
> +
> +  // Check Scope(_SB) at first
> +  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
> +    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
> +  }
> +
> +  for (DevHandle = NULL; ; ) {
> +    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
> +    if (EFI_ERROR(Status) || DevHandle == NULL) {
> +      break;
> +    }
> +
> +    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +static EFI_STATUS ProcessDSDT(
> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
> +  EFI_ACPI_HANDLE TableHandle)
> +{
> +  EFI_STATUS              Status;
> +  EFI_ACPI_HANDLE         ChildHandle;
> +  //
> +  // Parse table for device type
> +  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
> +  for (ChildHandle = NULL; ; ) {
> +    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
> +    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
> +    if (EFI_ERROR(Status))
> +      break;
> +    if (ChildHandle == NULL)
> +      break;
> +
> +    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +STATIC
> +VOID
> +AcpiCheckSum (
> +  IN OUT  EFI_ACPI_SDT_HEADER *Table
> +  )
> +{
> +  UINTN ChecksumOffset;
> +  UINT8 *Buffer;
> +
> +  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
> +  Buffer = (UINT8 *)Table;
> +
> +  //
> +  // set checksum to 0 first
> +  //
> +  Buffer[ChecksumOffset] = 0;
> +
> +  //
> +  // Update checksum value
> +  //
> +  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
> +}
> +
> +EFI_STATUS UpdateAcpiDsdtTable(void)
> +{
> +  EFI_STATUS              Status;
> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
> +  EFI_ACPI_SDT_HEADER     *Table;
> +  EFI_ACPI_TABLE_VERSION  TableVersion;
> +  UINTN                   TableKey;
> +  EFI_ACPI_HANDLE         TableHandle;
> +  UINTN                   i;
> +
> +  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
> +
> +  //
> +  // Find the AcpiTable protocol
> +  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
> +  if (EFI_ERROR(Status)) {
> +    DBG("Unable to locate ACPI table protocol\n");
> +    return EFI_SUCCESS;
> +  }
> +
> +  //
> +  // Search for DSDT Table
> +  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
> +    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
> +    if (EFI_ERROR(Status))
> +      break;
> +    if (Table->Signature != DSDT_SIGNATURE)
> +      continue;
> +
> +    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
> +    if (EFI_ERROR(Status))
> +      break;
> +
> +    ProcessDSDT(AcpiTableProtocol, TableHandle);
> +
> +    AcpiTableProtocol->Close(TableHandle);
> +    AcpiCheckSum (Table);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
> new file mode 100644
> index 0000000..a7e1eed
> --- /dev/null
> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
> @@ -0,0 +1,16 @@
> +/*
> + *
> + * Copyright (c) 2014, Applied Micro Circuits Corporation
> + * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
> + * Copyright (c) 2015, Linaro Limited. All rights reserved.
> + * Author: Loc Ho <lho@apm.com>
> + *
> + * SPDX-License-Identifier: BSD-2-Clause-Patent
> + */
> +#ifndef _ETH_MAC_H_
> +#define _ETH_MAC_H_
> +
> +EFI_STATUS UpdateAcpiDsdtTable (VOID);
> +
> +#endif
> +
> -- 
> 2.8.1
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event
  2020-05-26 17:40   ` Leif Lindholm
@ 2020-05-27 11:38     ` Ming Huang
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Huang @ 2020-05-27 11:38 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen



在 2020/5/27 1:40, Leif Lindholm 写道:
> Please call your patches PATCH. RFC is when a potential solution
> is put up for discussion, not for changing platform code.

Modify it in v2.

> 
> On Thu, May 21, 2020 at 22:43:02 +0800, Ming Huang wrote:
>> The better time for updating dsdt is in ready to boot event,
>> so change the updating time.
> 
> The commit message should explain *why* it is better.

Modify it in v2.

> 
>>
>> Signed-off-by: Ming Huang <huangming23@huawei.com>
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c | 60 ++++++++++++++++++--
>>  1 file changed, 56 insertions(+), 4 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index b888cb1..1ab55bc 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -1,8 +1,8 @@
>>  /** @file
>>  
>> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
>> -  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
>> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
> 
> Only the Hisilicon copyright should be updated (or a Huawei one added,
> given that this is the address used for submitting).

Ok, just modify Hisilicon copyright in v2.

Thanks,
Ming

> 
> /
>     Leif
> 
>>    SPDX-License-Identifier: BSD-2-Clause-Patent
>>  
>>  **/
>> @@ -23,6 +23,38 @@
>>  #include <IndustryStandard/AcpiAml.h>
>>  #include "EthMac.h"
>>  
>> +EFI_EVENT       mUpdateAcpiDsdtTableEvent;
>> +
>> +VOID
>> +EFIAPI
>> +UpdateAcpiDsdt (
>> +  IN EFI_EVENT         Event,
>> +  IN VOID              *Context
>> +  )
>> +{
>> +  EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
>> +  EFI_STATUS              Status;
>> +
>> +  Status = gBS->LocateProtocol (
>> +                  &gEfiAcpiTableProtocolGuid,
>> +                  NULL,
>> +                  (VOID**)&AcpiTableProtocol
>> +                  );
>> +
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR, " Unable to locate ACPI table protocol\n"));
>> +    return;
>> +  }
>> +
>> +  Status = EthMacInit ();
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
>> +  }
>> +
>> +  gBS->CloseEvent (Event);
>> +  return;
>> +}
>> +
>>  EFI_STATUS
>>  EFIAPI
>>  AcpiPlatformEntryPoint (
>> @@ -30,5 +62,25 @@ AcpiPlatformEntryPoint (
>>    IN EFI_SYSTEM_TABLE   *SystemTable
>>    )
>>  {
>> -  return EthMacInit();
>> +  EFI_STATUS Status;
>> +
>> +  //
>> +  // Register notify function
>> +  //
>> +  Status = gBS->CreateEventEx (
>> +                  EVT_NOTIFY_SIGNAL,
>> +                  TPL_CALLBACK,
>> +                  UpdateAcpiDsdt,
>> +                  NULL,
>> +                  &gEfiEventReadyToBootGuid,
>> +                  &mUpdateAcpiDsdtTableEvent
>> +                  );
>> +
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR, "Create ReadyToBoot event for UpdateAcpiDsdt failed.\n"));
>> +  } else {
>> +    DEBUG ((DEBUG_INFO, "Create ReadyToBoot event for UpdateAcpiDsdt success.\n"));
>> +  }
>> +
>> +  return Status;
>>  }
>> -- 
>> 2.8.1
>>
> 
> .
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature
  2020-05-26 18:49   ` Leif Lindholm
@ 2020-05-27 14:21     ` Ming Huang
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Huang @ 2020-05-27 14:21 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen



在 2020/5/27 2:49, Leif Lindholm 写道:
> On Thu, May 21, 2020 at 22:43:03 +0800, Ming Huang wrote:
>> The updating sas address feature is similar with apdating mac address.
>> Modify updating dsdt flow for add this feature.
>>
>> Signed-off-by: Ming Huang <huangming23@huawei.com>
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c       | 200 +++++++++++++++-----
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h       |   2 +-
>>  3 files changed, 158 insertions(+), 46 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index 1ab55bc..d3ea051 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -46,7 +46,7 @@ UpdateAcpiDsdt (
>>      return;
>>    }
>>  
>> -  Status = EthMacInit ();
>> +  Status = UpdateAcpiDsdtTable ();
>>    if (EFI_ERROR (Status)) {
>>      DEBUG ((DEBUG_ERROR, " UpdateAcpiDsdtTable Failed, Status = %r\n", Status));
>>    }
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> index cd98506..205f2f9 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> @@ -1,8 +1,8 @@
>>  /** @file
>>  
>> -  Copyright (c) 2014, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> -  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
>> -  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
>> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
> 
> Same comment as for 1/3.

Modify it in v2.

> 
>>    SPDX-License-Identifier: BSD-2-Clause-Patent
>>  
>>    This driver is called to initialize the FW part of the PHY in preparation
>> @@ -30,6 +30,7 @@
>>  #include <Library/UefiRuntimeServicesTableLib.h>
>>  #include <IndustryStandard/Acpi.h>
>>  #include <IndustryStandard/AcpiAml.h>
>> +#include <Library/MemoryAllocationLib.h>
> 
> Good lord this include block is a mess.
> Nevertheless, a less offensive place to insert this new header would
> be between
> #include <Library/DebugLib.h>
> and
> #include <Library/PcdLib.h>
> .

Ok, modify it in v2.

> 
>>  
>>  #include <Protocol/HisiBoardNicProtocol.h>
>>  
>> @@ -45,13 +46,20 @@
>>  #define EFI_ACPI_MAX_NUM_TABLES         20
>>  #define DSDT_SIGNATURE                  0x54445344
>>  
>> -#define D03_ACPI_ETH_ID                     "HISI00C2"
>> -
>>  #define ACPI_ETH_MAC_KEY                "local-mac-address"
>> +#define ACPI_ETH_SAS_KEY                 "sas-addr"
> 
> Please consider column alignment.
> 
>>  
>>  #define PREFIX_VARIABLE_NAME            L"MAC"
>>  #define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
>> -#define MAC_MAX_LEN                     30
>> +#define ADDRESS_MAX_LEN                     30
> 
> Please consider column alignment.

Ok, modify it in v2.

> 
>>
>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> +
>> +typedef enum {
>> +  DsdtDeviceUnknown,
>> +  DsdtDeviceLan,
>> +  DsdtDeviceSas
>> +} DSDT_DEVICE_TYPE;
>>  
>>  EFI_STATUS GetEnvMac(
>>    IN          UINTN    MacNextID,
>> @@ -89,12 +97,35 @@ EFI_STATUS GetEnvMac(
>>    return EFI_SUCCESS;
>>  }
>>  
>> -EFI_STATUS _SearchReplacePackageMACAddress(
>> +EFI_STATUS GetSasAddress (
> 
> Function name should be on separate line.
> If only used in this module, function should also be STATIC.

Ok, modify it in v2.

> 
>> +  IN UINT8        Index,
>> +  IN OUT UINT8    *SasAddrBuffer
>> +  )
>> +{
>> +  if (SasAddrBuffer == NULL) {
>> +      return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  SasAddrBuffer[0] = 0x50;
>> +  SasAddrBuffer[1] = 0x01;
>> +  SasAddrBuffer[2] = 0x88;
>> +  SasAddrBuffer[3] = 0x20;
>> +  SasAddrBuffer[4] = 0x16;
>> +  SasAddrBuffer[5] = 0x00;
>> +  SasAddrBuffer[6] = 0x00;
>> +  SasAddrBuffer[7] = Index;
> 
> What does the above do?
> What are the hardcoded values?

In v2, add a protocol interface to get sas address and this SasAddrBuffer assignment
will only in error branch.

> 
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +EFI_STATUS _SearchReplacePackageAddress(
> 
> Function name should be on separate line.
> If only used in this module, function should also be STATIC.
> Functions should not have names starting with _.

Ok, modify it in v2.

> 
>>    IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>>    IN EFI_ACPI_HANDLE        ChildHandle,
>>    IN UINTN                  Level,
>>    IN OUT BOOLEAN            *Found,
>> -  IN UINTN                  MacNextID)
>> +  IN UINTN                  DevNextID,
>> +  IN DSDT_DEVICE_TYPE       FoundDev
>> +  )
>>  {
>>    // ASL template for ethernet driver:
>>  /*
>> @@ -117,12 +148,18 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>    UINTN               Count;
>>    EFI_ACPI_HANDLE     CurrentHandle;
>>    EFI_ACPI_HANDLE     NextHandle;
>> -  UINT8               MACBuffer[MAC_MAX_LEN];
>> +  EFI_ACPI_HANDLE     Level1Handle;
>> +  UINT8               *AddressBuffer;
>> +  UINT8               AddressByte = 0;
>>  
>>    DBG("In Level:%d\n", Level);
>> +  Level1Handle = NULL;
>>    Status = EFI_SUCCESS;
>>    for (CurrentHandle = NULL; ;) {
>>      Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>> +    if (Level == 1) {
>> +      Level1Handle = CurrentHandle;
>> +    }
>>      if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
>>         break;
>>  
>> @@ -143,11 +180,14 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>                DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>>  
>>        Data = Buffer;
>> -      if (DataType != EFI_ACPI_DATA_TYPE_STRING
>> -              || AsciiStrCmp((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0)
>> +      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
>> +            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
>> +            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
> 
> Indentation should help clarify the relationship between the differenc
> comparison values:
> 
>       if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
>           ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
>            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {

Ok, modify it in v2.

> 
>> +        ChildHandle = Level1Handle;
>>          continue;
>> +      }
>>  
>> -      DBG("_DSD Key Type %d. Found MAC address key\n", DataType);
>> +      DBG("_DSD Key Type %d. Found address key\n", DataType);
>>  
>>        //
>>        // We found the node.
>> @@ -157,13 +197,33 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>      }
>>  
>>      if (Level == 3 && *Found) {
>> +      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
>> +      if (AddressBuffer == NULL) {
>> +        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
>> +        return EFI_OUT_OF_RESOURCES;
>> +      }
>>  
>> -      //Update the MAC
>> -      Status = GetEnvMac(MacNextID, MACBuffer);
>> -      if (EFI_ERROR(Status))
>> +      switch (FoundDev) {
>> +        case DsdtDeviceLan:
>> +          //Update the MAC
>> +          Status = GetEnvMac (DevNextID, AddressBuffer);
>> +          AddressByte = 6;
>> +          break;
>> +        case DsdtDeviceSas:
>> +          //Update SAS Address.
>> +          Status = GetSasAddress (DevNextID, AddressBuffer);
>> +          AddressByte = 8;
>> +          break;
>> +        default:
>> +          Status = EFI_INVALID_PARAMETER;
>> +      }
>> +      if (EFI_ERROR (Status)) {
>> +        FreePool (AddressBuffer);
>> +        AddressBuffer = NULL;
> 
> These nested for loops could certainly benefit from having their
> contents broken down into a few helper functions, but fundamentally -
> this AddressBuffer is only used again on another time around the loop,
> and if so, it is overwritten by the call to AllocateZeroPool. Why are
> we rewriting the pointer?

Good idea, I will break down it into a new helper funtion.

The reason for rewriting the pointer is that there is a internal programming
specification to do this. The rewriting is not need in reality, so I will
delete it in v2.

> 
>>          break;
>> +      }
>>  
>> -      for (Count = 0; Count < 6; Count++) {
>> +      for (Count = 0; Count < AddressByte; Count++) {
>>          Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>>          if (EFI_ERROR(Status))
>>            break;
>> @@ -177,13 +237,15 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>  
>>          // only need one byte.
>>          // FIXME: Assume the CPU is little endian
>> -        Status = AcpiTableProtocol->SetOption(CurrentHandle, 1, (VOID *)&MACBuffer[Count], sizeof(UINT8));
>> +        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
>>          if (EFI_ERROR(Status))
>>            break;
>>          Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>>          if (EFI_ERROR(Status) || CurrentHandle == NULL)
>>            break;
>>        }
>> +      FreePool (AddressBuffer);
>> +      AddressBuffer = NULL;
> 
> Same thing again - why rewrite the pointer after free?
> 
>>        break;
>>      }
>>  
>> @@ -192,7 +254,13 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>  
>>      //Search next package
>>      AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
>> -    Status = _SearchReplacePackageMACAddress(AcpiTableProtocol, NextHandle, Level + 1, Found, MacNextID);
>> +    Status = _SearchReplacePackageAddress(
> 
> Indentation looks wrong because of the function name. Drop the leading
> _ and it will be fine.

Ok, modify it in v2.

> 
>> +               AcpiTableProtocol,
>> +               NextHandle,
>> +               Level + 1,
>> +               Found,
>> +               DevNextID,
>> +               FoundDev);
>>      AcpiTableProtocol->Close(NextHandle);
>>      if (!EFI_ERROR(Status))
>>        break;
>> @@ -201,22 +269,26 @@ EFI_STATUS _SearchReplacePackageMACAddress(
>>    return Status;
>>  }
>>  
>> -EFI_STATUS SearchReplacePackageMACAddress(
>> +EFI_STATUS SearchReplacePackageAddress(
>>    IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>>    IN EFI_ACPI_HANDLE        ChildHandle,
>> -  IN UINTN                  MacNextID)
>> +  IN UINTN                  DevNextID,
>> +  IN DSDT_DEVICE_TYPE       FoundDev
>> +  )
>>  {
>>    BOOLEAN Found = FALSE;
>>    UINTN Level = 0;
>>  
>> -  return _SearchReplacePackageMACAddress(AcpiTableProtocol, ChildHandle, Level, &Found, MacNextID);
>> +  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
>> +                                      &Found, DevNextID, FoundDev);
>>  }
>>  
>>  EFI_STATUS
>> -GetEthID (
>> +GetDeviceInfo (
>>    EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>>    EFI_ACPI_HANDLE         ChildHandle,
>> -  UINTN                   *EthID
>> +  UINTN                   *DevID,
>> +  DSDT_DEVICE_TYPE        *FoundDev
>>    )
>>  {
>>    EFI_STATUS Status;
>> @@ -225,7 +297,7 @@ GetEthID (
>>    CONST VOID          *Buffer;
>>    UINTN               DataSize;
>>  
>> -  // Get NameString ETHx
>> +  // Get NameString
>>    Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
>>    if (EFI_ERROR (Status)) {
>>      DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
>> @@ -236,14 +308,23 @@ GetEthID (
>>    DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
>>  
>>    Data[4] = '\0';
>> -  if (DataSize != 4 ||
>> -      AsciiStrnCmp ("ETH", Data, 3) != 0 ||
>> -      Data[3] > '9' || Data[3] < '0') {
>> -    DEBUG ((EFI_D_ERROR, "[%a:%d] The NameString %a is not ETHn\n", __FUNCTION__, __LINE__, Data));
>> +  if ((DataSize != 4) ||
>> +    (Data[3] > '9' || Data[3] < '0')) {
>> +    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
>>      return EFI_INVALID_PARAMETER;
>>    }
>>  
>> -  *EthID = Data[3] - '0';
>> +  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
>> +    *FoundDev = DsdtDeviceLan;
>> +  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
>> +    *FoundDev = DsdtDeviceSas;
>> +  } else {
>> +    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
>> +            __FUNCTION__, __LINE__, Data));
>> +    return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  *DevID = Data[3] - '0';
>>    return EFI_SUCCESS;
>>  }
>>  
>> @@ -257,8 +338,10 @@ EFI_STATUS ProcessDSDTDevice (
>>    CONST VOID          *Buffer;
>>    UINTN               DataSize;
>>    EFI_ACPI_HANDLE     DevHandle;
>> -  INTN                Found = 0;
>> -  UINTN               MacNextID;
>> +  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
>> +  UINTN               DevNextID;
>> +  BOOLEAN             HisiAcpiDevNotFound;
>> +  UINTN               Index;
>>  
>>    Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
>>    if (EFI_ERROR(Status))
>> @@ -280,7 +363,7 @@ EFI_STATUS ProcessDSDTDevice (
>>        break;
>>  
>>      //
>> -    // Search for _HID with Ethernet ID
>> +    // Search for _HID with Device ID
>>      //
>>      Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
>>      if (EFI_ERROR(Status))
>> @@ -312,23 +395,34 @@ EFI_STATUS ProcessDSDTDevice (
>>            DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
>>  
>>            if (EFI_ERROR(Status) ||
>> -              DataType != EFI_ACPI_DATA_TYPE_STRING ||
>> -              (AsciiStrCmp((CHAR8 *) Data, D03_ACPI_ETH_ID) != 0)) {
>> -            AcpiTableProtocol->Close(ValueHandle);
>> -            Found = 0;
>> +              DataType != EFI_ACPI_DATA_TYPE_STRING) {
>> +            AcpiTableProtocol->Close (ValueHandle);
>> +            FoundDev = DsdtDeviceUnknown;
>> +            continue;
>> +          }
>> +
>> +          HisiAcpiDevNotFound = TRUE;
>> +          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
>> +            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
>> +              HisiAcpiDevNotFound = FALSE;
>> +              break;
>> +            }
>> +          }
>> +          if (HisiAcpiDevNotFound) {
>> +            AcpiTableProtocol->Close (ValueHandle);
>> +            FoundDev = DsdtDeviceUnknown;
>>              continue;
>>            }
>>  
>> -          DBG("Found Ethernet device\n");
>> +          DBG("Found device\n");
>>            AcpiTableProtocol->Close(ValueHandle);
>> -          Status = GetEthID (AcpiTableProtocol, ChildHandle, &MacNextID);
>> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>>            if (EFI_ERROR (Status)) {
>>              continue;
>>            }
>> -          Found = 1;
>> -        } else if (Found == 1 && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
>> +        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
>>            //
>> -          // Patch MAC address for open source kernel
>> +          // Patch DSD data
>>            //
>>            EFI_ACPI_HANDLE    PkgHandle;
>>            Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
>> @@ -351,12 +445,30 @@ EFI_STATUS ProcessDSDTDevice (
>>            //
>>            // Walk the _DSD node
>>            //
>> -          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP)
>> -            Status = SearchReplacePackageMACAddress(AcpiTableProtocol, PkgHandle, MacNextID);
>> +          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
>> +            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
>> +          }
>>  
>>            AcpiTableProtocol->Close(PkgHandle);
>> +        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
>> +          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
>> +          if (EFI_ERROR (Status)) {
>> +            break;
>> +          }
>> +
>> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
>> +            continue;
>> +          }
>> +
>> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>> +
>> +          if (EFI_ERROR (Status)) {
>> +            continue;
>> +          }
>>          }
>>        }
>> +    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
>> +      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>>      }
>>    }
>>  
>> @@ -457,7 +569,7 @@ AcpiCheckSum (
>>    Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
>>  }
>>  
>> -EFI_STATUS EthMacInit(void)
>> +EFI_STATUS UpdateAcpiDsdtTable(void)
> 
> Function name on its own line.

Ok, modify it in v2.

Thanks,
Ming

> 
> /
>     Leif
> 
>>  {
>>    EFI_STATUS              Status;
>>    EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>> index 0a3e811..a7e1eed 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>> @@ -10,7 +10,7 @@
>>  #ifndef _ETH_MAC_H_
>>  #define _ETH_MAC_H_
>>  
>> -EFI_STATUS EthMacInit(VOID);
>> +EFI_STATUS UpdateAcpiDsdtTable (VOID);
>>  
>>  #endif
>>  
>> -- 
>> 2.8.1
>>
> 
> .
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files
  2020-05-26 18:50   ` Leif Lindholm
@ 2020-05-27 14:22     ` Ming Huang
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Huang @ 2020-05-27 14:22 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen



在 2020/5/27 2:50, Leif Lindholm 写道:
> On Thu, May 21, 2020 at 22:43:04 +0800, Ming Huang wrote:
>> As not only update mac address feature in EthMac files, so rename
>> them to UpdateDsdt.
>>
>> Signed-off-by: Ming Huang <huangming23@huawei.com>
>> ---
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |   2 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 612 --------------------
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
>>  6 files changed, 633 insertions(+), 633 deletions(-)
>>
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> index d3ea051..fd67677 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c
>> @@ -21,7 +21,7 @@
>>  #include <Library/UefiRuntimeServicesTableLib.h>
>>  #include <IndustryStandard/Acpi.h>
>>  #include <IndustryStandard/AcpiAml.h>
>> -#include "EthMac.h"
>> +#include "UpdateDsdt.h"
>>  
>>  EFI_EVENT       mUpdateAcpiDsdtTableEvent;
>>  
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> index 53da731..a2b669d 100644
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
>> @@ -1,8 +1,8 @@
>>  ## @file
>>  #
>> -#  Copyright (c) 2014, Applied Micro Curcuit Corp. All rights reserved.<BR>
>> -#  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
>> -#  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
>> +#  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights reserved.<BR>
>> +#  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
>> +#  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
> 
> Same comment on copyright as on 1/3 and 2/3.

Modify it in v2.

Thanks,
Ming

> 
> /
>     Leif
> 
>>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>>  #
>>  ##
>> @@ -18,7 +18,7 @@
>>  
>>  [Sources]
>>    AcpiPlatform.c
>> -  EthMac.c
>> +  UpdateDsdt.c
>>  
>>  [Packages]
>>    MdePkg/MdePkg.dec
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> deleted file mode 100644
>> index 205f2f9..0000000
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>> +++ /dev/null
>> @@ -1,612 +0,0 @@
>> -/** @file
>> -
>> -  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> -  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
>> -  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
>> -  SPDX-License-Identifier: BSD-2-Clause-Patent
>> -
>> -  This driver is called to initialize the FW part of the PHY in preparation
>> -  for the OS.
>> -
>> -**/
>> -
>> -#include <Guid/ShellVariableGuid.h>
>> -#include <Library/UefiRuntimeServicesTableLib.h>
>> -#include <Library/DebugLib.h>
>> -#include <Library/TimerLib.h>
>> -
>> -#include <PiDxe.h>
>> -#include <Guid/EventGroup.h>
>> -#include <Protocol/AcpiTable.h>
>> -#include <Protocol/FirmwareVolume2.h>
>> -#include <Library/BaseLib.h>
>> -#include <Library/UefiBootServicesTableLib.h>
>> -#include <Protocol/AcpiSystemDescriptionTable.h>
>> -#include <Library/DebugLib.h>
>> -#include <Library/PcdLib.h>
>> -#include <Library/PrintLib.h>
>> -#include <Library/DebugLib.h>
>> -#include <Library/BaseMemoryLib.h>
>> -#include <Library/UefiRuntimeServicesTableLib.h>
>> -#include <IndustryStandard/Acpi.h>
>> -#include <IndustryStandard/AcpiAml.h>
>> -#include <Library/MemoryAllocationLib.h>
>> -
>> -#include <Protocol/HisiBoardNicProtocol.h>
>> -
>> -// Turn on debug message by enabling below define
>> -//#define ACPI_DEBUG
>> -
>> -#ifdef ACPI_DEBUG
>> -#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
>> -#else
>> -#define DBG(arg...)
>> -#endif
>> -
>> -#define EFI_ACPI_MAX_NUM_TABLES         20
>> -#define DSDT_SIGNATURE                  0x54445344
>> -
>> -#define ACPI_ETH_MAC_KEY                "local-mac-address"
>> -#define ACPI_ETH_SAS_KEY                 "sas-addr"
>> -
>> -#define PREFIX_VARIABLE_NAME            L"MAC"
>> -#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
>> -#define ADDRESS_MAX_LEN                     30
>> -
>> -CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> -
>> -typedef enum {
>> -  DsdtDeviceUnknown,
>> -  DsdtDeviceLan,
>> -  DsdtDeviceSas
>> -} DSDT_DEVICE_TYPE;
>> -
>> -EFI_STATUS GetEnvMac(
>> -  IN          UINTN    MacNextID,
>> -  IN OUT      UINT8    *MacBuffer)
>> -{
>> -  EFI_MAC_ADDRESS Mac;
>> -  EFI_STATUS Status;
>> -  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
>> -
>> -  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
>> -  if(EFI_ERROR(Status))
>> -  {
>> -    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
>> -    return Status;
>> -  }
>> -
>> -  Status = OemNic->GetMac(&Mac, MacNextID);
>> -  if(EFI_ERROR(Status))
>> -  {
>> -    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
>> -    return Status;
>> -  }
>> -
>> -  CopyMem (MacBuffer, &Mac, 6);
>> -  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
>> -        MacNextID,
>> -        MacBuffer[0],
>> -        MacBuffer[1],
>> -        MacBuffer[2],
>> -        MacBuffer[3],
>> -        MacBuffer[4],
>> -        MacBuffer[5]
>> -        ));
>> -
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -EFI_STATUS GetSasAddress (
>> -  IN UINT8        Index,
>> -  IN OUT UINT8    *SasAddrBuffer
>> -  )
>> -{
>> -  if (SasAddrBuffer == NULL) {
>> -      return EFI_INVALID_PARAMETER;
>> -  }
>> -
>> -  SasAddrBuffer[0] = 0x50;
>> -  SasAddrBuffer[1] = 0x01;
>> -  SasAddrBuffer[2] = 0x88;
>> -  SasAddrBuffer[3] = 0x20;
>> -  SasAddrBuffer[4] = 0x16;
>> -  SasAddrBuffer[5] = 0x00;
>> -  SasAddrBuffer[6] = 0x00;
>> -  SasAddrBuffer[7] = Index;
>> -
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -EFI_STATUS _SearchReplacePackageAddress(
>> -  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>> -  IN EFI_ACPI_HANDLE        ChildHandle,
>> -  IN UINTN                  Level,
>> -  IN OUT BOOLEAN            *Found,
>> -  IN UINTN                  DevNextID,
>> -  IN DSDT_DEVICE_TYPE       FoundDev
>> -  )
>> -{
>> -  // ASL template for ethernet driver:
>> -/*
>> - *   Name (_DSD, Package () {
>> - *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>> - *   Package () {
>> - *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
>> - *     Package (2) {"phy-channel", 0},
>> - *     Package (2) {"phy-mode", "rgmii"},
>> - *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
>> - *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
>> - *   }
>> - * })
>> - */
>> -  EFI_STATUS          Status;
>> -  EFI_ACPI_DATA_TYPE  DataType;
>> -  CONST UINT8         *Data;
>> -  CONST VOID          *Buffer;
>> -  UINTN               DataSize;
>> -  UINTN               Count;
>> -  EFI_ACPI_HANDLE     CurrentHandle;
>> -  EFI_ACPI_HANDLE     NextHandle;
>> -  EFI_ACPI_HANDLE     Level1Handle;
>> -  UINT8               *AddressBuffer;
>> -  UINT8               AddressByte = 0;
>> -
>> -  DBG("In Level:%d\n", Level);
>> -  Level1Handle = NULL;
>> -  Status = EFI_SUCCESS;
>> -  for (CurrentHandle = NULL; ;) {
>> -    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>> -    if (Level == 1) {
>> -      Level1Handle = CurrentHandle;
>> -    }
>> -    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
>> -       break;
>> -
>> -    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
>> -    Data = Buffer;
>> -    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
>> -        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>> -
>> -    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
>> -      continue;
>> -
>> -    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
>> -      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>> -      if (EFI_ERROR(Status))
>> -        break;
>> -
>> -      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
>> -              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>> -
>> -      Data = Buffer;
>> -      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
>> -            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
>> -            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
>> -        ChildHandle = Level1Handle;
>> -        continue;
>> -      }
>> -
>> -      DBG("_DSD Key Type %d. Found address key\n", DataType);
>> -
>> -      //
>> -      // We found the node.
>> -      //
>> -      *Found = TRUE;
>> -      continue;
>> -    }
>> -
>> -    if (Level == 3 && *Found) {
>> -      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
>> -      if (AddressBuffer == NULL) {
>> -        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
>> -        return EFI_OUT_OF_RESOURCES;
>> -      }
>> -
>> -      switch (FoundDev) {
>> -        case DsdtDeviceLan:
>> -          //Update the MAC
>> -          Status = GetEnvMac (DevNextID, AddressBuffer);
>> -          AddressByte = 6;
>> -          break;
>> -        case DsdtDeviceSas:
>> -          //Update SAS Address.
>> -          Status = GetSasAddress (DevNextID, AddressBuffer);
>> -          AddressByte = 8;
>> -          break;
>> -        default:
>> -          Status = EFI_INVALID_PARAMETER;
>> -      }
>> -      if (EFI_ERROR (Status)) {
>> -        FreePool (AddressBuffer);
>> -        AddressBuffer = NULL;
>> -        break;
>> -      }
>> -
>> -      for (Count = 0; Count < AddressByte; Count++) {
>> -        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>> -        if (EFI_ERROR(Status))
>> -          break;
>> -
>> -        Data = Buffer;
>> -        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
>> -            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
>> -
>> -        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
>> -          break;
>> -
>> -        // only need one byte.
>> -        // FIXME: Assume the CPU is little endian
>> -        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
>> -        if (EFI_ERROR(Status))
>> -          break;
>> -        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>> -        if (EFI_ERROR(Status) || CurrentHandle == NULL)
>> -          break;
>> -      }
>> -      FreePool (AddressBuffer);
>> -      AddressBuffer = NULL;
>> -      break;
>> -    }
>> -
>> -    if (Level > 3)
>> -      break;
>> -
>> -    //Search next package
>> -    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
>> -    Status = _SearchReplacePackageAddress(
>> -               AcpiTableProtocol,
>> -               NextHandle,
>> -               Level + 1,
>> -               Found,
>> -               DevNextID,
>> -               FoundDev);
>> -    AcpiTableProtocol->Close(NextHandle);
>> -    if (!EFI_ERROR(Status))
>> -      break;
>> -  }
>> -
>> -  return Status;
>> -}
>> -
>> -EFI_STATUS SearchReplacePackageAddress(
>> -  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>> -  IN EFI_ACPI_HANDLE        ChildHandle,
>> -  IN UINTN                  DevNextID,
>> -  IN DSDT_DEVICE_TYPE       FoundDev
>> -  )
>> -{
>> -  BOOLEAN Found = FALSE;
>> -  UINTN Level = 0;
>> -
>> -  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
>> -                                      &Found, DevNextID, FoundDev);
>> -}
>> -
>> -EFI_STATUS
>> -GetDeviceInfo (
>> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>> -  EFI_ACPI_HANDLE         ChildHandle,
>> -  UINTN                   *DevID,
>> -  DSDT_DEVICE_TYPE        *FoundDev
>> -  )
>> -{
>> -  EFI_STATUS Status;
>> -  EFI_ACPI_DATA_TYPE  DataType;
>> -  CHAR8               Data[5];
>> -  CONST VOID          *Buffer;
>> -  UINTN               DataSize;
>> -
>> -  // Get NameString
>> -  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
>> -  if (EFI_ERROR (Status)) {
>> -    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
>> -    return Status;
>> -  }
>> -
>> -  CopyMem (Data, Buffer, 4);
>> -  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
>> -
>> -  Data[4] = '\0';
>> -  if ((DataSize != 4) ||
>> -    (Data[3] > '9' || Data[3] < '0')) {
>> -    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
>> -    return EFI_INVALID_PARAMETER;
>> -  }
>> -
>> -  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
>> -    *FoundDev = DsdtDeviceLan;
>> -  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
>> -    *FoundDev = DsdtDeviceSas;
>> -  } else {
>> -    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
>> -            __FUNCTION__, __LINE__, Data));
>> -    return EFI_INVALID_PARAMETER;
>> -  }
>> -
>> -  *DevID = Data[3] - '0';
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -EFI_STATUS ProcessDSDTDevice (
>> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> -  EFI_ACPI_HANDLE ChildHandle)
>> -{
>> -  EFI_STATUS          Status;
>> -  EFI_ACPI_DATA_TYPE  DataType;
>> -  CONST UINT8         *Data;
>> -  CONST VOID          *Buffer;
>> -  UINTN               DataSize;
>> -  EFI_ACPI_HANDLE     DevHandle;
>> -  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
>> -  UINTN               DevNextID;
>> -  BOOLEAN             HisiAcpiDevNotFound;
>> -  UINTN               Index;
>> -
>> -  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
>> -  if (EFI_ERROR(Status))
>> -    return EFI_SUCCESS;
>> -
>> -  Data = Buffer;
>> -  //
>> -  // Skip all non-device type
>> -  //
>> -  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
>> -    return EFI_SUCCESS;
>> -
>> -  //
>> -  // Walk the device type node
>> -  //
>> -  for (DevHandle = NULL; ; ) {
>> -    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
>> -    if (EFI_ERROR(Status) || DevHandle == NULL)
>> -      break;
>> -
>> -    //
>> -    // Search for _HID with Device ID
>> -    //
>> -    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
>> -    if (EFI_ERROR(Status))
>> -      break;
>> -
>> -    Data = Buffer;
>> -    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
>> -    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
>> -      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
>> -      if (EFI_ERROR(Status))
>> -        break;
>> -
>> -      Data = Buffer;
>> -      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
>> -        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
>> -          EFI_ACPI_HANDLE ValueHandle;
>> -
>> -          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
>> -          if (EFI_ERROR(Status))
>> -            break;
>> -
>> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
>> -            continue;
>> -
>> -          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
>> -          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
>> -
>> -          Data = Buffer;
>> -          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
>> -
>> -          if (EFI_ERROR(Status) ||
>> -              DataType != EFI_ACPI_DATA_TYPE_STRING) {
>> -            AcpiTableProtocol->Close (ValueHandle);
>> -            FoundDev = DsdtDeviceUnknown;
>> -            continue;
>> -          }
>> -
>> -          HisiAcpiDevNotFound = TRUE;
>> -          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
>> -            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
>> -              HisiAcpiDevNotFound = FALSE;
>> -              break;
>> -            }
>> -          }
>> -          if (HisiAcpiDevNotFound) {
>> -            AcpiTableProtocol->Close (ValueHandle);
>> -            FoundDev = DsdtDeviceUnknown;
>> -            continue;
>> -          }
>> -
>> -          DBG("Found device\n");
>> -          AcpiTableProtocol->Close(ValueHandle);
>> -          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>> -          if (EFI_ERROR (Status)) {
>> -            continue;
>> -          }
>> -        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
>> -          //
>> -          // Patch DSD data
>> -          //
>> -          EFI_ACPI_HANDLE    PkgHandle;
>> -          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
>> -          if (EFI_ERROR(Status))
>> -            break;
>> -
>> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
>> -            continue;
>> -
>> -          //
>> -          // Open package data
>> -          //
>> -          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
>> -          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
>> -
>> -          Data = Buffer;
>> -          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
>> -                Data[0], DataSize > 1 ? Data[1] : 0);
>> -
>> -          //
>> -          // Walk the _DSD node
>> -          //
>> -          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
>> -            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
>> -          }
>> -
>> -          AcpiTableProtocol->Close(PkgHandle);
>> -        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
>> -          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
>> -          if (EFI_ERROR (Status)) {
>> -            break;
>> -          }
>> -
>> -          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
>> -            continue;
>> -          }
>> -
>> -          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>> -
>> -          if (EFI_ERROR (Status)) {
>> -            continue;
>> -          }
>> -        }
>> -      }
>> -    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
>> -      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>> -    }
>> -  }
>> -
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -
>> -BOOLEAN
>> -IsSbScope (
>> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>> -  EFI_ACPI_HANDLE         ChildHandle
>> -  )
>> -{
>> -  EFI_STATUS          Status;
>> -  EFI_ACPI_DATA_TYPE  DataType;
>> -  CONST UINT8         *Data;
>> -  CONST VOID          *Buffer;
>> -  UINTN               DataSize;
>> -
>> -  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
>> -  if (EFI_ERROR(Status)) return FALSE;
>> -
>> -  Data = Buffer;
>> -  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
>> -    return FALSE;
>> -  }
>> -
>> -  return TRUE;
>> -}
>> -
>> -EFI_STATUS ProcessDSDTChild(
>> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> -  EFI_ACPI_HANDLE ChildHandle)
>> -{
>> -  EFI_STATUS          Status;
>> -  EFI_ACPI_HANDLE     DevHandle;
>> -
>> -  // Check Scope(_SB) at first
>> -  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
>> -    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
>> -  }
>> -
>> -  for (DevHandle = NULL; ; ) {
>> -    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
>> -    if (EFI_ERROR(Status) || DevHandle == NULL) {
>> -      break;
>> -    }
>> -
>> -    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>> -  }
>> -
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -static EFI_STATUS ProcessDSDT(
>> -  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> -  EFI_ACPI_HANDLE TableHandle)
>> -{
>> -  EFI_STATUS              Status;
>> -  EFI_ACPI_HANDLE         ChildHandle;
>> -  //
>> -  // Parse table for device type
>> -  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
>> -  for (ChildHandle = NULL; ; ) {
>> -    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
>> -    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
>> -    if (EFI_ERROR(Status))
>> -      break;
>> -    if (ChildHandle == NULL)
>> -      break;
>> -
>> -    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
>> -  }
>> -
>> -  return EFI_SUCCESS;
>> -}
>> -
>> -STATIC
>> -VOID
>> -AcpiCheckSum (
>> -  IN OUT  EFI_ACPI_SDT_HEADER *Table
>> -  )
>> -{
>> -  UINTN ChecksumOffset;
>> -  UINT8 *Buffer;
>> -
>> -  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
>> -  Buffer = (UINT8 *)Table;
>> -
>> -  //
>> -  // set checksum to 0 first
>> -  //
>> -  Buffer[ChecksumOffset] = 0;
>> -
>> -  //
>> -  // Update checksum value
>> -  //
>> -  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
>> -}
>> -
>> -EFI_STATUS UpdateAcpiDsdtTable(void)
>> -{
>> -  EFI_STATUS              Status;
>> -  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
>> -  EFI_ACPI_SDT_HEADER     *Table;
>> -  EFI_ACPI_TABLE_VERSION  TableVersion;
>> -  UINTN                   TableKey;
>> -  EFI_ACPI_HANDLE         TableHandle;
>> -  UINTN                   i;
>> -
>> -  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
>> -
>> -  //
>> -  // Find the AcpiTable protocol
>> -  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
>> -  if (EFI_ERROR(Status)) {
>> -    DBG("Unable to locate ACPI table protocol\n");
>> -    return EFI_SUCCESS;
>> -  }
>> -
>> -  //
>> -  // Search for DSDT Table
>> -  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
>> -    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
>> -    if (EFI_ERROR(Status))
>> -      break;
>> -    if (Table->Signature != DSDT_SIGNATURE)
>> -      continue;
>> -
>> -    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
>> -    if (EFI_ERROR(Status))
>> -      break;
>> -
>> -    ProcessDSDT(AcpiTableProtocol, TableHandle);
>> -
>> -    AcpiTableProtocol->Close(TableHandle);
>> -    AcpiCheckSum (Table);
>> -  }
>> -
>> -  return EFI_SUCCESS;
>> -}
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>> deleted file mode 100644
>> index a7e1eed..0000000
>> --- a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>> +++ /dev/null
>> @@ -1,16 +0,0 @@
>> -/*
>> - *
>> - * Copyright (c) 2014, Applied Micro Circuits Corporation
>> - * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> - * Copyright (c) 2015, Linaro Limited. All rights reserved.
>> - * Author: Loc Ho <lho@apm.com>
>> - *
>> - * SPDX-License-Identifier: BSD-2-Clause-Patent
>> - */
>> -#ifndef _ETH_MAC_H_
>> -#define _ETH_MAC_H_
>> -
>> -EFI_STATUS UpdateAcpiDsdtTable (VOID);
>> -
>> -#endif
>> -
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
>> new file mode 100644
>> index 0000000..205f2f9
>> --- /dev/null
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
>> @@ -0,0 +1,612 @@
>> +/** @file
>> +
>> +  Copyright (c) 2014 - 2020, Applied Micro Curcuit Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<BR>
>> +  Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.<BR>
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +  This driver is called to initialize the FW part of the PHY in preparation
>> +  for the OS.
>> +
>> +**/
>> +
>> +#include <Guid/ShellVariableGuid.h>
>> +#include <Library/UefiRuntimeServicesTableLib.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/TimerLib.h>
>> +
>> +#include <PiDxe.h>
>> +#include <Guid/EventGroup.h>
>> +#include <Protocol/AcpiTable.h>
>> +#include <Protocol/FirmwareVolume2.h>
>> +#include <Library/BaseLib.h>
>> +#include <Library/UefiBootServicesTableLib.h>
>> +#include <Protocol/AcpiSystemDescriptionTable.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/PcdLib.h>
>> +#include <Library/PrintLib.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/BaseMemoryLib.h>
>> +#include <Library/UefiRuntimeServicesTableLib.h>
>> +#include <IndustryStandard/Acpi.h>
>> +#include <IndustryStandard/AcpiAml.h>
>> +#include <Library/MemoryAllocationLib.h>
>> +
>> +#include <Protocol/HisiBoardNicProtocol.h>
>> +
>> +// Turn on debug message by enabling below define
>> +//#define ACPI_DEBUG
>> +
>> +#ifdef ACPI_DEBUG
>> +#define DBG(arg...) DEBUG((EFI_D_ERROR,## arg))
>> +#else
>> +#define DBG(arg...)
>> +#endif
>> +
>> +#define EFI_ACPI_MAX_NUM_TABLES         20
>> +#define DSDT_SIGNATURE                  0x54445344
>> +
>> +#define ACPI_ETH_MAC_KEY                "local-mac-address"
>> +#define ACPI_ETH_SAS_KEY                 "sas-addr"
>> +
>> +#define PREFIX_VARIABLE_NAME            L"MAC"
>> +#define PREFIX_VARIABLE_NAME_COMPAT     L"RGMII_MAC"
>> +#define ADDRESS_MAX_LEN                     30
>> +
>> +CHAR8 *mHisiAcpiDevId[] = {"HISI00C1","HISI00C2","HISI0162"};
>> +
>> +typedef enum {
>> +  DsdtDeviceUnknown,
>> +  DsdtDeviceLan,
>> +  DsdtDeviceSas
>> +} DSDT_DEVICE_TYPE;
>> +
>> +EFI_STATUS GetEnvMac(
>> +  IN          UINTN    MacNextID,
>> +  IN OUT      UINT8    *MacBuffer)
>> +{
>> +  EFI_MAC_ADDRESS Mac;
>> +  EFI_STATUS Status;
>> +  HISI_BOARD_NIC_PROTOCOL *OemNic = NULL;
>> +
>> +  Status = gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (VOID **)&OemNic);
>> +  if(EFI_ERROR(Status))
>> +  {
>> +    DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FUNCTION__, __LINE__, Status));
>> +    return Status;
>> +  }
>> +
>> +  Status = OemNic->GetMac(&Mac, MacNextID);
>> +  if(EFI_ERROR(Status))
>> +  {
>> +    DEBUG((EFI_D_ERROR, "[%a]:[%dL] GetMac failed %r\n", __FUNCTION__, __LINE__, Status));
>> +    return Status;
>> +  }
>> +
>> +  CopyMem (MacBuffer, &Mac, 6);
>> +  DEBUG((EFI_D_ERROR, "Port %d MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
>> +        MacNextID,
>> +        MacBuffer[0],
>> +        MacBuffer[1],
>> +        MacBuffer[2],
>> +        MacBuffer[3],
>> +        MacBuffer[4],
>> +        MacBuffer[5]
>> +        ));
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +EFI_STATUS GetSasAddress (
>> +  IN UINT8        Index,
>> +  IN OUT UINT8    *SasAddrBuffer
>> +  )
>> +{
>> +  if (SasAddrBuffer == NULL) {
>> +      return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  SasAddrBuffer[0] = 0x50;
>> +  SasAddrBuffer[1] = 0x01;
>> +  SasAddrBuffer[2] = 0x88;
>> +  SasAddrBuffer[3] = 0x20;
>> +  SasAddrBuffer[4] = 0x16;
>> +  SasAddrBuffer[5] = 0x00;
>> +  SasAddrBuffer[6] = 0x00;
>> +  SasAddrBuffer[7] = Index;
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +EFI_STATUS _SearchReplacePackageAddress(
>> +  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>> +  IN EFI_ACPI_HANDLE        ChildHandle,
>> +  IN UINTN                  Level,
>> +  IN OUT BOOLEAN            *Found,
>> +  IN UINTN                  DevNextID,
>> +  IN DSDT_DEVICE_TYPE       FoundDev
>> +  )
>> +{
>> +  // ASL template for ethernet driver:
>> +/*
>> + *   Name (_DSD, Package () {
>> + *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>> + *   Package () {
>> + *     Package (2) {"mac-address", Package (6) { 00, 11, 22, 33, 44, 55 }}
>> + *     Package (2) {"phy-channel", 0},
>> + *     Package (2) {"phy-mode", "rgmii"},
>> + *     Package (2) {"max-transfer-unit", 0x5dc},   // MTU of 1500
>> + *     Package (2) {"max-speed", 0x3e8},            // 1000 Mbps
>> + *   }
>> + * })
>> + */
>> +  EFI_STATUS          Status;
>> +  EFI_ACPI_DATA_TYPE  DataType;
>> +  CONST UINT8         *Data;
>> +  CONST VOID          *Buffer;
>> +  UINTN               DataSize;
>> +  UINTN               Count;
>> +  EFI_ACPI_HANDLE     CurrentHandle;
>> +  EFI_ACPI_HANDLE     NextHandle;
>> +  EFI_ACPI_HANDLE     Level1Handle;
>> +  UINT8               *AddressBuffer;
>> +  UINT8               AddressByte = 0;
>> +
>> +  DBG("In Level:%d\n", Level);
>> +  Level1Handle = NULL;
>> +  Status = EFI_SUCCESS;
>> +  for (CurrentHandle = NULL; ;) {
>> +    Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>> +    if (Level == 1) {
>> +      Level1Handle = CurrentHandle;
>> +    }
>> +    if (Level != 3 && (EFI_ERROR(Status) || CurrentHandle == NULL))
>> +       break;
>> +
>> +    Status = AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataType, &Buffer, &DataSize);
>> +    Data = Buffer;
>> +    DBG("_DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
>> +        DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>> +
>> +    if (Level < 2 && Data[0] != AML_PACKAGE_OP)
>> +      continue;
>> +
>> +    if (Level == 2 && Data[0] == AML_STRING_PREFIX) {
>> +      Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>> +      if (EFI_ERROR(Status))
>> +        break;
>> +
>> +      DBG("  _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X\n",
>> +              DataSize, Data[0], DataSize > 1 ? Data[1] : 0);
>> +
>> +      Data = Buffer;
>> +      if ((DataType != EFI_ACPI_DATA_TYPE_STRING) ||
>> +            ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) != 0) &&
>> +            (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) != 0))) {
>> +        ChildHandle = Level1Handle;
>> +        continue;
>> +      }
>> +
>> +      DBG("_DSD Key Type %d. Found address key\n", DataType);
>> +
>> +      //
>> +      // We found the node.
>> +      //
>> +      *Found = TRUE;
>> +      continue;
>> +    }
>> +
>> +    if (Level == 3 && *Found) {
>> +      AddressBuffer = AllocateZeroPool (ADDRESS_MAX_LEN);
>> +      if (AddressBuffer == NULL) {
>> +        DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FILE__, __LINE__));
>> +        return EFI_OUT_OF_RESOURCES;
>> +      }
>> +
>> +      switch (FoundDev) {
>> +        case DsdtDeviceLan:
>> +          //Update the MAC
>> +          Status = GetEnvMac (DevNextID, AddressBuffer);
>> +          AddressByte = 6;
>> +          break;
>> +        case DsdtDeviceSas:
>> +          //Update SAS Address.
>> +          Status = GetSasAddress (DevNextID, AddressBuffer);
>> +          AddressByte = 8;
>> +          break;
>> +        default:
>> +          Status = EFI_INVALID_PARAMETER;
>> +      }
>> +      if (EFI_ERROR (Status)) {
>> +        FreePool (AddressBuffer);
>> +        AddressBuffer = NULL;
>> +        break;
>> +      }
>> +
>> +      for (Count = 0; Count < AddressByte; Count++) {
>> +        Status = AcpiTableProtocol->GetOption(CurrentHandle, 1, &DataType, &Buffer, &DataSize);
>> +        if (EFI_ERROR(Status))
>> +          break;
>> +
>> +        Data = Buffer;
>> +        DBG("    _DSD Child Subnode Store Op Code 0x%02X 0x%02X %02X DataType 0x%X\n",
>> +            DataSize, Data[0], DataSize > 1 ? Data[1] : 0, DataType);
>> +
>> +        if (DataType != EFI_ACPI_DATA_TYPE_UINT)
>> +          break;
>> +
>> +        // only need one byte.
>> +        // FIXME: Assume the CPU is little endian
>> +        Status = AcpiTableProtocol->SetOption (CurrentHandle, 1, AddressBuffer + Count, sizeof(UINT8));
>> +        if (EFI_ERROR(Status))
>> +          break;
>> +        Status = AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandle);
>> +        if (EFI_ERROR(Status) || CurrentHandle == NULL)
>> +          break;
>> +      }
>> +      FreePool (AddressBuffer);
>> +      AddressBuffer = NULL;
>> +      break;
>> +    }
>> +
>> +    if (Level > 3)
>> +      break;
>> +
>> +    //Search next package
>> +    AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle);
>> +    Status = _SearchReplacePackageAddress(
>> +               AcpiTableProtocol,
>> +               NextHandle,
>> +               Level + 1,
>> +               Found,
>> +               DevNextID,
>> +               FoundDev);
>> +    AcpiTableProtocol->Close(NextHandle);
>> +    if (!EFI_ERROR(Status))
>> +      break;
>> +  }
>> +
>> +  return Status;
>> +}
>> +
>> +EFI_STATUS SearchReplacePackageAddress(
>> +  IN EFI_ACPI_SDT_PROTOCOL  *AcpiTableProtocol,
>> +  IN EFI_ACPI_HANDLE        ChildHandle,
>> +  IN UINTN                  DevNextID,
>> +  IN DSDT_DEVICE_TYPE       FoundDev
>> +  )
>> +{
>> +  BOOLEAN Found = FALSE;
>> +  UINTN Level = 0;
>> +
>> +  return _SearchReplacePackageAddress(AcpiTableProtocol, ChildHandle, Level,
>> +                                      &Found, DevNextID, FoundDev);
>> +}
>> +
>> +EFI_STATUS
>> +GetDeviceInfo (
>> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>> +  EFI_ACPI_HANDLE         ChildHandle,
>> +  UINTN                   *DevID,
>> +  DSDT_DEVICE_TYPE        *FoundDev
>> +  )
>> +{
>> +  EFI_STATUS Status;
>> +  EFI_ACPI_DATA_TYPE  DataType;
>> +  CHAR8               Data[5];
>> +  CONST VOID          *Buffer;
>> +  UINTN               DataSize;
>> +
>> +  // Get NameString
>> +  Status = AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType, &Buffer, &DataSize);
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUNCTION__, __LINE__, Status));
>> +    return Status;
>> +  }
>> +
>> +  CopyMem (Data, Buffer, 4);
>> +  DBG("Size %p Data %02x %02x %02x %02x\n", DataSize, Data[0], Data[1], Data[2], Data[3]);
>> +
>> +  Data[4] = '\0';
>> +  if ((DataSize != 4) ||
>> +    (Data[3] > '9' || Data[3] < '0')) {
>> +    DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", Data));
>> +    return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  if (AsciiStrnCmp ("ETH", Data, 3) == 0) {
>> +    *FoundDev = DsdtDeviceLan;
>> +  } else if (AsciiStrnCmp ("SAS", Data, 3) == 0) {
>> +    *FoundDev = DsdtDeviceSas;
>> +  } else {
>> +    DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SASn\n",
>> +            __FUNCTION__, __LINE__, Data));
>> +    return EFI_INVALID_PARAMETER;
>> +  }
>> +
>> +  *DevID = Data[3] - '0';
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +EFI_STATUS ProcessDSDTDevice (
>> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> +  EFI_ACPI_HANDLE ChildHandle)
>> +{
>> +  EFI_STATUS          Status;
>> +  EFI_ACPI_DATA_TYPE  DataType;
>> +  CONST UINT8         *Data;
>> +  CONST VOID          *Buffer;
>> +  UINTN               DataSize;
>> +  EFI_ACPI_HANDLE     DevHandle;
>> +  DSDT_DEVICE_TYPE    FoundDev = DsdtDeviceUnknown;
>> +  UINTN               DevNextID;
>> +  BOOLEAN             HisiAcpiDevNotFound;
>> +  UINTN               Index;
>> +
>> +  Status = AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, &Buffer, &DataSize);
>> +  if (EFI_ERROR(Status))
>> +    return EFI_SUCCESS;
>> +
>> +  Data = Buffer;
>> +  //
>> +  // Skip all non-device type
>> +  //
>> +  if (DataSize != 2 || Data[0] != AML_EXT_OP || Data[1] != AML_EXT_DEVICE_OP)
>> +    return EFI_SUCCESS;
>> +
>> +  //
>> +  // Walk the device type node
>> +  //
>> +  for (DevHandle = NULL; ; ) {
>> +    Status = AcpiTableProtocol->GetChild(ChildHandle, &DevHandle);
>> +    if (EFI_ERROR(Status) || DevHandle == NULL)
>> +      break;
>> +
>> +    //
>> +    // Search for _HID with Device ID
>> +    //
>> +    Status = AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, &Buffer, &DataSize);
>> +    if (EFI_ERROR(Status))
>> +      break;
>> +
>> +    Data = Buffer;
>> +    DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : 0);
>> +    if (DataSize == 1 && Data[0] == AML_NAME_OP) {
>> +      Status = AcpiTableProtocol->GetOption(DevHandle, 1, &DataType, &Buffer, &DataSize);
>> +      if (EFI_ERROR(Status))
>> +        break;
>> +
>> +      Data = Buffer;
>> +      if (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING) {
>> +        if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) == 0) {
>> +          EFI_ACPI_HANDLE ValueHandle;
>> +
>> +          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
>> +          if (EFI_ERROR(Status))
>> +            break;
>> +
>> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
>> +            continue;
>> +
>> +          AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle);
>> +          Status = AcpiTableProtocol->GetOption(ValueHandle, 1, &DataType, &Buffer, &DataSize);
>> +
>> +          Data = Buffer;
>> +          DBG("[%a:%d] - _HID = %a\n", __FUNCTION__, __LINE__, Data);
>> +
>> +          if (EFI_ERROR(Status) ||
>> +              DataType != EFI_ACPI_DATA_TYPE_STRING) {
>> +            AcpiTableProtocol->Close (ValueHandle);
>> +            FoundDev = DsdtDeviceUnknown;
>> +            continue;
>> +          }
>> +
>> +          HisiAcpiDevNotFound = TRUE;
>> +          for (Index = 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Index++) {
>> +            if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) == 0) {
>> +              HisiAcpiDevNotFound = FALSE;
>> +              break;
>> +            }
>> +          }
>> +          if (HisiAcpiDevNotFound) {
>> +            AcpiTableProtocol->Close (ValueHandle);
>> +            FoundDev = DsdtDeviceUnknown;
>> +            continue;
>> +          }
>> +
>> +          DBG("Found device\n");
>> +          AcpiTableProtocol->Close(ValueHandle);
>> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>> +          if (EFI_ERROR (Status)) {
>> +            continue;
>> +          }
>> +        } else if ((FoundDev != DsdtDeviceUnknown) && AsciiStrnCmp((CHAR8 *) Data, "_DSD", 4) == 0) {
>> +          //
>> +          // Patch DSD data
>> +          //
>> +          EFI_ACPI_HANDLE    PkgHandle;
>> +          Status = AcpiTableProtocol->GetOption(DevHandle, 2, &DataType, &Buffer, &DataSize);
>> +          if (EFI_ERROR(Status))
>> +            break;
>> +
>> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD)
>> +            continue;
>> +
>> +          //
>> +          // Open package data
>> +          //
>> +          AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle);
>> +          Status = AcpiTableProtocol->GetOption(PkgHandle, 0, &DataType, &Buffer, &DataSize);
>> +
>> +          Data = Buffer;
>> +          DBG("_DSD Subnode Store Op Code 0x%02X %02X\n",
>> +                Data[0], DataSize > 1 ? Data[1] : 0);
>> +
>> +          //
>> +          // Walk the _DSD node
>> +          //
>> +          if (DataSize == 1 && Data[0] == AML_PACKAGE_OP) {
>> +            Status = SearchReplacePackageAddress (AcpiTableProtocol, PkgHandle, DevNextID, FoundDev);
>> +          }
>> +
>> +          AcpiTableProtocol->Close(PkgHandle);
>> +        } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) == 0) {
>> +          Status = AcpiTableProtocol->GetOption (DevHandle, 2, &DataType, &Buffer, &DataSize);
>> +          if (EFI_ERROR (Status)) {
>> +            break;
>> +          }
>> +
>> +          if (DataType != EFI_ACPI_DATA_TYPE_CHILD) {
>> +            continue;
>> +          }
>> +
>> +          Status = GetDeviceInfo (AcpiTableProtocol, ChildHandle, &DevNextID, &FoundDev);
>> +
>> +          if (EFI_ERROR (Status)) {
>> +            continue;
>> +          }
>> +        }
>> +      }
>> +    } else if ((DataSize == 2) && (Data[0] == AML_EXT_OP) && (Data[1] == AML_EXT_DEVICE_OP)) {
>> +      ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>> +    }
>> +  }
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +
>> +BOOLEAN
>> +IsSbScope (
>> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol,
>> +  EFI_ACPI_HANDLE         ChildHandle
>> +  )
>> +{
>> +  EFI_STATUS          Status;
>> +  EFI_ACPI_DATA_TYPE  DataType;
>> +  CONST UINT8         *Data;
>> +  CONST VOID          *Buffer;
>> +  UINTN               DataSize;
>> +
>> +  Status = AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType, &Buffer, &DataSize);
>> +  if (EFI_ERROR(Status)) return FALSE;
>> +
>> +  Data = Buffer;
>> +  if (DataSize != 1 || Data[0] != AML_SCOPE_OP) {
>> +    return FALSE;
>> +  }
>> +
>> +  return TRUE;
>> +}
>> +
>> +EFI_STATUS ProcessDSDTChild(
>> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> +  EFI_ACPI_HANDLE ChildHandle)
>> +{
>> +  EFI_STATUS          Status;
>> +  EFI_ACPI_HANDLE     DevHandle;
>> +
>> +  // Check Scope(_SB) at first
>> +  if (!IsSbScope (AcpiTableProtocol, ChildHandle)) {
>> +    return ProcessDSDTDevice (AcpiTableProtocol, ChildHandle);
>> +  }
>> +
>> +  for (DevHandle = NULL; ; ) {
>> +    Status = AcpiTableProtocol->GetChild (ChildHandle, &DevHandle);
>> +    if (EFI_ERROR(Status) || DevHandle == NULL) {
>> +      break;
>> +    }
>> +
>> +    ProcessDSDTDevice (AcpiTableProtocol, DevHandle);
>> +  }
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +static EFI_STATUS ProcessDSDT(
>> +  EFI_ACPI_SDT_PROTOCOL *AcpiTableProtocol,
>> +  EFI_ACPI_HANDLE TableHandle)
>> +{
>> +  EFI_STATUS              Status;
>> +  EFI_ACPI_HANDLE         ChildHandle;
>> +  //
>> +  // Parse table for device type
>> +  DBG ("[%a:%d] - TableHandle=%p\n", __FUNCTION__, __LINE__, TableHandle);
>> +  for (ChildHandle = NULL; ; ) {
>> +    Status = AcpiTableProtocol->GetChild(TableHandle, &ChildHandle);
>> +    DBG ("[%a:%d] - Child=%p, %r\n", __FUNCTION__, __LINE__, ChildHandle, Status);
>> +    if (EFI_ERROR(Status))
>> +      break;
>> +    if (ChildHandle == NULL)
>> +      break;
>> +
>> +    ProcessDSDTChild(AcpiTableProtocol, ChildHandle);
>> +  }
>> +
>> +  return EFI_SUCCESS;
>> +}
>> +
>> +STATIC
>> +VOID
>> +AcpiCheckSum (
>> +  IN OUT  EFI_ACPI_SDT_HEADER *Table
>> +  )
>> +{
>> +  UINTN ChecksumOffset;
>> +  UINT8 *Buffer;
>> +
>> +  ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
>> +  Buffer = (UINT8 *)Table;
>> +
>> +  //
>> +  // set checksum to 0 first
>> +  //
>> +  Buffer[ChecksumOffset] = 0;
>> +
>> +  //
>> +  // Update checksum value
>> +  //
>> +  Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Table->Length);
>> +}
>> +
>> +EFI_STATUS UpdateAcpiDsdtTable(void)
>> +{
>> +  EFI_STATUS              Status;
>> +  EFI_ACPI_SDT_PROTOCOL   *AcpiTableProtocol;
>> +  EFI_ACPI_SDT_HEADER     *Table;
>> +  EFI_ACPI_TABLE_VERSION  TableVersion;
>> +  UINTN                   TableKey;
>> +  EFI_ACPI_HANDLE         TableHandle;
>> +  UINTN                   i;
>> +
>> +  DEBUG ((EFI_D_ERROR, "Updating Ethernet MAC in ACPI DSDT...\n"));
>> +
>> +  //
>> +  // Find the AcpiTable protocol
>> +  Status = gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOID**) &AcpiTableProtocol);
>> +  if (EFI_ERROR(Status)) {
>> +    DBG("Unable to locate ACPI table protocol\n");
>> +    return EFI_SUCCESS;
>> +  }
>> +
>> +  //
>> +  // Search for DSDT Table
>> +  for (i = 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) {
>> +    Status = AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersion, &TableKey);
>> +    if (EFI_ERROR(Status))
>> +      break;
>> +    if (Table->Signature != DSDT_SIGNATURE)
>> +      continue;
>> +
>> +    Status = AcpiTableProtocol->OpenSdt(TableKey, &TableHandle);
>> +    if (EFI_ERROR(Status))
>> +      break;
>> +
>> +    ProcessDSDT(AcpiTableProtocol, TableHandle);
>> +
>> +    AcpiTableProtocol->Close(TableHandle);
>> +    AcpiCheckSum (Table);
>> +  }
>> +
>> +  return EFI_SUCCESS;
>> +}
>> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
>> new file mode 100644
>> index 0000000..a7e1eed
>> --- /dev/null
>> +++ b/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
>> @@ -0,0 +1,16 @@
>> +/*
>> + *
>> + * Copyright (c) 2014, Applied Micro Circuits Corporation
>> + * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> + * Copyright (c) 2015, Linaro Limited. All rights reserved.
>> + * Author: Loc Ho <lho@apm.com>
>> + *
>> + * SPDX-License-Identifier: BSD-2-Clause-Patent
>> + */
>> +#ifndef _ETH_MAC_H_
>> +#define _ETH_MAC_H_
>> +
>> +EFI_STATUS UpdateAcpiDsdtTable (VOID);
>> +
>> +#endif
>> +
>> -- 
>> 2.8.1
>>
> 
> .
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC edk2-platforms v1 0/3] Improve D0x
  2020-05-26 18:09 ` [RFC edk2-platforms v1 0/3] Improve D0x Leif Lindholm
@ 2020-05-27 14:31   ` Ming Huang
  0 siblings, 0 replies; 12+ messages in thread
From: Ming Huang @ 2020-05-27 14:31 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel, ard.biesheuvel, lidongzhan, songdongkuang, wanghuiqiang,
	qiuliangen



在 2020/5/27 2:09, Leif Lindholm 写道:
> On trying to build the resulting output, I found the build breaks with
> /work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:
> In function ‘FlashFvbInitialize’:
> /work/git/edk2-platforms/Silicon/Hisilicon/Drivers/FlashFvbDxe/FlashFvbDxe.c:1231:20:
> error: ‘gEfiEventVirtualAddressChangeGuid’ undeclared (first use in
> this function); did you mean ‘EfiSetVirtualAddressMap’?
>                    &gEfiEventVirtualAddressChangeGuid,
> 		                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 				                           EfiSetVirtualAddressMap
> 
> The error would appear identical to that resolved by
> commit a327627dd3f9edc113b1de6d897222d0517834db
> 
> Could you please provide a corresponding fix?

Ok, I will add a patch in v2.

Thanks,
Ming

> 
> Best Regards,
> 
> Leif
> 
> On Thu, May 21, 2020 at 22:43:01 +0800, Ming Huang wrote:
>> Main Changes:
>> Add update sas address feature in AcpiPlatformDxe.
>>
>> Ming Huang (3):
>>   Silicon/Hisilicon: Change updating dsdt in ready to boot event
>>   Silicon/Hisilicon/Acpi: Add update sas address feature
>>   Silicon/Hisilicon: Rename EthMac files
>>
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |  62 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   8 +-
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c            | 500 ----------------
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h            |  16 -
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c        | 612 ++++++++++++++++++++
>>  Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h        |  16 +
>>  6 files changed, 689 insertions(+), 525 deletions(-)
>>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c
>>  delete mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.h
>>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.c
>>  create mode 100644 Silicon/Hisilicon/Drivers/AcpiPlatformDxe/UpdateDsdt.h
>>
>> -- 
>> 2.8.1
>>
> 
> .
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-05-27 14:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-21 14:43 [RFC edk2-platforms v1 0/3] Improve D0x Ming Huang
2020-05-21 14:43 ` [RFC edk2-platforms v1 1/3] Silicon/Hisilicon: Change updating dsdt in ready to boot event Ming Huang
2020-05-26 17:40   ` Leif Lindholm
2020-05-27 11:38     ` Ming Huang
2020-05-21 14:43 ` [RFC edk2-platforms v1 2/3] Silicon/Hisilicon/Acpi: Add update sas address feature Ming Huang
2020-05-26 18:49   ` Leif Lindholm
2020-05-27 14:21     ` Ming Huang
2020-05-21 14:43 ` [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files Ming Huang
2020-05-26 18:50   ` Leif Lindholm
2020-05-27 14:22     ` Ming Huang
2020-05-26 18:09 ` [RFC edk2-platforms v1 0/3] Improve D0x Leif Lindholm
2020-05-27 14:31   ` Ming Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox