From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web09.627.1572229928030825531 for ; Sun, 27 Oct 2019 19:32:08 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=02044412f4=abner.chang@hpe.com) Received: from pps.filterd (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9S2VoNs021381; Mon, 28 Oct 2019 02:32:07 GMT Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 2vvet60gm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2019 02:32:07 +0000 Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id 9E70354; Mon, 28 Oct 2019 02:32:06 +0000 (UTC) Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 4A4504B; Mon, 28 Oct 2019 02:32:05 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com, Leif Lindholm , Gilbert Chen Subject: [edk2-staging/RISC-V-V2 PATCH v3 28/39] RiscVPlatformPkg/FirmwareContextProcessorSpecificLib:Add FirmwareContextProcessorSpecificLib module Date: Mon, 28 Oct 2019 09:59:06 +0800 Message-Id: <1572227957-13169-29-git-send-email-abner.chang@hpe.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1572227957-13169-1-git-send-email-abner.chang@hpe.com> References: <1572227957-13169-1-git-send-email-abner.chang@hpe.com> X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-27_09:2019-10-25,2019-10-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 suspectscore=1 priorityscore=1501 phishscore=0 clxscore=1015 impostorscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1910280025 Add OpenSBI firmware context processor specific library which provides interface to create processor specific firmware context hob data. Signed-off-by: Abner Chang Cc: Leif Lindholm Cc: Gilbert Chen --- .../FirmwareContextProcessorSpecificLib.inf | 31 +++++++ .../Library/FirmwareContextProcessorSpecificLib.h | 42 ++++++++++ .../FirmwareContextProcessorSpecificLib.c | 94 ++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.inf create mode 100644 RiscVPlatformPkg/Include/Library/FirmwareContextProcessorSpecificLib.h create mode 100644 RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.c diff --git a/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.inf b/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.inf new file mode 100644 index 0000000..8ea37ae --- /dev/null +++ b/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.inf @@ -0,0 +1,31 @@ +#/** @file +# +# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x0001001b + BASE_NAME = FirmwareContextProcessorSpecificLib + FILE_GUID = 8BEC9FD7-C554-403A-94F1-0EBBFD81A242 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = FirmwareContextProcessorSpecificLib + +[Sources.common] + FirmwareContextProcessorSpecificLib.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + RiscVPkg/RiscVPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + MemoryAllocationLib + PrintLib + + diff --git a/RiscVPlatformPkg/Include/Library/FirmwareContextProcessorSpecificLib.h b/RiscVPlatformPkg/Include/Library/FirmwareContextProcessorSpecificLib.h new file mode 100644 index 0000000..5fe99a4 --- /dev/null +++ b/RiscVPlatformPkg/Include/Library/FirmwareContextProcessorSpecificLib.h @@ -0,0 +1,42 @@ +/** @file + Firmware Context Processor-specific common library + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#ifndef FIRMWARE_CONTEXT_PROCESSOR_SPECIFIC_LIB_H +#define FIRMWARE_CONTEXT_PROCESSOR_SPECIFIC_LIB_H + +#include +#include +#include + +/** + Build up common firmware context processor-specific information + + @param FirmwareContextHartSpecific Pointer to EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC + @param ParentProcessorGuid Pointer to GUID of Processor which contains this core + @param ParentProcessorUid Unique ID of pysical processor which owns this core. + @param CoreGuid Pointer to GUID of core + @param HartId Hart ID of this core. + @param IsBootHart This is boot hart or not + @param ProcessorSpecDataHob Pointer to RISC_V_PROCESSOR_SPECIFIC_DATA_HOB + + @return EFI_STATUS + +**/ +EFI_STATUS +EFIAPI +CommonFirmwareContextHartSpecificInfo ( + EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *FirmwareContextHartSpecific, + EFI_GUID *ParentProcessorGuid, + UINTN ParentProcessorUid, + EFI_GUID *CoreGuid, + UINTN HartId, + BOOLEAN IsBootHart, + RISC_V_PROCESSOR_SPECIFIC_HOB_DATA *ProcessorSpecDataHob + ); + +#endif diff --git a/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.c b/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.c new file mode 100644 index 0000000..21b26be --- /dev/null +++ b/RiscVPlatformPkg/Library/FirmwareContextProcessorSpecificLib/FirmwareContextProcessorSpecificLib.c @@ -0,0 +1,94 @@ +/**@file + Common library to build upfirmware context processor-specific information + + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +// The package level header files this module uses +// +#include + +// +// The Library classes this module consumes +// +#include +#include +#include +#include +#include +#include +#include +#include + +/** + Build up common firmware context processor-specific information + + @param FirmwareContextHartSpecific Pointer to EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC + @param ParentProcessorGuid Pointer to GUID of Processor which contains this core + @param ParentProcessorUid Unique ID of pysical processor which owns this core. + @param CoreGuid Pointer to GUID of core + @param HartId Hart ID of this core. + @param IsBootHart This is boot hart or not + @param ProcessorSpecificDataHob Pointer to RISC_V_PROCESSOR_SPECIFIC_DATA_HOB + + @return EFI_STATUS + +**/ +EFI_STATUS +EFIAPI +CommonFirmwareContextHartSpecificInfo ( + EFI_RISCV_FIRMWARE_CONTEXT_HART_SPECIFIC *FirmwareContextHartSpecific, + EFI_GUID *ParentProcessorGuid, + UINTN ParentProcessorUid, + EFI_GUID *CoreGuid, + UINTN HartId, + BOOLEAN IsBootHart, + RISC_V_PROCESSOR_SPECIFIC_HOB_DATA *ProcessorSpecificDataHob + ) +{ + // + // Build up RISC_V_PROCESSOR_SPECIFIC_DATA_HOB. + // + CopyGuid (&ProcessorSpecificDataHob->ParentPrcessorGuid, ParentProcessorGuid); + ProcessorSpecificDataHob->ParentProcessorUid = ParentProcessorUid; + CopyGuid (&ProcessorSpecificDataHob->CoreGuid, CoreGuid); + ProcessorSpecificDataHob->Context = NULL; + ProcessorSpecificDataHob->ProcessorSpecificData.Revision = + SMBIOS_RISC_V_PROCESSOR_SPECIFIC_DATA_REVISION; + ProcessorSpecificDataHob->ProcessorSpecificData.Length = + sizeof (SMBIOS_RISC_V_PROCESSOR_SPECIFIC_DATA); + ProcessorSpecificDataHob->ProcessorSpecificData.HartId.Value64_L = (UINT64)HartId; + ProcessorSpecificDataHob->ProcessorSpecificData.HartId.Value64_H = 0; + ProcessorSpecificDataHob->ProcessorSpecificData.BootHartId = (UINT8)IsBootHart; + ProcessorSpecificDataHob->ProcessorSpecificData.InstSetSupported = + FirmwareContextHartSpecific->IsaExtensionSupported; + ProcessorSpecificDataHob->ProcessorSpecificData.PrivilegeModeSupported = + SMBIOS_RISC_V_PSD_MACHINE_MODE_SUPPORTED; + if ((ProcessorSpecificDataHob->ProcessorSpecificData.InstSetSupported & + RISC_V_ISA_SUPERVISOR_MODE_IMPLEMENTED) != 0) { + ProcessorSpecificDataHob->ProcessorSpecificData.PrivilegeModeSupported |= + SMBIOS_RISC_V_PSD_SUPERVISOR_MODE_SUPPORTED; + } + if ((ProcessorSpecificDataHob->ProcessorSpecificData.InstSetSupported & + RISC_V_ISA_USER_MODE_IMPLEMENTED) != 0) { + ProcessorSpecificDataHob->ProcessorSpecificData.PrivilegeModeSupported |= + SMBIOS_RISC_V_PSD_USER_MODE_SUPPORTED; + } + ProcessorSpecificDataHob->ProcessorSpecificData.MachineVendorId.Value64_L = + FirmwareContextHartSpecific->MachineVendorId.Value64_L; + ProcessorSpecificDataHob->ProcessorSpecificData.MachineVendorId.Value64_H = + FirmwareContextHartSpecific->MachineVendorId.Value64_H; + ProcessorSpecificDataHob->ProcessorSpecificData.MachineArchId.Value64_L = + FirmwareContextHartSpecific->MachineArchId.Value64_L; + ProcessorSpecificDataHob->ProcessorSpecificData.MachineArchId.Value64_H = + FirmwareContextHartSpecific->MachineArchId.Value64_H; + ProcessorSpecificDataHob->ProcessorSpecificData.MachineImplId.Value64_L = + FirmwareContextHartSpecific->MachineImplId.Value64_L; + ProcessorSpecificDataHob->ProcessorSpecificData.MachineImplId.Value64_H = + FirmwareContextHartSpecific->MachineImplId.Value64_H; + return EFI_SUCCESS; +} -- 2.7.4