From: "Sunil V L" <sunilvl@ventanamicro.com>
To: caiyuqing_hz@163.com
Cc: devel@edk2.groups.io, quic_llindhol@quicinc.com,
libing1202@outlook.com, inochiama@outlook.com
Subject: Re: [edk2-devel] [PATCH v3 5/8] Sophgo/SG2042Pkg: Add SEC module.
Date: Fri, 15 Sep 2023 16:27:15 +0530 [thread overview]
Message-ID: <ZQQ4i3aCjM3d6lVY@sunil-laptop> (raw)
In-Reply-To: <27f47b7e4d8a1837529b06b311ed14f16669a5b2.1694010673.git.202235273@mail.sdu.edu.cn>
On Thu, Sep 07, 2023 at 06:25:48PM +0800, caiyuqing_hz@163.com wrote:
> From: caiyuqing379 <202235273@mail.sdu.edu.cn>
>
> This module supports Sophgo SG2042 EVB platform. It uses the
> PEI less design. Add this module in SG2042Pkg leveraging the
> one from OvmfPkg/RiscVVirt.
>
> Signed-off-by: caiyuqing379 <202235273@mail.sdu.edu.cn>
> Co-authored-by: USER0FISH <libing1202@outlook.com>
> Cc: dahogn <dahogn@hotmail.com>
> Cc: meng-cz <mengcz1126@gmail.com>
> Cc: yli147 <yong.li@intel.com>
> Cc: ChaiEvan <evan.chai@intel.com>
> Cc: Sunil V L <sunilvl@ventanamicro.com>
> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
> ---
> Silicon/Sophgo/SG2042Pkg/Sec/SecMain.inf | 68 +++++
> Silicon/Sophgo/SG2042Pkg/Sec/SecMain.h | 104 +++++++
> Silicon/Sophgo/SG2042Pkg/Sec/Cpu.c | 29 ++
> Silicon/Sophgo/SG2042Pkg/Sec/Memory.c | 347 +++++++++++++++++++++++
> Silicon/Sophgo/SG2042Pkg/Sec/Platform.c | 130 +++++++++
> Silicon/Sophgo/SG2042Pkg/Sec/SecMain.c | 115 ++++++++
> Silicon/Sophgo/SG2042Pkg/Sec/SecEntry.S | 18 ++
> 7 files changed, 811 insertions(+)
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/SecMain.inf
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/SecMain.h
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/Cpu.c
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/Memory.c
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/Platform.c
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/SecMain.c
> create mode 100644 Silicon/Sophgo/SG2042Pkg/Sec/SecEntry.S
>
> diff --git a/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.inf b/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.inf
> new file mode 100644
> index 000000000000..3b4d6d6b86bc
> --- /dev/null
> +++ b/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.inf
> @@ -0,0 +1,68 @@
> +## @file
> +# SEC Driver for RISC-V
> +#
> +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
> +# Copyright (c) 2023, Academy of Intelligent Innovation, Shandong Universiy, China.P.R. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> + INF_VERSION = 0x0001001B
> + BASE_NAME = SecMainRiscV64
> + FILE_GUID = 125E1236-9D4F-457B-BF7E-6311C88A1621
> + MODULE_TYPE = SEC
> + VERSION_STRING = 1.0
> + ENTRY_POINT = SecMain
> +
> +#
> +# The following information is for reference only and not required by the build tools.
> +#
> +# VALID_ARCHITECTURES = RISCV64
> +#
> +
> +[Sources]
> + SecEntry.S
> + SecMain.c
> + SecMain.h
> + Cpu.c
> + Memory.c
> + Platform.c
> +
> +[Packages]
> + EmbeddedPkg/EmbeddedPkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + UefiCpuPkg/UefiCpuPkg.dec
> + Silicon/Sophgo/SG2042Pkg/SG2042Pkg.dec
> + Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec
> +
> +[LibraryClasses]
> + BaseLib
> + DebugLib
> + PcdLib
> + IoLib
> + PeCoffLib
> + LzmaDecompressLib
> + RiscVSbiLib
> + PrePiLib
> + FdtLib
> + MemoryAllocationLib
> + HobLib
> + SerialPortLib
> +
> +[FixedPcd]
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRiscVDxeFvBase ## CONSUMES
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdRiscVDxeFvSize ## CONSUMES
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFirmwareRegionBaseAddress ## CONSUMES
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdVariableFirmwareRegionSize ## CONSUMES
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdTemporaryRamBase ## CONSUMES
> + gUefiRiscVPlatformPkgTokenSpaceGuid.PcdTemporaryRamSize ## CONSUMES
> +
> +[Guids]
> + gFdtHobGuid ## PRODUCES
> +
> +[BuildOptions]
> + GCC:*_*_*_PP_FLAGS = -D__ASSEMBLY__
> +
> diff --git a/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.h b/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.h
> new file mode 100644
> index 000000000000..9d615e9fa6a1
> --- /dev/null
> +++ b/Silicon/Sophgo/SG2042Pkg/Sec/SecMain.h
> @@ -0,0 +1,104 @@
> +/** @file
> + Master header file for SecCore.
> +
> + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.<BR>
> + Copyright (c) 2023, Academy of Intelligent Innovation, Shandong Universiy, China.P.R. All rights reserved.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef SEC_MAIN_H_
> +#define SEC_MAIN_H_
> +
> +#include <PiPei.h>
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugAgentLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/ExtractGuidedSectionLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/HobLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PeCoffExtraActionLib.h>
> +#include <Library/PeCoffGetEntryPointLib.h>
> +#include <Library/PeCoffLib.h>
> +#include <Library/PeiServicesLib.h>
> +#include <Library/PeiServicesTablePointerLib.h>
> +#include <Library/DebugPrintErrorLevelLib.h>
> +#include <Library/PrintLib.h>
> +#include <Library/BaseRiscVSbiLib.h>
> +#include <Library/PrePiLib.h>
> +#include <Library/PrePiHobListPointerLib.h>
> +#include <Library/SerialPortLib.h>
> +#include <Register/RiscV64/RiscVImpl.h>
> +
> +/**
> + Entry point to the C language phase of SEC. After the SEC assembly
> + code has initialized some temporary memory and set up the stack,
> + the control is transferred to this function.
> +
> + @param SizeOfRam Size of the temporary memory available for use.
> + @param TempRamBase Base address of temporary ram
> + @param BootFirmwareVolume Base address of the Boot Firmware Volume.
> +**/
> +VOID
> +NORETURN
> +EFIAPI
> +SecStartup (
> + IN UINTN BootHartId,
> + IN VOID *DeviceTreeAddress
> + );
> +
> +/**
> + Auto-generated function that calls the library constructors for all of the module's
> + dependent libraries. This function must be called by the SEC Core once a stack has
> + been established.
> +
> +**/
> +VOID
> +EFIAPI
> +ProcessLibraryConstructorList (
> + VOID
> + );
> +
> +/**
> + Perform Platform PEIM initialization.
> +
> + @return EFI_SUCCESS The platform initialized successfully.
> + @retval Others - As the error code indicates
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +PlatformPeimInitialization (
> + IN VOID *DeviceTreeAddress
> + );
> +
> +/**
> + Perform Memory PEIM initialization.
> +
> + @param DeviceTreeAddress Pointer to FDT.
> + @return EFI_SUCCESS The platform initialized successfully.
> + @retval Others - As the error code indicates
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +MemoryPeimInitialization (
> + IN VOID *DeviceTreeAddress
> + );
> +
> +/**
> + Perform CPU PEIM initialization.
> +
> + @return EFI_SUCCESS The platform initialized successfully.
> + @retval Others - As the error code indicates
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +CpuPeimInitialization (
> + VOID
> + );
> +
> +#endif
> diff --git a/Silicon/Sophgo/SG2042Pkg/Sec/Cpu.c b/Silicon/Sophgo/SG2042Pkg/Sec/Cpu.c
> new file mode 100644
> index 000000000000..c72bafdcc478
> --- /dev/null
> +++ b/Silicon/Sophgo/SG2042Pkg/Sec/Cpu.c
> @@ -0,0 +1,29 @@
> +/** @file
> +The library call to pass the device tree to DXE via HOB.
> +
> +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
> +
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiPei.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +
> +/**
> + Cpu Peim initialization.
> +
> +**/
> +EFI_STATUS
> +CpuPeimInitialization (
> + VOID
> + )
> +{
> + //
> + // for MMU type >= sv39
> + //
> + BuildCpuHob (40, 39);
> +
> + return EFI_SUCCESS;
> +}
> diff --git a/Silicon/Sophgo/SG2042Pkg/Sec/Memory.c b/Silicon/Sophgo/SG2042Pkg/Sec/Memory.c
> new file mode 100644
> index 000000000000..3fa4df148ad2
> --- /dev/null
> +++ b/Silicon/Sophgo/SG2042Pkg/Sec/Memory.c
> @@ -0,0 +1,347 @@
> +/** @file
> + Memory Detection for SG2042 EVB.
> +
> + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
> + Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) 2023, Academy of Intelligent Innovation, Shandong Universiy, China.P.R. All rights reserved.<BR>
> +
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +Module Name:
> +
> + MemDetect.c
> +
> +**/
> +
> +#include <PiPei.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PeimEntryPoint.h>
> +#include <Library/ResourcePublicationLib.h>
> +#include <Register/RiscV64/RiscVEncoding.h>
> +#include <Library/PrePiLib.h>
> +#include <libfdt.h>
> +#include <Guid/FdtHob.h>
> +
> +VOID
> +BuildMemoryTypeInformationHob (
> + VOID
> + );
> +
> +/**
> + Create memory range resource HOB using the memory base
> + address and size.
> +
> + @param MemoryBase Memory range base address.
> + @param MemorySize Memory range size.
> +
> +**/
> +STATIC
> +VOID
> +AddMemoryBaseSizeHob (
> + IN EFI_PHYSICAL_ADDRESS MemoryBase,
> + IN UINT64 MemorySize
> + )
> +{
> + BuildResourceDescriptorHob (
> + EFI_RESOURCE_SYSTEM_MEMORY,
> + EFI_RESOURCE_ATTRIBUTE_PRESENT |
> + EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
> + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> + EFI_RESOURCE_ATTRIBUTE_TESTED,
> + MemoryBase,
> + MemorySize
> + );
> +}
> +
> +/**
> + Create memory range resource HOB using memory base
> + address and top address of the memory range.
> +
> + @param MemoryBase Memory range base address.
> + @param MemoryLimit Memory range size.
> +
> +**/
> +STATIC
> +VOID
> +AddMemoryRangeHob (
> + IN EFI_PHYSICAL_ADDRESS MemoryBase,
> + IN EFI_PHYSICAL_ADDRESS MemoryLimit
> + )
> +{
> + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
> +}
> +
> +/**
> + Publish system RAM and reserve memory regions.
> +
> +**/
> +STATIC
> +VOID
> +InitializeRamRegions (
> + IN EFI_PHYSICAL_ADDRESS SystemMemoryBase,
> + IN UINT64 SystemMemorySize
> + )
> +{
> + AddMemoryRangeHob (
> + SystemMemoryBase,
> + SystemMemoryBase + SystemMemorySize
> + );
> +}
> +
> +/** Get the number of cells for a given property
> +
> + @param[in] Fdt Pointer to Device Tree (DTB)
> + @param[in] Node Node
> + @param[in] Name Name of the property
> +
> + @return Number of cells.
> +**/
> +STATIC
> +INT32
> +GetNumCells (
> + IN VOID *Fdt,
> + IN INT32 Node,
> + IN CONST CHAR8 *Name
> + )
> +{
> + CONST INT32 *Prop;
> + INT32 Len;
> + UINT32 Val;
> +
> + Prop = fdt_getprop (Fdt, Node, Name, &Len);
> + if (Prop == NULL) {
> + return Len;
> + }
> +
> + if (Len != sizeof (*Prop)) {
> + return -FDT_ERR_BADNCELLS;
> + }
> +
> + Val = fdt32_to_cpu (*Prop);
> + if (Val > FDT_MAX_NCELLS) {
> + return -FDT_ERR_BADNCELLS;
> + }
> +
> + return (INT32)Val;
> +}
> +
> +/** Mark reserved memory ranges in the EFI memory map
> +
> + * As per DT spec v0.4 Section 3.5.4,
> + * "Reserved regions with the no-map property must be listed in the
> + * memory map with type EfiReservedMemoryType. All other reserved
> + * regions must be listed with type EfiBootServicesData."
> +
> + @param FdtPointer Pointer to FDT
> +
> +**/
> +STATIC
> +VOID
> +AddReservedMemoryMap (
> + IN VOID *FdtPointer
> + )
> +{
> + CONST INT32 *RegProp;
> + INT32 Node;
> + INT32 SubNode;
> + INT32 Len;
> + EFI_PHYSICAL_ADDRESS Addr;
> + UINT64 Size;
> + INTN NumRsv, i;
> + INT32 NumAddrCells, NumSizeCells;
> +
> + NumRsv = fdt_num_mem_rsv (FdtPointer);
> +
> + /* Look for an existing entry and add it to the efi mem map. */
> + for (i = 0; i < NumRsv; i++) {
> + if (fdt_get_mem_rsv (FdtPointer, i, &Addr, &Size) != 0) {
> + continue;
> + }
> +
> + BuildMemoryAllocationHob (
> + Addr,
> + Size,
> + EfiReservedMemoryType
> + );
> + }
> +
> + /* process reserved-memory */
> + Node = fdt_subnode_offset (FdtPointer, 0, "reserved-memory");
> + if (Node >= 0) {
> + NumAddrCells = GetNumCells (FdtPointer, Node, "#address-cells");
> + if (NumAddrCells <= 0) {
> + return;
> + }
> +
> + NumSizeCells = GetNumCells (FdtPointer, Node, "#size-cells");
> + if (NumSizeCells <= 0) {
> + return;
> + }
> +
> + fdt_for_each_subnode (SubNode, FdtPointer, Node) {
> + RegProp = fdt_getprop (FdtPointer, SubNode, "reg", &Len);
> +
> + if ((RegProp != 0) && (Len == ((NumAddrCells + NumSizeCells) * sizeof (INT32)))) {
> + Addr = fdt32_to_cpu (RegProp[0]);
> +
> + if (NumAddrCells > 1) {
> + Addr = (Addr << 32) | fdt32_to_cpu (RegProp[1]);
> + }
> +
> + RegProp += NumAddrCells;
> + Size = fdt32_to_cpu (RegProp[0]);
> +
> + if (NumSizeCells > 1) {
> + Size = (Size << 32) | fdt32_to_cpu (RegProp[1]);
> + }
> +
> + DEBUG ((
> + DEBUG_INFO,
> + "%a: Adding Reserved Memory Addr = 0x%llx, Size = 0x%llx\n",
> + __func__,
> + Addr,
> + Size
> + ));
> +
> + if (fdt_getprop (FdtPointer, SubNode, "no-map", &Len)) {
Ensure you document that OpenSBI 1.3/1.3.1 should be used which fixed
its no-map issue. Otherwise, you can get into some issues in linux
kernel.
Acked-by: Sunil V L <sunilvl@ventanamicro.com>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108711): https://edk2.groups.io/g/devel/message/108711
Mute This Topic: https://groups.io/mt/101213494/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-09-15 10:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 10:25 [edk2-devel] [PATCH v3 0/8] EDK2 on RISC-V Sophgo SG2042 platform caiyuqing_hz
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 1/8] Sophgo/SG2042Pkg: Add SmbiosPlatformDxe module caiyuqing_hz
2023-09-15 10:36 ` Sunil V L
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 2/8] Sophgo/SG2042Pkg: Add PlatformUpdateMmuDxe module caiyuqing_hz
2023-09-15 10:41 ` Sunil V L
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 3/8] Sophgo/SG2042Pkg: Add Sophgo SDHCI driver caiyuqing_hz
2023-09-15 10:47 ` Sunil V L
2023-09-15 14:23 ` Leif Lindholm
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 4/8] Sophgo/SG2042Pkg: Add base MMC driver caiyuqing_hz
2023-09-15 10:53 ` Sunil V L
2023-09-15 14:25 ` Leif Lindholm
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 5/8] Sophgo/SG2042Pkg: Add SEC module caiyuqing_hz
2023-09-15 10:57 ` Sunil V L [this message]
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 6/8] Sophgo/SG2042_EVB_Board: Add Sophgo SG2042 platform caiyuqing_hz
2023-09-15 11:03 ` Sunil V L
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 7/8] Sophgo/SG2042Pkg: Add SG2042Pkg caiyuqing_hz
2023-09-07 10:25 ` [edk2-devel] [PATCH v3 8/8] Sophgo/SG2042Pkg: Add platform readme and document caiyuqing_hz
2023-09-15 10:35 ` [edk2-devel] [PATCH v3 0/8] EDK2 on RISC-V Sophgo SG2042 platform Sunil V L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZQQ4i3aCjM3d6lVY@sunil-laptop \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox