xref: /kvm-unit-tests/lib/riscv/asm/processor.h (revision 71f7db53297d39b7d9b779d6ecbd49f0d8da1dfc)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _ASMRISCV_PROCESSOR_H_
3 #define _ASMRISCV_PROCESSOR_H_
4 #include <asm/csr.h>
5 #include <asm/ptrace.h>
6 
7 #define EXCEPTION_CAUSE_MAX	24
8 #define INTERRUPT_CAUSE_MAX	16
9 
10 typedef void (*exception_fn)(struct pt_regs *);
11 
12 struct thread_info {
13 	int cpu;
14 	unsigned long hartid;
15 	unsigned long isa[1];
16 	unsigned long sp;
17 	exception_fn exception_handlers[EXCEPTION_CAUSE_MAX];
18 	exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX];
19 };
20 
current_thread_info(void)21 static inline struct thread_info *current_thread_info(void)
22 {
23 	return (struct thread_info *)csr_read(CSR_SSCRATCH);
24 }
25 
local_irq_enable(void)26 static inline void local_irq_enable(void)
27 {
28 	csr_set(CSR_SSTATUS, SR_SIE);
29 }
30 
local_irq_disable(void)31 static inline void local_irq_disable(void)
32 {
33 	csr_clear(CSR_SSTATUS, SR_SIE);
34 }
35 
local_ipi_enable(void)36 static inline void local_ipi_enable(void)
37 {
38 	csr_set(CSR_SIE, IE_SSIE);
39 }
40 
local_ipi_disable(void)41 static inline void local_ipi_disable(void)
42 {
43 	csr_clear(CSR_SIE, IE_SSIE);
44 }
45 
ipi_ack(void)46 static inline void ipi_ack(void)
47 {
48 	csr_clear(CSR_SIP, IE_SSIE);
49 }
50 
51 void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *));
52 void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *));
53 void do_handle_exception(struct pt_regs *regs);
54 void thread_info_init(void);
55 void local_hart_init(void);
56 
57 void show_regs(struct pt_regs *regs);
58 
59 #endif /* _ASMRISCV_PROCESSOR_H_ */
60