Commit Graph

174 Commits

Author SHA1 Message Date
Ville Juven
aacdbf2a3b risc-v/addrenv: Improve the commenting on struct arch_addrenv_s
I can never remember whether the static page table list contains the
table's physical or kernel virtual address.. Add the fact as a comment
there.

Also add the limitations that come from this static page table approach
for Sv32.
2023-11-02 21:52:23 +08:00
Stuart Ianna
ee84ea3875 arch/risc-v/litex/litex_gpio: Fix ISR dispatch when using higher GPIO indexes.
Previously, GPIO interrupts were not correctly mapped to the peripheral base register responsible for the interrupt.

Change the IRQ number calculation so the interrupts work correctly on all GPIO peripheral bases.
2023-10-25 15:42:25 +08:00
Lee Lup Yuen
856526adee arch/risc-v: Add support for StarFive JH7110 SoC
This PR adds support for the StarFive JH7110 RISC-V SoC. This will be used by the upcoming port of NuttX for PINE64 Star64 SBC. [The source files are explained in the articles here](https://github.com/lupyuen/nuttx-star64)

Modified Files in arch/risc-v:

Kconfig: Added ARCH_CHIP_JH7110 for JH7110 SoC

New Files in arch/risc-v:

include/jh7110/chip.h: JH7110 Definitions

include/jh7110/irq.h: Support 127 External Interrupts

src/jh7110/chip.h: Interrupt Stack Macro

src/jh7110/jh7110_allocateheap.c: Kernel Heap

src/jh7110/jh7110_head.S: Linux Header and Boot Code

src/jh7110/jh7110_irq.c: Configure Interrupts

src/jh7110/jh7110_irq_dispatch.c: Dispatch Interrupts

src/jh7110/jh7110_memorymap.h: Memory Map

src/jh7110/jh7110_mm_init.c, jh7110_mm_init.h: Memory Mgmt

src/jh7110/jh7110_pgalloc.c: Page Allocator

src/jh7110/jh7110_start.c: Startup Code

src/jh7110/jh7110_timerisr.c: Timer Interrupt

src/jh7110/hardware/jh7110_memorymap.h: PLIC Base Address

src/jh7110/hardware/jh7110_plic.h: PLIC Register Addresses

src/jh7110/Kconfig: JH7110 Config

src/jh7110/Make.defs: Makefile
2023-08-03 22:55:55 -07:00
Ville Juven
d0fbf9883d riscv/lazyfpu: Add option to disable lazy FPU
Adds option to use the old implementation where FPU is stored into
the process stack.
2023-07-31 07:48:53 -07:00
Ville Juven
b409d72e9d riscv/fpu: Restore correct lazy-FPU functionality
- Save the FPU registers into the tcb so they don't get lost if the stack
  frame for xcp.regs moves (as it does)
- Handle interger and FPU register save/load separately
- Integer registers are saved/loaded always, like before
- FPU registers are only saved during a context switch:
  - Save ONLY if FPU is dirty
  - Restore always if FPU has been used (not in FSTATE_OFF, FSTATE_INIT)
- Remove all lazy-FPU related logic from the macros, it is not needed
2023-07-31 07:48:53 -07:00
Lucas Saavedra Vaz
8aeba210e4 arch/risc-v/espressif: Add full GPIO support
Full GPIO support using Espressif's HAL
2023-06-24 13:11:45 +08:00
Masayuki Ishikawa
2c6ad5c2bf Revert "riscv/fpu: Restore correct lazy-FPU functionality"
This reverts commit 35c27b5a9a.
2023-06-20 06:17:11 +09:00
Masayuki Ishikawa
7410f4a6b8 Revert "riscv/lazyfpu: Add option to disable lazy FPU"
This reverts commit 425cc89989.
2023-06-20 06:17:11 +09:00
Ville Juven
425cc89989 riscv/lazyfpu: Add option to disable lazy FPU
Adds option to use the old implementation where FPU is stored into
the process stack.
2023-06-19 19:28:07 +08:00
Ville Juven
35c27b5a9a riscv/fpu: Restore correct lazy-FPU functionality
- Save the FPU registers into the tcb so they don't get lost if the stack
  frame for xcp.regs moves (as it does)
- Handle interger and FPU register save/load separately
- Integer registers are saved/loaded always, like before
- FPU registers are only saved during a context switch:
  - Save ONLY if FPU is dirty
  - Restore always if FPU has been used (not in FSTATE_OFF, FSTATE_INIT)
- Remove all lazy-FPU related logic from the macros, it is not needed
2023-06-19 19:28:07 +08:00
Ville Juven
9b5746cb5f riscv/barrier: Define more granular memory barriers
Separate barriers for full (memory + I/O) and local memory (cache) flushing.
2023-06-14 16:14:57 -03:00
Ville Juven
7bc8e59cce riscv/kernel_stack: Use kernel stack to store the user context
If a kernel stack exists, use that whenever the user process is in
privileged mode, i.e. running an exception or in system call. Previously
the exception context was stored into the user's stack, which is not ideal.

Why?

1. Because the exception entry status (REG_INT_CTX) is needed by the
   kernel, and this is now in user memory which requires that the correct
   user mappings are active when it is accessed.

2. The user must currently account for the exception stack frame (which
   is BIG) in its own stack allocation. Moving the exception context save
   to the kernel stack offloads this responsibility from the user to the
   kernel, which is IMO the correct behavior.

3. The kernel access to user memory is currently allowed without condition,
   however this is not ideal either. The privileged mode status CSR allows
   blocking access to user memory via the STATUS_SUM-bit, which should be
   disabled by default and only enabled when access to user space is really
   needed. This patch allows implementing such features.
2023-06-09 13:53:27 +08:00
zhangyuan21
89ae45be18 arch/risc-v: change up_saveusercontext to assembly code
minidump will backtrace failure when use C code to save user context,
because the stack push operation in C code can disrupt the stack information.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-27 17:34:30 +08:00
Stuart Ianna
4cae98674d litex: Support for kernel build with vexriscv-smp. 2023-04-22 01:40:32 +08:00
Stuart Ianna
01b0305ab5 risc-v: SV32 MMU support for qemu-rv. 2023-03-29 22:15:19 +09:00
Gustavo Henrique Nihei
17f7f6e86d risc-v: Add Espressif chip family support on top of esp-hal-3rdparty
Initially supporting ESP32-C3 chip, to be followed by other RISC-V-based
chips from Espressif.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-03-14 23:55:35 +01:00
Xiang Xiao
2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00
Eero Nurkkala
b9ba262fb7 risc-v/mpfs: add athena irq defines
Add the Athena cryptographic microprocessor irq defines.

Signed-off-by: Eero Nurkkala <eero.nurkkala@offcode.fi>
2023-02-15 00:21:03 +08:00
chenwen@espressif.com
cfc9029c5d risc-v/esp32c6: Add ESP32-C6 basic support
1. Bring up OS kernel.
  2. Add interrupt support.
  3. Add system timer support.
  4. Add the ESP32-C6 devkit board.
  5. Add basic UART support for console.
  6. Add clock configuration.
  7. Add board reset support.
2023-02-10 17:38:41 -03:00
Zhihong Chen
d082af34f7 add hpmicro chip: hpm6750
Signed-off-by: Zhihong Chen <zhihong.chen@hpmicro.com>
2023-02-09 14:17:49 +08:00
Lucas Saavedra Vaz
14d95eb131 arch/risc-v/esp32c3: Add RTC interrupt support 2023-02-08 10:42:19 +08:00
Ville Juven
f4b82b6405 sched/addrenv: Remove up_addrenv_restore
The function is not relevant any longer, remove it. Also remove
save_addrenv_t, the parameter taken by up_addrenv_restore.

Implement addrenv_select() / addrenv_restore() to handle the temporary
instantiation of address environments, e.g. when a process is being
created.
2023-02-08 02:51:23 +08:00
Alan Carvalho de Assis
e950e53df2 esp32c3: Always reserve CPU INT 0 and fix cpu init order
Co-author: Tiago Medicci <tiago.medicci@espressif.com>
Co-author: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-03 12:24:11 +08:00
Stuart Ianna
26ac5335e5 litex: Add GPIO driver.
GPIO driver with optional ISR support. Allows for multiple GPIO peripherals to be specified at an arbitrary addresses.
2023-02-01 11:02:03 +08:00
Ville Juven
42d0e356c2 arch/addrenv: Change group_addrenv_t to arch_addrenv_t
This is preparation for moving address environments out of the group
structure into the tcb.

Why move ? Because the group is destroyed very early in the exit phase,
but the MMU mappings are needed until the context switch to the next
process is complete. Otherwise the MMU will lose its mappings and the
system will crash.
2023-01-27 23:17:01 +08:00
Gustavo Henrique Nihei
80bbb0f24c esp32c3: Fix IRQ initialization, it was crashing on DEBUG_ASSERTIONS
Co-author: Alan C. Assis <alan.carvalho@espressif.com>
2023-01-27 13:15:39 +08:00
Stuart Ianna
34fdc3da0d litex: Allow custom peripheral memory mapping and IRQ. 2023-01-25 14:11:06 +08:00
Alan Carvalho de Assis
87a1f69a3c Modify the IRQ APIs to be compatible with ESP32/S2/S3 2022-12-31 12:47:41 +08:00
Huang Qi
f93964ad3c riscv: Dump trap val in exception handler
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-30 14:55:33 +08:00
Nathan Hartman
20bdd44e7b Remove executable permission from source and build files. 2022-08-04 12:48:18 -03:00
Xiang Xiao
9ab3417882 arch/risc-v: Move __XSTR, FLOAD/FSTORE and REGLOAD/REGSTORE to the right place
1.Move __XSTR from include/arch.h to include/irq.h
2.Move  FLOAD/FSTORE and REGLOAD/REGSTORE from include/arch.h to src/common/riscv_internal.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-04 13:25:56 +03:00
Xiang Xiao
c20ed58879 arch: Remove the inclusion of arch/irq.h from chip/irq.h
since arch/irq.h will include chip/irq.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-04 13:03:47 +03:00
Xiang Xiao
3d1ce144df arch: Move up_getsp from arch.h to irq.h
since all other special register operation in irq.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-01 10:44:55 -03:00
Richard Tucker
8f36649aad arch/risc-v/src/litex/litex_emac: add liteeth peripheral driver
See the following for details on the pepheral:
https://github.com/enjoy-digital/liteeth
2022-06-21 12:06:37 +03:00
Xiang Xiao
11e1a8b28b arch: Define WCHAR_[MIN|MAX] in arch/include/limits.h
follow up the below change:
commit 6357523892
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Mon Nov 1 12:40:51 2021 +0800

    arch: Add _wchar_t typedef like other basic types

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 22:25:49 +03:00
chao.an
3f65b562bb arch: inline up_interrupt_context()
inline the up_interrupt_context() to avoid unnecessary stack pushes

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-05-26 04:36:07 +08:00
Ville Juven
91063e85f0 risc-v/vfork: FPU was not saved correctly
The FPU register saving upon vfork entry was missing.

Also added macro that tells the actual size of an FPU reg, instead
of just having a coefficient for qfpu/no-qfpu.
2022-05-20 15:59:24 +08:00
Ville Juven
ef42b7c31e risc-v/irq: Add ABI name versions of FPU registers 2022-05-19 09:05:00 -03:00
Masayuki Ishikawa
5a9b2920e8 arch: risc-v: Add support for semihosting and hostfs
Summary:
- This commit adds support for semihosting and hostfs

Impact:
- None

Testing:
- Tested with nsh and nsh64 (defconfig will be updated later)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-05-02 19:46:58 +08:00
Xiang Xiao
1e23799455 arch/riscv: Optimize the syscall performance in kernel mode
by renaming riscv_dispatch_syscall to sys_callx, so the caller
don't need the immediate step(syscallx->riscv_dispatch_syscall)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-01 11:31:01 +03:00
Xiang Xiao
efce8bd198 Revert "arch/risc-v: use STACK_FRAME_SIZE for in S-mode syscall asm"
This reverts commit 9b7f9867aa.
2022-05-01 11:31:01 +03:00
Ville Juven
57127b9429 RISC-V: Initial support for CONFIG_BUILD_KERNEL
This implements initial support for kernel build (address environments,
page allocator) for RISC-V.

This is done a bit differently compared to the ARMV7 implementation:

- Support implemented for Sv39 MMU, however the implementation should be
  extensible for other MMU types also.
- Instead of preserving and moving the L1 references around, a canonical
  approach is used instead, where the page table base address register
  is switched upon context switch.
- To preserve a bit of memory, only a single L1/L2 table is supported,
  this gives access to 1GiB of virtual memory for each process, which
  should be more than enough.

Some things worth noting:
- Assumes page pool is mapped with vaddr=paddr mappings
- The CONFIG_ARCH_XXXX_VBASE and CONFIG_ARCH_XXXX_NPAGES values are
  ignored, with the exception of CONFIG_ARCH_DATA_VBASE which is used
  for ARCH_DATA_RESERVE
- ARCH_DATA_RESERVE is placed at the beginning of the userspace task's
  address environment
2022-04-29 02:02:15 +08:00
Ville Juven
d5ea259828 RISC-V: Combine 3 variables that depend on CPU amount into one
IRQ_NSTACKS, ARCH_CPU_COUNT, CONFIG_SMP_NCPUS all relate to each
other. However, a bit of clean up can be done and everything can
be merged into SMP_NCPUS.

The MPFS bootloader case works also as it requires only 1 IRQ stack
for the hart that executes as bootloader.
2022-04-12 01:59:35 +08:00
Huang Qi
4ebc581c73 esp32c3: Simplify irq dispatch logic
ESP32C3 use customized irq encoding so it's hard to share further code
with other risc-v based chips, in this patch, we keep the exception
number definition with risc-v spec.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-04-07 18:16:35 +02:00
Petro Karashchenko
9b7f9867aa arch/risc-v: use STACK_FRAME_SIZE for in S-mode syscall asm
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-04-04 12:05:53 +08:00
Xiang Xiao
e959775397 arch/riscv: Access [m|s]scratch through CSR_SCRATCH macro
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-02 14:08:37 +03:00
Xiang Xiao
629d9969dd arch/riscv: Rename riscv_syscall_dispatch to riscv_dispatch_syscall
follow other function naming(e.g. riscv_dispatch_irq)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-02 14:08:37 +03:00
Xiang Xiao
7a209e6ee8 arch/riscv: Align the macro definition in csr.h
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-02 14:08:37 +03:00
Ville Juven
c15b6701ce RISC-V: Implement option to run NuttX in supervisor mode (S-mode)
- Add config "ARCH_USE_S_MODE" which controls whether the kernel
  runs in M-mode or S-mode
- Add more MSTATUS and most of the SSTATUS register definitions
- Add more MIP flags for interrupt delegation
- Add handling of interrupts from S-mode
- Add handling of FPU from S-mode
- Add new context handling functions that are not dependent on the trap
  handlers / ecall

NOTE: S-mode requires a companion SW (SBI) which is not yet implemented,
      thus S-mode is not usable as is, yet.
2022-04-01 16:19:42 -03:00
Petro Karashchenko
870ca12146 arch/risc-v: get wider visibility for arch instruction macros
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-04-01 10:31:24 +08:00