all: run clang-format and update checked-in files

Noisy commit, no functional changes.

Generated with an current upstream clang-format and:

clang-format -i $(find . -name \*.[ch])

Signed-off-by: Olof Johansson <olof@lixom.net>
This commit is contained in:
Olof Johansson 2019-04-10 17:41:52 -07:00 committed by Anup Patel
parent fbf986ac2a
commit 10baa64c02
59 changed files with 943 additions and 1004 deletions

View file

@ -10,9 +10,9 @@
#include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_ecall_interface.h>
#define wfi() \ #define wfi() \
do { \ do { \
__asm__ __volatile__ ("wfi" ::: "memory"); \ __asm__ __volatile__("wfi" ::: "memory"); \
} while (0) } while (0)
void test_main(unsigned long a0, unsigned long a1) void test_main(unsigned long a0, unsigned long a1)
{ {

View file

@ -85,73 +85,80 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#define csr_swap(csr, val) \ #define csr_swap(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrw %0, " __ASM_STR(csr) ", %1"\ __asm__ __volatile__("csrrw %0, " __ASM_STR(csr) ", %1" \
: "=r" (__v) : "rK" (__v) \ : "=r"(__v) \
: "rK"(__v) \
: "memory"); \ : "memory"); \
__v; \ __v; \
}) })
#define csr_read(csr) \ #define csr_read(csr) \
({ \ ({ \
register unsigned long __v; \ register unsigned long __v; \
__asm__ __volatile__ ("csrr %0, " __ASM_STR(csr) \ __asm__ __volatile__("csrr %0, " __ASM_STR(csr) \
: "=r" (__v) : \ : "=r"(__v) \
: \
: "memory"); \ : "memory"); \
__v; \ __v; \
}) })
#define csr_write(csr, val) \ #define csr_write(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrw " __ASM_STR(csr) ", %0" \ __asm__ __volatile__("csrw " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \ : \
: "rK"(__v) \
: "memory"); \ : "memory"); \
}) })
#define csr_read_set(csr, val) \ #define csr_read_set(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrs %0, " __ASM_STR(csr) ", %1"\ __asm__ __volatile__("csrrs %0, " __ASM_STR(csr) ", %1" \
: "=r" (__v) : "rK" (__v) \ : "=r"(__v) \
: "rK"(__v) \
: "memory"); \ : "memory"); \
__v; \ __v; \
}) })
#define csr_set(csr, val) \ #define csr_set(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrs " __ASM_STR(csr) ", %0" \ __asm__ __volatile__("csrs " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \ : \
: "rK"(__v) \
: "memory"); \ : "memory"); \
}) })
#define csr_read_clear(csr, val) \ #define csr_read_clear(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrc %0, " __ASM_STR(csr) ", %1"\ __asm__ __volatile__("csrrc %0, " __ASM_STR(csr) ", %1" \
: "=r" (__v) : "rK" (__v) \ : "=r"(__v) \
: "rK"(__v) \
: "memory"); \ : "memory"); \
__v; \ __v; \
}) })
#define csr_clear(csr, val) \ #define csr_clear(csr, val) \
({ \ ({ \
unsigned long __v = (unsigned long)(val); \ unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrc " __ASM_STR(csr) ", %0" \ __asm__ __volatile__("csrc " __ASM_STR(csr) ", %0" \
: : "rK" (__v) \ : \
: "rK"(__v) \
: "memory"); \ : "memory"); \
}) })
unsigned long csr_read_num(int csr_num); unsigned long csr_read_num(int csr_num);
void csr_write_num(int csr_num, unsigned long val); void csr_write_num(int csr_num, unsigned long val);
#define wfi() \ #define wfi() \
do { \ do { \
__asm__ __volatile__ ("wfi" ::: "memory"); \ __asm__ __volatile__("wfi" ::: "memory"); \
} while (0) } while (0)
static inline int misa_extension(char ext) static inline int misa_extension(char ext)
{ {
@ -177,11 +184,11 @@ static inline void misa_string(char *out, unsigned int out_sz)
out++; out++;
} }
int pmp_set(unsigned int n, unsigned long prot, int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long addr, unsigned long log2len); unsigned long log2len);
int pmp_get(unsigned int n, unsigned long *prot_out, int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *addr_out, unsigned long *log2len_out); unsigned long *log2len_out);
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */

View file

@ -14,11 +14,12 @@ typedef struct {
volatile long counter; volatile long counter;
} atomic_t; } atomic_t;
#define ATOMIC_INIT(_lptr, val) \ #define ATOMIC_INIT(_lptr, val) (_lptr)->counter = (val)
(_lptr)->counter = (val)
#define ATOMIC_INITIALIZER(val) \ #define ATOMIC_INITIALIZER(val) \
{ .counter = (val), } { \
.counter = (val), \
}
long atomic_read(atomic_t *atom); long atomic_read(atomic_t *atom);

View file

@ -42,16 +42,16 @@
/* clang-format on */ /* clang-format on */
#define __smp_store_release(p, v) \ #define __smp_store_release(p, v) \
do { \ do { \
RISCV_FENCE(rw,w); \ RISCV_FENCE(rw, w); \
*(p) = (v); \ *(p) = (v); \
} while (0) } while (0)
#define __smp_load_acquire(p) \ #define __smp_load_acquire(p) \
({ \ ({ \
typeof(*p) ___p1 = *(p); \ typeof(*p) ___p1 = *(p); \
RISCV_FENCE(r,rw); \ RISCV_FENCE(r, rw); \
___p1; \ ___p1; \
}) })
#endif #endif

View file

@ -21,28 +21,49 @@
#ifdef __riscv_flen #ifdef __riscv_flen
#define GET_F32_REG(insn, pos, regs) ({ \ #define GET_F32_REG(insn, pos, regs) \
register s32 value asm("a0") = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ ({ \
register s32 value asm("a0") = \
SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \
ulong tmp; \ ulong tmp; \
asm ("1: auipc %0, %%pcrel_hi(get_f32_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp), "+&r"(value) :: "t0"); \ asm("1: auipc %0, %%pcrel_hi(get_f32_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" \
value; }) : "=&r"(tmp), "+&r"(value)::"t0"); \
#define SET_F32_REG(insn, pos, regs, val) ({ \ value; \
})
#define SET_F32_REG(insn, pos, regs, val) \
({ \
register u32 value asm("a0") = (val); \ register u32 value asm("a0") = (val); \
ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \
ulong tmp; \ ulong tmp; \
asm volatile ("1: auipc %0, %%pcrel_hi(put_f32_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp) : "r"(value), "r"(offset) : "t0"); }) asm volatile( \
"1: auipc %0, %%pcrel_hi(put_f32_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" \
: "=&r"(tmp) \
: "r"(value), "r"(offset) \
: "t0"); \
})
#define init_fp_reg(i) SET_F32_REG((i) << 3, 3, 0, 0) #define init_fp_reg(i) SET_F32_REG((i) << 3, 3, 0, 0)
#define GET_F64_REG(insn, pos, regs) ({ \ #define GET_F64_REG(insn, pos, regs) \
register ulong value asm("a0") = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ ({ \
register ulong value asm("a0") = \
SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \
ulong tmp; \ ulong tmp; \
asm ("1: auipc %0, %%pcrel_hi(get_f64_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp), "+&r"(value) :: "t0"); \ asm("1: auipc %0, %%pcrel_hi(get_f64_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" \
sizeof(ulong) == 4 ? *(int64_t*)value : (int64_t)value; }) : "=&r"(tmp), "+&r"(value)::"t0"); \
#define SET_F64_REG(insn, pos, regs, val) ({ \ sizeof(ulong) == 4 ? *(int64_t *)value : (int64_t)value; \
})
#define SET_F64_REG(insn, pos, regs, val) \
({ \
uint64_t __val = (val); \ uint64_t __val = (val); \
register ulong value asm("a0") = sizeof(ulong) == 4 ? (ulong)&__val : (ulong)__val; \ register ulong value asm("a0") = \
sizeof(ulong) == 4 ? (ulong)&__val : (ulong)__val; \
ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \
ulong tmp; \ ulong tmp; \
asm volatile ("1: auipc %0, %%pcrel_hi(put_f64_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp) : "r"(value), "r"(offset) : "t0"); }) asm volatile( \
"1: auipc %0, %%pcrel_hi(put_f64_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" \
: "=&r"(tmp) \
: "r"(value), "r"(offset) \
: "t0"); \
})
#define GET_FCSR() csr_read(CSR_FCSR) #define GET_FCSR() csr_read(CSR_FCSR)
#define SET_FCSR(value) csr_write(CSR_FCSR, (value)) #define SET_FCSR(value) csr_write(CSR_FCSR, (value))
#define GET_FRM() csr_read(CSR_FRM) #define GET_FRM() csr_read(CSR_FRM)
@ -50,7 +71,7 @@
#define GET_FFLAGS() csr_read(CSR_FFLAGS) #define GET_FFLAGS() csr_read(CSR_FFLAGS)
#define SET_FFLAGS(value) csr_write(CSR_FFLAGS, (value)) #define SET_FFLAGS(value) csr_write(CSR_FFLAGS, (value))
#define SET_FS_DIRTY() ((void) 0) #define SET_FS_DIRTY() ((void)0)
#else #else
#error "Floating point emulation not supported.\n" #error "Floating point emulation not supported.\n"
@ -62,8 +83,10 @@
#define GET_F64_RS1(insn, regs) (GET_F64_REG(insn, 15, regs)) #define GET_F64_RS1(insn, regs) (GET_F64_REG(insn, 15, regs))
#define GET_F64_RS2(insn, regs) (GET_F64_REG(insn, 20, regs)) #define GET_F64_RS2(insn, regs) (GET_F64_REG(insn, 20, regs))
#define GET_F64_RS3(insn, regs) (GET_F64_REG(insn, 27, regs)) #define GET_F64_RS3(insn, regs) (GET_F64_REG(insn, 27, regs))
#define SET_F32_RD(insn, regs, val) (SET_F32_REG(insn, 7, regs, val), SET_FS_DIRTY()) #define SET_F32_RD(insn, regs, val) \
#define SET_F64_RD(insn, regs, val) (SET_F64_REG(insn, 7, regs, val), SET_FS_DIRTY()) (SET_F32_REG(insn, 7, regs, val), SET_FS_DIRTY())
#define SET_F64_RD(insn, regs, val) \
(SET_F64_REG(insn, 7, regs, val), SET_FS_DIRTY())
#define GET_F32_RS2C(insn, regs) (GET_F32_REG(insn, 2, regs)) #define GET_F32_RS2C(insn, regs) (GET_F32_REG(insn, 2, regs))
#define GET_F32_RS2S(insn, regs) (GET_F32_REG(RVC_RS2S(insn), 0, regs)) #define GET_F32_RS2S(insn, regs) (GET_F32_REG(RVC_RS2S(insn), 0, regs))

View file

@ -15,23 +15,23 @@
static inline void __raw_writeb(u8 val, volatile void *addr) static inline void __raw_writeb(u8 val, volatile void *addr)
{ {
asm volatile("sb %0, 0(%1)" : : "r" (val), "r" (addr)); asm volatile("sb %0, 0(%1)" : : "r"(val), "r"(addr));
} }
static inline void __raw_writew(u16 val, volatile void *addr) static inline void __raw_writew(u16 val, volatile void *addr)
{ {
asm volatile("sh %0, 0(%1)" : : "r" (val), "r" (addr)); asm volatile("sh %0, 0(%1)" : : "r"(val), "r"(addr));
} }
static inline void __raw_writel(u32 val, volatile void *addr) static inline void __raw_writel(u32 val, volatile void *addr)
{ {
asm volatile("sw %0, 0(%1)" : : "r" (val), "r" (addr)); asm volatile("sw %0, 0(%1)" : : "r"(val), "r"(addr));
} }
#if __riscv_xlen != 32 #if __riscv_xlen != 32
static inline void __raw_writeq(u64 val, volatile void *addr) static inline void __raw_writeq(u64 val, volatile void *addr)
{ {
asm volatile("sd %0, 0(%1)" : : "r" (val), "r" (addr)); asm volatile("sd %0, 0(%1)" : : "r"(val), "r"(addr));
} }
#endif #endif
@ -39,7 +39,7 @@ static inline u8 __raw_readb(const volatile void *addr)
{ {
u8 val; u8 val;
asm volatile("lb %0, 0(%1)" : "=r" (val) : "r" (addr)); asm volatile("lb %0, 0(%1)" : "=r"(val) : "r"(addr));
return val; return val;
} }
@ -47,7 +47,7 @@ static inline u16 __raw_readw(const volatile void *addr)
{ {
u16 val; u16 val;
asm volatile("lh %0, 0(%1)" : "=r" (val) : "r" (addr)); asm volatile("lh %0, 0(%1)" : "=r"(val) : "r"(addr));
return val; return val;
} }
@ -55,7 +55,7 @@ static inline u32 __raw_readl(const volatile void *addr)
{ {
u32 val; u32 val;
asm volatile("lw %0, 0(%1)" : "=r" (val) : "r" (addr)); asm volatile("lw %0, 0(%1)" : "=r"(val) : "r"(addr));
return val; return val;
} }
@ -64,7 +64,7 @@ static inline u64 __raw_readq(const volatile void *addr)
{ {
u64 val; u64 val;
asm volatile("ld %0, 0(%1)" : "=r" (val) : "r" (addr)); asm volatile("ld %0, 0(%1)" : "=r"(val) : "r"(addr));
return val; return val;
} }
#endif #endif

View file

@ -16,11 +16,12 @@ typedef struct {
#define __RISCV_SPIN_UNLOCKED 0 #define __RISCV_SPIN_UNLOCKED 0
#define SPIN_LOCK_INIT(_lptr) \ #define SPIN_LOCK_INIT(_lptr) (_lptr)->lock = __RISCV_SPIN_UNLOCKED
(_lptr)->lock = __RISCV_SPIN_UNLOCKED
#define SPIN_LOCK_INITIALIZER \ #define SPIN_LOCK_INITIALIZER \
{ .lock = __RISCV_SPIN_UNLOCKED, } { \
.lock = __RISCV_SPIN_UNLOCKED, \
}
int spin_lock_check(spinlock_t *lock); int spin_lock_check(spinlock_t *lock);

View file

@ -15,28 +15,29 @@
#include <sbi/sbi_types.h> #include <sbi/sbi_types.h>
#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn) \ #define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type, insn) \
static inline type load_##type(const type *addr) \ static inline type load_##type(const type *addr) \
{ \ { \
register ulong __mstatus asm ("a2"); \ register ulong __mstatus asm("a2"); \
type val; \ type val; \
asm ("csrrs %0, "STR(CSR_MSTATUS)", %3\n" \ asm("csrrs %0, " STR(CSR_MSTATUS) ", %3\n" #insn " %1, %2\n" \
#insn " %1, %2\n" \ "csrw " STR( \
"csrw "STR(CSR_MSTATUS)", %0" \ CSR_MSTATUS) ", %0" \
: "+&r" (__mstatus), "=&r" (val) \ : "+&r"(__mstatus), "=&r"(val) \
: "m" (*addr), "r" (MSTATUS_MPRV)); \ : "m"(*addr), "r"(MSTATUS_MPRV)); \
return val; \ return val; \
} }
#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn) \ #define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type, insn) \
static inline void store_##type(type *addr, type val) \ static inline void store_##type(type *addr, type val) \
{ \ { \
register ulong __mstatus asm ("a3"); \ register ulong __mstatus asm("a3"); \
asm volatile ("csrrs %0, "STR(CSR_MSTATUS)", %3\n" \ asm volatile( \
#insn " %1, %2\n" \ "csrrs %0, " STR( \
"csrw "STR(CSR_MSTATUS)", %0" \ CSR_MSTATUS) ", %3\n" #insn " %1, %2\n" \
: "+&r" (__mstatus) \ "csrw " STR(CSR_MSTATUS) ", %0" \
: "r" (val), "m" (*addr), "r" (MSTATUS_MPRV)); \ : "+&r"(__mstatus) \
} : "r"(val), "m"(*addr), "r"(MSTATUS_MPRV)); \
}
DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8, lbu) DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8, lbu)
DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16, lhu) DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16, lhu)
@ -57,8 +58,7 @@ DECLARE_UNPRIVILEGED_LOAD_FUNCTION(ulong, lw)
static inline u64 load_u64(const u64 *addr) static inline u64 load_u64(const u64 *addr)
{ {
return load_u32((u32 *)addr) return load_u32((u32 *)addr) + ((u64)load_u32((u32 *)addr + 1) << 32);
+ ((u64)load_u32((u32 *)addr + 1) << 32);
} }
static inline void store_u64(u64 *addr, u64 val) static inline void store_u64(u64 *addr, u64 val)
@ -70,22 +70,22 @@ static inline void store_u64(u64 *addr, u64 val)
static inline ulong get_insn(ulong mepc, ulong *mstatus) static inline ulong get_insn(ulong mepc, ulong *mstatus)
{ {
register ulong __mepc asm ("a2") = mepc; register ulong __mepc asm("a2") = mepc;
register ulong __mstatus asm ("a3"); register ulong __mstatus asm("a3");
ulong val; ulong val;
#ifndef __riscv_compressed #ifndef __riscv_compressed
asm ("csrrs %[mstatus], "STR(CSR_MSTATUS)", %[mprv]\n" asm("csrrs %[mstatus], " STR(CSR_MSTATUS) ", %[mprv]\n"
#if __riscv_xlen == 64 #if __riscv_xlen == 64
STR(LWU) " %[insn], (%[addr])\n" STR(LWU) " %[insn], (%[addr])\n"
#else #else
STR(LW) " %[insn], (%[addr])\n" STR(LW) " %[insn], (%[addr])\n"
#endif #endif
"csrw "STR(CSR_MSTATUS)", %[mstatus]" "csrw " STR(CSR_MSTATUS) ", %[mstatus]"
: [mstatus] "+&r" (__mstatus), [insn] "=&r" (val) : [mstatus] "+&r"(__mstatus), [insn] "=&r"(val)
: [mprv] "r" (MSTATUS_MPRV|MSTATUS_MXR), [addr] "r" (__mepc)); : [mprv] "r"(MSTATUS_MPRV | MSTATUS_MXR), [addr] "r"(__mepc));
#else #else
ulong rvc_mask = 3, tmp; ulong rvc_mask = 3, tmp;
asm ("csrrs %[mstatus], "STR(CSR_MSTATUS)", %[mprv]\n" asm("csrrs %[mstatus], " STR(CSR_MSTATUS) ", %[mprv]\n"
"and %[tmp], %[addr], 2\n" "and %[tmp], %[addr], 2\n"
"bnez %[tmp], 1f\n" "bnez %[tmp], 1f\n"
#if __riscv_xlen == 64 #if __riscv_xlen == 64
@ -105,10 +105,10 @@ static inline ulong get_insn(ulong mepc, ulong *mstatus)
"lhu %[tmp], 2(%[addr])\n" "lhu %[tmp], 2(%[addr])\n"
"sll %[tmp], %[tmp], 16\n" "sll %[tmp], %[tmp], 16\n"
"add %[insn], %[insn], %[tmp]\n" "add %[insn], %[insn], %[tmp]\n"
"2: csrw "STR(CSR_MSTATUS)", %[mstatus]" "2: csrw " STR(CSR_MSTATUS) ", %[mstatus]"
: [mstatus] "+&r" (__mstatus), [insn] "=&r" (val), [tmp] "=&r" (tmp) : [mstatus] "+&r"(__mstatus), [insn] "=&r"(val), [tmp] "=&r"(tmp)
: [mprv] "r" (MSTATUS_MPRV|MSTATUS_MXR), [addr] "r" (__mepc), : [mprv] "r"(MSTATUS_MPRV | MSTATUS_MXR), [addr] "r"(__mepc),
[rvc_mask] "r" (rvc_mask), [xlen_minus_16] "i" (__riscv_xlen - 16)); [rvc_mask] "r"(rvc_mask), [xlen_minus_16] "i"(__riscv_xlen - 16));
#endif #endif
if (mstatus) if (mstatus)
*mstatus = __mstatus; *mstatus = __mstatus;

View file

@ -13,15 +13,16 @@
#define likely(x) __builtin_expect((x), 1) #define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0) #define unlikely(x) __builtin_expect((x), 0)
#define ROUNDUP(a, b) ((((a)-1)/(b)+1)*(b)) #define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
#define ROUNDDOWN(a, b) ((a)/(b)*(b)) #define ROUNDDOWN(a, b) ((a) / (b) * (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi) #define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
#define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1))) #define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
#define INSERT_FIELD(val, which, fieldval) (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1)))) #define INSERT_FIELD(val, which, fieldval) \
(((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
#define STR(x) XSTR(x) #define STR(x) XSTR(x)
#define XSTR(x) #x #define XSTR(x) #x

View file

@ -26,8 +26,7 @@ void sbi_gets(char *s, int maxwidth, char endchar);
int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...); int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...);
int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...);
const char *format, ...);
int __printf(1, 2) sbi_printf(const char *format, ...); int __printf(1, 2) sbi_printf(const char *format, ...);

View file

@ -19,8 +19,7 @@ u16 sbi_ecall_version_major(void);
u16 sbi_ecall_version_minor(void); u16 sbi_ecall_version_minor(void);
int sbi_ecall_handler(u32 hartid, ulong mcause, int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
struct sbi_trap_regs *regs,
struct sbi_scratch *scratch); struct sbi_scratch *scratch);
#endif #endif

View file

@ -24,24 +24,24 @@
/* clang-format on */ /* clang-format on */
#define SBI_ECALL(__num, __a0, __a1, __a2) ({ \ #define SBI_ECALL(__num, __a0, __a1, __a2) \
register unsigned long a0 asm ("a0") = (unsigned long)(__a0); \ ({ \
register unsigned long a1 asm ("a1") = (unsigned long)(__a1); \ register unsigned long a0 asm("a0") = (unsigned long)(__a0); \
register unsigned long a2 asm ("a2") = (unsigned long)(__a2); \ register unsigned long a1 asm("a1") = (unsigned long)(__a1); \
register unsigned long a7 asm ("a7") = (unsigned long)(__num); \ register unsigned long a2 asm("a2") = (unsigned long)(__a2); \
asm volatile ("ecall" \ register unsigned long a7 asm("a7") = (unsigned long)(__num); \
: "+r" (a0) \ asm volatile("ecall" \
: "r" (a1), "r" (a2), "r" (a7) \ : "+r"(a0) \
: "r"(a1), "r"(a2), "r"(a7) \
: "memory"); \ : "memory"); \
a0; \ a0; \
}) })
#define SBI_ECALL_0(__num) SBI_ECALL(__num, 0, 0, 0) #define SBI_ECALL_0(__num) SBI_ECALL(__num, 0, 0, 0)
#define SBI_ECALL_1(__num, __a0) SBI_ECALL(__num, __a0, 0, 0) #define SBI_ECALL_1(__num, __a0) SBI_ECALL(__num, __a0, 0, 0)
#define SBI_ECALL_2(__num, __a0, __a1) SBI_ECALL(__num, __a0, __a1, 0) #define SBI_ECALL_2(__num, __a0, __a1) SBI_ECALL(__num, __a0, __a1, 0)
#define sbi_ecall_console_putc(c) \ #define sbi_ecall_console_putc(c) SBI_ECALL_1(SBI_ECALL_CONSOLE_PUTCHAR, (c));
SBI_ECALL_1(SBI_ECALL_CONSOLE_PUTCHAR, (c));
static inline void sbi_ecall_console_puts(const char *str) static inline void sbi_ecall_console_puts(const char *str)
{ {

View file

@ -14,14 +14,10 @@
struct sbi_scratch; struct sbi_scratch;
int sbi_emulate_csr_read(int csr_num, int sbi_emulate_csr_read(int csr_num, u32 hartid, ulong mstatus,
u32 hartid, ulong mstatus, struct sbi_scratch *scratch, ulong *csr_val);
struct sbi_scratch *scratch,
ulong *csr_val);
int sbi_emulate_csr_write(int csr_num, int sbi_emulate_csr_write(int csr_num, u32 hartid, ulong mstatus,
u32 hartid, ulong mstatus, struct sbi_scratch *scratch, ulong csr_val);
struct sbi_scratch *scratch,
ulong csr_val);
#endif #endif

View file

@ -32,12 +32,12 @@ enum sbi_fifo_inplace_update_types {
int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data); int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data);
int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data); int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data);
void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
u16 entries, u16 entry_size); u16 entry_size);
bool sbi_fifo_is_empty(struct sbi_fifo *fifo); bool sbi_fifo_is_empty(struct sbi_fifo *fifo);
bool sbi_fifo_is_full(struct sbi_fifo *fifo); bool sbi_fifo_is_full(struct sbi_fifo *fifo);
int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in, int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
int (*fptr) (void *in, void *data)); int (*fptr)(void *in, void *data));
u16 sbi_fifo_avail(struct sbi_fifo *fifo); u16 sbi_fifo_avail(struct sbi_fifo *fifo);
#endif #endif

View file

@ -20,10 +20,9 @@ void sbi_hart_pmp_dump(struct sbi_scratch *scratch);
void __attribute__((noreturn)) sbi_hart_hang(void); void __attribute__((noreturn)) sbi_hart_hang(void);
void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, void __attribute__((noreturn))
unsigned long arg1, sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
unsigned long next_addr, unsigned long next_addr, unsigned long next_mode);
unsigned long next_mode);
void sbi_hart_mark_available(u32 hartid); void sbi_hart_mark_available(u32 hartid);

View file

@ -44,8 +44,8 @@ struct sbi_tlb_info {
#define SBI_TLB_INFO_SIZE sizeof(struct sbi_tlb_info) #define SBI_TLB_INFO_SIZE sizeof(struct sbi_tlb_info)
int sbi_ipi_send_many(struct sbi_scratch *scratch, int sbi_ipi_send_many(struct sbi_scratch *scratch, ulong *pmask, u32 event,
ulong *pmask, u32 event, void *data); void *data);
void sbi_ipi_clear_smode(struct sbi_scratch *scratch); void sbi_ipi_clear_smode(struct sbi_scratch *scratch);

View file

@ -41,10 +41,8 @@ enum sbi_platform_features {
/** Default feature set for a platform */ /** Default feature set for a platform */
#define SBI_PLATFORM_DEFAULT_FEATURES \ #define SBI_PLATFORM_DEFAULT_FEATURES \
(SBI_PLATFORM_HAS_TIMER_VALUE | \ (SBI_PLATFORM_HAS_TIMER_VALUE | SBI_PLATFORM_HAS_PMP | \
SBI_PLATFORM_HAS_PMP | \ SBI_PLATFORM_HAS_SCOUNTEREN | SBI_PLATFORM_HAS_MCOUNTEREN | \
SBI_PLATFORM_HAS_SCOUNTEREN | \
SBI_PLATFORM_HAS_MCOUNTEREN | \
SBI_PLATFORM_HAS_MFAULTS_DELEGATION) SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
/** Representation of a platform */ /** Representation of a platform */
@ -71,8 +69,8 @@ struct sbi_platform {
* Get PMP regions details (namely: protection, base address, * Get PMP regions details (namely: protection, base address,
* and size) for given HART * and size) for given HART
*/ */
int (*pmp_region_info)(u32 hartid, u32 index, int (*pmp_region_info)(u32 hartid, u32 index, ulong *prot, ulong *addr,
ulong *prot, ulong *addr, ulong *log2size); ulong *log2size);
/** Write a character to the platform console output */ /** Write a character to the platform console output */
void (*console_putc)(char ch); void (*console_putc)(char ch);
@ -113,7 +111,8 @@ struct sbi_platform {
((const struct sbi_platform *)((__s)->platform_addr)) ((const struct sbi_platform *)((__s)->platform_addr))
/** Get pointer to sbi_platform for current HART */ /** Get pointer to sbi_platform for current HART */
#define sbi_platform_thishart_ptr() \ #define sbi_platform_thishart_ptr() \
((const struct sbi_platform *)(sbi_scratch_thishart_ptr()->platform_addr)) ((const struct sbi_platform *)(sbi_scratch_thishart_ptr() \
->platform_addr))
/** Check whether the platform supports timer value */ /** Check whether the platform supports timer value */
#define sbi_platform_has_timer_value(__p) \ #define sbi_platform_has_timer_value(__p) \
((__p)->features & SBI_PLATFORM_HAS_TIMER_VALUE) ((__p)->features & SBI_PLATFORM_HAS_TIMER_VALUE)
@ -121,8 +120,7 @@ struct sbi_platform {
#define sbi_platform_has_hart_hotplug(__p) \ #define sbi_platform_has_hart_hotplug(__p) \
((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG) ((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG)
/** Check whether the platform has PMP support */ /** Check whether the platform has PMP support */
#define sbi_platform_has_pmp(__p) \ #define sbi_platform_has_pmp(__p) ((__p)->features & SBI_PLATFORM_HAS_PMP)
((__p)->features & SBI_PLATFORM_HAS_PMP)
/** Check whether the platform supports scounteren CSR */ /** Check whether the platform supports scounteren CSR */
#define sbi_platform_has_scounteren(__p) \ #define sbi_platform_has_scounteren(__p) \
((__p)->features & SBI_PLATFORM_HAS_SCOUNTEREN) ((__p)->features & SBI_PLATFORM_HAS_SCOUNTEREN)
@ -258,8 +256,8 @@ static inline int sbi_platform_pmp_region_info(const struct sbi_platform *plat,
ulong *log2size) ulong *log2size)
{ {
if (plat && plat->pmp_region_info) if (plat && plat->pmp_region_info)
return plat->pmp_region_info(hartid, index, return plat->pmp_region_info(hartid, index, prot, addr,
prot, addr, log2size); log2size);
return 0; return 0;
} }
@ -395,9 +393,8 @@ static inline u64 sbi_platform_timer_value(const struct sbi_platform *plat)
* @param plat pointer to struct struct sbi_platform * @param plat pointer to struct struct sbi_platform
* @param next_event timer value when timer event will happen * @param next_event timer value when timer event will happen
*/ */
static inline void sbi_platform_timer_event_start( static inline void
const struct sbi_platform *plat, sbi_platform_timer_event_start(const struct sbi_platform *plat, u64 next_event)
u64 next_event)
{ {
if (plat && plat->timer_event_start) if (plat && plat->timer_event_start)
plat->timer_event_start(next_event); plat->timer_event_start(next_event);
@ -408,8 +405,8 @@ static inline void sbi_platform_timer_event_start(
* *
* @param plat pointer to struct sbi_platform * @param plat pointer to struct sbi_platform
*/ */
static inline void sbi_platform_timer_event_stop( static inline void
const struct sbi_platform *plat) sbi_platform_timer_event_stop(const struct sbi_platform *plat)
{ {
if (plat && plat->timer_event_stop) if (plat && plat->timer_event_stop)
plat->timer_event_stop(); plat->timer_event_stop();

View file

@ -84,23 +84,23 @@ enum sbi_scratch_options {
/** Get pointer to sbi_scratch for current HART */ /** Get pointer to sbi_scratch for current HART */
#define sbi_scratch_thishart_ptr() \ #define sbi_scratch_thishart_ptr() \
((struct sbi_scratch *)csr_read(CSR_MSCRATCH)) ((struct sbi_scratch *)csr_read(CSR_MSCRATCH))
/** Get Arg1 of next booting stage for current HART */ /** Get Arg1 of next booting stage for current HART */
#define sbi_scratch_thishart_arg1_ptr() \ #define sbi_scratch_thishart_arg1_ptr() \
((void *)(sbi_scratch_thishart_ptr()->next_arg1)) ((void *)(sbi_scratch_thishart_ptr()->next_arg1))
/** Get pointer to sbi_ipi_data from sbi_scratch */ /** Get pointer to sbi_ipi_data from sbi_scratch */
#define sbi_ipi_data_ptr(scratch) \ #define sbi_ipi_data_ptr(scratch) \
((struct sbi_ipi_data *)(void*)scratch + SBI_IPI_DATA_IPI_TYPE_OFFSET) ((struct sbi_ipi_data *)(void *)scratch + SBI_IPI_DATA_IPI_TYPE_OFFSET)
/** Get pointer to tlb flush info fifo header from sbi_scratch */ /** Get pointer to tlb flush info fifo header from sbi_scratch */
#define sbi_tlb_fifo_head_ptr(scratch) \ #define sbi_tlb_fifo_head_ptr(scratch) \
((struct sbi_fifo *)(void*)scratch + SBI_SCRATCH_TLB_QUEUE_HEAD_OFFSET) ((struct sbi_fifo *)(void *)scratch + SBI_SCRATCH_TLB_QUEUE_HEAD_OFFSET)
/** Get pointer to tlb flush info fifo queue address from sbi_scratch */ /** Get pointer to tlb flush info fifo queue address from sbi_scratch */
#define sbi_tlb_fifo_mem_ptr(scratch) \ #define sbi_tlb_fifo_mem_ptr(scratch) \
(void *)((void*)scratch + SBI_SCRATCH_TLB_QUEUE_MEM_OFFSET) (void *)((void *)scratch + SBI_SCRATCH_TLB_QUEUE_MEM_OFFSET)
#endif #endif

View file

@ -18,10 +18,10 @@ int sbi_system_early_init(struct sbi_scratch *scratch, bool cold_boot);
int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot); int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot);
void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch, void __attribute__((noreturn))
u32 type); sbi_system_reboot(struct sbi_scratch *scratch, u32 type);
void __attribute__((noreturn)) sbi_system_shutdown(struct sbi_scratch *scratch, void __attribute__((noreturn))
u32 type); sbi_system_shutdown(struct sbi_scratch *scratch, u32 type);
#endif #endif

View file

@ -86,8 +86,7 @@
/* clang-format on */ /* clang-format on */
/** Get offset of member with name 'x' in sbi_trap_regs */ /** Get offset of member with name 'x' in sbi_trap_regs */
#define SBI_TRAP_REGS_OFFSET(x) \ #define SBI_TRAP_REGS_OFFSET(x) ((SBI_TRAP_REGS_##x) * __SIZEOF_POINTER__)
((SBI_TRAP_REGS_##x) * __SIZEOF_POINTER__)
/** Size (in bytes) of sbi_trap_regs */ /** Size (in bytes) of sbi_trap_regs */
#define SBI_TRAP_REGS_SIZE SBI_TRAP_REGS_OFFSET(last) #define SBI_TRAP_REGS_SIZE SBI_TRAP_REGS_OFFSET(last)
@ -169,12 +168,10 @@ struct sbi_trap_regs {
struct sbi_scratch; struct sbi_scratch;
int sbi_trap_redirect(struct sbi_trap_regs *regs, int sbi_trap_redirect(struct sbi_trap_regs *regs, struct sbi_scratch *scratch,
struct sbi_scratch *scratch,
ulong epc, ulong cause, ulong tval); ulong epc, ulong cause, ulong tval);
void sbi_trap_handler(struct sbi_trap_regs *regs, void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch);
struct sbi_scratch *scratch);
#endif #endif

View file

@ -163,17 +163,15 @@ static unsigned long ctz(unsigned long x)
return ret; return ret;
} }
int pmp_set(unsigned int n, unsigned long prot, int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long addr, unsigned long log2len) unsigned long log2len)
{ {
int pmpcfg_csr, pmpcfg_shift, pmpaddr_csr; int pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;
unsigned long cfgmask, pmpcfg; unsigned long cfgmask, pmpcfg;
unsigned long addrmask, pmpaddr; unsigned long addrmask, pmpaddr;
/* check parameters */ /* check parameters */
if (n >= PMP_COUNT || if (n >= PMP_COUNT || log2len > __riscv_xlen || log2len < PMP_SHIFT)
log2len > __riscv_xlen ||
log2len < PMP_SHIFT)
return SBI_EINVAL; return SBI_EINVAL;
/* calculate PMP register and offset */ /* calculate PMP register and offset */
@ -217,16 +215,15 @@ int pmp_set(unsigned int n, unsigned long prot,
return 0; return 0;
} }
int pmp_get(unsigned int n, unsigned long *prot_out, int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *addr_out, unsigned long *log2len_out) unsigned long *log2len_out)
{ {
int pmpcfg_csr, pmpcfg_shift, pmpaddr_csr; int pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;
unsigned long cfgmask, pmpcfg, prot; unsigned long cfgmask, pmpcfg, prot;
unsigned long t1, addr, log2len; unsigned long t1, addr, log2len;
/* check parameters */ /* check parameters */
if (n >= PMP_COUNT || !prot_out || if (n >= PMP_COUNT || !prot_out || !addr_out || !log2len_out)
!addr_out || !log2len_out)
return SBI_EINVAL; return SBI_EINVAL;
*prot_out = *addr_out = *log2len_out = 0; *prot_out = *addr_out = *log2len_out = 0;

View file

@ -30,10 +30,9 @@ long atomic_add_return(atomic_t *atom, long value)
{ {
long ret; long ret;
__asm__ __volatile__ ( __asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0"
" amoadd.w.aqrl %1, %2, %0" : "+A"(atom->counter), "=r"(ret)
: "+A" (atom->counter), "=r" (ret) : "r"(value)
: "r" (value)
: "memory"); : "memory");
return ret + value; return ret + value;
@ -43,56 +42,55 @@ long atomic_sub_return(atomic_t *atom, long value)
{ {
long ret; long ret;
__asm__ __volatile__ ( __asm__ __volatile__(" amoadd.w.aqrl %1, %2, %0"
" amoadd.w.aqrl %1, %2, %0" : "+A"(atom->counter), "=r"(ret)
: "+A" (atom->counter), "=r" (ret) : "r"(-value)
: "r" (-value)
: "memory"); : "memory");
return ret - value; return ret - value;
} }
#define __xchg(ptr, new, size) \ #define __xchg(ptr, new, size) \
({ \ ({ \
__typeof__(ptr) __ptr = (ptr); \ __typeof__(ptr) __ptr = (ptr); \
__typeof__(*(ptr)) __new = (new); \ __typeof__(*(ptr)) __new = (new); \
__typeof__(*(ptr)) __ret; \ __typeof__(*(ptr)) __ret; \
register unsigned int __rc; \ register unsigned int __rc; \
switch (size) { \ switch (size) { \
case 4: \ case 4: \
__asm__ __volatile__ ( \ __asm__ __volatile__("0: lr.w %0, %2\n" \
"0: lr.w %0, %2\n" \
" sc.w.rl %1, %z3, %2\n" \ " sc.w.rl %1, %z3, %2\n" \
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
" fence rw, rw\n" \ " fence rw, rw\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r"(__ret), "=&r"(__rc), \
: "rJ" (__new) \ "+A"(*__ptr) \
: "rJ"(__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
__asm__ __volatile__ ( \ __asm__ __volatile__("0: lr.d %0, %2\n" \
"0: lr.d %0, %2\n" \
" sc.d.rl %1, %z3, %2\n" \ " sc.d.rl %1, %z3, %2\n" \
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
" fence rw, rw\n" \ " fence rw, rw\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r"(__ret), "=&r"(__rc), \
: "rJ" (__new) \ "+A"(*__ptr) \
: "rJ"(__new) \
: "memory"); \ : "memory"); \
break; \ break; \
default: \ default: \
break; \ break; \
} \ } \
__ret; \ __ret; \
}) })
#define xchg(ptr, n) \ #define xchg(ptr, n) \
({ \ ({ \
__typeof__(*(ptr)) _n_ = (n); \ __typeof__(*(ptr)) _n_ = (n); \
(__typeof__(*(ptr))) __xchg((ptr), _n_, sizeof(*(ptr))); \ (__typeof__(*(ptr))) __xchg((ptr), _n_, sizeof(*(ptr))); \
}) })
#define __cmpxchg(ptr, old, new, size) \ #define __cmpxchg(ptr, old, new, size) \
({ \ ({ \
__typeof__(ptr) __ptr = (ptr); \ __typeof__(ptr) __ptr = (ptr); \
__typeof__(*(ptr)) __old = (old); \ __typeof__(*(ptr)) __old = (old); \
__typeof__(*(ptr)) __new = (new); \ __typeof__(*(ptr)) __new = (new); \
@ -100,42 +98,42 @@ long atomic_sub_return(atomic_t *atom, long value)
register unsigned int __rc; \ register unsigned int __rc; \
switch (size) { \ switch (size) { \
case 4: \ case 4: \
__asm__ __volatile__ ( \ __asm__ __volatile__("0: lr.w %0, %2\n" \
"0: lr.w %0, %2\n" \
" bne %0, %z3, 1f\n" \ " bne %0, %z3, 1f\n" \
" sc.w.rl %1, %z4, %2\n" \ " sc.w.rl %1, %z4, %2\n" \
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
" fence rw, rw\n" \ " fence rw, rw\n" \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r"(__ret), "=&r"(__rc), \
: "rJ" (__old), "rJ" (__new) \ "+A"(*__ptr) \
: "rJ"(__old), "rJ"(__new) \
: "memory"); \ : "memory"); \
break; \ break; \
case 8: \ case 8: \
__asm__ __volatile__ ( \ __asm__ __volatile__("0: lr.d %0, %2\n" \
"0: lr.d %0, %2\n" \
" bne %0, %z3, 1f\n" \ " bne %0, %z3, 1f\n" \
" sc.d.rl %1, %z4, %2\n" \ " sc.d.rl %1, %z4, %2\n" \
" bnez %1, 0b\n" \ " bnez %1, 0b\n" \
" fence rw, rw\n" \ " fence rw, rw\n" \
"1:\n" \ "1:\n" \
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "=&r"(__ret), "=&r"(__rc), \
: "rJ" (__old), "rJ" (__new) \ "+A"(*__ptr) \
: "rJ"(__old), "rJ"(__new) \
: "memory"); \ : "memory"); \
break; \ break; \
default: \ default: \
break; \ break; \
} \ } \
__ret; \ __ret; \
}) })
#define cmpxchg(ptr, o, n) \ #define cmpxchg(ptr, o, n) \
({ \ ({ \
__typeof__(*(ptr)) _o_ = (o); \ __typeof__(*(ptr)) _o_ = (o); \
__typeof__(*(ptr)) _n_ = (n); \ __typeof__(*(ptr)) _n_ = (n); \
(__typeof__(*(ptr))) __cmpxchg((ptr), \ (__typeof__(*(ptr))) \
_o_, _n_, sizeof(*(ptr))); \ __cmpxchg((ptr), _o_, _n_, sizeof(*(ptr))); \
}) })
long arch_atomic_cmpxchg(atomic_t *atom, long oldval, long newval) long arch_atomic_cmpxchg(atomic_t *atom, long oldval, long newval)
{ {
@ -186,16 +184,15 @@ unsigned int atomic_raw_xchg_uint(volatile unsigned int *ptr,
#endif #endif
#define __atomic_op_bit_ord(op, mod, nr, addr, ord) \ #define __atomic_op_bit_ord(op, mod, nr, addr, ord) \
({ \ ({ \
unsigned long __res, __mask; \ unsigned long __res, __mask; \
__mask = BIT_MASK(nr); \ __mask = BIT_MASK(nr); \
__asm__ __volatile__ ( \ __asm__ __volatile__(__AMO(op) #ord " %0, %2, %1" \
__AMO(op) #ord " %0, %2, %1" \ : "=r"(__res), "+A"(addr[BIT_WORD(nr)]) \
: "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \ : "r"(mod(__mask)) \
: "r" (mod(__mask)) \
: "memory"); \ : "memory"); \
__res; \ __res; \
}) })
#define __atomic_op_bit(op, mod, nr, addr) \ #define __atomic_op_bit(op, mod, nr, addr) \
__atomic_op_bit_ord(op, mod, nr, addr, .aqrl) __atomic_op_bit_ord(op, mod, nr, addr, .aqrl)

View file

@ -19,11 +19,10 @@ int spin_trylock(spinlock_t *lock)
{ {
int tmp = 1, busy; int tmp = 1, busy;
__asm__ __volatile__ ( __asm__ __volatile__(
" amoswap.w %0, %2, %1\n" " amoswap.w %0, %2, %1\n" RISCV_ACQUIRE_BARRIER
RISCV_ACQUIRE_BARRIER : "=r"(busy), "+A"(lock->lock)
: "=r" (busy), "+A" (lock->lock) : "r"(tmp)
: "r" (tmp)
: "memory"); : "memory");
return !busy; return !busy;

View file

@ -16,11 +16,8 @@ static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER;
bool sbi_isprintable(char c) bool sbi_isprintable(char c)
{ {
if (((31 < c) && (c < 127)) || if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') ||
(c == '\f') || (c == '\n') || (c == '\t')) {
(c == '\r') ||
(c == '\n') ||
(c == '\t')) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -54,7 +51,7 @@ void sbi_gets(char *s, int maxwidth, char endchar)
char *retval = s; char *retval = s;
while ((ch = sbi_getc()) != endchar && ch >= 0 && maxwidth > 1) { while ((ch = sbi_getc()) != endchar && ch >= 0 && maxwidth > 1) {
*retval = (char) ch; *retval = (char)ch;
retval++; retval++;
maxwidth--; maxwidth--;
} }
@ -66,7 +63,7 @@ void sbi_gets(char *s, int maxwidth, char endchar)
#define PAD_ALTERNATE 4 #define PAD_ALTERNATE 4
#define PRINT_BUF_LEN 64 #define PRINT_BUF_LEN 64
#define va_start(v,l) __builtin_va_start((v),l) #define va_start(v, l) __builtin_va_start((v), l)
#define va_end __builtin_va_end #define va_end __builtin_va_end
#define va_arg __builtin_va_arg #define va_arg __builtin_va_arg
typedef __builtin_va_list va_list; typedef __builtin_va_list va_list;
@ -89,7 +86,8 @@ static void printc(char **out, u32 *out_len, char ch)
} }
} }
static int prints(char **out, u32 *out_len, const char *string, int width, int flags) static int prints(char **out, u32 *out_len, const char *string, int width,
int flags)
{ {
int pc = 0; int pc = 0;
char padchar = ' '; char padchar = ' ';
@ -211,54 +209,54 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
if (*format == 's') { if (*format == 's') {
char *s = va_arg(args, char *); char *s = va_arg(args, char *);
acnt += sizeof(char *); acnt += sizeof(char *);
pc += prints(out, out_len, pc += prints(out, out_len, s ? s : "(null)",
s ? s : "(null)", width, flags); width, flags);
continue; continue;
} }
if ((*format == 'd') || (*format == 'i')) { if ((*format == 'd') || (*format == 'i')) {
pc += printi(out, out_len, pc += printi(out, out_len, va_arg(args, int),
va_arg(args, int),
10, 1, width, flags, '0'); 10, 1, width, flags, '0');
acnt += sizeof(int); acnt += sizeof(int);
continue; continue;
} }
if (*format == 'x') { if (*format == 'x') {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, unsigned int), va_arg(args, unsigned int), 16, 0,
16, 0, width, flags, 'a'); width, flags, 'a');
acnt += sizeof(unsigned int); acnt += sizeof(unsigned int);
continue; continue;
} }
if (*format == 'X') { if (*format == 'X') {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, unsigned int), va_arg(args, unsigned int), 16, 0,
16, 0, width, flags, 'A'); width, flags, 'A');
acnt += sizeof(unsigned int); acnt += sizeof(unsigned int);
continue; continue;
} }
if (*format == 'u') { if (*format == 'u') {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, unsigned int), va_arg(args, unsigned int), 10, 0,
10, 0, width, flags, 'a'); width, flags, 'a');
acnt += sizeof(unsigned int); acnt += sizeof(unsigned int);
continue; continue;
} }
if (*format == 'p') { if (*format == 'p') {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, unsigned long), va_arg(args, unsigned long), 16, 0,
16, 0, width, flags, 'a'); width, flags, 'a');
acnt += sizeof(unsigned long); acnt += sizeof(unsigned long);
continue; continue;
} }
if (*format == 'P') { if (*format == 'P') {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, unsigned long), va_arg(args, unsigned long), 16, 0,
16, 0, width, flags, 'A'); width, flags, 'A');
acnt += sizeof(unsigned long); acnt += sizeof(unsigned long);
continue; continue;
} }
if (*format == 'l' && *(format + 1) == 'l') { if (*format == 'l' && *(format + 1) == 'l') {
while (acnt & (sizeof(unsigned long long)-1)) { while (acnt &
(sizeof(unsigned long long) - 1)) {
va_arg(args, int); va_arg(args, int);
acnt += sizeof(int); acnt += sizeof(int);
} }
@ -271,48 +269,51 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
va_arg(args, unsigned long); va_arg(args, unsigned long);
((unsigned long *)&tmp)[1] = ((unsigned long *)&tmp)[1] =
va_arg(args, unsigned long); va_arg(args, unsigned long);
acnt += 2*sizeof(unsigned long); acnt += 2 * sizeof(unsigned long);
} }
if (*(format + 2) == 'u') { if (*(format + 2) == 'u') {
format += 2; format += 2;
pc += printi(out, out_len, tmp, pc += printi(out, out_len, tmp, 10, 0,
10, 0, width, flags, 'a'); width, flags, 'a');
} else if (*(format + 2) == 'x') { } else if (*(format + 2) == 'x') {
format += 2; format += 2;
pc += printi(out, out_len, tmp, pc += printi(out, out_len, tmp, 16, 0,
16, 0, width, flags, 'a'); width, flags, 'a');
} else if (*(format + 2) == 'X') { } else if (*(format + 2) == 'X') {
format += 2; format += 2;
pc += printi(out, out_len, tmp, pc += printi(out, out_len, tmp, 16, 0,
16, 0, width, flags, 'A'); width, flags, 'A');
} else { } else {
format += 1; format += 1;
pc += printi(out, out_len, tmp, pc += printi(out, out_len, tmp, 10, 1,
10, 1, width, flags, '0'); width, flags, '0');
} }
continue; continue;
} else if (*format == 'l') { } else if (*format == 'l') {
if (*(format + 1) == 'u') { if (*(format + 1) == 'u') {
format += 1; format += 1;
pc += printi(out, out_len, pc += printi(
va_arg(args, unsigned long), out, out_len,
10, 0, width, flags, 'a'); va_arg(args, unsigned long), 10,
0, width, flags, 'a');
} else if (*(format + 1) == 'x') { } else if (*(format + 1) == 'x') {
format += 1; format += 1;
pc += printi(out, out_len, pc += printi(
va_arg(args, unsigned long), out, out_len,
16, 0, width, flags, 'a'); va_arg(args, unsigned long), 16,
0, width, flags, 'a');
acnt += sizeof(unsigned long); acnt += sizeof(unsigned long);
} else if (*(format + 1) == 'X') { } else if (*(format + 1) == 'X') {
format += 1; format += 1;
pc += printi(out, out_len, pc += printi(
va_arg(args, unsigned long), out, out_len,
16, 0, width, flags, 'A'); va_arg(args, unsigned long), 16,
0, width, flags, 'A');
acnt += sizeof(unsigned long); acnt += sizeof(unsigned long);
} else { } else {
pc += printi(out, out_len, pc += printi(out, out_len,
va_arg(args, long), va_arg(args, long), 10, 1,
10, 1, width, flags, '0'); width, flags, '0');
acnt += sizeof(long); acnt += sizeof(long);
} }
} }
@ -325,7 +326,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
continue; continue;
} }
} else { } else {
out: out:
printc(out, out_len, *format); printc(out, out_len, *format);
++pc; ++pc;
} }

View file

@ -29,8 +29,7 @@ u16 sbi_ecall_version_minor(void)
return SBI_ECALL_VERSION_MINOR; return SBI_ECALL_VERSION_MINOR;
} }
int sbi_ecall_handler(u32 hartid, ulong mcause, int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs,
struct sbi_trap_regs *regs,
struct sbi_scratch *scratch) struct sbi_scratch *scratch)
{ {
int ret = SBI_ENOTSUPP; int ret = SBI_ENOTSUPP;
@ -81,7 +80,8 @@ int sbi_ecall_handler(u32 hartid, ulong mcause,
tlb_info.type = SBI_TLB_FLUSH_VMA_ASID; tlb_info.type = SBI_TLB_FLUSH_VMA_ASID;
ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0, ret = sbi_ipi_send_many(scratch, (ulong *)regs->a0,
SBI_IPI_EVENT_SFENCE_VMA_ASID, &tlb_info); SBI_IPI_EVENT_SFENCE_VMA_ASID,
&tlb_info);
break; break;
case SBI_ECALL_SHUTDOWN: case SBI_ECALL_SHUTDOWN:
sbi_system_shutdown(scratch, 0); sbi_system_shutdown(scratch, 0);

View file

@ -15,10 +15,8 @@
#include <sbi/sbi_error.h> #include <sbi/sbi_error.h>
#include <sbi/sbi_timer.h> #include <sbi/sbi_timer.h>
int sbi_emulate_csr_read(int csr_num, int sbi_emulate_csr_read(int csr_num, u32 hartid, ulong mstatus,
u32 hartid, ulong mstatus, struct sbi_scratch *scratch, ulong *csr_val)
struct sbi_scratch *scratch,
ulong *csr_val)
{ {
ulong cen = -1UL; ulong cen = -1UL;
@ -85,18 +83,16 @@ int sbi_emulate_csr_read(int csr_num,
*csr_val = csr_read(CSR_MHPMEVENT4); *csr_val = csr_read(CSR_MHPMEVENT4);
break; break;
default: default:
sbi_printf("%s: hartid%d: invalid csr_num=0x%x\n", sbi_printf("%s: hartid%d: invalid csr_num=0x%x\n", __func__,
__func__, hartid, csr_num); hartid, csr_num);
return SBI_ENOTSUPP; return SBI_ENOTSUPP;
}; };
return 0; return 0;
} }
int sbi_emulate_csr_write(int csr_num, int sbi_emulate_csr_write(int csr_num, u32 hartid, ulong mstatus,
u32 hartid, ulong mstatus, struct sbi_scratch *scratch, ulong csr_val)
struct sbi_scratch *scratch,
ulong csr_val)
{ {
switch (csr_num) { switch (csr_num) {
case CSR_CYCLE: case CSR_CYCLE:
@ -132,8 +128,8 @@ int sbi_emulate_csr_write(int csr_num,
csr_write(CSR_MHPMEVENT4, csr_val); csr_write(CSR_MHPMEVENT4, csr_val);
break; break;
default: default:
sbi_printf("%s: hartid%d: invalid csr_num=0x%x\n", sbi_printf("%s: hartid%d: invalid csr_num=0x%x\n", __func__,
__func__, hartid, csr_num); hartid, csr_num);
return SBI_ENOTSUPP; return SBI_ENOTSUPP;
}; };

View file

@ -12,8 +12,8 @@
#include <sbi/sbi_fifo.h> #include <sbi/sbi_fifo.h>
#include <plat/string.h> #include <plat/string.h>
void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
u16 entries, u16 entry_size) u16 entry_size)
{ {
fifo->queue = queue_mem; fifo->queue = queue_mem;
fifo->num_entries = entries; fifo->num_entries = entries;
@ -105,7 +105,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
int ret = SBI_FIFO_UNCHANGED; int ret = SBI_FIFO_UNCHANGED;
void *entry; void *entry;
if (!fifo || !in ) if (!fifo || !in)
return ret; return ret;
spin_lock(&fifo->qlock); spin_lock(&fifo->qlock);
if (__sbi_fifo_is_empty(fifo)) { if (__sbi_fifo_is_empty(fifo)) {
@ -113,11 +113,11 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
return ret; return ret;
} }
for (i = 0; i < fifo->avail; i ++) { for (i = 0; i < fifo->avail; i++) {
index = fifo->tail + i; index = fifo->tail + i;
if (index >= fifo->num_entries) if (index >= fifo->num_entries)
index = index - fifo->num_entries; index = index - fifo->num_entries;
entry = (void *)fifo->queue + (u32) index * fifo->entry_size; entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
ret = fptr(in, entry); ret = fptr(in, entry);
if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) { if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
break; break;

View file

@ -35,8 +35,7 @@ static void mstatus_init(struct sbi_scratch *scratch, u32 hartid)
csr_write(CSR_MSTATUS, MSTATUS_FS); csr_write(CSR_MSTATUS, MSTATUS_FS);
/* Enable user/supervisor use of perf counters */ /* Enable user/supervisor use of perf counters */
if (misa_extension('S') && if (misa_extension('S') && sbi_platform_has_scounteren(plat))
sbi_platform_has_scounteren(plat))
csr_write(CSR_SCOUNTEREN, -1); csr_write(CSR_SCOUNTEREN, -1);
if (sbi_platform_has_mcounteren(plat)) if (sbi_platform_has_mcounteren(plat))
csr_write(CSR_MCOUNTEREN, -1); csr_write(CSR_MCOUNTEREN, -1);
@ -88,8 +87,7 @@ static int delegate_traps(struct sbi_scratch *scratch, u32 hartid)
/* Send M-mode interrupts and most exceptions to S-mode */ /* Send M-mode interrupts and most exceptions to S-mode */
interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP;
exceptions = (1U << CAUSE_MISALIGNED_FETCH) | exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) |
(1U << CAUSE_BREAKPOINT) |
(1U << CAUSE_USER_ECALL); (1U << CAUSE_USER_ECALL);
if (sbi_platform_has_mfaults_delegation(plat)) if (sbi_platform_has_mfaults_delegation(plat))
exceptions |= (1U << CAUSE_FETCH_PAGE_FAULT) | exceptions |= (1U << CAUSE_FETCH_PAGE_FAULT) |
@ -175,8 +173,8 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid)
count = (PMP_COUNT - 1); count = (PMP_COUNT - 1);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (sbi_platform_pmp_region_info(plat, hartid, i, if (sbi_platform_pmp_region_info(plat, hartid, i, &prot, &addr,
&prot, &addr, &log2size)) &log2size))
continue; continue;
pmp_set(i + 1, prot, addr, log2size); pmp_set(i + 1, prot, addr, log2size);
} }
@ -208,10 +206,9 @@ void __attribute__((noreturn)) sbi_hart_hang(void)
__builtin_unreachable(); __builtin_unreachable();
} }
void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, void __attribute__((noreturn))
unsigned long arg1, sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
unsigned long next_addr, unsigned long next_addr, unsigned long next_mode)
unsigned long next_mode)
{ {
unsigned long val; unsigned long val;
@ -248,9 +245,9 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0,
csr_write(CSR_UIE, 0); csr_write(CSR_UIE, 0);
} }
register unsigned long a0 asm ("a0") = arg0; register unsigned long a0 asm("a0") = arg0;
register unsigned long a1 asm ("a1") = arg1; register unsigned long a1 asm("a1") = arg1;
__asm__ __volatile__ ("mret" : : "r" (a0), "r" (a1)); __asm__ __volatile__("mret" : : "r"(a0), "r"(a1));
__builtin_unreachable(); __builtin_unreachable();
} }
@ -327,7 +324,7 @@ void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid)
const struct sbi_platform *plat = sbi_platform_ptr(scratch); const struct sbi_platform *plat = sbi_platform_ptr(scratch);
int max_hart = sbi_platform_hart_count(plat); int max_hart = sbi_platform_hart_count(plat);
for(int i = 0; i < max_hart ; i++) { for (int i = 0; i < max_hart; i++) {
/* send an IPI to every other hart */ /* send an IPI to every other hart */
spin_lock(&coldboot_wait_bitmap_lock); spin_lock(&coldboot_wait_bitmap_lock);
if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i))) if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i)))

View file

@ -16,21 +16,18 @@
#include <sbi/sbi_illegal_insn.h> #include <sbi/sbi_illegal_insn.h>
#include <sbi/sbi_trap.h> #include <sbi/sbi_trap.h>
typedef int (*illegal_insn_func)(ulong insn, typedef int (*illegal_insn_func)(ulong insn, u32 hartid, ulong mcause,
u32 hartid, ulong mcause,
struct sbi_trap_regs *regs, struct sbi_trap_regs *regs,
struct sbi_scratch *scratch); struct sbi_scratch *scratch);
static int truly_illegal_insn(ulong insn, static int truly_illegal_insn(ulong insn, u32 hartid, ulong mcause,
u32 hartid, ulong mcause,
struct sbi_trap_regs *regs, struct sbi_trap_regs *regs,
struct sbi_scratch *scratch) struct sbi_scratch *scratch)
{ {
return sbi_trap_redirect(regs, scratch, regs->mepc, mcause, insn); return sbi_trap_redirect(regs, scratch, regs->mepc, mcause, insn);
} }
static int system_opcode_insn(ulong insn, static int system_opcode_insn(ulong insn, u32 hartid, ulong mcause,
u32 hartid, ulong mcause,
struct sbi_trap_regs *regs, struct sbi_trap_regs *regs,
struct sbi_scratch *scratch) struct sbi_scratch *scratch)
{ {
@ -39,10 +36,9 @@ static int system_opcode_insn(ulong insn,
int csr_num = (u32)insn >> 20; int csr_num = (u32)insn >> 20;
ulong csr_val, new_csr_val; ulong csr_val, new_csr_val;
if (sbi_emulate_csr_read(csr_num, hartid, regs->mstatus, if (sbi_emulate_csr_read(csr_num, hartid, regs->mstatus, scratch,
scratch, &csr_val)) &csr_val))
return truly_illegal_insn(insn, hartid, mcause, return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
regs, scratch);
do_write = rs1_num; do_write = rs1_num;
switch (GET_RM(insn)) { switch (GET_RM(insn)) {
@ -53,7 +49,8 @@ static int system_opcode_insn(ulong insn,
case 2: case 2:
new_csr_val = csr_val | rs1_val; new_csr_val = csr_val | rs1_val;
break; break;
case 3: new_csr_val = csr_val & ~rs1_val; case 3:
new_csr_val = csr_val & ~rs1_val;
break; break;
case 5: case 5:
new_csr_val = rs1_num; new_csr_val = rs1_num;
@ -66,15 +63,12 @@ static int system_opcode_insn(ulong insn,
new_csr_val = csr_val & ~rs1_num; new_csr_val = csr_val & ~rs1_num;
break; break;
default: default:
return truly_illegal_insn(insn, hartid, mcause, return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
regs, scratch);
}; };
if (do_write && if (do_write && sbi_emulate_csr_write(csr_num, hartid, regs->mstatus,
sbi_emulate_csr_write(csr_num, hartid, regs->mstatus,
scratch, new_csr_val)) scratch, new_csr_val))
return truly_illegal_insn(insn, hartid, mcause, return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
regs, scratch);
SET_RD(insn, regs, csr_val); SET_RD(insn, regs, csr_val);
@ -128,8 +122,8 @@ int sbi_illegal_insn_handler(u32 hartid, ulong mcause,
if (insn == 0) if (insn == 0)
insn = get_insn(regs->mepc, NULL); insn = get_insn(regs->mepc, NULL);
if ((insn & 3) != 3) if ((insn & 3) != 3)
return truly_illegal_insn(insn, hartid, mcause, return truly_illegal_insn(insn, hartid, mcause, regs,
regs, scratch); scratch);
} }
return illegal_insn_table[(insn & 0x7c) >> 2](insn, hartid, mcause, return illegal_insn_table[(insn & 0x7c) >> 2](insn, hartid, mcause,

View file

@ -34,9 +34,8 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
const struct sbi_platform *plat = sbi_platform_ptr(scratch); const struct sbi_platform *plat = sbi_platform_ptr(scratch);
misa_string(str, sizeof(str)); misa_string(str, sizeof(str));
sbi_printf("\nOpenSBI v%d.%d (%s %s)\n", sbi_printf("\nOpenSBI v%d.%d (%s %s)\n", OPENSBI_VERSION_MAJOR,
OPENSBI_VERSION_MAJOR, OPENSBI_VERSION_MINOR, OPENSBI_VERSION_MINOR, __DATE__, __TIME__);
__DATE__, __TIME__);
sbi_printf(BANNER); sbi_printf(BANNER);
@ -97,8 +96,8 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
if (!sbi_platform_has_hart_hotplug(plat)) if (!sbi_platform_has_hart_hotplug(plat))
sbi_hart_wake_coldboot_harts(scratch, hartid); sbi_hart_wake_coldboot_harts(scratch, hartid);
sbi_hart_mark_available(hartid); sbi_hart_mark_available(hartid);
sbi_hart_switch_mode(hartid, scratch->next_arg1, sbi_hart_switch_mode(hartid, scratch->next_arg1, scratch->next_addr,
scratch->next_addr, scratch->next_mode); scratch->next_mode);
} }
static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid) static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)

View file

@ -36,8 +36,7 @@ static inline int __sbi_tlb_fifo_range_check(struct sbi_tlb_info *curr,
curr->start = next->start; curr->start = next->start;
curr->size = next->size; curr->size = next->size;
ret = SBI_FIFO_UPDATED; ret = SBI_FIFO_UPDATED;
} else if (next->start >= curr->start && } else if (next->start >= curr->start && next_end <= curr_end) {
next_end <= curr_end) {
ret = SBI_FIFO_SKIP; ret = SBI_FIFO_SKIP;
} }
@ -69,8 +68,8 @@ int sbi_tlb_fifo_update_cb(void *in, void *data)
if (!in && !!data) if (!in && !!data)
return ret; return ret;
curr = (struct sbi_tlb_info *) data; curr = (struct sbi_tlb_info *)data;
next = (struct sbi_tlb_info *) in; next = (struct sbi_tlb_info *)in;
if (next->type == SBI_TLB_FLUSH_VMA_ASID && if (next->type == SBI_TLB_FLUSH_VMA_ASID &&
curr->type == SBI_TLB_FLUSH_VMA_ASID) { curr->type == SBI_TLB_FLUSH_VMA_ASID) {
if (next->asid == curr->asid) if (next->asid == curr->asid)
@ -86,8 +85,8 @@ int sbi_tlb_fifo_update_cb(void *in, void *data)
return ret; return ret;
} }
static int sbi_ipi_send(struct sbi_scratch *scratch, u32 hartid, static int sbi_ipi_send(struct sbi_scratch *scratch, u32 hartid, u32 event,
u32 event, void *data) void *data)
{ {
struct sbi_scratch *remote_scratch = NULL; struct sbi_scratch *remote_scratch = NULL;
const struct sbi_platform *plat = sbi_platform_ptr(scratch); const struct sbi_platform *plat = sbi_platform_ptr(scratch);
@ -109,7 +108,7 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 hartid,
if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) { if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
goto done; goto done;
} }
while(sbi_fifo_enqueue(ipi_tlb_fifo, data) < 0) { while (sbi_fifo_enqueue(ipi_tlb_fifo, data) < 0) {
/** /**
* For now, Busy loop until there is space in the fifo. * For now, Busy loop until there is space in the fifo.
* There may be case where target hart is also * There may be case where target hart is also
@ -132,8 +131,8 @@ done:
return 0; return 0;
} }
int sbi_ipi_send_many(struct sbi_scratch *scratch, int sbi_ipi_send_many(struct sbi_scratch *scratch, ulong *pmask, u32 event,
ulong *pmask, u32 event, void *data) void *data)
{ {
ulong i, m; ulong i, m;
ulong mask = sbi_hart_available_mask(); ulong mask = sbi_hart_available_mask();
@ -153,7 +152,6 @@ int sbi_ipi_send_many(struct sbi_scratch *scratch,
if (mask & (1UL << hartid)) if (mask & (1UL << hartid))
sbi_ipi_send(scratch, hartid, event, data); sbi_ipi_send(scratch, hartid, event, data);
return 0; return 0;
} }
@ -179,8 +177,9 @@ static void sbi_ipi_sfence_vma(struct sbi_tlb_info *tinfo)
} }
for (i = 0; i < size; i += PAGE_SIZE) { for (i = 0; i < size; i += PAGE_SIZE) {
__asm__ __volatile__ ("sfence.vma %0" __asm__ __volatile__("sfence.vma %0"
: : "r" (start + i) :
: "r"(start + i)
: "memory"); : "memory");
} }
} }
@ -199,15 +198,17 @@ static void sbi_ipi_sfence_vma_asid(struct sbi_tlb_info *tinfo)
/* Flush entire MM context for a given ASID */ /* Flush entire MM context for a given ASID */
if (size == SBI_TLB_FLUSH_ALL) { if (size == SBI_TLB_FLUSH_ALL) {
__asm__ __volatile__ ("sfence.vma x0, %0" __asm__ __volatile__("sfence.vma x0, %0"
: : "r" (asid) :
: "r"(asid)
: "memory"); : "memory");
return; return;
} }
for (i = 0; i < size; i += PAGE_SIZE) { for (i = 0; i < size; i += PAGE_SIZE) {
__asm__ __volatile__ ("sfence.vma %0, %1" __asm__ __volatile__("sfence.vma %0, %1"
: : "r" (start + i), "r" (asid) :
: "r"(start + i), "r"(asid)
: "memory"); : "memory");
} }
} }
@ -236,7 +237,7 @@ void sbi_ipi_process(struct sbi_scratch *scratch)
break; break;
case SBI_IPI_EVENT_SFENCE_VMA: case SBI_IPI_EVENT_SFENCE_VMA:
case SBI_IPI_EVENT_SFENCE_VMA_ASID: case SBI_IPI_EVENT_SFENCE_VMA_ASID:
while(!sbi_fifo_dequeue(ipi_tlb_fifo, &tinfo)) { while (!sbi_fifo_dequeue(ipi_tlb_fifo, &tinfo)) {
if (tinfo.type == SBI_TLB_FLUSH_VMA) if (tinfo.type == SBI_TLB_FLUSH_VMA)
sbi_ipi_sfence_vma(&tinfo); sbi_ipi_sfence_vma(&tinfo);
else if (tinfo.type == SBI_TLB_FLUSH_VMA_ASID) else if (tinfo.type == SBI_TLB_FLUSH_VMA_ASID)
@ -248,8 +249,9 @@ void sbi_ipi_process(struct sbi_scratch *scratch)
sbi_hart_hang(); sbi_hart_hang();
break; break;
}; };
ipi_type = atomic_raw_clear_bit(ipi_event, &sbi_ipi_data_ptr(scratch)->ipi_type); ipi_type = atomic_raw_clear_bit(
} while(ipi_type > 0); ipi_event, &sbi_ipi_data_ptr(scratch)->ipi_type);
} while (ipi_type > 0);
} }
int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot) int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot)
@ -263,6 +265,5 @@ int sbi_ipi_init(struct sbi_scratch *scratch, bool cold_boot)
/* Enable software interrupts */ /* Enable software interrupts */
csr_set(CSR_MIE, MIP_MSIP); csr_set(CSR_MIE, MIP_MSIP);
return sbi_platform_ipi_init(sbi_platform_ptr(scratch), return sbi_platform_ipi_init(sbi_platform_ptr(scratch), cold_boot);
cold_boot);
} }

