blob: 644e6baa1579787bf562b404ee2fcdc1ff595a04 [file] [log] [blame]
Bin Meng055700e2018-09-26 06:55:14 -07001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2015 Regents of the University of California
4 *
5 * Taken from Linux arch/riscv/include/asm/csr.h
6 */
7
8#ifndef _ASM_RISCV_CSR_H
9#define _ASM_RISCV_CSR_H
10
Baruch Siach401885a2018-11-11 12:31:01 +020011#include <linux/const.h>
12
Bin Meng055700e2018-09-26 06:55:14 -070013/* Status register flags */
14#define SR_SIE _AC(0x00000002, UL) /* Supervisor Interrupt Enable */
15#define SR_SPIE _AC(0x00000020, UL) /* Previous Supervisor IE */
16#define SR_SPP _AC(0x00000100, UL) /* Previously Supervisor */
17#define SR_SUM _AC(0x00040000, UL) /* Supervisor access User Memory */
18
19#define SR_FS _AC(0x00006000, UL) /* Floating-point Status */
20#define SR_FS_OFF _AC(0x00000000, UL)
21#define SR_FS_INITIAL _AC(0x00002000, UL)
22#define SR_FS_CLEAN _AC(0x00004000, UL)
23#define SR_FS_DIRTY _AC(0x00006000, UL)
24
25#define SR_XS _AC(0x00018000, UL) /* Extension Status */
26#define SR_XS_OFF _AC(0x00000000, UL)
27#define SR_XS_INITIAL _AC(0x00008000, UL)
28#define SR_XS_CLEAN _AC(0x00010000, UL)
29#define SR_XS_DIRTY _AC(0x00018000, UL)
30
31#ifndef CONFIG_64BIT
32#define SR_SD _AC(0x80000000, UL) /* FS/XS dirty */
33#else
34#define SR_SD _AC(0x8000000000000000, UL) /* FS/XS dirty */
35#endif
36
37/* SATP flags */
38#if __riscv_xlen == 32
39#define SATP_PPN _AC(0x003FFFFF, UL)
40#define SATP_MODE_32 _AC(0x80000000, UL)
41#define SATP_MODE SATP_MODE_32
42#else
43#define SATP_PPN _AC(0x00000FFFFFFFFFFF, UL)
44#define SATP_MODE_39 _AC(0x8000000000000000, UL)
45#define SATP_MODE SATP_MODE_39
46#endif
47
48/* Interrupt Enable and Interrupt Pending flags */
Lukas Auera3596652019-03-17 19:28:37 +010049#define MIE_MSIE _AC(0x00000008, UL) /* Software Interrupt Enable */
Bin Meng055700e2018-09-26 06:55:14 -070050#define SIE_SSIE _AC(0x00000002, UL) /* Software Interrupt Enable */
51#define SIE_STIE _AC(0x00000020, UL) /* Timer Interrupt Enable */
52
53#define EXC_INST_MISALIGNED 0
54#define EXC_INST_ACCESS 1
55#define EXC_BREAKPOINT 3
56#define EXC_LOAD_ACCESS 5
57#define EXC_STORE_ACCESS 7
58#define EXC_SYSCALL 8
59#define EXC_INST_PAGE_FAULT 12
60#define EXC_LOAD_PAGE_FAULT 13
61#define EXC_STORE_PAGE_FAULT 15
62
63#ifndef __ASSEMBLY__
64
Bin Meng9e9e6fe2018-12-12 06:12:39 -080065#define xcsr(csr) #csr
66
Bin Meng055700e2018-09-26 06:55:14 -070067#define csr_swap(csr, val) \
68({ \
69 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -080070 __asm__ __volatile__ ("csrrw %0, " xcsr(csr) ", %1" \
Bin Meng055700e2018-09-26 06:55:14 -070071 : "=r" (__v) : "rK" (__v) \
72 : "memory"); \
73 __v; \
74})
75
76#define csr_read(csr) \
77({ \
78 register unsigned long __v; \
Bin Meng9e9e6fe2018-12-12 06:12:39 -080079 __asm__ __volatile__ ("csrr %0, " xcsr(csr) \
Bin Meng055700e2018-09-26 06:55:14 -070080 : "=r" (__v) : \
81 : "memory"); \
82 __v; \
83})
84
85#define csr_write(csr, val) \
86({ \
87 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -080088 __asm__ __volatile__ ("csrw " xcsr(csr) ", %0" \
Bin Meng055700e2018-09-26 06:55:14 -070089 : : "rK" (__v) \
90 : "memory"); \
91})
92
93#define csr_read_set(csr, val) \
94({ \
95 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -080096 __asm__ __volatile__ ("csrrs %0, " xcsr(csr) ", %1" \
Bin Meng055700e2018-09-26 06:55:14 -070097 : "=r" (__v) : "rK" (__v) \
98 : "memory"); \
99 __v; \
100})
101
102#define csr_set(csr, val) \
103({ \
104 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -0800105 __asm__ __volatile__ ("csrs " xcsr(csr) ", %0" \
Bin Meng055700e2018-09-26 06:55:14 -0700106 : : "rK" (__v) \
107 : "memory"); \
108})
109
110#define csr_read_clear(csr, val) \
111({ \
112 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -0800113 __asm__ __volatile__ ("csrrc %0, " xcsr(csr) ", %1" \
Bin Meng055700e2018-09-26 06:55:14 -0700114 : "=r" (__v) : "rK" (__v) \
115 : "memory"); \
116 __v; \
117})
118
119#define csr_clear(csr, val) \
120({ \
121 unsigned long __v = (unsigned long)(val); \
Bin Meng9e9e6fe2018-12-12 06:12:39 -0800122 __asm__ __volatile__ ("csrc " xcsr(csr) ", %0" \
Bin Meng055700e2018-09-26 06:55:14 -0700123 : : "rK" (__v) \
124 : "memory"); \
125})
126
127#endif /* __ASSEMBLY__ */
128
129#endif /* _ASM_RISCV_CSR_H */