Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions arch/riscv/Kconfig.isa
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ config RISCV_ISA_EXT_ZICSR
The "Zicsr" extension introduces support for the full set of CSR
instructions that operate on CSRs registers.

config RISCV_ISA_EXT_SMCSRIND
bool
select RISCV_ISA_EXT_ZICSR
help
(Smcsrind) - Standard Extension for Indirect CSR Access

The Smcsrind extension provides indirect access to CSRs through
the MISELECT and MIREG registers.

config RISCV_ISA_EXT_ZIFENCEI
bool
help
Expand Down
40 changes: 40 additions & 0 deletions include/zephyr/arch/riscv/csr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in include/zephyr/arch/riscv/csr.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

include/zephyr/arch/riscv/csr.h:1 License file for 'SHL-0.51' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.
* Copyright (c) 2020 Michael Schaffner
* Copyright (c) 2020 BayLibre, SAS
*
Expand Down Expand Up @@ -233,4 +233,44 @@
: "memory"); \
})

#ifdef CONFIG_RISCV_ISA_EXT_SMCSRIND

#define MISELECT 0x350
#define MIREG 0x351
#define MIREG2 0x352
#define MIREG3 0x353
#define MIREG4 0x355
#define MIREG5 0x356
#define MIREG6 0x357

static inline unsigned long icsr_read(unsigned int index)
{
csr_write(MISELECT, index);
return csr_read(MIREG);
}

static inline void icsr_write(unsigned int index, unsigned long value)
{
csr_write(MISELECT, index);
csr_write(MIREG, value);
}

static inline unsigned long icsr_read_set(unsigned int index, unsigned long mask)
{
unsigned long val = icsr_read(index);

icsr_write(index, val | mask);
return val;
}

static inline unsigned long icsr_read_clear(unsigned int index, unsigned long mask)
{
unsigned long val = icsr_read(index);

icsr_write(index, val & ~mask);
return val;
}

#endif /* CONFIG_RISCV_ISA_EXT_SMCSRIND */

#endif /* CSR_H_ */
Loading