From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from huawei.com (huawei.com [45.249.212.191]) by mx.groups.io with SMTP id smtpd.web12.7068.1590589345314784425 for ; Wed, 27 May 2020 07:22:26 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.191, mailfrom: huangming23@huawei.com) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DEA74CCA90CABF2C98C7; Wed, 27 May 2020 22:22:22 +0800 (CST) Received: from [127.0.0.1] (10.78.51.60) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Wed, 27 May 2020 22:22:12 +0800 Subject: Re: [RFC edk2-platforms v1 3/3] Silicon/Hisilicon: Rename EthMac files To: Leif Lindholm CC: , , , , , References: <1590072184-16219-1-git-send-email-huangming23@huawei.com> <1590072184-16219-4-git-send-email-huangming23@huawei.com> <20200526185049.GQ1923@vanye> From: Ming Huang Message-ID: <81567246-c0b6-db12-071e-3fea8ff01e31@huawei.com> Date: Wed, 27 May 2020 22:22:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20200526185049.GQ1923@vanye> X-Originating-IP: [10.78.51.60] X-CFilter-Loop: Reflected Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: quoted-printable =D4=DA 2020/5/27 2:50, Leif Lindholm =D0=B4=B5=C0: > 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 >> --- >> 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 >> #include >> #include >> -#include "EthMac.h" >> +#include "UpdateDsdt.h" >> =20 >> EFI_EVENT mUpdateAcpiDsdtTableEvent; >> =20 >> 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 reserve= d.
>> -# Copyright (c) 2015, Hisilicon Limited. All rights reserved.
>> -# Copyright (c) 2015, Linaro Limited. All rights reserved.
>> +# Copyright (c) 2014 - 2020, Applied Micro Curcuit Corp. All rights = reserved.
>> +# Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.=
>> +# Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved. >=20 > Same comment on copyright as on 1/3 and 2/3. Modify it in v2. Thanks, Ming >=20 > / > Leif >=20 >> # SPDX-License-Identifier: BSD-2-Clause-Patent >> # >> ## >> @@ -18,7 +18,7 @@ >> =20 >> [Sources] >> AcpiPlatform.c >> - EthMac.c >> + UpdateDsdt.c >> =20 >> [Packages] >> MdePkg/MdePkg.dec >> diff --git a/Silicon/Hisilicon/Drivers/AcpiPlatformDxe/EthMac.c b/Sili= con/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 r= ights reserved.
>> - Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<= BR> >> - Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
>> - SPDX-License-Identifier: BSD-2-Clause-Patent >> - >> - This driver is called to initialize the FW part of the PHY in prepa= ration >> - for the OS. >> - >> -**/ >> - >> -#include >> -#include >> -#include >> -#include >> - >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> -#include >> - >> -#include >> - >> -// 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[] =3D {"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 =3D NULL; >> - >> - Status =3D gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (V= OID **)&OemNic); >> - if(EFI_ERROR(Status)) >> - { >> - DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FU= NCTION__, __LINE__, Status)); >> - return Status; >> - } >> - >> - Status =3D 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 =3D=3D NULL) { >> - return EFI_INVALID_PARAMETER; >> - } >> - >> - SasAddrBuffer[0] =3D 0x50; >> - SasAddrBuffer[1] =3D 0x01; >> - SasAddrBuffer[2] =3D 0x88; >> - SasAddrBuffer[3] =3D 0x20; >> - SasAddrBuffer[4] =3D 0x16; >> - SasAddrBuffer[5] =3D 0x00; >> - SasAddrBuffer[6] =3D 0x00; >> - SasAddrBuffer[7] =3D 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 =3D 0; >> - >> - DBG("In Level:%d\n", Level); >> - Level1Handle =3D NULL; >> - Status =3D EFI_SUCCESS; >> - for (CurrentHandle =3D NULL; ;) { >> - Status =3D AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandl= e); >> - if (Level =3D=3D 1) { >> - Level1Handle =3D CurrentHandle; >> - } >> - if (Level !=3D 3 && (EFI_ERROR(Status) || CurrentHandle =3D=3D NU= LL)) >> - break; >> - >> - Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataTy= pe, &Buffer, &DataSize); >> - Data =3D 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] !=3D AML_PACKAGE_OP) >> - continue; >> - >> - if (Level =3D=3D 2 && Data[0] =3D=3D AML_STRING_PREFIX) { >> - Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 1, &Data= Type, &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 =3D Buffer; >> - if ((DataType !=3D EFI_ACPI_DATA_TYPE_STRING) || >> - ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) !=3D 0) = && >> - (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) !=3D 0)))= { >> - ChildHandle =3D Level1Handle; >> - continue; >> - } >> - >> - DBG("_DSD Key Type %d. Found address key\n", DataType); >> - >> - // >> - // We found the node. >> - // >> - *Found =3D TRUE; >> - continue; >> - } >> - >> - if (Level =3D=3D 3 && *Found) { >> - AddressBuffer =3D AllocateZeroPool (ADDRESS_MAX_LEN); >> - if (AddressBuffer =3D=3D NULL) { >> - DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FIL= E__, __LINE__)); >> - return EFI_OUT_OF_RESOURCES; >> - } >> - >> - switch (FoundDev) { >> - case DsdtDeviceLan: >> - //Update the MAC >> - Status =3D GetEnvMac (DevNextID, AddressBuffer); >> - AddressByte =3D 6; >> - break; >> - case DsdtDeviceSas: >> - //Update SAS Address. >> - Status =3D GetSasAddress (DevNextID, AddressBuffer); >> - AddressByte =3D 8; >> - break; >> - default: >> - Status =3D EFI_INVALID_PARAMETER; >> - } >> - if (EFI_ERROR (Status)) { >> - FreePool (AddressBuffer); >> - AddressBuffer =3D NULL; >> - break; >> - } >> - >> - for (Count =3D 0; Count < AddressByte; Count++) { >> - Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 1, &Da= taType, &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - break; >> - >> - Data =3D 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 !=3D EFI_ACPI_DATA_TYPE_UINT) >> - break; >> - >> - // only need one byte. >> - // FIXME: Assume the CPU is little endian >> - Status =3D AcpiTableProtocol->SetOption (CurrentHandle, 1, Ad= dressBuffer + Count, sizeof(UINT8)); >> - if (EFI_ERROR(Status)) >> - break; >> - Status =3D AcpiTableProtocol->GetChild(ChildHandle, &CurrentH= andle); >> - if (EFI_ERROR(Status) || CurrentHandle =3D=3D NULL) >> - break; >> - } >> - FreePool (AddressBuffer); >> - AddressBuffer =3D NULL; >> - break; >> - } >> - >> - if (Level > 3) >> - break; >> - >> - //Search next package >> - AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle); >> - Status =3D _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 =3D FALSE; >> - UINTN Level =3D 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 =3D AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType,= &Buffer, &DataSize); >> - if (EFI_ERROR (Status)) { >> - DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUN= CTION__, __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] =3D '\0'; >> - if ((DataSize !=3D 4) || >> - (Data[3] > '9' || Data[3] < '0')) { >> - DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", D= ata)); >> - return EFI_INVALID_PARAMETER; >> - } >> - >> - if (AsciiStrnCmp ("ETH", Data, 3) =3D=3D 0) { >> - *FoundDev =3D DsdtDeviceLan; >> - } else if (AsciiStrnCmp ("SAS", Data, 3) =3D=3D 0) { >> - *FoundDev =3D DsdtDeviceSas; >> - } else { >> - DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SA= Sn\n", >> - __FUNCTION__, __LINE__, Data)); >> - return EFI_INVALID_PARAMETER; >> - } >> - >> - *DevID =3D 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 =3D DsdtDeviceUnknown; >> - UINTN DevNextID; >> - BOOLEAN HisiAcpiDevNotFound; >> - UINTN Index; >> - >> - Status =3D AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, = &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - return EFI_SUCCESS; >> - >> - Data =3D Buffer; >> - // >> - // Skip all non-device type >> - // >> - if (DataSize !=3D 2 || Data[0] !=3D AML_EXT_OP || Data[1] !=3D AML_= EXT_DEVICE_OP) >> - return EFI_SUCCESS; >> - >> - // >> - // Walk the device type node >> - // >> - for (DevHandle =3D NULL; ; ) { >> - Status =3D AcpiTableProtocol->GetChild(ChildHandle, &DevHandle); >> - if (EFI_ERROR(Status) || DevHandle =3D=3D NULL) >> - break; >> - >> - // >> - // Search for _HID with Device ID >> - // >> - Status =3D AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, = &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - break; >> - >> - Data =3D Buffer; >> - DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : = 0); >> - if (DataSize =3D=3D 1 && Data[0] =3D=3D AML_NAME_OP) { >> - Status =3D AcpiTableProtocol->GetOption(DevHandle, 1, &DataType= , &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - break; >> - >> - Data =3D Buffer; >> - if (DataType =3D=3D EFI_ACPI_DATA_TYPE_NAME_STRING) { >> - if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) =3D=3D 0) { >> - EFI_ACPI_HANDLE ValueHandle; >> - >> - Status =3D AcpiTableProtocol->GetOption(DevHandle, 2, &Data= Type, &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - break; >> - >> - if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) >> - continue; >> - >> - AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle); >> - Status =3D AcpiTableProtocol->GetOption(ValueHandle, 1, &Da= taType, &Buffer, &DataSize); >> - >> - Data =3D Buffer; >> - DBG("[%a:%d] - _HID =3D %a\n", __FUNCTION__, __LINE__, Data= ); >> - >> - if (EFI_ERROR(Status) || >> - DataType !=3D EFI_ACPI_DATA_TYPE_STRING) { >> - AcpiTableProtocol->Close (ValueHandle); >> - FoundDev =3D DsdtDeviceUnknown; >> - continue; >> - } >> - >> - HisiAcpiDevNotFound =3D TRUE; >> - for (Index =3D 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Inde= x++) { >> - if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) =3D= =3D 0) { >> - HisiAcpiDevNotFound =3D FALSE; >> - break; >> - } >> - } >> - if (HisiAcpiDevNotFound) { >> - AcpiTableProtocol->Close (ValueHandle); >> - FoundDev =3D DsdtDeviceUnknown; >> - continue; >> - } >> - >> - DBG("Found device\n"); >> - AcpiTableProtocol->Close(ValueHandle); >> - Status =3D GetDeviceInfo (AcpiTableProtocol, ChildHandle, &= DevNextID, &FoundDev); >> - if (EFI_ERROR (Status)) { >> - continue; >> - } >> - } else if ((FoundDev !=3D DsdtDeviceUnknown) && AsciiStrnCmp(= (CHAR8 *) Data, "_DSD", 4) =3D=3D 0) { >> - // >> - // Patch DSD data >> - // >> - EFI_ACPI_HANDLE PkgHandle; >> - Status =3D AcpiTableProtocol->GetOption(DevHandle, 2, &Data= Type, &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) >> - break; >> - >> - if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) >> - continue; >> - >> - // >> - // Open package data >> - // >> - AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle); >> - Status =3D AcpiTableProtocol->GetOption(PkgHandle, 0, &Data= Type, &Buffer, &DataSize); >> - >> - Data =3D Buffer; >> - DBG("_DSD Subnode Store Op Code 0x%02X %02X\n", >> - Data[0], DataSize > 1 ? Data[1] : 0); >> - >> - // >> - // Walk the _DSD node >> - // >> - if (DataSize =3D=3D 1 && Data[0] =3D=3D AML_PACKAGE_OP) { >> - Status =3D SearchReplacePackageAddress (AcpiTableProtocol= , PkgHandle, DevNextID, FoundDev); >> - } >> - >> - AcpiTableProtocol->Close(PkgHandle); >> - } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) =3D=3D 0)= { >> - Status =3D AcpiTableProtocol->GetOption (DevHandle, 2, &Dat= aType, &Buffer, &DataSize); >> - if (EFI_ERROR (Status)) { >> - break; >> - } >> - >> - if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) { >> - continue; >> - } >> - >> - Status =3D GetDeviceInfo (AcpiTableProtocol, ChildHandle, &= DevNextID, &FoundDev); >> - >> - if (EFI_ERROR (Status)) { >> - continue; >> - } >> - } >> - } >> - } else if ((DataSize =3D=3D 2) && (Data[0] =3D=3D AML_EXT_OP) && = (Data[1] =3D=3D 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 =3D AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType,= &Buffer, &DataSize); >> - if (EFI_ERROR(Status)) return FALSE; >> - >> - Data =3D Buffer; >> - if (DataSize !=3D 1 || Data[0] !=3D 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 =3D NULL; ; ) { >> - Status =3D AcpiTableProtocol->GetChild (ChildHandle, &DevHandle); >> - if (EFI_ERROR(Status) || DevHandle =3D=3D 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=3D%p\n", __FUNCTION__, __LINE__, TableH= andle); >> - for (ChildHandle =3D NULL; ; ) { >> - Status =3D AcpiTableProtocol->GetChild(TableHandle, &ChildHandle)= ; >> - DBG ("[%a:%d] - Child=3D%p, %r\n", __FUNCTION__, __LINE__, ChildH= andle, Status); >> - if (EFI_ERROR(Status)) >> - break; >> - if (ChildHandle =3D=3D NULL) >> - break; >> - >> - ProcessDSDTChild(AcpiTableProtocol, ChildHandle); >> - } >> - >> - return EFI_SUCCESS; >> -} >> - >> -STATIC >> -VOID >> -AcpiCheckSum ( >> - IN OUT EFI_ACPI_SDT_HEADER *Table >> - ) >> -{ >> - UINTN ChecksumOffset; >> - UINT8 *Buffer; >> - >> - ChecksumOffset =3D OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum= ); >> - Buffer =3D (UINT8 *)Table; >> - >> - // >> - // set checksum to 0 first >> - // >> - Buffer[ChecksumOffset] =3D 0; >> - >> - // >> - // Update checksum value >> - // >> - Buffer[ChecksumOffset] =3D CalculateCheckSum8 (Buffer, Table->Lengt= h); >> -} >> - >> -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 =3D gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOI= D**) &AcpiTableProtocol); >> - if (EFI_ERROR(Status)) { >> - DBG("Unable to locate ACPI table protocol\n"); >> - return EFI_SUCCESS; >> - } >> - >> - // >> - // Search for DSDT Table >> - for (i =3D 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) { >> - Status =3D AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersi= on, &TableKey); >> - if (EFI_ERROR(Status)) >> - break; >> - if (Table->Signature !=3D DSDT_SIGNATURE) >> - continue; >> - >> - Status =3D 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/Sili= con/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 >> - * >> - * 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 r= ights reserved.
>> + Copyright (c) 2015 - 2020, Hisilicon Limited. All rights reserved.<= BR> >> + Copyright (c) 2015 - 2020, Linaro Limited. All rights reserved.
>> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> + This driver is called to initialize the FW part of the PHY in prepa= ration >> + for the OS. >> + >> +**/ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include >> + >> +// 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[] =3D {"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 =3D NULL; >> + >> + Status =3D gBS->LocateProtocol(&gHisiBoardNicProtocolGuid, NULL, (V= OID **)&OemNic); >> + if(EFI_ERROR(Status)) >> + { >> + DEBUG((EFI_D_ERROR, "[%a]:[%dL] LocateProtocol failed %r\n", __FU= NCTION__, __LINE__, Status)); >> + return Status; >> + } >> + >> + Status =3D 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 =3D=3D NULL) { >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + SasAddrBuffer[0] =3D 0x50; >> + SasAddrBuffer[1] =3D 0x01; >> + SasAddrBuffer[2] =3D 0x88; >> + SasAddrBuffer[3] =3D 0x20; >> + SasAddrBuffer[4] =3D 0x16; >> + SasAddrBuffer[5] =3D 0x00; >> + SasAddrBuffer[6] =3D 0x00; >> + SasAddrBuffer[7] =3D 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 =3D 0; >> + >> + DBG("In Level:%d\n", Level); >> + Level1Handle =3D NULL; >> + Status =3D EFI_SUCCESS; >> + for (CurrentHandle =3D NULL; ;) { >> + Status =3D AcpiTableProtocol->GetChild(ChildHandle, &CurrentHandl= e); >> + if (Level =3D=3D 1) { >> + Level1Handle =3D CurrentHandle; >> + } >> + if (Level !=3D 3 && (EFI_ERROR(Status) || CurrentHandle =3D=3D NU= LL)) >> + break; >> + >> + Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 0, &DataTy= pe, &Buffer, &DataSize); >> + Data =3D 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] !=3D AML_PACKAGE_OP) >> + continue; >> + >> + if (Level =3D=3D 2 && Data[0] =3D=3D AML_STRING_PREFIX) { >> + Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 1, &Data= Type, &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 =3D Buffer; >> + if ((DataType !=3D EFI_ACPI_DATA_TYPE_STRING) || >> + ((AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_MAC_KEY) !=3D 0) = && >> + (AsciiStrCmp ((CHAR8 *) Data, ACPI_ETH_SAS_KEY) !=3D 0)))= { >> + ChildHandle =3D Level1Handle; >> + continue; >> + } >> + >> + DBG("_DSD Key Type %d. Found address key\n", DataType); >> + >> + // >> + // We found the node. >> + // >> + *Found =3D TRUE; >> + continue; >> + } >> + >> + if (Level =3D=3D 3 && *Found) { >> + AddressBuffer =3D AllocateZeroPool (ADDRESS_MAX_LEN); >> + if (AddressBuffer =3D=3D NULL) { >> + DEBUG ((DEBUG_ERROR, "%a:%d AllocateZeroPool failed\n", __FIL= E__, __LINE__)); >> + return EFI_OUT_OF_RESOURCES; >> + } >> + >> + switch (FoundDev) { >> + case DsdtDeviceLan: >> + //Update the MAC >> + Status =3D GetEnvMac (DevNextID, AddressBuffer); >> + AddressByte =3D 6; >> + break; >> + case DsdtDeviceSas: >> + //Update SAS Address. >> + Status =3D GetSasAddress (DevNextID, AddressBuffer); >> + AddressByte =3D 8; >> + break; >> + default: >> + Status =3D EFI_INVALID_PARAMETER; >> + } >> + if (EFI_ERROR (Status)) { >> + FreePool (AddressBuffer); >> + AddressBuffer =3D NULL; >> + break; >> + } >> + >> + for (Count =3D 0; Count < AddressByte; Count++) { >> + Status =3D AcpiTableProtocol->GetOption(CurrentHandle, 1, &Da= taType, &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + break; >> + >> + Data =3D 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 !=3D EFI_ACPI_DATA_TYPE_UINT) >> + break; >> + >> + // only need one byte. >> + // FIXME: Assume the CPU is little endian >> + Status =3D AcpiTableProtocol->SetOption (CurrentHandle, 1, Ad= dressBuffer + Count, sizeof(UINT8)); >> + if (EFI_ERROR(Status)) >> + break; >> + Status =3D AcpiTableProtocol->GetChild(ChildHandle, &CurrentH= andle); >> + if (EFI_ERROR(Status) || CurrentHandle =3D=3D NULL) >> + break; >> + } >> + FreePool (AddressBuffer); >> + AddressBuffer =3D NULL; >> + break; >> + } >> + >> + if (Level > 3) >> + break; >> + >> + //Search next package >> + AcpiTableProtocol->Open((VOID *) Buffer, &NextHandle); >> + Status =3D _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 =3D FALSE; >> + UINTN Level =3D 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 =3D AcpiTableProtocol->GetOption (ChildHandle, 1, &DataType,= &Buffer, &DataSize); >> + if (EFI_ERROR (Status)) { >> + DEBUG ((EFI_D_ERROR, "[%a:%d] Get NameString failed: %r\n", __FUN= CTION__, __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] =3D '\0'; >> + if ((DataSize !=3D 4) || >> + (Data[3] > '9' || Data[3] < '0')) { >> + DEBUG ((DEBUG_ERROR, "The NameString %a is not ETHn or SASn\n", D= ata)); >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + if (AsciiStrnCmp ("ETH", Data, 3) =3D=3D 0) { >> + *FoundDev =3D DsdtDeviceLan; >> + } else if (AsciiStrnCmp ("SAS", Data, 3) =3D=3D 0) { >> + *FoundDev =3D DsdtDeviceSas; >> + } else { >> + DEBUG ((DEBUG_ERROR, "[%a:%d] The NameString %a is not ETHn or SA= Sn\n", >> + __FUNCTION__, __LINE__, Data)); >> + return EFI_INVALID_PARAMETER; >> + } >> + >> + *DevID =3D 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 =3D DsdtDeviceUnknown; >> + UINTN DevNextID; >> + BOOLEAN HisiAcpiDevNotFound; >> + UINTN Index; >> + >> + Status =3D AcpiTableProtocol->GetOption(ChildHandle, 0, &DataType, = &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + return EFI_SUCCESS; >> + >> + Data =3D Buffer; >> + // >> + // Skip all non-device type >> + // >> + if (DataSize !=3D 2 || Data[0] !=3D AML_EXT_OP || Data[1] !=3D AML_= EXT_DEVICE_OP) >> + return EFI_SUCCESS; >> + >> + // >> + // Walk the device type node >> + // >> + for (DevHandle =3D NULL; ; ) { >> + Status =3D AcpiTableProtocol->GetChild(ChildHandle, &DevHandle); >> + if (EFI_ERROR(Status) || DevHandle =3D=3D NULL) >> + break; >> + >> + // >> + // Search for _HID with Device ID >> + // >> + Status =3D AcpiTableProtocol->GetOption(DevHandle, 0, &DataType, = &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + break; >> + >> + Data =3D Buffer; >> + DBG("Data Type 0x%02X %02X\n", Data[0], DataSize > 1 ? Data[1] : = 0); >> + if (DataSize =3D=3D 1 && Data[0] =3D=3D AML_NAME_OP) { >> + Status =3D AcpiTableProtocol->GetOption(DevHandle, 1, &DataType= , &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + break; >> + >> + Data =3D Buffer; >> + if (DataType =3D=3D EFI_ACPI_DATA_TYPE_NAME_STRING) { >> + if (AsciiStrnCmp((CHAR8 *) Data, "_HID", 4) =3D=3D 0) { >> + EFI_ACPI_HANDLE ValueHandle; >> + >> + Status =3D AcpiTableProtocol->GetOption(DevHandle, 2, &Data= Type, &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + break; >> + >> + if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) >> + continue; >> + >> + AcpiTableProtocol->Open((VOID *) Buffer, &ValueHandle); >> + Status =3D AcpiTableProtocol->GetOption(ValueHandle, 1, &Da= taType, &Buffer, &DataSize); >> + >> + Data =3D Buffer; >> + DBG("[%a:%d] - _HID =3D %a\n", __FUNCTION__, __LINE__, Data= ); >> + >> + if (EFI_ERROR(Status) || >> + DataType !=3D EFI_ACPI_DATA_TYPE_STRING) { >> + AcpiTableProtocol->Close (ValueHandle); >> + FoundDev =3D DsdtDeviceUnknown; >> + continue; >> + } >> + >> + HisiAcpiDevNotFound =3D TRUE; >> + for (Index =3D 0; Index < ARRAY_SIZE (mHisiAcpiDevId); Inde= x++) { >> + if (AsciiStrCmp ((CHAR8 *)Data, mHisiAcpiDevId[Index]) =3D= =3D 0) { >> + HisiAcpiDevNotFound =3D FALSE; >> + break; >> + } >> + } >> + if (HisiAcpiDevNotFound) { >> + AcpiTableProtocol->Close (ValueHandle); >> + FoundDev =3D DsdtDeviceUnknown; >> + continue; >> + } >> + >> + DBG("Found device\n"); >> + AcpiTableProtocol->Close(ValueHandle); >> + Status =3D GetDeviceInfo (AcpiTableProtocol, ChildHandle, &= DevNextID, &FoundDev); >> + if (EFI_ERROR (Status)) { >> + continue; >> + } >> + } else if ((FoundDev !=3D DsdtDeviceUnknown) && AsciiStrnCmp(= (CHAR8 *) Data, "_DSD", 4) =3D=3D 0) { >> + // >> + // Patch DSD data >> + // >> + EFI_ACPI_HANDLE PkgHandle; >> + Status =3D AcpiTableProtocol->GetOption(DevHandle, 2, &Data= Type, &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) >> + break; >> + >> + if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) >> + continue; >> + >> + // >> + // Open package data >> + // >> + AcpiTableProtocol->Open((VOID *) Buffer, &PkgHandle); >> + Status =3D AcpiTableProtocol->GetOption(PkgHandle, 0, &Data= Type, &Buffer, &DataSize); >> + >> + Data =3D Buffer; >> + DBG("_DSD Subnode Store Op Code 0x%02X %02X\n", >> + Data[0], DataSize > 1 ? Data[1] : 0); >> + >> + // >> + // Walk the _DSD node >> + // >> + if (DataSize =3D=3D 1 && Data[0] =3D=3D AML_PACKAGE_OP) { >> + Status =3D SearchReplacePackageAddress (AcpiTableProtocol= , PkgHandle, DevNextID, FoundDev); >> + } >> + >> + AcpiTableProtocol->Close(PkgHandle); >> + } else if (AsciiStrnCmp ((CHAR8 *) Data, "_ADR", 4) =3D=3D 0)= { >> + Status =3D AcpiTableProtocol->GetOption (DevHandle, 2, &Dat= aType, &Buffer, &DataSize); >> + if (EFI_ERROR (Status)) { >> + break; >> + } >> + >> + if (DataType !=3D EFI_ACPI_DATA_TYPE_CHILD) { >> + continue; >> + } >> + >> + Status =3D GetDeviceInfo (AcpiTableProtocol, ChildHandle, &= DevNextID, &FoundDev); >> + >> + if (EFI_ERROR (Status)) { >> + continue; >> + } >> + } >> + } >> + } else if ((DataSize =3D=3D 2) && (Data[0] =3D=3D AML_EXT_OP) && = (Data[1] =3D=3D 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 =3D AcpiTableProtocol->GetOption (ChildHandle, 0, &DataType,= &Buffer, &DataSize); >> + if (EFI_ERROR(Status)) return FALSE; >> + >> + Data =3D Buffer; >> + if (DataSize !=3D 1 || Data[0] !=3D 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 =3D NULL; ; ) { >> + Status =3D AcpiTableProtocol->GetChild (ChildHandle, &DevHandle); >> + if (EFI_ERROR(Status) || DevHandle =3D=3D 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=3D%p\n", __FUNCTION__, __LINE__, TableH= andle); >> + for (ChildHandle =3D NULL; ; ) { >> + Status =3D AcpiTableProtocol->GetChild(TableHandle, &ChildHandle)= ; >> + DBG ("[%a:%d] - Child=3D%p, %r\n", __FUNCTION__, __LINE__, ChildH= andle, Status); >> + if (EFI_ERROR(Status)) >> + break; >> + if (ChildHandle =3D=3D NULL) >> + break; >> + >> + ProcessDSDTChild(AcpiTableProtocol, ChildHandle); >> + } >> + >> + return EFI_SUCCESS; >> +} >> + >> +STATIC >> +VOID >> +AcpiCheckSum ( >> + IN OUT EFI_ACPI_SDT_HEADER *Table >> + ) >> +{ >> + UINTN ChecksumOffset; >> + UINT8 *Buffer; >> + >> + ChecksumOffset =3D OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum= ); >> + Buffer =3D (UINT8 *)Table; >> + >> + // >> + // set checksum to 0 first >> + // >> + Buffer[ChecksumOffset] =3D 0; >> + >> + // >> + // Update checksum value >> + // >> + Buffer[ChecksumOffset] =3D CalculateCheckSum8 (Buffer, Table->Lengt= h); >> +} >> + >> +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 =3D gBS->LocateProtocol(&gEfiAcpiSdtProtocolGuid, NULL, (VOI= D**) &AcpiTableProtocol); >> + if (EFI_ERROR(Status)) { >> + DBG("Unable to locate ACPI table protocol\n"); >> + return EFI_SUCCESS; >> + } >> + >> + // >> + // Search for DSDT Table >> + for (i =3D 0; i < EFI_ACPI_MAX_NUM_TABLES; i++) { >> + Status =3D AcpiTableProtocol->GetAcpiTable(i, &Table, &TableVersi= on, &TableKey); >> + if (EFI_ERROR(Status)) >> + break; >> + if (Table->Signature !=3D DSDT_SIGNATURE) >> + continue; >> + >> + Status =3D 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 >> + * >> + * SPDX-License-Identifier: BSD-2-Clause-Patent >> + */ >> +#ifndef _ETH_MAC_H_ >> +#define _ETH_MAC_H_ >> + >> +EFI_STATUS UpdateAcpiDsdtTable (VOID); >> + >> +#endif >> + >> --=20 >> 2.8.1 >> >=20 > . >=20