View file

@ -52,7 +52,7 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause,
} else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) { } else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) {
len = 2; len = 2;
#ifdef __riscv_compressed #ifdef __riscv_compressed
# if __riscv_xlen >= 64 #if __riscv_xlen >= 64
} else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) { } else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) {
len = 8; len = 8;
shift = 8 * (sizeof(ulong) - len); shift = 8 * (sizeof(ulong) - len);
@ -61,8 +61,8 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause,
((insn >> SH_RD) & 0x1f)) { ((insn >> SH_RD) & 0x1f)) {
len = 8; len = 8;
shift = 8 * (sizeof(ulong) - len); shift = 8 * (sizeof(ulong) - len);
# endif #endif
} else if ((insn & INSN_MASK_C_LW) ==INSN_MATCH_C_LW) { } else if ((insn & INSN_MASK_C_LW) == INSN_MATCH_C_LW) {
len = 4; len = 4;
shift = 8 * (sizeof(ulong) - len); shift = 8 * (sizeof(ulong) - len);
insn = RVC_RS2S(insn) << SH_RD; insn = RVC_RS2S(insn) << SH_RD;
@ -77,7 +77,7 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause,
} else if ((insn & INSN_MASK_C_FLDSP) == INSN_MATCH_C_FLDSP) { } else if ((insn & INSN_MASK_C_FLDSP) == INSN_MATCH_C_FLDSP) {
fp = 1; fp = 1;
len = 8; len = 8;
# if __riscv_xlen == 32 #if __riscv_xlen == 32
} else if ((insn & INSN_MASK_C_FLW) == INSN_MATCH_C_FLW) { } else if ((insn & INSN_MASK_C_FLW) == INSN_MATCH_C_FLW) {
fp = 1; fp = 1;
len = 4; len = 4;
@ -85,7 +85,7 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause,
} else if ((insn & INSN_MASK_C_FLWSP) == INSN_MATCH_C_FLWSP) { } else if ((insn & INSN_MASK_C_FLWSP) == INSN_MATCH_C_FLWSP) {
fp = 1; fp = 1;
len = 4; len = 4;
# endif #endif
#endif #endif
} else } else
return SBI_EILL; return SBI_EILL;
@ -132,7 +132,7 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause,
} else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) { } else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) {
len = 2; len = 2;
#ifdef __riscv_compressed #ifdef __riscv_compressed
# if __riscv_xlen >= 64 #if __riscv_xlen >= 64
} else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) { } else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) {
len = 8; len = 8;
val.data_ulong = GET_RS2S(insn, regs); val.data_ulong = GET_RS2S(insn, regs);
@ -140,7 +140,7 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause,
((insn >> SH_RD) & 0x1f)) { ((insn >> SH_RD) & 0x1f)) {
len = 8; len = 8;
val.data_ulong = GET_RS2C(insn, regs); val.data_ulong = GET_RS2C(insn, regs);
# endif #endif
} else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) { } else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) {
len = 4; len = 4;
val.data_ulong = GET_RS2S(insn, regs); val.data_ulong = GET_RS2S(insn, regs);
@ -154,14 +154,14 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause,
} else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) { } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) {
len = 8; len = 8;
val.data_u64 = GET_F64_RS2C(insn, regs); val.data_u64 = GET_F64_RS2C(insn, regs);
# if __riscv_xlen == 32 #if __riscv_xlen == 32
} else if ((insn & INSN_MASK_C_FSW) == INSN_MATCH_C_FSW) { } else if ((insn & INSN_MASK_C_FSW) == INSN_MATCH_C_FSW) {
len = 4; len = 4;
val.data_ulong = GET_F32_RS2S(insn, regs); val.data_ulong = GET_F32_RS2S(insn, regs);
} else if ((insn & INSN_MASK_C_FSWSP) == INSN_MATCH_C_FSWSP) { } else if ((insn & INSN_MASK_C_FSWSP) == INSN_MATCH_C_FSWSP) {
len = 4; len = 4;
val.data_ulong = GET_F32_RS2C(insn, regs); val.data_ulong = GET_F32_RS2C(insn, regs);
# endif #endif
#endif #endif
} else } else
return SBI_EILL; return SBI_EILL;

