From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web09.2629.1641618535879190538 for ; Fri, 07 Jan 2022 21:08:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=X7bx8UD5; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=000704d8ca=abner.chang@hpe.com) Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2083XYZl021038 for ; Sat, 8 Jan 2022 05:08:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=fbLnd8mc818MdrEptDRndz3yj59oR0tTmriJL0ApVq0=; b=X7bx8UD5PHW54f5FpZqNgWLULjxL6O2WCXFLezMe5hyodKrJ4dmu8QFFQ/cuLpt6RfUl sWHRrqHEEVc8I4R+ONZzZ6Y7xcZj19vipnXtpPXnggu1VY2nAqIfx+YRKleYiNhwCdjS mOh0+Zwo2Nli8DtHXDIzbL/hcX2O52fyx8kqCdGRwMGA/DM0NVlfi5q83zW8S1sVG5CI Qje+PvaCC+BVNR8L3wHJMyOye0UI1eryTDZ0TAIfJR80C839VOkeEgP6VJ2QIPs6O5+V 6RTDtIuwHuh+81qnuN4f3hqrYymIuZ+PrSbO7Jg1Dfer3wNBEywc3Mcy0ywB4HkYal2G Hg== Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25]) by mx0a-002e3701.pphosted.com (PPS) with ESMTPS id 3df2tk0b1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 08 Jan 2022 05:08:55 +0000 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 85F4585 for ; Sat, 8 Jan 2022 05:08:54 +0000 (UTC) Received: from UB16Abner.asiapacific.hpqcorp.net (ub16abner.asiapacific.hpqcorp.net [15.119.209.229]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id CD9B636; Sat, 8 Jan 2022 05:08:53 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com Subject: [PATCH 01/79] ProcessorPkg/Include: Add header files of RISC-V processor package Date: Sat, 8 Jan 2022 12:07:53 +0800 Message-Id: <20220108040753.15926-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 470hDF1HTq-HZ0DTj_6KZN3IHA1gOi-t X-Proofpoint-GUID: 470hDF1HTq-HZ0DTj_6KZN3IHA1gOi-t X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-08_01,2022-01-07_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 suspectscore=0 impostorscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201080035 Content-Transfer-Encoding: quoted-printable (This is migrated from edk2-platforms:Silicon/RISC-V) RISC-V processor package library definitions. IndustryStandard/RiscV.h -Add RiscV.h which conform with RISC-V Privilege Spec v1.10. RiscVImpl.h -Definition of EDK2 RISC-V implementation. Signed-off-by: Abner Chang Co-authored-by: Daniel Schaefer Co-authored-by: Gilbert Chen Reviewed-by: Leif Lindholm Cc: Leif Lindholm Cc: Gilbert Chen --- .../Include/IndustryStandard/RiscV.h | 156 ++++++++++++++++++ .../RISC-V/ProcessorPkg/Include/RiscVImpl.h | 87 ++++++++++ 2 files changed, 243 insertions(+) create mode 100644 Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/Ri= scV.h create mode 100644 Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h diff --git a/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h b= /Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h new file mode 100644 index 0000000000..2a992394ed --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/IndustryStandard/RiscV.h @@ -0,0 +1,156 @@ +/** @file=0D + RISC-V package definitions.=0D +=0D + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All right= s reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef RISCV_INDUSTRY_STANDARD_H_=0D +#define RISCV_INDUSTRY_STANDARD_H_=0D +=0D +#if defined (MDE_CPU_RISCV64)=0D +#define RISC_V_XLEN_BITS 64=0D +#else=0D +#endif=0D +=0D +#define RISC_V_ISA_ATOMIC_EXTENSION (0x00000001 << 0)=0D +#define RISC_V_ISA_BIT_OPERATION_EXTENSION (0x00000001 << 1)=0D +#define RISC_V_ISA_COMPRESSED_EXTENSION (0x00000001 << 2)=0D +#define RISC_V_ISA_DOUBLE_PRECISION_FP_EXTENSION (0x00000001 << 3)=0D +#define RISC_V_ISA_RV32E_ISA (0x00000001 << 4)=0D +#define RISC_V_ISA_SINGLE_PRECISION_FP_EXTENSION (0x00000001 << 5)=0D +#define RISC_V_ISA_ADDITIONAL_STANDARD_EXTENSION (0x00000001 << 6)=0D +#define RISC_V_ISA_RESERVED_1 (0x00000001 << 7)=0D +#define RISC_V_ISA_INTEGER_ISA_EXTENSION (0x00000001 << 8)=0D +#define RISC_V_ISA_DYNAMICALLY_TRANSLATED_LANGUAGE_EXTENSION (0x0000000= 1 << 9)=0D +#define RISC_V_ISA_RESERVED_2 (0x00000001 << 10)=0D +#define RISC_V_ISA_DECIMAL_FP_EXTENSION (0x00000001 << 11)=0D +#define RISC_V_ISA_INTEGER_MUL_DIV_EXTENSION (0x00000001 << 12)=0D +#define RISC_V_ISA_USER_LEVEL_INTERRUPT_SUPPORTED (0x00000001 << 13)=0D +#define RISC_V_ISA_RESERVED_3 (0x00000001 << 14)=0D +#define RISC_V_ISA_PACKED_SIMD_EXTENSION (0x00000001 << 15)=0D +#define RISC_V_ISA_QUAD_PRECISION_FP_EXTENSION (0x00000001 << 16)=0D +#define RISC_V_ISA_RESERVED_4 (0x00000001 << 17)=0D +#define RISC_V_ISA_SUPERVISOR_MODE_IMPLEMENTED (0x00000001 << 18)=0D +#define RISC_V_ISA_TRANSATIONAL_MEMORY_EXTENSION (0x00000001 << 19)=0D +#define RISC_V_ISA_USER_MODE_IMPLEMENTED (0x00000001 << 20)=0D +#define RISC_V_ISA_VECTOR_EXTENSION (0x00000001 << 21)=0D +#define RISC_V_ISA_RESERVED_5 (0x00000001 << 22)=0D +#define RISC_V_ISA_NON_STANDARD_EXTENSION (0x00000001 << 23)=0D +#define RISC_V_ISA_RESERVED_6 (0x00000001 << 24)=0D +#define RISC_V_ISA_RESERVED_7 (0x00000001 << 25)=0D +=0D +//=0D +// RISC-V CSR definitions.=0D +//=0D +//=0D +// Machine information=0D +//=0D +#define RISCV_CSR_MACHINE_MVENDORID 0xF11=0D +#define RISCV_CSR_MACHINE_MARCHID 0xF12=0D +#define RISCV_CSR_MACHINE_MIMPID 0xF13=0D +#define RISCV_CSR_MACHINE_HARRID 0xF14=0D +//=0D +// Machine Trap Setup.=0D +//=0D +#define RISCV_CSR_MACHINE_MSTATUS 0x300=0D +#define RISCV_CSR_MACHINE_MISA 0x301=0D +#define RISCV_CSR_MACHINE_MEDELEG 0x302=0D +#define RISCV_CSR_MACHINE_MIDELEG 0x303=0D +#define RISCV_CSR_MACHINE_MIE 0x304=0D +#define RISCV_CSR_MACHINE_MTVEC 0x305=0D +=0D +#define RISCV_TIMER_COMPARE_BITS 32=0D +//=0D +// Machine Timer and Counter.=0D +//=0D +//#define RISCV_CSR_MACHINE_MTIME 0x701=0D +//#define RISCV_CSR_MACHINE_MTIMEH 0x741=0D +//=0D +// Machine Trap Handling.=0D +//=0D +#define RISCV_CSR_MACHINE_MSCRATCH 0x340=0D +#define RISCV_CSR_MACHINE_MEPC 0x341=0D +#define RISCV_CSR_MACHINE_MCAUSE 0x342=0D + #define MACHINE_MCAUSE_EXCEPTION_ MASK 0x0f=0D + #define MACHINE_MCAUSE_INTERRUPT (RISC_V_XLEN_BITS - 1)=0D +#define RISCV_CSR_MACHINE_MBADADDR 0x343=0D +#define RISCV_CSR_MACHINE_MIP 0x344=0D +=0D +//=0D +// Machine Protection and Translation.=0D +//=0D +#define RISCV_CSR_MACHINE_MBASE 0x380=0D +#define RISCV_CSR_MACHINE_MBOUND 0x381=0D +#define RISCV_CSR_MACHINE_MIBASE 0x382=0D +#define RISCV_CSR_MACHINE_MIBOUND 0x383=0D +#define RISCV_CSR_MACHINE_MDBASE 0x384=0D +#define RISCV_CSR_MACHINE_MDBOUND 0x385=0D +=0D +//=0D +// Supervisor mode CSR.=0D +//=0D +#define RISCV_CSR_SUPERVISOR_SSTATUS 0x100=0D + #define SSTATUS_SIE_BIT_POSITION 1=0D + #define SSTATUS_SPP_BIT_POSITION 8=0D +#define RISCV_CSR_SUPERVISOR_SIE 0x104=0D +#define RISCV_CSR_SUPERVISOR_SSCRATCH 0x140=0D +#define RISCV_CSR_SUPERVISOR_SEPC 0x141=0D +#define RISCV_CSR_SUPERVISOR_SCAUSE 0x142=0D + #define SCAUSE_USER_SOFTWARE_INT 0=0D + #define SCAUSE_SUPERVISOR_SOFTWARE_INT 1=0D + #define SCAUSE_USER_TIMER_INT 4=0D + #define SCAUSE_SUPERVISOR_TIMER_INT 5=0D + #define SCAUSE_USER_EXTERNAL_INT 8=0D + #define SCAUSE_SUPERVISOR_EXTERNAL_INT 9=0D +#define RISCV_CSR_SUPERVISOR_STVAL 0x143=0D +#define RISCV_CSR_SUPERVISOR_SIP 0x144=0D +#define RISCV_CSR_SUPERVISOR_SATP 0x180=0D +=0D +#if defined (MDE_CPU_RISCV64)=0D + #define RISCV_SATP_MODE_MASK 0xF000000000000000=0D + #define RISCV_SATP_MODE_BIT_POSITION 60=0D +#endif=0D + #define RISCV_SATP_MODE_OFF 0=0D + #define RISCV_SATP_MODE_SV32 1=0D + #define RISCV_SATP_MODE_SV39 8=0D + #define RISCV_SATP_MODE_SV48 9=0D + #define RISCV_SATP_MODE_SV57 10=0D + #define RISCV_SATP_MODE_SV64 11=0D +=0D + #define SATP64_ASID_MASK 0x0FFFF00000000000=0D + #define SATP64_PPN_MASK 0x00000FFFFFFFFFFF=0D +=0D +#define RISCV_CAUSE_MISALIGNED_FETCH 0x0=0D +#define RISCV_CAUSE_FETCH_ACCESS 0x1=0D +#define RISCV_CAUSE_ILLEGAL_INSTRUCTION 0x2=0D +#define RISCV_CAUSE_BREAKPOINT 0x3=0D +#define RISCV_CAUSE_MISALIGNED_LOAD 0x4=0D +#define RISCV_CAUSE_LOAD_ACCESS 0x5=0D +#define RISCV_CAUSE_MISALIGNED_STORE 0x6=0D +#define RISCV_CAUSE_STORE_ACCESS 0x7=0D +#define RISCV_CAUSE_USER_ECALL 0x8=0D +#define RISCV_CAUSE_HYPERVISOR_ECALL 0x9=0D +#define RISCV_CAUSE_SUPERVISOR_ECALL 0xa=0D +#define RISCV_CAUSE_MACHINE_ECALL 0xb=0D +#define RISCV_CAUSE_FETCH_PAGE_FAULT 0xc=0D +#define RISCV_CAUSE_LOAD_PAGE_FAULT 0xd=0D +#define RISCV_CAUSE_STORE_PAGE_FAULT 0xf=0D +#define RISCV_CAUSE_FETCH_GUEST_PAGE_FAULT 0x14=0D +#define RISCV_CAUSE_LOAD_GUEST_PAGE_FAULT 0x15=0D +#define RISCV_CAUSE_STORE_GUEST_PAGE_FAULT 0x17=0D +=0D +//=0D +// Machine Read-Write Shadow of Hypervisor Read-Only Registers=0D +//=0D +#define RISCV_CSR_HTIMEW 0xB01=0D +#define RISCV_CSR_HTIMEHW 0xB81=0D +//=0D +// Machine Host-Target Interface (Non-Standard Berkeley Extension)=0D +//=0D +#define RISCV_CSR_MTOHOST 0x780=0D +#define RISCV_CSR_MFROMHOST 0x781=0D +=0D +#endif=0D diff --git a/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h b/Silicon/RISC= -V/ProcessorPkg/Include/RiscVImpl.h new file mode 100644 index 0000000000..14092df174 --- /dev/null +++ b/Silicon/RISC-V/ProcessorPkg/Include/RiscVImpl.h @@ -0,0 +1,87 @@ +/** @file=0D + RISC-V package definitions.=0D +=0D + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef RISCV_H_=0D +#define RISCV_H_=0D +=0D +#include =0D +#include =0D +=0D +#define _ASM_FUNC(Name, Section) \=0D + .global Name ; \=0D + .section #Section, "ax" ; \=0D + .type Name, %function ; \=0D + .p2align 2 ; \=0D + Name:=0D +=0D +#define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name)=0D +=0D +#if defined (MDE_CPU_RISCV64)=0D +typedef UINT64 RISC_V_REGS_PROTOTYPE;=0D +#else=0D +#endif=0D +=0D +//=0D +// Structure for 128-bit value=0D +//=0D +typedef struct {=0D + UINT64 Value64_L;=0D + UINT64 Value64_H;=0D +} RISCV_UINT128;=0D +=0D +#define RISCV_MACHINE_CONTEXT_SIZE 0x1000=0D +typedef struct _RISCV_MACHINE_MODE_CONTEXT RISCV_MACHINE_MODE_CONTEXT;=0D +=0D +///=0D +/// Exception handlers in context.=0D +///=0D +typedef struct _EXCEPTION_HANDLER_CONTEXT {=0D + EFI_PHYSICAL_ADDRESS InstAddressMisalignedHander;=0D + EFI_PHYSICAL_ADDRESS InstAccessFaultHander;=0D + EFI_PHYSICAL_ADDRESS IllegalInstHander;=0D + EFI_PHYSICAL_ADDRESS BreakpointHander;=0D + EFI_PHYSICAL_ADDRESS LoadAddrMisalignedHander;=0D + EFI_PHYSICAL_ADDRESS LoadAccessFaultHander;=0D + EFI_PHYSICAL_ADDRESS StoreAmoAddrMisalignedHander;=0D + EFI_PHYSICAL_ADDRESS StoreAmoAccessFaultHander;=0D + EFI_PHYSICAL_ADDRESS EnvCallFromUModeHander;=0D + EFI_PHYSICAL_ADDRESS EnvCallFromSModeHander;=0D + EFI_PHYSICAL_ADDRESS EnvCallFromHModeHander;=0D + EFI_PHYSICAL_ADDRESS EnvCallFromMModeHander;=0D +} EXCEPTION_HANDLER_CONTEXT;=0D +=0D +///=0D +/// Exception handlers in context.=0D +///=0D +typedef struct _INTERRUPT_HANDLER_CONTEXT {=0D + EFI_PHYSICAL_ADDRESS SoftwareIntHandler;=0D + EFI_PHYSICAL_ADDRESS TimerIntHandler;=0D +} INTERRUPT_HANDLER_CONTEXT;=0D +=0D +///=0D +/// Interrupt handlers in context.=0D +///=0D +typedef struct _TRAP_HANDLER_CONTEXT {=0D + EXCEPTION_HANDLER_CONTEXT ExceptionHandlerContext;=0D + INTERRUPT_HANDLER_CONTEXT IntHandlerContext;=0D +} TRAP_HANDLER_CONTEXT;=0D +=0D +///=0D +/// Machine mode context used for saveing hart-local context.=0D +///=0D +typedef struct _RISCV_MACHINE_MODE_CONTEXT {=0D + EFI_PHYSICAL_ADDRESS PeiService; /// PEI service.=0D + EFI_PHYSICAL_ADDRESS MachineModeTrapHandler; /// Machine mode trap ha= ndler.=0D + EFI_PHYSICAL_ADDRESS HypervisorModeTrapHandler; /// Hypervisor mode trap= handler.=0D + EFI_PHYSICAL_ADDRESS SupervisorModeTrapHandler; /// Supervisor mode trap= handler.=0D + EFI_PHYSICAL_ADDRESS UserModeTrapHandler; /// USer mode trap handl= er.=0D + TRAP_HANDLER_CONTEXT MModeHandler; /// Handler for machine = mode.=0D +} RISCV_MACHINE_MODE_CONTEXT;=0D +=0D +#endif=0D --=20 2.31.1