xref: /kvm-unit-tests/lib/riscv/asm/processor.h (revision 17f6f2fd17935eb5e564f621c71244b4a3ddeafb)
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 	exception_fn exception_handlers[EXCEPTION_CAUSE_MAX];
17 	exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX];
18 };
19 
20 static inline struct thread_info *current_thread_info(void)
21 {
22 	return (struct thread_info *)csr_read(CSR_SSCRATCH);
23 }
24 
25 static inline void local_irq_enable(void)
26 {
27 	csr_set(CSR_SSTATUS, SR_SIE);
28 }
29 
30 static inline void local_irq_disable(void)
31 {
32 	csr_clear(CSR_SSTATUS, SR_SIE);
33 }
34 
35 static inline void local_ipi_enable(void)
36 {
37 	csr_set(CSR_SIE, IE_SSIE);
38 }
39 
40 static inline void local_ipi_disable(void)
41 {
42 	csr_clear(CSR_SIE, IE_SSIE);
43 }
44 
45 static inline void ipi_ack(void)
46 {
47 	csr_clear(CSR_SIP, IE_SSIE);
48 }
49 
50 void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *));
51 void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *));
52 void do_handle_exception(struct pt_regs *regs);
53 void thread_info_init(void);
54 void local_hart_init(void);
55 
56 void show_regs(struct pt_regs *regs);
57 
58 #endif /* _ASMRISCV_PROCESSOR_H_ */
59