View file

@ -15,26 +15,24 @@
int sbi_system_early_init(struct sbi_scratch *scratch, bool cold_boot) int sbi_system_early_init(struct sbi_scratch *scratch, bool cold_boot)
{ {
return sbi_platform_early_init(sbi_platform_ptr(scratch), return sbi_platform_early_init(sbi_platform_ptr(scratch), cold_boot);
cold_boot);
} }
int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot) int sbi_system_final_init(struct sbi_scratch *scratch, bool cold_boot)
{ {
return sbi_platform_final_init(sbi_platform_ptr(scratch), return sbi_platform_final_init(sbi_platform_ptr(scratch), cold_boot);
cold_boot);
} }
void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch, void __attribute__((noreturn))
u32 type) sbi_system_reboot(struct sbi_scratch *scratch, u32 type)
{ {
sbi_platform_system_reboot(sbi_platform_ptr(scratch), type); sbi_platform_system_reboot(sbi_platform_ptr(scratch), type);
sbi_hart_hang(); sbi_hart_hang();
} }
void __attribute__((noreturn)) sbi_system_shutdown(struct sbi_scratch *scratch, void __attribute__((noreturn))
u32 type) sbi_system_shutdown(struct sbi_scratch *scratch, u32 type)
{ {
/* First try the platform-specific method */ /* First try the platform-specific method */
sbi_platform_system_shutdown(sbi_platform_ptr(scratch), type); sbi_platform_system_shutdown(sbi_platform_ptr(scratch), type);

View file

@ -16,13 +16,12 @@
u64 get_ticks(void) u64 get_ticks(void)
{ {
u32 lo, hi, tmp; u32 lo, hi, tmp;
__asm__ __volatile__ ( __asm__ __volatile__("1:\n"
"1:\n"
"rdtimeh %0\n" "rdtimeh %0\n"
"rdtime %1\n" "rdtime %1\n"
"rdtimeh %2\n" "rdtimeh %2\n"
"bne %0, %2, 1b" "bne %0, %2, 1b"
: "=&r" (hi), "=&r" (lo), "=&r" (tmp)); : "=&r"(hi), "=&r"(lo), "=&r"(tmp));
return ((u64)hi << 32) | lo; return ((u64)hi << 32) | lo;
} }
#else #else
@ -30,9 +29,7 @@ u64 get_ticks(void)
{ {
unsigned long n; unsigned long n;
__asm__ __volatile__ ( __asm__ __volatile__("rdtime %0" : "=r"(n));
"rdtime %0"
: "=r" (n));
return n; return n;
} }
#endif #endif
@ -54,8 +51,7 @@ void sbi_timer_event_stop(struct sbi_scratch *scratch)
void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event) void sbi_timer_event_start(struct sbi_scratch *scratch, u64 next_event)
{ {
sbi_platform_timer_event_start(sbi_platform_ptr(scratch), sbi_platform_timer_event_start(sbi_platform_ptr(scratch), next_event);
next_event);
csr_clear(CSR_MIP, MIP_STIP); csr_clear(CSR_MIP, MIP_STIP);
csr_set(CSR_MIE, MIP_MTIP); csr_set(CSR_MIE, MIP_MTIP);
} }
@ -68,6 +64,5 @@ void sbi_timer_process(struct sbi_scratch *scratch)
int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
{ {
return sbi_platform_timer_init(sbi_platform_ptr(scratch), return sbi_platform_timer_init(sbi_platform_ptr(scratch), cold_boot);
cold_boot);
} }

View file

@ -19,49 +19,47 @@
#include <sbi/sbi_timer.h> #include <sbi/sbi_timer.h>
#include <sbi/sbi_trap.h> #include <sbi/sbi_trap.h>
static void __noreturn sbi_trap_error(const char *msg, static void __noreturn sbi_trap_error(const char *msg, int rc, u32 hartid,
int rc, u32 hartid,
ulong mcause, ulong mtval, ulong mcause, ulong mtval,
struct sbi_trap_regs *regs) struct sbi_trap_regs *regs)
{ {
sbi_printf("%s: hart%d: %s (error %d)\n", sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc);
__func__, hartid, msg, rc); sbi_printf("%s: hart%d: mcause=0x%" PRILX " mtval=0x%" PRILX "\n",
sbi_printf("%s: hart%d: mcause=0x%"PRILX" mtval=0x%"PRILX"\n",
__func__, hartid, mcause, mtval); __func__, hartid, mcause, mtval);
sbi_printf("%s: hart%d: mepc=0x%"PRILX" mstatus=0x%"PRILX"\n", sbi_printf("%s: hart%d: mepc=0x%" PRILX " mstatus=0x%" PRILX "\n",
__func__, hartid, regs->mepc, regs->mstatus); __func__, hartid, regs->mepc, regs->mstatus);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "ra", regs->ra, "sp", regs->sp); hartid, "ra", regs->ra, "sp", regs->sp);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "gp", regs->gp, "tp", regs->tp); hartid, "gp", regs->gp, "tp", regs->tp);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s0", regs->s0, "s1", regs->s1); hartid, "s0", regs->s0, "s1", regs->s1);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "a0", regs->a0, "a1", regs->a1); hartid, "a0", regs->a0, "a1", regs->a1);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "a2", regs->a2, "a3", regs->a3); hartid, "a2", regs->a2, "a3", regs->a3);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "a4", regs->a4, "a5", regs->a5); hartid, "a4", regs->a4, "a5", regs->a5);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "a6", regs->a6, "a7", regs->a7); hartid, "a6", regs->a6, "a7", regs->a7);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s2", regs->s2, "s3", regs->s3); hartid, "s2", regs->s2, "s3", regs->s3);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s4", regs->s4, "s5", regs->s5); hartid, "s4", regs->s4, "s5", regs->s5);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s6", regs->s6, "s7", regs->s7); hartid, "s6", regs->s6, "s7", regs->s7);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s8", regs->s8, "s9", regs->s9); hartid, "s8", regs->s8, "s9", regs->s9);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "s10", regs->s10, "s11", regs->s11); hartid, "s10", regs->s10, "s11", regs->s11);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "t0", regs->t0, "t1", regs->t1); hartid, "t0", regs->t0, "t1", regs->t1);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "t2", regs->t2, "t3", regs->t3); hartid, "t2", regs->t2, "t3", regs->t3);
sbi_printf("%s: hart%d: %s=0x%"PRILX" %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
__func__, hartid, "t4", regs->t4, "t5", regs->t5); hartid, "t4", regs->t4, "t5", regs->t5);
sbi_printf("%s: hart%d: %s=0x%"PRILX"\n", sbi_printf("%s: hart%d: %s=0x%" PRILX "\n", __func__, hartid, "t6",
__func__, hartid, "t6", regs->t6); regs->t6);
sbi_hart_hang(); sbi_hart_hang();
} }
@ -77,8 +75,7 @@ static void __noreturn sbi_trap_error(const char *msg,
* *
* @return 0 on success and negative error code on failure * @return 0 on success and negative error code on failure
*/ */
int sbi_trap_redirect(struct sbi_trap_regs *regs, int sbi_trap_redirect(struct sbi_trap_regs *regs, struct sbi_scratch *scratch,
struct sbi_scratch *scratch,
ulong epc, ulong cause, ulong tval) ulong epc, ulong cause, ulong tval)
{ {
ulong new_mstatus, prev_mode; ulong new_mstatus, prev_mode;
@ -100,8 +97,8 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs,
new_mstatus = regs->mstatus; new_mstatus = regs->mstatus;
/* Clear MPP, SPP, SPIE, and SIE */ /* Clear MPP, SPP, SPIE, and SIE */
new_mstatus &= ~(MSTATUS_MPP | new_mstatus &=
MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE); ~(MSTATUS_MPP | MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE);
/* Set SPP */ /* Set SPP */
if (prev_mode == PRV_S) if (prev_mode == PRV_S)
@ -135,8 +132,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs,
* @param regs pointer to register state * @param regs pointer to register state
* @param scratch pointer to sbi_scratch of current HART * @param scratch pointer to sbi_scratch of current HART
*/ */
void sbi_trap_handler(struct sbi_trap_regs *regs, void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch)
struct sbi_scratch *scratch)
{ {
int rc = SBI_ENOTSUPP; int rc = SBI_ENOTSUPP;
const char *msg = "trap handler failed"; const char *msg = "trap handler failed";
@ -170,7 +166,8 @@ void sbi_trap_handler(struct sbi_trap_regs *regs,
msg = "misaligned load handler failed"; msg = "misaligned load handler failed";
break; break;
case CAUSE_MISALIGNED_STORE: case CAUSE_MISALIGNED_STORE:
rc = sbi_misaligned_store_handler(hartid, mcause, regs, scratch); rc = sbi_misaligned_store_handler(hartid, mcause, regs,
scratch);
msg = "misaligned store handler failed"; msg = "misaligned store handler failed";
break; break;
case CAUSE_SUPERVISOR_ECALL: case CAUSE_SUPERVISOR_ECALL:
@ -186,6 +183,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs,
trap_error: trap_error:
if (rc) { if (rc) {
sbi_trap_error(msg, rc, hartid, mcause, csr_read(CSR_MTVAL), regs); sbi_trap_error(msg, rc, hartid, mcause, csr_read(CSR_MTVAL),
regs);
} }
} }

View file

@ -14,10 +14,8 @@
void plic_fdt_fixup(void *fdt, const char *compat); void plic_fdt_fixup(void *fdt, const char *compat);
int plic_warm_irqchip_init(u32 target_hart, int plic_warm_irqchip_init(u32 target_hart, int m_cntx_id, int s_cntx_id);
int m_cntx_id, int s_cntx_id);
int plic_cold_irqchip_init(unsigned long base, int plic_cold_irqchip_init(unsigned long base, u32 num_sources, u32 hart_count);
u32 num_sources, u32 hart_count);
#endif #endif

View file

@ -16,7 +16,6 @@ void sifive_uart_putc(char ch);
int sifive_uart_getc(void); int sifive_uart_getc(void);
int sifive_uart_init(unsigned long base, int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate);
u32 in_freq, u32 baudrate);
#endif #endif

View file

@ -16,8 +16,7 @@ void uart8250_putc(char ch);
int uart8250_getc(void); int uart8250_getc(void);
int uart8250_init(unsigned long base, int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
u32 in_freq, u32 baudrate, u32 reg_width);
u32 reg_shift, u32 reg_width);
#endif #endif

View file

@ -18,7 +18,7 @@ size_t strlen(const char *str);
size_t strnlen(const char *str, size_t count); size_t strnlen(const char *str, size_t count);
char *strcpy(char *dest,const char *src); char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t count); char *strncpy(char *dest, const char *src, size_t count);
@ -26,13 +26,13 @@ char *strchr(const char *s, int c);
char *strrchr(const char *s, int c); char *strrchr(const char *s, int c);
void *memset(void *s,int c,size_t count); void *memset(void *s, int c, size_t count);
void *memcpy(void *dest, const void *src, size_t count); void *memcpy(void *dest, const void *src, size_t count);
void *memmove(void *dest,const void *src, size_t count); void *memmove(void *dest, const void *src, size_t count);
int memcmp(const void *s1,const void *s2, size_t count); int memcmp(const void *s1, const void *s2, size_t count);
void *memchr(const void *s, int c, size_t count); void *memchr(const void *s, int c, size_t count);

