···11+# CONFIG_CPU_ISOLATION is not set22+CONFIG_LOG_BUF_SHIFT=1633+CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=1244+CONFIG_BLK_DEV_INITRD=y55+# CONFIG_RD_BZIP2 is not set66+# CONFIG_RD_LZMA is not set77+# CONFIG_RD_XZ is not set88+# CONFIG_RD_LZO is not set99+# CONFIG_RD_LZ4 is not set1010+CONFIG_CC_OPTIMIZE_FOR_SIZE=y1111+CONFIG_EXPERT=y1212+# CONFIG_SYSFS_SYSCALL is not set1313+# CONFIG_FHANDLE is not set1414+# CONFIG_BASE_FULL is not set1515+# CONFIG_EPOLL is not set1616+# CONFIG_SIGNALFD is not set1717+# CONFIG_TIMERFD is not set1818+# CONFIG_EVENTFD is not set1919+# CONFIG_AIO is not set2020+# CONFIG_IO_URING is not set2121+# CONFIG_ADVISE_SYSCALLS is not set2222+# CONFIG_MEMBARRIER is not set2323+# CONFIG_KALLSYMS is not set2424+# CONFIG_VM_EVENT_COUNTERS is not set2525+# CONFIG_COMPAT_BRK is not set2626+CONFIG_SLOB=y2727+# CONFIG_SLAB_MERGE_DEFAULT is not set2828+# CONFIG_MMU is not set2929+CONFIG_MAXPHYSMEM_2GB=y3030+CONFIG_SMP=y3131+CONFIG_CMDLINE="root=/dev/vda rw earlycon=uart8250,mmio,0x10000000,115200n8 console=ttyS0"3232+CONFIG_CMDLINE_FORCE=y3333+# CONFIG_BLK_DEV_BSG is not set3434+CONFIG_PARTITION_ADVANCED=y3535+# CONFIG_MSDOS_PARTITION is not set3636+# CONFIG_EFI_PARTITION is not set3737+# CONFIG_MQ_IOSCHED_DEADLINE is not set3838+# CONFIG_MQ_IOSCHED_KYBER is not set3939+CONFIG_BINFMT_FLAT=y4040+# CONFIG_COREDUMP is not set4141+CONFIG_DEVTMPFS=y4242+CONFIG_DEVTMPFS_MOUNT=y4343+# CONFIG_FW_LOADER is not set4444+# CONFIG_ALLOW_DEV_COREDUMP is not set4545+CONFIG_VIRTIO_BLK=y4646+# CONFIG_INPUT_KEYBOARD is not set4747+# CONFIG_INPUT_MOUSE is not set4848+# CONFIG_SERIO is not set4949+# CONFIG_LEGACY_PTYS is not set5050+# CONFIG_LDISC_AUTOLOAD is not set5151+# CONFIG_DEVMEM is not set5252+CONFIG_SERIAL_8250=y5353+# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set5454+CONFIG_SERIAL_8250_CONSOLE=y5555+CONFIG_SERIAL_8250_NR_UARTS=15656+CONFIG_SERIAL_8250_RUNTIME_UARTS=15757+CONFIG_SERIAL_OF_PLATFORM=y5858+# CONFIG_HW_RANDOM is not set5959+# CONFIG_HWMON is not set6060+# CONFIG_LCD_CLASS_DEVICE is not set6161+# CONFIG_BACKLIGHT_CLASS_DEVICE is not set6262+# CONFIG_VGA_CONSOLE is not set6363+# CONFIG_HID is not set6464+# CONFIG_USB_SUPPORT is not set6565+CONFIG_VIRTIO_MMIO=y6666+CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y6767+CONFIG_SIFIVE_PLIC=y6868+# CONFIG_VALIDATE_FS_PARSER is not set6969+CONFIG_EXT2_FS=y7070+# CONFIG_DNOTIFY is not set7171+# CONFIG_INOTIFY_USER is not set7272+# CONFIG_MISC_FILESYSTEMS is not set7373+CONFIG_LSM="[]"7474+CONFIG_PRINTK_TIME=y7575+# CONFIG_SCHED_DEBUG is not set7676+# CONFIG_RCU_TRACE is not set7777+# CONFIG_FTRACE is not set7878+# CONFIG_RUNTIME_TESTING_MENU is not set
+8
arch/riscv/include/asm/cache.h
···11111212#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)13131414+/*1515+ * RISC-V requires the stack pointer to be 16-byte aligned, so ensure that1616+ * the flat loader aligns it accordingly.1717+ */1818+#ifndef CONFIG_MMU1919+#define ARCH_SLAB_MINALIGN 162020+#endif2121+1422#endif /* _ASM_RISCV_CACHE_H */
+39
arch/riscv/include/asm/clint.h
···11+/* SPDX-License-Identifier: GPL-2.0 */22+#ifndef _ASM_RISCV_CLINT_H33+#define _ASM_RISCV_CLINT_H 144+55+#include <linux/io.h>66+#include <linux/smp.h>77+88+#ifdef CONFIG_RISCV_M_MODE99+extern u32 __iomem *clint_ipi_base;1010+1111+void clint_init_boot_cpu(void);1212+1313+static inline void clint_send_ipi_single(unsigned long hartid)1414+{1515+ writel(1, clint_ipi_base + hartid);1616+}1717+1818+static inline void clint_send_ipi_mask(const struct cpumask *hartid_mask)1919+{2020+ int hartid;2121+2222+ for_each_cpu(hartid, hartid_mask)2323+ clint_send_ipi_single(hartid);2424+}2525+2626+static inline void clint_clear_ipi(unsigned long hartid)2727+{2828+ writel(0, clint_ipi_base + hartid);2929+}3030+#else /* CONFIG_RISCV_M_MODE */3131+#define clint_init_boot_cpu() do { } while (0)3232+3333+/* stubs to for code is only reachable under IS_ENABLED(CONFIG_RISCV_M_MODE): */3434+void clint_send_ipi_single(unsigned long hartid);3535+void clint_send_ipi_mask(const struct cpumask *hartid_mask);3636+void clint_clear_ipi(unsigned long hartid);3737+#endif /* CONFIG_RISCV_M_MODE */3838+3939+#endif /* _ASM_RISCV_CLINT_H */
···5656 */5757#define ELF_PLATFORM (NULL)58585959+#ifdef CONFIG_MMU5960#define ARCH_DLINFO \6061do { \6162 NEW_AUX_ENT(AT_SYSINFO_EHDR, \6263 (elf_addr_t)current->mm->context.vdso); \6364} while (0)6464-6565-6665#define ARCH_HAS_SETUP_ADDITIONAL_PAGES6766struct linux_binprm;6867extern int arch_setup_additional_pages(struct linux_binprm *bprm,6968 int uses_interp);6969+#endif /* CONFIG_MMU */70707171#endif /* _ASM_RISCV_ELF_H */
+2
arch/riscv/include/asm/fixmap.h
···1111#include <asm/page.h>1212#include <asm/pgtable.h>13131414+#ifdef CONFIG_MMU1415/*1516 * Here we define all the compile-time 'special' virtual addresses.1617 * The point is to have a constant address at compile time, but to···43424443#include <asm-generic/fixmap.h>45444545+#endif /* CONFIG_MMU */4646#endif /* _ASM_RISCV_FIXMAP_H */
+6
arch/riscv/include/asm/futex.h
···1212#include <linux/errno.h>1313#include <asm/asm.h>14141515+/* We don't even really need the extable code, but for now keep it simple */1616+#ifndef CONFIG_MMU1717+#define __enable_user_access() do { } while (0)1818+#define __disable_user_access() do { } while (0)1919+#endif2020+1521#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \1622{ \1723 uintptr_t tmp; \
+5-144
arch/riscv/include/asm/io.h
···1515#include <asm/mmiowb.h>1616#include <asm/pgtable.h>17171818-extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);1919-2018/*2121- * The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't2222- * change the properties of memory regions. This should be fixed by the2323- * upcoming platform spec.1919+ * MMIO access functions are separated out to break dependency cycles2020+ * when using {read,write}* fns in low-level headers2421 */2525-#define ioremap_nocache(addr, size) ioremap((addr), (size))2626-#define ioremap_wc(addr, size) ioremap((addr), (size))2727-#define ioremap_wt(addr, size) ioremap((addr), (size))2828-2929-extern void iounmap(volatile void __iomem *addr);3030-3131-/* Generic IO read/write. These perform native-endian accesses. */3232-#define __raw_writeb __raw_writeb3333-static inline void __raw_writeb(u8 val, volatile void __iomem *addr)3434-{3535- asm volatile("sb %0, 0(%1)" : : "r" (val), "r" (addr));3636-}3737-3838-#define __raw_writew __raw_writew3939-static inline void __raw_writew(u16 val, volatile void __iomem *addr)4040-{4141- asm volatile("sh %0, 0(%1)" : : "r" (val), "r" (addr));4242-}4343-4444-#define __raw_writel __raw_writel4545-static inline void __raw_writel(u32 val, volatile void __iomem *addr)4646-{4747- asm volatile("sw %0, 0(%1)" : : "r" (val), "r" (addr));4848-}4949-5050-#ifdef CONFIG_64BIT5151-#define __raw_writeq __raw_writeq5252-static inline void __raw_writeq(u64 val, volatile void __iomem *addr)5353-{5454- asm volatile("sd %0, 0(%1)" : : "r" (val), "r" (addr));5555-}5656-#endif5757-5858-#define __raw_readb __raw_readb5959-static inline u8 __raw_readb(const volatile void __iomem *addr)6060-{6161- u8 val;6262-6363- asm volatile("lb %0, 0(%1)" : "=r" (val) : "r" (addr));6464- return val;6565-}6666-6767-#define __raw_readw __raw_readw6868-static inline u16 __raw_readw(const volatile void __iomem *addr)6969-{7070- u16 val;7171-7272- asm volatile("lh %0, 0(%1)" : "=r" (val) : "r" (addr));7373- return val;7474-}7575-7676-#define __raw_readl __raw_readl7777-static inline u32 __raw_readl(const volatile void __iomem *addr)7878-{7979- u32 val;8080-8181- asm volatile("lw %0, 0(%1)" : "=r" (val) : "r" (addr));8282- return val;8383-}8484-8585-#ifdef CONFIG_64BIT8686-#define __raw_readq __raw_readq8787-static inline u64 __raw_readq(const volatile void __iomem *addr)8888-{8989- u64 val;9090-9191- asm volatile("ld %0, 0(%1)" : "=r" (val) : "r" (addr));9292- return val;9393-}9494-#endif9595-9696-/*9797- * Unordered I/O memory access primitives. These are even more relaxed than9898- * the relaxed versions, as they don't even order accesses between successive9999- * operations to the I/O regions.100100- */101101-#define readb_cpu(c) ({ u8 __r = __raw_readb(c); __r; })102102-#define readw_cpu(c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })103103-#define readl_cpu(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })104104-105105-#define writeb_cpu(v,c) ((void)__raw_writeb((v),(c)))106106-#define writew_cpu(v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))107107-#define writel_cpu(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))108108-109109-#ifdef CONFIG_64BIT110110-#define readq_cpu(c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; })111111-#define writeq_cpu(v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))112112-#endif113113-114114-/*115115- * Relaxed I/O memory access primitives. These follow the Device memory116116- * ordering rules but do not guarantee any ordering relative to Normal memory117117- * accesses. These are defined to order the indicated access (either a read or118118- * write) with all other I/O memory accesses. Since the platform specification119119- * defines that all I/O regions are strongly ordered on channel 2, no explicit120120- * fences are required to enforce this ordering.121121- */122122-/* FIXME: These are now the same as asm-generic */123123-#define __io_rbr() do {} while (0)124124-#define __io_rar() do {} while (0)125125-#define __io_rbw() do {} while (0)126126-#define __io_raw() do {} while (0)127127-128128-#define readb_relaxed(c) ({ u8 __v; __io_rbr(); __v = readb_cpu(c); __io_rar(); __v; })129129-#define readw_relaxed(c) ({ u16 __v; __io_rbr(); __v = readw_cpu(c); __io_rar(); __v; })130130-#define readl_relaxed(c) ({ u32 __v; __io_rbr(); __v = readl_cpu(c); __io_rar(); __v; })131131-132132-#define writeb_relaxed(v,c) ({ __io_rbw(); writeb_cpu((v),(c)); __io_raw(); })133133-#define writew_relaxed(v,c) ({ __io_rbw(); writew_cpu((v),(c)); __io_raw(); })134134-#define writel_relaxed(v,c) ({ __io_rbw(); writel_cpu((v),(c)); __io_raw(); })135135-136136-#ifdef CONFIG_64BIT137137-#define readq_relaxed(c) ({ u64 __v; __io_rbr(); __v = readq_cpu(c); __io_rar(); __v; })138138-#define writeq_relaxed(v,c) ({ __io_rbw(); writeq_cpu((v),(c)); __io_raw(); })139139-#endif140140-141141-/*142142- * I/O memory access primitives. Reads are ordered relative to any143143- * following Normal memory access. Writes are ordered relative to any prior144144- * Normal memory access. The memory barriers here are necessary as RISC-V145145- * doesn't define any ordering between the memory space and the I/O space.146146- */147147-#define __io_br() do {} while (0)148148-#define __io_ar(v) __asm__ __volatile__ ("fence i,r" : : : "memory");149149-#define __io_bw() __asm__ __volatile__ ("fence w,o" : : : "memory");150150-#define __io_aw() mmiowb_set_pending()151151-152152-#define readb(c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; })153153-#define readw(c) ({ u16 __v; __io_br(); __v = readw_cpu(c); __io_ar(__v); __v; })154154-#define readl(c) ({ u32 __v; __io_br(); __v = readl_cpu(c); __io_ar(__v); __v; })155155-156156-#define writeb(v,c) ({ __io_bw(); writeb_cpu((v),(c)); __io_aw(); })157157-#define writew(v,c) ({ __io_bw(); writew_cpu((v),(c)); __io_aw(); })158158-#define writel(v,c) ({ __io_bw(); writel_cpu((v),(c)); __io_aw(); })159159-160160-#ifdef CONFIG_64BIT161161-#define readq(c) ({ u64 __v; __io_br(); __v = readq_cpu(c); __io_ar(__v); __v; })162162-#define writeq(v,c) ({ __io_bw(); writeq_cpu((v),(c)); __io_aw(); })163163-#endif2222+#include <asm/mmio.h>1642316524/*16625 * I/O port access constants.16726 */2727+#ifdef CONFIG_MMU16828#define IO_SPACE_LIMIT (PCI_IO_SIZE - 1)16929#define PCI_IOBASE ((void __iomem *)PCI_IO_START)3030+#endif /* CONFIG_MMU */1703117132/*17233 * Emulation routines for the port-mapped IO space used by some PCI drivers.
+6-6
arch/riscv/include/asm/irqflags.h
···1313/* read interrupt enabled status */1414static inline unsigned long arch_local_save_flags(void)1515{1616- return csr_read(CSR_SSTATUS);1616+ return csr_read(CSR_STATUS);1717}18181919/* unconditionally enable interrupts */2020static inline void arch_local_irq_enable(void)2121{2222- csr_set(CSR_SSTATUS, SR_SIE);2222+ csr_set(CSR_STATUS, SR_IE);2323}24242525/* unconditionally disable interrupts */2626static inline void arch_local_irq_disable(void)2727{2828- csr_clear(CSR_SSTATUS, SR_SIE);2828+ csr_clear(CSR_STATUS, SR_IE);2929}30303131/* get status and disable interrupts */3232static inline unsigned long arch_local_irq_save(void)3333{3434- return csr_read_clear(CSR_SSTATUS, SR_SIE);3434+ return csr_read_clear(CSR_STATUS, SR_IE);3535}36363737/* test flags */3838static inline int arch_irqs_disabled_flags(unsigned long flags)3939{4040- return !(flags & SR_SIE);4040+ return !(flags & SR_IE);4141}42424343/* test hardware interrupt enable bit */···4949/* set interrupt enabled status */5050static inline void arch_local_irq_restore(unsigned long flags)5151{5252- csr_set(CSR_SSTATUS, flags & SR_SIE);5252+ csr_set(CSR_STATUS, flags & SR_IE);5353}54545555#endif /* _ASM_RISCV_IRQFLAGS_H */
+168
arch/riscv/include/asm/mmio.h
···11+/* SPDX-License-Identifier: GPL-2.0-only */22+/*33+ * {read,write}{b,w,l,q} based on arch/arm64/include/asm/io.h44+ * which was based on arch/arm/include/io.h55+ *66+ * Copyright (C) 1996-2000 Russell King77+ * Copyright (C) 2012 ARM Ltd.88+ * Copyright (C) 2014 Regents of the University of California99+ */1010+1111+#ifndef _ASM_RISCV_MMIO_H1212+#define _ASM_RISCV_MMIO_H1313+1414+#include <linux/types.h>1515+#include <asm/mmiowb.h>1616+1717+#ifdef CONFIG_MMU1818+void __iomem *ioremap(phys_addr_t offset, unsigned long size);1919+2020+/*2121+ * The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't2222+ * change the properties of memory regions. This should be fixed by the2323+ * upcoming platform spec.2424+ */2525+#define ioremap_nocache(addr, size) ioremap((addr), (size))2626+#define ioremap_wc(addr, size) ioremap((addr), (size))2727+#define ioremap_wt(addr, size) ioremap((addr), (size))2828+2929+void iounmap(volatile void __iomem *addr);3030+#else3131+#define pgprot_noncached(x) (x)3232+#endif /* CONFIG_MMU */3333+3434+/* Generic IO read/write. These perform native-endian accesses. */3535+#define __raw_writeb __raw_writeb3636+static inline void __raw_writeb(u8 val, volatile void __iomem *addr)3737+{3838+ asm volatile("sb %0, 0(%1)" : : "r" (val), "r" (addr));3939+}4040+4141+#define __raw_writew __raw_writew4242+static inline void __raw_writew(u16 val, volatile void __iomem *addr)4343+{4444+ asm volatile("sh %0, 0(%1)" : : "r" (val), "r" (addr));4545+}4646+4747+#define __raw_writel __raw_writel4848+static inline void __raw_writel(u32 val, volatile void __iomem *addr)4949+{5050+ asm volatile("sw %0, 0(%1)" : : "r" (val), "r" (addr));5151+}5252+5353+#ifdef CONFIG_64BIT5454+#define __raw_writeq __raw_writeq5555+static inline void __raw_writeq(u64 val, volatile void __iomem *addr)5656+{5757+ asm volatile("sd %0, 0(%1)" : : "r" (val), "r" (addr));5858+}5959+#endif6060+6161+#define __raw_readb __raw_readb6262+static inline u8 __raw_readb(const volatile void __iomem *addr)6363+{6464+ u8 val;6565+6666+ asm volatile("lb %0, 0(%1)" : "=r" (val) : "r" (addr));6767+ return val;6868+}6969+7070+#define __raw_readw __raw_readw7171+static inline u16 __raw_readw(const volatile void __iomem *addr)7272+{7373+ u16 val;7474+7575+ asm volatile("lh %0, 0(%1)" : "=r" (val) : "r" (addr));7676+ return val;7777+}7878+7979+#define __raw_readl __raw_readl8080+static inline u32 __raw_readl(const volatile void __iomem *addr)8181+{8282+ u32 val;8383+8484+ asm volatile("lw %0, 0(%1)" : "=r" (val) : "r" (addr));8585+ return val;8686+}8787+8888+#ifdef CONFIG_64BIT8989+#define __raw_readq __raw_readq9090+static inline u64 __raw_readq(const volatile void __iomem *addr)9191+{9292+ u64 val;9393+9494+ asm volatile("ld %0, 0(%1)" : "=r" (val) : "r" (addr));9595+ return val;9696+}9797+#endif9898+9999+/*100100+ * Unordered I/O memory access primitives. These are even more relaxed than101101+ * the relaxed versions, as they don't even order accesses between successive102102+ * operations to the I/O regions.103103+ */104104+#define readb_cpu(c) ({ u8 __r = __raw_readb(c); __r; })105105+#define readw_cpu(c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })106106+#define readl_cpu(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })107107+108108+#define writeb_cpu(v, c) ((void)__raw_writeb((v), (c)))109109+#define writew_cpu(v, c) ((void)__raw_writew((__force u16)cpu_to_le16(v), (c)))110110+#define writel_cpu(v, c) ((void)__raw_writel((__force u32)cpu_to_le32(v), (c)))111111+112112+#ifdef CONFIG_64BIT113113+#define readq_cpu(c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; })114114+#define writeq_cpu(v, c) ((void)__raw_writeq((__force u64)cpu_to_le64(v), (c)))115115+#endif116116+117117+/*118118+ * Relaxed I/O memory access primitives. These follow the Device memory119119+ * ordering rules but do not guarantee any ordering relative to Normal memory120120+ * accesses. These are defined to order the indicated access (either a read or121121+ * write) with all other I/O memory accesses. Since the platform specification122122+ * defines that all I/O regions are strongly ordered on channel 2, no explicit123123+ * fences are required to enforce this ordering.124124+ */125125+/* FIXME: These are now the same as asm-generic */126126+#define __io_rbr() do {} while (0)127127+#define __io_rar() do {} while (0)128128+#define __io_rbw() do {} while (0)129129+#define __io_raw() do {} while (0)130130+131131+#define readb_relaxed(c) ({ u8 __v; __io_rbr(); __v = readb_cpu(c); __io_rar(); __v; })132132+#define readw_relaxed(c) ({ u16 __v; __io_rbr(); __v = readw_cpu(c); __io_rar(); __v; })133133+#define readl_relaxed(c) ({ u32 __v; __io_rbr(); __v = readl_cpu(c); __io_rar(); __v; })134134+135135+#define writeb_relaxed(v, c) ({ __io_rbw(); writeb_cpu((v), (c)); __io_raw(); })136136+#define writew_relaxed(v, c) ({ __io_rbw(); writew_cpu((v), (c)); __io_raw(); })137137+#define writel_relaxed(v, c) ({ __io_rbw(); writel_cpu((v), (c)); __io_raw(); })138138+139139+#ifdef CONFIG_64BIT140140+#define readq_relaxed(c) ({ u64 __v; __io_rbr(); __v = readq_cpu(c); __io_rar(); __v; })141141+#define writeq_relaxed(v, c) ({ __io_rbw(); writeq_cpu((v), (c)); __io_raw(); })142142+#endif143143+144144+/*145145+ * I/O memory access primitives. Reads are ordered relative to any146146+ * following Normal memory access. Writes are ordered relative to any prior147147+ * Normal memory access. The memory barriers here are necessary as RISC-V148148+ * doesn't define any ordering between the memory space and the I/O space.149149+ */150150+#define __io_br() do {} while (0)151151+#define __io_ar(v) __asm__ __volatile__ ("fence i,r" : : : "memory")152152+#define __io_bw() __asm__ __volatile__ ("fence w,o" : : : "memory")153153+#define __io_aw() mmiowb_set_pending()154154+155155+#define readb(c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; })156156+#define readw(c) ({ u16 __v; __io_br(); __v = readw_cpu(c); __io_ar(__v); __v; })157157+#define readl(c) ({ u32 __v; __io_br(); __v = readl_cpu(c); __io_ar(__v); __v; })158158+159159+#define writeb(v, c) ({ __io_bw(); writeb_cpu((v), (c)); __io_aw(); })160160+#define writew(v, c) ({ __io_bw(); writew_cpu((v), (c)); __io_aw(); })161161+#define writel(v, c) ({ __io_bw(); writel_cpu((v), (c)); __io_aw(); })162162+163163+#ifdef CONFIG_64BIT164164+#define readq(c) ({ u64 __v; __io_br(); __v = readq_cpu(c); __io_ar(__v); __v; })165165+#define writeq(v, c) ({ __io_bw(); writeq_cpu((v), (c)); __io_aw(); })166166+#endif167167+168168+#endif /* _ASM_RISCV_MMIO_H */
+3
arch/riscv/include/asm/mmu.h
···1010#ifndef __ASSEMBLY__11111212typedef struct {1313+#ifndef CONFIG_MMU1414+ unsigned long end_brk;1515+#endif1316 void *vdso;1417#ifdef CONFIG_SMP1518 /* A local icache flush is needed before user execution can resume. */
···1212#ifndef __ASSEMBLY__13131414struct pt_regs {1515- unsigned long sepc;1515+ unsigned long epc;1616 unsigned long ra;1717 unsigned long sp;1818 unsigned long gp;···4444 unsigned long t4;4545 unsigned long t5;4646 unsigned long t6;4747- /* Supervisor CSRs */4848- unsigned long sstatus;4949- unsigned long sbadaddr;5050- unsigned long scause;4747+ /* Supervisor/Machine CSRs */4848+ unsigned long status;4949+ unsigned long badaddr;5050+ unsigned long cause;5151 /* a0 value before the syscall */5252 unsigned long orig_a0;5353};···5858#define REG_FMT "%08lx"5959#endif60606161-#define user_mode(regs) (((regs)->sstatus & SR_SPP) == 0)6161+#define user_mode(regs) (((regs)->status & SR_PP) == 0)626263636464/* Helpers for working with the instruction pointer */6565static inline unsigned long instruction_pointer(struct pt_regs *regs)6666{6767- return regs->sepc;6767+ return regs->epc;6868}6969static inline void instruction_pointer_set(struct pt_regs *regs,7070 unsigned long val)7171{7272- regs->sepc = val;7272+ regs->epc = val;7373}74747575#define profile_pc(regs) instruction_pointer(regs)
+8-1
arch/riscv/include/asm/sbi.h
···8899#include <linux/types.h>10101111+#ifdef CONFIG_RISCV_SBI1112#define SBI_SET_TIMER 01213#define SBI_CONSOLE_PUTCHAR 11314#define SBI_CONSOLE_GETCHAR 2···9493{9594 SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid);9695}9797-9696+#else /* CONFIG_RISCV_SBI */9797+/* stubs for code that is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */9898+void sbi_set_timer(uint64_t stime_value);9999+void sbi_clear_ipi(void);100100+void sbi_send_ipi(const unsigned long *hart_mask);101101+void sbi_remote_fence_i(const unsigned long *hart_mask);102102+#endif /* CONFIG_RISCV_SBI */98103#endif /* _ASM_RISCV_SBI_H */
···11+// SPDX-License-Identifier: GPL-2.022+/*33+ * Copyright (c) 2019 Christoph Hellwig.44+ */55+66+#include <linux/io.h>77+#include <linux/of_address.h>88+#include <linux/types.h>99+#include <asm/clint.h>1010+#include <asm/csr.h>1111+#include <asm/timex.h>1212+#include <asm/smp.h>1313+1414+/*1515+ * This is the layout used by the SiFive clint, which is also shared by the qemu1616+ * virt platform, and the Kendryte KD210 at least.1717+ */1818+#define CLINT_IPI_OFF 01919+#define CLINT_TIME_CMP_OFF 0x40002020+#define CLINT_TIME_VAL_OFF 0xbff82121+2222+u32 __iomem *clint_ipi_base;2323+2424+void clint_init_boot_cpu(void)2525+{2626+ struct device_node *np;2727+ void __iomem *base;2828+2929+ np = of_find_compatible_node(NULL, NULL, "riscv,clint0");3030+ if (!np) {3131+ panic("clint not found");3232+ return;3333+ }3434+3535+ base = of_iomap(np, 0);3636+ if (!base)3737+ panic("could not map CLINT");3838+3939+ clint_ipi_base = base + CLINT_IPI_OFF;4040+ riscv_time_cmp = base + CLINT_TIME_CMP_OFF;4141+ riscv_time_val = base + CLINT_TIME_VAL_OFF;4242+4343+ clint_clear_ipi(boot_cpu_hartid);4444+}
+54-31
arch/riscv/kernel/entry.S
···26262727 /*2828 * If coming from userspace, preserve the user thread pointer and load2929- * the kernel thread pointer. If we came from the kernel, sscratch3030- * will contain 0, and we should continue on the current TP.2929+ * the kernel thread pointer. If we came from the kernel, the scratch3030+ * register will contain 0, and we should continue on the current TP.3131 */3232- csrrw tp, CSR_SSCRATCH, tp3232+ csrrw tp, CSR_SCRATCH, tp3333 bnez tp, _save_context34343535_restore_kernel_tpsp:3636- csrr tp, CSR_SSCRATCH3636+ csrr tp, CSR_SCRATCH3737 REG_S sp, TASK_TI_KERNEL_SP(tp)3838_save_context:3939 REG_S sp, TASK_TI_USER_SP(tp)···7979 li t0, SR_SUM | SR_FS80808181 REG_L s0, TASK_TI_USER_SP(tp)8282- csrrc s1, CSR_SSTATUS, t08383- csrr s2, CSR_SEPC8484- csrr s3, CSR_STVAL8585- csrr s4, CSR_SCAUSE8686- csrr s5, CSR_SSCRATCH8282+ csrrc s1, CSR_STATUS, t08383+ csrr s2, CSR_EPC8484+ csrr s3, CSR_TVAL8585+ csrr s4, CSR_CAUSE8686+ csrr s5, CSR_SCRATCH8787 REG_S s0, PT_SP(sp)8888- REG_S s1, PT_SSTATUS(sp)8989- REG_S s2, PT_SEPC(sp)9090- REG_S s3, PT_SBADADDR(sp)9191- REG_S s4, PT_SCAUSE(sp)8888+ REG_S s1, PT_STATUS(sp)8989+ REG_S s2, PT_EPC(sp)9090+ REG_S s3, PT_BADADDR(sp)9191+ REG_S s4, PT_CAUSE(sp)9292 REG_S s5, PT_TP(sp)9393 .endm9494···9797 * registers from the stack.9898 */9999 .macro RESTORE_ALL100100- REG_L a0, PT_SSTATUS(sp)100100+ REG_L a0, PT_STATUS(sp)101101 /*102102 * The current load reservation is effectively part of the processor's103103 * state, in the sense that load reservations cannot be shared between···115115 * completes, implementations are allowed to expand reservations to be116116 * arbitrarily large.117117 */118118- REG_L a2, PT_SEPC(sp)119119- REG_SC x0, a2, PT_SEPC(sp)118118+ REG_L a2, PT_EPC(sp)119119+ REG_SC x0, a2, PT_EPC(sp)120120121121- csrw CSR_SSTATUS, a0122122- csrw CSR_SEPC, a2121121+ csrw CSR_STATUS, a0122122+ csrw CSR_EPC, a2123123124124 REG_L x1, PT_RA(sp)125125 REG_L x3, PT_GP(sp)···163163 SAVE_ALL164164165165 /*166166- * Set sscratch register to 0, so that if a recursive exception166166+ * Set the scratch register to 0, so that if a recursive exception167167 * occurs, the exception vector knows it came from the kernel168168 */169169- csrw CSR_SSCRATCH, x0169169+ csrw CSR_SCRATCH, x0170170171171 /* Load the global pointer */172172.option push···185185 move a0, sp /* pt_regs */186186 tail do_IRQ1871871:188188- /* Exceptions run with interrupts enabled or disabled189189- depending on the state of sstatus.SR_SPIE */190190- andi t0, s1, SR_SPIE188188+ /*189189+ * Exceptions run with interrupts enabled or disabled depending on the190190+ * state of SR_PIE in m/sstatus.191191+ */192192+ andi t0, s1, SR_PIE191193 beqz t0, 1f192192- csrs CSR_SSTATUS, SR_SIE194194+ csrs CSR_STATUS, SR_IE1931951941961:195197 /* Handle syscalls */···219217 * scall instruction on sret220218 */221219 addi s2, s2, 0x4222222- REG_S s2, PT_SEPC(sp)220220+ REG_S s2, PT_EPC(sp)223221 /* Trace syscalls, but only if requested by the user. */224222 REG_L t0, TASK_TI_FLAGS(tp)225223 andi t0, t0, _TIF_SYSCALL_WORK···269267 bnez t0, handle_syscall_trace_exit270268271269ret_from_exception:272272- REG_L s0, PT_SSTATUS(sp)273273- csrc CSR_SSTATUS, SR_SIE270270+ REG_L s0, PT_STATUS(sp)271271+ csrc CSR_STATUS, SR_IE272272+#ifdef CONFIG_RISCV_M_MODE273273+ /* the MPP value is too large to be used as an immediate arg for addi */274274+ li t0, SR_MPP275275+ and s0, s0, t0276276+#else274277 andi s0, s0, SR_SPP278278+#endif275279 bnez s0, resume_kernel276280277281resume_userspace:···291283 REG_S s0, TASK_TI_KERNEL_SP(tp)292284293285 /*294294- * Save TP into sscratch, so we can find the kernel data structures295295- * again.286286+ * Save TP into the scratch register , so we can find the kernel data287287+ * structures again.296288 */297297- csrw CSR_SSCRATCH, tp289289+ csrw CSR_SCRATCH, tp298290299291restore_all:300292 RESTORE_ALL293293+#ifdef CONFIG_RISCV_M_MODE294294+ mret295295+#else301296 sret297297+#endif302298303299#if IS_ENABLED(CONFIG_PREEMPT)304300resume_kernel:···322310 bnez s1, work_resched323311work_notifysig:324312 /* Handle pending signals and notify-resume requests */325325- csrs CSR_SSTATUS, SR_SIE /* Enable interrupts for do_notify_resume() */313313+ csrs CSR_STATUS, SR_IE /* Enable interrupts for do_notify_resume() */326314 move a0, sp /* pt_regs */327315 move a1, s0 /* current_thread_info->flags */328316 tail do_notify_resume···421409 ret422410ENDPROC(__switch_to)423411412412+#ifndef CONFIG_MMU413413+#define do_page_fault do_trap_unknown414414+#endif415415+424416 .section ".rodata"425417 /* Exception vector table */426418ENTRY(excp_vect_table)···446430 RISCV_PTR do_page_fault /* store page fault */447431excp_vect_table_end:448432END(excp_vect_table)433433+434434+#ifndef CONFIG_MMU435435+ENTRY(__user_rt_sigreturn)436436+ li a7, __NR_rt_sigreturn437437+ scall438438+END(__user_rt_sigreturn)439439+#endif
···1111#include <asm/thread_info.h>1212#include <asm/page.h>1313#include <asm/csr.h>1414+#include <asm/hwcap.h>1415#include <asm/image.h>15161617__INIT···4847.global _start_kernel4948_start_kernel:5049 /* Mask all interrupts */5151- csrw CSR_SIE, zero5252- csrw CSR_SIP, zero5050+ csrw CSR_IE, zero5151+ csrw CSR_IP, zero5252+5353+#ifdef CONFIG_RISCV_M_MODE5454+ /* flush the instruction cache */5555+ fence.i5656+5757+ /* Reset all registers except ra, a0, a1 */5858+ call reset_regs5959+6060+ /*6161+ * The hartid in a0 is expected later on, and we have no firmware6262+ * to hand it to us.6363+ */6464+ csrr a0, CSR_MHARTID6565+#endif /* CONFIG_RISCV_M_MODE */53665467 /* Load the global pointer */5568.option push···7661 * floating point in kernel space7762 */7863 li t0, SR_FS7979- csrc CSR_SSTATUS, t06464+ csrc CSR_STATUS, t080658166#ifdef CONFIG_SMP8267 li t0, CONFIG_NR_CPUS···10994 la sp, init_thread_union + THREAD_SIZE11095 mv a0, s111196 call setup_vm9797+#ifdef CONFIG_MMU11298 la a0, early_pg_dir11399 call relocate100100+#endif /* CONFIG_MMU */114101115102 /* Restore C environment */116103 la tp, init_task···123106 call parse_dtb124107 tail start_kernel125108109109+#ifdef CONFIG_MMU126110relocate:127111 /* Relocate return address */128112 li a1, PAGE_OFFSET···134116 /* Point stvec to virtual address of intruction after satp write */135117 la a2, 1f136118 add a2, a2, a1137137- csrw CSR_STVEC, a2119119+ csrw CSR_TVEC, a2138120139121 /* Compute satp for kernel page tables, but don't load it yet */140122 srl a2, a0, PAGE_SHIFT···1561381:157139 /* Set trap vector to spin forever to help debug */158140 la a0, .Lsecondary_park159159- csrw CSR_STVEC, a0141141+ csrw CSR_TVEC, a0160142161143 /* Reload the global pointer */162144.option push···174156 sfence.vma175157176158 ret159159+#endif /* CONFIG_MMU */177160178161.Lsecondary_start:179162#ifdef CONFIG_SMP180163 /* Set trap vector to spin forever to help debug */181164 la a3, .Lsecondary_park182182- csrw CSR_STVEC, a3165165+ csrw CSR_TVEC, a3183166184167 slli a3, a0, LGREG185168 la a1, __cpu_up_stack_pointer···200181 beqz tp, .Lwait_for_cpu_up201182 fence202183184184+#ifdef CONFIG_MMU203185 /* Enable virtual memory and relocate to virtual address */204186 la a0, swapper_pg_dir205187 call relocate188188+#endif206189207190 tail smp_callin208191#endif···215194 wfi216195 j .Lsecondary_park217196END(_start)197197+198198+#ifdef CONFIG_RISCV_M_MODE199199+ENTRY(reset_regs)200200+ li sp, 0201201+ li gp, 0202202+ li tp, 0203203+ li t0, 0204204+ li t1, 0205205+ li t2, 0206206+ li s0, 0207207+ li s1, 0208208+ li a2, 0209209+ li a3, 0210210+ li a4, 0211211+ li a5, 0212212+ li a6, 0213213+ li a7, 0214214+ li s2, 0215215+ li s3, 0216216+ li s4, 0217217+ li s5, 0218218+ li s6, 0219219+ li s7, 0220220+ li s8, 0221221+ li s9, 0222222+ li s10, 0223223+ li s11, 0224224+ li t3, 0225225+ li t4, 0226226+ li t5, 0227227+ li t6, 0228228+ csrw sscratch, 0229229+230230+#ifdef CONFIG_FPU231231+ csrr t0, CSR_MISA232232+ andi t0, t0, (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D)233233+ bnez t0, .Lreset_regs_done234234+235235+ li t1, SR_FS236236+ csrs CSR_STATUS, t1237237+ fmv.s.x f0, zero238238+ fmv.s.x f1, zero239239+ fmv.s.x f2, zero240240+ fmv.s.x f3, zero241241+ fmv.s.x f4, zero242242+ fmv.s.x f5, zero243243+ fmv.s.x f6, zero244244+ fmv.s.x f7, zero245245+ fmv.s.x f8, zero246246+ fmv.s.x f9, zero247247+ fmv.s.x f10, zero248248+ fmv.s.x f11, zero249249+ fmv.s.x f12, zero250250+ fmv.s.x f13, zero251251+ fmv.s.x f14, zero252252+ fmv.s.x f15, zero253253+ fmv.s.x f16, zero254254+ fmv.s.x f17, zero255255+ fmv.s.x f18, zero256256+ fmv.s.x f19, zero257257+ fmv.s.x f20, zero258258+ fmv.s.x f21, zero259259+ fmv.s.x f22, zero260260+ fmv.s.x f23, zero261261+ fmv.s.x f24, zero262262+ fmv.s.x f25, zero263263+ fmv.s.x f26, zero264264+ fmv.s.x f27, zero265265+ fmv.s.x f28, zero266266+ fmv.s.x f29, zero267267+ fmv.s.x f30, zero268268+ fmv.s.x f31, zero269269+ csrw fcsr, 0270270+ /* note that the caller must clear SR_FS */271271+#endif /* CONFIG_FPU */272272+.Lreset_regs_done:273273+ ret274274+END(reset_regs)275275+#endif /* CONFIG_RISCV_M_MODE */218276219277__PAGE_ALIGNED_BSS220278 /* Empty zero page */
+5-12
arch/riscv/kernel/irq.c
···1111#include <linux/seq_file.h>1212#include <asm/smp.h>13131414-/*1515- * Possible interrupt causes:1616- */1717-#define INTERRUPT_CAUSE_SOFTWARE IRQ_S_SOFT1818-#define INTERRUPT_CAUSE_TIMER IRQ_S_TIMER1919-#define INTERRUPT_CAUSE_EXTERNAL IRQ_S_EXT2020-2114int arch_show_interrupts(struct seq_file *p, int prec)2215{2316 show_ipi_stats(p, prec);···2229 struct pt_regs *old_regs = set_irq_regs(regs);23302431 irq_enter();2525- switch (regs->scause & ~SCAUSE_IRQ_FLAG) {2626- case INTERRUPT_CAUSE_TIMER:3232+ switch (regs->cause & ~CAUSE_IRQ_FLAG) {3333+ case IRQ_TIMER:2734 riscv_timer_interrupt();2835 break;2936#ifdef CONFIG_SMP3030- case INTERRUPT_CAUSE_SOFTWARE:3737+ case IRQ_SOFT:3138 /*3239 * We only use software interrupts to pass IPIs, so if a non-SMP3340 * system gets one, then we don't know what to do.···3542 riscv_software_interrupt();3643 break;3744#endif3838- case INTERRUPT_CAUSE_EXTERNAL:4545+ case IRQ_EXT:3946 handle_arch_irq(regs);4047 break;4148 default:4242- pr_alert("unexpected interrupt cause 0x%lx", regs->scause);4949+ pr_alert("unexpected interrupt cause 0x%lx", regs->cause);4350 BUG();4451 }4552 irq_exit();
···3434 int code = SEGV_MAPERR;3535 vm_fault_t fault;36363737- cause = regs->scause;3838- addr = regs->sbadaddr;3737+ cause = regs->cause;3838+ addr = regs->badaddr;39394040 tsk = current;4141 mm = tsk->mm;···5353 goto vmalloc_fault;54545555 /* Enable interrupts if they were enabled in the parent context. */5656- if (likely(regs->sstatus & SR_SPIE))5656+ if (likely(regs->status & SR_PIE))5757 local_irq_enable();58585959 /*
···33 * Copyright (C) 2012 Regents of the University of California44 * Copyright (C) 2017 SiFive55 *66- * All RISC-V systems have a timer attached to every hart. These timers can be77- * read from the "time" and "timeh" CSRs, and can use the SBI to setup88- * events.66+ * All RISC-V systems have a timer attached to every hart. These timers can77+ * either be read from the "time" and "timeh" CSRs, and can use the SBI to88+ * setup events, or directly accessed using MMIO registers.99 */1010#include <linux/clocksource.h>1111#include <linux/clockchips.h>···1313#include <linux/delay.h>1414#include <linux/irq.h>1515#include <linux/sched_clock.h>1616+#include <linux/io-64-nonatomic-lo-hi.h>1617#include <asm/smp.h>1718#include <asm/sbi.h>1919+2020+u64 __iomem *riscv_time_cmp;2121+u64 __iomem *riscv_time_val;2222+2323+static inline void mmio_set_timer(u64 val)2424+{2525+ void __iomem *r;2626+2727+ r = riscv_time_cmp + cpuid_to_hartid_map(smp_processor_id());2828+ writeq_relaxed(val, r);2929+}18301931static int riscv_clock_next_event(unsigned long delta,2032 struct clock_event_device *ce)2133{2222- csr_set(sie, SIE_STIE);2323- sbi_set_timer(get_cycles64() + delta);3434+ csr_set(CSR_IE, IE_TIE);3535+ if (IS_ENABLED(CONFIG_RISCV_SBI))3636+ sbi_set_timer(get_cycles64() + delta);3737+ else3838+ mmio_set_timer(get_cycles64() + delta);2439 return 0;2540}2641···7661 ce->cpumask = cpumask_of(cpu);7762 clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff);78637979- csr_set(sie, SIE_STIE);6464+ csr_set(CSR_IE, IE_TIE);8065 return 0;8166}82678368static int riscv_timer_dying_cpu(unsigned int cpu)8469{8585- csr_clear(sie, SIE_STIE);7070+ csr_clear(CSR_IE, IE_TIE);8671 return 0;8772}8873···9176{9277 struct clock_event_device *evdev = this_cpu_ptr(&riscv_clock_event);93789494- csr_clear(sie, SIE_STIE);7979+ csr_clear(CSR_IE, IE_TIE);9580 evdev->event_handler(evdev);9681}9782
+7-4
drivers/irqchip/irq-sifive-plic.c
···181181182182 WARN_ON_ONCE(!handler->present);183183184184- csr_clear(sie, SIE_SEIE);184184+ csr_clear(CSR_IE, IE_EIE);185185 while ((hwirq = readl(claim))) {186186 int irq = irq_find_mapping(plic_irqdomain, hwirq);187187···191191 else192192 generic_handle_irq(irq);193193 }194194- csr_set(sie, SIE_SEIE);194194+ csr_set(CSR_IE, IE_EIE);195195}196196197197/*···252252 continue;253253 }254254255255- /* skip contexts other than supervisor external interrupt */256256- if (parent.args[0] != IRQ_S_EXT)255255+ /*256256+ * Skip contexts other than external interrupts for our257257+ * privilege level.258258+ */259259+ if (parent.args[0] != IRQ_EXT)257260 continue;258261259262 hartid = plic_find_hart_id(parent.np);
+1-1
drivers/tty/hvc/Kconfig
···89899090config HVC_RISCV_SBI9191 bool "RISC-V SBI console support"9292- depends on RISCV9292+ depends on RISCV_SBI9393 select HVC_DRIVER9494 help9595 This enables support for console output via RISC-V SBI calls, which
+1-1
drivers/tty/serial/Kconfig
···88888989config SERIAL_EARLYCON_RISCV_SBI9090 bool "Early console using RISC-V SBI"9191- depends on RISCV9191+ depends on RISCV_SBI9292 select SERIAL_CORE9393 select SERIAL_CORE_CONSOLE9494 select SERIAL_EARLYCON