1386561f8SAndrew Jones /* SPDX-License-Identifier: GPL-2.0-only */ 2386561f8SAndrew Jones #ifndef _ASMRISCV_PROCESSOR_H_ 3386561f8SAndrew Jones #define _ASMRISCV_PROCESSOR_H_ 4386561f8SAndrew Jones #include <asm/csr.h> 5386561f8SAndrew Jones #include <asm/ptrace.h> 6386561f8SAndrew Jones 7c20c0aa7SJames Raphael Tiovalen #define EXCEPTION_CAUSE_MAX 24 8a3c0b550SAndrew Jones #define INTERRUPT_CAUSE_MAX 16 9386561f8SAndrew Jones 10386561f8SAndrew Jones typedef void (*exception_fn)(struct pt_regs *); 11386561f8SAndrew Jones 12386561f8SAndrew Jones struct thread_info { 13386561f8SAndrew Jones int cpu; 14386561f8SAndrew Jones unsigned long hartid; 15db0ae91cSAndrew Jones unsigned long isa[1]; 16*50fab1a5SAndrew Jones unsigned long sp; 17386561f8SAndrew Jones exception_fn exception_handlers[EXCEPTION_CAUSE_MAX]; 18a3c0b550SAndrew Jones exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX]; 19386561f8SAndrew Jones }; 20386561f8SAndrew Jones current_thread_info(void)21386561f8SAndrew Jonesstatic inline struct thread_info *current_thread_info(void) 22386561f8SAndrew Jones { 23386561f8SAndrew Jones return (struct thread_info *)csr_read(CSR_SSCRATCH); 24386561f8SAndrew Jones } 25386561f8SAndrew Jones local_irq_enable(void)26a3c0b550SAndrew Jonesstatic inline void local_irq_enable(void) 27a3c0b550SAndrew Jones { 28a3c0b550SAndrew Jones csr_set(CSR_SSTATUS, SR_SIE); 29a3c0b550SAndrew Jones } 30a3c0b550SAndrew Jones local_irq_disable(void)31a3c0b550SAndrew Jonesstatic inline void local_irq_disable(void) 32a3c0b550SAndrew Jones { 33a3c0b550SAndrew Jones csr_clear(CSR_SSTATUS, SR_SIE); 34a3c0b550SAndrew Jones } 35a3c0b550SAndrew Jones local_ipi_enable(void)3670df1827SAndrew Jonesstatic inline void local_ipi_enable(void) 3770df1827SAndrew Jones { 3870df1827SAndrew Jones csr_set(CSR_SIE, IE_SSIE); 3970df1827SAndrew Jones } 4070df1827SAndrew Jones local_ipi_disable(void)4170df1827SAndrew Jonesstatic inline void local_ipi_disable(void) 4270df1827SAndrew Jones { 4370df1827SAndrew Jones csr_clear(CSR_SIE, IE_SSIE); 4470df1827SAndrew Jones } 4570df1827SAndrew Jones ipi_ack(void)4670df1827SAndrew Jonesstatic inline void ipi_ack(void) 4770df1827SAndrew Jones { 4870df1827SAndrew Jones csr_clear(CSR_SIP, IE_SSIE); 4970df1827SAndrew Jones } 5070df1827SAndrew Jones 51386561f8SAndrew Jones void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)); 52a3c0b550SAndrew Jones void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)); 53386561f8SAndrew Jones void do_handle_exception(struct pt_regs *regs); 54386561f8SAndrew Jones void thread_info_init(void); 5594ca1aafSAndrew Jones void local_hart_init(void); 56386561f8SAndrew Jones 57386561f8SAndrew Jones void show_regs(struct pt_regs *regs); 58386561f8SAndrew Jones 59386561f8SAndrew Jones #endif /* _ASMRISCV_PROCESSOR_H_ */ 60