View file

@ -38,33 +38,27 @@ ulong fdt_strlen(const char *str);
int fdt_strcmp(const char *a, const char *b); int fdt_strcmp(const char *a, const char *b);
/* Find index of matching string from a list of strings */ /* Find index of matching string from a list of strings */
int fdt_prop_string_index(const struct fdt_prop *prop, int fdt_prop_string_index(const struct fdt_prop *prop, const char *str);
const char *str);
/* Iterate over each property of matching node */ /* Iterate over each property of matching node */
int fdt_match_node_prop(void *fdt, int fdt_match_node_prop(void *fdt,
int (*match)(const struct fdt_node *node, int (*match)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *match_priv, void *match_priv,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv); void *fn_priv);
/* Iterate over each property of compatible node */ /* Iterate over each property of compatible node */
int fdt_compat_node_prop(void *fdt, int fdt_compat_node_prop(void *fdt, const char *compat,
const char *compat,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv); void *fn_priv);
/* Iterate over each node and property */ /* Iterate over each node and property */
int fdt_walk(void *fdt, int fdt_walk(void *fdt,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv); void *fn_priv);
/* Get size of FDT */ /* Get size of FDT */

View file

@ -27,31 +27,27 @@ static volatile void *plic_base;
static void plic_set_priority(u32 source, u32 val) static void plic_set_priority(u32 source, u32 val)
{ {
volatile void *plic_priority = plic_base + volatile void *plic_priority =
PLIC_PRIORITY_BASE + plic_base + PLIC_PRIORITY_BASE + 4 * source;
4 * source;
writel(val, plic_priority); writel(val, plic_priority);
} }
static void plic_set_thresh(u32 cntxid, u32 val) static void plic_set_thresh(u32 cntxid, u32 val)
{ {
volatile void *plic_thresh = plic_base + volatile void *plic_thresh =
PLIC_CONTEXT_BASE + plic_base + PLIC_CONTEXT_BASE + PLIC_CONTEXT_STRIDE * cntxid;
PLIC_CONTEXT_STRIDE * cntxid;
writel(val, plic_thresh); writel(val, plic_thresh);
} }
static void plic_set_ie(u32 cntxid, u32 word_index, u32 val) static void plic_set_ie(u32 cntxid, u32 word_index, u32 val)
{ {
volatile void *plic_ie = plic_base + volatile void *plic_ie =
PLIC_ENABLE_BASE + plic_base + PLIC_ENABLE_BASE + PLIC_ENABLE_STRIDE * cntxid;
PLIC_ENABLE_STRIDE * cntxid;
writel(val, plic_ie + word_index * 4); writel(val, plic_ie + word_index * 4);
} }
static void plic_fdt_fixup_prop(const struct fdt_node *node, static void plic_fdt_fixup_prop(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv)
void *priv)
{ {
u32 *cells; u32 *cells;
u32 i, cells_count; u32 i, cells_count;
@ -67,9 +63,9 @@ static void plic_fdt_fixup_prop(const struct fdt_node *node,
if (!cells_count) if (!cells_count)
return; return;
for (i = 0; i < (cells_count/2); i++) { for (i = 0; i < (cells_count / 2); i++) {
if (fdt_rev32(cells[2*i+1]) == IRQ_M_EXT) if (fdt_rev32(cells[2 * i + 1]) == IRQ_M_EXT)
cells[2*i+1] = fdt_rev32(0xffffffff); cells[2 * i + 1] = fdt_rev32(0xffffffff);
} }
} }
@ -78,8 +74,7 @@ void plic_fdt_fixup(void *fdt, const char *compat)
fdt_compat_node_prop(fdt, compat, plic_fdt_fixup_prop, NULL); fdt_compat_node_prop(fdt, compat, plic_fdt_fixup_prop, NULL);
} }
int plic_warm_irqchip_init(u32 target_hart, int plic_warm_irqchip_init(u32 target_hart, int m_cntx_id, int s_cntx_id)
int m_cntx_id, int s_cntx_id)
{ {
size_t i, ie_words = plic_num_sources / 32 + 1; size_t i, ie_words = plic_num_sources / 32 + 1;
@ -109,8 +104,7 @@ int plic_warm_irqchip_init(u32 target_hart,
return 0; return 0;
} }
int plic_cold_irqchip_init(unsigned long base, int plic_cold_irqchip_init(unsigned long base, u32 num_sources, u32 hart_count)
u32 num_sources, u32 hart_count)
{ {
int i; int i;

View file

@ -17,7 +17,8 @@
int strcmp(const char *a, const char *b) int strcmp(const char *a, const char *b)
{ {
/* search first diff or end of string */ /* search first diff or end of string */
for (; *a == *b && *a != '\0'; a++, b++); for (; *a == *b && *a != '\0'; a++, b++)
;
return *a - *b; return *a - *b;
} }
@ -51,7 +52,7 @@ char *strcpy(char *dest, const char *src)
{ {
char *ret = dest; char *ret = dest;
while(*src != '\0') { while (*src != '\0') {
*dest++ = *src++; *dest++ = *src++;
} }
@ -62,7 +63,7 @@ char *strncpy(char *dest, const char *src, size_t count)
{ {
char *ret = dest; char *ret = dest;
while(count-- && *src != '\0') { while (count-- && *src != '\0') {
*dest++ = *src++; *dest++ = *src++;
} }
@ -71,7 +72,7 @@ char *strncpy(char *dest, const char *src, size_t count)
char *strchr(const char *s, int c) char *strchr(const char *s, int c)
{ {
while(*s != '\0' && *s != (char)c) while (*s != '\0' && *s != (char)c)
s++; s++;
if (*s == '\0') if (*s == '\0')
@ -96,7 +97,7 @@ void *memset(void *s, int c, size_t count)
{ {
char *temp = s; char *temp = s;
while(count > 0 ){ while (count > 0) {
count--; count--;
*temp++ = c; *temp++ = c;
} }
@ -126,7 +127,7 @@ void *memmove(void *dest, const void *src, size_t count)
return dest; return dest;
if (dest < src) { if (dest < src) {
while(count > 0) { while (count > 0) {
*temp1++ = *temp2++; *temp1++ = *temp2++;
count--; count--;
} }
@ -134,7 +135,7 @@ void *memmove(void *dest, const void *src, size_t count)
temp1 = dest + count - 1; temp1 = dest + count - 1;
temp2 = src + count - 1; temp2 = src + count - 1;
while(count > 0) { while (count > 0) {
*temp1-- = *temp2--; *temp1-- = *temp2--;
count--; count--;
} }
@ -165,7 +166,7 @@ void *memchr(const void *s, int c, size_t count)
while (count > 0) { while (count > 0) {
if ((unsigned char)c == *temp++) { if ((unsigned char)c == *temp++) {
return (void *)(temp-1); return (void *)(temp - 1);
} }
count--; count--;
} }

View file

@ -51,8 +51,8 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <libfdt_env.h>
#include <fdt.h> #include <fdt.h>
#include <libfdt_env.h>
#define FDT_FIRST_SUPPORTED_VERSION 0x02 #define FDT_FIRST_SUPPORTED_VERSION 0x02
#define FDT_LAST_SUPPORTED_VERSION 0x11 #define FDT_LAST_SUPPORTED_VERSION 0x11

View file

@ -52,8 +52,8 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <sbi/sbi_types.h>
#include <plat/string.h> #include <plat/string.h>
#include <sbi/sbi_types.h>
#define INT_MAX ((int)(~0U >> 1)) #define INT_MAX ((int)(~0U >> 1))
#define UINT_MAX ((unsigned int)~0U) #define UINT_MAX ((unsigned int)~0U)

View file

@ -68,7 +68,8 @@ static void set_reg(u32 num, u32 val)
void sifive_uart_putc(char ch) void sifive_uart_putc(char ch)
{ {
while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL); while (get_reg(UART_REG_TXFIFO) & UART_TXFIFO_FULL)
;
set_reg(UART_REG_TXFIFO, ch); set_reg(UART_REG_TXFIFO, ch);
} }
@ -81,8 +82,7 @@ int sifive_uart_getc(void)
return -1; return -1;
} }
int sifive_uart_init(unsigned long base, int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
u32 in_freq, u32 baudrate)
{ {
uart_base = (volatile void *)base; uart_base = (volatile void *)base;
uart_in_freq = in_freq; uart_in_freq = in_freq;

View file

@ -70,7 +70,8 @@ static void set_reg(u32 num, u32 val)
void uart8250_putc(char ch) void uart8250_putc(char ch)
{ {
while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0); while ((get_reg(UART_LSR_OFFSET) & UART_LSR_THRE) == 0)
;
set_reg(UART_THR_OFFSET, ch); set_reg(UART_THR_OFFSET, ch);
} }
@ -82,9 +83,8 @@ int uart8250_getc(void)
return -1; return -1;
} }
int uart8250_init(unsigned long base, int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
u32 in_freq, u32 baudrate, u32 reg_width)
u32 reg_shift, u32 reg_width)
{ {
u16 bdiv; u16 bdiv;

View file

@ -127,7 +127,8 @@ void clint_timer_event_start(u64 next_event)
#else #else
u32 mask = -1UL; u32 mask = -1UL;
writel_relaxed(next_event & mask, &clint_time_cmp[target_hart]); writel_relaxed(next_event & mask, &clint_time_cmp[target_hart]);
writel_relaxed(next_event >> 32, (void *)(&clint_time_cmp[target_hart]) + 0x04); writel_relaxed(next_event >> 32,
(void *)(&clint_time_cmp[target_hart]) + 0x04);
#endif #endif
} }
@ -135,8 +136,7 @@ int clint_warm_timer_init(void)
{ {
u32 target_hart = sbi_current_hartid(); u32 target_hart = sbi_current_hartid();
if (clint_time_hart_count <= target_hart || if (clint_time_hart_count <= target_hart || !clint_time_base)
!clint_time_base)
return -1; return -1;
/* Clear CLINT Time Compare */ /* Clear CLINT Time Compare */

View file

@ -34,14 +34,11 @@ struct fdt_header {
u32 fdt_rev32(u32 v) u32 fdt_rev32(u32 v)
{ {
return ((v & 0x000000FF) << 24) | return ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) |
((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24);
((v & 0x00FF0000) >> 8) |
((v & 0xFF000000) >> 24);
} }
int fdt_prop_string_index(const struct fdt_prop *prop, int fdt_prop_string_index(const struct fdt_prop *prop, const char *str)
const char *str)
{ {
int i; int i;
ulong l = 0; ulong l = 0;
@ -62,14 +59,13 @@ int fdt_prop_string_index(const struct fdt_prop *prop,
} }
struct recursive_iter_info { struct recursive_iter_info {
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node, const struct fdt_prop *prop,
const struct fdt_prop *prop,
void *priv); void *priv);
void *fn_priv; void *fn_priv;
const char *str; const char *str;
}; };
#define DATA32(ptr) fdt_rev32(*((u32*)ptr)) #define DATA32(ptr) fdt_rev32(*((u32 *)ptr))
static void recursive_iter(char **data, struct recursive_iter_info *info, static void recursive_iter(char **data, struct recursive_iter_info *info,
const struct fdt_node *parent) const struct fdt_node *parent)
@ -129,19 +125,16 @@ static void recursive_iter(char **data, struct recursive_iter_info *info,
} }
struct match_iter_info { struct match_iter_info {
int (*match)(const struct fdt_node *node, int (*match)(const struct fdt_node *node, const struct fdt_prop *prop,
const struct fdt_prop *prop,
void *priv); void *priv);
void *match_priv; void *match_priv;
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node, const struct fdt_prop *prop,
const struct fdt_prop *prop,
void *priv); void *priv);
void *fn_priv; void *fn_priv;
const char *str; const char *str;
}; };
static void match_iter(const struct fdt_node *node, static void match_iter(const struct fdt_node *node, const struct fdt_prop *prop,
const struct fdt_prop *prop,
void *priv) void *priv)
{ {
char *data; char *data;
@ -185,12 +178,10 @@ static void match_iter(const struct fdt_node *node,
int fdt_match_node_prop(void *fdt, int fdt_match_node_prop(void *fdt,
int (*match)(const struct fdt_node *node, int (*match)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *match_priv, void *match_priv,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv) void *fn_priv)
{ {
char *data; char *data;
@ -230,8 +221,7 @@ struct match_compat_info {
}; };
static int match_compat(const struct fdt_node *node, static int match_compat(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv)
void *priv)
{ {
struct match_compat_info *cinfo = priv; struct match_compat_info *cinfo = priv;
@ -247,21 +237,17 @@ static int match_compat(const struct fdt_node *node,
return 1; return 1;
} }
int fdt_compat_node_prop(void *fdt, int fdt_compat_node_prop(void *fdt, const char *compat,
const char *compat,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv) void *fn_priv)
{ {
struct match_compat_info cinfo = { .compat = compat }; struct match_compat_info cinfo = { .compat = compat };
return fdt_match_node_prop(fdt, match_compat, &cinfo, return fdt_match_node_prop(fdt, match_compat, &cinfo, fn, fn_priv);
fn, fn_priv);
} }
static int match_walk(const struct fdt_node *node, static int match_walk(const struct fdt_node *node, const struct fdt_prop *prop,
const struct fdt_prop *prop,
void *priv) void *priv)
{ {
if (!prop) if (!prop)
@ -272,12 +258,10 @@ static int match_walk(const struct fdt_node *node,
int fdt_walk(void *fdt, int fdt_walk(void *fdt,
void (*fn)(const struct fdt_node *node, void (*fn)(const struct fdt_node *node,
const struct fdt_prop *prop, const struct fdt_prop *prop, void *priv),
void *priv),
void *fn_priv) void *fn_priv)
{ {
return fdt_match_node_prop(fdt, match_walk, NULL, return fdt_match_node_prop(fdt, match_walk, NULL, fn, fn_priv);
fn, fn_priv);
} }
u32 fdt_size(void *fdt) u32 fdt_size(void *fdt)

View file

@ -42,16 +42,13 @@ static int k210_irqchip_init(bool cold_boot)
u32 hartid = sbi_current_hartid(); u32 hartid = sbi_current_hartid();
if (cold_boot) { if (cold_boot) {
rc = plic_cold_irqchip_init(PLIC_BASE_ADDR, rc = plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES,
PLIC_NUM_SOURCES,
K210_HART_COUNT); K210_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }
return plic_warm_irqchip_init(hartid, return plic_warm_irqchip_init(hartid, (2 * hartid), (2 * hartid + 1));
(2 * hartid),
(2 * hartid + 1));
} }
static int k210_ipi_init(bool cold_boot) static int k210_ipi_init(bool cold_boot)
@ -59,8 +56,7 @@ static int k210_ipi_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_ipi_init(CLINT_BASE_ADDR, rc = clint_cold_ipi_init(CLINT_BASE_ADDR, K210_HART_COUNT);
K210_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }
@ -73,8 +69,7 @@ static int k210_timer_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_timer_init(CLINT_BASE_ADDR, rc = clint_cold_timer_init(CLINT_BASE_ADDR, K210_HART_COUNT);
K210_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }

View file

@ -55,4 +55,3 @@ u32 sysctl_get_cpu_freq(void)
return 0; return 0;
} }
} }

View file

@ -588,7 +588,7 @@ typedef struct _sysctl_clk_th6 {
typedef struct _sysctl_misc { typedef struct _sysctl_misc {
u32 debug_sel : 6; u32 debug_sel : 6;
u32 reserved0 : 4; u32 reserved0 : 4;
u32 spi_dvp_data_enable: 1; u32 spi_dvp_data_enable : 1;
u32 reserved1 : 21; u32 reserved1 : 21;
} __attribute__((packed, aligned(4))) sysctl_misc_t; } __attribute__((packed, aligned(4))) sysctl_misc_t;

View file

@ -47,7 +47,8 @@ void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit)
void uarths_putc(char c) void uarths_putc(char c)
{ {
while (uarths->txdata.full); while (uarths->txdata.full)
;
uarths->txdata.data = (u8)c; uarths->txdata.data = (u8)c;
} }
@ -61,4 +62,3 @@ int uarths_getc(void)
return rx.data; return rx.data;
} }

View file

@ -162,10 +162,7 @@ struct uarths {
struct uarths_div div; struct uarths_div div;
} __attribute__((packed, aligned(4))); } __attribute__((packed, aligned(4)));
enum uarths_stopbit { enum uarths_stopbit { UARTHS_STOP_1, UARTHS_STOP_2 };
UARTHS_STOP_1,
UARTHS_STOP_2
};
void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit); void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit);
void uarths_putc(char c); void uarths_putc(char c);

View file

@ -52,8 +52,8 @@ static u32 sifive_u_pmp_region_count(u32 hartid)
return 1; return 1;
} }
static int sifive_u_pmp_region_info(u32 hartid, u32 index, static int sifive_u_pmp_region_info(u32 hartid, u32 index, ulong *prot,
ulong *prot, ulong *addr, ulong *log2size) ulong *addr, ulong *log2size)
{ {
int ret = 0; int ret = 0;
@ -73,8 +73,8 @@ static int sifive_u_pmp_region_info(u32 hartid, u32 index,
static int sifive_u_console_init(void) static int sifive_u_console_init(void)
{ {
return sifive_uart_init(SIFIVE_U_UART0_ADDR, return sifive_uart_init(SIFIVE_U_UART0_ADDR, SIFIVE_U_PERIPH_CLK,
SIFIVE_U_PERIPH_CLK, 115200); 115200);
} }
static int sifive_u_irqchip_init(bool cold_boot) static int sifive_u_irqchip_init(bool cold_boot)
@ -90,9 +90,7 @@ static int sifive_u_irqchip_init(bool cold_boot)
return rc; return rc;
} }
return plic_warm_irqchip_init(hartid, return plic_warm_irqchip_init(hartid, (2 * hartid), (2 * hartid + 1));
(2 * hartid),
(2 * hartid + 1));
} }
static int sifive_u_ipi_init(bool cold_boot) static int sifive_u_ipi_init(bool cold_boot)

View file

@ -56,8 +56,8 @@ static u32 virt_pmp_region_count(u32 hartid)
return 1; return 1;
} }
static int virt_pmp_region_info(u32 hartid, u32 index, static int virt_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr,
ulong *prot, ulong *addr, ulong *log2size) ulong *log2size)
{ {
int ret = 0; int ret = 0;
@ -77,8 +77,7 @@ static int virt_pmp_region_info(u32 hartid, u32 index,
static int virt_console_init(void) static int virt_console_init(void)
{ {
return uart8250_init(VIRT_UART16550_ADDR, return uart8250_init(VIRT_UART16550_ADDR, VIRT_UART_SHIFTREG_ADDR,
VIRT_UART_SHIFTREG_ADDR,
VIRT_UART_BAUDRATE, 0, 1); VIRT_UART_BAUDRATE, 0, 1);
} }
@ -88,16 +87,13 @@ static int virt_irqchip_init(bool cold_boot)
u32 hartid = sbi_current_hartid(); u32 hartid = sbi_current_hartid();
if (cold_boot) { if (cold_boot) {
rc = plic_cold_irqchip_init(VIRT_PLIC_ADDR, rc = plic_cold_irqchip_init(
VIRT_PLIC_NUM_SOURCES, VIRT_PLIC_ADDR, VIRT_PLIC_NUM_SOURCES, VIRT_HART_COUNT);
VIRT_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }
return plic_warm_irqchip_init(hartid, return plic_warm_irqchip_init(hartid, (2 * hartid), (2 * hartid + 1));
(2 * hartid),
(2 * hartid + 1));
} }
static int virt_ipi_init(bool cold_boot) static int virt_ipi_init(bool cold_boot)
@ -105,8 +101,7 @@ static int virt_ipi_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_ipi_init(VIRT_CLINT_ADDR, rc = clint_cold_ipi_init(VIRT_CLINT_ADDR, VIRT_HART_COUNT);
VIRT_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }
@ -119,8 +114,7 @@ static int virt_timer_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_timer_init(VIRT_CLINT_ADDR, rc = clint_cold_timer_init(VIRT_CLINT_ADDR, VIRT_HART_COUNT);
VIRT_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }

View file

@ -67,7 +67,7 @@ static void fu540_modify_dt(void *fdt)
cpu_offset = fdt_path_offset(fdt, cpu_node); cpu_offset = fdt_path_offset(fdt, cpu_node);
mmu_type = fdt_getprop(fdt, cpu_offset, "mmu-type", NULL); mmu_type = fdt_getprop(fdt, cpu_offset, "mmu-type", NULL);
if (mmu_type && (!strcmp(mmu_type, "riscv,sv39") || if (mmu_type && (!strcmp(mmu_type, "riscv,sv39") ||
!strcmp(mmu_type,"riscv,sv48"))) !strcmp(mmu_type, "riscv,sv48")))
continue; continue;
else else
fdt_setprop_string(fdt, cpu_offset, "status", "masked"); fdt_setprop_string(fdt, cpu_offset, "status", "masked");
@ -76,7 +76,8 @@ static void fu540_modify_dt(void *fdt)
size = fdt_totalsize(fdt); size = fdt_totalsize(fdt);
err = fdt_open_into(fdt, fdt, size + 256); err = fdt_open_into(fdt, fdt, size + 256);
if (err < 0) if (err < 0)
sbi_printf("Device Tree can't be expanded to accmodate new node"); sbi_printf(
"Device Tree can't be expanded to accmodate new node");
chosen_offset = fdt_path_offset(fdt, "/chosen"); chosen_offset = fdt_path_offset(fdt, "/chosen");
fdt_setprop_string(fdt, chosen_offset, "stdout-path", fdt_setprop_string(fdt, chosen_offset, "stdout-path",
@ -103,8 +104,8 @@ static u32 fu540_pmp_region_count(u32 hartid)
return 1; return 1;
} }
static int fu540_pmp_region_info(u32 hartid, u32 index, static int fu540_pmp_region_info(u32 hartid, u32 index, ulong *prot,
ulong *prot, ulong *addr, ulong *log2size) ulong *addr, ulong *log2size)
{ {
int ret = 0; int ret = 0;
@ -134,8 +135,8 @@ static int fu540_console_init(void)
peri_in_freq = FU540_SYS_CLK / 2; peri_in_freq = FU540_SYS_CLK / 2;
} }
return sifive_uart_init(FU540_UART0_ADDR, return sifive_uart_init(FU540_UART0_ADDR, peri_in_freq,
peri_in_freq, FU540_UART_BAUDRATE); FU540_UART_BAUDRATE);
} }
static int fu540_irqchip_init(bool cold_boot) static int fu540_irqchip_init(bool cold_boot)
@ -151,8 +152,7 @@ static int fu540_irqchip_init(bool cold_boot)
return rc; return rc;
} }
return plic_warm_irqchip_init(hartid, return plic_warm_irqchip_init(hartid, (hartid) ? (2 * hartid - 1) : 0,
(hartid) ? (2 * hartid - 1) : 0,
(hartid) ? (2 * hartid) : -1); (hartid) ? (2 * hartid) : -1);
} }
@ -161,11 +161,9 @@ static int fu540_ipi_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_ipi_init(FU540_CLINT_ADDR, rc = clint_cold_ipi_init(FU540_CLINT_ADDR, FU540_HART_COUNT);
FU540_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }
return clint_warm_ipi_init(); return clint_warm_ipi_init();
@ -176,8 +174,7 @@ static int fu540_timer_init(bool cold_boot)
int rc; int rc;
if (cold_boot) { if (cold_boot) {
rc = clint_cold_timer_init(FU540_CLINT_ADDR, rc = clint_cold_timer_init(FU540_CLINT_ADDR, FU540_HART_COUNT);
FU540_HART_COUNT);
if (rc) if (rc)
return rc; return rc;
} }

