From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by mx.groups.io with SMTP id smtpd.web08.7825.1632487888835382384 for ; Fri, 24 Sep 2021 05:51:29 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20210112.gappssmtp.com header.s=20210112 header.b=4tVb/vUX; spf=pass (domain: nuviainc.com, ip: 209.85.221.54, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f54.google.com with SMTP id u18so27250772wrg.5 for ; Fri, 24 Sep 2021 05:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oOshD3shVDS/hbm6jP7l7ZZt5Ir7+XwMnC7IZ02Yzok=; b=4tVb/vUX9sxZ+nojlPKbQSTB6e4ZBpHnB27peymk5JAITcLUUEN5ZbdkrSGCAlDuDp tMNse4IOyNiwK/rTw4jx9GSjI6L2DnJ6ifpLmNjuPwZMzkyGebY1/DvoVWX24L3a12Mi DMJNR9TCJ/L1BUfWMxV+rkuBcrWGJEkwhzk96vT3sc7/v8/mDdSPkDojBTwzngIpUTYW xNZRMhxDhnfCvrRPJ9XTCDrIVZQnkQ/vzI4KHDRqXHmEIOkfP8FtePXcfpu2fX4HiC/3 ERyplayIIxK9sJ0L0IWOfjGDJ71+mS/0RXfJB4mVvomwXdQ+qbI51YVTVWiPW/DHA+dJ f1Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oOshD3shVDS/hbm6jP7l7ZZt5Ir7+XwMnC7IZ02Yzok=; b=2Aawf9I8IzYpeS9NVH+Q3P0/Z3HKCjBw7kgNtCW/bXsPshAtI1U3qhk5ql4R0wk3kS Km5s7A9GZ+s3xK+ltq/rwj0iF+2UF4rwmVlnmzcGfU1eaiWwDpXzCEooQfMDzUOgem22 ug9x2r9ieHDlvvd9s0nAWD8qfA4cdA9rTU/rUYX5gVvMDMZWGyN3ar2fhxaMn0kY8GOD x+W3vf1iYcvc6FjWATApOji2Uq8YpDtetYy8U8t5WAzwPyUtZtFy+vM9cF4bTIjgVSBo oRjIuCEcQLXxqNSKk+7P96s2kDT5LqonMxP7ceY9wPAJUOEVZ7yfyFp/HP1fb50TiL8R W5Lg== X-Gm-Message-State: AOAM530tqO+TVEO9EP4VV35tEHVtdNBetllHF9j7KhJp19I2eFLXeTz+ ivPf1fso/de6YQTjVOs0ixpdmw== X-Google-Smtp-Source: ABdhPJzXYrTmBLc+VUSP55lFDWtMXbWZJW2wcprY2Cs0AaaFWKM8Skp46SSPnBYqrzjI9wSsOdqz+Q== X-Received: by 2002:a05:6000:1844:: with SMTP id c4mr10813291wri.355.1632487887252; Fri, 24 Sep 2021 05:51:27 -0700 (PDT) Return-Path: Received: from leviathan (cpc92314-cmbg19-2-0-cust559.5-4.cable.virginm.net. [82.11.186.48]) by smtp.gmail.com with ESMTPSA id f19sm8238275wmf.11.2021.09.24.05.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 05:51:26 -0700 (PDT) Date: Fri, 24 Sep 2021 13:51:24 +0100 From: "Leif Lindholm" To: Nhi Pham Cc: devel@edk2.groups.io, patches@amperecomputing.com, vunguyen@os.amperecomputing.com, Thang Nguyen , Chuong Tran , Phong Vo , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: Re: [PATCH v3 24/28] AmpereAltraPkg: Add configuration screen for CPU Message-ID: <20210924125124.iz652yv3fknhpffg@leviathan> References: <20210915155527.8176-1-nhi@os.amperecomputing.com> <20210915155527.8176-25-nhi@os.amperecomputing.com> MIME-Version: 1.0 In-Reply-To: <20210915155527.8176-25-nhi@os.amperecomputing.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 15, 2021 at 22:55:23 +0700, Nhi Pham wrote: > From: Vu Nguyen > > This screen is to add configuration regarding CPU. Currently, this > screen just adds a option for SubNUMA mode selection. > > Cc: Thang Nguyen > Cc: Chuong Tran > Cc: Phong Vo > Cc: Leif Lindholm > Cc: Michael D Kinney > Cc: Ard Biesheuvel > Cc: Nate DeSimone > > Signed-off-by: Vu Nguyen Reviewed-by: Leif Lindholm > --- > Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec | 3 + > Platform/Ampere/JadePkg/Jade.dsc | 1 + > Platform/Ampere/JadePkg/Jade.fdf | 1 + > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf | 58 +++ > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.h | 52 ++ > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigNVDataStruc.h | 19 + > Silicon/Ampere/AmpereAltraPkg/Include/Guid/CpuConfigHii.h | 19 + > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigVfr.vfr | 43 ++ > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.c | 530 ++++++++++++++++++++ > Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigStrings.uni | 17 + > 10 files changed, 743 insertions(+) > > diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec > index 93da9b38def5..6ea247c75e87 100644 > --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec > +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec > @@ -50,6 +50,9 @@ [LibraryClasses] > TrngLib|Silicon/Ampere/AmpereAltraPkg/Include/Library/TrngLib.h > > [Guids] > + # GUID for the CPU HII configuration form > + gCpuConfigFormSetGuid = { 0x43FAA144, 0xA2DF, 0x4050, { 0xA7, 0xFD, 0xEE, 0x17, 0xC9, 0xB8, 0x88, 0x8E } } > + > ## NVParam MM GUID > gNVParamMmGuid = { 0xE4AC5024, 0x29BE, 0x4ADC, { 0x93, 0x36, 0x87, 0xB5, 0xA0, 0x76, 0x23, 0x2D } } > > diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jade.dsc > index 5fc83745cdbc..8ca3a729728f 100644 > --- a/Platform/Ampere/JadePkg/Jade.dsc > +++ b/Platform/Ampere/JadePkg/Jade.dsc > @@ -198,3 +198,4 @@ [Components.common] > # > Silicon/Ampere/AmpereAltraPkg/Drivers/PlatformInfoDxe/PlatformInfoDxe.inf > Silicon/Ampere/AmpereAltraPkg/Drivers/MemInfoDxe/MemInfoDxe.inf > + Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf > diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jade.fdf > index 6fe023025034..d9552886fbcf 100644 > --- a/Platform/Ampere/JadePkg/Jade.fdf > +++ b/Platform/Ampere/JadePkg/Jade.fdf > @@ -356,5 +356,6 @@ [FV.FvMain] > # > INF Silicon/Ampere/AmpereAltraPkg/Drivers/PlatformInfoDxe/PlatformInfoDxe.inf > INF Silicon/Ampere/AmpereAltraPkg/Drivers/MemInfoDxe/MemInfoDxe.inf > + INF Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf > > !include Platform/Ampere/AmperePlatformPkg/FvRules.fdf.inc > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf > new file mode 100644 > index 000000000000..2b13ef526685 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.inf > @@ -0,0 +1,58 @@ > +## @file > +# > +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = CpuConfigDxe > + MODULE_UNI_FILE = CpuConfigDxe.uni > + FILE_GUID = A20D8E6E-EE6C-43C5-809F-19BB930653AE > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = CpuConfigDxeEntryPoint > + > +[Sources.common] > + CpuConfigDxe.c > + CpuConfigDxe.h > + CpuConfigNVDataStruc.h > + CpuConfigVfr.vfr > + CpuConfigStrings.uni > + > +[Packages] > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec > + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec > + > +[LibraryClasses] > + ArmLib > + BaseLib > + DebugLib > + DevicePathLib > + HiiLib > + HobLib > + IoLib > + MemoryAllocationLib > + NVParamLib > + PcdLib > + PrintLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + UefiLib > + UefiRuntimeServicesTableLib > + > +[Protocols] > + gEfiHiiConfigRoutingProtocolGuid ## CONSUMES > + gEfiHiiConfigAccessProtocolGuid ## PRODUCES > + gEfiDevicePathProtocolGuid ## PRODUCES > + > +[Guids] > + gCpuConfigFormSetGuid > + gPlatformManagerFormsetGuid > + > +[Depex] > + TRUE > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.h > new file mode 100644 > index 000000000000..b7e74a09da5b > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.h > @@ -0,0 +1,52 @@ > +/** @file > + > + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef CPU_CONFIG_H_ > +#define CPU_CONFIG_H_ > + > +#include "CpuConfigNVDataStruc.h" > + > +// > +// This is the generated IFR binary data for each formset defined in VFR. > +// > +extern UINT8 CpuConfigVfrBin[]; > + > +// > +// This is the generated String package data for all .UNI files. > +// > +extern UINT8 CpuConfigDxeStrings[]; > + > +#define CPU_CONFIG_PRIVATE_SIGNATURE SIGNATURE_32 ('C', 'P', 'U', '_') > + > +typedef struct { > + UINTN Signature; > + > + EFI_HANDLE DriverHandle; > + EFI_HII_HANDLE HiiHandle; > + CPU_VARSTORE_DATA Configuration; > + > + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; > + > + EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; > +} CPU_CONFIG_PRIVATE_DATA; > + > +#define CPU_CONFIG_PRIVATE_FROM_THIS(a) CR (a, CPU_CONFIG_PRIVATE_DATA, ConfigAccess, CPU_CONFIG_PRIVATE_SIGNATURE) > + > +#pragma pack(1) > + > +/// > +/// HII specific Vendor Device Path definition. > +/// > +typedef struct { > + VENDOR_DEVICE_PATH VendorDevicePath; > + EFI_DEVICE_PATH_PROTOCOL End; > +} HII_VENDOR_DEVICE_PATH; > + > +#pragma pack() > + > +#endif /* CPU_CONFIG_H_ */ > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigNVDataStruc.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigNVDataStruc.h > new file mode 100644 > index 000000000000..dbcaebded1b7 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigNVDataStruc.h > @@ -0,0 +1,19 @@ > +/** @file > + > + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef CPU_CONFIG_NV_DATA_STRUC_H_ > +#define CPU_CONFIG_NV_DATA_STRUC_H_ > + > +#pragma pack(1) > +typedef struct { > + UINT32 CpuSubNumaMode; > +} CPU_VARSTORE_DATA; > + > +#pragma pack() > + > +#endif /* CPU_CONFIG_NV_DATA_STRUC_H_ */ > diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Guid/CpuConfigHii.h b/Silicon/Ampere/AmpereAltraPkg/Include/Guid/CpuConfigHii.h > new file mode 100644 > index 000000000000..71c8492f76a1 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Guid/CpuConfigHii.h > @@ -0,0 +1,19 @@ > +/** @file > + > + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef CPU_CONFIG_HII_H_ > +#define CPU_CONFIG_HII_H_ > + > +#define CPU_CONFIGURATION_FORMSET_GUID \ > + { \ > + 0x43FAA144, 0xA2DF, 0x4050, { 0xA7, 0xFD, 0xEE, 0x17, 0xC9, 0xB8, 0x88, 0x8E } \ > + } > + > +extern EFI_GUID gCpuConfigFormSetGuid; > + > +#endif /* CPU_CONFIG_HII_H_ */ > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigVfr.vfr b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigVfr.vfr > new file mode 100644 > index 000000000000..8e68b1e9dcb7 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigVfr.vfr > @@ -0,0 +1,43 @@ > +/** @file > + > + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include "CpuConfigNVDataStruc.h" > + > +#define SUBNUMA_MODE_FORM_ID 1 > + > +formset > + guid = CPU_CONFIGURATION_FORMSET_GUID, > + title = STRING_TOKEN(STR_CPU_FORM), > + help = STRING_TOKEN(STR_CPU_FORM_HELP), > + classguid = gPlatformManagerFormsetGuid, > + > + varstore CPU_VARSTORE_DATA, > + name = CpuConfigNVData, > + guid = CPU_CONFIGURATION_FORMSET_GUID; > + > + form > + formid = SUBNUMA_MODE_FORM_ID, > + title = STRING_TOKEN(STR_CPU_FORM); > + subtitle text = STRING_TOKEN(STR_CPU_FORM_HELP); > + > + oneof > + varid = CpuConfigNVData.CpuSubNumaMode, > + prompt = STRING_TOKEN(STR_CPU_SUBNUMA_MODE_PROMPT), > + help = STRING_TOKEN(STR_CPU_SUBNUMA_MODE_HELP), > + flags = RESET_REQUIRED, > + option text = STRING_TOKEN(STR_CPU_SUBNUMA_MODE_MONOLITHIC), value = 0x0, flags = DEFAULT; > + option text = STRING_TOKEN(STR_CPU_SUBNUMA_MODE_HEMISPHERE), value = 0x1, flags = 0; > + option text = STRING_TOKEN(STR_CPU_SUBNUMA_MODE_QUADRANT), value = 0x2, flags = 0; > + endoneof; > + > + endform; > + > +endformset; > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.c > new file mode 100644 > index 000000000000..a5cab9eb8d9a > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigDxe.c > @@ -0,0 +1,530 @@ > +/** @file > + > + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "CpuConfigDxe.h" > + > +// > +// Default settings definitions > +// > +#define NV_SI_SUBNUMA_MODE_DEFAULT 0x00 /* Monolithic mode */ > +#define WA_ERRATUM_1542419_DEFAULT 0x00 /* Disable I-Cache coherency */ > +#define NEAR_ATOMIC_DISABLE_DEFAULT 0x00 /* Enable Near Atomic */ > +#define CPU_SLC_REPLACE_POLICY 0x00 /* eLRU */ > + > +CHAR16 CpuVarstoreDataName[] = L"CpuConfigNVData"; > + > +EFI_HANDLE mDriverHandle = NULL; > +CPU_CONFIG_PRIVATE_DATA *mPrivateData = NULL; > + > +HII_VENDOR_DEVICE_PATH mCpuConfigHiiVendorDevicePath = { > + { > + { > + HARDWARE_DEVICE_PATH, > + HW_VENDOR_DP, > + { > + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), > + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) > + } > + }, > + CPU_CONFIGURATION_FORMSET_GUID > + }, > + { > + END_DEVICE_PATH_TYPE, > + END_ENTIRE_DEVICE_PATH_SUBTYPE, > + { > + (UINT8)(END_DEVICE_PATH_LENGTH), > + (UINT8)((END_DEVICE_PATH_LENGTH) >> 8) > + } > + } > +}; > + > +STATIC > +EFI_STATUS > +CpuNvParamGet ( > + OUT CPU_VARSTORE_DATA *Configuration > + ) > +{ > + EFI_STATUS Status; > + UINT32 Value; > + > + ASSERT (Configuration != NULL); > + > + Status = NVParamGet ( > + NV_SI_SUBNUMA_MODE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + &Value > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a %d Fail to write NVParam \n", __FUNCTION__, __LINE__)); > + Configuration->CpuSubNumaMode = SUBNUMA_MODE_MONOLITHIC; > + } else { > + Configuration->CpuSubNumaMode = Value; > + } > + > + return EFI_SUCCESS; > +} > + > +STATIC > +EFI_STATUS > +CpuNvParamSet ( > + IN CPU_VARSTORE_DATA *Configuration > + ) > +{ > + EFI_STATUS Status; > + UINT32 Value; > + > + ASSERT (Configuration != NULL); > + > + Status = NVParamGet ( > + NV_SI_SUBNUMA_MODE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + &Value > + ); > + ASSERT_EFI_ERROR (Status); > + > + if (EFI_ERROR (Status) || Value != Configuration->CpuSubNumaMode) { > + Status = NVParamSet ( > + NV_SI_SUBNUMA_MODE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + NV_PERM_BIOS | NV_PERM_MANU, > + Configuration->CpuSubNumaMode > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a %d Fail to access NVParam \n", __FUNCTION__, __LINE__)); > + ASSERT_EFI_ERROR (Status); > + return Status; > + } > + } > + > + return EFI_SUCCESS; > +} > + > +STATIC > +EFI_STATUS > +SetupDefaultSettings ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + UINT32 Value; > + > + // > + // Subnuma Mode > + // > + Status = NVParamGet ( > + NV_SI_SUBNUMA_MODE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + &Value > + ); > + if (EFI_ERROR (Status)) { > + Status = NVParamSet ( > + NV_SI_SUBNUMA_MODE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + NV_PERM_BIOS | NV_PERM_MANU, > + NV_SI_SUBNUMA_MODE_DEFAULT > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + } > + > + // > + // ARM ERRATA 1542419 workaround > + // > + Status = NVParamSet ( > + NV_SI_ERRATUM_1542419_WA, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + NV_PERM_BIOS | NV_PERM_MANU, > + WA_ERRATUM_1542419_DEFAULT > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Near atomic > + // > + Status = NVParamSet ( > + NV_SI_NEAR_ATOMIC_DISABLE, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + NV_PERM_BIOS | NV_PERM_MANU, > + NEAR_ATOMIC_DISABLE_DEFAULT > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // SLC Replacement Policy > + // > + Status = NVParamSet ( > + NV_SI_HNF_AUX_CTL_32_63, > + NV_PERM_ATF | NV_PERM_BIOS | NV_PERM_MANU | NV_PERM_BMC, > + NV_PERM_BIOS | NV_PERM_MANU, > + CPU_SLC_REPLACE_POLICY > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + This function allows a caller to extract the current configuration for one > + or more named elements from the target driver. > + > + @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. > + @param Request A null-terminated Unicode string in > + format. > + @param Progress On return, points to a character in the Request > + string. Points to the string's null terminator if > + request was successful. Points to the most recent > + '&' before the first failing name/value pair (or > + the beginning of the string if the failure is in > + the first name/value pair) if the request was not > + successful. > + @param Results A null-terminated Unicode string in > + format which has all values filled > + in for the names in the Request string. String to > + be allocated by the called function. > + > + @retval EFI_SUCCESS The Results is filled with the requested values. > + @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results. > + @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name. > + @retval EFI_NOT_FOUND Routing data doesn't match any storage in this > + driver. > + > +**/ > +EFI_STATUS > +EFIAPI > +CpuConfigExtractConfig ( > + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, > + IN CONST EFI_STRING Request, > + OUT EFI_STRING *Progress, > + OUT EFI_STRING *Results > + ) > +{ > + EFI_STATUS Status; > + UINTN BufferSize; > + CPU_CONFIG_PRIVATE_DATA *PrivateData; > + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; > + EFI_STRING ConfigRequest; > + EFI_STRING ConfigRequestHdr; > + UINTN Size; > + BOOLEAN AllocatedRequest; > + > + if (Progress == NULL || Results == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + // > + // Initialize the local variables. > + // > + ConfigRequestHdr = NULL; > + ConfigRequest = NULL; > + Size = 0; > + *Progress = Request; > + AllocatedRequest = FALSE; > + > + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gCpuConfigFormSetGuid, CpuVarstoreDataName)) { > + return EFI_NOT_FOUND; > + } > + > + PrivateData = CPU_CONFIG_PRIVATE_FROM_THIS (This); > + HiiConfigRouting = PrivateData->HiiConfigRouting; > + > + // > + // Get current setting from NVParam. > + // > + Status = CpuNvParamGet (&PrivateData->Configuration); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + // > + // Convert buffer data to by helper function BlockToConfig() > + // > + BufferSize = sizeof (CPU_VARSTORE_DATA); > + ConfigRequest = Request; > + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { > + // > + // Request has no request element, construct full request string. > + // Allocate and fill a buffer large enough to hold the template > + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator > + // > + ConfigRequestHdr = HiiConstructConfigHdr (&gCpuConfigFormSetGuid, CpuVarstoreDataName, PrivateData->DriverHandle); > + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); > + ConfigRequest = AllocateZeroPool (Size); > + ASSERT (ConfigRequest != NULL); > + if (ConfigRequest == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + AllocatedRequest = TRUE; > + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); > + FreePool (ConfigRequestHdr); > + } > + > + // > + // Convert buffer data to by helper function BlockToConfig() > + // > + Status = HiiConfigRouting->BlockToConfig ( > + HiiConfigRouting, > + ConfigRequest, > + (UINT8 *)&PrivateData->Configuration, > + BufferSize, > + Results, > + Progress > + ); > + > + // > + // Free the allocated config request string. > + // > + if (AllocatedRequest) { > + FreePool (ConfigRequest); > + ConfigRequest = NULL; > + } > + > + // > + // Set Progress string to the original request string. > + // > + if (Request == NULL) { > + *Progress = NULL; > + } else if (StrStr (Request, L"OFFSET") == NULL) { > + *Progress = Request + StrLen (Request); > + } > + > + return Status; > +} > + > +/** > + This function processes the results of changes in configuration. > + > + @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. > + @param Configuration A null-terminated Unicode string in > + format. > + @param Progress A pointer to a string filled in with the offset of > + the most recent '&' before the first failing > + name/value pair (or the beginning of the string if > + the failure is in the first name/value pair) or > + the terminating NULL if all was successful. > + > + @retval EFI_SUCCESS The Results is processed successfully. > + @retval EFI_INVALID_PARAMETER Configuration is NULL. > + @retval EFI_NOT_FOUND Routing data doesn't match any storage in this > + driver. > + > +**/ > +EFI_STATUS > +EFIAPI > +CpuConfigRouteConfig ( > + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, > + IN CONST EFI_STRING Configuration, > + OUT EFI_STRING *Progress > + ) > +{ > + EFI_STATUS Status; > + UINTN BufferSize; > + CPU_CONFIG_PRIVATE_DATA *PrivateData; > + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; > + > + if (Configuration == NULL || Progress == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + PrivateData = CPU_CONFIG_PRIVATE_FROM_THIS (This); > + HiiConfigRouting = PrivateData->HiiConfigRouting; > + *Progress = Configuration; > + > + // > + // Check routing data in . > + // Note: if only one Storage is used, then this checking could be skipped. > + // > + if (!HiiIsConfigHdrMatch (Configuration, &gCpuConfigFormSetGuid, CpuVarstoreDataName)) { > + return EFI_NOT_FOUND; > + } > + > + // > + // Get configuration data from NVParam > + // > + Status = CpuNvParamGet (&PrivateData->Configuration); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Convert to buffer data by helper function ConfigToBlock() > + // > + BufferSize = sizeof (CPU_VARSTORE_DATA); > + Status = HiiConfigRouting->ConfigToBlock ( > + HiiConfigRouting, > + Configuration, > + (UINT8 *)&PrivateData->Configuration, > + &BufferSize, > + Progress > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Store configuration data back to NVParam > + // > + Status = CpuNvParamSet (&PrivateData->Configuration); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return Status; > +} > + > +/** > + This function processes the results of changes in configuration. > + > + @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. > + @param Action Specifies the type of action taken by the browser. > + @param QuestionId A unique value which is sent to the original > + exporting driver so that it can identify the type > + of data to expect. > + @param Type The type of value for the question. > + @param Value A pointer to the data being sent to the original > + exporting driver. > + @param ActionRequest On return, points to the action requested by the > + callback function. > + > + @retval EFI_SUCCESS The callback successfully handled the action. > + @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters. > + > +**/ > +EFI_STATUS > +EFIAPI > +CpuConfigCallback ( > + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, > + IN EFI_BROWSER_ACTION Action, > + IN EFI_QUESTION_ID QuestionId, > + IN UINT8 Type, > + IN EFI_IFR_TYPE_VALUE *Value, > + OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest > + ) > +{ > + if (Action != EFI_BROWSER_ACTION_CHANGING) { > + // > + // Do nothing for other UEFI Action. Only do call back when data is changed. > + // > + return EFI_UNSUPPORTED; > + } > + if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))|| > + (ActionRequest == NULL)) > + { > + return EFI_INVALID_PARAMETER; > + } > + > + return EFI_SUCCESS; > +} > + > +EFI_STATUS > +CpuConfigDxeEntryPoint ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_HII_HANDLE HiiHandle; > + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; > + > + // > + // Initialize driver private data > + // > + mPrivateData = AllocateZeroPool (sizeof (CPU_CONFIG_PRIVATE_DATA)); > + if (mPrivateData == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + mPrivateData->Signature = CPU_CONFIG_PRIVATE_SIGNATURE; > + > + mPrivateData->ConfigAccess.ExtractConfig = CpuConfigExtractConfig; > + mPrivateData->ConfigAccess.RouteConfig = CpuConfigRouteConfig; > + mPrivateData->ConfigAccess.Callback = CpuConfigCallback; > + > + // > + // Locate ConfigRouting protocol > + // > + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&HiiConfigRouting); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + mPrivateData->HiiConfigRouting = HiiConfigRouting; > + > + Status = gBS->InstallMultipleProtocolInterfaces ( > + &mDriverHandle, > + &gEfiDevicePathProtocolGuid, > + &mCpuConfigHiiVendorDevicePath, > + &gEfiHiiConfigAccessProtocolGuid, > + &mPrivateData->ConfigAccess, > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > + > + mPrivateData->DriverHandle = mDriverHandle; > + > + // > + // Publish our HII data > + // > + HiiHandle = HiiAddPackages ( > + &gCpuConfigFormSetGuid, > + mDriverHandle, > + CpuConfigDxeStrings, > + CpuConfigVfrBin, > + NULL > + ); > + if (HiiHandle == NULL) { > + gBS->UninstallMultipleProtocolInterfaces ( > + mDriverHandle, > + &gEfiDevicePathProtocolGuid, > + &mCpuConfigHiiVendorDevicePath, > + &gEfiHiiConfigAccessProtocolGuid, > + &mPrivateData->ConfigAccess, > + NULL > + ); > + return EFI_OUT_OF_RESOURCES; > + } > + > + mPrivateData->HiiHandle = HiiHandle; > + > + // > + // With the fresh system, the NVParam value is invalid (0xFFFFFFFF). > + // It causes reading from the NVParam is failed. > + // So, the NVParam should be setting with default values if any params is invalid. > + // > + Status = SetupDefaultSettings (); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + return EFI_SUCCESS; > +} > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigStrings.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigStrings.uni > new file mode 100644 > index 000000000000..70c01f65e4b6 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/CpuConfigDxe/CpuConfigStrings.uni > @@ -0,0 +1,17 @@ > +// > +// Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > + > +#langdef en-US "English" > + > +#string STR_CPU_FORM #language en-US "CPU Configuration" > +#string STR_CPU_FORM_HELP #language en-US "CPU Configuration" > +#string STR_CPU_FORM_SEPERATE_LINE #language en-US "" > + > +#string STR_CPU_SUBNUMA_MODE_PROMPT #language en-US "ANC mode" > +#string STR_CPU_SUBNUMA_MODE_HELP #language en-US "Provides 3 modes: Monolithic, Hemisphere, Quadrant. System with Monolithic mode has single NUMA partition per socket. System with Hemisphere has 2 NUMA partitions per socket. System with Quandrant has 4 NUMA partitions per socket" > +#string STR_CPU_SUBNUMA_MODE_MONOLITHIC #language en-US "Monolithic" > +#string STR_CPU_SUBNUMA_MODE_HEMISPHERE #language en-US "Hemisphere" > +#string STR_CPU_SUBNUMA_MODE_QUADRANT #language en-US "Quadrant" > -- > 2.17.1 >