From patchwork Thu Nov 10 13:52:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 81675 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp748767qge; Thu, 10 Nov 2016 06:18:28 -0800 (PST) X-Received: by 10.55.179.195 with SMTP id c186mr5235432qkf.137.1478787508075; Thu, 10 Nov 2016 06:18:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j68si3485487qte.13.2016.11.10.06.18.27; Thu, 10 Nov 2016 06:18:28 -0800 (PST) Received-SPF: pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-uefi-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A49E860675; Thu, 10 Nov 2016 14:18:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id F283160EB5; Thu, 10 Nov 2016 14:01:25 +0000 (UTC) X-Original-To: linaro-uefi@lists.linaro.org Delivered-To: linaro-uefi@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DFB6460EAD; Thu, 10 Nov 2016 14:00:27 +0000 (UTC) Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by lists.linaro.org (Postfix) with ESMTPS id 4EC7D60E65 for ; Thu, 10 Nov 2016 13:54:11 +0000 (UTC) Received: by mail-pf0-f173.google.com with SMTP id n85so147126941pfi.1 for ; Thu, 10 Nov 2016 05:54:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zEOt53vnU3KA3sGhmiDo1xQHWH0iQQA8mq1ctUHFbC8=; b=E9qVNWDOBYZLxuNyxivtjLt/bLvdvHgHq3Mh78gEl9gvvwmsHRoPMt4BSLn5Y4MDoK ooMsitt+h5jbgbJiHxe6K+1BPpA7mlIl7Ac4mRm5IC+G68BPk5PbQiYUK978/QV5mdhV 2rFAT5s7Vf1qGkGIuJNboqjbNkHFfn4Q9bB+GhyEfnfxtYn9UxvEYct4SQ/yHbF36QbG 8+oehmsqvt/Ny+z2AhoC58e7hns/KPoAvTBzVoFifqyKDLzn/UssW/Di45hCex/jJHck SPDScpThPEEWcWBnSgY4RxfQnXzW2idyiVxvWzJJde9qE4Bvz0JJRaYPlCIeNOFMOFmE IGww== X-Gm-Message-State: ABUngveUlHPeNNbHyrSVJ+nr2/C6G2WRMg8la7QvCypaSrkDHnO9ikrMKOP9fMPDsFIb5jeka1E= X-Received: by 10.98.217.67 with SMTP id s64mr10289793pfg.66.1478786050564; Thu, 10 Nov 2016 05:54:10 -0800 (PST) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id g78sm7625705pfe.19.2016.11.10.05.54.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Nov 2016 05:54:10 -0800 (PST) From: Heyi Guo To: linaro-uefi@lists.linaro.org Date: Thu, 10 Nov 2016 21:52:29 +0800 Message-Id: <1478785950-24197-26-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1478785950-24197-1-git-send-email-heyi.guo@linaro.org> References: <1478785950-24197-1-git-send-email-heyi.guo@linaro.org> Subject: [Linaro-uefi] [PATCH 26/27] Hisilicon/ACPI: Update SRAT from real memory configuration X-BeenThere: linaro-uefi@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-uefi-bounces@lists.linaro.org Sender: "Linaro-uefi" we add updating ACPI table feature to update SRAT and SLIT table for D05 platform. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo --- .../Drivers/HisiAcpiPlatformDxe/AcpiPlatform.c | 53 +++++--- .../HisiAcpiPlatformDxe/AcpiPlatformDxe.inf | 6 + .../Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 137 +++++++++++++++++++++ 3 files changed, 176 insertions(+), 20 deletions(-) create mode 100644 Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c diff --git a/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatform.c b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatform.c index 5b679fa..c1a31b5 100644 --- a/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatform.c +++ b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatform.c @@ -24,6 +24,11 @@ #include +EFI_STATUS +UpdateAcpiTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader +); + /** Locate the first instance of a protocol. If the protocol requested is an FV protocol, then it will return the first FV that contains the ACPI table @@ -180,6 +185,8 @@ AcpiPlatformEntryPoint ( UINT32 FvStatus; UINTN TableSize; UINTN Size; + EFI_STATUS TableStatus; + EFI_ACPI_DESCRIPTION_HEADER *TableHeader; Instance = 0; CurrentTable = NULL; @@ -218,26 +225,32 @@ AcpiPlatformEntryPoint ( // // Add the table // - TableHandle = 0; - - TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length; - ASSERT (Size >= TableSize); - - // - // Checksum ACPI table - // - AcpiPlatformChecksum ((UINT8*)CurrentTable, TableSize); - - // - // Install ACPI table - // - Status = AcpiTable->InstallAcpiTable ( - AcpiTable, - CurrentTable, - TableSize, - &TableHandle - ); - + TableHeader = (EFI_ACPI_DESCRIPTION_HEADER*) (CurrentTable); + //Update specfic Acpi Table + //If the Table is updated failed, doesn't install it, + //go to find next section. + TableStatus = UpdateAcpiTable(TableHeader); + if (TableStatus == EFI_SUCCESS) { + TableHandle = 0; + + TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length; + ASSERT (Size >= TableSize); + + // + // Checksum ACPI table + // + AcpiPlatformChecksum ((UINT8*)CurrentTable, TableSize); + + // + // Install ACPI table + // + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + CurrentTable, + TableSize, + &TableHandle + ); + } // // Free memory allocated by ReadSection // diff --git a/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf index 80ff49b..35b4a0a 100644 --- a/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf @@ -29,10 +29,12 @@ [Sources] AcpiPlatform.c + UpdateAcpiTable.c [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OpenPlatformPkg/Chips/Hisilicon/HisiPkg.dec [LibraryClasses] UefiLib @@ -42,10 +44,14 @@ DebugLib UefiBootServicesTableLib UefiDriverEntryPoint + HobLib [Protocols] gEfiAcpiTableProtocolGuid ## CONSUMES +[Guids] + gHisiEfiMemoryMapGuid + [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile ## CONSUMES diff --git a/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c new file mode 100644 index 0000000..1d7797c --- /dev/null +++ b/Chips/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c @@ -0,0 +1,137 @@ +/** @file + Copyright (c) 2016, Hisilicon Limited. All rights reserved. + This program and the accompanying materials are licensed and made available + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CORE_NUM_PER_SOCKET 32 +#define NODE_IN_SOCKET 2 + +STATIC +VOID +RemoveInvalidMemoryNode ( + IN OUT EFI_ACPI_STATIC_RESOURCE_AFFINITY_TABLE *Table, + IN UINTN MemoryNodeNum +) +{ + UINT8 *CurrPtr, *NewPtr; + + if (MemoryNodeNum >= EFI_ACPI_MEMORY_AFFINITY_STRUCTURE_COUNT) { + return; + } + + CurrPtr = (UINT8 *) &(Table->Memory[EFI_ACPI_MEMORY_AFFINITY_STRUCTURE_COUNT]); + NewPtr = (UINT8 *) &(Table->Memory[MemoryNodeNum]); + + CopyMem (NewPtr, CurrPtr, (UINT8 *)Table + Table->Header.Header.Length - CurrPtr); + + Table->Header.Header.Length -= CurrPtr - NewPtr; + + return; +} + +STATIC +EFI_STATUS +UpdateSrat ( + IN OUT EFI_ACPI_STATIC_RESOURCE_AFFINITY_TABLE *Table + ) +{ + UINT8 Skt = 0; + UINTN Index = 0; + VOID *HobList; + GBL_DATA *Gbl_Data; + UINTN Base; + UINTN Size; + UINT8 NodeId; + UINT32 ScclInterleaveEn; + UINT8 i; + UINTN MemoryNode = 0; + + DEBUG((DEBUG_INFO, "SRAT: Updating SRAT memory information.\n")); + + HobList = GetHobList(); + if (HobList == NULL) { + return EFI_UNSUPPORTED; + } + Gbl_Data = (GBL_DATA*)GetNextGuidHob(&gHisiEfiMemoryMapGuid, HobList); + if (Gbl_Data == NULL) { + DEBUG((DEBUG_ERROR, "Get next Guid HOb fail.\n")); + return EFI_NOT_FOUND; + } + Gbl_Data = GET_GUID_HOB_DATA(Gbl_Data); + for(Skt = 0; Skt < MAX_SOCKET; Skt++) { + for(Index = 0; Index < MAX_NUM_PER_TYPE; Index++) { + NodeId = Gbl_Data->NumaInfo[Skt][Index].NodeId; + Base = Gbl_Data->NumaInfo[Skt][Index].Base; + Size = Gbl_Data->NumaInfo[Skt][Index].Length; + DEBUG((DEBUG_INFO, "Skt %d Index %d: NodeId = %d, Base = 0x%lx, Size = 0x%lx\n", Skt, Index, NodeId, Base, Size)); + if (Size > 0) { + Table->Memory[MemoryNode].ProximityDomain = NodeId; + Table->Memory[MemoryNode].AddressBaseLow = Base; + Table->Memory[MemoryNode].AddressBaseHigh = Base >> 32; + Table->Memory[MemoryNode].LengthLow = Size; + Table->Memory[MemoryNode].LengthHigh = Size >> 32; + MemoryNode = MemoryNode + 1; + } + } + ScclInterleaveEn = Gbl_Data->NumaInfo[Skt][0].ScclInterleaveEn; + DEBUG((DEBUG_INFO, "ScclInterleaveEn = %d\n", ScclInterleaveEn)); + //update gicc structure + if (ScclInterleaveEn != 0) { + DEBUG((DEBUG_INFO, "SRAT: Updating SRAT Gicc information.\n" )); + for (i = Skt * CORE_NUM_PER_SOCKET; i < (Skt + 1) * CORE_NUM_PER_SOCKET; i++) { + Table->Gicc[i].ProximityDomain = Skt * NODE_IN_SOCKET; + } + } + } + + //remove invalid memory node + RemoveInvalidMemoryNode (Table, MemoryNode); + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +UpdateSlit ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *Table + ) +{ + return EFI_SUCCESS; +} + +EFI_STATUS +UpdateAcpiTable ( + IN OUT EFI_ACPI_DESCRIPTION_HEADER *TableHeader +) +{ + EFI_STATUS Status = EFI_SUCCESS; + + switch (TableHeader->Signature) { + + case EFI_ACPI_6_0_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE: + Status = UpdateSrat ((EFI_ACPI_STATIC_RESOURCE_AFFINITY_TABLE *) TableHeader); + break; + + case EFI_ACPI_6_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE: + Status = UpdateSlit (TableHeader); + break; + } + return Status; +}