View file

@ -44,8 +44,8 @@ static u32 platform_pmp_region_count(u32 hartid)
* Get PMP regions details (namely: protection, base address, and size) for * Get PMP regions details (namely: protection, base address, and size) for
* a given HART. * a given HART.
*/ */
static int platform_pmp_region_info(u32 hartid, u32 index, static int platform_pmp_region_info(u32 hartid, u32 index, ulong *prot,
ulong *prot, ulong *addr, ulong *log2size) ulong *addr, ulong *log2size)
{ {
return 0; return 0;
} }
@ -56,8 +56,7 @@ static int platform_pmp_region_info(u32 hartid, u32 index,
static int platform_console_init(void) static int platform_console_init(void)
{ {
/* Example if the generic UART8250 driver is used */ /* Example if the generic UART8250 driver is used */
return uart8250_init(PLATFORM_UART_ADDR, return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_SHIFTREG_ADDR,
PLATFORM_UART_SHIFTREG_ADDR,
PLATFORM_UART_BAUDRATE, 0, 1); PLATFORM_UART_BAUDRATE, 0, 1);
} }
@ -239,4 +238,3 @@ const struct sbi_platform platform = {
.system_reboot = platform_system_reboot, .system_reboot = platform_system_reboot,
.system_shutdown = platform_system_shutdown .system_shutdown = platform_system_shutdown
}; };