Skip to contentSkip to conversation

RISC-V Linux Port v1

PATCH In review Palmer Dabbelt 22 participants 213 messages May 23, 2017 – Jul 5, 2017 1 message not in the archive Page 1 of 2

Subsystems (21)
lore
Share & tools
lore

Palmer Dabbelt

author maintainer
#0 lore raw

We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.

This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.

These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.

Albert and I will volunteer to maintain this port if it's OK with everyone.

We'd like to thank the various members of the RISC-V software community who have helped us with the port.

Thanks!

In addition to the threaded messages, our port can be found on Git Hib

https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

author maintainer
#8 lore raw

PATCH 2/7 RISC-V: arch/riscv Makefile and Kconfigs

---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
arch/riscv/.gitignore new file +35 -0
new file mode 100644
index 000000000000..376d06eb5d52
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a
+*.s
+*.ko
+*.so
+*.so.dbg
+*.mod.c
+*.i
+*.lst
+*.symtypes
+*.order
+modules.builtin
+*.elf
+*.bin
+*.gz
+*.bz2
+*.lzma
+*.xz
+*.lzo
+*.patch
+*.gcno
+
+include/generated
+kernel/vmlinux.lds
+
+# Then reinclude .gitignore.
+!.gitignore
arch/riscv/Kconfig new file +300 -0

300 lines not on this page · raw message

arch/riscv/Makefile new file +64 -0

64 lines not on this page · raw message

arch/riscv/configs/riscv32_spike new file +47 -0

47 lines not on this page · raw message

arch/riscv/configs/riscv64_freedom-u new file +52 -0

52 lines not on this page · raw message

arch/riscv/configs/riscv64_qemu new file +64 -0

64 lines not on this page · raw message

arch/riscv/configs/riscv64_spike new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#28 lore raw

PATCH 4/7 RISC-V: arch/riscv/include

In reply to Palmer Dabbelt
---
 arch/riscv/include/asm/Kbuild             |  60 ++++
 arch/riscv/include/asm/asm-offsets.h      |   1 +
 arch/riscv/include/asm/asm.h              |  65 +++++
 arch/riscv/include/asm/atomic.h           | 349 +++++++++++++++++++++++
 arch/riscv/include/asm/atomic64.h         | 355 +++++++++++++++++++++++
 arch/riscv/include/asm/barrier.h          |  33 +++
 arch/riscv/include/asm/bitops.h           | 229 +++++++++++++++
 arch/riscv/include/asm/bug.h              |  81 ++++++
 arch/riscv/include/asm/cache.h            |  23 ++
 arch/riscv/include/asm/cacheflush.h       |  40 +++
 arch/riscv/include/asm/cmpxchg.h          | 125 ++++++++
 arch/riscv/include/asm/csr.h              | 126 +++++++++
 arch/riscv/include/asm/delay.h            |  29 ++
 arch/riscv/include/asm/device.h           |  28 ++
 arch/riscv/include/asm/dma-mapping.h      |  61 ++++
 arch/riscv/include/asm/elf.h              |  83 ++++++
 arch/riscv/include/asm/io.h               |  36 +++
 arch/riscv/include/asm/irq.h              |  32 +++
 arch/riscv/include/asm/irqflags.h         |  64 +++++
 arch/riscv/include/asm/kprobes.h          |  23 ++
 arch/riscv/include/asm/linkage.h          |  21 ++
 arch/riscv/include/asm/mmu.h              |  27 ++
 arch/riscv/include/asm/mmu_context.h      |  70 +++++
 arch/riscv/include/asm/page.h             | 138 +++++++++
 arch/riscv/include/asm/pci.h              |  51 ++++
 arch/riscv/include/asm/pgalloc.h          | 126 +++++++++
 arch/riscv/include/asm/pgtable-32.h       |  26 ++
 arch/riscv/include/asm/pgtable-64.h       |  85 ++++++
 arch/riscv/include/asm/pgtable-bits.h     |  49 ++++
 arch/riscv/include/asm/pgtable.h          | 426 ++++++++++++++++++++++++++++
 arch/riscv/include/asm/processor.h        | 103 +++++++
 arch/riscv/include/asm/ptrace.h           | 117 ++++++++
 arch/riscv/include/asm/sbi.h              | 101 +++++++
 arch/riscv/include/asm/serial.h           |  43 +++
 arch/riscv/include/asm/setup.h            |  20 ++
 arch/riscv/include/asm/smp.h              |  42 +++
 arch/riscv/include/asm/spinlock.h         | 156 ++++++++++
 arch/riscv/include/asm/spinlock_types.h   |  34 +++
 arch/riscv/include/asm/string.h           |  31 ++
 arch/riscv/include/asm/switch_to.h        |  71 +++++
 arch/riscv/include/asm/syscall.h          |  91 ++++++
 arch/riscv/include/asm/syscalls.h         |  26 ++
 arch/riscv/include/asm/thread_info.h      | 103 +++++++
 arch/riscv/include/asm/timex.h            |  55 ++++
 arch/riscv/include/asm/tlb.h              |  25 ++
 arch/riscv/include/asm/tlbflush.h         |  95 +++++++
 arch/riscv/include/asm/uaccess.h          | 455 ++++++++++++++++++++++++++++++
 arch/riscv/include/asm/unistd.h           |  17 ++
 arch/riscv/include/asm/vdso.h             |  32 +++
 arch/riscv/include/asm/word-at-a-time.h   |  56 ++++
 arch/riscv/include/uapi/asm/Kbuild        |  10 +
 arch/riscv/include/uapi/asm/auxvec.h      |  24 ++
 arch/riscv/include/uapi/asm/bitsperlong.h |  25 ++
 arch/riscv/include/uapi/asm/byteorder.h   |  23 ++
 arch/riscv/include/uapi/asm/elf.h         |  83 ++++++
 arch/riscv/include/uapi/asm/ptrace.h      |  69 +++++
 arch/riscv/include/uapi/asm/sigcontext.h  |  30 ++
 arch/riscv/include/uapi/asm/siginfo.h     |  24 ++
 arch/riscv/include/uapi/asm/unistd.h      |  23 ++
 59 files changed, 4846 insertions(+)
 create mode 100644 arch/riscv/include/asm/Kbuild
 create mode 100644 arch/riscv/include/asm/asm-offsets.h
 create mode 100644 arch/riscv/include/asm/asm.h
 create mode 100644 arch/riscv/include/asm/atomic.h
 create mode 100644 arch/riscv/include/asm/atomic64.h
 create mode 100644 arch/riscv/include/asm/barrier.h
 create mode 100644 arch/riscv/include/asm/bitops.h
 create mode 100644 arch/riscv/include/asm/bug.h
 create mode 100644 arch/riscv/include/asm/cache.h
 create mode 100644 arch/riscv/include/asm/cacheflush.h
 create mode 100644 arch/riscv/include/asm/cmpxchg.h
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/delay.h
 create mode 100644 arch/riscv/include/asm/device.h
 create mode 100644 arch/riscv/include/asm/dma-mapping.h
 create mode 100644 arch/riscv/include/asm/elf.h
 create mode 100644 arch/riscv/include/asm/io.h
 create mode 100644 arch/riscv/include/asm/irq.h
 create mode 100644 arch/riscv/include/asm/irqflags.h
 create mode 100644 arch/riscv/include/asm/kprobes.h
 create mode 100644 arch/riscv/include/asm/linkage.h
 create mode 100644 arch/riscv/include/asm/mmu.h
 create mode 100644 arch/riscv/include/asm/mmu_context.h
 create mode 100644 arch/riscv/include/asm/page.h
 create mode 100644 arch/riscv/include/asm/pci.h
 create mode 100644 arch/riscv/include/asm/pgalloc.h
 create mode 100644 arch/riscv/include/asm/pgtable-32.h
 create mode 100644 arch/riscv/include/asm/pgtable-64.h
 create mode 100644 arch/riscv/include/asm/pgtable-bits.h
 create mode 100644 arch/riscv/include/asm/pgtable.h
 create mode 100644 arch/riscv/include/asm/processor.h
 create mode 100644 arch/riscv/include/asm/ptrace.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/serial.h
 create mode 100644 arch/riscv/include/asm/setup.h
 create mode 100644 arch/riscv/include/asm/smp.h
 create mode 100644 arch/riscv/include/asm/spinlock.h
 create mode 100644 arch/riscv/include/asm/spinlock_types.h
 create mode 100644 arch/riscv/include/asm/string.h
 create mode 100644 arch/riscv/include/asm/switch_to.h
 create mode 100644 arch/riscv/include/asm/syscall.h
 create mode 100644 arch/riscv/include/asm/syscalls.h
 create mode 100644 arch/riscv/include/asm/thread_info.h
 create mode 100644 arch/riscv/include/asm/timex.h
 create mode 100644 arch/riscv/include/asm/tlb.h
 create mode 100644 arch/riscv/include/asm/tlbflush.h
 create mode 100644 arch/riscv/include/asm/uaccess.h
 create mode 100644 arch/riscv/include/asm/unistd.h
 create mode 100644 arch/riscv/include/asm/vdso.h
 create mode 100644 arch/riscv/include/asm/word-at-a-time.h
 create mode 100644 arch/riscv/include/uapi/asm/Kbuild
 create mode 100644 arch/riscv/include/uapi/asm/auxvec.h
 create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h
 create mode 100644 arch/riscv/include/uapi/asm/byteorder.h
 create mode 100644 arch/riscv/include/uapi/asm/elf.h
 create mode 100644 arch/riscv/include/uapi/asm/ptrace.h
 create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h
 create mode 100644 arch/riscv/include/uapi/asm/siginfo.h
 create mode 100644 arch/riscv/include/uapi/asm/unistd.h
arch/riscv/include/asm/Kbuild new file +60 -0
new file mode 100644
index 000000000000..d861450998bb
@@ -0,0 +1,60 @@
+generic-y += bugs.h
+generic-y += cacheflush.h
+generic-y += checksum.h
+generic-y += clkdev.h
+generic-y += cputime.h
+generic-y += current.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += exec.h
+generic-y += fb.h
+generic-y += fcntl.h
+generic-y += ftrace.h
+generic-y += futex.h
+generic-y += hardirq.h
+generic-y += hash.h
+generic-y += hw_irq.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += irq_regs.h
+generic-y += irq_work.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += kvm_para.h
+generic-y += local.h
+generic-y += mm-arch-hooks.h
+generic-y += mman.h
+generic-y += module.h
+generic-y += msgbuf.h
+generic-y += mutex.h
+generic-y += param.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += preempt.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += sembuf.h
+generic-y += shmbuf.h
+generic-y += shmparam.h
+generic-y += signal.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += stat.h
+generic-y += statfs.h
+generic-y += swab.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += topology.h
+generic-y += trace_clock.h
+generic-y += types.h
+generic-y += ucontext.h
+generic-y += unaligned.h
+generic-y += user.h
+generic-y += vga.h
+generic-y += vmlinux.lds.h
+generic-y += xor.h
arch/riscv/include/asm/asm-offsets.h new file +1 -0
new file mode 100644
index 000000000000..d370ee36a182
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
arch/riscv/include/asm/asm.h new file +65 -0

65 lines not on this page · raw message

arch/riscv/include/asm/atomic.h new file +349 -0

349 lines not on this page · raw message

arch/riscv/include/asm/atomic64.h new file +355 -0

355 lines not on this page · raw message

arch/riscv/include/asm/barrier.h new file +33 -0
new file mode 100644
index 000000000000..e340a80135ae
@@ -0,0 +1,33 @@
+/*
+ * Based on arch/arm/include/asm/barrier.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2013 Regents of the University of California
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _ASM_RISCV_BARRIER_H
+#define _ASM_RISCV_BARRIER_H
+
+#ifndef __ASSEMBLY__
+
+#define nop()	__asm__ __volatile__ ("nop")
+
+#define mb()	__asm__ __volatile__ ("fence" : : : "memory")
+
+#include <asm-generic/barrier.h>
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_RISCV_BARRIER_H */
arch/riscv/include/asm/bitops.h new file +229 -0

229 lines not on this page · raw message

arch/riscv/include/asm/bug.h new file +81 -0

81 lines not on this page · raw message

arch/riscv/include/asm/cache.h new file +23 -0
new file mode 100644
index 000000000000..02082e118178
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 Chen Liqin <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT		6
+
+#define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
+
+#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/cacheflush.h new file +40 -0
new file mode 100644
index 000000000000..0546ae75d368
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_CACHEFLUSH_H
+#define _ASM_RISCV_CACHEFLUSH_H
+
+#include <asm-generic/cacheflush.h>
+
+#undef flush_icache_range
+#undef flush_icache_user_range
+
+static inline void local_flush_icache_all(void)
+{
+	asm volatile ("fence.i" ::: "memory");
+}
+
+#ifndef CONFIG_SMP
+
+#define flush_icache_range(start, end) local_flush_icache_all()
+#define flush_icache_user_range(vma, pg, addr, len) local_flush_icache_all()
+
+#else /* CONFIG_SMP */
+
+#define flush_icache_range(start, end) sbi_remote_fence_i(0)
+#define flush_icache_user_range(vma, pg, addr, len) sbi_remote_fence_i(0)
+
+#endif /* CONFIG_SMP */
+
+#endif /* _ASM_RISCV_CACHEFLUSH_H */
arch/riscv/include/asm/cmpxchg.h new file +125 -0

125 lines not on this page · raw message

arch/riscv/include/asm/csr.h new file +126 -0

126 lines not on this page · raw message

arch/riscv/include/asm/delay.h new file +29 -0
new file mode 100644
index 000000000000..18d399d3e689
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2009 Chen Liqin <[email protected]>
+ * Copyright (C) 2016 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_DELAY_H
+#define _ASM_RISCV_DELAY_H
+
+extern unsigned long timebase;
+
+#define udelay udelay
+extern void udelay(unsigned long usecs);
+
+#define ndelay ndelay
+extern void ndelay(unsigned long nsecs);
+
+extern void __delay(unsigned long cycles);
+
+#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/include/asm/device.h new file +28 -0
new file mode 100644
index 000000000000..89e8ce022e37
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2016 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+
+#ifndef _ASM_RISCV_DEVICE_H
+#define _ASM_RISCV_DEVICE_H
+
+#include <linux/sysfs.h>
+
+struct dev_archdata {
+	struct dma_map_ops *dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif /* _ASM_RISCV_DEVICE_H */
arch/riscv/include/asm/dma-mapping.h new file +61 -0

61 lines not on this page · raw message

arch/riscv/include/asm/elf.h new file +83 -0

83 lines not on this page · raw message

arch/riscv/include/asm/io.h new file +36 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>
+
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MMU
+
+extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
+
+#define ioremap_nocache(addr, size) ioremap((addr), (size))
+#define ioremap_wc(addr, size) ioremap((addr), (size))
+#define ioremap_wt(addr, size) ioremap((addr), (size))
+
+extern void iounmap(void __iomem *addr);
+
+#endif /* CONFIG_MMU */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_RISCV_IO_H */
arch/riscv/include/asm/irq.h new file +32 -0
new file mode 100644
index 000000000000..ce024e60f585
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_IRQ_H
+#define _ASM_RISCV_IRQ_H
+
+#define NR_IRQS         0
+
+#define INTERRUPT_CAUSE_SOFTWARE    1
+#define INTERRUPT_CAUSE_TIMER       5
+#define INTERRUPT_CAUSE_EXTERNAL    9
+
+void riscv_timer_interrupt(void);
+
+#include <asm-generic/irq.h>
+
+/* The value of csr sie before init_traps runs (core is up) */
+DECLARE_PER_CPU(atomic_long_t, riscv_early_sie);
+
+#endif /* _ASM_RISCV_IRQ_H */
arch/riscv/include/asm/irqflags.h new file +64 -0

64 lines not on this page · raw message

arch/riscv/include/asm/kprobes.h new file +23 -0
new file mode 100644
index 000000000000..61a03e7c1975
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+
+#ifndef ASM_RISCV_KPROBES_H
+#define ASM_RISCV_KPROBES_H
+
+#ifdef CONFIG_KPROBES
+#error "RISC-V doesn't skpport CONFIG_KPROBES"
+#endif
+
+#endif
arch/riscv/include/asm/linkage.h new file +21 -0
new file mode 100644
index 000000000000..6d4d4f6b6951
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_LINKAGE_H
+#define _ASM_RISCV_LINKAGE_H
+
+#define __ALIGN		.balign 4
+#define __ALIGN_STR	".balign 4"
+
+#endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/mmu.h new file +27 -0
new file mode 100644
index 000000000000..9eeee484fd81
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+
+#ifndef _ASM_RISCV_MMU_H
+#define _ASM_RISCV_MMU_H
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+	void *vdso;
+} mm_context_t;
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_RISCV_MMU_H */
arch/riscv/include/asm/mmu_context.h new file +70 -0

70 lines not on this page · raw message

arch/riscv/include/asm/page.h new file +138 -0

138 lines not on this page · raw message

arch/riscv/include/asm/pci.h new file +51 -0

51 lines not on this page · raw message

arch/riscv/include/asm/pgalloc.h new file +126 -0

126 lines not on this page · raw message

arch/riscv/include/asm/pgtable-32.h new file +26 -0
new file mode 100644
index 000000000000..ae6ad80f80a5
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_PGTABLE_32_H
+#define _ASM_RISCV_PGTABLE_32_H
+
+#include <asm-generic/pgtable-nopmd.h>
+#include <linux/const.h>
+
+/* Size of region mapped by a page global directory */
+#define PGDIR_SHIFT     22
+#define PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
+#define PGDIR_MASK      (~(PGDIR_SIZE - 1))
+
+#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +85 -0

85 lines not on this page · raw message

arch/riscv/include/asm/pgtable-bits.h new file +49 -0

49 lines not on this page · raw message

arch/riscv/include/asm/pgtable.h new file +426 -0

426 lines not on this page · raw message

arch/riscv/include/asm/processor.h new file +103 -0

103 lines not on this page · raw message

arch/riscv/include/asm/ptrace.h new file +117 -0

35 lines not on this page · raw message

arch/riscv/include/asm/sbi.h new file +101 -0

101 lines not on this page · raw message

arch/riscv/include/asm/serial.h new file +43 -0

43 lines not on this page · raw message

arch/riscv/include/asm/setup.h new file +20 -0
new file mode 100644
index 000000000000..e457854e9988

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/smp.h new file +42 -0

42 lines not on this page · raw message

arch/riscv/include/asm/spinlock.h new file +156 -0

156 lines not on this page · raw message

arch/riscv/include/asm/spinlock_types.h new file +34 -0
new file mode 100644
index 000000000000..0a4ff7086e8a

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/string.h new file +31 -0
new file mode 100644
index 000000000000..b394c02a537a

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/switch_to.h new file +71 -0

71 lines not on this page · raw message

arch/riscv/include/asm/syscall.h new file +91 -0

91 lines not on this page · raw message

arch/riscv/include/asm/syscalls.h new file +26 -0
new file mode 100644
index 000000000000..1dd23596b0d3

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/thread_info.h new file +103 -0

103 lines not on this page · raw message

arch/riscv/include/asm/timex.h new file +55 -0

55 lines not on this page · raw message

arch/riscv/include/asm/tlb.h new file +25 -0
new file mode 100644
index 000000000000..6195b0ea718b

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/tlbflush.h new file +95 -0

95 lines not on this page · raw message

arch/riscv/include/asm/uaccess.h new file +455 -0

455 lines not on this page · raw message

arch/riscv/include/asm/unistd.h new file +17 -0
new file mode 100644
index 000000000000..3f5820f50912

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/vdso.h new file +32 -0
new file mode 100644
index 000000000000..95768a3810a7

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/word-at-a-time.h new file +56 -0

56 lines not on this page · raw message

arch/riscv/include/uapi/asm/Kbuild new file +10 -0
new file mode 100644
index 000000000000..276b6dae745c

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
new file mode 100644
index 000000000000..1376515547cd

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
new file mode 100644
index 000000000000..0b3cb52fd29d

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
new file mode 100644
index 000000000000..4ca38af2cd32

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/elf.h new file +83 -0

83 lines not on this page · raw message

arch/riscv/include/uapi/asm/ptrace.h new file +69 -0

69 lines not on this page · raw message

arch/riscv/include/uapi/asm/sigcontext.h new file +30 -0
new file mode 100644
index 000000000000..04967aade3a6

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
new file mode 100644
index 000000000000..f96849aac662

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/unistd.h new file +23 -0
new file mode 100644
index 000000000000..124810f71633

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.0

Part of the diff is not shown here. View the raw message.

author maintainer
#61 lore raw

PATCH 7/7 RISC-V: arch/riscv/mm

In reply to Palmer Dabbelt
---
 arch/riscv/mm/Makefile  |   1 +
 arch/riscv/mm/extable.c |  38 +++++++
 arch/riscv/mm/fault.c   | 279 ++++++++++++++++++++++++++++++++++++++++++++++++
 arch/riscv/mm/init.c    |  72 +++++++++++++
 arch/riscv/mm/ioremap.c |  96 +++++++++++++++++
 5 files changed, 486 insertions(+)
 create mode 100644 arch/riscv/mm/Makefile
 create mode 100644 arch/riscv/mm/extable.c
 create mode 100644 arch/riscv/mm/fault.c
 create mode 100644 arch/riscv/mm/init.c
 create mode 100644 arch/riscv/mm/ioremap.c
arch/riscv/mm/Makefile new file +1 -0
new file mode 100644
index 000000000000..36ebe6feb5d6
@@ -0,0 +1 @@
+obj-y := init.o fault.o extable.o ioremap.o
arch/riscv/mm/extable.c new file +38 -0
new file mode 100644
index 000000000000..811b298c2475
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
+ *  Lennox Wu <[email protected]>
+ *  Chen Liqin <[email protected]>
+ * Copyright (C) 2013 Regents of the University of California
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include <linux/extable.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+	const struct exception_table_entry *fixup;
+
+	fixup = search_exception_tables(regs->sepc);
+	if (fixup) {
+		regs->sepc = fixup->fixup;
+		return 1;
+	}
+	return 0;
+}
arch/riscv/mm/fault.c new file +279 -0

279 lines not on this page · raw message

arch/riscv/mm/init.c new file +72 -0

72 lines not on this page · raw message

arch/riscv/mm/ioremap.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#37 lore raw

PATCH 5/7 RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt
---
 arch/riscv/lib/Makefile  |   5 ++
 arch/riscv/lib/ashldi3.c |  42 ++++++++++++++++
 arch/riscv/lib/ashrdi3.c |  44 +++++++++++++++++
 arch/riscv/lib/delay.c   |  42 ++++++++++++++++
 arch/riscv/lib/libgcc.h  |  46 +++++++++++++++++
 arch/riscv/lib/lshrdi3.c |  42 ++++++++++++++++
 arch/riscv/lib/memcpy.S  |  99 +++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/memset.S  | 119 ++++++++++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/uaccess.S | 125 +++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 564 insertions(+)
 create mode 100644 arch/riscv/lib/Makefile
 create mode 100644 arch/riscv/lib/ashldi3.c
 create mode 100644 arch/riscv/lib/ashrdi3.c
 create mode 100644 arch/riscv/lib/delay.c
 create mode 100644 arch/riscv/lib/libgcc.h
 create mode 100644 arch/riscv/lib/lshrdi3.c
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memset.S
 create mode 100644 arch/riscv/lib/uaccess.S
arch/riscv/lib/Makefile new file +5 -0
new file mode 100644
index 000000000000..f644e582f4b8
@@ -0,0 +1,5 @@
+lib-y	:= delay.o memcpy.o memset.o uaccess.o
+
+ifeq ($(CONFIG_64BIT),)
+lib-y += ashldi3.o ashrdi3.o lshrdi3.o
+endif
arch/riscv/lib/ashldi3.c new file +42 -0

42 lines not on this page · raw message

arch/riscv/lib/ashrdi3.c new file +44 -0

44 lines not on this page · raw message

arch/riscv/lib/delay.c new file +42 -0

42 lines not on this page · raw message

arch/riscv/lib/libgcc.h new file +46 -0

46 lines not on this page · raw message

arch/riscv/lib/lshrdi3.c new file +42 -0

42 lines not on this page · raw message

arch/riscv/lib/memcpy.S new file +99 -0

99 lines not on this page · raw message

arch/riscv/lib/memset.S new file +119 -0

119 lines not on this page · raw message

arch/riscv/lib/uaccess.S new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#48 lore raw

PATCH 6/7 RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
---
 arch/riscv/kernel/Makefile         |  19 ++
 arch/riscv/kernel/asm-offsets.c    | 113 ++++++++++
 arch/riscv/kernel/cacheinfo.c      |  82 ++++++++
 arch/riscv/kernel/cpu.c            |  81 ++++++++
 arch/riscv/kernel/entry.S          | 414 +++++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           | 139 +++++++++++++
 arch/riscv/kernel/irq.c            | 205 ++++++++++++++++++
 arch/riscv/kernel/module.c         | 185 +++++++++++++++++
 arch/riscv/kernel/pci.c            |  36 ++++
 arch/riscv/kernel/plic.c           | 208 +++++++++++++++++++
 arch/riscv/kernel/process.c        | 130 ++++++++++++
 arch/riscv/kernel/ptrace.c         | 148 +++++++++++++
 arch/riscv/kernel/reset.c          |  33 +++
 arch/riscv/kernel/riscv_ksyms.c    |  16 ++
 arch/riscv/kernel/sbi-con.c        | 214 +++++++++++++++++++
 arch/riscv/kernel/setup.c          | 234 +++++++++++++++++++++
 arch/riscv/kernel/signal.c         | 258 +++++++++++++++++++++++
 arch/riscv/kernel/smp.c            | 107 ++++++++++
 arch/riscv/kernel/smpboot.c        | 105 ++++++++++
 arch/riscv/kernel/stacktrace.c     | 183 ++++++++++++++++
 arch/riscv/kernel/sys_riscv.c      |  85 ++++++++
 arch/riscv/kernel/syscall_table.c  |  26 +++
 arch/riscv/kernel/time.c           | 116 +++++++++++
 arch/riscv/kernel/traps.c          | 167 +++++++++++++++
 arch/riscv/kernel/vdso.c           | 125 +++++++++++
 arch/riscv/kernel/vdso/.gitignore  |   1 +
 arch/riscv/kernel/vdso/Makefile    |  61 ++++++
 arch/riscv/kernel/vdso/sigreturn.S |  25 +++
 arch/riscv/kernel/vdso/vdso.S      |  28 +++
 arch/riscv/kernel/vdso/vdso.lds.S  |  77 +++++++
 arch/riscv/kernel/vmlinux.lds.S    |  93 +++++++++
 31 files changed, 3714 insertions(+)
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/pci.c
 create mode 100644 arch/riscv/kernel/plic.c
 create mode 100644 arch/riscv/kernel/process.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/sbi-con.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/signal.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.c
 create mode 100644 arch/riscv/kernel/stacktrace.c
 create mode 100644 arch/riscv/kernel/sys_riscv.c
 create mode 100644 arch/riscv/kernel/syscall_table.c
 create mode 100644 arch/riscv/kernel/time.c
 create mode 100644 arch/riscv/kernel/traps.c
 create mode 100644 arch/riscv/kernel/vdso.c
 create mode 100644 arch/riscv/kernel/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/Makefile new file +19 -0
new file mode 100644
index 000000000000..94ac2931c56a
@@ -0,0 +1,19 @@
+#
+# Makefile for the RISC-V Linux kernel
+#
+
+extra-y := head.o vmlinux.lds
+
+obj-y	:= cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
+	   signal.o syscall_table.o sys_riscv.o time.o traps.o \
+	   riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/
+
+CFLAGS_setup.o := -mcmodel=medany
+
+obj-$(CONFIG_SMP)		+= smpboot.o smp.o
+obj-$(CONFIG_SBI_CONSOLE)	+= sbi-con.o
+obj-$(CONFIG_PCI)		+= pci.o
+obj-$(CONFIG_MODULES)		+= module.o
+obj-$(CONFIG_PLIC)		+= plic.o
+
+clean:
arch/riscv/kernel/asm-offsets.c new file +113 -0

113 lines not on this page · raw message

arch/riscv/kernel/cacheinfo.c new file +82 -0

82 lines not on this page · raw message

arch/riscv/kernel/cpu.c new file +81 -0

81 lines not on this page · raw message

arch/riscv/kernel/entry.S new file +414 -0

414 lines not on this page · raw message

arch/riscv/kernel/head.S new file +139 -0

139 lines not on this page · raw message

arch/riscv/kernel/irq.c new file +205 -0

205 lines not on this page · raw message

arch/riscv/kernel/module.c new file +185 -0

185 lines not on this page · raw message

arch/riscv/kernel/pci.c new file +36 -0
new file mode 100644
index 000000000000..4191a5ffdd67
@@ -0,0 +1,36 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c
+ *
+ * Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM
+ * Copyright (C) 2014 ARM Ltd.
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+
+/*
+ * Called after each bus is probed, but before its children are examined
+ */
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+	/* nothing to do, expected to be removed in the future */
+}
+
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here
+ */
+resource_size_t pcibios_align_resource(void *data, const struct resource *res,
+				resource_size_t size, resource_size_t align)
+{
+	return res->start;
+}
arch/riscv/kernel/plic.c new file +208 -0

208 lines not on this page · raw message

arch/riscv/kernel/process.c new file +130 -0

130 lines not on this page · raw message

arch/riscv/kernel/ptrace.c new file +148 -0

148 lines not on this page · raw message

arch/riscv/kernel/reset.c new file +33 -0
new file mode 100644
index 000000000000..58bad9598e21
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/reboot.h>
+#include <linux/export.h>
+#include <asm/sbi.h>
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_restart(char *cmd)
+{
+}
+
+void machine_halt(void)
+{
+}
+
+void machine_power_off(void)
+{
+  sbi_shutdown();
+}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
new file mode 100644
index 000000000000..ab0db6d48101
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2017 Zihao Yu
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/export.h>
+#include <linux/uaccess.h>
+
+/*
+ * Assembly functions that may be used (directly or indirectly) by modules
+ */
+EXPORT_SYMBOL(__copy_user);
+
arch/riscv/kernel/sbi-con.c new file +214 -0

214 lines not on this page · raw message

arch/riscv/kernel/setup.c new file +234 -0

234 lines not on this page · raw message

arch/riscv/kernel/signal.c new file +258 -0

258 lines not on this page · raw message

arch/riscv/kernel/smp.c new file +107 -0

107 lines not on this page · raw message

arch/riscv/kernel/smpboot.c new file +105 -0

105 lines not on this page · raw message

arch/riscv/kernel/stacktrace.c new file +183 -0

183 lines not on this page · raw message

arch/riscv/kernel/sys_riscv.c new file +85 -0

85 lines not on this page · raw message

arch/riscv/kernel/syscall_table.c new file +26 -0
new file mode 100644
index 000000000000..6b5505b1dbb5
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2009 Arnd Bergmann <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/time.c new file +116 -0

116 lines not on this page · raw message

arch/riscv/kernel/traps.c new file +167 -0

167 lines not on this page · raw message

arch/riscv/kernel/vdso.c new file +125 -0

125 lines not on this page · raw message

arch/riscv/kernel/vdso/.gitignore new file +1 -0
new file mode 100644
index 000000000000..f8b69d84238e

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/Makefile new file +61 -0

61 lines not on this page · raw message

arch/riscv/kernel/vdso/sigreturn.S new file +25 -0
new file mode 100644
index 000000000000..d5d33dbb5976

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.S new file +28 -0
new file mode 100644
index 000000000000..e2edb3529286

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.lds.S new file +77 -0

77 lines not on this page · raw message

arch/riscv/kernel/vmlinux.lds.S new file +93 -0

93 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.0

Part of the diff is not shown here. View the raw message.

author maintainer
#25 lore raw

PATCH 3/7 RISC-V: Device Tree Documentation

In reply to Palmer Dabbelt
---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
new file mode 100644
index 000000000000..62f02e834ff9
@@ -0,0 +1,46 @@
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------
+
+RISC-V cores include Control Status Registers (CSRs) which are local to each
+hart and can be read or written by software. Some of these CSRs are used to
+control local interrupts connected to the core.
+
+Typical examples of local interrupts on a RISC-V core include: software IPI
+interrupts, timer interrupts, and a link to the PLIC interrupt controller.
+
+Required properties:
+- compatible : "riscv,cpu-intc"
+- #interrupt-cells : should be <1>
+- interrupt-controller : Identifies the node as an interrupt controller
+
+Furthermore, this interrupt-controller MUST be embedded inside the cpu
+definition of the hart whose CSRs control these local interrupts.
+
+Example:
+
+	cpu1: cpu@1 {
+		clock-frequency = <1600000000>;
+		compatible = "riscv";
+		d-cache-block-size = <64>;
+		d-cache-sets = <64>;
+		d-cache-size = <16384>;
+		d-tlb-sets = <1>;
+		d-tlb-size = <32>;
+		device_type = "cpu";
+		i-cache-block-size = <64>;
+		i-cache-sets = <64>;
+		i-cache-size = <16384>;
+		i-tlb-sets = <1>;
+		i-tlb-size = <32>;
+		mmu-type = "riscv,sv39";
+		next-level-cache = <&L2>;
+		reg = <1>;
+		riscv,isa = "rv64imac";
+		status = "okay";
+		tlb-split;
+		cpu1-intc: interrupt-controller {
+			#interrupt-cells = <1>;
+			compatible = "riscv,cpu-intc";
+			interrupt-controller;
+		};
+	};
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#1 lore raw

PATCH 1/7 RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

---
 Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)
Makefile +8 -0
index 63e10bd4f14a..0606f28cd4fd 100644
@@ -269,6 +269,14 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
+# Additional ARCH settings for RISC-V
+ifeq ($(ARCH),riscv32)
+	SRCARCH := riscv
+endif
+ifeq ($(ARCH),riscv64)
+	SRCARCH := riscv
+endif
+
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc
Signature · 1 line
2.13.0
#65 lore raw
In reply to Palmer Dabbelt

Hi Palmer,

Quoted 11 lines · Palmer Dabbelt

We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.

This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.

Quoted 8 lines

These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.

Time is right for review and eventual merge of this. Whether it makes 4.13 depends on how much discussion ensues. :)

Quoted 1 line

Albert and I will volunteer to maintain this port if it's OK with everyone.

It always makes sense to have architecture-knowledge people maintain it; no complaints from me.

What we've seen been useful on other platforms (i.e. arm/arm64) is to offload the per-vendor stuff to a separate tree. It might or might not be needed here; likely to start out it won't be enough material to need it.

Quoted 9 lines

We'd like to thank the various members of the RISC-V software community who have helped us with the port.

Thanks!

In addition to the threaded messages, our port can be found on Git Hib

https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1

Quoted 7 lines

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add Makefile contents that refers to directories not yet introduced).

While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.

Also, none of the patches seem to have any descriptions. Adding some high-level descriptions of what's in each patch in the patch itself is useful both for reviewing now, and for educating anyone coming along later on trying to learn about the code and why it's been implemented as it has.

I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.

-Olof

reviewer
#66 lore raw
Quoted 16 lines · Olof Johansson

Hi Palmer,

Quoted 11 lines · Palmer Dabbelt

In addition to the threaded messages, our port can be found on Git Hib

https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

Quoted 8 lines

So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add Makefile contents that refers to directories not yet introduced).

While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.

Neither the email patches nor the git tree have any Signed-off-by:
entries AFAICT.

Signature · 1 line
~Randy
#9 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt

Hi,

Quoted 8 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
Quoted 8 lines
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike

Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.

Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.

Quoted 26 lines
arch/riscv/.gitignore new file +19 -0
new file mode 100644
index 000000000000..376d06eb5d52
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a
+*.s
+*.ko
+*.so
+*.so.dbg
+*.mod.c
+*.i
+*.lst
+*.symtypes
+*.order

arch/riscv/.gitignore line 29

Quoted 10 lines
arch/riscv/.gitignore new file +10 -0
+modules.builtin
+*.elf
+*.bin
+*.gz
+*.bz2
+*.lzma
+*.xz
+*.lzo
+*.patch
+*.gcno

I don't think you need to do any of this, just inherit the global one (by not having one here)?

arch/riscv/.gitignore line 31

Quoted 2 lines
arch/riscv/.gitignore new file +2 -0
+
+include/generated

This is already covered by the global .gitignore.

arch/riscv/.gitignore line 32

Quoted 1 line
arch/riscv/.gitignore new file +1 -0
+kernel/vmlinux.lds

And if needed this should be added to the arch/riscv/kernel/.gitignore file instead.

Quoted 105 lines
arch/riscv/Kconfig new file +99 -0
new file mode 100644
index 000000000000..510ead1d3343
@@ -0,0 +1,300 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+       def_bool y
+       select OF
+       select OF_EARLY_FLATTREE
+       select OF_IRQ
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_WANT_FRAME_POINTERS
+       select CLONE_BACKWARDS
+       select COMMON_CLK
+       select GENERIC_CLOCKEVENTS
+       select GENERIC_CPU_DEVICES
+       select GENERIC_IRQ_SHOW
+       select GENERIC_PCI_IOMAP
+       select GENERIC_STRNCPY_FROM_USER
+       select GENERIC_STRNLEN_USER
+       select GENERIC_SMP_IDLE_THREAD
+       select GENERIC_ATOMIC64 if !64BIT || !RV_ATOMIC
+       select ARCH_WANT_OPTIONAL_GPIOLIB
+       select HAVE_MEMBLOCK
+       select HAVE_DMA_API_DEBUG
+       select HAVE_DMA_CONTIGUOUS
+       select HAVE_GENERIC_DMA_COHERENT
+       select IRQ_DOMAIN
+       select NO_BOOTMEM
+       select RV_ATOMIC if SMP
+       select RV_SYSRISCV_ATOMIC if !RV_ATOMIC
+       select SPARSE_IRQ
+       select SYSCTL_EXCEPTION_TRACE
+       select HAVE_ARCH_TRACEHOOK
+       select MODULES_USE_ELF_RELA if MODULES
+
+config MMU
+       def_bool y
+
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+       def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+       def_bool y
+
+config STACKTRACE_SUPPORT
+       def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+       def_bool y
+
+config GENERIC_BUG
+       def_bool y
+       depends on BUG
+       select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
+
+config GENERIC_BUG_RELATIVE_POINTERS
+       bool
+
+config GENERIC_CALIBRATE_DELAY
+       def_bool y
+
+config GENERIC_CSUM
+       def_bool y
+
+config GENERIC_HWEIGHT
+       def_bool y
+
+config PGTABLE_LEVELS
+       int
+       default 3 if 64BIT
+       default 2
+
+config HAVE_KPROBES
+       def_bool n
+
+config DMA_NOOP_OPS
+       def_bool y
+
+menu "Platform type"
+
+config SMP
+       bool "Symmetric Multi-Processing"
+       help
+         This enables support for systems with more than one CPU.  If
+         you say N here, the kernel will run on single and
+         multiprocessor machines, but will use only one CPU of a
+         multiprocessor machine. If you say Y here, the kernel will run
+         on many, but not all, single processor machines. On a single
+         processor machine, the kernel will run faster if you say N
+         here.
+
+         If you don't know what to do here, say N.
+
+config NR_CPUS
+       int "Maximum number of CPUs (2-32)"
+       range 2 32
+       depends on SMP

arch/riscv/Kconfig line 109

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       default "8"
+
+choice
+       prompt "CPU selection"
+       default CPU_RV_GENERIC
+
+config CPU_RV_GENERIC
+       bool "Generic RISC-V"
+       select CPU_SUPPORTS_32BIT_KERNEL
+       select CPU_SUPPORTS_64BIT_KERNEL

Is this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (CPU_RV_GENERIC that is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_bool y' for now.

Quoted 13 lines
arch/riscv/Kconfig new file +13 -0
+
+endchoice
+
+config PLIC
+       bool "Platform-Level Interrupt Controller"
+       default y
+       help
+          This enables support for the PLIC chip found in standard RISC-V
+          systems. The PLIC is the top-most interrupt controller found in
+          the system, connected directly to the core complex. All other
+          interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+          If you don't know what to do here, say Y.

arch/riscv/Kconfig line 132

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+
+config CPU_SUPPORTS_32BIT_KERNEL
+       bool
+config CPU_SUPPORTS_64BIT_KERNEL
+       bool
+
+config SBI_CONSOLE
+       tristate "SBI console support"
+       select TTY
+       default y

Usually you end up having a DRIVER_FOO and DRIVER_FOO_CONSOLE option to enable registering it as console.

Also, unless there's strong reason to keep it under arch/, it should probably go under drivers/tty/.

arch/riscv/Kconfig line 136

Quoted 3 lines
arch/riscv/Kconfig new file +3 -0
+config RVC
+       bool "Use compressed instructions (RV32C or RV64C)"
+       default n

What does "use" here mean? Use during build, or allow userspace to use them?

arch/riscv/Kconfig line 140

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y

Same for this.

arch/riscv/Kconfig line 152

Quoted 11 lines
arch/riscv/Kconfig new file +11 -0
+config RV_SYSRISCV_ATOMIC
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

If it's mandatory then Kconfig language should make it so.

Quoted 22 lines
arch/riscv/Kconfig new file +22 -0
+config RV_PUM
+       def_bool y
+       prompt "Protect User Memory" if EXPERT
+       ---help---
+         Protect User Memory (PUM) prevents the kernel from inadvertently
+         accessing user-space memory.  There is a small performance cost
+         and kernel size increase if this is enabled.
+
+         If unsure, say Y.
+
+endmenu
+
+menu "Kernel type"
+
+choice
+       prompt "Kernel code model"
+       default 64BIT
+
+config 32BIT
+       bool "32-bit kernel"
+       depends on CPU_SUPPORTS_32BIT_KERNEL
+       help

arch/riscv/Kconfig line 185

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+         Select this option to build a 32-bit kernel.
+
+config 64BIT
+       bool "64-bit kernel"
+       depends on CPU_SUPPORTS_64BIT_KERNEL
+       help
+         Select this option to build a 64-bit kernel.
+
+endchoice
+

[...]

-Olof

reviewer
#62 lore raw

Re: [PATCH 7/7] RISC-V: arch/riscv/mm

In reply to Palmer Dabbelt

arch/riscv/mm/fault.c line 4

Quoted 11 lines
arch/riscv/mm/fault.c new file +4 -0
new file mode 100644
index 000000000000..f02e286dd1c1
@@ -0,0 +1,279 @@
+/*
+ * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
+ *  Lennox Wu <[email protected]>
+ *  Chen Liqin <[email protected]>

is "sunplusct.com" correct? They don't have a web server?

Signature · 1 line
~Randy
reviewer
#10 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Olof Johansson
Quoted 21 lines · Olof Johansson

Hi,

Quoted 8 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
Quoted 8 lines
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
Quoted 8 lines

Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.

Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.

well, the top-level Makefile looks for "make *config" to indicate that there is a config-command in progress (or in process), so they usually have to end in the string "config".

Have these been tested?

Signature · 1 line
~Randy
#49 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
Quoted 56 lines · Palmer Dabbelt
---
 arch/riscv/kernel/Makefile         |  19 ++
 arch/riscv/kernel/asm-offsets.c    | 113 ++++++++++
 arch/riscv/kernel/cacheinfo.c      |  82 ++++++++
 arch/riscv/kernel/cpu.c            |  81 ++++++++
 arch/riscv/kernel/entry.S          | 414 +++++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           | 139 +++++++++++++
 arch/riscv/kernel/irq.c            | 205 ++++++++++++++++++
 arch/riscv/kernel/module.c         | 185 +++++++++++++++++
 arch/riscv/kernel/pci.c            |  36 ++++
 arch/riscv/kernel/plic.c           | 208 +++++++++++++++++++
 arch/riscv/kernel/process.c        | 130 ++++++++++++
 arch/riscv/kernel/ptrace.c         | 148 +++++++++++++
 arch/riscv/kernel/reset.c          |  33 +++
 arch/riscv/kernel/riscv_ksyms.c    |  16 ++
 arch/riscv/kernel/sbi-con.c        | 214 +++++++++++++++++++
 arch/riscv/kernel/setup.c          | 234 +++++++++++++++++++++
 arch/riscv/kernel/signal.c         | 258 +++++++++++++++++++++++
 arch/riscv/kernel/smp.c            | 107 ++++++++++
 arch/riscv/kernel/smpboot.c        | 105 ++++++++++
 arch/riscv/kernel/stacktrace.c     | 183 ++++++++++++++++
 arch/riscv/kernel/sys_riscv.c      |  85 ++++++++
 arch/riscv/kernel/syscall_table.c  |  26 +++
 arch/riscv/kernel/time.c           | 116 +++++++++++
 arch/riscv/kernel/traps.c          | 167 +++++++++++++++
 arch/riscv/kernel/vdso.c           | 125 +++++++++++
 arch/riscv/kernel/vdso/.gitignore  |   1 +
 arch/riscv/kernel/vdso/Makefile    |  61 ++++++
 arch/riscv/kernel/vdso/sigreturn.S |  25 +++
 arch/riscv/kernel/vdso/vdso.S      |  28 +++
 arch/riscv/kernel/vdso/vdso.lds.S  |  77 +++++++
 arch/riscv/kernel/vmlinux.lds.S    |  93 +++++++++
 31 files changed, 3714 insertions(+)
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/pci.c
 create mode 100644 arch/riscv/kernel/plic.c
 create mode 100644 arch/riscv/kernel/process.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/sbi-con.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/signal.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.c
 create mode 100644 arch/riscv/kernel/stacktrace.c
 create mode 100644 arch/riscv/kernel/sys_riscv.c
 create mode 100644 arch/riscv/kernel/syscall_table.c
 create mode 100644 arch/riscv/kernel/time.c
Quoted 8 lines
 create mode 100644 arch/riscv/kernel/traps.c
 create mode 100644 arch/riscv/kernel/vdso.c
 create mode 100644 arch/riscv/kernel/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S

What's missing from this patchset (ideally) is a good writeup under DOcumentation/ on expectations of system state (and/or configuration) upon entry of the kernel. For comparison, see the arm64 documentation where they were quite specific in this.

This patch is also pushing size limits, and is getting unwieldy to comment on. I'll point out a few things below with plenty of snipped out lines.

Quoted 34 lines
arch/riscv/kernel/Makefile new file +19 -0
new file mode 100644
index 000000000000..94ac2931c56a
@@ -0,0 +1,19 @@
+#
+# Makefile for the RISC-V Linux kernel
+#
+
+extra-y := head.o vmlinux.lds
+
+obj-y  := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
+          signal.o syscall_table.o sys_riscv.o time.o traps.o \
+          riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/
+
+CFLAGS_setup.o := -mcmodel=medany
+
+obj-$(CONFIG_SMP)              += smpboot.o smp.o
+obj-$(CONFIG_SBI_CONSOLE)      += sbi-con.o
+obj-$(CONFIG_PCI)              += pci.o
+obj-$(CONFIG_MODULES)          += module.o
+obj-$(CONFIG_PLIC)             += plic.o
+
+clean:
arch/riscv/kernel/asm-offsets.c new file +2 -0
new file mode 100644
index 000000000000..ac2e0cfaf8a3
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California

arch/riscv/kernel/asm-offsets.c line 12

Quoted 10 lines
arch/riscv/kernel/asm-offsets.c new file +10 -0
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.

Hmm, I haven't seen these terms used often, but they seem to exist around the tree in a few places. arch/tile is littered with them.

I am not a lawyer, but I can't seem any reference to "good title" in the GPLv2 text.

Rather than having to go through the process of figuring out if this license header is acceptable or not, you might find it easier to just go with something more established.

Quoted 62 lines
arch/riscv/kernel/cacheinfo.c new file +56 -0
new file mode 100644
index 000000000000..a22ea8abbf3c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/cacheinfo.h>
+#include <linux/cpu.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+
+static void ci_leaf_init(struct cacheinfo *this_leaf,
+                         struct device_node *node,
+                         enum cache_type type, unsigned int level)
+{
+        this_leaf->of_node = node;
+        this_leaf->level = level;
+        this_leaf->type = type;
+        this_leaf->physical_line_partition = 1; // not a sector cache
+        this_leaf->attributes = CACHE_WRITE_BACK | CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE; // TODO: add to DTS
+}
+
+static int __init_cache_level(unsigned int cpu)
+{
+       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
+       struct device_node *np = of_cpu_device_node_get(cpu);
+       int levels = 0, leaves = 0, level;
+
+       if (of_property_read_bool(np, "cache-size")) ++leaves;
+       if (of_property_read_bool(np, "i-cache-size")) ++leaves;
+       if (of_property_read_bool(np, "d-cache-size")) ++leaves;
+       if (leaves > 0) levels = 1;
+
+       while ((np = of_find_next_cache_node(np))) {
+               if (!of_device_is_compatible(np, "cache")) break;
+               if (of_property_read_u32(np, "cache-level", &level)) break;
+               if (level <= levels) break;
+               if (of_property_read_bool(np, "cache-size")) ++leaves;
+               if (of_property_read_bool(np, "i-cache-size")) ++leaves;
+               if (of_property_read_bool(np, "d-cache-size")) ++leaves;
+               levels = level;
+       }
+
+       this_cpu_ci->num_levels = levels;
+       this_cpu_ci->num_leaves = leaves;
+       return 0;
+}
+

arch/riscv/kernel/cacheinfo.c line 66

Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10 -0
+static int __populate_cache_leaves(unsigned int cpu)
+{
+       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
+       struct cacheinfo *this_leaf = this_cpu_ci->info_list;
+       struct device_node *np = of_cpu_device_node_get(cpu);
+       int levels = 1, level = 1;
+
+       if (of_property_read_bool(np, "cache-size"))   ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
+       if (of_property_read_bool(np, "i-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
+       if (of_property_read_bool(np, "d-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);

Please run checkpatch, kernel coding style doesn't use one-line ifs (here nor elsewhere).

Quoted 43 lines
arch/riscv/kernel/cacheinfo.c new file +16 -0
+
+       while ((np = of_find_next_cache_node(np))) {
+               if (!of_device_is_compatible(np, "cache")) break;
+               if (of_property_read_u32(np, "cache-level", &level)) break;
+               if (level <= levels) break;
+               if (of_property_read_bool(np, "cache-size"))   ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
+               if (of_property_read_bool(np, "i-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
+               if (of_property_read_bool(np, "d-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
+               levels = level;
+       }
+
+       return 0;
+}
+
+DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level)
+DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves)
arch/riscv/kernel/cpu.c new file +21 -0
new file mode 100644
index 000000000000..9cbf53eb58be
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/init.h>
+#include <linux/seq_file.h>
+#include <linux/of.h>
+
+/* Return -1 if not a valid hart */
+int riscv_of_processor_hart(struct device_node *node)
+{

arch/riscv/kernel/cpu.c line 31

Quoted 10 lines
arch/riscv/kernel/cpu.c new file +10 -0
+       const char *isa, *status;
+       u32 hart;
+
+       if (!of_device_is_compatible(node, "riscv")) return -1;
+       if (of_property_read_u32(node, "reg", &hart) || hart >= NR_CPUS) return -1;
+       if (of_property_read_string(node, "status", &status) || strcmp(status, "okay")) return -1;
+       if (of_property_read_string(node, "riscv,isa", &isa) || isa[0] != 'r' || isa[1] != 'v') return -1;
+
+       return hart;
+}

We usually prefer to see real -E<foo> returns instead of -1 in the kernel.

[...]

Quoted 207 lines
arch/riscv/kernel/head.S new file +139 -0
new file mode 100644
index 000000000000..52d574206d76
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <asm/thread_info.h>
+#include <asm/asm-offsets.h>
+#include <asm/asm.h>
+#include <linux/init.h>
+#include <linux/linkage.h>
+#include <asm/thread_info.h>
+#include <asm/page.h>
+#include <asm/csr.h>
+
+__INIT
+ENTRY(_start)
+       /* Mask all interrupts */
+       csrw sie, zero
+
+       /* Disable FPU to detect illegal usage of
+          floating point in kernel space */
+       li t0, SR_FS
+       csrc sstatus, t0
+
+#ifndef CONFIG_RV_PUM
+       /* Allow access to user memory */
+       li t0, SR_SUM
+       csrs sstatus, t0
+#endif
+
+       /* Pick one hart to run the main boot sequence */
+       la a3, hart_lottery
+       li a2, 1
+       amoadd.w a3, a2, (a3)
+       bnez a3, .Lsecondary_start
+
+       /* Save hart ID and DTB physical address */
+       mv s0, a0
+       mv s1, a1
+
+       /* Initialize page tables and relocate to virtual addresses */
+       la sp, init_thread_union + THREAD_SIZE
+       call setup_vm
+       call relocate
+
+       /* Restore C environment */
+       la tp, init_thread_union
+       li sp, THREAD_SIZE
+       add sp, sp, tp
+
+       /* Start the kernel */
+       mv a0, s0
+       mv a1, s1
+       call sbi_save
+       tail start_kernel
+
+relocate:
+       /* Relocate return address */
+       li a1, PAGE_OFFSET
+       la a0, _start
+       sub a1, a1, a0
+       add ra, ra, a1
+
+       /* Point stvec to virtual address of intruction after sptbr write */
+       la a0, 1f
+       add a0, a0, a1
+       csrw stvec, a0
+
+       /* Compute sptbr for kernel page tables, but don't load it yet */
+       la a2, swapper_pg_dir
+       srl a2, a2, PAGE_SHIFT
+       li a1, SPTBR_MODE
+       or a2, a2, a1
+
+       /* Load trampoline page directory, which will cause us to trap to
+          stvec if VA != PA, or simply fall through if VA == PA */
+       la a0, trampoline_pg_dir
+       srl a0, a0, PAGE_SHIFT
+       or a0, a0, a1
+       sfence.vma
+       csrw sptbr, a0
+1:
+       /* Set trap vector to spin forever to help debug */
+       la a0, .Lsecondary_park
+       csrw stvec, a0
+
+       /* Load the global pointer */
+       la gp, __global_pointer$
+
+       /* Switch to kernel page tables */
+       csrw sptbr, a2
+
+       ret
+
+.Lsecondary_start:
+#ifdef CONFIG_SMP
+       li a1, CONFIG_NR_CPUS
+       bgeu a0, a1, .Lsecondary_park
+
+       la a1, __cpu_up_stack_pointer
+       slli a0, a0, LGREG
+       add a0, a0, a1
+
+.Lwait_for_cpu_up:
+       REG_L sp, (a0)
+       beqz sp, .Lwait_for_cpu_up
+       fence
+
+       /* Enable virtual memory and relocate to virtual address */
+       call relocate
+
+       /* Initialize task_struct pointer */
+       li tp, -THREAD_SIZE
+       add tp, tp, sp
+
+       tail smp_callin
+#endif
+
+.Lsecondary_park:
+       /* We lack SMP support or have too many harts, so park this hart */
+       wfi
+       j .Lsecondary_park
+END(_start)
+
+__PAGE_ALIGNED_BSS
+       /* Empty zero page */
+       .balign PAGE_SIZE
+ENTRY(empty_zero_page)
+       .fill (empty_zero_page + PAGE_SIZE) - ., 1, 0x00
+END(empty_zero_page)
arch/riscv/kernel/irq.c new file +56 -0
new file mode 100644
index 000000000000..b772bb9539cf
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/interrupt.h>
+#include <linux/ftrace.h>
+#include <linux/of.h>
+#include <linux/seq_file.h>
+
+#include <asm/ptrace.h>
+#include <asm/sbi.h>
+#include <asm/smp.h>
+
+struct riscv_irq_data {
+       struct irq_chip         chip;
+       struct irq_domain       *domain;
+       int                     hart;
+       char                    name[20];
+};
+DEFINE_PER_CPU(struct riscv_irq_data, riscv_irq_data);
+DEFINE_PER_CPU(atomic_long_t, riscv_early_sie);
+
+static void riscv_software_interrupt(void)
+{
+#ifdef CONFIG_SMP
+       irqreturn_t ret;
+
+       ret = handle_ipi();
+       if (ret != IRQ_NONE)
+               return;
+#endif
+
+       BUG();
+}
+
+asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
+{
+       struct pt_regs *old_regs = set_irq_regs(regs);
+       irq_enter();
+
+       /* There are three classes of interrupt: timer, software, and
+          external devices.  We dispatch between them here.  External

arch/riscv/kernel/irq.c line 66

Quoted 10 lines
arch/riscv/kernel/irq.c new file +10 -0
+          device interrupts use the generic IRQ mechanisms. */
+       switch (cause) {
+               case INTERRUPT_CAUSE_TIMER:
+                       riscv_timer_interrupt();
+                       break;
+               case INTERRUPT_CAUSE_SOFTWARE:
+                       riscv_software_interrupt();
+                       break;
+               default: {
+                       struct irq_domain *domain = per_cpu(riscv_irq_data, smp_processor_id()).domain;

Move this up to top of function and remove the { } wrap, please.

Quoted 38 lines
arch/riscv/kernel/irq.c new file +38 -0
+                       generic_handle_irq(irq_find_mapping(domain, cause));
+                       break;
+               }
+       }
+
+       irq_exit();
+       set_irq_regs(old_regs);
+}
+
+static int riscv_irqdomain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq)
+{
+       struct riscv_irq_data *data = d->host_data;
+
+        irq_set_chip_and_handler(irq, &data->chip, handle_simple_irq);
+        irq_set_chip_data(irq, data);
+        irq_set_noprobe(irq);
+
+        return 0;
+}
+
+static const struct irq_domain_ops riscv_irqdomain_ops = {
+       .map    = riscv_irqdomain_map,
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static void riscv_irq_mask(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+       BUG_ON(smp_processor_id() != data->hart);
+       csr_clear(sie, 1 << (long)d->hwirq);
+}
+
+static void riscv_irq_unmask(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+       BUG_ON(smp_processor_id() != data->hart);
+       csr_set(sie, 1 << (long)d->hwirq);
+}

arch/riscv/kernel/irq.c line 114

Quoted 10 lines
arch/riscv/kernel/irq.c new file +10 -0
+
+static void riscv_irq_enable_helper(void *d)
+{
+       riscv_irq_unmask(d);
+}
+
+static void riscv_irq_enable(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+       atomic_long_or((1 << (long)d->hwirq), &per_cpu(riscv_early_sie, data->hart));

This is a bit dense to get into without a few words of how it's expected to work.

Quoted 54 lines
arch/riscv/kernel/irq.c new file +54 -0
+       if (data->hart == smp_processor_id()) {
+               riscv_irq_unmask(d);
+       } else if (cpu_online(data->hart)) {
+               smp_call_function_single(data->hart, riscv_irq_enable_helper, d, true);
+       }
+}
+
+static void riscv_irq_disable_helper(void *d)
+{
+       riscv_irq_mask(d);
+}
+
+static void riscv_irq_disable(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+       atomic_long_and(~(1 << (long)d->hwirq), &per_cpu(riscv_early_sie, data->hart));
+       if (data->hart == smp_processor_id()) {
+               riscv_irq_mask(d);
+       } else if (cpu_online(data->hart)) {
+               smp_call_function_single(data->hart, riscv_irq_disable_helper, d, true);
+       }
+}
+
+static void riscv_irq_mask_noop(struct irq_data *d) { }
+
+static void riscv_irq_unmask_noop(struct irq_data *d) { }
+
+static void riscv_irq_enable_noop(struct irq_data *d)
+{
+       struct device_node *data = irq_data_get_irq_chip_data(d);
+       u32 hart;
+
+       if (!of_property_read_u32(data, "reg", &hart)) {
+               printk("WARNING: enabled interrupt %d for missing hart %d (this interrupt has no handler)\n", (int)d->hwirq, hart);
+       }
+}
+
+static struct irq_chip riscv_noop_chip = {
+       .name = "riscv,cpu-intc,noop",
+       .irq_mask = riscv_irq_mask_noop,
+       .irq_unmask = riscv_irq_unmask_noop,
+       .irq_enable = riscv_irq_enable_noop,
+};
+
+static int riscv_irqdomain_map_noop(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq)
+{
+       struct device_node *data = d->host_data;
+       irq_set_chip_and_handler(irq, &riscv_noop_chip, handle_simple_irq);
+       irq_set_chip_data(irq, data);
+       return 0;
+}
+
+static const struct irq_domain_ops riscv_irqdomain_ops_noop = {
+       .map    = riscv_irqdomain_map_noop,

arch/riscv/kernel/irq.c line 178

Quoted 10 lines
arch/riscv/kernel/irq.c new file +10 -0
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static int riscv_intc_init(struct device_node *node, struct device_node *parent)
+{
+       int hart;
+
+       if (parent) return 0; // should have no interrupt parent
+
+       if ((hart = riscv_of_processor_hart(node->parent)) >= 0) {

Common pattern in kernel is to detect error instead:

    hart = riscv_of_processor_hart(node->parent);
    if (hart < 0) {
        <from your else side here>
        return 0;
    }
    <body if your if statement here>

    return 0;
Quoted 34 lines
arch/riscv/kernel/irq.c new file +27 -0
+               struct riscv_irq_data *data = &per_cpu(riscv_irq_data, hart);
+               snprintf(data->name, sizeof(data->name), "riscv,cpu_intc,%d", hart);
+               data->hart = hart;
+               data->chip.name = data->name;
+               data->chip.irq_mask = riscv_irq_mask;
+               data->chip.irq_unmask = riscv_irq_unmask;
+               data->chip.irq_enable = riscv_irq_enable;
+               data->chip.irq_disable = riscv_irq_disable;
+               data->domain = irq_domain_add_linear(node, 8*sizeof(uintptr_t), &riscv_irqdomain_ops, data);
+               WARN_ON(!data->domain);
+               printk("%s: %d local interrupts mapped\n", data->name, 8*(int)sizeof(uintptr_t));
+       } else {
+               /* If a hart is disabled, create a no-op irq domain.
+                * Devices may still have interrupts connected to those harts.
+                * This is not wrong... unless they actually load a driver that needs it!
+                */
+               irq_domain_add_linear(node, 8*sizeof(uintptr_t), &riscv_irqdomain_ops_noop, node->parent);
+       }
+       return 0;
+}
+
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);
+
+void __init init_IRQ(void)
+{
+       irqchip_init();
+}
arch/riscv/kernel/pci.c new file +0 -0
new file mode 100644
index 000000000000..4191a5ffdd67

arch/riscv/kernel/pci.c line 2

Quoted 2 lines
arch/riscv/kernel/pci.c new file +2 -0
@@ -0,0 +1,36 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c

So, you should add recursive reference from there (i.e. powerpc).

But in the end, there's essentially no code in this file. :)

Quoted 57 lines
arch/riscv/kernel/pci.c new file +34 -0
+ *
+ * Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM
+ * Copyright (C) 2014 ARM Ltd.
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+
+/*
+ * Called after each bus is probed, but before its children are examined
+ */
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+       /* nothing to do, expected to be removed in the future */
+}
+
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here
+ */
+resource_size_t pcibios_align_resource(void *data, const struct resource *res,
+                               resource_size_t size, resource_size_t align)
+{
+       return res->start;
+}
arch/riscv/kernel/plic.c new file +17 -0
new file mode 100644
index 000000000000..5b3d4241f4e2
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irq.h>

arch/riscv/kernel/plic.c line 27

Quoted 10 lines
arch/riscv/kernel/plic.c new file +10 -0
+#include <linux/irqchip.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+
+#define MAX_DEVICES    1024 // 0 is reserved

Seems like an odd comment to have here (and should probably not go at the end of the line)

arch/riscv/kernel/plic.c line 38

Quoted 11 lines
arch/riscv/kernel/plic.c new file +11 -0
+#define MAX_CONTEXTS   15872
+
+#define PRIORITY_BASE  0
+#define ENABLE_BASE    0x2000
+#define ENABLE_SIZE    0x80
+#define HART_BASE      0x200000
+#define HART_SIZE      0x1000
+
+#define PLIC_HART_CONTEXT(data, i)     (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i)
+#define PLIC_ENABLE_CONTEXT(data, i)   (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i)
+#define PLIC_PRIORITY(data)            (struct plic_priority *)((char *)data->reg + PRIORITY_BASE)

Since you have typecasting and stuff here, small static inlines with appropriate return types seems slightly tidier.

Quoted 78 lines
arch/riscv/kernel/plic.c new file +78 -0
+
+struct plic_hart_context {
+       volatile u32 threshold;
+       volatile u32 claim;
+};
+
+struct plic_enable_context {
+       atomic_t mask[32]; // 32-bit * 32-entry
+};
+
+struct plic_priority {
+       volatile u32 prio[MAX_DEVICES];
+};
+
+struct plic_data {
+       struct irq_chip         chip;
+       struct irq_domain       *domain;
+       u32                     ndev;
+       void __iomem            *reg;
+       int                     handlers;
+       struct plic_handler     *handler;
+       char                    name[30];
+};
+
+struct plic_handler {
+       struct plic_hart_context        *context;
+       struct plic_data                *data;
+};
+
+static void plic_disable(struct plic_data *data, int i, int hwirq)
+{
+       struct plic_enable_context *enable = PLIC_ENABLE_CONTEXT(data, i);
+       atomic_and(~(1 << (hwirq % 32)), &enable->mask[hwirq / 32]);
+}
+
+static void plic_enable(struct plic_data *data, int i, int hwirq)
+{
+       struct plic_enable_context *enable = PLIC_ENABLE_CONTEXT(data, i);
+       atomic_or((1 << (hwirq % 32)), &enable->mask[hwirq / 32]);
+}
+
+// There is no need to mask/unmask PLIC interrupts
+// They are "masked" by reading claim and "unmasked" when writing it back.
+static void plic_irq_mask(struct irq_data *d) { }
+static void plic_irq_unmask(struct irq_data *d) { }
+
+static void plic_irq_enable(struct irq_data *d)
+{
+       struct plic_data *data = irq_data_get_irq_chip_data(d);
+       struct plic_priority *priority = PLIC_PRIORITY(data);
+       int i;
+       iowrite32(1, &priority->prio[d->hwirq]);
+       for (i = 0; i < data->handlers; ++i)
+               if (data->handler[i].context)
+                       plic_enable(data, i, d->hwirq);
+}
+
+static void plic_irq_disable(struct irq_data *d)
+{
+       struct plic_data *data = irq_data_get_irq_chip_data(d);
+       struct plic_priority *priority = PLIC_PRIORITY(data);
+       int i;
+       iowrite32(0, &priority->prio[d->hwirq]);
+       for (i = 0; i < data->handlers; ++i)
+               if (data->handler[i].context)
+                       plic_disable(data, i, d->hwirq);
+}
+
+static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq)
+{
+       struct plic_data *data = d->host_data;
+
+        irq_set_chip_and_handler(irq, &data->chip, handle_simple_irq);
+        irq_set_chip_data(irq, data);
+        irq_set_noprobe(irq);
+
+        return 0;
+}

arch/riscv/kernel/plic.c line 126

Quoted 10 lines
arch/riscv/kernel/plic.c new file +10 -0
+
+static const struct irq_domain_ops plic_irqdomain_ops = {
+       .map    = plic_irqdomain_map,
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static void plic_chained_handle_irq(struct irq_desc *desc)
+{
+        struct plic_handler *handler = irq_desc_get_handler_data(desc);
+       struct irq_chip *chip = irq_desc_get_chip(desc);

Whitespace.

Quoted 72 lines
arch/riscv/kernel/plic.c new file +72 -0
+       struct irq_domain *domain = handler->data->domain;
+       u32 what;
+
+       chained_irq_enter(chip, desc);
+
+       while ((what = ioread32(&handler->context->claim))) {
+               int irq = irq_find_mapping(domain, what);
+               if (irq > 0) {
+                       generic_handle_irq(irq);
+               } else {
+                       handle_bad_irq(desc);
+               }
+               iowrite32(what, &handler->context->claim);
+       }
+
+       chained_irq_exit(chip, desc);
+}
+
+// TODO: add a /sys interface to set priority + per-hart enables for steering
+
+static int plic_init(struct device_node *node, struct device_node *parent)
+{
+       struct plic_data *data;
+       struct resource resource;
+       int i, ok = 0;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (WARN_ON(!data)) return -ENOMEM;
+
+       data->reg = of_iomap(node, 0);
+       if (WARN_ON(!data->reg)) return -EIO;
+
+       of_property_read_u32(node, "riscv,ndev", &data->ndev);
+       if (WARN_ON(!data->ndev)) return -EINVAL;
+
+       data->handlers = of_irq_count(node);
+       if (WARN_ON(!data->handlers)) return -EINVAL;
+
+       data->handler = kzalloc(sizeof(*data->handler)*data->handlers, GFP_KERNEL);
+       if (WARN_ON(!data->handler)) return -ENOMEM;
+
+       data->domain = irq_domain_add_linear(node, data->ndev+1, &plic_irqdomain_ops, data);
+       if (WARN_ON(!data->domain)) return -ENOMEM;
+
+       of_address_to_resource(node, 0, &resource);
+       snprintf(data->name, sizeof(data->name), "riscv,plic0,%llx", resource.start);
+       data->chip.name = data->name;
+       data->chip.irq_mask = plic_irq_mask;
+       data->chip.irq_unmask = plic_irq_unmask;
+       data->chip.irq_enable = plic_irq_enable;
+       data->chip.irq_disable = plic_irq_disable;
+
+       for (i = 0; i < data->handlers; ++i) {
+               struct plic_handler *handler = &data->handler[i];
+               struct of_phandle_args parent;
+               int parent_irq, hwirq;
+
+               if (of_irq_parse_one(node, i, &parent)) continue;
+               if (parent.args[0] == -1) continue; // skip context holes
+
+               // skip any contexts that lead to inactive harts
+               if (of_device_is_compatible(parent.np, "riscv,cpu-intc") &&
+                   parent.np->parent &&
+                   riscv_of_processor_hart(parent.np->parent) < 0) continue;
+
+               parent_irq = irq_create_of_mapping(&parent);
+               if (!parent_irq) continue;
+
+               handler->context = PLIC_HART_CONTEXT(data, i);
+               handler->data = data;
+               iowrite32(0, &handler->context->threshold); // hwirq prio must be > this to trigger an interrupt
+               for (hwirq = 1; hwirq <= data->ndev; ++hwirq) plic_disable(data, i, hwirq);

arch/riscv/kernel/plic.c line 208

Quoted 10 lines
arch/riscv/kernel/plic.c new file +10 -0
+               irq_set_chained_handler_and_data(parent_irq, plic_chained_handle_irq, handler);
+               ++ok;
+       }
+
+       printk("%s: mapped %d interrupts to %d/%d handlers\n", data->name, data->ndev, ok, data->handlers);
+       WARN_ON(!ok);
+       return 0;
+}
+
+IRQCHIP_DECLARE(plic0, "riscv,plic0", plic_init);

[wrapping up review of this patch at this point to keep size down]

-Olof

reviewer
#71 lore raw
In reply to Palmer Dabbelt
Quoted 8 lines · Palmer Dabbelt

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

Now at patch 0004-riscv.patch
Warning: trailing whitespace in line 3 of arch/riscv/include/asm/asm.h
Warning: trailing whitespace in line 115 of arch/riscv/include/asm/spinlock.h

Now at patch 0006-riscv.patch
Warning: trailing whitespace in line 271 of arch/riscv/kernel/entry.S
Warning: trailing whitespace in line 77 of arch/riscv/kernel/process.c
Warning: trailing whitespace in line 78 of arch/riscv/kernel/smpboot.c

Signature · 1 line
~Randy
#63 lore raw

Re: [PATCH 7/7] RISC-V: arch/riscv/mm

In reply to Randy Dunlap
Quoted 13 lines · Randy Dunlap

arch/riscv/mm/fault.c line 4

Quoted 11 lines
arch/riscv/mm/fault.c new file +4 -0
new file mode 100644
index 000000000000..f02e286dd1c1
@@ -0,0 +1,279 @@
+/*
+ * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
+ *  Lennox Wu <[email protected]>
+ *  Chen Liqin <[email protected]>

is "sunplusct.com" correct? They don't have a web server?

Seems to come from arch/score/ contents. Looks like true genealogy is from MIPS though.

-Olof

author maintainer
#68 lore raw
In reply to Olof Johansson
Quoted 28 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:

Hi Palmer,

Quoted 11 lines · Palmer Dabbelt

We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.

This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.

Quoted 8 lines

These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.

Time is right for review and eventual merge of this. Whether it makes 4.13 depends on how much discussion ensues. :)

Quoted 1 line

Albert and I will volunteer to maintain this port if it's OK with everyone.

Quoted 7 lines

It always makes sense to have architecture-knowledge people maintain it; no complaints from me.

What we've seen been useful on other platforms (i.e. arm/arm64) is to offload the per-vendor stuff to a separate tree. It might or might not be needed here; likely to start out it won't be enough material to need it.

I'm OK with that. We've been using http://github.com/riscv to hold all our other "riscv-next" branches, but if you think another place is more appropriate then I'm OK with that as well.

Quoted 17 lines
Quoted 9 lines

We'd like to thank the various members of the RISC-V software community who have helped us with the port.

Thanks!

In addition to the threaded messages, our port can be found on Git Hib

https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1

Quoted 7 lines

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

Quoted 8 lines

So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add Makefile contents that refers to directories not yet introduced).

While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.

I only really split things up so they'll get through the various mailing lists, I think of this as one logical commit so I didn't really worry about ordering. I'll swizzle them around next time so everything always builds.

Quoted 5 lines

Also, none of the patches seem to have any descriptions. Adding some high-level descriptions of what's in each patch in the patch itself is useful both for reviewing now, and for educating anyone coming along later on trying to learn about the code and why it's been implemented as it has.

I guess I just wasn't really sure what to say in the big code dumps. I'll look through and try to come up with something better for next time.

Quoted 6 lines

I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.

OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.

Thanks!

author maintainer
#67 lore raw
In reply to Randy Dunlap
Quoted 21 lines · On Mon, 22 May 2017 18:25:41 PDT (-0700), [email protected] wrote:
Quoted 20 lines · Olof Johansson

Hi Palmer,

Quoted 11 lines · Palmer Dabbelt

In addition to the threaded messages, our port can be found on Git Hib

https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add Makefile contents that refers to directories not yet introduced).

Quoted 7 lines
Quoted 4 lines

While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.

Neither the email patches nor the git tree have any Signed-off-by:
entries AFAICT.

Makes sense. I went through and checked everything for copyright, so I'll sign off on the next patch set.

Thanks!

author maintainer
#64 lore raw

Re: [PATCH 7/7] RISC-V: arch/riscv/mm

In reply to Olof Johansson
Quoted 15 lines · On Mon, 22 May 2017 19:17:52 PDT (-0700), [email protected] wrote:
Quoted 13 lines · Randy Dunlap

arch/riscv/mm/fault.c line 4

Quoted 11 lines
arch/riscv/mm/fault.c new file +4 -0
new file mode 100644
index 000000000000..f02e286dd1c1
@@ -0,0 +1,279 @@
+/*
+ * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
+ *  Lennox Wu <[email protected]>
+ *  Chen Liqin <[email protected]>

is "sunplusct.com" correct? They don't have a web server?

Quoted 2 lines

Seems to come from arch/score/ contents. Looks like true genealogy is from MIPS though.

Albert based the original port on score, so I copied their license header files and appended to them.

author maintainer
#12 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Olof Johansson
Quoted 21 lines · On Mon, 22 May 2017 18:27:21 PDT (-0700), [email protected] wrote:

Hi,

Quoted 8 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
Quoted 8 lines
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
Quoted 8 lines

Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.

Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.

Works for me <https://github.com/riscv/riscv-linux/commit/b1165397ba6cb54f23910537c4bf4c3488ef9aad>

I'll squash all the CR comments into a v2.

Quoted 32 lines
Quoted 32 lines
arch/riscv/.gitignore new file +24 -0
new file mode 100644
index 000000000000..376d06eb5d52
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a
+*.s
+*.ko
+*.so
+*.so.dbg
+*.mod.c
+*.i
+*.lst
+*.symtypes
+*.order
+modules.builtin
+*.elf
+*.bin
+*.gz
+*.bz2
Quoted 8 lines

arch/riscv/.gitignore line 29

Quoted 5 lines
arch/riscv/.gitignore new file +5 -0
+*.lzma
+*.xz
+*.lzo
+*.patch
+*.gcno

I don't think you need to do any of this, just inherit the global one (by not having one here)?

Sorry, that's a holdover from how we used to manage our out-of-tree port and can just be deleted.

https://github.com/riscv/riscv-linux/commit/68032fb592297331a2f2caf246968da7b70373fe

Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig new file +1 -0
new file mode 100644
index 000000000000..510ead1d3343
+config CPU_RV_GENERIC
Quoted 8 lines

arch/riscv/Kconfig line 109

Quoted 3 lines
arch/riscv/Kconfig new file +3 -0
+       bool "Generic RISC-V"
+       select CPU_SUPPORTS_32BIT_KERNEL
+       select CPU_SUPPORTS_64BIT_KERNEL

Is this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (CPU_RV_GENERIC that is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_bool y' for now.

I think this is actually broken in the opposite direction: we only support 32-bit kernels on RV32 and 64-bit kernels on RV64, not both at the same time. I don't really think it makes sense to build a kernel that supports both 32-bit and 64-bit on RISC-V (as they're different base ISAs), so I think it'd be better to just have a "base ISA" configuration.

https://github.com/riscv/riscv-linux/commit/695d428d65bf6fe1382d34393e9d07f40b74e1b2

We'll think on this a bit more and get something saner.

Quoted 10 lines

arch/riscv/Kconfig line 132

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config SBI_CONSOLE
+       tristate "SBI console support"
+       select TTY
+       default y

Usually you end up having a DRIVER_FOO and DRIVER_FOO_CONSOLE option to enable registering it as console.

Also, unless there's strong reason to keep it under arch/, it should probably go under drivers/tty/.

In this case "SBI" is the "Supervisor Binary Interface". This is a set of routines that are provided by the platform for OS use that do things like writing to the boot console or TLB shootdowns. The SBI is part of the RISC-V ISA, so there isn't a config option for turning it off. SBI_CONSOLE enables/disables the SBI's console support, so I think this option is sane.

It's in arch/riscv because the SBI is part of the RISC-V ISA -- essentially there's special SBI instructions that mean "write some register to the console" (there's some implementation tricks behind this, so it's really just a specification). That said, I'm fine moving this to drivers.

Quoted 4 lines

arch/riscv/Kconfig line 136

Quoted 3 lines
arch/riscv/Kconfig new file +3 -0
+config RVC
+       bool "Use compressed instructions (RV32C or RV64C)"
+       default n
Quoted 8 lines

What does "use" here mean? Use during build, or allow userspace to use them?

arch/riscv/Kconfig line 140

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y

Same for this.

These mean "tell the compiler that it can emit these instructions when building Linux". Userspace applications can still use these instructions either way. How does "Emit compressed instructions when building Linux" sound?

https://github.com/riscv/riscv-linux/commit/d6e65bd8b7dcfa72578d62e5eb367f680b55f5a8

Quoted 14 lines

arch/riscv/Kconfig line 152

Quoted 12 lines
arch/riscv/Kconfig new file +11 -0
+config RV_SYSRISCV_ATOMIC
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

If it's mandatory then Kconfig language should make it so.

I'm not sure what you mean by this. We have

config RISCV
...
select RV_SYSRISCV_ATOMIC if !RV_ATOMIC

Should this constraint just live within "config RV_SYSRISCV_ATOMIC"? It seems cleaner to have the constraints next to the config definitions.

Thanks!

author maintainer
#72 lore raw
In reply to Randy Dunlap
Quoted 11 lines · On Mon, 22 May 2017 19:16:43 PDT (-0700), [email protected] wrote:
Quoted 8 lines · Palmer Dabbelt

[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm

Quoted 8 lines

Now at patch 0004-riscv.patch
Warning: trailing whitespace in line 3 of arch/riscv/include/asm/asm.h
Warning: trailing whitespace in line 115 of arch/riscv/include/asm/spinlock.h

Now at patch 0006-riscv.patch
Warning: trailing whitespace in line 271 of arch/riscv/kernel/entry.S
Warning: trailing whitespace in line 77 of arch/riscv/kernel/process.c
Warning: trailing whitespace in line 78 of arch/riscv/kernel/smpboot.c

Sorry about that, I'll fix these for v2.

author maintainer
#11 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Randy Dunlap
Quoted 28 lines · On Mon, 22 May 2017 18:31:08 PDT (-0700), [email protected] wrote:
Quoted 27 lines · Olof Johansson

Hi,

Quoted 8 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
Quoted 8 lines
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike

Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.

Quoted 8 lines
Quoted 2 lines

Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.

well, the top-level Makefile looks for "make *config" to indicate that there is a config-command in progress (or in process), so they usually have to end in the string "config".

Have these been tested?

Ah, that's much better -- I've just been copying them to .config :). I've already renamed them to things that end in defconfig.

Thanks!

#13 lore raw

Re: [patches] Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt
Quoted 102 lines · Palmer Dabbelt
Quoted 21 lines · On Mon, 22 May 2017 18:27:21 PDT (-0700), [email protected] wrote:

Hi,

Quoted 8 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
Quoted 8 lines
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
Quoted 8 lines

Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.

Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.

Works for me <https://github.com/riscv/riscv-linux/commit/b1165397ba6cb54f23910537c4bf4c3488ef9aad>

I'll squash all the CR comments into a v2.

Quoted 32 lines
Quoted 32 lines
arch/riscv/.gitignore new file +24 -0
new file mode 100644
index 000000000000..376d06eb5d52
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a
+*.s
+*.ko
+*.so
+*.so.dbg
+*.mod.c
+*.i
+*.lst
+*.symtypes
+*.order
+modules.builtin
+*.elf
+*.bin
+*.gz
+*.bz2
Quoted 8 lines

arch/riscv/.gitignore line 29

Quoted 5 lines
arch/riscv/.gitignore new file +5 -0
+*.lzma
+*.xz
+*.lzo
+*.patch
+*.gcno

I don't think you need to do any of this, just inherit the global one (by not having one here)?

Sorry, that's a holdover from how we used to manage our out-of-tree port and can just be deleted.

https://github.com/riscv/riscv-linux/commit/68032fb592297331a2f2caf246968da7b70373fe

Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig new file +1 -0
new file mode 100644
index 000000000000..510ead1d3343
+config CPU_RV_GENERIC
Quoted 8 lines

arch/riscv/Kconfig line 109

Quoted 3 lines
arch/riscv/Kconfig new file +3 -0
+       bool "Generic RISC-V"
+       select CPU_SUPPORTS_32BIT_KERNEL
+       select CPU_SUPPORTS_64BIT_KERNEL

Is this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (CPU_RV_GENERIC that is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_bool y' for now.

I think this is actually broken in the opposite direction: we only support 32-bit kernels on RV32 and 64-bit kernels on RV64, not both at the same time. I don't really think it makes sense to build a kernel that supports both 32-bit and 64-bit on RISC-V (as they're different base ISAs), so I think it'd be better to just have a "base ISA" configuration.

Quoted 3 lines

https://github.com/riscv/riscv-linux/commit/695d428d65bf6fe1382d34393e9d07f40b74e1b2

We'll think on this a bit more and get something saner.

Sure, sounds good overall though.

Quoted 17 lines
Quoted 10 lines

arch/riscv/Kconfig line 132

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config SBI_CONSOLE
+       tristate "SBI console support"
+       select TTY
+       default y

Usually you end up having a DRIVER_FOO and DRIVER_FOO_CONSOLE option to enable registering it as console.

Also, unless there's strong reason to keep it under arch/, it should probably go under drivers/tty/.

In this case "SBI" is the "Supervisor Binary Interface". This is a set of routines that are provided by the platform for OS use that do things like writing to the boot console or TLB shootdowns. The SBI is part of the RISC-V ISA, so there isn't a config option for turning it off. SBI_CONSOLE enables/disables the SBI's console support, so I think this option is sane.

Quoted 4 lines

It's in arch/riscv because the SBI is part of the RISC-V ISA -- essentially there's special SBI instructions that mean "write some register to the console" (there's some implementation tricks behind this, so it's really just a specification). That said, I'm fine moving this to drivers.

The same is true for some other drivers. Actually, I wonder if it might be just as easy to implement a sbi backend for hvc -- see hvc_udbg.c for an example where, on power, you have a simple get/put char hypervisor call in a very similar manner.

Either way (keeping discrete sbi driver or implementing hvc backend), moving to drivers/tty is the right thing here -- we've worked hard on ARM to get rid of random drivers under arch/ and it'd be nice to not see new ones intoduced here.

Quoted 14 lines
Quoted 5 lines

arch/riscv/Kconfig line 136

Quoted 4 lines
arch/riscv/Kconfig new file +3 -0
+config RVC
+       bool "Use compressed instructions (RV32C or RV64C)"
+       default n
Quoted 8 lines

What does "use" here mean? Use during build, or allow userspace to use them?

arch/riscv/Kconfig line 140

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y

Same for this.

Quoted 5 lines

These mean "tell the compiler that it can emit these instructions when building Linux". Userspace applications can still use these instructions either way. How does "Emit compressed instructions when building Linux" sound?

https://github.com/riscv/riscv-linux/commit/d6e65bd8b7dcfa72578d62e5eb367f680b55f5a8

Sounds good, you can still reference the ISA extensions if you want though.

Quoted 15 lines
Quoted 14 lines

arch/riscv/Kconfig line 152

Quoted 12 lines
arch/riscv/Kconfig new file +11 -0
+config RV_SYSRISCV_ATOMIC
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

If it's mandatory then Kconfig language should make it so.

Quoted 8 lines

I'm not sure what you mean by this. We have

config RISCV
...
select RV_SYSRISCV_ATOMIC if !RV_ATOMIC

Should this constraint just live within "config RV_SYSRISCV_ATOMIC"? It seems cleaner to have the constraints next to the config definitions.

Ah, I just missed the select.

-Olof

#15 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt

(new top-level subthread here since this is a separate topic):

Quoted 52 lines · Palmer Dabbelt
arch/riscv/Makefile new file +46 -0
new file mode 100644
index 000000000000..07ef200e0675
@@ -0,0 +1,64 @@
+# This file is included by the global makefile so that you can add your own
+# architecture-specific flags and dependencies. Remember to do have actions
+# for "archclean" and "archdep" for cleaning up and making dependencies for
+# this architecture
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+
+LDFLAGS         :=
+OBJCOPYFLAGS    := -O binary
+LDFLAGS_vmlinux :=
+KBUILD_AFLAGS_MODULE += -fPIC
+KBUILD_CFLAGS_MODULE += -fPIC
+
+ifeq ($(ARCH),riscv)
+       KBUILD_DEFCONFIG = riscv64_spike
+else
+       KBUILD_DEFCONFIG = $(ARCH)_spike
+endif
+
+export BITS
+ifeq ($(CONFIG_64BIT),y)
+       BITS := 64
+       UTS_MACHINE := riscv64
+
+       KBUILD_CFLAGS += -mabi=lp64
+       KBUILD_AFLAGS += -mabi=lp64
+       KBUILD_MARCH = rv64im
+       LDFLAGS += -melf64lriscv
+else
+       BITS := 32
+       UTS_MACHINE := riscv32
+
+       KBUILD_CFLAGS += -mabi=ilp32
+       KBUILD_AFLAGS += -mabi=ilp32
+       KBUILD_MARCH = rv32im
+       LDFLAGS += -melf32lriscv
+endif
+
+ifeq ($(CONFIG_RV_ATOMIC),y)
+       KBUILD_RV_ATOMIC = a
+endif
+
+KBUILD_CFLAGS += -Wall

arch/riscv/Makefile line 56

Quoted 10 lines
arch/riscv/Makefile new file +10 -0
+
+ifeq ($(CONFIG_RVC),y)
+       KBUILD_RVC = c
+endif
+
+KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC)
+
+KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC)
+KBUILD_CFLAGS += -mno-save-restore
+KBUILD_CFLAGS += -mstrict-align

I built a vanilla gcc-7.1.0 here, with 'riscv64-linux' as target, and I get:

riscv64-linux-gcc: error: unrecognized command line option '-mstrict-align'; did you mean '-Wstrict-aliasing'?

The suggestion seems completely bogus, but the error is real. Looking at the gcc sources, I only see strict-align plumbed up on rs6000, aarch64, m68k(!) and v850. Or am I missing something here?

-Olof

#69 lore raw
In reply to Palmer Dabbelt

Hi Palmer,

Quoted 21 lines · Palmer Dabbelt
Quoted 20 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:
Quoted 19 lines · Palmer Dabbelt

We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.

This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.

These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.

[...]

Quoted 8 lines
Quoted 5 lines

I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.

OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.

You might want to Cc [email protected] on future iterations of this patchset where there's less "noise" than on LKML and the relevant people are more likely to notice ;) Likewise, the device-tree specific bits (e.g. the bindings documentation) should probably be Cc'ed to [email protected]

Tobias

#38 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt

Hi Palmer,

Quoted 2 lines · Palmer Dabbelt
 arch/riscv/lib/Makefile  |   5 ++
 arch/riscv/lib/ashldi3.c |  42 ++++++++++++++++

At least this one has already two identical copies in arch/score/lib/ashldi3.c and arch/sh/lib/ashldi3.c. Probably these should be moved to lib/, and built depending on a new config symbol that is selected on score, sh, and riscv.

Didn't check the others.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#17 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt

Hi Palmer,

Quoted 5 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +1 -0
@@ -0,0 +1,300 @@
 
+config PLIC

arch/riscv/Kconfig line 123

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Platform-Level Interrupt Controller"
+       default y
+       help
+          This enables support for the PLIC chip found in standard RISC-V
+          systems. The PLIC is the top-most interrupt controller found in
+          the system, connected directly to the core complex. All other
+          interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+          If you don't know what to do here, say Y.
+

I think this symbol belongs in drivers/irqchip/Kconfig, and the corresponding driver in drivers/irqchip/.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer
#40 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt
Quoted 19 lines · Palmer Dabbelt
arch/riscv/lib/Makefile new file +13 -0
new file mode 100644
index 000000000000..f644e582f4b8
 
+
+void __delay(unsigned long cycles)
+{
+       u64 t0 = get_cycles();
+
+       while ((unsigned long)(get_cycles() - t0) < cycles)
+               cpu_relax();
+}
+
+void udelay(unsigned long usecs)
+{
+       u64 ucycles = (u64)usecs * timebase;
+       do_div(ucycles, 1000000U);

arch/riscv/lib/Makefile

Quoted 10 lines
arch/riscv/lib/Makefile new file +10 -0
+       __delay((unsigned long)ucycles);
+}
+EXPORT_SYMBOL(udelay);
+
+void ndelay(unsigned long nsecs)
+{
+       u64 ncycles = (u64)nsecs * timebase;
+       do_div(ncycles, 1000000000U);
+       __delay((unsigned long)ncycles);
+}

I'd be slightly worried about a global 'timebase' identifier that might conflict with a variable in some random driver.

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Arnd

maintainer
#2 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Palmer Dabbelt
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

Arnd

maintainer
#19 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt
Quoted 23 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
arch/riscv/.gitignore new file +0 -0
new file mode 100644
index 000000000000..376d06eb5d52

arch/riscv/.gitignore line 10

Quoted 10 lines
arch/riscv/.gitignore new file +10 -0
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
+.*
+*.o
+*.o.*
+*.a

This doesn't seem to belong here: There is no reason for riscv to be different from all other architectures. Is something wrong with the top-level .gitignore? If so, we should just fix it there.

Quoted 14 lines
arch/riscv/Kconfig new file +8 -0
new file mode 100644
index 000000000000..510ead1d3343
@@ -0,0 +1,300 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+       def_bool y
+       select OF

arch/riscv/Kconfig line 18

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       select OF_EARLY_FLATTREE
+       select OF_IRQ
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_WANT_FRAME_POINTERS
+       select CLONE_BACKWARDS
+       select COMMON_CLK
+       select GENERIC_CLOCKEVENTS
+       select GENERIC_CPU_DEVICES
+       select GENERIC_IRQ_SHOW
+       select GENERIC_PCI_IOMAP

You normally don't want GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()

arch/riscv/Kconfig line 20

Quoted 2 lines
arch/riscv/Kconfig new file +2 -0
+config MMU
+       def_bool y

Just a general question: has there been any interest in a no-MMU version?

arch/riscv/Kconfig line 45

Quoted 6 lines
arch/riscv/Kconfig new file +6 -0
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+       def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+       def_bool y

Are you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit dma_addr_t and phys_addr_t when possible makes some code noticeably more efficient.

arch/riscv/Kconfig line 73

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config PGTABLE_LEVELS
+       int
+       default 3 if 64BIT
+       default 2

With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.

Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y
+
+config RV_SYSRISCV_ATOMIC

arch/riscv/Kconfig line 152

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

Just express this in Kconfig terms to prevent misconfiguration:

config RV_SYSRISCV_ATOMIC
bool "Include support for atomic operation syscalls" if RV_ATOMIC default !RV_ATOMIC

I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:

That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.

arch/riscv/Kconfig line 211

Quoted 8 lines
arch/riscv/Kconfig new file +8 -0
+config PCI_DOMAINS
+       def_bool PCI
+
+config PCI_DOMAINS_GENERIC
+       def_bool PCI
+
+config PCI_SYSCALL
+       def_bool PCI

I don't think you want PCI_SYSCALL

Arnd

maintainer
#26 lore raw

Re: [PATCH 3/7] RISC-V: Device Tree Documentation

In reply to Palmer Dabbelt
Quoted 3 lines · Palmer Dabbelt
---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++

The patch needs a description, and should be sent to the irqchip maintainers and the devicetree maintainers for review, along for the respective drivers/irqchip/
patch.

Arnd

maintainer
#29 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Palmer Dabbelt
Quoted 11 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +11 -0
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+static inline int atomic_read(const atomic_t *v)
+{
+       return *((volatile int *)(&(v->counter)));
+}
+/**

arch/riscv/include/asm/atomic.h line 42

Quoted 10 lines
arch/riscv/include/asm/atomic.h new file +10 -0
+ * atomic_set - set atomic variable
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.
+ */
+static inline void atomic_set(atomic_t *v, int i)
+{
+       v->counter = i;
+}

These commonly use READ_ONCE() and WRITE_ONCE, I'd recommend doing the same here to be on the safe side.

Quoted 12 lines
arch/riscv/include/asm/atomic64.h new file +12 -0
+/**
+ * atomic64_read - read atomic64 variable
+ * @v: pointer of type atomic64_t
+ *
+ * Atomically reads the value of @v.
+ */
+static inline s64 atomic64_read(const atomic64_t *v)
+{
+       return *((volatile long *)(&(v->counter)));
+}
+
+/**

arch/riscv/include/asm/atomic64.h line 43

Quoted 10 lines
arch/riscv/include/asm/atomic64.h new file +10 -0
+ * atomic64_set - set atomic64 variable
+ * @v: pointer to type atomic64_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.
+ */
+static inline void atomic64_set(atomic64_t *v, s64 i)
+{
+       v->counter = i;
+}

same here

arch/riscv/include/asm/bug.h line 25

Quoted 13 lines
arch/riscv/include/asm/bug.h new file +5 -0
new file mode 100644
index 000000000000..10d894ac3137
@@ -0,0 +1,81 @@
+/*
 
+#ifndef _ASM_RISCV_BUG_H
+#define _ASM_RISCV_BUG_H
 
+#ifdef CONFIG_GENERIC_BUG
+#define __BUG_INSN     _AC(0x00100073, UL) /* sbreak */

Please have a look at the modifications I did for !CONFIG_BUG on x86, arm and arm64. It's generally better to define BUG to a trap even when CONFIG_BUG is disabled, otherwise you run into undefined behavior in some code, and gcc will print annoying warnings about that.

arch/riscv/include/asm/bug.h

Quoted 6 lines
arch/riscv/include/asm/bug.h new file +6 -0
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT         6
+
+#define L1_CACHE_BYTES         (1 << L1_CACHE_SHIFT)

Is this the only valid cache line size on riscv, or just the largest one that is allowed?

arch/riscv/include/asm/bug.h

Quoted 10 lines
arch/riscv/include/asm/bug.h new file +10 -0
+
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+       return (dma_addr_t)paddr;
+}
+
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+{
+       return (phys_addr_t)dev_addr;
+}

What do you need these for? If possible, try to remove them.

arch/riscv/include/asm/bug.h

Quoted 9 lines
arch/riscv/include/asm/bug.h new file +9 -0
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir)
+{
+       /*
+        * RISC-V is cache-coherent, so this is mostly a no-op.
+        * However, we do need to ensure that dma_cache_sync()
+        * enforces order, hence the mb().
+        */
+       mb();
+}

Do you even support any drivers that use
dma_alloc_noncoherent()/dma_cache_sync()?

I would guess you can just leave this out.

arch/riscv/include/asm/io.h line 18

Quoted 11 lines
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

arch/riscv/include/asm/io.h line 28

Quoted 9 lines
arch/riscv/include/asm/io.h new file +9 -0
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MMU
+
+extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
+
+#define ioremap_nocache(addr, size) ioremap((addr), (size))
+#define ioremap_wc(addr, size) ioremap((addr), (size))
+#define ioremap_wt(addr, size) ioremap((addr), (size))

Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and ioremap_wc() gets used for by memremap() for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags

Quoted 18 lines
arch/riscv/include/asm/serial.h new file +12 -0
new file mode 100644
index 000000000000..d783dbe80a4b
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.

arch/riscv/include/asm/serial.h line 22

Quoted 10 lines
arch/riscv/include/asm/serial.h new file +10 -0
+ */
+
+#ifndef _ASM_RISCV_SERIAL_H
+#define _ASM_RISCV_SERIAL_H
+
+/*
+ * FIXME: interim serial support for riscv-qemu
+ *
+ * Currently requires that the emulator itself create a hole at addresses
+ * 0x3f8 - 0x3ff without looking through page tables.

This sounds like something we want to fix in qemu and not have in the mainline kernel. In particular, something seems really wrong if your inb()/outb() get remapped to physical CPU address 0+offset.

Quoted 16 lines
arch/riscv/include/asm/setup.h new file +10 -0
new file mode 100644
index 000000000000..e457854e9988
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or

arch/riscv/include/asm/setup.h line 20

Quoted 10 lines
arch/riscv/include/asm/setup.h new file +10 -0
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_SETUP_H
+#define _ASM_RISCV_SETUP_H
+
+#include <asm-generic/setup.h>
+
+#endif /* _ASM_RISCV_SETUP_H */

Can you remove this file and add it to asm/Kbuild as generic-y instead?

Quoted 4 lines
arch/riscv/include/asm/setup.h new file +4 -0
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct resides at the bottom of the supervisor stack

arch/riscv/include/asm/setup.h

Quoted 10 lines
arch/riscv/include/asm/setup.h new file +10 -0
+ * - if the members of this struct changes, the assembly constants
+ *   in asm-offsets.c must be updated accordingly
+ */
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current CPU */
+       int                     preempt_count;  /* 0 => preemptable, <0 => BUG */
+       mm_segment_t            addr_limit;
+};

Please see 15f4eae70d36 ("x86: Move thread_info into task_struct") and try to do the same.

arch/riscv/include/asm/setup.h

Quoted 11 lines
arch/riscv/include/asm/setup.h new file +11 -0
+#else /* !CONFIG_MMU */
+
+static inline void flush_tlb_all(void)
+{
+       BUG();
+}
+
+static inline void flush_tlb_mm(struct mm_struct *mm)
+{
+       BUG();
+}

The NOMMU support is rather incomplete and CONFIG_MMU is hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.

Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +0 -0
new file mode 100644
index 000000000000..276b6dae745c

arch/riscv/include/uapi/asm/Kbuild line 10

Quoted 10 lines
arch/riscv/include/uapi/asm/Kbuild new file +10 -0
@@ -0,0 +1,10 @@
+# UAPI Header export list
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += auxvec.h
+header-y += bitsperlong.h
+header-y += byteorder.h
+header-y += ptrace.h
+header-y += sigcontext.h
+header-y += siginfo.h
+header-y += unistd.h

Please see
fcc8487d477a ("uapi: export all headers under uapi directories")

and adapt the file accordingly

arch/riscv/include/uapi/asm/Kbuild

Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +6 -0
+#include <asm-generic/unistd.h>
+
+#define __NR_sysriscv  __NR_arch_specific_syscall
+#ifndef __riscv_atomic
+__SYSCALL(__NR_sysriscv, sys_sysriscv)
+#endif

Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on __riscv_atomic rather than the Kconfig symbol?

Arnd

maintainer
#55 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
Quoted 1 line

+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);

Please move the majority of this file into drivers/irqchip as a standalone driver.

Quoted 31 lines
arch/riscv/kernel/pci.c new file +25 -0
new file mode 100644
index 000000000000..4191a5ffdd67
@@ -0,0 +1,36 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c
+ *
+ * Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM
+ * Copyright (C) 2014 ARM Ltd.
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+
+/*
+ * Called after each bus is probed, but before its children are examined
+ */
+void pcibios_fixup_bus(struct pci_bus *bus)
+{

arch/riscv/kernel/pci.c line 35

Quoted 10 lines
arch/riscv/kernel/pci.c new file +10 -0
+       /* nothing to do, expected to be removed in the future */
+}
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here
+ */
+resource_size_t pcibios_align_resource(void *data, const struct resource *res,
+                               resource_size_t size, resource_size_t align)
+{
+       return res->start;
+}

Can you add a patch to remove the need for this, and send that to the PCI maintainers?

In the long run, I think we want both of these to be pci host bridge driver specific callbacks rather than per-architecture definitions, but for the moment, moving the empty version as a __weak copy into drivers/pci/ should be sufficient.

[note: don't ever use __weak elsewhere, the use in PCI is
only done for historic reasons and we want to get rid of that too, but for now it's more important to avoid adding yet another pointless copy]

If you don't care about LPC/ISA devices, then your PCI_MIN_IO should also be zero instead of 0x1000

arch/riscv/kernel/plic.c

Quoted 5 lines
arch/riscv/kernel/plic.c new file +0 -0
new file mode 100644
index 000000000000..5b3d4241f4e2

drivers/irqchip/riscv-plic.c

The file needs some work for following coding style, once that is done, please submit to the irqchip maintainers.

Quoted 6 lines
arch/riscv/kernel/plic.c new file +6 -0
+#define PLIC_HART_CONTEXT(data, i)     (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i)
+#define PLIC_ENABLE_CONTEXT(data, i)   (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i)
+#define PLIC_PRIORITY(data)            (struct plic_priority *)((char *)data->reg + PRIORITY_BASE)
+
+struct plic_hart_context {
+       volatile u32 threshold;

arch/riscv/kernel/plic.c line 51

Quoted 10 lines
arch/riscv/kernel/plic.c new file +10 -0
+       volatile u32 claim;
+};
+
+struct plic_enable_context {
+       atomic_t mask[32]; // 32-bit * 32-entry
+};
+
+struct plic_priority {
+       volatile u32 prio[MAX_DEVICES];
+};

The 'volatile' seems misplaced here. What is it for?

Quoted 1 line

+// TODO: add a /sys interface to set priority + per-hart enables for steering

No driver-private sysfs interfaces please for irqchips please.
See http://elixir.free-electrons.com/linux/latest/source/Documentation/IRQ-affinity.txt
for setting the affinity.

Quoted 20 lines
arch/riscv/kernel/reset.c new file +14 -0
new file mode 100644
index 000000000000..58bad9598e21
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+

arch/riscv/kernel/reset.c line 24

Quoted 10 lines
arch/riscv/kernel/reset.c new file +10 -0
+#include <linux/reboot.h>
+#include <linux/export.h>
+#include <asm/sbi.h>
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_restart(char *cmd)
+{
+}

Call do_kernel_restart(cmd) here.

arch/riscv/kernel/reset.c line 28

Quoted 3 lines
arch/riscv/kernel/reset.c new file +3 -0
+void machine_halt(void)
+{
+}

This should not return. Either make it call sbi_shutdown as well, or use the ARM implementation:

void machine_halt(void)

{
        local_irq_disable();
        smp_send_stop();
        while (1);
}

arch/riscv/kernel/sbi-con.c

Quoted 5 lines
arch/riscv/kernel/sbi-con.c new file +0 -0
new file mode 100644
index 000000000000..86baeb5ef0cd

As Olof said, move it to drivers/tty/hvc/ and use those helpers.

Quoted 36 lines
arch/riscv/kernel/sys_riscv.c new file +30 -0
new file mode 100644
index 000000000000..3e07308e24f5
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2014 Darius Rad <[email protected]>
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/syscalls.h>
+#include <asm/unistd.h>
+
+SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
+       unsigned long, prot, unsigned long, flags,
+       unsigned long, fd, off_t, offset)
+{
+       if (unlikely(offset & (~PAGE_MASK)))
+               return -EINVAL;
+       return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+}
+
+#ifndef CONFIG_64BIT
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+       unsigned long, prot, unsigned long, flags,

arch/riscv/kernel/sys_riscv.c line 40

Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10 -0
+       unsigned long, fd, off_t, offset)
+{
+       /* Note that the shift for mmap2 is constant (12),
+          regardless of PAGE_SIZE */
+       if (unlikely(offset & (~PAGE_MASK >> 12)))
+               return -EINVAL;
+       return sys_mmap_pgoff(addr, len, prot, flags, fd,
+               offset >> (PAGE_SHIFT - 12));
+}
+#endif /* !CONFIG_64BIT */

The first one should be CONFIG_64BIT only.

Quoted 16 lines
arch/riscv/kernel/sys_riscv.c new file +16 -0
+#ifdef CONFIG_RV_SYSRISCV_ATOMIC
+SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1,
+       unsigned long, arg2, unsigned long, arg3)
+{
+       unsigned long flags;
+       unsigned long prev;
+       unsigned int *ptr;
+       unsigned int err;
+
+       switch (cmd) {
+       case RISCV_ATOMIC_CMPXCHG:
+               ptr = (unsigned int *)arg1;
+               if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned int)))
+                       return -EFAULT;
+
+               preempt_disable();

arch/riscv/kernel/sys_riscv.c line 67

Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10 -0
+               raw_local_irq_save(flags);
+               err = __get_user(prev, ptr);
+               if (likely(!err && prev == arg2))
+                       err = __put_user(arg3, ptr);
+               raw_local_irq_restore(flags);
+               preempt_enable();
+
+               return unlikely(err) ? err : prev;
+
+       case RISCV_ATOMIC_CMPXCHG64:

Make these two separate syscalls and get rid of the wrapper (I already mentioned it in the header file comments, but it fits better here).

It may be good to have an optimized version in the vdso that does an atomic operation directly if the CPU supports it.

arch/riscv/kernel/time.c

Quoted 5 lines
arch/riscv/kernel/time.c new file +0 -0
new file mode 100644
index 000000000000..ce8c459fadaa

drivers/clocksource/riscv-timer.c, and submit it to the respective maintainers.

Arnd

author maintainer
#16 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Olof Johansson
Quoted 69 lines · On Mon, 22 May 2017 22:23:17 PDT (-0700), [email protected] wrote:

(new top-level subthread here since this is a separate topic):

Quoted 52 lines · Palmer Dabbelt
arch/riscv/Makefile new file +46 -0
new file mode 100644
index 000000000000..07ef200e0675
@@ -0,0 +1,64 @@
+# This file is included by the global makefile so that you can add your own
+# architecture-specific flags and dependencies. Remember to do have actions
+# for "archclean" and "archdep" for cleaning up and making dependencies for
+# this architecture
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+
+LDFLAGS         :=
+OBJCOPYFLAGS    := -O binary
+LDFLAGS_vmlinux :=
+KBUILD_AFLAGS_MODULE += -fPIC
+KBUILD_CFLAGS_MODULE += -fPIC
+
+ifeq ($(ARCH),riscv)
+       KBUILD_DEFCONFIG = riscv64_spike
+else
+       KBUILD_DEFCONFIG = $(ARCH)_spike
+endif
+
+export BITS
+ifeq ($(CONFIG_64BIT),y)
+       BITS := 64
+       UTS_MACHINE := riscv64
+
+       KBUILD_CFLAGS += -mabi=lp64
+       KBUILD_AFLAGS += -mabi=lp64
+       KBUILD_MARCH = rv64im
+       LDFLAGS += -melf64lriscv
+else
+       BITS := 32
+       UTS_MACHINE := riscv32
+
+       KBUILD_CFLAGS += -mabi=ilp32
+       KBUILD_AFLAGS += -mabi=ilp32
+       KBUILD_MARCH = rv32im
+       LDFLAGS += -melf32lriscv
+endif
+
+ifeq ($(CONFIG_RV_ATOMIC),y)
+       KBUILD_RV_ATOMIC = a
+endif
+
+KBUILD_CFLAGS += -Wall

arch/riscv/Makefile line 56

Quoted 10 lines
arch/riscv/Makefile new file +10 -0
+
+ifeq ($(CONFIG_RVC),y)
+       KBUILD_RVC = c
+endif
+
+KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC)
+
+KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC)
+KBUILD_CFLAGS += -mno-save-restore
+KBUILD_CFLAGS += -mstrict-align

I built a vanilla gcc-7.1.0 here, with 'riscv64-linux' as target, and I get:

Quoted 7 lines

riscv64-linux-gcc: error: unrecognized command line option '-mstrict-align'; did you mean '-Wstrict-aliasing'?

The suggestion seems completely bogus, but the error is real. Looking at the gcc sources, I only see strict-align plumbed up on rs6000, aarch64, m68k(!) and v850. Or am I missing something here?

We didn't get the "-mstrict-align" patch for RISC-V into the 7.1.0 release. The boot loader install machine-mode unaligned access handlers, so in theory you shouldn't need this at all -- it snuck its way in as a debugging attempt because the Radeon driver was exhibiting some weird behavior.

I'll drop this from the next patch set.

author maintainer
#70 lore raw
In reply to Tobias Klauser
Quoted 33 lines · On Mon, 22 May 2017 23:45:34 PDT (-0700), [email protected] wrote:

Hi Palmer,

Quoted 21 lines · Palmer Dabbelt
Quoted 20 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:
Quoted 19 lines · Palmer Dabbelt

We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.

This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.

These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.

[...]

Quoted 6 lines
Quoted 5 lines

I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.

Quoted 8 lines
Quoted 2 lines

OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.

You might want to Cc [email protected] on future iterations of this patchset where there's less "noise" than on LKML and the relevant people are more likely to notice ;) Likewise, the device-tree specific bits (e.g. the bindings documentation) should probably be Cc'ed to [email protected]

OK, thanks. I'll do that for the v2.

#14 lore raw

Re: [patches] Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Olof Johansson
Quoted 4 lines · Olof Johansson

The same is true for some other drivers. Actually, I wonder if it might be just as easy to implement a sbi backend for hvc -- see hvc_udbg.c for an example where, on power, you have a simple get/put char hypervisor call in a very similar manner.

Rather look at hvc_opal. This is the console driver we use on native POWER servers with the OPAL firmware, and it calls into a firmware in a very similar way.

The driver lives in drivers/tty/hvc. It does call some "helpers" in the arch code that wrap the actual FW calls.

Quoted 4 lines

Either way (keeping discrete sbi driver or implementing hvc backend), moving to drivers/tty is the right thing here -- we've worked hard on ARM to get rid of random drivers under arch/ and it'd be nice to not see new ones intoduced here.

Yup. The reason mostly is that if the tty maintainer needs to do a subsystem-wide change, he can address all drivers in drivers/tty and doesn't have to look for others elsewhere in the tree. This is the same for all subsystems.

Cheers,
Ben.

#30 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

arch/riscv/include/asm/io.h line 18

Quoted 2 lines
arch/riscv/include/asm/io.h new file +2 -0
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Right, I was about to comment on that one.

The question Palmer is about the ordering semantics of non-cached storage.

What kind of ordering is provided architecturally ? Especially between cachable and non-cachable loads and stores ?

Also, you have PCIe right ? What is the behaviour of MSIs ?

Does your HW provide a guarantee that in the case of a series of DMA writes to memory by a device followed by an MSI, the CPU getting the MSI will only get it after all the previous DMA writes have reached coherency ? (Unlike LSIs where the driver is required to do an MMIO read from the device, MSIs are expected to be ordered with data).

Another things with the read*() accessors. It's not uncommon for a driver to do:

	writel(1, reset_reg);
	readl(reset_reg); /* flush posted writes */
	udelay(10);
	writel(0, reset_reg);

Now, in the above case, what can typically happen if you aren't careful is that the readl which is intended to "push" the previous writel, will not actually do its job because the return value hasn't been "consumed" by the processor. Thus, the CPU will stick that on some kind of load queue and won't actually wait for the return value before hitting the delay loop.

Thus you might end up in a situation where the writel of 1 to the device is itself reaching the device way after you started the delay loop, and thus end up violating the delay requirement of the HW.

On powerpc we solve that by using a special instruction construct inside the read* accessors that prevents the CPU from executing subsequent instructions until the read value has been returned.

You may want to consider something similar.

Cheers,
Ben.

author maintainer
#39 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Geert Uytterhoeven
Quoted 11 lines · On Tue, 23 May 2017 03:47:34 PDT (-0700), [email protected] wrote:

Hi Palmer,

Quoted 2 lines · Palmer Dabbelt
 arch/riscv/lib/Makefile  |   5 ++
 arch/riscv/lib/ashldi3.c |  42 ++++++++++++++++

At least this one has already two identical copies in arch/score/lib/ashldi3.c and arch/sh/lib/ashldi3.c. Probably these should be moved to lib/, and built depending on a new config symbol that is selected on score, sh, and riscv.

Didn't check the others.

Thanks. It looks like there's actually a lot of these on many architectures. I have another patch set to correct all of these that you're To'd on, I'll just pick up the first patch in the set for v2

https://lkml.org/lkml/2017/5/23/1280

author maintainer
#50 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Olof Johansson
Quoted 5 lines · On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:

On Mon, May 22, 2017 at 5:41 PM, Palmer Dabbelt <[email protected]> wrote:
What's missing from this patchset (ideally) is a good writeup under DOcumentation/ on expectations of system state (and/or configuration) upon entry of the kernel. For comparison, see the arm64 documentation where they were quite specific in this.

We don't have a spec written for this yet, but one is being written. Is it OK if I wait until there's a spec?

Quoted 3 lines

This patch is also pushing size limits, and is getting unwieldy to comment on. I'll point out a few things below with plenty of snipped out lines.

I'm also going to start dropping diffs, as this is very big.

Quoted 18 lines
Quoted 4 lines

+++ b/arch/riscv/kernel/asm-offsets.c

arch/riscv/kernel/asm-offsets.c new file +2 -0
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California

arch/riscv/kernel/asm-offsets.c line 12

Quoted 10 lines
arch/riscv/kernel/asm-offsets.c new file +10 -0
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.

Hmm, I haven't seen these terms used often, but they seem to exist around the tree in a few places. arch/tile is littered with them.

Quoted 6 lines

I am not a lawyer, but I can't seem any reference to "good title" in the GPLv2 text.

Rather than having to go through the process of figuring out if this license header is acceptable or not, you might find it easier to just go with something more established.

This almost certainly came from Tilera: I stole our ptrace from there becuase that was the ISA I understood best, and that header must have proliferated everywhere else.

I've changed it to a header I copied from ARM

https://github.com/riscv/riscv-linux/commit/ccc4f51b40b28adf01b14ed6578bf26dc02f1425

Quoted 5 lines
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5 -0
+static int __populate_cache_leaves(unsigned int cpu)
+{
+       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
+       struct cacheinfo *this_leaf = this_cpu_ci->info_list;
+       struct device_node *np = of_cpu_device_node_get(cpu);
Quoted 8 lines

arch/riscv/kernel/cacheinfo.c line 66

Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5 -0
+       int levels = 1, level = 1;
+
+       if (of_property_read_bool(np, "cache-size"))   ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
+       if (of_property_read_bool(np, "i-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
+       if (of_property_read_bool(np, "d-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);

Please run checkpatch, kernel coding style doesn't use one-line ifs (here nor elsewhere).

I went through and fixed many of the checkpatch messages. The ones that are left fall into the following categories:

* Lots of uses of BUG/BUG_ON instead of WARN_ON. Lots of these are in boot code, but some of them can probably be fixed.

* Parens around single-statement __asm__ macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.

* Parens around macros like "#define RISCV_PTR .dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.

* Warnings about volatile in function declarations in bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.

* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.

* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).

* A handful of lines over 80 characters that I think are onerous to break any more.

* Some warnings about printk() not having a KERN_ prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (in show_regs, for example, where arm64 also has them).

* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.

There's also a bunch of false positives:

* The spelling of SEPC, which is correct (Supervisor Exception Program Counter).

* Fall-through warnings, probably getting confused by the break looking like "break; \" (they're in macros).

I'll make another pass on these before a v2 patch set.

Quoted 7 lines
Quoted 7 lines
arch/riscv/kernel/cpu.c new file +7 -0
+/* Return -1 if not a valid hart */
+int riscv_of_processor_hart(struct device_node *node)
+{
+       const char *isa, *status;
+       u32 hart;
+
+       if (!of_device_is_compatible(node, "riscv")) return -1;
Quoted 8 lines

arch/riscv/kernel/cpu.c line 31

Quoted 6 lines
arch/riscv/kernel/cpu.c new file +6 -0
+       if (of_property_read_u32(node, "reg", &hart) || hart >= NR_CPUS) return -1;
+       if (of_property_read_string(node, "status", &status) || strcmp(status, "okay")) return -1;
+       if (of_property_read_string(node, "riscv,isa", &isa) || isa[0] != 'r' || isa[1] != 'v') return -1;
+
+       return hart;
+}

We usually prefer to see real -E<foo> returns instead of -1 in the kernel.

Makes sense. https://github.com/riscv/riscv-linux/commit/10ef72b2aa16b2b69f9f349cffc06d12e183a56e

Quoted 11 lines
Quoted 11 lines
arch/riscv/kernel/irq.c new file +11 -0
+asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
+{
+       struct pt_regs *old_regs = set_irq_regs(regs);
+       irq_enter();
+
+       /* There are three classes of interrupt: timer, software, and
+          external devices.  We dispatch between them here.  External
+          device interrupts use the generic IRQ mechanisms. */
+       switch (cause) {
+               case INTERRUPT_CAUSE_TIMER:
+                       riscv_timer_interrupt();
Quoted 8 lines

arch/riscv/kernel/irq.c line 66

Quoted 6 lines
arch/riscv/kernel/irq.c new file +6 -0
+                       break;
+               case INTERRUPT_CAUSE_SOFTWARE:
+                       riscv_software_interrupt();
+                       break;
+               default: {
+                       struct irq_domain *domain = per_cpu(riscv_irq_data, smp_processor_id()).domain;

Move this up to top of function and remove the { } wrap, please.

https://github.com/riscv/riscv-linux/commit/17879136caa05ed9f686736b3343f4b2063920ab

Quoted 7 lines

arch/riscv/kernel/irq.c line 114

Quoted 4 lines
arch/riscv/kernel/irq.c new file +4 -0
+static void riscv_irq_enable(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+       atomic_long_or((1 << (long)d->hwirq), &per_cpu(riscv_early_sie, data->hart));

This is a bit dense to get into without a few words of how it's expected to work.

OK, how does this look? https://github.com/riscv/riscv-linux/commit/112fd2d882c2363508a660061da558d772a4ff0b

Quoted 9 lines

arch/riscv/kernel/irq.c line 178

Quoted 7 lines
arch/riscv/kernel/irq.c new file +7 -0
+static int riscv_intc_init(struct device_node *node, struct device_node *parent)
+{
+       int hart;
+
+       if (parent) return 0; // should have no interrupt parent
+
+       if ((hart = riscv_of_processor_hart(node->parent)) >= 0) {

Common pattern in kernel is to detect error instead:

Quoted 8 lines
    hart = riscv_of_processor_hart(node->parent);
    if (hart < 0) {
        <from your else side here>
        return 0;
    }
    <body if your if statement here>

    return 0;

OK. I've fixed this one here

https://github.com/riscv/riscv-linux/commit/5f48d9ba0d3cd19dc0bf95f66370de4cfcd84cca

I'll try to remember to fix any others that I come across.

Quoted 11 lines

arch/riscv/kernel/pci.c line 2

Quoted 8 lines
arch/riscv/kernel/pci.c new file +2 -0
new file mode 100644
index 000000000000..4191a5ffdd67
@@ -0,0 +1,36 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c

So, you should add recursive reference from there (i.e. powerpc).

Quoted 1 line

But in the end, there's essentially no code in this file. :)

Well, now there's more copyright notices than lines of code... :)

https://github.com/riscv/riscv-linux/commit/5ad312f755935319fdbb6739377b400ea81cd2ec

Quoted 4 lines

arch/riscv/kernel/pci.c line 3

Quoted 1 line
arch/riscv/kernel/pci.c new file +1 -0
+#define MAX_DEVICES    1024 // 0 is reserved

Seems like an odd comment to have here (and should probably not go at the end of the line)

Device 0 in the PLIC is reserved to mean "no device", which means "MAX_DEVICES" is a bit of an odd name (there can only be MAX_DEVICES-1 devices). I've added a larger comment to describe this better.

https://github.com/riscv/riscv-linux/commit/9d16413051dd86db0fb8a792f3d5f05ce788d145

Quoted 6 lines

arch/riscv/kernel/pci.c line 6

Quoted 3 lines
arch/riscv/kernel/pci.c new file +3 -0
+#define PLIC_HART_CONTEXT(data, i)     (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i)
+#define PLIC_ENABLE_CONTEXT(data, i)   (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i)
+#define PLIC_PRIORITY(data)            (struct plic_priority *)((char *)data->reg + PRIORITY_BASE)

Since you have typecasting and stuff here, small static inlines with appropriate return types seems slightly tidier.

OK. https://github.com/riscv/riscv-linux/commit/c416649b203276d944be595d87caf042c998727f

Quoted 6 lines

arch/riscv/kernel/pci.c line 10

Quoted 4 lines
arch/riscv/kernel/pci.c new file +4 -0
+static void plic_chained_handle_irq(struct irq_desc *desc)
+{
+        struct plic_handler *handler = irq_desc_get_handler_data(desc);
+       struct irq_chip *chip = irq_desc_get_chip(desc);

Whitespace.

These were fixed along with the other checkpatch messages.

Quoted 4 lines

[wrapping up review of this patch at this point to keep size down]

-Olof

Thanks for the comments! I'll batch these up into a v2 when I'm done with everyone's comments from this round.

author maintainer
#18 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Geert Uytterhoeven
Quoted 7 lines · On Tue, 23 May 2017 03:51:24 PDT (-0700), [email protected] wrote:

Hi Palmer,

Quoted 3 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +0 -0
@@ -0,0 +1,300 @@
Quoted 14 lines

arch/riscv/Kconfig line 123

Quoted 11 lines
arch/riscv/Kconfig new file +11 -0
+config PLIC
+       bool "Platform-Level Interrupt Controller"
+       default y
+       help
+          This enables support for the PLIC chip found in standard RISC-V
+          systems. The PLIC is the top-most interrupt controller found in
+          the system, connected directly to the core complex. All other
+          interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+          If you don't know what to do here, say Y.
+

I think this symbol belongs in drivers/irqchip/Kconfig, and the corresponding driver in drivers/irqchip/.

OK, makes sense.

https://github.com/riscv/riscv-linux/commit/81e5c9e581c318ea99192d5c1aaf97c197e79272

I'll batch this up with all the other code review comments for a v2.

author maintainer
#41 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Arnd Bergmann
Quoted 25 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
arch/riscv/lib/Makefile new file +18 -0
new file mode 100644
index 000000000000..f644e582f4b8
 
+
+void __delay(unsigned long cycles)
+{
+       u64 t0 = get_cycles();
+
+       while ((unsigned long)(get_cycles() - t0) < cycles)
+               cpu_relax();
+}
+
+void udelay(unsigned long usecs)
+{
+       u64 ucycles = (u64)usecs * timebase;
+       do_div(ucycles, 1000000U);
+       __delay((unsigned long)ucycles);
+}
+EXPORT_SYMBOL(udelay);
+
+void ndelay(unsigned long nsecs)
Quoted 8 lines

arch/riscv/lib/Makefile

Quoted 5 lines
arch/riscv/lib/Makefile new file +5 -0
+{
+       u64 ncycles = (u64)nsecs * timebase;
+       do_div(ncycles, 1000000000U);
+       __delay((unsigned long)ncycles);
+}

I'd be slightly worried about a global 'timebase' identifier that might conflict with a variable in some random driver.

Makes sense. I've renamed it to riscv_timebase

https://github.com/riscv/riscv-linux/commit/ed7d769e2c14e8809c3c125e0bba2978cb6fd37b

Quoted 3 lines

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

  [    0.048000] before 1000x usleep 1000
  [    1.060000] before 1000x nsleep 1000000
  [    2.072000] done
Quoted 1 line

Arnd

Thanks for the feedback. I'll incorporate this along with all the other feedback into a v2.

#59 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt

Hi!

arch/riscv/kernel/cacheinfo.c line 29

Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10 -0
+static void ci_leaf_init(struct cacheinfo *this_leaf,
+                         struct device_node *node,
+                         enum cache_type type, unsigned int level)
+{
+        this_leaf->of_node = node;
+        this_leaf->level = level;
+        this_leaf->type = type;
+        this_leaf->physical_line_partition = 1; // not a sector cache
+        this_leaf->attributes = CACHE_WRITE_BACK | CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE; // TODO: add to DTS
+}

You may want to run the patches through checkpatch. (Comment style, long lines).

Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10 -0
+static int __populate_cache_leaves(unsigned int cpu)
+{
+	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
+	struct cacheinfo *this_leaf = this_cpu_ci->info_list;
+	struct device_node *np = of_cpu_device_node_get(cpu);
+	int levels = 1, level = 1;
+
+	if (of_property_read_bool(np, "cache-size"))   ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level);
+	if (of_property_read_bool(np, "i-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level);
+	if (of_property_read_bool(np, "d-cache-size")) ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
maintainer
#51 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
Quoted 5 lines · Palmer Dabbelt

On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:

* Parens around single-statement __asm__ macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.

I would generally recommend using inline functions for those, and only do macros when you need them.

Quoted 3 lines

* Parens around macros like "#define RISCV_PTR .dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.

agreed

Quoted 3 lines

* Warnings about volatile in function declarations in bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.

Agreed, bitops.h is one of the few headers that should use 'volatile'.

Quoted 2 lines

* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.

What is the warning here? I would assume that you should leave this unchanged as well.

Quoted 2 lines

* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).

It depends. What typedefs are those? Removing the typedefs in both the kernel and the other code that uses the same types is likely the best option here.

Quoted 2 lines

* A handful of lines over 80 characters that I think are onerous to break any more.

Right, don't worry about it too much, and use common sense for this warning.

Quoted 3 lines

* Some warnings about printk() not having a KERN_ prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (in show_regs, for example, where arm64 also has them).

KERN_CONT

Quoted 2 lines

* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.

I would try to fix those by using a header even if there is only one user. I'd actually like to get a compile-time warning for those in the long run, maybe with 'make W=1', so better don't introduce new ones.

Arnd

maintainer
#42 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Quoted 6 lines

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }

You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.

Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.

Arnd

author maintainer
#3 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

I don't think that does the same thing. The desired effect of this diff is:

* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.

* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.

* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.

Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this

Makefile +2 -9
index 0606f28..4adc609 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+                                 -e s/riscv.*/riscv/ )
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
-# Additional ARCH settings for RISC-V
-ifeq ($(ARCH),riscv32)
-       SRCARCH := riscv
-endif
-ifeq ($(ARCH),riscv64)
-       SRCARCH := riscv
-endif
-
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc

then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.

author maintainer
#20 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Arnd Bergmann
Quoted 30 lines · Arnd Bergmann
Quoted 29 lines · Palmer Dabbelt
---
 arch/riscv/.gitignore                |  35 ++++
 arch/riscv/Kconfig                   | 300 +++++++++++++++++++++++++++++++++++
 arch/riscv/Makefile                  |  64 ++++++++
 arch/riscv/configs/riscv32_spike     |  47 ++++++
 arch/riscv/configs/riscv64_freedom-u |  52 ++++++
 arch/riscv/configs/riscv64_qemu      |  64 ++++++++
 arch/riscv/configs/riscv64_spike     |  45 ++++++
 7 files changed, 607 insertions(+)
 create mode 100644 arch/riscv/.gitignore
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/riscv32_spike
 create mode 100644 arch/riscv/configs/riscv64_freedom-u
 create mode 100644 arch/riscv/configs/riscv64_qemu
 create mode 100644 arch/riscv/configs/riscv64_spike
arch/riscv/.gitignore new file +6 -0
new file mode 100644
index 000000000000..376d06eb5d52
@@ -0,0 +1,35 @@
+# Now un-ignore all files.
+!*
+
+# But then re-ignore the files listed in the Linux .gitignore
+# Normal rules
+#
Quoted 8 lines

arch/riscv/.gitignore line 10

Quoted 4 lines
arch/riscv/.gitignore new file +4 -0
+.*
+*.o
+*.o.*
+*.a

This doesn't seem to belong here: There is no reason for riscv to be different from all other architectures. Is something wrong with the top-level .gitignore? If so, we should just fix it there.

Sorry, this snuck in from how we used to track the kernel. It's been fixed.

Quoted 19 lines
Quoted 19 lines
arch/riscv/Kconfig new file +13 -0
new file mode 100644
index 000000000000..510ead1d3343
@@ -0,0 +1,300 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+       def_bool y
+       select OF
+       select OF_EARLY_FLATTREE
+       select OF_IRQ
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_WANT_FRAME_POINTERS
+       select CLONE_BACKWARDS
Quoted 8 lines

arch/riscv/Kconfig line 18

Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+       select COMMON_CLK
+       select GENERIC_CLOCKEVENTS
+       select GENERIC_CPU_DEVICES
+       select GENERIC_IRQ_SHOW
+       select GENERIC_PCI_IOMAP

You normally don't want GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()

We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.

It looks like most of my candidates for patterning things after use GENERIC_PCI_IOMAP, but I ended up setting GENERIC_IOMAP and things still at least build and boot without any PCI

https://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e

I'll be sure to check if I broke PCI, as I don't actually know what's going on here.

Quoted 5 lines

arch/riscv/Kconfig line 20

Quoted 2 lines
arch/riscv/Kconfig new file +2 -0
+config MMU
+       def_bool y

Just a general question: has there been any interest in a no-MMU version?

One of the fun things about RISC-V is that there's at least some interest in _everything_... :). There hasn't been any serious interest, and I don't know of anyone building systems where no-MMU Linux would run (our DDR phy is a lot bigger than our MMU), but I wouldn't rule it out.

Quoted 11 lines

arch/riscv/Kconfig line 45

Quoted 6 lines
arch/riscv/Kconfig new file +6 -0
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+       def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+       def_bool y

Are you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit dma_addr_t and phys_addr_t when possible makes some code noticeably more efficient.

Quoted 8 lines

arch/riscv/Kconfig line 73

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config PGTABLE_LEVELS
+       int
+       default 3 if 64BIT
+       default 2

With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.

We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.

Quoted 18 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y
+
+config RV_SYSRISCV_ATOMIC

arch/riscv/Kconfig line 152

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

Just express this in Kconfig terms to prevent misconfiguration:

Quoted 3 lines

config RV_SYSRISCV_ATOMIC
bool "Include support for atomic operation syscalls" if RV_ATOMIC default !RV_ATOMIC

Done

https://github.com/riscv/riscv-linux/commit/921703e0a6639d10826e5bbad73f4998977dc244

Quoted 7 lines

I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:

That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.

I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.

The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.

I'll add it to my TODO list.

Quoted 10 lines

arch/riscv/Kconfig line 211

Quoted 8 lines
arch/riscv/Kconfig new file +8 -0
+config PCI_DOMAINS
+       def_bool PCI
+
+config PCI_DOMAINS_GENERIC
+       def_bool PCI
+
+config PCI_SYSCALL
+       def_bool PCI

I don't think you want PCI_SYSCALL

OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens

https://github.com/riscv/riscv-linux/commit/710b5bb81ab99cf1d49a74bb706f6aae179fc111

author maintainer
#27 lore raw

Re: [PATCH 3/7] RISC-V: Device Tree Documentation

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++

The patch needs a description, and should be sent to the irqchip maintainers and the devicetree maintainers for review, along for the respective drivers/irqchip/
patch.

OK, I'll include that as part of my v2.

maintainer
#4 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Palmer Dabbelt
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

I don't think that does the same thing. The desired effect of this diff is:

* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.

Quoted 6 lines

* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.

* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.

Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.

Quoted 35 lines

Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this

Makefile +2 -9
index 0606f28..4adc609 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+                                 -e s/riscv.*/riscv/ )
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
-# Additional ARCH settings for RISC-V
-ifeq ($(ARCH),riscv32)
-       SRCARCH := riscv
-endif
-ifeq ($(ARCH),riscv64)
-       SRCARCH := riscv
-endif
-
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc
Quoted 2 lines

then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.

Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on CONFIG_64BIT.

Arnd

maintainer
#21 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt
Quoted 30 lines · Palmer Dabbelt
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +13 -0
new file mode 100644
index 000000000000..510ead1d3343
@@ -0,0 +1,300 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+       def_bool y
+       select OF
+       select OF_EARLY_FLATTREE
+       select OF_IRQ
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_WANT_FRAME_POINTERS
+       select CLONE_BACKWARDS
Quoted 8 lines

arch/riscv/Kconfig line 18

Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+       select COMMON_CLK
+       select GENERIC_CLOCKEVENTS
+       select GENERIC_CPU_DEVICES
+       select GENERIC_IRQ_SHOW
+       select GENERIC_PCI_IOMAP

You normally don't want GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()

Quoted 2 lines

We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.

Ah, interesting. What is the exact behavior of that fence? (this is slightly unrelated but worth looking at anyway)

Quoted 8 lines

It looks like most of my candidates for patterning things after use GENERIC_PCI_IOMAP, but I ended up setting GENERIC_IOMAP and things still at least build and boot without any PCI

https://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e

I'll be sure to check if I broke PCI, as I don't actually know what's going on here.

Actually I made a mistake: GENERIC_PCI_IOMAP is fine, please use that, GENERIC_IOMAP is the option you don't want, and you already don't enable that one.

Quoted 16 lines
Quoted 16 lines

arch/riscv/Kconfig line 45

Quoted 6 lines
arch/riscv/Kconfig new file +6 -0
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+       def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+       def_bool y

Are you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit dma_addr_t and phys_addr_t when possible makes some code noticeably more efficient.

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config PGTABLE_LEVELS
+       int
+       default 3 if 64BIT
+       default 2
Quoted 7 lines
Quoted 3 lines

With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.

We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.

I'd suggest to leave it turned off initially and only use it once someone actually builds a system that makes use of the high address space.

Of course if there is already hardware that needs it, there has to be a way to turn it on.

This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:

- Every major platform gets a Kconfig option in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)

- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.

On ARM, we have a bit of both, which is not as good as being consistent one way or another.

Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y
+
+config RV_SYSRISCV_ATOMIC

arch/riscv/Kconfig line 152

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:

Quoted 3 lines

That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.

I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.

Quoted 6 lines

The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.

I'll add it to my TODO list.

This would be another variant of the question above.

Quoted 11 lines
Quoted 10 lines

arch/riscv/Kconfig line 211

Quoted 8 lines
arch/riscv/Kconfig new file +8 -0
+config PCI_DOMAINS
+       def_bool PCI
+
+config PCI_DOMAINS_GENERIC
+       def_bool PCI
+
+config PCI_SYSCALL
+       def_bool PCI

I don't think you want PCI_SYSCALL

Quoted 2 lines

OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens

I'd argue that's a user space bug that we want to fix anyway to make the code portable to other architectures.

Arnd

author maintainer
#32 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Arnd Bergmann
Quoted 17 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +16 -0
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+static inline int atomic_read(const atomic_t *v)
+{
+       return *((volatile int *)(&(v->counter)));
+}
+/**
+ * atomic_set - set atomic variable
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.
Quoted 8 lines

arch/riscv/include/asm/atomic.h line 42

Quoted 5 lines

+ */

arch/riscv/include/asm/atomic.h new file +4 -0
+static inline void atomic_set(atomic_t *v, int i)
+{
+       v->counter = i;
+}

These commonly use READ_ONCE() and WRITE_ONCE, I'd recommend doing the same here to be on the safe side.

Makes sense. https://github.com/riscv/riscv-linux/commit/77647f9e4dccab68c69a212a63c9efe1db2b7b1c

Quoted 11 lines
Quoted 10 lines
arch/riscv/include/asm/bug.h new file +3 -0
new file mode 100644
index 000000000000..10d894ac3137
@@ -0,0 +1,81 @@
+/*
 
+#ifndef _ASM_RISCV_BUG_H
+#define _ASM_RISCV_BUG_H
Quoted 8 lines

arch/riscv/include/asm/bug.h line 25

Quoted 2 lines
arch/riscv/include/asm/bug.h new file +2 -0
+#ifdef CONFIG_GENERIC_BUG
+#define __BUG_INSN     _AC(0x00100073, UL) /* sbreak */

Please have a look at the modifications I did for !CONFIG_BUG on x86, arm and arm64. It's generally better to define BUG to a trap even when CONFIG_BUG is disabled, otherwise you run into undefined behavior in some code, and gcc will print annoying warnings about that.

OK, seems like a good thing. https://github.com/riscv/riscv-linux/commit/67db001653614c6555424b3812d7edfba12a6d4c

Quoted 9 lines

arch/riscv/include/asm/bug.h

Quoted 6 lines
arch/riscv/include/asm/bug.h new file +6 -0
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT         6
+
+#define L1_CACHE_BYTES         (1 << L1_CACHE_SHIFT)

Is this the only valid cache line size on riscv, or just the largest one that is allowed?

The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.

We could always make this a Kconfig parameter.

Quoted 26 lines

arch/riscv/include/asm/bug.h

Quoted 10 lines
arch/riscv/include/asm/bug.h new file +10 -0
+
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+       return (dma_addr_t)paddr;
+}
+
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+{
+       return (phys_addr_t)dev_addr;
+}

What do you need these for? If possible, try to remove them.

arch/riscv/include/asm/bug.h

Quoted 9 lines
arch/riscv/include/asm/bug.h new file +9 -0
+static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir)
+{
+       /*
+        * RISC-V is cache-coherent, so this is mostly a no-op.
+        * However, we do need to ensure that dma_cache_sync()
+        * enforces order, hence the mb().
+        */
+       mb();
+}

Do you even support any drivers that use
dma_alloc_noncoherent()/dma_cache_sync()?

Quoted 1 line

I would guess you can just leave this out.

These must have been vestigial code, they appear safe to remove.

https://github.com/riscv/riscv-linux/commit/d1c88783d5ff66464a25173f7a4af139f0ebf5e2

Quoted 16 lines

arch/riscv/include/asm/io.h line 18

Quoted 11 lines
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

where I think the only odd thing is our definition of mmiowb

+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");
+
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");

which I think is correct.

Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/io.h new file +8 -0
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MMU
+
+extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
+
+#define ioremap_nocache(addr, size) ioremap((addr), (size))
+#define ioremap_wc(addr, size) ioremap((addr), (size))
Quoted 8 lines
Quoted 1 line

+#define ioremap_wt(addr, size) ioremap((addr), (size))

Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and ioremap_wc() gets used for by memremap() for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags

This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.

Quoted 24 lines
Quoted 24 lines
arch/riscv/include/asm/serial.h new file +18 -0
new file mode 100644
index 000000000000..d783dbe80a4b
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#ifndef _ASM_RISCV_SERIAL_H
+#define _ASM_RISCV_SERIAL_H
+
+/*
Quoted 8 lines

arch/riscv/include/asm/serial.h line 22

Quoted 4 lines
arch/riscv/include/asm/serial.h new file +4 -0
+ * FIXME: interim serial support for riscv-qemu
+ *
+ * Currently requires that the emulator itself create a hole at addresses
+ * 0x3f8 - 0x3ff without looking through page tables.

This sounds like something we want to fix in qemu and not have in the mainline kernel. In particular, something seems really wrong if your inb()/outb() get remapped to physical CPU address 0+offset.

Sorry, we had some hacks floating around for QEMU from before we actually had any devices interfaces working (ie, before device tree and proper MMIO support). I'll go through and drop these before v2.

Quoted 20 lines
Quoted 20 lines
arch/riscv/include/asm/setup.h new file +14 -0
new file mode 100644
index 000000000000..e457854e9988
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
Quoted 8 lines

arch/riscv/include/asm/setup.h line 20

Quoted 6 lines
arch/riscv/include/asm/setup.h new file +6 -0
+#ifndef _ASM_RISCV_SETUP_H
+#define _ASM_RISCV_SETUP_H
+
+#include <asm-generic/setup.h>
+
+#endif /* _ASM_RISCV_SETUP_H */

Can you remove this file and add it to asm/Kbuild as generic-y instead?

Yes. https://github.com/riscv/riscv-linux/commit/8f35ce93bd1230ac0cb4aa92e5673c61e50dd862

Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/setup.h new file +9 -0
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct resides at the bottom of the supervisor stack
+ * - if the members of this struct changes, the assembly constants
+ *   in asm-offsets.c must be updated accordingly
+ */
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
Quoted 8 lines

arch/riscv/include/asm/setup.h

Quoted 5 lines
arch/riscv/include/asm/setup.h new file +5 -0
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current CPU */
+       int                     preempt_count;  /* 0 => preemptable, <0 => BUG */
+       mm_segment_t            addr_limit;
+};

Please see 15f4eae70d36 ("x86: Move thread_info into task_struct") and try to do the same.

OK, here's my attempt

https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd

Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)

"
This is patterned more off the arm64 move than the x86 one, since we still need to have at least addr_limit to emulate FS.

The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to task_struct. thread_info must be at a 0 offset from task_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP in task_struct, but those are really acting more as extra scratch space than pemanent storage.
"

Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/setup.h new file +6 -0
+#else /* !CONFIG_MMU */
+
+static inline void flush_tlb_all(void)
+{
+       BUG();
+}
Quoted 8 lines

arch/riscv/include/asm/setup.h

Quoted 5 lines
arch/riscv/include/asm/setup.h new file +5 -0
+
+static inline void flush_tlb_mm(struct mm_struct *mm)
+{
+       BUG();
+}

The NOMMU support is rather incomplete and CONFIG_MMU is hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.

OK. I've left in the "#ifdef CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.

https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067

Quoted 20 lines
Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +0 -0
new file mode 100644
index 000000000000..276b6dae745c

arch/riscv/include/uapi/asm/Kbuild line 10

Quoted 10 lines
arch/riscv/include/uapi/asm/Kbuild new file +10 -0
@@ -0,0 +1,10 @@
+# UAPI Header export list
+include include/uapi/asm-generic/Kbuild.asm
+
+header-y += auxvec.h
+header-y += bitsperlong.h
+header-y += byteorder.h
+header-y += ptrace.h
+header-y += sigcontext.h
+header-y += siginfo.h
+header-y += unistd.h

Please see
fcc8487d477a ("uapi: export all headers under uapi directories")

Quoted 1 line

and adapt the file accordingly

https://github.com/riscv/riscv-linux/commit/52c5e300b498742390434891db34f9dbacd082e9

Quoted 10 lines

arch/riscv/include/uapi/asm/Kbuild

Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +6 -0
+#include <asm-generic/unistd.h>
+
+#define __NR_sysriscv  __NR_arch_specific_syscall
+#ifndef __riscv_atomic
+__SYSCALL(__NR_sysriscv, sys_sysriscv)
+#endif

Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on __riscv_atomic rather than the Kconfig symbol?

I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.

I can change this to two system calls: sysriscv_cmpxchg32 and sysriscv_cmpxchg64.

maintainer
#33 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

Quoted 14 lines · Palmer Dabbelt
Quoted 12 lines · Arnd Bergmann

arch/riscv/include/asm/cache.h line 21

Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/cache.h new file +6 -0
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT         6
+
+#define L1_CACHE_BYTES         (1 << L1_CACHE_SHIFT)

Is this the only valid cache line size on riscv, or just the largest one that is allowed?

Quoted 7 lines

The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.

We could always make this a Kconfig parameter.

The cache line size is used in a couple of places, let's go through the most common ones to see where that abstraction might be leaky and you actually get an architectural effect:

- On SMP machines, ____cacheline_aligned_in_smp is used to annotate data structures used in lockless algorithms, typically with one CPU writing to some members of a structure, and another CPU reading from it but not writing the same members. Depending on the architecture, having a larger actual alignment than L1_CACHE_BYTES will either lead to bad performance from cache line ping pong, or actual data corruption.

- On systems with DMA masters that are not fully coherent, ____cacheline_aligned is used to annotate data structures used for DMA buffers, to make sure that the cache maintenance operations in dma_sync_*_for_*() helpers don't corrup data outside of the DMA buffer. You don't seem to support noncoherent DMA masters or the cache maintenance operations required to use those, so this might not be a problem until someone adds an extension for those.

- Depending on the bus interconnect, a coherent DMA master might not be able to update partial cache lines, so you need the same annotation.

- The kmalloc() family of memory allocators aligns data to the cache line size, for both DMA and SMP synchronization above.

- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.

Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.

Quoted 28 lines
Quoted 16 lines

arch/riscv/include/asm/io.h line 18

Quoted 11 lines
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

where I think the only odd thing is our definition of mmiowb

Quoted 12 lines

+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");

Looks ok, yes.

Quoted 3 lines
  +#define mmiowb()                __asm__ __volatile__ ("fence io,io" : : : "memory");

which I think is correct.

I can never remember what exactly this one does.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/io.h new file +8 -0
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MMU
+
+extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
+
+#define ioremap_nocache(addr, size) ioremap((addr), (size))
+#define ioremap_wc(addr, size) ioremap((addr), (size))
Quoted 8 lines
Quoted 1 line

+#define ioremap_wt(addr, size) ioremap((addr), (size))

Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and ioremap_wc() gets used for by memremap() for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags

Quoted 5 lines

This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.

Ok. Maybe add that as a comment above these definitions then.

Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9 -0
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct resides at the bottom of the supervisor stack
+ * - if the members of this struct changes, the assembly constants
+ *   in asm-offsets.c must be updated accordingly
+ */
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
Quoted 8 lines

arch/riscv/include/asm/io.h

Quoted 5 lines
arch/riscv/include/asm/io.h new file +5 -0
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current CPU */
+       int                     preempt_count;  /* 0 => preemptable, <0 => BUG */
+       mm_segment_t            addr_limit;
+};

Please see 15f4eae70d36 ("x86: Move thread_info into task_struct") and try to do the same.

OK, here's my attempt

https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd

Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)

"
This is patterned more off the arm64 move than the x86 one, since we still need to have at least addr_limit to emulate FS.

Quoted 7 lines

The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to task_struct. thread_info must be at a 0 offset from task_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP in task_struct, but those are really acting more as extra scratch space than pemanent storage.
"

I haven't looked at all the details of the x86 patch, but it seems they decided to put the arch specific members into 'struct thread_struct' rather than 'struct thread_info', so I'd suggest you do the same here for consistency, unless there is a strong reason against doing it.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6 -0
+#else /* !CONFIG_MMU */
+
+static inline void flush_tlb_all(void)
+{
+       BUG();
+}
Quoted 8 lines

arch/riscv/include/asm/io.h

Quoted 5 lines
arch/riscv/include/asm/io.h new file +5 -0
+
+static inline void flush_tlb_mm(struct mm_struct *mm)
+{
+       BUG();
+}

The NOMMU support is rather incomplete and CONFIG_MMU is hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.

Quoted 5 lines

OK. I've left in the "#ifdef CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.

https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067

Ok.

Quoted 11 lines
Quoted 10 lines

arch/riscv/include/asm/io.h

Quoted 6 lines
arch/riscv/include/asm/io.h new file +6 -0
+#include <asm-generic/unistd.h>
+
+#define __NR_sysriscv  __NR_arch_specific_syscall
+#ifndef __riscv_atomic
+__SYSCALL(__NR_sysriscv, sys_sysriscv)
+#endif

Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on __riscv_atomic rather than the Kconfig symbol?

Quoted 6 lines

I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.

I can change this to two system calls: sysriscv_cmpxchg32 and sysriscv_cmpxchg64.

Sounds good.

Arnd

author maintainer
#56 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann
Quoted 1 line

+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);

Please move the majority of this file into drivers/irqchip as a standalone driver.

OK.

https://github.com/riscv/riscv-linux/commit/549c7f5ef63d7be04c9cac7e332ef81ec6ffe103

Quoted 50 lines
Quoted 31 lines
arch/riscv/kernel/pci.c new file +25 -0
new file mode 100644
index 000000000000..4191a5ffdd67
@@ -0,0 +1,36 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c
+ *
+ * Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM
+ * Copyright (C) 2014 ARM Ltd.
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+
+/*
+ * Called after each bus is probed, but before its children are examined
+ */
+void pcibios_fixup_bus(struct pci_bus *bus)
+{

arch/riscv/kernel/pci.c line 35

Quoted 10 lines
arch/riscv/kernel/pci.c new file +10 -0
+       /* nothing to do, expected to be removed in the future */
+}
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here
+ */
+resource_size_t pcibios_align_resource(void *data, const struct resource *res,
+                               resource_size_t size, resource_size_t align)
+{
+       return res->start;
+}

Can you add a patch to remove the need for this, and send that to the PCI maintainers?

In the long run, I think we want both of these to be pci host bridge driver specific callbacks rather than per-architecture definitions, but for the moment, moving the empty version as a __weak copy into drivers/pci/ should be sufficient.

Quoted 4 lines

[note: don't ever use __weak elsewhere, the use in PCI is
only done for historic reasons and we want to get rid of that too, but for now it's more important to avoid adding yet another pointless copy]

Sounds good

https://github.com/riscv/riscv-linux/commit/4aa540bf849b2a190e288e7d25d262dee21306b3
https://github.com/riscv/riscv-linux/commit/bb3b4c6ca4841538d101f2b9c437f5dccda0b3a7

Quoted 2 lines

If you don't care about LPC/ISA devices, then your PCI_MIN_IO should also be zero instead of 0x1000

Sorry, but the only Google results for PCI_MIN_IO is this email. There don't appear to be any relevant references to PCI_MIN in the kernel

  $ git grep PCI_MIN_
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:      ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT                 0x00
  drivers/ata/pata_hpt366.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt37x.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt3x2n.c:     pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ide/hpt366.c:   pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT     0x3e    /*  8 bit       Min_Gnt */
  drivers/net/fddi/skfp/h/skfbi.h:/*      PCI_MIN_GNT     8 bit   Min_Gnt */
  include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT               0x3e    /* 8 bits */

I'm afraid that I'm not sure what to do here.

Quoted 10 lines

arch/riscv/kernel/plic.c

Quoted 5 lines
arch/riscv/kernel/plic.c new file +0 -0
new file mode 100644
index 000000000000..5b3d4241f4e2

drivers/irqchip/riscv-plic.c

The file needs some work for following coding style, once that is done, please submit to the irqchip maintainers.

I've addressed most of this thanks to some other code reviews, so I'm going to drop the comments that are about things I've already fixed.

Quoted 5 lines
Quoted 1 line

+// TODO: add a /sys interface to set priority + per-hart enables for steering

No driver-private sysfs interfaces please for irqchips please.
See http://elixir.free-electrons.com/linux/latest/source/Documentation/IRQ-affinity.txt
for setting the affinity.

We'll do it the right way when we add IRQ affinity control. Thanks for the heads up!

Quoted 40 lines
Quoted 20 lines
arch/riscv/kernel/reset.c new file +14 -0
new file mode 100644
index 000000000000..58bad9598e21
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+

arch/riscv/kernel/reset.c line 24

Quoted 10 lines
arch/riscv/kernel/reset.c new file +10 -0
+#include <linux/reboot.h>
+#include <linux/export.h>
+#include <asm/sbi.h>
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_restart(char *cmd)
+{
+}

Call do_kernel_restart(cmd) here.

arch/riscv/kernel/reset.c line 28

Quoted 3 lines
arch/riscv/kernel/reset.c new file +3 -0
+void machine_halt(void)
+{
+}

This should not return. Either make it call sbi_shutdown as well, or use the ARM implementation:

Quoted 6 lines

void machine_halt(void)

{
        local_irq_disable();
        smp_send_stop();
        while (1);
}

OK.

https://github.com/riscv/riscv-linux/commit/5f486cb73e3a0a5a218d26781e9eae651e59203f

Quoted 7 lines

arch/riscv/kernel/sbi-con.c

Quoted 5 lines
arch/riscv/kernel/sbi-con.c new file +0 -0
new file mode 100644
index 000000000000..86baeb5ef0cd

As Olof said, move it to drivers/tty/hvc/ and use those helpers.

Ah, that's great: now there's almost no code left :)

https://github.com/riscv/riscv-linux/commit/8adad12c5525a70b8837196b8f2d4ac003a7647c

Quoted 40 lines
Quoted 40 lines
arch/riscv/kernel/sys_riscv.c new file +34 -0
new file mode 100644
index 000000000000..3e07308e24f5
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2014 Darius Rad <[email protected]>
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *   NON INFRINGEMENT.  See the GNU General Public License for
+ *   more details.
+ */
+
+#include <linux/syscalls.h>
+#include <asm/unistd.h>
+
+SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
+       unsigned long, prot, unsigned long, flags,
+       unsigned long, fd, off_t, offset)
+{
+       if (unlikely(offset & (~PAGE_MASK)))
+               return -EINVAL;
+       return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+}
+
+#ifndef CONFIG_64BIT
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+       unsigned long, prot, unsigned long, flags,
+       unsigned long, fd, off_t, offset)
+{
+       /* Note that the shift for mmap2 is constant (12),
+          regardless of PAGE_SIZE */
Quoted 8 lines

arch/riscv/kernel/sys_riscv.c line 40

Quoted 6 lines
arch/riscv/kernel/sys_riscv.c new file +6 -0
+       if (unlikely(offset & (~PAGE_MASK >> 12)))
+               return -EINVAL;
+       return sys_mmap_pgoff(addr, len, prot, flags, fd,
+               offset >> (PAGE_SHIFT - 12));
+}
+#endif /* !CONFIG_64BIT */

The first one should be CONFIG_64BIT only.

OK. https://github.com/riscv/riscv-linux/commit/ed7545c6765ba7d705e1bc6ce7b67bb7e8cb0926

Quoted 31 lines
Quoted 16 lines
arch/riscv/kernel/sys_riscv.c new file +16 -0
+#ifdef CONFIG_RV_SYSRISCV_ATOMIC
+SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1,
+       unsigned long, arg2, unsigned long, arg3)
+{
+       unsigned long flags;
+       unsigned long prev;
+       unsigned int *ptr;
+       unsigned int err;
+
+       switch (cmd) {
+       case RISCV_ATOMIC_CMPXCHG:
+               ptr = (unsigned int *)arg1;
+               if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned int)))
+                       return -EFAULT;
+
+               preempt_disable();

arch/riscv/kernel/sys_riscv.c line 67

Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10 -0
+               raw_local_irq_save(flags);
+               err = __get_user(prev, ptr);
+               if (likely(!err && prev == arg2))
+                       err = __put_user(arg3, ptr);
+               raw_local_irq_restore(flags);
+               preempt_enable();
+
+               return unlikely(err) ? err : prev;
+
+       case RISCV_ATOMIC_CMPXCHG64:

Make these two separate syscalls and get rid of the wrapper (I already mentioned it in the header file comments, but it fits better here).

Quoted 3 lines

It may be good to have an optimized version in the vdso that does an atomic operation directly if the CPU supports it.

Yep. It's on the list.

Quoted 8 lines

arch/riscv/kernel/time.c

Quoted 5 lines
arch/riscv/kernel/time.c new file +0 -0
new file mode 100644
index 000000000000..ce8c459fadaa

drivers/clocksource/riscv-timer.c, and submit it to the respective maintainers.

Sounds good.

https://github.com/riscv/riscv-linux/commit/d9fcab4603c158755e19663dec0040b28ea1aad1

author maintainer
#31 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Benjamin Herrenschmidt
Quoted 8 lines · On Tue, 23 May 2017 14:23:50 PDT (-0700), [email protected] wrote:
Quoted 7 lines · Arnd Bergmann

arch/riscv/include/asm/io.h line 18

Quoted 2 lines
arch/riscv/include/asm/io.h new file +2 -0
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 5 lines
Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Right, I was about to comment on that one.

Well, you're both correct: what was there just isn't correct. Our implementations were safe because they don't have aggressive MMIO systems, but that won't remain true for long.

I've gone ahead and added a proper IO implementation patterned on arm64. It'll be part of the v2 patch set. Here's the bulk of the patch, if you're curious

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

Quoted 5 lines

The question Palmer is about the ordering semantics of non-cached storage.

What kind of ordering is provided architecturally ? Especially between cachable and non-cachable loads and stores ?

The memory model on RISC-V is pretty weak. Without fences there are no ordering constraints. We provide 2 "ordering spaces" (an odd name I just made up, there's one address space): the IO space and the regular memory space. The base RISC-V ordering primitive is a fence, which takes a predecessor set and successor set. Fences can look like

fence IORW,IORW

where the left side is the predecessor set and the right side is the successor set. The fence enforces ordering between any operations in the two sets: all operations in the predecessor set must be globally visible before any operation in the successor set becomes visible anywhere.

For example, if you're emitting a DMA transaction you'd have to do something like

build_message_in_memory()
fence w,o
set_control_register()

with the fence ensuring all the memory writes are visible before the control register write.

More information can be found in the ISA manuals

https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user-2.2/riscv-spec-v2.2.pdf
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-priv-1.10/riscv-privileged-v1.10.pdf

Quoted 7 lines

Also, you have PCIe right ? What is the behaviour of MSIs ?

Does your HW provide a guarantee that in the case of a series of DMA writes to memory by a device followed by an MSI, the CPU getting the MSI will only get it after all the previous DMA writes have reached coherency ? (Unlike LSIs where the driver is required to do an MMIO read from the device, MSIs are expected to be ordered with data).

We do have PCIe, but I'm not particularly familiar with it as I haven't spent any time hacking on our PCIe hardware or driver. My understanding here is that PCIe defines that MSIs must not be reordered before the DMA writes, so the implementation is required to enforce this ordering. Thus it's a problem for the PCIe controller implementation (which isn't covered by RISC-V) and therefor doesn't need any ordering enforced by the driver.

If I'm correct in the assumption that the hardware is required to enforce these ordering constraints then I think this isn't a RISC-V issue. I'll go bug our PCIe guys to make sure everything is kosher in that case, but it's an ordering constraint that is possible to enforce in our coherence protocol so it's not a fundamental problem (and just an implementation one at that).

If the hardware isn't required to enforce the ordering, then we'll need a fence before handling the data.

Quoted 19 lines

Another things with the read*() accessors. It's not uncommon for a driver to do:

	writel(1, reset_reg);
	readl(reset_reg); /* flush posted writes */
	udelay(10);
	writel(0, reset_reg);

Now, in the above case, what can typically happen if you aren't careful is that the readl which is intended to "push" the previous writel, will not actually do its job because the return value hasn't been "consumed" by the processor. Thus, the CPU will stick that on some kind of load queue and won't actually wait for the return value before hitting the delay loop.

Thus you might end up in a situation where the writel of 1 to the device is itself reaching the device way after you started the delay loop, and thus end up violating the delay requirement of the HW.

Quoted 5 lines

On powerpc we solve that by using a special instruction construct inside the read* accessors that prevents the CPU from executing subsequent instructions until the read value has been returned.

You may want to consider something similar.

Ooh, that's a fun one :). I bugged Andrew (the ISA wizard), and this might
require some clarification in the ISA manual. The code we emit will look something like

fence io,o
st 1, RESET_REG
ld RESET_REG
fence o,io
loop:
rdtime
blt loop
fence io,o
st 0, RESET_REG

Since the fences just enforce ordering between the loads and stores, there's nothing that prevents the processor from releasing the store before the delay loop completes. I think we might be safe here because you're not allowed to make speculative writes visible, but arguably that's not a speculative write because you can predict the timer will keep increasing. The distinction is somewhat academic, though: I'm not sure what purpose that very specific sort of predictor would have aside from breaking existing code.

This issue of "how is time ordered" has come up a handful of times, most of which don't have the loop. The idea of adding the result rdtime instruction to the IO space. I've opened a spec bug

https://github.com/riscv/riscv-isa-manual/issues/78

Thanks!

author maintainer
#60 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Pavel Machek
Quoted 5 lines · On Thu, 25 May 2017 10:05:05 PDT (-0700), [email protected] wrote:
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5 -0
+static void ci_leaf_init(struct cacheinfo *this_leaf,
+                         struct device_node *node,
+                         enum cache_type type, unsigned int level)
+{
+        this_leaf->of_node = node;
Quoted 8 lines

arch/riscv/kernel/cacheinfo.c line 29

Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5 -0
+        this_leaf->level = level;
+        this_leaf->type = type;
+        this_leaf->physical_line_partition = 1; // not a sector cache
+        this_leaf->attributes = CACHE_WRITE_BACK | CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE; // TODO: add to DTS
+}

You may want to run the patches through checkpatch. (Comment style, long lines).

Thanks. Someone else suggested this and I've fixed most of the errors. I'll submit a v2 with everyone's feedback once I get through my mail.

author maintainer
#52 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 5 lines · Palmer Dabbelt

On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:

* Parens around single-statement __asm__ macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.

I would generally recommend using inline functions for those, and only do macros when you need them.

We've tried to avoid new macros, so these are mostly from places where other architectures use macros (like mb) or where we need to use CPP token pasting (like __op_bit). Should I change things like mb?

Quoted 10 lines
Quoted 3 lines

* Parens around macros like "#define RISCV_PTR .dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.

agreed

Quoted 3 lines

* Warnings about volatile in function declarations in bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.

Quoted 7 lines

Agreed, bitops.h is one of the few headers that should use 'volatile'.

Quoted 2 lines

* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.

What is the warning here? I would assume that you should leave this unchanged as well.

ERROR: #define of 'ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - use Kconfig variables or standard guards instead #2533: FILE: arch/riscv/include/asm/elf.h:79:
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES

Quoted 6 lines
Quoted 2 lines

* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).

It depends. What typedefs are those? Removing the typedefs in both the kernel and the other code that uses the same types is likely the best option here.

OK, I'll add it to my TODO list.

Quoted 11 lines
Quoted 2 lines

* A handful of lines over 80 characters that I think are onerous to break any more.

Right, don't worry about it too much, and use common sense for this warning.

Quoted 3 lines

* Some warnings about printk() not having a KERN_ prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (in show_regs, for example, where arm64 also has them).

KERN_CONT

https://github.com/riscv/riscv-linux/commit/98e8fe9cb19d495180a9be03a0aa48c0183dd5be

Quoted 6 lines
Quoted 2 lines

* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.

I would try to fix those by using a header even if there is only one user. I'd actually like to get a compile-time warning for those in the long run, maybe with 'make W=1', so better don't introduce new ones.

OK, I'll fix them.

author maintainer
#43 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Quoted 6 lines

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

Quoted 7 lines

+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }

You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.

The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is

Quoted 1 line

=2ms, so the division won't cost much in comparison.

The normal case should have no division in it.

I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.

Quoted 2 lines

Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.

That makes sense, I just based this blindly off the ARM version. I'll see if that lets me avoid unnecessary overflow for ndelay. If it doesn't then I'd prefer to just keep exactly the same constraints ARM has to avoid unexpected behavior.

author maintainer
#22 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Arnd Bergmann
Quoted 41 lines · Arnd Bergmann
Quoted 30 lines · Palmer Dabbelt
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +13 -0
new file mode 100644
index 000000000000..510ead1d3343
@@ -0,0 +1,300 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+       def_bool y
+       select OF
+       select OF_EARLY_FLATTREE
+       select OF_IRQ
+       select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_WANT_FRAME_POINTERS
+       select CLONE_BACKWARDS
Quoted 8 lines

arch/riscv/Kconfig line 18

Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+       select COMMON_CLK
+       select GENERIC_CLOCKEVENTS
+       select GENERIC_CPU_DEVICES
+       select GENERIC_IRQ_SHOW
+       select GENERIC_PCI_IOMAP

You normally don't want GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()

Quoted 2 lines

We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.

Ah, interesting. What is the exact behavior of that fence? (this is slightly unrelated but worth looking at anyway)

Quoted 4 lines

It looks like most of my candidates for patterning things after use GENERIC_PCI_IOMAP, but I ended up setting GENERIC_IOMAP and things still at least build and boot without any PCI

Quoted 8 lines
Quoted 4 lines

https://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e

I'll be sure to check if I broke PCI, as I don't actually know what's going on here.

Actually I made a mistake: GENERIC_PCI_IOMAP is fine, please use that, GENERIC_IOMAP is the option you don't want, and you already don't enable that one.

Great -- I actually ended up reverting the patch already as I couldn't figure out how to make it work. That was the one big thing on my TODO list before a v2, so with any luck I'll be able to get a new patch set out soon.

Quoted 24 lines
Quoted 16 lines
Quoted 16 lines

arch/riscv/Kconfig line 45

Quoted 6 lines
arch/riscv/Kconfig new file +6 -0
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+       def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+       def_bool y

Are you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit dma_addr_t and phys_addr_t when possible makes some code noticeably more efficient.

Quoted 4 lines
arch/riscv/Kconfig new file +4 -0
+config PGTABLE_LEVELS
+       int
+       default 3 if 64BIT
+       default 2
Quoted 7 lines
Quoted 3 lines

With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.

We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.

Quoted 5 lines

I'd suggest to leave it turned off initially and only use it once someone actually builds a system that makes use of the high address space.

Of course if there is already hardware that needs it, there has to be a way to turn it on.

There isn't, and I'm find with 32-bit physical addresses on RV32I. I doubt anyone will be building big RV32 systems. I'll make the change for the v2.

Quoted 9 lines

This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:

- Every major platform gets a Kconfig option in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)

Quoted 7 lines

- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.

On ARM, we have a bit of both, which is not as good as being consistent one way or another.

This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform Kconfig menu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.

For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.

Quoted 27 lines
Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y
+
+config RV_SYSRISCV_ATOMIC

arch/riscv/Kconfig line 152

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:

Quoted 3 lines

That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.

I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.

Quoted 8 lines
Quoted 6 lines

The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.

I'll add it to my TODO list.

This would be another variant of the question above.

After talking with people a bit about this, I think the sane thing to do here is to just always provide the atomic system call (and VDSO implementation), and to default to enabling the atomic extensions. While I expect non-atomic implementations to be very much the exception, there's a stronger argument for supporting non-atomic userspace programs with reasonable performance on atomic systems -- the first round of small Linux-capable embedded systems might not support atomic (though ours will), but we don't want to wed software to a syscall in this case.

Before the VDSO was suggested I was leaning towards disabling the atomic system call by default, but since the VDSO implementation will provide very good performance for non-atomic userspace code on atomic systems I think it's best to just enable it everywhere. It's only a few bytes of binary size.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

arch/riscv/Kconfig line 211

Quoted 8 lines
arch/riscv/Kconfig new file +8 -0
+config PCI_DOMAINS
+       def_bool PCI
+
+config PCI_DOMAINS_GENERIC
+       def_bool PCI
+
+config PCI_SYSCALL
+       def_bool PCI

I don't think you want PCI_SYSCALL

Quoted 5 lines
Quoted 2 lines

OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens

I'd argue that's a user space bug that we want to fix anyway to make the code portable to other architectures.

I buy it.

author maintainer
#5 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Arnd Bergmann
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

I don't think that does the same thing. The desired effect of this diff is:

* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.

Quoted 6 lines

* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.

* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.

Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.

Quoted 35 lines

Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this

Makefile +2 -9
index 0606f28..4adc609 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+                                 -e s/riscv.*/riscv/ )
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
-# Additional ARCH settings for RISC-V
-ifeq ($(ARCH),riscv32)
-       SRCARCH := riscv
-endif
-ifeq ($(ARCH),riscv64)
-       SRCARCH := riscv
-endif
-
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc
Quoted 6 lines
Quoted 2 lines

then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.

Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on CONFIG_64BIT.

OK, I didn't know about COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.

author maintainer
#34 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Arnd Bergmann
Quoted 27 lines · Arnd Bergmann
Quoted 14 lines · Palmer Dabbelt
Quoted 12 lines · Arnd Bergmann

arch/riscv/include/asm/cache.h line 21

Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/cache.h new file +6 -0
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT         6
+
+#define L1_CACHE_BYTES         (1 << L1_CACHE_SHIFT)

Is this the only valid cache line size on riscv, or just the largest one that is allowed?

Quoted 7 lines

The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.

We could always make this a Kconfig parameter.

The cache line size is used in a couple of places, let's go through the most common ones to see where that abstraction might be leaky and you actually get an architectural effect:

Quoted 6 lines

- On SMP machines, ____cacheline_aligned_in_smp is used to annotate data structures used in lockless algorithms, typically with one CPU writing to some members of a structure, and another CPU reading from it but not writing the same members. Depending on the architecture, having a larger actual alignment than L1_CACHE_BYTES will either lead to bad performance from cache line ping pong, or actual data corruption.

On RISC-V it's just a performance problem, so at least it's not catastrophic.

Quoted 11 lines

- On systems with DMA masters that are not fully coherent, ____cacheline_aligned is used to annotate data structures used for DMA buffers, to make sure that the cache maintenance operations in dma_sync_*_for_*() helpers don't corrup data outside of the DMA buffer. You don't seem to support noncoherent DMA masters or the cache maintenance operations required to use those, so this might not be a problem until someone adds an extension for those.

- Depending on the bus interconnect, a coherent DMA master might not be able to update partial cache lines, so you need the same annotation.

Well, our (SiFive's) bus is easy to master so hopefully we won't end up doing that. There is, of course, the rest of the world -- but that's just a bridge we'll have to cross later (if such an implementation arises).

Quoted 2 lines

- The kmalloc() family of memory allocators aligns data to the cache line size, for both DMA and SMP synchronization above.

Ya, but luckily just a performance problem on RISC-V.

Quoted 5 lines

- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.

We actually have an implicit prefetch (loads to x0, the zero register), but it still has all the load side-effects so nothing uses it.

Quoted 3 lines

Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.

I bugged our L1 guy and he says 64-byte lines are a bit of a magic number because of how they line up with DIMMs. Since there's no spec to define this, there's no correct answer. I'd be amenable to making this a Kconfig option, but I think we'll leave it alone for now. It does match the extant implementations.

Quoted 41 lines
Quoted 28 lines
Quoted 16 lines

arch/riscv/include/asm/io.h line 18

Quoted 11 lines
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

where I think the only odd thing is our definition of mmiowb

Quoted 12 lines

+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");

Quoted 7 lines

Looks ok, yes.

Quoted 3 lines
  +#define mmiowb()                __asm__ __volatile__ ("fence io,io" : : : "memory");

which I think is correct.

I can never remember what exactly this one does.

I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by

https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to use mmiowb()?
AFAICT, they're both right. Generally, mmiowb() should be used prior to unlock in a critical section whose last PIO operation is a writeX.

Thus, I think the actual fence should be at least

fence o,w

Documentation/memory-barries.txt says

"
The Linux kernel also has a special barrier for use with memory-mapped I/O writes:

  	mmiowb();

This is a variation on the mandatory write barrier that causes writes to weakly ordered I/O regions to be partially ordered. Its effects may go beyond the CPU->Hardware interface and actually affect the hardware at some level.

See the subsection "Acquires vs I/O accesses" for more information. "

"
ACQUIRES VS I/O ACCESSES
------------------------

Under certain circumstances (especially involving NUMA), I/O accesses within two spinlocked sections on two different CPUs may be seen as interleaved by the PCI bridge, because the PCI bridge does not necessarily participate in the cache-coherence protocol, and is therefore incapable of issuing the required read memory barriers.

For example:

  	CPU 1				CPU 2
  	===============================	===============================
  	spin_lock(Q)
  	writel(0, ADDR)
  	writel(1, DATA);
  	spin_unlock(Q);
  					spin_lock(Q);
  					writel(4, ADDR);
  					writel(5, DATA);
  					spin_unlock(Q);

may be seen by the PCI bridge as follows:

STORE *ADDR = 0, STORE *ADDR = 4, STORE *DATA = 1, STORE *DATA = 5

which would probably cause the hardware to malfunction.

What is necessary here is to intervene with an mmiowb() before dropping the spinlock, for example:

  	CPU 1				CPU 2
  	===============================	===============================
  	spin_lock(Q)
  	writel(0, ADDR)
  	writel(1, DATA);
  	mmiowb();
  	spin_unlock(Q);
  					spin_lock(Q);
  					writel(4, ADDR);
  					writel(5, DATA);
  					mmiowb();
  					spin_unlock(Q);

this will ensure that the two stores issued on CPU 1 appear at the PCI bridge before either of the stores issued on CPU 2.

Furthermore, following a store by a load from the same device obviates the need for the mmiowb(), because the load forces the store to complete before the load is performed:

  	CPU 1				CPU 2
  	===============================	===============================
  	spin_lock(Q)
  	writel(0, ADDR)
  	a = readl(DATA);
  	spin_unlock(Q);
  					spin_lock(Q);
  					writel(4, ADDR);
  					b = readl(DATA);
  					spin_unlock(Q);

See Documentation/driver-api/device-io.rst for more information. "

which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

arch/riscv/include/asm/io.h line 28

Quoted 9 lines
arch/riscv/include/asm/io.h new file +9 -0
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MMU
+
+extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
+
+#define ioremap_nocache(addr, size) ioremap((addr), (size))
+#define ioremap_wc(addr, size) ioremap((addr), (size))
+#define ioremap_wt(addr, size) ioremap((addr), (size))

Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and ioremap_wc() gets used for by memremap() for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags

Quoted 7 lines
Quoted 5 lines

This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.

Ok. Maybe add that as a comment above these definitions then.

OK.

Quoted 37 lines
Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9 -0
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct resides at the bottom of the supervisor stack
+ * - if the members of this struct changes, the assembly constants
+ *   in asm-offsets.c must be updated accordingly
+ */
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
Quoted 8 lines

arch/riscv/include/asm/io.h

Quoted 5 lines
arch/riscv/include/asm/io.h new file +5 -0
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current CPU */
+       int                     preempt_count;  /* 0 => preemptable, <0 => BUG */
+       mm_segment_t            addr_limit;
+};

Please see 15f4eae70d36 ("x86: Move thread_info into task_struct") and try to do the same.

OK, here's my attempt

https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd

Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)

"
This is patterned more off the arm64 move than the x86 one, since we still need to have at least addr_limit to emulate FS.

Quoted 7 lines

The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to task_struct. thread_info must be at a 0 offset from task_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP in task_struct, but those are really acting more as extra scratch space than pemanent storage.
"

Quoted 4 lines

I haven't looked at all the details of the x86 patch, but it seems they decided to put the arch specific members into 'struct thread_struct' rather than 'struct thread_info', so I'd suggest you do the same here for consistency, unless there is a strong reason against doing it.

We actually can't put them in "struct thread_struct" in a sane manner. On context switches on RISC-V there are no register saved, instead we use the instructions

csrrw REG, sscratch, REG

which swaps some register (used to be sp, now tp) with the "sscratch" CSR (a register only visible to the supervisor). At this point we only have one register to work with in order to save the user state. Since "struct thread_info" is 0-offset from "struct task_struct", we're guaranteed to be able to access it using our one addressing mode (a 12-bit signed constant offset from a register).

Unfortunately, "struct thread_struct" is at a potentially large offset from the saved TP. We could do something silly like

addi tp, tp, OFFSET_1
addi tp, tp, OFFSET_2
addi tp, tp, OFFSET_3

but for an "allyesconfig" we end up with offsets of about 9KiB, which would require 4 additional instructions to find "struct thread_struct". While this is possible, I'd prefer to avoid the extra cycles. We usually handle long immediate with a two-instruction sequence

li REG, IMM31-12 (loads the high bits of REG, zeroing the low bits) addi REG, REG, IMM11-0 (loads the low bits of REG, leaving the high bits alone)

but there's no scratch register here so we can't use that. We don't have a long-immediate-add instruction.

The arguments in x86 land for moving everything to "struct thread_struct" were that they always know it's in "struct task_struct", but since that's all we're supporting on RISC-V I don't think it counts. There were also discussions of eliminating "struct thread_info", but unless there's something at the start of "struct task_struct" then RISC-V will have to pay a bunch of cycles on a context switch.

Quoted 44 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6 -0
+#else /* !CONFIG_MMU */
+
+static inline void flush_tlb_all(void)
+{
+       BUG();
+}
Quoted 8 lines

arch/riscv/include/asm/io.h

Quoted 5 lines
arch/riscv/include/asm/io.h new file +5 -0
+
+static inline void flush_tlb_mm(struct mm_struct *mm)
+{
+       BUG();
+}

The NOMMU support is rather incomplete and CONFIG_MMU is hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.

Quoted 5 lines

OK. I've left in the "#ifdef CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.

https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067

Ok.

Quoted 11 lines
Quoted 10 lines

arch/riscv/include/asm/io.h

Quoted 6 lines
arch/riscv/include/asm/io.h new file +6 -0
+#include <asm-generic/unistd.h>
+
+#define __NR_sysriscv  __NR_arch_specific_syscall
+#ifndef __riscv_atomic
+__SYSCALL(__NR_sysriscv, sys_sysriscv)
+#endif

Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on __riscv_atomic rather than the Kconfig symbol?

Quoted 6 lines

I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.

I can change this to two system calls: sysriscv_cmpxchg32 and sysriscv_cmpxchg64.

Sounds good.

Arnd

maintainer
#35 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

Quoted 17 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 2 lines · Palmer Dabbelt
Quoted 1 line · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.

We actually have an implicit prefetch (loads to x0, the zero register), but it still has all the load side-effects so nothing uses it.

Quoted 3 lines

Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.

Quoted 5 lines

I bugged our L1 guy and he says 64-byte lines are a bit of a magic number because of how they line up with DIMMs. Since there's no spec to define this, there's no correct answer. I'd be amenable to making this a Kconfig option, but I think we'll leave it alone for now. It does match the extant implementations.

Hmm, this sounds like a hole in the architecture definition: if you have an instruction that performs a prefetch (even one that is not easily usable), I would argue that the cache line size has become a feature of the architecture and is no longer strictly an implementation detail of the microarchitecture.

Regarding the memory interface, a lot of systems use two DIMMs on each memory channel for 128-bit parallel buses, and with LP-DDRx controllers, you might have a width as small as 16 bits.

Quoted 63 lines
Quoted 41 lines
Quoted 28 lines
Quoted 16 lines

arch/riscv/include/asm/io.h line 18

Quoted 11 lines
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

where I think the only odd thing is our definition of mmiowb

Quoted 12 lines

+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");

Quoted 7 lines

Looks ok, yes.

Quoted 3 lines
  +#define mmiowb()                __asm__ __volatile__ ("fence io,io" : : : "memory");

which I think is correct.

I can never remember what exactly this one does.

I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by

https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to use mmiowb()?
AFAICT, they're both right. Generally, mmiowb() should be used prior to unlock in a critical section whose last PIO operation is a writeX.

Thus, I think the actual fence should be at least

fence o,w

...

Quoted 2 lines

which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.

This sounds reasonable according to the documentation, but with your longer explanation of the barriers, I think the __iormb/__iowmb definitions above are wrong. What you actually need I think is

void writel(u32 v, volatile void __iomem *addr)

{
         asm volatile("fence w,o" : : : "memory");
         writel_relaxed(v, addr);
}

u32 readl(volatile void __iomem *addr)

{
         u32 ret = readl_relaxed(addr);
         asm volatile("fence i,r" : : : "memory");
         return ret;
}

to synchronize between DMA and I/O. The barriers you listed above in contrast appear to be directed at synchronizing I/O with other I/O. We normally assume that this is not required when you have subsequent MMIO accesses on the same device (on PCI) or the same address region (per ARM architecture and others). If you do need to enforce ordering between MMIO, you might even need to add those barriers in the relaxed version to be portable with drivers written for ARM SoCs:

void writel_relaxed(u32 v, volatile void __iomem *addr)

{
        __raw_writel((__force u32)cpu_to_le32(v, addr)
         asm volatile("fence o,io" : : : "memory");
}

u32 readl_relaxed(volatile void __iomem *addr)

{
         asm volatile("fence i,io" : : : "memory");
         return le32_to_cpu((__force __le32)__raw_readl(addr));
}

You then end up with a barrier before and after each regular readl/writel in order to synchronize both with DMA and MMIO instrictructions, and you still need the extre mmiowb() to synchronize against the spinlock.

My memory on mmiowb is still a bit cloudy, but I think we don't need that on ARM, and while PowerPC originally needed it, it is now implied by the spin_unlock(). If this is actually right, you might want to do the same here. Very few drivers actually use mmiowb(), but there might be more drivers that would need it if your spin_unlock() doesn't synchronize against writel() or writel_relaxed(). Maybe it the mmiowb() should really be implied by writel() but not writel_relaxed()? That might be sensible, but only if we do it the same way on powerpc, which currently doesn't have writel_relaxed() any more relaxed than writel()

Quoted 6 lines

The arguments in x86 land for moving everything to "struct thread_struct" were that they always know it's in "struct task_struct", but since that's all we're supporting on RISC-V I don't think it counts. There were also discussions of eliminating "struct thread_info", but unless there's something at the start of "struct task_struct" then RISC-V will have to pay a bunch of cycles on a context switch.

Ok. Since you have THREAD_INFO_IN_TASK, it probably doesn't matter too much then, it's just a bit inconsistent with the other architectures, but the effect is the same, so just do it the way that is more efficient for you.

Arnd

maintainer
#57 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
Quoted 19 lines · Palmer Dabbelt
Quoted 3 lines · Arnd Bergmann
Quoted 1 line

+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);

If you don't care about LPC/ISA devices, then your PCI_MIN_IO should also be zero instead of 0x1000

Sorry, but the only Google results for PCI_MIN_IO is this email. There don't appear to be any relevant references to PCI_MIN in the kernel

  $ git grep PCI_MIN_
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:      ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT                 0x00
  drivers/ata/pata_hpt366.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt37x.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt3x2n.c:     pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ide/hpt366.c:   pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT     0x3e    /*  8 bit       Min_Gnt */
  drivers/net/fddi/skfp/h/skfbi.h:/*      PCI_MIN_GNT     8 bit   Min_Gnt */
  include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT               0x3e    /* 8 bits */
Quoted 1 line

I'm afraid that I'm not sure what to do here.

Sorry, I meant PCIBIOS_MIN_IO

Arnd

maintainer
#53 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Palmer Dabbelt
Quoted 7 lines · Palmer Dabbelt
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Palmer Dabbelt

On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:

* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.

Quoted 6 lines
Quoted 2 lines

What is the warning here? I would assume that you should leave this unchanged as well.

ERROR: #define of 'ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - use Kconfig variables or standard guards instead #2533: FILE: arch/riscv/include/asm/elf.h:79:
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES

Ok, you can definitely ignore this one. The warning is meant to prevent adding new macros like that, but the macro already exists in the other architectures, and I see no point in converting them all into a CONFIG_ symbol.

Arnd

maintainer
#23 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Palmer Dabbelt
Quoted 31 lines · Palmer Dabbelt
Quoted 11 lines · Arnd Bergmann
Quoted 1 line · Palmer Dabbelt

On Tue, 23 May 2017 04:46:22 PDT (-0700), Arnd Bergmann wrote:

This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:

- Every major platform gets a Kconfig option in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)

Quoted 7 lines

- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.

On ARM, we have a bit of both, which is not as good as being consistent one way or another.

This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform Kconfig menu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.

Quoted 4 lines

For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.

Ok. Another related point, which may or may not be obvious: when you come up with platform definitions, they should not be mutually exclusive.

For instance, supporting both MMU/NOMMU, big/little-endian or 32/64-bit kernels will of course require building separate binaries, but almost every other configuration option should be backward compatible: An SMP kernel should run on a uniprocessor machine and vice versa (using only one CPU), and you should be able to run a kernel with support multiple instruction set revisions by restricting the build to the smallest subset of instructions.

On older ARM platforms and most MIPS platforms, we are still restricted to building a kernel binary that will only run on a particular SoC family and not even another SoC with the same CPU core. Fixing this for most ARM platforms required a lot of work that you should avoid by requiring them all to work with a common kernel from the start.

Similarly, ARM has an incompatibility that prevents us from running on older (ARMv4/v5) along with newer (ARMv6 or higher) instruction set versions with a single kernel. Avoiding this on RISC-V may become challenging as one of the strengths of the architecture is its flexibility: Someone may come up with their own architecture extensions that they really want to support in the kernel but can't get it to work without making the kernel binary incompatible with other implementations. Do you already have a policy for how to deal with this? Usually by the time someone ships hardware, it's too late and it becomes hard to argue for their kernel port to not get merged.

Quoted 45 lines
Quoted 27 lines
Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5 -0
+config RV_ATOMIC
+       bool "Use atomic memory instructions (RV32A or RV64A)"
+       default y
+
+config RV_SYSRISCV_ATOMIC

arch/riscv/Kconfig line 152

Quoted 10 lines
arch/riscv/Kconfig new file +10 -0
+       bool "Include support for atomic operation syscalls"
+       default n
+       help
+         If atomic memory instructions are present, i.e.,
+         CONFIG_RV_ATOMIC, this includes support for the syscall that
+         provides atomic accesses.  This is only useful to run
+         binaries that require atomic access but were compiled with
+         -mno-atomic.
+
+         If CONFIG_RV_ATOMIC is unset, this option is mandatory.

I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:

Quoted 3 lines

That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.

I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.

Quoted 8 lines
Quoted 6 lines

The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.

I'll add it to my TODO list.

This would be another variant of the question above.

After talking with people a bit about this, I think the sane thing to do here is to just always provide the atomic system call (and VDSO implementation), and to default to enabling the atomic extensions. While I expect non-atomic implementations to be very much the exception, there's a stronger argument for supporting non-atomic userspace programs with reasonable performance on atomic systems -- the first round of small Linux-capable embedded systems might not support atomic (though ours will), but we don't want to wed software to a syscall in this case.

Quoted 4 lines

Before the VDSO was suggested I was leaning towards disabling the atomic system call by default, but since the VDSO implementation will provide very good performance for non-atomic userspace code on atomic systems I think it's best to just enable it everywhere. It's only a few bytes of binary size.

Ok.

Arnd

maintainer
#44 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Quoted 6 lines

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

Quoted 7 lines

+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }

You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.

Quoted 8 lines

The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is

Quoted 1 line

=2ms, so the division won't cost much in comparison.

The normal case should have no division in it.

I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.

I think the intention originally was to avoid overflowing the 32-bit argument in

void __delay(unsigned long cycles)

If you need to delay for more than 4 billion clocksource cycles, your code is still broken.

Quoted 7 lines
Quoted 2 lines

Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.

That makes sense, I just based this blindly off the ARM version. I'll see if that lets me avoid unnecessary overflow for ndelay. If it doesn't then I'd prefer to just keep exactly the same constraints ARM has to avoid unexpected behavior.

Right, I should have been more specific here, as ARM has two implementations (loop and timer) and it gets much easier if you know you can rely on the timer to be available.

Arnd

#6 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

In reply to Palmer Dabbelt
Quoted 71 lines · Palmer Dabbelt
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

I don't think that does the same thing. The desired effect of this diff is:

* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.

Quoted 6 lines

* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.

* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.

Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.

Quoted 35 lines

Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this

Makefile +2 -9
index 0606f28..4adc609 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+                                 -e s/riscv.*/riscv/ )
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
-# Additional ARCH settings for RISC-V
-ifeq ($(ARCH),riscv32)
-       SRCARCH := riscv
-endif
-ifeq ($(ARCH),riscv64)
-       SRCARCH := riscv
-endif
-
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc
Quoted 6 lines
Quoted 2 lines

then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.

Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on CONFIG_64BIT.

Quoted 2 lines

OK, I didn't know about COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.

Hello Palmer,

I suppose the commit:

https://github.com/riscv/riscv-linux/commit/8c826930d2a19ecd4f1036f10a380dc4fddd0da5

aims to address this, but it appears to be incomplete. It lacks the first fragment of the patch above, i.e. the conversion from the "uname -m" output (i.e. "riscv{64,32}") to the canonical arch string (i.e. "riscv"). As a result, a native build (which normally doesn't explicitly pass ARCH=riscv to make and therefore relies on the output of "uname -m") would fail.

Regards,
Karsten

Signature · 3 lines
Gem. Par. 28 Abs. 4 Bundesdatenschutzgesetz widerspreche ich der Nutzung
sowie der Weitergabe meiner personenbezogenen Daten für Zwecke der
Werbung sowie der Markt- oder Meinungsforschung.
author maintainer
#7 lore raw

Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}

Quoted 79 lines · On Tue, 06 Jun 2017 10:39:04 PDT (-0700), [email protected] wrote:
Quoted 71 lines · Palmer Dabbelt
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt

RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.

I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.

I don't think that does the same thing. The desired effect of this diff is:

* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.

Quoted 6 lines

* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.

* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.

Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.

Quoted 35 lines

Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this

Makefile +2 -9
index 0606f28..4adc609 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
                                  -e s/s390x/s390/ -e s/parisc64/parisc/ \
                                  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+                                 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+                                 -e s/riscv.*/riscv/ )
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64)
         SRCARCH := x86
 endif
 
-# Additional ARCH settings for RISC-V
-ifeq ($(ARCH),riscv32)
-       SRCARCH := riscv
-endif
-ifeq ($(ARCH),riscv64)
-       SRCARCH := riscv
-endif
-
 # Additional ARCH settings for sparc
 ifeq ($(ARCH),sparc32)
        SRCARCH := sparc
Quoted 6 lines
Quoted 2 lines

then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.

Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on CONFIG_64BIT.

Quoted 2 lines

OK, I didn't know about COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.

Hello Palmer,

I suppose the commit:

Quoted 8 lines

https://github.com/riscv/riscv-linux/commit/8c826930d2a19ecd4f1036f10a380dc4fddd0da5

aims to address this, but it appears to be incomplete. It lacks the first fragment of the patch above, i.e. the conversion from the "uname -m" output (i.e. "riscv{64,32}") to the canonical arch string (i.e. "riscv"). As a result, a native build (which normally doesn't explicitly pass ARCH=riscv to make and therefore relies on the output of "uname -m") would fail.

Sorry about that, I dropped the commit. I'm in the middle of bisecting to find a regression, so the patch might now show up for a bit, but it'll be fixed.

author maintainer
#36 lore raw

Re: [PATCH 4/7] RISC-V: arch/riscv/include

In reply to Arnd Bergmann
Quoted 110 lines · Arnd Bergmann
Quoted 67 lines · Palmer Dabbelt
Quoted 44 lines · Arnd Bergmann
Quoted 30 lines · Palmer Dabbelt
Quoted 17 lines · Arnd Bergmann

arch/riscv/include/asm/io.h line 18

Quoted 11 lines · Palmer Dabbelt
arch/riscv/include/asm/io.h new file +4 -0
new file mode 100644
index 000000000000..d942555a7a08
@@ -0,0 +1,36 @@
 
+#ifndef _ASM_RISCV_IO_H
+#define _ASM_RISCV_IO_H
+
+#include <asm-generic/io.h>

I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.

Quoted 3 lines

Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.

Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64

https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa

where I think the only odd thing is our definition of mmiowb

Quoted 12 lines

+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");

Quoted 7 lines

Looks ok, yes.

Quoted 3 lines
  +#define mmiowb()                __asm__ __volatile__ ("fence io,io" : : : "memory");

which I think is correct.

I can never remember what exactly this one does.

I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by

https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to use mmiowb()?
AFAICT, they're both right. Generally, mmiowb() should be used prior to unlock in a critical section whose last PIO operation is a writeX.

Thus, I think the actual fence should be at least

fence o,w

...

Quoted 2 lines

which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.

This sounds reasonable according to the documentation, but with your longer explanation of the barriers, I think the __iormb/__iowmb definitions above are wrong. What you actually need I think is

void writel(u32 v, volatile void __iomem *addr)

{
         asm volatile("fence w,o" : : : "memory");
         writel_relaxed(v, addr);
}

u32 readl(volatile void __iomem *addr)

{
         u32 ret = readl_relaxed(addr);
         asm volatile("fence i,r" : : : "memory");
         return ret;
}

to synchronize between DMA and I/O. The barriers you listed above in contrast appear to be directed at synchronizing I/O with other I/O. We normally assume that this is not required when you have subsequent MMIO accesses on the same device (on PCI) or the same address region (per ARM architecture and others). If you do need to enforce ordering between MMIO, you might even need to add those barriers in the relaxed version to be portable with drivers written for ARM SoCs:

void writel_relaxed(u32 v, volatile void __iomem *addr)

{
        __raw_writel((__force u32)cpu_to_le32(v, addr)
         asm volatile("fence o,io" : : : "memory");
}

u32 readl_relaxed(volatile void __iomem *addr)

{
         asm volatile("fence i,io" : : : "memory");
         return le32_to_cpu((__force __le32)__raw_readl(addr));
}
Quoted 4 lines

You then end up with a barrier before and after each regular readl/writel in order to synchronize both with DMA and MMIO instrictructions, and you still need the extre mmiowb() to synchronize against the spinlock.

Ah, thanks. I guess I just had those wrong. I'll fix the non-relaxed versions and add relaxed versions that have the fence.

Quoted 10 lines

My memory on mmiowb is still a bit cloudy, but I think we don't need that on ARM, and while PowerPC originally needed it, it is now implied by the spin_unlock(). If this is actually right, you might want to do the same here. Very few drivers actually use mmiowb(), but there might be more drivers that would need it if your spin_unlock() doesn't synchronize against writel() or writel_relaxed(). Maybe it the mmiowb() should really be implied by writel() but not writel_relaxed()? That might be sensible, but only if we do it the same way on powerpc, which currently doesn't have writel_relaxed() any more relaxed than writel()

I like the idea of putting this in spin_unlock() better, particularly if PowerPC does it that way. I was worried that with mmiowb being such an esoteric thing that it would be wrong all over the place, this feels much better.

author maintainer
#58 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Arnd Bergmann
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
Quoted 3 lines · Arnd Bergmann
Quoted 1 line

+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);

If you don't care about LPC/ISA devices, then your PCI_MIN_IO should also be zero instead of 0x1000

Sorry, but the only Google results for PCI_MIN_IO is this email. There don't appear to be any relevant references to PCI_MIN in the kernel

  $ git grep PCI_MIN_
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:      ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \
  arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT                 0x00
  drivers/ata/pata_hpt366.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt37x.c:      pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ata/pata_hpt3x2n.c:     pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/ide/hpt366.c:   pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT     0x3e    /*  8 bit       Min_Gnt */
  drivers/net/fddi/skfp/h/skfbi.h:/*      PCI_MIN_GNT     8 bit   Min_Gnt */
  include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT               0x3e    /* 8 bits */
Quoted 3 lines
Quoted 1 line

I'm afraid that I'm not sure what to do here.

Sorry, I meant PCIBIOS_MIN_IO

OK, fixed.

author maintainer
#24 lore raw

Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs

In reply to Arnd Bergmann
Quoted 40 lines · Arnd Bergmann
Quoted 31 lines · Palmer Dabbelt
Quoted 11 lines · Arnd Bergmann
Quoted 1 line · Palmer Dabbelt

On Tue, 23 May 2017 04:46:22 PDT (-0700), Arnd Bergmann wrote:

This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:

- Every major platform gets a Kconfig option in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)

Quoted 7 lines

- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.

On ARM, we have a bit of both, which is not as good as being consistent one way or another.

This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform Kconfig menu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.

Quoted 4 lines

For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.

Ok. Another related point, which may or may not be obvious: when you come up with platform definitions, they should not be mutually exclusive.

Quoted 7 lines

For instance, supporting both MMU/NOMMU, big/little-endian or 32/64-bit kernels will of course require building separate binaries, but almost every other configuration option should be backward compatible: An SMP kernel should run on a uniprocessor machine and vice versa (using only one CPU), and you should be able to run a kernel with support multiple instruction set revisions by restricting the build to the smallest subset of instructions.

We're actually trying really hard to ensure a single binary can run anywhere:
for example, an XLEN (the RISC-V term for the general purpose register bit width) agnostic code sequence can be run that determines if you're on a 32-bit or 64-bit platform without taking any traps, then enumerate the entire set of user and supervisor extensions available. In theory one could build a kernel image that supports both RV32I and RV64I, as well as optionally supporting paging. This won't happen for Linux, but our debugger examines the target chip using this mechanism.

An explicit goal of the supervisor specification is to make it possible for one Linux image to run on every platform. Right now the only constraints we have is that SMP kernels require atomics. Specifically:

* non-SMP kernels run on multiprocessor systems, picking an arbitrary hart to run on (or hart 0 if there's no atomics).
* The kernel is always built with floating-point enabled, it just never sees the "FPU is on" bit if there's no FPU and therefor doesn't execute any F-extension instructions.

[Though of course after writing this I went to check our boot code and found it using an unguarded AMO... Luckily it was an easy fix. Thanks!]

The big hole right now is that the SBI (our version of Alpha's PAL code) isn't specified because it's part of the upcoming platform spec. We'll just have to home this isn't a problem.

Quoted 6 lines

On older ARM platforms and most MIPS platforms, we are still restricted to building a kernel binary that will only run on a particular SoC family and not even another SoC with the same CPU core. Fixing this for most ARM platforms required a lot of work that you should avoid by requiring them all to work with a common kernel from the start.

We're hoping that everyone is more amenable to play ball here after seeing how much pain it was in ARM land. We'll see how well the platform specification goes.

Quoted 11 lines

Similarly, ARM has an incompatibility that prevents us from running on older (ARMv4/v5) along with newer (ARMv6 or higher) instruction set versions with a single kernel. Avoiding this on RISC-V may become challenging as one of the strengths of the architecture is its flexibility: Someone may come up with their own architecture extensions that they really want to support in the kernel but can't get it to work without making the kernel binary incompatible with other implementations. Do you already have a policy for how to deal with this? Usually by the time someone ships hardware, it's too late and it becomes hard to argue for their kernel port to not get merged.

The RISC-V ISA defines extension mechanisms that allows new non-standard extensions to coexist, so as long as everyone is well behaved we should be safe. I believe there is some mechanism to disallow bad behavior via the RISC-V foundation and a certification process, but we'll see if that actually has any teeth.

Of course, we're hoping to only need to support standard extensions, but nothing ever goes that well :).

author maintainer
#54 lore raw

Re: [PATCH 6/7] RISC-V: arch/riscv/kernel

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · Palmer Dabbelt

On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:

* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.

What is the warning here? I would assume that you should leave this unchanged as well.

Quoted 7 lines
Quoted 3 lines

ERROR: #define of 'ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - use Kconfig variables or standard guards instead #2533: FILE: arch/riscv/include/asm/elf.h:79:
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES

Ok, you can definitely ignore this one. The warning is meant to prevent adding new macros like that, but the macro already exists in the other architectures, and I see no point in converting them all into a CONFIG_ symbol.

Sounds good.

author maintainer
#45 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Arnd Bergmann
Quoted 34 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Quoted 6 lines

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

Quoted 7 lines

+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }

You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.

Quoted 8 lines

The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is

Quoted 1 line

=2ms, so the division won't cost much in comparison.

The normal case should have no division in it.

I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.

Quoted 7 lines

I think the intention originally was to avoid overflowing the 32-bit argument in

void __delay(unsigned long cycles)

If you need to delay for more than 4 billion clocksource cycles, your code is still broken.

Maybe I'm crazy, but I thought the goal was to avoid overflowing on the multiply. Specifically, the code looks like

  udelay(long input) {
    long a = input * MUL_VAL;
    long b = a >> SHIFT_VAL;
    __delay(b);
  }

so the place there's extra overflow is at computing a, not b (the input to __delay). When I modified the ARM code I went and recalculated the point at which the multiply would overflow and it matched the value from the ARM code, which is 2000us.

While I can buy the argument that 2000us is still too long, the real reason I wrote the code this way is because I thought it was easier than having an error case. If you think the error is better then I'll do it that way.

author maintainer
#73 lore raw

RISC-V Linux Port v2

In reply to Palmer Dabbelt

Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.

A highlight of the changes since the v1 patch set includes:

* We've split out our drivers into the right places, which means now there's a lot more patches. I'll be submitting these patches to various subsystem maintainers and including them in any future RISC-V patch sets until they've been merged.

* The SBI console driver has been completely rewritten to use the HVC helpers and is now significantly smaller.

* We've begun to use weaker barries as opposed to just the big "fence". There's still some work to do here, specifically:
- We need fences in the realxed MMIO functions.
- The non-relaxed MMIO functions are missing R/W bits on their fences.
- Many AMOs need the aq and rl bits set.

* We now have thread_info in task_struct. As a result, sscratch now contains TP instead of SP. This was necessary because thread_info is no longer on the stack.

* A few shared routines have been added that we use instead of creating another arch copy.

Here's my TODO list

* The memory model changes indicated above.

* I need to go through checkpatch again to make sure none of the messages are valid problems.

* Put an implementation of atomic compare/exchange in the VDSO when atomic instructions are enabled, otherwise insert stubs to the cmpxchg syscall.

* Remove the extra multiplexing in the cmpxchg syscall.

Aside from those two releatively minor ABI issues, I think our ABI is in good shape. Unless there are any other issues that crop up I'd like to begin our glibc submission early next week.

[PATCH 01/17] drivers: support PCIe in RISCV
[PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt [PATCH 03/17] base: fix order of OF initialization [PATCH 04/17] Documentation: atomic_ops.txt is
[PATCH 05/17] MAINTAINERS: Add RISC-V
[PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource} [PATCH 07/17] lib: Add shared copies of some GCC library routines [PATCH 08/17] dts: include documentation for the RISC-V interrupt [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource [PATCH 10/17] irqchip: New RISC-V PLIC Driver
[PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver [PATCH 12/17] tty: New RISC-V SBI Console Driver
[PATCH 13/17] RISC-V: Add include subdirectory
[PATCH 14/17] RISC-V: lib files
[PATCH 15/17] RISC-V: Add mm subdirectory
[PATCH 16/17] RISC-V: Add kernel subdirectory
[PATCH 17/17] RISC-V: Makefile and Kconfig

author maintainer
#81 lore raw

PATCH 2/17 pcie-xilinx: add missing 5th legacy interrupt

In reply to Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

These are numbered from 1.

---
 drivers/pci/host/pcie-xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +2 -2
index 2fe2df51f9f8..8804145d399a 100644
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
 			val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
 				XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
 			generic_handle_irq(irq_find_mapping(port->leg_domain,
-							    val));
+							    val + 1));
 		}
 	}
 
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 		return -ENODEV;
 	}
 
-	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 4,
+	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 5,
 						 &intx_domain_ops,
 						 port);
 	if (!port->leg_domain) {
Signature · 1 line
2.13.0
author maintainer
#86 lore raw

PATCH 3/17 base: fix order of OF initialization

In reply to Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

This fixes: [ 0.010000] cpu cpu0: Error -2 creating of_node link
... which you get for every CPU on all architectures with a OF cpu/ node.

This affects riscv, nios, etc.

---
 drivers/base/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/init.c +1 -1
index 48c0e220acc0..0dcd17e561d0 100644
@@ -31,9 +31,9 @@ void __init driver_init(void)
 	/* These are also core pieces, but must come after the
 	 * core core pieces.
 	 */
+	of_core_init();
 	platform_bus_init();
 	cpu_dev_init();
 	memory_dev_init();
 	container_dev_init();
-	of_core_init();
 }
Signature · 1 line
2.13.0
author maintainer
#94 lore raw

PATCH 4/17 Documentation: atomic_ops.txt is core-api/atomic_ops.rst

In reply to Palmer Dabbelt

I was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.

---
 Documentation/memory-barriers.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/memory-barriers.txt +5 -5
index 732f10ea382e..f1c9eaa45a57 100644
@@ -498,11 +498,11 @@ And a couple of implicit varieties:
      This means that ACQUIRE acts as a minimal "acquire" operation and
      RELEASE acts as a minimal "release" operation.
 
-A subset of the atomic operations described in atomic_ops.txt have ACQUIRE
-and RELEASE variants in addition to fully-ordered and relaxed (no barrier
-semantics) definitions.  For compound atomics performing both a load and a
-store, ACQUIRE semantics apply only to the load and RELEASE semantics apply
-only to the store portion of the operation.
+A subset of the atomic operations described in core-api/atomic_ops.rst have
+ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no
+barrier semantics) definitions.  For compound atomics performing both a load
+and a store, ACQUIRE semantics apply only to the load and RELEASE semantics
+apply only to the store portion of the operation.
 
 Memory barriers are only required where there's a possibility of interaction
 between two CPUs or between a CPU and a device.  If it can be guaranteed that
Signature · 1 line
2.13.0
author maintainer
#97 lore raw

PATCH 5/17 MAINTAINERS: Add RISC-V

In reply to Palmer Dabbelt

From: Jonathan Neuschäfer <[email protected]>

RISC-V needs a MAINTAINERS entry. Let's add one.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 7a28acd7f525..50b18dad8c22 100644
@@ -10877,6 +10877,14 @@ M:	Maxim Levitsky <[email protected]>
 S:	Maintained
 F:	drivers/memstick/host/r592.*
 
+RISC-V ARCHITECTURE
+M:	Palmer Dabbelt <[email protected]>
+M:	Albert Ou <[email protected]>
+L:	[email protected]
+T:	git https://github.com/riscv/riscv-linux
+S:	Supported
+F:	arch/riscv/
+
 ROCCAT DRIVERS
 M:	Stefan Achatz <[email protected]>
 W:	http://sourceforge.net/projects/roccat/
Signature · 1 line
2.13.0
author maintainer
#99 lore raw

PATCH 6/17 pci: Add generic pcibios_{fixup_bus,align_resource}

In reply to Palmer Dabbelt

While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.

---
 drivers/pci/Makefile |  2 +-
 drivers/pci/bios.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pci/bios.c
drivers/pci/Makefile +1 -1
index a29d9ec05d13..fa7040915194 100644
@@ -4,7 +4,7 @@
 
 obj-y		+= access.o bus.o probe.o host-bridge.o remove.o pci.o \
 			pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \
-			irq.o vpd.o setup-bus.o vc.o mmap.o
+			irq.o vpd.o setup-bus.o vc.o mmap.o bios.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSFS) += slot.o
 
drivers/pci/bios.c new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#106 lore raw

PATCH 7/17 lib: Add shared copies of some GCC library routines

In reply to Palmer Dabbelt

Many ports (m32r, microblaze, mips, parisc, score, and sparc) use functionally identical copies of various GCC library routine files, which came up as we were submitting the RISC-V port (which also uses some of these).

This patch adds a new copy of these library routine files, which are functionally identical to the various other copies. These are availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't used anywhere.

---
 include/lib/libgcc.h | 44 ++++++++++++++++++++++++++++++++
 lib/Kconfig          | 18 +++++++++++++
 lib/Makefile         |  8 ++++++
 lib/ashldi3.c        | 45 ++++++++++++++++++++++++++++++++
 lib/ashrdi3.c        | 46 +++++++++++++++++++++++++++++++++
 lib/cmpdi2.c         | 42 ++++++++++++++++++++++++++++++
 lib/lshrdi3.c        | 45 ++++++++++++++++++++++++++++++++
 lib/muldi3.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/ucmpdi2.c        | 35 +++++++++++++++++++++++++
 9 files changed, 355 insertions(+)
 create mode 100644 include/lib/libgcc.h
 create mode 100644 lib/ashldi3.c
 create mode 100644 lib/ashrdi3.c
 create mode 100644 lib/cmpdi2.c
 create mode 100644 lib/lshrdi3.c
 create mode 100644 lib/muldi3.c
 create mode 100644 lib/ucmpdi2.c
include/lib/libgcc.h new file +44 -0
new file mode 100644
index 000000000000..a5397e34e005
@@ -0,0 +1,44 @@
+/*
+ * include/lib/libgcc.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+
+#ifndef __LIB_LIBGCC_H
+#define __LIB_LIBGCC_H
+
+#include <asm/byteorder.h>
+
+typedef int word_type __attribute__ ((mode (__word__)));
+
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+	int high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+	int low, high;
+};
+#else
+#error I feel sick.
+#endif
+
+typedef union {
+	struct DWstruct s;
+	long long ll;
+} DWunion;
+
+#endif /* __ASM_LIBGCC_H */
lib/Kconfig +18 -0
index 0c8b78a9ae2e..7a9c934d91fd 100644
@@ -565,3 +565,21 @@ config PRIME_NUMBERS
 	tristate
 
 endmenu
+
+config GENERIC_ASHLDI3
+	def_bool n
+
+config GENERIC_ASHRDI3
+	def_bool n
+
+config GENERIC_LSHRDI3
+	def_bool n
+
+config GENERIC_MULDI3
+	def_bool n
+
+config GENERIC_CMPDI2
+	def_bool n
+
+config GENERIC_UCMPDI2
+	def_bool n
lib/Makefile +8 -0
index 0166fbc0fa81..5f68242f7774 100644
@@ -243,3 +243,11 @@ UBSAN_SANITIZE_ubsan.o := n
 obj-$(CONFIG_SBITMAP) += sbitmap.o
 
 obj-$(CONFIG_PARMAN) += parman.o
+
+# GCC library routines
+obj-$(CONFIG_GENERIC_ASHLDI3) += ashldi3.o
+obj-$(CONFIG_GENERIC_ASHRDI3) += ashrdi3.o
+obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o
+obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o
+obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o
+obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
lib/ashldi3.c new file +45 -0

45 lines not on this page · raw message

lib/ashrdi3.c new file +46 -0

46 lines not on this page · raw message

lib/cmpdi2.c new file +42 -0

42 lines not on this page · raw message

lib/lshrdi3.c new file +45 -0

45 lines not on this page · raw message

lib/muldi3.c new file +72 -0

72 lines not on this page · raw message

lib/ucmpdi2.c new file +35 -0
new file mode 100644
index 000000000000..49a53505c8e3
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+#include <linux/module.h>
+#include <lib/libgcc.h>
+
+word_type __ucmpdi2(unsigned long long a, unsigned long long b)
+{
+	const DWunion au = {.ll = a};
+	const DWunion bu = {.ll = b};
+
+	if ((unsigned int) au.s.high < (unsigned int) bu.s.high)
+		return 0;
+	else if ((unsigned int) au.s.high > (unsigned int) bu.s.high)
+		return 2;
+	if ((unsigned int) au.s.low < (unsigned int) bu.s.low)
+		return 0;
+	else if ((unsigned int) au.s.low > (unsigned int) bu.s.low)
+		return 2;
+	return 1;
+}
+EXPORT_SYMBOL(__ucmpdi2);
Signature · 1 line
2.13.0
author maintainer
#108 lore raw

PATCH 8/17 dts: include documentation for the RISC-V interrupt controllers

In reply to Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
new file mode 100644
index 000000000000..62f02e834ff9
@@ -0,0 +1,46 @@
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------
+
+RISC-V cores include Control Status Registers (CSRs) which are local to each
+hart and can be read or written by software. Some of these CSRs are used to
+control local interrupts connected to the core.
+
+Typical examples of local interrupts on a RISC-V core include: software IPI
+interrupts, timer interrupts, and a link to the PLIC interrupt controller.
+
+Required properties:
+- compatible : "riscv,cpu-intc"
+- #interrupt-cells : should be <1>
+- interrupt-controller : Identifies the node as an interrupt controller
+
+Furthermore, this interrupt-controller MUST be embedded inside the cpu
+definition of the hart whose CSRs control these local interrupts.
+
+Example:
+
+	cpu1: cpu@1 {
+		clock-frequency = <1600000000>;
+		compatible = "riscv";
+		d-cache-block-size = <64>;
+		d-cache-sets = <64>;
+		d-cache-size = <16384>;
+		d-tlb-sets = <1>;
+		d-tlb-size = <32>;
+		device_type = "cpu";
+		i-cache-block-size = <64>;
+		i-cache-sets = <64>;
+		i-cache-size = <16384>;
+		i-tlb-sets = <1>;
+		i-tlb-size = <32>;
+		mmu-type = "riscv,sv39";
+		next-level-cache = <&L2>;
+		reg = <1>;
+		riscv,isa = "rv64imac";
+		status = "okay";
+		tlb-split;
+		cpu1-intc: interrupt-controller {
+			#interrupt-cells = <1>;
+			compatible = "riscv,cpu-intc";
+			interrupt-controller;
+		};
+	};
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#126 lore raw

PATCH 10/17 irqchip: New RISC-V PLIC Driver

In reply to Palmer Dabbelt

This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.

---
 drivers/irqchip/Kconfig          |  12 ++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +12 -0
index 478f8ace2664..2906d63934ef 100644
@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER
 	help
 	  Say yes here to add support for the IRQ combiner devices embedded
 	  in Qualcomm Technologies chips.
+
+config RISCV_PLIC
+        bool "Platform-Level Interrupt Controller"
+	depends on RISCV
+        default y
+        help
+	   This enables support for the PLIC chip found in standard RISC-V
+	   systems. The PLIC is the top-most interrupt controller found in
+	   the system, connected directly to the core complex. All other
+	   interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+	   If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
index b64c59b838a0..bed94cc89146 100644
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC)			+= irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)		+= irq-aspeed-vic.o
 obj-$(CONFIG_STM32_EXTI) 		+= irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)		+= qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_PLIC)		+= irq-riscv-plic.o
drivers/irqchip/irq-riscv-plic.c new file +253 -0

253 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#137 lore raw

PATCH 12/17 tty: New RISC-V SBI Console Driver

In reply to Palmer Dabbelt

This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.

The SBI console is made availiable for early printk messages and is also availiable as a regular console.

---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
index 574da15fe618..f3774adab240 100644
@@ -114,4 +114,15 @@ config HVCS
 	  which will also be compiled when this driver is built as a
 	  module.
 
+config HVC_SBI
+	bool "SBI console support"
+	depends on RISCV
+	select HVC_DRIVER
+	default y
+	help
+	  This enables support for console output via RISC-V SBI calls, which
+	  is normally used only during boot to output printk.
+
+	  If you don't know what do to here, say Y.
+
 endif # TTY
drivers/tty/hvc/Makefile +1 -0
index 6a2702be76d1..2d63bfe4a96b 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS)		+= hvcs.o
+obj-$(CONFIG_HVC_SBI)		+= hvc_sbi.o
drivers/tty/hvc/hvc_sbi.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#142 lore raw

PATCH 13/17 RISC-V: Add include subdirectory

In reply to Palmer Dabbelt

This patch adds the include files for the RISC-V port. These are mostly based on the score port, but there are a lot of arm64-based files as well.

---
 arch/riscv/include/asm/Kbuild             |  61 +++++
 arch/riscv/include/asm/asm-offsets.h      |   1 +
 arch/riscv/include/asm/asm.h              |  76 ++++++
 arch/riscv/include/asm/atomic.h           | 349 ++++++++++++++++++++++++
 arch/riscv/include/asm/atomic64.h         | 355 ++++++++++++++++++++++++
 arch/riscv/include/asm/barrier.h          |  41 +++
 arch/riscv/include/asm/bitops.h           | 228 ++++++++++++++++
 arch/riscv/include/asm/bug.h              |  88 ++++++
 arch/riscv/include/asm/cache.h            |  22 ++
 arch/riscv/include/asm/cacheflush.h       |  39 +++
 arch/riscv/include/asm/cmpxchg.h          | 124 +++++++++
 arch/riscv/include/asm/compat.h           |  31 +++
 arch/riscv/include/asm/csr.h              | 125 +++++++++
 arch/riscv/include/asm/current.h          |  42 +++
 arch/riscv/include/asm/delay.h            |  28 ++
 arch/riscv/include/asm/device.h           |  27 ++
 arch/riscv/include/asm/dma-mapping.h      |  41 +++
 arch/riscv/include/asm/elf.h              |  85 ++++++
 arch/riscv/include/asm/io.h               | 152 +++++++++++
 arch/riscv/include/asm/irq.h              |  31 +++
 arch/riscv/include/asm/irqflags.h         |  63 +++++
 arch/riscv/include/asm/kprobes.h          |  22 ++
 arch/riscv/include/asm/linkage.h          |  20 ++
 arch/riscv/include/asm/mmu.h              |  26 ++
 arch/riscv/include/asm/mmu_context.h      |  69 +++++
 arch/riscv/include/asm/page.h             | 138 ++++++++++
 arch/riscv/include/asm/pci.h              |  50 ++++
 arch/riscv/include/asm/pgalloc.h          | 124 +++++++++
 arch/riscv/include/asm/pgtable-32.h       |  25 ++
 arch/riscv/include/asm/pgtable-64.h       |  84 ++++++
 arch/riscv/include/asm/pgtable-bits.h     |  48 ++++
 arch/riscv/include/asm/pgtable.h          | 427 +++++++++++++++++++++++++++++
 arch/riscv/include/asm/processor.h        | 102 +++++++
 arch/riscv/include/asm/ptrace.h           | 116 ++++++++
 arch/riscv/include/asm/sbi.h              | 100 +++++++
 arch/riscv/include/asm/smp.h              |  41 +++
 arch/riscv/include/asm/spinlock.h         | 155 +++++++++++
 arch/riscv/include/asm/spinlock_types.h   |  33 +++
 arch/riscv/include/asm/string.h           |  30 ++
 arch/riscv/include/asm/switch_to.h        |  69 +++++
 arch/riscv/include/asm/syscall.h          |  90 ++++++
 arch/riscv/include/asm/syscalls.h         |  25 ++
 arch/riscv/include/asm/thread_info.h      |  96 +++++++
 arch/riscv/include/asm/timex.h            |  43 +++
 arch/riscv/include/asm/tlb.h              |  24 ++
 arch/riscv/include/asm/tlbflush.h         |  64 +++++
 arch/riscv/include/asm/uaccess.h          | 440 ++++++++++++++++++++++++++++++
 arch/riscv/include/asm/unistd.h           |  16 ++
 arch/riscv/include/asm/vdso.h             |  32 +++
 arch/riscv/include/asm/word-at-a-time.h   |  55 ++++
 arch/riscv/include/uapi/asm/Kbuild        |   2 +
 arch/riscv/include/uapi/asm/auxvec.h      |  24 ++
 arch/riscv/include/uapi/asm/bitsperlong.h |  25 ++
 arch/riscv/include/uapi/asm/byteorder.h   |  23 ++
 arch/riscv/include/uapi/asm/elf.h         |  83 ++++++
 arch/riscv/include/uapi/asm/ptrace.h      |  68 +++++
 arch/riscv/include/uapi/asm/sigcontext.h  |  29 ++
 arch/riscv/include/uapi/asm/siginfo.h     |  24 ++
 arch/riscv/include/uapi/asm/unistd.h      |  22 ++
 59 files changed, 4873 insertions(+)
 create mode 100644 arch/riscv/include/asm/Kbuild
 create mode 100644 arch/riscv/include/asm/asm-offsets.h
 create mode 100644 arch/riscv/include/asm/asm.h
 create mode 100644 arch/riscv/include/asm/atomic.h
 create mode 100644 arch/riscv/include/asm/atomic64.h
 create mode 100644 arch/riscv/include/asm/barrier.h
 create mode 100644 arch/riscv/include/asm/bitops.h
 create mode 100644 arch/riscv/include/asm/bug.h
 create mode 100644 arch/riscv/include/asm/cache.h
 create mode 100644 arch/riscv/include/asm/cacheflush.h
 create mode 100644 arch/riscv/include/asm/cmpxchg.h
 create mode 100644 arch/riscv/include/asm/compat.h
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/current.h
 create mode 100644 arch/riscv/include/asm/delay.h
 create mode 100644 arch/riscv/include/asm/device.h
 create mode 100644 arch/riscv/include/asm/dma-mapping.h
 create mode 100644 arch/riscv/include/asm/elf.h
 create mode 100644 arch/riscv/include/asm/io.h
 create mode 100644 arch/riscv/include/asm/irq.h
 create mode 100644 arch/riscv/include/asm/irqflags.h
 create mode 100644 arch/riscv/include/asm/kprobes.h
 create mode 100644 arch/riscv/include/asm/linkage.h
 create mode 100644 arch/riscv/include/asm/mmu.h
 create mode 100644 arch/riscv/include/asm/mmu_context.h
 create mode 100644 arch/riscv/include/asm/page.h
 create mode 100644 arch/riscv/include/asm/pci.h
 create mode 100644 arch/riscv/include/asm/pgalloc.h
 create mode 100644 arch/riscv/include/asm/pgtable-32.h
 create mode 100644 arch/riscv/include/asm/pgtable-64.h
 create mode 100644 arch/riscv/include/asm/pgtable-bits.h
 create mode 100644 arch/riscv/include/asm/pgtable.h
 create mode 100644 arch/riscv/include/asm/processor.h
 create mode 100644 arch/riscv/include/asm/ptrace.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/smp.h
 create mode 100644 arch/riscv/include/asm/spinlock.h
 create mode 100644 arch/riscv/include/asm/spinlock_types.h
 create mode 100644 arch/riscv/include/asm/string.h
 create mode 100644 arch/riscv/include/asm/switch_to.h
 create mode 100644 arch/riscv/include/asm/syscall.h
 create mode 100644 arch/riscv/include/asm/syscalls.h
 create mode 100644 arch/riscv/include/asm/thread_info.h
 create mode 100644 arch/riscv/include/asm/timex.h
 create mode 100644 arch/riscv/include/asm/tlb.h
 create mode 100644 arch/riscv/include/asm/tlbflush.h
 create mode 100644 arch/riscv/include/asm/uaccess.h
 create mode 100644 arch/riscv/include/asm/unistd.h
 create mode 100644 arch/riscv/include/asm/vdso.h
 create mode 100644 arch/riscv/include/asm/word-at-a-time.h
 create mode 100644 arch/riscv/include/uapi/asm/Kbuild
 create mode 100644 arch/riscv/include/uapi/asm/auxvec.h
 create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h
 create mode 100644 arch/riscv/include/uapi/asm/byteorder.h
 create mode 100644 arch/riscv/include/uapi/asm/elf.h
 create mode 100644 arch/riscv/include/uapi/asm/ptrace.h
 create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h
 create mode 100644 arch/riscv/include/uapi/asm/siginfo.h
 create mode 100644 arch/riscv/include/uapi/asm/unistd.h
arch/riscv/include/asm/Kbuild new file +61 -0
new file mode 100644
index 000000000000..710397395981
@@ -0,0 +1,61 @@
+generic-y += bugs.h
+generic-y += cacheflush.h
+generic-y += checksum.h
+generic-y += clkdev.h
+generic-y += cputime.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += dma-contiguous.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += exec.h
+generic-y += fb.h
+generic-y += fcntl.h
+generic-y += ftrace.h
+generic-y += futex.h
+generic-y += hardirq.h
+generic-y += hash.h
+generic-y += hw_irq.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += irq_regs.h
+generic-y += irq_work.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += kvm_para.h
+generic-y += local.h
+generic-y += mm-arch-hooks.h
+generic-y += mman.h
+generic-y += module.h
+generic-y += msgbuf.h
+generic-y += mutex.h
+generic-y += param.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += preempt.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += sembuf.h
+generic-y += setup.h
+generic-y += shmbuf.h
+generic-y += shmparam.h
+generic-y += signal.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += stat.h
+generic-y += statfs.h
+generic-y += swab.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += topology.h
+generic-y += trace_clock.h
+generic-y += types.h
+generic-y += ucontext.h
+generic-y += unaligned.h
+generic-y += user.h
+generic-y += vga.h
+generic-y += vmlinux.lds.h
+generic-y += xor.h
arch/riscv/include/asm/asm-offsets.h new file +1 -0
new file mode 100644
index 000000000000..d370ee36a182
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
arch/riscv/include/asm/asm.h new file +76 -0

76 lines not on this page · raw message

arch/riscv/include/asm/atomic.h new file +349 -0

349 lines not on this page · raw message

arch/riscv/include/asm/atomic64.h new file +355 -0

355 lines not on this page · raw message

arch/riscv/include/asm/barrier.h new file +41 -0

41 lines not on this page · raw message

arch/riscv/include/asm/bitops.h new file +228 -0

228 lines not on this page · raw message

arch/riscv/include/asm/bug.h new file +88 -0

88 lines not on this page · raw message

arch/riscv/include/asm/cache.h new file +22 -0
new file mode 100644
index 000000000000..e8f0d1110d74
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 Chen Liqin <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_CACHE_H
+#define _ASM_RISCV_CACHE_H
+
+#define L1_CACHE_SHIFT		6
+
+#define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
+
+#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/cacheflush.h new file +39 -0
new file mode 100644
index 000000000000..0595585013b0
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_CACHEFLUSH_H
+#define _ASM_RISCV_CACHEFLUSH_H
+
+#include <asm-generic/cacheflush.h>
+
+#undef flush_icache_range
+#undef flush_icache_user_range
+
+static inline void local_flush_icache_all(void)
+{
+	asm volatile ("fence.i" ::: "memory");
+}
+
+#ifndef CONFIG_SMP
+
+#define flush_icache_range(start, end) local_flush_icache_all()
+#define flush_icache_user_range(vma, pg, addr, len) local_flush_icache_all()
+
+#else /* CONFIG_SMP */
+
+#define flush_icache_range(start, end) sbi_remote_fence_i(0)
+#define flush_icache_user_range(vma, pg, addr, len) sbi_remote_fence_i(0)
+
+#endif /* CONFIG_SMP */
+
+#endif /* _ASM_RISCV_CACHEFLUSH_H */
arch/riscv/include/asm/cmpxchg.h new file +124 -0

124 lines not on this page · raw message

arch/riscv/include/asm/compat.h new file +31 -0
new file mode 100644
index 000000000000..b42bf54f42e4
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_COMPAT_H
+#define __ASM_COMPAT_H
+#ifdef __KERNEL__
+#ifdef CONFIG_COMPAT
+
+#if defined(CONFIG_64BIT)
+#define COMPAT_UTS_MACHINE "riscv64\0\0"
+#elif defined(CONFIG_32BIT)
+#define COMPAT_UTS_MACHINE "riscv32\0\0"
+#else
+#error "Unknown RISC-V base ISA"
+#endif
+
+#endif /*CONFIG_COMPAT*/
+#endif /*__KERNEL__*/
+#endif /*__ASM_COMPAT_H*/
arch/riscv/include/asm/csr.h new file +125 -0

125 lines not on this page · raw message

arch/riscv/include/asm/current.h new file +42 -0

42 lines not on this page · raw message

arch/riscv/include/asm/delay.h new file +28 -0
new file mode 100644
index 000000000000..cbb0c9eb96cb
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2009 Chen Liqin <[email protected]>
+ * Copyright (C) 2016 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_DELAY_H
+#define _ASM_RISCV_DELAY_H
+
+extern unsigned long riscv_timebase;
+
+#define udelay udelay
+extern void udelay(unsigned long usecs);
+
+#define ndelay ndelay
+extern void ndelay(unsigned long nsecs);
+
+extern void __delay(unsigned long cycles);
+
+#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/include/asm/device.h new file +27 -0
new file mode 100644
index 000000000000..28975e528d2f
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#ifndef _ASM_RISCV_DEVICE_H
+#define _ASM_RISCV_DEVICE_H
+
+#include <linux/sysfs.h>
+
+struct dev_archdata {
+	struct dma_map_ops *dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif /* _ASM_RISCV_DEVICE_H */
arch/riscv/include/asm/dma-mapping.h new file +41 -0

41 lines not on this page · raw message

arch/riscv/include/asm/elf.h new file +85 -0

85 lines not on this page · raw message

arch/riscv/include/asm/io.h new file +152 -0

152 lines not on this page · raw message

arch/riscv/include/asm/irq.h new file +31 -0
new file mode 100644
index 000000000000..e64c61e89f76
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_IRQ_H
+#define _ASM_RISCV_IRQ_H
+
+#define NR_IRQS         0
+
+#define INTERRUPT_CAUSE_SOFTWARE    1
+#define INTERRUPT_CAUSE_TIMER       5
+#define INTERRUPT_CAUSE_EXTERNAL    9
+
+void riscv_timer_interrupt(void);
+
+#include <asm-generic/irq.h>
+
+/* The value of csr sie before init_traps runs (core is up) */
+DECLARE_PER_CPU(atomic_long_t, riscv_early_sie);
+
+#endif /* _ASM_RISCV_IRQ_H */
arch/riscv/include/asm/irqflags.h new file +63 -0

63 lines not on this page · raw message

arch/riscv/include/asm/kprobes.h new file +22 -0
new file mode 100644
index 000000000000..1190de7a0f74
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#ifndef ASM_RISCV_KPROBES_H
+#define ASM_RISCV_KPROBES_H
+
+#ifdef CONFIG_KPROBES
+#error "RISC-V doesn't skpport CONFIG_KPROBES"
+#endif
+
+#endif
arch/riscv/include/asm/linkage.h new file +20 -0
new file mode 100644
index 000000000000..b7b304ca89c4
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_LINKAGE_H
+#define _ASM_RISCV_LINKAGE_H
+
+#define __ALIGN		.balign 4
+#define __ALIGN_STR	".balign 4"
+
+#endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/mmu.h new file +26 -0
new file mode 100644
index 000000000000..66805cba9a27
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#ifndef _ASM_RISCV_MMU_H
+#define _ASM_RISCV_MMU_H
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+	void *vdso;
+} mm_context_t;
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_RISCV_MMU_H */
arch/riscv/include/asm/mmu_context.h new file +69 -0

69 lines not on this page · raw message

arch/riscv/include/asm/page.h new file +138 -0

138 lines not on this page · raw message

arch/riscv/include/asm/pci.h new file +50 -0

50 lines not on this page · raw message

arch/riscv/include/asm/pgalloc.h new file +124 -0

124 lines not on this page · raw message

arch/riscv/include/asm/pgtable-32.h new file +25 -0
new file mode 100644
index 000000000000..d61974b74182
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_PGTABLE_32_H
+#define _ASM_RISCV_PGTABLE_32_H
+
+#include <asm-generic/pgtable-nopmd.h>
+#include <linux/const.h>
+
+/* Size of region mapped by a page global directory */
+#define PGDIR_SHIFT     22
+#define PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
+#define PGDIR_MASK      (~(PGDIR_SIZE - 1))
+
+#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +84 -0

84 lines not on this page · raw message

arch/riscv/include/asm/pgtable-bits.h new file +48 -0

48 lines not on this page · raw message

arch/riscv/include/asm/pgtable.h new file +427 -0

385 lines not on this page · raw message

arch/riscv/include/asm/processor.h new file +102 -0

102 lines not on this page · raw message

arch/riscv/include/asm/ptrace.h new file +116 -0

116 lines not on this page · raw message

arch/riscv/include/asm/sbi.h new file +100 -0

100 lines not on this page · raw message

arch/riscv/include/asm/smp.h new file +41 -0

41 lines not on this page · raw message

arch/riscv/include/asm/spinlock.h new file +155 -0

155 lines not on this page · raw message

arch/riscv/include/asm/spinlock_types.h new file +33 -0
new file mode 100644
index 000000000000..83ac4ac9e2ac

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/string.h new file +30 -0
new file mode 100644
index 000000000000..1c59cf4e8ccc

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/switch_to.h new file +69 -0

69 lines not on this page · raw message

arch/riscv/include/asm/syscall.h new file +90 -0

90 lines not on this page · raw message

arch/riscv/include/asm/syscalls.h new file +25 -0
new file mode 100644
index 000000000000..d85267c4f7ea

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/thread_info.h new file +96 -0

96 lines not on this page · raw message

arch/riscv/include/asm/timex.h new file +43 -0

43 lines not on this page · raw message

arch/riscv/include/asm/tlb.h new file +24 -0
new file mode 100644
index 000000000000..c229509288ea

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/tlbflush.h new file +64 -0

64 lines not on this page · raw message

arch/riscv/include/asm/uaccess.h new file +440 -0

440 lines not on this page · raw message

arch/riscv/include/asm/unistd.h new file +16 -0
new file mode 100644
index 000000000000..9f250ed007cd

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/vdso.h new file +32 -0
new file mode 100644
index 000000000000..95768a3810a7

Lines of this file are not shown. View the raw message.

arch/riscv/include/asm/word-at-a-time.h new file +55 -0

55 lines not on this page · raw message

arch/riscv/include/uapi/asm/Kbuild new file +2 -0
new file mode 100644
index 000000000000..b15bf6bc0e94

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
new file mode 100644
index 000000000000..1376515547cd

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
new file mode 100644
index 000000000000..0b3cb52fd29d

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
new file mode 100644
index 000000000000..4ca38af2cd32

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/elf.h new file +83 -0

83 lines not on this page · raw message

arch/riscv/include/uapi/asm/ptrace.h new file +68 -0

68 lines not on this page · raw message

arch/riscv/include/uapi/asm/sigcontext.h new file +29 -0
new file mode 100644
index 000000000000..dc882d598834

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
new file mode 100644
index 000000000000..f96849aac662

Lines of this file are not shown. View the raw message.

arch/riscv/include/uapi/asm/unistd.h new file +22 -0
new file mode 100644
index 000000000000..aedba7d32370

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.0

Part of the diff is not shown here. View the raw message.

author maintainer
#164 lore raw

PATCH 14/17 RISC-V: lib files

In reply to Palmer Dabbelt

Most of these files are based off code in GCC, but the delay code is mostly from ARM.

---
 arch/riscv/lib/Makefile  |   5 ++
 arch/riscv/lib/delay.c   | 107 ++++++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/memcpy.S  |  98 +++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/memset.S  | 118 ++++++++++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/uaccess.S | 125 +++++++++++++++++++++++++++++++++++++++++++++++
 arch/riscv/lib/udivdi3.S |  39 +++++++++++++++
 6 files changed, 492 insertions(+)
 create mode 100644 arch/riscv/lib/Makefile
 create mode 100644 arch/riscv/lib/delay.c
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memset.S
 create mode 100644 arch/riscv/lib/uaccess.S
 create mode 100644 arch/riscv/lib/udivdi3.S
arch/riscv/lib/Makefile new file +5 -0
new file mode 100644
index 000000000000..120c38e77a46
@@ -0,0 +1,5 @@
+lib-y	:= delay.o memcpy.o memset.o uaccess.o
+
+ifeq ($(CONFIG_64BIT),)
+lib-y += udivdi3.o
+endif
arch/riscv/lib/delay.c new file +107 -0

107 lines not on this page · raw message

arch/riscv/lib/memcpy.S new file +98 -0

98 lines not on this page · raw message

arch/riscv/lib/memset.S new file +118 -0

118 lines not on this page · raw message

arch/riscv/lib/uaccess.S new file +125 -0

125 lines not on this page · raw message

arch/riscv/lib/udivdi3.S new file +39 -0
new file mode 100644
index 000000000000..d8a7a1d03615
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+  .globl __udivdi3
+__udivdi3:
+  mv    a2, a1
+  mv    a1, a0
+  li    a0, -1
+  beqz  a2, .L5
+  li    a3, 1
+  bgeu  a2, a1, .L2
+.L1:
+  blez  a2, .L2
+  slli  a2, a2, 1
+  slli  a3, a3, 1
+  bgtu  a1, a2, .L1
+.L2:
+  li    a0, 0
+.L3:
+  bltu  a1, a2, .L4
+  sub   a1, a1, a2
+  or    a0, a0, a3
+.L4:
+  srli  a3, a3, 1
+  srli  a2, a2, 1
+  bnez  a3, .L3
+.L5:
+  ret
+
Signature · 1 line
2.13.0
author maintainer
#166 lore raw

PATCH 16/17 RISC-V: Add kernel subdirectory

In reply to Palmer Dabbelt

These files were mostly based on the score port, but many of them are very ISA specific.

---
 arch/riscv/kernel/.gitignore       |   1 +
 arch/riscv/kernel/Makefile         |  16 ++
 arch/riscv/kernel/asm-offsets.c    | 316 +++++++++++++++++++++++++++
 arch/riscv/kernel/cacheinfo.c      | 103 +++++++++
 arch/riscv/kernel/cpu.c            |  89 ++++++++
 arch/riscv/kernel/entry.S          | 437 +++++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           | 147 +++++++++++++
 arch/riscv/kernel/irq.c            |  20 ++
 arch/riscv/kernel/module.c         | 215 ++++++++++++++++++
 arch/riscv/kernel/process.c        | 132 +++++++++++
 arch/riscv/kernel/ptrace.c         | 147 +++++++++++++
 arch/riscv/kernel/reset.c          |  36 +++
 arch/riscv/kernel/riscv_ksyms.c    |  16 ++
 arch/riscv/kernel/setup.c          | 240 ++++++++++++++++++++
 arch/riscv/kernel/signal.c         | 257 ++++++++++++++++++++++
 arch/riscv/kernel/smp.c            | 110 ++++++++++
 arch/riscv/kernel/smpboot.c        | 103 +++++++++
 arch/riscv/kernel/stacktrace.c     | 177 +++++++++++++++
 arch/riscv/kernel/sys_riscv.c      |  85 ++++++++
 arch/riscv/kernel/syscall_table.c  |  25 +++
 arch/riscv/kernel/traps.c          | 183 ++++++++++++++++
 arch/riscv/kernel/vdso.c           | 125 +++++++++++
 arch/riscv/kernel/vdso/.gitignore  |   1 +
 arch/riscv/kernel/vdso/Makefile    |  61 ++++++
 arch/riscv/kernel/vdso/sigreturn.S |  24 ++
 arch/riscv/kernel/vdso/vdso.S      |  27 +++
 arch/riscv/kernel/vdso/vdso.lds.S  |  76 +++++++
 arch/riscv/kernel/vmlinux.lds.S    |  92 ++++++++
 28 files changed, 3261 insertions(+)
 create mode 100644 arch/riscv/kernel/.gitignore
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/process.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/signal.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.c
 create mode 100644 arch/riscv/kernel/stacktrace.c
 create mode 100644 arch/riscv/kernel/sys_riscv.c
 create mode 100644 arch/riscv/kernel/syscall_table.c
 create mode 100644 arch/riscv/kernel/traps.c
 create mode 100644 arch/riscv/kernel/vdso.c
 create mode 100644 arch/riscv/kernel/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/.gitignore new file +1 -0
new file mode 100644
index 000000000000..b51634f6a7cd
@@ -0,0 +1 @@
+/vmlinux.lds
arch/riscv/kernel/Makefile new file +16 -0
new file mode 100644
index 000000000000..b6de129d4a23
@@ -0,0 +1,16 @@
+#
+# Makefile for the RISC-V Linux kernel
+#
+
+extra-y := head.o vmlinux.lds
+
+obj-y	:= cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
+	   signal.o syscall_table.o sys_riscv.o traps.o \
+	   riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/
+
+CFLAGS_setup.o := -mcmodel=medany
+
+obj-$(CONFIG_SMP)		+= smpboot.o smp.o
+obj-$(CONFIG_MODULES)		+= module.o
+
+clean:
arch/riscv/kernel/asm-offsets.c new file +316 -0

316 lines not on this page · raw message

arch/riscv/kernel/cacheinfo.c new file +103 -0

103 lines not on this page · raw message

arch/riscv/kernel/cpu.c new file +89 -0

89 lines not on this page · raw message

arch/riscv/kernel/entry.S new file +437 -0

437 lines not on this page · raw message

arch/riscv/kernel/head.S new file +147 -0

147 lines not on this page · raw message

arch/riscv/kernel/irq.c new file +20 -0
new file mode 100644
index 000000000000..737d7cce2c6d
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/irqchip.h>
+
+void __init init_IRQ(void)
+{
+	irqchip_init();
+}
arch/riscv/kernel/module.c new file +215 -0

215 lines not on this page · raw message

arch/riscv/kernel/process.c new file +132 -0

132 lines not on this page · raw message

arch/riscv/kernel/ptrace.c new file +147 -0

147 lines not on this page · raw message

arch/riscv/kernel/reset.c new file +36 -0
new file mode 100644
index 000000000000..2a53d26ffdd6
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/reboot.h>
+#include <linux/export.h>
+#include <asm/sbi.h>
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_restart(char *cmd)
+{
+	do_kernel_restart(cmd);
+	while (1);
+}
+
+void machine_halt(void)
+{
+	machine_power_off();
+}
+
+void machine_power_off(void)
+{
+	sbi_shutdown();
+	while (1);
+}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
new file mode 100644
index 000000000000..ab0db6d48101
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2017 Zihao Yu
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/export.h>
+#include <linux/uaccess.h>
+
+/*
+ * Assembly functions that may be used (directly or indirectly) by modules
+ */
+EXPORT_SYMBOL(__copy_user);
+
arch/riscv/kernel/setup.c new file +240 -0

240 lines not on this page · raw message

arch/riscv/kernel/signal.c new file +257 -0

257 lines not on this page · raw message

arch/riscv/kernel/smp.c new file +110 -0

110 lines not on this page · raw message

arch/riscv/kernel/smpboot.c new file +103 -0

103 lines not on this page · raw message

arch/riscv/kernel/stacktrace.c new file +177 -0

177 lines not on this page · raw message

arch/riscv/kernel/sys_riscv.c new file +85 -0

85 lines not on this page · raw message

arch/riscv/kernel/syscall_table.c new file +25 -0
new file mode 100644
index 000000000000..8fa239b67cbc
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2009 Arnd Bergmann <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/syscalls.h>
+
+#include <asm/syscalls.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call)	[nr] = (call),
+
+void *sys_call_table[__NR_syscalls] = {
+	[0 ... __NR_syscalls - 1] = sys_ni_syscall,
+#include <asm/unistd.h>
+};
arch/riscv/kernel/traps.c new file +183 -0

183 lines not on this page · raw message

arch/riscv/kernel/vdso.c new file +125 -0

125 lines not on this page · raw message

arch/riscv/kernel/vdso/.gitignore new file +1 -0
new file mode 100644
index 000000000000..f8b69d84238e
@@ -0,0 +1 @@
+vdso.lds
arch/riscv/kernel/vdso/Makefile new file +61 -0

19 lines not on this page · raw message

arch/riscv/kernel/vdso/sigreturn.S new file +24 -0
new file mode 100644
index 000000000000..f5aa3d72acfb

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.S new file +27 -0
new file mode 100644
index 000000000000..7055de5f9174

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.lds.S new file +76 -0

76 lines not on this page · raw message

arch/riscv/kernel/vmlinux.lds.S new file +92 -0

92 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.0

Part of the diff is not shown here. View the raw message.

author maintainer
#168 lore raw

PATCH 17/17 RISC-V: Makefile and Kconfig

In reply to Palmer Dabbelt

This patch adds RISC-V support to the build infastructure.

---
 Makefile                                  |   3 +-
 arch/riscv/Kconfig                        | 318 ++++++++++++++++++++++++++++++
 arch/riscv/Makefile                       |  64 ++++++
 arch/riscv/configs/freedom-u500_defconfig |  53 +++++
 arch/riscv/configs/spike32_defconfig      |  50 +++++
 arch/riscv/configs/spike64_defconfig      |  46 +++++
 6 files changed, 533 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/freedom-u500_defconfig
 create mode 100644 arch/riscv/configs/spike32_defconfig
 create mode 100644 arch/riscv/configs/spike64_defconfig
Makefile +2 -1
index 853ae9179af9..88711cbcc3ca 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 				  -e s/arm.*/arm/ -e s/sa110/arm/ \
 				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
 				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+				  -e s/riscv.*/riscv/)
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
arch/riscv/Kconfig new file +318 -0

318 lines not on this page · raw message

arch/riscv/Makefile new file +64 -0

64 lines not on this page · raw message

arch/riscv/configs/freedom-u500_defconfig new file +53 -0

53 lines not on this page · raw message

arch/riscv/configs/spike32_defconfig new file +50 -0

50 lines not on this page · raw message

arch/riscv/configs/spike64_defconfig new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#74 lore raw

RISC-V Linux Port v2

In reply to Palmer Dabbelt

Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.

A highlight of the changes since the v1 patch set includes:

* We've split out our drivers into the right places, which means now there's a lot more patches. I'll be submitting these patches to various subsystem maintainers and including them in any future RISC-V patch sets until they've been merged.

* The SBI console driver has been completely rewritten to use the HVC helpers and is now significantly smaller.

* We've begun to use weaker barries as opposed to just the big "fence". There's still some work to do here, specifically:
- We need fences in the realxed MMIO functions.
- The non-relaxed MMIO functions are missing R/W bits on their fences.
- Many AMOs need the aq and rl bits set.

* We now have thread_info in task_struct. As a result, sscratch now contains TP instead of SP. This was necessary because thread_info is no longer on the stack.

* A few shared routines have been added that we use instead of creating another arch copy.

Here's my TODO list

* The memory model changes indicated above.

* I need to go through checkpatch again to make sure none of the messages are valid problems.

* Put an implementation of atomic compare/exchange in the VDSO when atomic instructions are enabled, otherwise insert stubs to the cmpxchg syscall.

* Remove the extra multiplexing in the cmpxchg syscall.

Aside from those two releatively minor ABI issues, I think our ABI is in good shape. Unless there are any other issues that crop up I'd like to begin our glibc submission early next week.

[PATCH 01/17] drivers: support PCIe in RISCV
[PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt [PATCH 03/17] base: fix order of OF initialization [PATCH 04/17] Documentation: atomic_ops.txt is
[PATCH 05/17] MAINTAINERS: Add RISC-V
[PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource} [PATCH 07/17] lib: Add shared copies of some GCC library routines [PATCH 08/17] dts: include documentation for the RISC-V interrupt [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource [PATCH 10/17] irqchip: New RISC-V PLIC Driver
[PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver [PATCH 12/17] tty: New RISC-V SBI Console Driver
[PATCH 13/17] RISC-V: Add include subdirectory
[PATCH 14/17] RISC-V: lib files
[PATCH 15/17] RISC-V: Add mm subdirectory
[PATCH 16/17] RISC-V: Add kernel subdirectory
[PATCH 17/17] RISC-V: Makefile and Kconfig

author maintainer
#75 lore raw

PATCH 1/17 drivers: support PCIe in RISCV

From: "Wesley W. Terpstra" <[email protected]>

There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.

---
 drivers/pci/Makefile     | 1 +
 drivers/pci/host/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/pci/Makefile +1 -0
index 462c1f5f5546..a29d9ec05d13 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o
 obj-$(CONFIG_TILE) += setup-irq.o
 obj-$(CONFIG_SPARC_LEON) += setup-irq.o
 obj-$(CONFIG_M68K) += setup-irq.o
+obj-$(CONFIG_RISCV) += setup-irq.o
 
 #
 # ACPI Related PCI FW Functions
drivers/pci/host/Kconfig +1 -1
index 7f47cd5e10a5..5148f3d3cab7 100644
@@ -71,7 +71,7 @@ config PCI_HOST_GENERIC
 
 config PCIE_XILINX
 	bool "Xilinx AXI PCIe host bridge support"
-	depends on ARCH_ZYNQ || MICROBLAZE
+	depends on ARCH_ZYNQ || MICROBLAZE || RISCV
 	help
 	  Say 'Y' here if you want kernel to support the Xilinx AXI PCIe
 	  Host Bridge driver.
Signature · 1 line
2.13.0
author maintainer
#85 lore raw

PATCH 2/17 pcie-xilinx: add missing 5th legacy interrupt

In reply to Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

These are numbered from 1.

---
 drivers/pci/host/pcie-xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +2 -2
index 2fe2df51f9f8..8804145d399a 100644
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
 			val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
 				XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
 			generic_handle_irq(irq_find_mapping(port->leg_domain,
-							    val));
+							    val + 1));
 		}
 	}
 
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 		return -ENODEV;
 	}
 
-	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 4,
+	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 5,
 						 &intx_domain_ops,
 						 port);
 	if (!port->leg_domain) {
Signature · 1 line
2.13.0
author maintainer
#107 lore raw

PATCH 7/17 lib: Add shared copies of some GCC library routines

In reply to Palmer Dabbelt

Many ports (m32r, microblaze, mips, parisc, score, and sparc) use functionally identical copies of various GCC library routine files, which came up as we were submitting the RISC-V port (which also uses some of these).

This patch adds a new copy of these library routine files, which are functionally identical to the various other copies. These are availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't used anywhere.

---
 include/lib/libgcc.h | 44 ++++++++++++++++++++++++++++++++
 lib/Kconfig          | 18 +++++++++++++
 lib/Makefile         |  8 ++++++
 lib/ashldi3.c        | 45 ++++++++++++++++++++++++++++++++
 lib/ashrdi3.c        | 46 +++++++++++++++++++++++++++++++++
 lib/cmpdi2.c         | 42 ++++++++++++++++++++++++++++++
 lib/lshrdi3.c        | 45 ++++++++++++++++++++++++++++++++
 lib/muldi3.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/ucmpdi2.c        | 35 +++++++++++++++++++++++++
 9 files changed, 355 insertions(+)
 create mode 100644 include/lib/libgcc.h
 create mode 100644 lib/ashldi3.c
 create mode 100644 lib/ashrdi3.c
 create mode 100644 lib/cmpdi2.c
 create mode 100644 lib/lshrdi3.c
 create mode 100644 lib/muldi3.c
 create mode 100644 lib/ucmpdi2.c
include/lib/libgcc.h new file +44 -0
new file mode 100644
index 000000000000..a5397e34e005
@@ -0,0 +1,44 @@
+/*
+ * include/lib/libgcc.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+
+#ifndef __LIB_LIBGCC_H
+#define __LIB_LIBGCC_H
+
+#include <asm/byteorder.h>
+
+typedef int word_type __attribute__ ((mode (__word__)));
+
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+	int high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+	int low, high;
+};
+#else
+#error I feel sick.
+#endif
+
+typedef union {
+	struct DWstruct s;
+	long long ll;
+} DWunion;
+
+#endif /* __ASM_LIBGCC_H */
lib/Kconfig +18 -0
index 0c8b78a9ae2e..7a9c934d91fd 100644
@@ -565,3 +565,21 @@ config PRIME_NUMBERS
 	tristate
 
 endmenu
+
+config GENERIC_ASHLDI3
+	def_bool n
+
+config GENERIC_ASHRDI3
+	def_bool n
+
+config GENERIC_LSHRDI3
+	def_bool n
+
+config GENERIC_MULDI3
+	def_bool n
+
+config GENERIC_CMPDI2
+	def_bool n
+
+config GENERIC_UCMPDI2
+	def_bool n
lib/Makefile +8 -0
index 0166fbc0fa81..5f68242f7774 100644
@@ -243,3 +243,11 @@ UBSAN_SANITIZE_ubsan.o := n
 obj-$(CONFIG_SBITMAP) += sbitmap.o
 
 obj-$(CONFIG_PARMAN) += parman.o
+
+# GCC library routines
+obj-$(CONFIG_GENERIC_ASHLDI3) += ashldi3.o
+obj-$(CONFIG_GENERIC_ASHRDI3) += ashrdi3.o
+obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o
+obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o
+obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o
+obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
lib/ashldi3.c new file +45 -0

45 lines not on this page · raw message

lib/ashrdi3.c new file +46 -0

46 lines not on this page · raw message

lib/cmpdi2.c new file +42 -0

42 lines not on this page · raw message

lib/lshrdi3.c new file +45 -0

45 lines not on this page · raw message

lib/muldi3.c new file +72 -0

72 lines not on this page · raw message

lib/ucmpdi2.c new file +35 -0
new file mode 100644
index 000000000000..49a53505c8e3
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+#include <linux/module.h>
+#include <lib/libgcc.h>
+
+word_type __ucmpdi2(unsigned long long a, unsigned long long b)
+{
+	const DWunion au = {.ll = a};
+	const DWunion bu = {.ll = b};
+
+	if ((unsigned int) au.s.high < (unsigned int) bu.s.high)
+		return 0;
+	else if ((unsigned int) au.s.high > (unsigned int) bu.s.high)
+		return 2;
+	if ((unsigned int) au.s.low < (unsigned int) bu.s.low)
+		return 0;
+	else if ((unsigned int) au.s.low > (unsigned int) bu.s.low)
+		return 2;
+	return 1;
+}
+EXPORT_SYMBOL(__ucmpdi2);
Signature · 1 line
2.13.0
author maintainer
#119 lore raw

PATCH 8/17 dts: include documentation for the RISC-V interrupt controllers

In reply to Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
new file mode 100644
index 000000000000..62f02e834ff9
@@ -0,0 +1,46 @@
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------
+
+RISC-V cores include Control Status Registers (CSRs) which are local to each
+hart and can be read or written by software. Some of these CSRs are used to
+control local interrupts connected to the core.
+
+Typical examples of local interrupts on a RISC-V core include: software IPI
+interrupts, timer interrupts, and a link to the PLIC interrupt controller.
+
+Required properties:
+- compatible : "riscv,cpu-intc"
+- #interrupt-cells : should be <1>
+- interrupt-controller : Identifies the node as an interrupt controller
+
+Furthermore, this interrupt-controller MUST be embedded inside the cpu
+definition of the hart whose CSRs control these local interrupts.
+
+Example:
+
+	cpu1: cpu@1 {
+		clock-frequency = <1600000000>;
+		compatible = "riscv";
+		d-cache-block-size = <64>;
+		d-cache-sets = <64>;
+		d-cache-size = <16384>;
+		d-tlb-sets = <1>;
+		d-tlb-size = <32>;
+		device_type = "cpu";
+		i-cache-block-size = <64>;
+		i-cache-sets = <64>;
+		i-cache-size = <16384>;
+		i-tlb-sets = <1>;
+		i-tlb-size = <32>;
+		mmu-type = "riscv,sv39";
+		next-level-cache = <&L2>;
+		reg = <1>;
+		riscv,isa = "rv64imac";
+		status = "okay";
+		tlb-split;
+		cpu1-intc: interrupt-controller {
+			#interrupt-cells = <1>;
+			compatible = "riscv,cpu-intc";
+			interrupt-controller;
+		};
+	};
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#141 lore raw

PATCH 12/17 tty: New RISC-V SBI Console Driver

In reply to Palmer Dabbelt

This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.

The SBI console is made availiable for early printk messages and is also availiable as a regular console.

---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
index 574da15fe618..f3774adab240 100644
@@ -114,4 +114,15 @@ config HVCS
 	  which will also be compiled when this driver is built as a
 	  module.
 
+config HVC_SBI
+	bool "SBI console support"
+	depends on RISCV
+	select HVC_DRIVER
+	default y
+	help
+	  This enables support for console output via RISC-V SBI calls, which
+	  is normally used only during boot to output printk.
+
+	  If you don't know what do to here, say Y.
+
 endif # TTY
drivers/tty/hvc/Makefile +1 -0
index 6a2702be76d1..2d63bfe4a96b 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV)		+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)		+= hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)	+= hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS)		+= hvcs.o
+obj-$(CONFIG_HVC_SBI)		+= hvc_sbi.o
drivers/tty/hvc/hvc_sbi.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#98 lore raw

PATCH 5/17 MAINTAINERS: Add RISC-V

In reply to Palmer Dabbelt

From: Jonathan Neuschäfer <[email protected]>

RISC-V needs a MAINTAINERS entry. Let's add one.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 7a28acd7f525..50b18dad8c22 100644
@@ -10877,6 +10877,14 @@ M:	Maxim Levitsky <[email protected]>
 S:	Maintained
 F:	drivers/memstick/host/r592.*
 
+RISC-V ARCHITECTURE
+M:	Palmer Dabbelt <[email protected]>
+M:	Albert Ou <[email protected]>
+L:	[email protected]
+T:	git https://github.com/riscv/riscv-linux
+S:	Supported
+F:	arch/riscv/
+
 ROCCAT DRIVERS
 M:	Stefan Achatz <[email protected]>
 W:	http://sourceforge.net/projects/roccat/
Signature · 1 line
2.13.0
author maintainer
#120 lore raw

PATCH 9/17 clocksource/timer-riscv: New RISC-V Clocksource

In reply to Palmer Dabbelt

The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.

---
 drivers/clocksource/Kconfig       |   8 +++
 drivers/clocksource/Makefile      |   1 +
 drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/clocksource/timer-riscv.c
drivers/clocksource/Kconfig +8 -0
index 545d541ae20e..1c2c6e7c7fab 100644
@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC
 	  Enable this option to use the Low Power controller timer
 	  as clocksource.
 
+config CLKSRC_RISCV
+	#bool "Clocksource for the RISC-V platform"
+	def_bool y if RISCV
+	depends on RISCV
+	help
+	  This enables a clocksource based on the RISC-V SBI timer, which is
+	  built in to all RISC-V systems.
+
 endmenu
drivers/clocksource/Makefile +1 -0
index 2b5b56a6f00f..408ed9d314dc 100644
@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16)		+= h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)			+= h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)		+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP)		+= numachip.o
+obj-$(CONFIG_CLKSRC_RISCV)		+= timer-riscv.o
drivers/clocksource/timer-riscv.c new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#135 lore raw

PATCH 11/17 irqchip: RISC-V Local Interrupt Controller Driver

In reply to Palmer Dabbelt

This patch adds a driver that manages the local interrupts on each RISC-V hart, as specifiec by the RISC-V supervisor level ISA manual. The local interrupt controller manages software interrupts, timer interrupts, and hardware interrupts (which are routed via the platform level interrupt controller). Per-hart local interrupt controllers are found on all RISC-V systems.

---
 drivers/irqchip/Kconfig          |  14 +++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-intc.c | 239 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/Kconfig +14 -0
index 2906d63934ef..dfde170e5886 100644
@@ -313,3 +313,17 @@ config RISCV_PLIC
 	   interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
 
 	   If you don't know what to do here, say Y.
+
+config RISCV_INTC
+	def_bool y if RISCV
+	#bool "RISC-V Interrupt Controller"
+	depends on RISCV
+	default y
+	help
+	   This enables support for the local interrupt controller found in
+	   standard RISC-V systems.  The local interrupt controller handles
+	   timer interrupts, software interrupts, and hardware interrupts.
+	   Without a local interrupt controller the system will be unable to
+	   handle any interrupts, including those passed via the PLIC.
+
+	   If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
index bed94cc89146..bc9a6b45903b 100644
@@ -77,3 +77,4 @@ obj-$(CONFIG_ARCH_ASPEED)		+= irq-aspeed-vic.o
 obj-$(CONFIG_STM32_EXTI) 		+= irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)		+= qcom-irq-combiner.o
 obj-$(CONFIG_RISCV_PLIC)		+= irq-riscv-plic.o
+obj-$(CONFIG_RISCV_INTC)		+= irq-riscv-intc.o
drivers/irqchip/irq-riscv-intc.c new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#169 lore raw

PATCH 17/17 RISC-V: Makefile and Kconfig

In reply to Palmer Dabbelt

This patch adds RISC-V support to the build infastructure.

---
 Makefile                                  |   3 +-
 arch/riscv/Kconfig                        | 318 ++++++++++++++++++++++++++++++
 arch/riscv/Makefile                       |  64 ++++++
 arch/riscv/configs/freedom-u500_defconfig |  53 +++++
 arch/riscv/configs/spike32_defconfig      |  50 +++++
 arch/riscv/configs/spike64_defconfig      |  46 +++++
 6 files changed, 533 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/freedom-u500_defconfig
 create mode 100644 arch/riscv/configs/spike32_defconfig
 create mode 100644 arch/riscv/configs/spike64_defconfig
Makefile +2 -1
index 853ae9179af9..88711cbcc3ca 100644
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
 				  -e s/arm.*/arm/ -e s/sa110/arm/ \
 				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
 				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+				  -e s/riscv.*/riscv/)
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---------------------------------------------------------------------------
arch/riscv/Kconfig new file +318 -0

318 lines not on this page · raw message

arch/riscv/Makefile new file +64 -0

64 lines not on this page · raw message

arch/riscv/configs/freedom-u500_defconfig new file +53 -0

53 lines not on this page · raw message

arch/riscv/configs/spike32_defconfig new file +50 -0

50 lines not on this page · raw message

arch/riscv/configs/spike64_defconfig new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#134 lore raw

PATCH 10/17 irqchip: New RISC-V PLIC Driver

In reply to Palmer Dabbelt

This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.

---
 drivers/irqchip/Kconfig          |  12 ++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +12 -0
index 478f8ace2664..2906d63934ef 100644
@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER
 	help
 	  Say yes here to add support for the IRQ combiner devices embedded
 	  in Qualcomm Technologies chips.
+
+config RISCV_PLIC
+        bool "Platform-Level Interrupt Controller"
+	depends on RISCV
+        default y
+        help
+	   This enables support for the PLIC chip found in standard RISC-V
+	   systems. The PLIC is the top-most interrupt controller found in
+	   the system, connected directly to the core complex. All other
+	   interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+	   If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
index b64c59b838a0..bed94cc89146 100644
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC)			+= irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)		+= irq-aspeed-vic.o
 obj-$(CONFIG_STM32_EXTI) 		+= irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)		+= qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_PLIC)		+= irq-riscv-plic.o
drivers/irqchip/irq-riscv-plic.c new file +253 -0

253 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#165 lore raw

PATCH 15/17 RISC-V: Add mm subdirectory

In reply to Palmer Dabbelt

These files are mostly based on the score port, but as all the non-stub functions are very ISA specific they've been heavily modified.

---
 arch/riscv/mm/Makefile  |   1 +
 arch/riscv/mm/extable.c |  37 +++++++
 arch/riscv/mm/fault.c   | 280 ++++++++++++++++++++++++++++++++++++++++++++++++
 arch/riscv/mm/init.c    |  72 +++++++++++++
 arch/riscv/mm/ioremap.c |  93 ++++++++++++++++
 5 files changed, 483 insertions(+)
 create mode 100644 arch/riscv/mm/Makefile
 create mode 100644 arch/riscv/mm/extable.c
 create mode 100644 arch/riscv/mm/fault.c
 create mode 100644 arch/riscv/mm/init.c
 create mode 100644 arch/riscv/mm/ioremap.c
arch/riscv/mm/Makefile new file +1 -0
new file mode 100644
index 000000000000..36ebe6feb5d6
@@ -0,0 +1 @@
+obj-y := init.o fault.o extable.o ioremap.o
arch/riscv/mm/extable.c new file +37 -0
new file mode 100644
index 000000000000..11bb9417123b
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
+ *  Lennox Wu <[email protected]>
+ *  Chen Liqin <[email protected]>
+ * Copyright (C) 2013 Regents of the University of California
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.,
+ */
+
+
+#include <linux/extable.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+	const struct exception_table_entry *fixup;
+
+	fixup = search_exception_tables(regs->sepc);
+	if (fixup) {
+		regs->sepc = fixup->fixup;
+		return 1;
+	}
+	return 0;
+}
arch/riscv/mm/fault.c new file +280 -0

280 lines not on this page · raw message

arch/riscv/mm/init.c new file +72 -0

72 lines not on this page · raw message

arch/riscv/mm/ioremap.c new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#167 lore raw

PATCH 16/17 RISC-V: Add kernel subdirectory

In reply to Palmer Dabbelt

These files were mostly based on the score port, but many of them are very ISA specific.

---
 arch/riscv/kernel/.gitignore       |   1 +
 arch/riscv/kernel/Makefile         |  16 ++
 arch/riscv/kernel/asm-offsets.c    | 316 +++++++++++++++++++++++++++
 arch/riscv/kernel/cacheinfo.c      | 103 +++++++++
 arch/riscv/kernel/cpu.c            |  89 ++++++++
 arch/riscv/kernel/entry.S          | 437 +++++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           | 147 +++++++++++++
 arch/riscv/kernel/irq.c            |  20 ++
 arch/riscv/kernel/module.c         | 215 ++++++++++++++++++
 arch/riscv/kernel/process.c        | 132 +++++++++++
 arch/riscv/kernel/ptrace.c         | 147 +++++++++++++
 arch/riscv/kernel/reset.c          |  36 +++
 arch/riscv/kernel/riscv_ksyms.c    |  16 ++
 arch/riscv/kernel/setup.c          | 240 ++++++++++++++++++++
 arch/riscv/kernel/signal.c         | 257 ++++++++++++++++++++++
 arch/riscv/kernel/smp.c            | 110 ++++++++++
 arch/riscv/kernel/smpboot.c        | 103 +++++++++
 arch/riscv/kernel/stacktrace.c     | 177 +++++++++++++++
 arch/riscv/kernel/sys_riscv.c      |  85 ++++++++
 arch/riscv/kernel/syscall_table.c  |  25 +++
 arch/riscv/kernel/traps.c          | 183 ++++++++++++++++
 arch/riscv/kernel/vdso.c           | 125 +++++++++++
 arch/riscv/kernel/vdso/.gitignore  |   1 +
 arch/riscv/kernel/vdso/Makefile    |  61 ++++++
 arch/riscv/kernel/vdso/sigreturn.S |  24 ++
 arch/riscv/kernel/vdso/vdso.S      |  27 +++
 arch/riscv/kernel/vdso/vdso.lds.S  |  76 +++++++
 arch/riscv/kernel/vmlinux.lds.S    |  92 ++++++++
 28 files changed, 3261 insertions(+)
 create mode 100644 arch/riscv/kernel/.gitignore
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/process.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/signal.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.c
 create mode 100644 arch/riscv/kernel/stacktrace.c
 create mode 100644 arch/riscv/kernel/sys_riscv.c
 create mode 100644 arch/riscv/kernel/syscall_table.c
 create mode 100644 arch/riscv/kernel/traps.c
 create mode 100644 arch/riscv/kernel/vdso.c
 create mode 100644 arch/riscv/kernel/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/.gitignore new file +1 -0
new file mode 100644
index 000000000000..b51634f6a7cd
@@ -0,0 +1 @@
+/vmlinux.lds
arch/riscv/kernel/Makefile new file +16 -0
new file mode 100644
index 000000000000..b6de129d4a23
@@ -0,0 +1,16 @@
+#
+# Makefile for the RISC-V Linux kernel
+#
+
+extra-y := head.o vmlinux.lds
+
+obj-y	:= cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
+	   signal.o syscall_table.o sys_riscv.o traps.o \
+	   riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/
+
+CFLAGS_setup.o := -mcmodel=medany
+
+obj-$(CONFIG_SMP)		+= smpboot.o smp.o
+obj-$(CONFIG_MODULES)		+= module.o
+
+clean:
arch/riscv/kernel/asm-offsets.c new file +316 -0

316 lines not on this page · raw message

arch/riscv/kernel/cacheinfo.c new file +103 -0

103 lines not on this page · raw message

arch/riscv/kernel/cpu.c new file +89 -0

89 lines not on this page · raw message

arch/riscv/kernel/entry.S new file +437 -0

437 lines not on this page · raw message

arch/riscv/kernel/head.S new file +147 -0

147 lines not on this page · raw message

arch/riscv/kernel/irq.c new file +20 -0
new file mode 100644
index 000000000000..737d7cce2c6d
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/irqchip.h>
+
+void __init init_IRQ(void)
+{
+	irqchip_init();
+}
arch/riscv/kernel/module.c new file +215 -0

215 lines not on this page · raw message

arch/riscv/kernel/process.c new file +132 -0

132 lines not on this page · raw message

arch/riscv/kernel/ptrace.c new file +147 -0

147 lines not on this page · raw message

arch/riscv/kernel/reset.c new file +36 -0
new file mode 100644
index 000000000000..2a53d26ffdd6
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/reboot.h>
+#include <linux/export.h>
+#include <asm/sbi.h>
+
+void (*pm_power_off)(void) = machine_power_off;
+EXPORT_SYMBOL(pm_power_off);
+
+void machine_restart(char *cmd)
+{
+	do_kernel_restart(cmd);
+	while (1);
+}
+
+void machine_halt(void)
+{
+	machine_power_off();
+}
+
+void machine_power_off(void)
+{
+	sbi_shutdown();
+	while (1);
+}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
new file mode 100644
index 000000000000..ab0db6d48101
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2017 Zihao Yu
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/export.h>
+#include <linux/uaccess.h>
+
+/*
+ * Assembly functions that may be used (directly or indirectly) by modules
+ */
+EXPORT_SYMBOL(__copy_user);
+
arch/riscv/kernel/setup.c new file +240 -0

240 lines not on this page · raw message

arch/riscv/kernel/signal.c new file +257 -0

257 lines not on this page · raw message

arch/riscv/kernel/smp.c new file +110 -0

110 lines not on this page · raw message

arch/riscv/kernel/smpboot.c new file +103 -0

103 lines not on this page · raw message

arch/riscv/kernel/stacktrace.c new file +177 -0

177 lines not on this page · raw message

arch/riscv/kernel/sys_riscv.c new file +85 -0

85 lines not on this page · raw message

arch/riscv/kernel/syscall_table.c new file +25 -0
new file mode 100644
index 000000000000..8fa239b67cbc
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2009 Arnd Bergmann <[email protected]>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/syscalls.h>
+
+#include <asm/syscalls.h>
+
+#undef __SYSCALL
+#define __SYSCALL(nr, call)	[nr] = (call),
+
+void *sys_call_table[__NR_syscalls] = {
+	[0 ... __NR_syscalls - 1] = sys_ni_syscall,
+#include <asm/unistd.h>
+};
arch/riscv/kernel/traps.c new file +183 -0

183 lines not on this page · raw message

arch/riscv/kernel/vdso.c new file +125 -0

125 lines not on this page · raw message

arch/riscv/kernel/vdso/.gitignore new file +1 -0
new file mode 100644
index 000000000000..f8b69d84238e
@@ -0,0 +1 @@
+vdso.lds
arch/riscv/kernel/vdso/Makefile new file +61 -0

19 lines not on this page · raw message

arch/riscv/kernel/vdso/sigreturn.S new file +24 -0
new file mode 100644
index 000000000000..f5aa3d72acfb

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.S new file +27 -0
new file mode 100644
index 000000000000..7055de5f9174

Lines of this file are not shown. View the raw message.

arch/riscv/kernel/vdso/vdso.lds.S new file +76 -0

76 lines not on this page · raw message

arch/riscv/kernel/vmlinux.lds.S new file +92 -0

92 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.0

Part of the diff is not shown here. View the raw message.

#87 lore raw

Re: [PATCH 03/17] base: fix order of OF initialization

In reply to Palmer Dabbelt

CC devicetree folks

Quoted 29 lines · Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

This fixes: [ 0.010000] cpu cpu0: Error -2 creating of_node link
... which you get for every CPU on all architectures with a OF cpu/ node.

This affects riscv, nios, etc.

---
 drivers/base/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/init.c +1 -2
index 48c0e220acc0..0dcd17e561d0 100644
@@ -31,9 +31,9 @@ void __init driver_init(void)
        /* These are also core pieces, but must come after the
         * core core pieces.
         */
+       of_core_init();
        platform_bus_init();
        cpu_dev_init();
        memory_dev_init();
        container_dev_init();
-       of_core_init();
 }
--

2.13.0

#109 lore raw

Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers

In reply to Palmer Dabbelt

CC irqchip and devicetree folks

Quoted 114 lines · Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

---
 .../interrupt-controller/riscv,cpu-intc.txt        | 46 ++++++++++++++++++++++
 .../bindings/interrupt-controller/riscv,plic0.txt  | 44 +++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
new file mode 100644
index 000000000000..62f02e834ff9
@@ -0,0 +1,46 @@
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------
+
+RISC-V cores include Control Status Registers (CSRs) which are local to each
+hart and can be read or written by software. Some of these CSRs are used to
+control local interrupts connected to the core.
+
+Typical examples of local interrupts on a RISC-V core include: software IPI
+interrupts, timer interrupts, and a link to the PLIC interrupt controller.
+
+Required properties:
+- compatible : "riscv,cpu-intc"
+- #interrupt-cells : should be <1>
+- interrupt-controller : Identifies the node as an interrupt controller
+
+Furthermore, this interrupt-controller MUST be embedded inside the cpu
+definition of the hart whose CSRs control these local interrupts.
+
+Example:
+
+       cpu1: cpu@1 {
+               clock-frequency = <1600000000>;
+               compatible = "riscv";
+               d-cache-block-size = <64>;
+               d-cache-sets = <64>;
+               d-cache-size = <16384>;
+               d-tlb-sets = <1>;
+               d-tlb-size = <32>;
+               device_type = "cpu";
+               i-cache-block-size = <64>;
+               i-cache-sets = <64>;
+               i-cache-size = <16384>;
+               i-tlb-sets = <1>;
+               i-tlb-size = <32>;
+               mmu-type = "riscv,sv39";
+               next-level-cache = <&L2>;
+               reg = <1>;
+               riscv,isa = "rv64imac";
+               status = "okay";
+               tlb-split;
+               cpu1-intc: interrupt-controller {
+                       #interrupt-cells = <1>;
+                       compatible = "riscv,cpu-intc";
+                       interrupt-controller;
+               };
+       };
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -1
new file mode 100644
index 000000000000..c05b5806f7d2
@@ -0,0 +1,44 @@
+RISC-V Platform-Level Interrupt Controller (PLIC)
+-------------------------------------------------
+
+RISC-V cores typically include a PLIC, which route interrupts from multiple
+devices to multiple hart contexts.  The PLIC is connected to the interrupt
+controller embedded in a RISC-V core via the interrupt-related CSRs.
+
+A hart context is a priviledge mode in a hardware execution thread.  For
+example, in an 4 core system with 2-way SMT, you have 8 harts and probably
+at least two priviledge modes per hart; machine mode and supervisor mode.
+
+Each interrupt can be enabled on per-context basis. Any context can claim
+a pending enabled interrupt and then release it once it has been handled.
+
+Each interrupt has a configurable priority. Higher priority interrupts are
+serviced firs. Each context can specify a priority threshold. Interrupts
+with priority below this threshold will not cause the PLIC to raise its
+interrupt line leading to the context.
+
+Required properties:
+- compatible : "riscv,plic0"
+- #address-cells : should be <0>
+- #interrupt-cells : should be <1>
+- interrupt-controller : Identifies the node as an interrupt controller
+- reg : Should contain 1 register range (address and length)
+- riscv,ndev : Specifies the number of interrupts attached to the PLIC
+- interrupts-extended : Specifies which contexts are connected to the PLIC
+
+Example:
+
+       plic: interrupt-controller@c000000 {
+               #address-cells = <0>;
+               #interrupt-cells = <1>;
+               compatible = "riscv,plic0";
+               interrupt-controller;
+               interrupts-extended = <
+                       &cpu0-intc 11
+                       &cpu1-intc 11 &cpu1-intc 9
+                       &cpu2-intc 11 &cpu2-intc 9
+                       &cpu3-intc 11 &cpu3-intc 9
+                       &cpu4-intc 11 &cpu4-intc 9>;
+               reg = <0xc000000 0x4000000>;
+               riscv,ndev = <10>;
+       };
--

2.13.0

#121 lore raw

Re: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource

In reply to Palmer Dabbelt

CC clocksource folks

Quoted 163 lines · Palmer Dabbelt

The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.

---
 drivers/clocksource/Kconfig       |   8 +++
 drivers/clocksource/Makefile      |   1 +
 drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/clocksource/timer-riscv.c
drivers/clocksource/Kconfig +8 -0
index 545d541ae20e..1c2c6e7c7fab 100644
@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC
          Enable this option to use the Low Power controller timer
          as clocksource.
 
+config CLKSRC_RISCV
+       #bool "Clocksource for the RISC-V platform"
+       def_bool y if RISCV
+       depends on RISCV
+       help
+         This enables a clocksource based on the RISC-V SBI timer, which is
+         built in to all RISC-V systems.
+
 endmenu
drivers/clocksource/Makefile +1 -0
index 2b5b56a6f00f..408ed9d314dc 100644
@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16)             += h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)                        += h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)            += clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP)             += numachip.o
+obj-$(CONFIG_CLKSRC_RISCV)             += timer-riscv.o
drivers/clocksource/timer-riscv.c new file +118 -1
new file mode 100644
index 000000000000..04ef7b9130b3
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/clocksource.h>
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/of.h>
+
+#include <asm/irq.h>
+#include <asm/csr.h>
+#include <asm/sbi.h>
+#include <asm/delay.h>
+
+unsigned long riscv_timebase;
+
+static DEFINE_PER_CPU(struct clock_event_device, clock_event);
+
+static int riscv_timer_set_next_event(unsigned long delta,
+       struct clock_event_device *evdev)
+{
+       sbi_set_timer(get_cycles() + delta);
+       return 0;
+}
+
+static int riscv_timer_set_oneshot(struct clock_event_device *evt)
+{
+       /* no-op; only one mode */
+       return 0;
+}
+
+static int riscv_timer_set_shutdown(struct clock_event_device *evt)
+{
+       /* can't stop the clock! */
+       return 0;
+}
+
+static u64 riscv_rdtime(struct clocksource *cs)
+{
+       return get_cycles();
+}
+
+static struct clocksource riscv_clocksource = {
+       .name = "riscv_clocksource",
+       .rating = 300,
+       .read = riscv_rdtime,
+#ifdef CONFIG_64BITS
+       .mask = CLOCKSOURCE_MASK(64),
+#else
+       .mask = CLOCKSOURCE_MASK(32),
+#endif /* CONFIG_64BITS */
+       .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+void riscv_timer_interrupt(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *evdev = &per_cpu(clock_event, cpu);
+
+       evdev->event_handler(evdev);
+}
+
+void __init init_clockevent(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *ce = &per_cpu(clock_event, cpu);
+
+       *ce = (struct clock_event_device){
+               .name = "riscv_timer_clockevent",
+               .features = CLOCK_EVT_FEAT_ONESHOT,
+               .rating = 300,
+               .cpumask = cpumask_of(cpu),
+               .set_next_event = riscv_timer_set_next_event,
+               .set_state_oneshot  = riscv_timer_set_oneshot,
+               .set_state_shutdown = riscv_timer_set_shutdown,
+       };
+
+       /* Enable timer interrupts */
+       csr_set(sie, SIE_STIE);
+
+       clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff);
+}
+
+static unsigned long __init of_timebase(void)
+{
+       struct device_node *cpu;
+       const __be32 *prop;
+
+       cpu = of_find_node_by_path("/cpus");
+       if (cpu) {
+               prop = of_get_property(cpu, "timebase-frequency", NULL);
+               if (prop)
+                       return be32_to_cpu(*prop);
+       }
+
+       return 10000000;
+}
+
+void __init time_init(void)
+{
+       riscv_timebase = of_timebase();
+       lpj_fine = riscv_timebase / HZ;
+
+       clocksource_register_hz(&riscv_clocksource, riscv_timebase);
+       init_clockevent();
+}
--

2.13.0

#127 lore raw

Re: [PATCH 10/17] irqchip: New RISC-V PLIC Driver

In reply to Palmer Dabbelt

CC irqchip folks

Quoted 303 lines · Palmer Dabbelt

This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.

---
 drivers/irqchip/Kconfig          |  12 ++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +12 -0
index 478f8ace2664..2906d63934ef 100644
@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER
        help
          Say yes here to add support for the IRQ combiner devices embedded
          in Qualcomm Technologies chips.
+
+config RISCV_PLIC
+        bool "Platform-Level Interrupt Controller"
+       depends on RISCV
+        default y
+        help
+          This enables support for the PLIC chip found in standard RISC-V
+          systems. The PLIC is the top-most interrupt controller found in
+          the system, connected directly to the core complex. All other
+          interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
+
+          If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
index b64c59b838a0..bed94cc89146 100644
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC)                       += irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)              += irq-aspeed-vic.o
 obj-$(CONFIG_STM32_EXTI)               += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)                += qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_PLIC)               += irq-riscv-plic.o
drivers/irqchip/irq-riscv-plic.c new file +253 -1
new file mode 100644
index 000000000000..906c8a62a911
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+
+/* From the RISC-V Privlidged Spec v1.10:
+ *
+ * Global interrupt sources are assigned small unsigned integer identifiers,
+ * beginning at the value 1.  An interrupt ID of 0 is reserved to mean “no
+ * interrupt”.  Interrupt identifiers are also used to break ties when two or
+ * more interrupt sources have the same assigned priority. Smaller values of
+ * interrupt ID take precedence over larger values of interrupt ID.
+ *
+ * It's not defined what the largest device ID is, so we're just fixing
+ * MAX_DEVICES right here (which is named oddly, as there will never be a
+ * device 0).
+ */
+#define MAX_DEVICES    1024
+#define MAX_CONTEXTS   15872
+
+#define PRIORITY_BASE  0
+#define ENABLE_BASE    0x2000
+#define ENABLE_SIZE    0x80
+#define HART_BASE      0x200000
+#define HART_SIZE      0x1000
+
+struct plic_hart_context {
+       u32 threshold;
+       u32 claim;
+};
+
+struct plic_enable_context {
+       atomic_t mask[32]; // 32-bit * 32-entry
+};
+
+struct plic_priority {
+       u32 prio[MAX_DEVICES];
+};
+
+struct plic_data {
+       struct irq_chip         chip;
+       struct irq_domain       *domain;
+       u32                     ndev;
+       void __iomem            *reg;
+       int                     handlers;
+       struct plic_handler     *handler;
+       char                    name[30];
+};
+
+struct plic_handler {
+       struct plic_hart_context        *context;
+       struct plic_data                *data;
+};
+
+static inline
+struct plic_hart_context *plic_hart_context(struct plic_data *data, size_t i)
+{
+       return (struct plic_hart_context *)((char *)data->reg + HART_BASE + HART_SIZE*i);
+}
+
+static inline
+struct plic_enable_context *plic_enable_context(struct plic_data *data, size_t i)
+{
+       return (struct plic_enable_context *)((char *)data->reg + ENABLE_BASE + ENABLE_SIZE*i);
+}
+
+static inline
+struct plic_priority *plic_priority(struct plic_data *data)
+{
+       return (struct plic_priority *)((char *)data->reg + PRIORITY_BASE);
+}
+
+static void plic_disable(struct plic_data *data, int i, int hwirq)
+{
+       struct plic_enable_context *enable = plic_enable_context(data, i);
+
+       atomic_and(~(1 << (hwirq % 32)), &enable->mask[hwirq / 32]);
+}
+
+static void plic_enable(struct plic_data *data, int i, int hwirq)
+{
+       struct plic_enable_context *enable = plic_enable_context(data, i);
+
+       atomic_or((1 << (hwirq % 32)), &enable->mask[hwirq / 32]);
+}
+
+// There is no need to mask/unmask PLIC interrupts
+// They are "masked" by reading claim and "unmasked" when writing it back.
+static void plic_irq_mask(struct irq_data *d) { }
+static void plic_irq_unmask(struct irq_data *d) { }
+
+static void plic_irq_enable(struct irq_data *d)
+{
+       struct plic_data *data = irq_data_get_irq_chip_data(d);
+       struct plic_priority *priority = plic_priority(data);
+       int i;
+
+       iowrite32(1, &priority->prio[d->hwirq]);
+       for (i = 0; i < data->handlers; ++i)
+               if (data->handler[i].context)
+                       plic_enable(data, i, d->hwirq);
+}
+
+static void plic_irq_disable(struct irq_data *d)
+{
+       struct plic_data *data = irq_data_get_irq_chip_data(d);
+       struct plic_priority *priority = plic_priority(data);
+       int i;
+
+       iowrite32(0, &priority->prio[d->hwirq]);
+       for (i = 0; i < data->handlers; ++i)
+               if (data->handler[i].context)
+                       plic_disable(data, i, d->hwirq);
+}
+
+static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq,
+                             irq_hw_number_t hwirq)
+{
+       struct plic_data *data = d->host_data;
+
+       irq_set_chip_and_handler(irq, &data->chip, handle_simple_irq);
+       irq_set_chip_data(irq, data);
+       irq_set_noprobe(irq);
+
+       return 0;
+}
+
+static const struct irq_domain_ops plic_irqdomain_ops = {
+       .map    = plic_irqdomain_map,
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static void plic_chained_handle_irq(struct irq_desc *desc)
+{
+       struct plic_handler *handler = irq_desc_get_handler_data(desc);
+       struct irq_chip *chip = irq_desc_get_chip(desc);
+       struct irq_domain *domain = handler->data->domain;
+       u32 what;
+
+       chained_irq_enter(chip, desc);
+
+       while ((what = ioread32(&handler->context->claim))) {
+               int irq = irq_find_mapping(domain, what);
+
+               if (irq > 0)
+                       generic_handle_irq(irq);
+               else
+                       handle_bad_irq(desc);
+               iowrite32(what, &handler->context->claim);
+       }
+
+       chained_irq_exit(chip, desc);
+}
+
+static int plic_init(struct device_node *node, struct device_node *parent)
+{
+       struct plic_data *data;
+       struct resource resource;
+       int i, ok = 0;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (WARN_ON(!data))
+               return -ENOMEM;
+
+       data->reg = of_iomap(node, 0);
+       if (WARN_ON(!data->reg))
+               return -EIO;
+
+       of_property_read_u32(node, "riscv,ndev", &data->ndev);
+       if (WARN_ON(!data->ndev))
+               return -EINVAL;
+
+       data->handlers = of_irq_count(node);
+       if (WARN_ON(!data->handlers))
+               return -EINVAL;
+
+       data->handler =
+               kcalloc(data->handlers, sizeof(*data->handler), GFP_KERNEL);
+       if (WARN_ON(!data->handler))
+               return -ENOMEM;
+
+       data->domain = irq_domain_add_linear(node, data->ndev+1, &plic_irqdomain_ops, data);
+       if (WARN_ON(!data->domain))
+               return -ENOMEM;
+
+       of_address_to_resource(node, 0, &resource);
+       snprintf(data->name, sizeof(data->name),
+                "riscv,plic0,%llx", resource.start);
+       data->chip.name = data->name;
+       data->chip.irq_mask = plic_irq_mask;
+       data->chip.irq_unmask = plic_irq_unmask;
+       data->chip.irq_enable = plic_irq_enable;
+       data->chip.irq_disable = plic_irq_disable;
+
+       for (i = 0; i < data->handlers; ++i) {
+               struct plic_handler *handler = &data->handler[i];
+               struct of_phandle_args parent;
+               int parent_irq, hwirq;
+
+               if (of_irq_parse_one(node, i, &parent))
+                       continue;
+               // skip context holes
+               if (parent.args[0] == -1)
+                       continue;
+
+               // skip any contexts that lead to inactive harts
+               if (of_device_is_compatible(parent.np, "riscv,cpu-intc") &&
+                   parent.np->parent &&
+                   riscv_of_processor_hart(parent.np->parent) < 0)
+                       continue;
+
+               parent_irq = irq_create_of_mapping(&parent);
+               if (!parent_irq)
+                       continue;
+
+               handler->context = plic_hart_context(data, i);
+               handler->data = data;
+               // hwirq prio must be > this to trigger an interrupt
+               iowrite32(0, &handler->context->threshold);
+
+               for (hwirq = 1; hwirq <= data->ndev; ++hwirq)
+                       plic_disable(data, i, hwirq);
+               irq_set_chained_handler_and_data(parent_irq, plic_chained_handle_irq, handler);
+               ++ok;
+       }
+
+       printk(KERN_INFO "%s: mapped %d interrupts to %d/%d handlers\n",
+              data->name, data->ndev, ok, data->handlers);
+       WARN_ON(!ok);
+       return 0;
+}
+
+IRQCHIP_DECLARE(plic0, "riscv,plic0", plic_init);
--

2.13.0

#136 lore raw

Re: [PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver

In reply to Palmer Dabbelt

CC irqchip folks

Quoted 293 lines · Palmer Dabbelt

This patch adds a driver that manages the local interrupts on each RISC-V hart, as specifiec by the RISC-V supervisor level ISA manual. The local interrupt controller manages software interrupts, timer interrupts, and hardware interrupts (which are routed via the platform level interrupt controller). Per-hart local interrupt controllers are found on all RISC-V systems.

---
 drivers/irqchip/Kconfig          |  14 +++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-intc.c | 239 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/Kconfig +14 -0
index 2906d63934ef..dfde170e5886 100644
@@ -313,3 +313,17 @@ config RISCV_PLIC
           interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC.
 
           If you don't know what to do here, say Y.
+
+config RISCV_INTC
+       def_bool y if RISCV
+       #bool "RISC-V Interrupt Controller"
+       depends on RISCV
+       default y
+       help
+          This enables support for the local interrupt controller found in
+          standard RISC-V systems.  The local interrupt controller handles
+          timer interrupts, software interrupts, and hardware interrupts.
+          Without a local interrupt controller the system will be unable to
+          handle any interrupts, including those passed via the PLIC.
+
+          If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
index bed94cc89146..bc9a6b45903b 100644
@@ -77,3 +77,4 @@ obj-$(CONFIG_ARCH_ASPEED)             += irq-aspeed-vic.o
 obj-$(CONFIG_STM32_EXTI)               += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)                += qcom-irq-combiner.o
 obj-$(CONFIG_RISCV_PLIC)               += irq-riscv-plic.o
+obj-$(CONFIG_RISCV_INTC)               += irq-riscv-intc.o
drivers/irqchip/irq-riscv-intc.c new file +239 -1
new file mode 100644
index 000000000000..8150a035aada
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/interrupt.h>
+#include <linux/ftrace.h>
+#include <linux/of.h>
+#include <linux/seq_file.h>
+
+#include <asm/ptrace.h>
+#include <asm/sbi.h>
+#include <asm/smp.h>
+
+struct riscv_irq_data {
+       struct irq_chip         chip;
+       struct irq_domain       *domain;
+       int                     hart;
+       char                    name[20];
+};
+DEFINE_PER_CPU(struct riscv_irq_data, riscv_irq_data);
+DEFINE_PER_CPU(atomic_long_t, riscv_early_sie);
+
+static void riscv_software_interrupt(void)
+{
+#ifdef CONFIG_SMP
+       irqreturn_t ret;
+
+       ret = handle_ipi();
+       if (ret != IRQ_NONE)
+               return;
+#endif
+
+       BUG();
+}
+
+asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
+{
+       struct pt_regs *old_regs = set_irq_regs(regs);
+       struct irq_domain *domain;
+
+       irq_enter();
+
+       /* There are three classes of interrupt: timer, software, and
+        * external devices.  We dispatch between them here.  External
+        * device interrupts use the generic IRQ mechanisms.
+        */
+       switch (cause) {
+       case INTERRUPT_CAUSE_TIMER:
+               riscv_timer_interrupt();
+               break;
+       case INTERRUPT_CAUSE_SOFTWARE:
+               riscv_software_interrupt();
+               break;
+       default:
+               domain = per_cpu(riscv_irq_data, smp_processor_id()).domain;
+               generic_handle_irq(irq_find_mapping(domain, cause));
+               break;
+       }
+
+       irq_exit();
+       set_irq_regs(old_regs);
+}
+
+static int riscv_irqdomain_map(struct irq_domain *d, unsigned int irq,
+                              irq_hw_number_t hwirq)
+{
+       struct riscv_irq_data *data = d->host_data;
+
+       irq_set_chip_and_handler(irq, &data->chip, handle_simple_irq);
+       irq_set_chip_data(irq, data);
+       irq_set_noprobe(irq);
+
+       return 0;
+}
+
+static const struct irq_domain_ops riscv_irqdomain_ops = {
+       .map    = riscv_irqdomain_map,
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static void riscv_irq_mask(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+
+       BUG_ON(smp_processor_id() != data->hart);
+       csr_clear(sie, 1 << (long)d->hwirq);
+}
+
+static void riscv_irq_unmask(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+
+       BUG_ON(smp_processor_id() != data->hart);
+       csr_set(sie, 1 << (long)d->hwirq);
+}
+
+static void riscv_irq_enable_helper(void *d)
+{
+       riscv_irq_unmask(d);
+}
+
+static void riscv_irq_enable(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+
+       /* There are two phases to setting up an interrupt: first we set a bit
+        * in this bookkeeping structure, which is used by trap_init to
+        * initialize SIE for each hart as it comes up.
+        */
+       atomic_long_or((1 << (long)d->hwirq),
+                      &per_cpu(riscv_early_sie, data->hart));
+
+       /* The CPU is usually online, so here we just attempt to enable the
+        * interrupt by writing SIE directly.  We need to write SIE on the
+        * correct hart, which might be another hart.
+        */
+       if (data->hart == smp_processor_id())
+               riscv_irq_unmask(d);
+       else if (cpu_online(data->hart))
+               smp_call_function_single(data->hart,
+                                        riscv_irq_enable_helper,
+                                        d,
+                                        true);
+}
+
+static void riscv_irq_disable_helper(void *d)
+{
+       riscv_irq_mask(d);
+}
+
+static void riscv_irq_disable(struct irq_data *d)
+{
+       struct riscv_irq_data *data = irq_data_get_irq_chip_data(d);
+
+       /* This is the mirror of riscv_irq_enable. */
+       atomic_long_and(~(1 << (long)d->hwirq),
+                       &per_cpu(riscv_early_sie, data->hart));
+       if (data->hart == smp_processor_id())
+               riscv_irq_mask(d);
+       else if (cpu_online(data->hart))
+               smp_call_function_single(data->hart,
+                                        riscv_irq_disable_helper,
+                                        d,
+                                        true);
+}
+
+static void riscv_irq_mask_noop(struct irq_data *d) { }
+
+static void riscv_irq_unmask_noop(struct irq_data *d) { }
+
+static void riscv_irq_enable_noop(struct irq_data *d)
+{
+       struct device_node *data = irq_data_get_irq_chip_data(d);
+       u32 hart;
+
+       if (!of_property_read_u32(data, "reg", &hart))
+               printk(
+                 KERN_WARNING "enabled interrupt %d for missing hart %d (this interrupt has no handler)\n",
+                 (int)d->hwirq, hart);
+}
+
+static struct irq_chip riscv_noop_chip = {
+       .name = "riscv,cpu-intc,noop",
+       .irq_mask = riscv_irq_mask_noop,
+       .irq_unmask = riscv_irq_unmask_noop,
+       .irq_enable = riscv_irq_enable_noop,
+};
+
+static int riscv_irqdomain_map_noop(struct irq_domain *d, unsigned int irq,
+                                   irq_hw_number_t hwirq)
+{
+       struct device_node *data = d->host_data;
+
+       irq_set_chip_and_handler(irq, &riscv_noop_chip, handle_simple_irq);
+       irq_set_chip_data(irq, data);
+       return 0;
+}
+
+static const struct irq_domain_ops riscv_irqdomain_ops_noop = {
+       .map    = riscv_irqdomain_map_noop,
+       .xlate  = irq_domain_xlate_onecell,
+};
+
+static int riscv_intc_init(struct device_node *node, struct device_node *parent)
+{
+       int hart;
+       struct riscv_irq_data *data;
+
+       if (parent)
+               return 0;
+
+       hart = riscv_of_processor_hart(node->parent);
+       if (hart < 0) {
+               /* If a hart is disabled, create a no-op irq domain.  Devices
+                * may still have interrupts connected to those harts.  This is
+                * not wrong... unless they actually load a driver that needs
+                * it!
+                */
+               irq_domain_add_linear(
+                       node,
+                       8*sizeof(uintptr_t),
+                       &riscv_irqdomain_ops_noop,
+                       node->parent);
+               return 0;
+       }
+
+       data = &per_cpu(riscv_irq_data, hart);
+       snprintf(data->name, sizeof(data->name), "riscv,cpu_intc,%d", hart);
+       data->hart = hart;
+       data->chip.name = data->name;
+       data->chip.irq_mask = riscv_irq_mask;
+       data->chip.irq_unmask = riscv_irq_unmask;
+       data->chip.irq_enable = riscv_irq_enable;
+       data->chip.irq_disable = riscv_irq_disable;
+       data->domain = irq_domain_add_linear(
+               node,
+               8*sizeof(uintptr_t),
+               &riscv_irqdomain_ops,
+               data);
+       WARN_ON(!data->domain);
+       printk(KERN_INFO "%s: %d local interrupts mapped\n",
+              data->name, 8*(int)sizeof(uintptr_t));
+       return 0;
+}
+
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init);
--

2.13.0

#138 lore raw

Re: [PATCH 12/17] tty: New RISC-V SBI Console Driver

In reply to Palmer Dabbelt

CC (hypervisor) console folks

Quoted 155 lines · Palmer Dabbelt

This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.

The SBI console is made availiable for early printk messages and is also availiable as a regular console.

---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
index 574da15fe618..f3774adab240 100644
@@ -114,4 +114,15 @@ config HVCS
          which will also be compiled when this driver is built as a
          module.
 
+config HVC_SBI
+       bool "SBI console support"
+       depends on RISCV
+       select HVC_DRIVER
+       default y
+       help
+         This enables support for console output via RISC-V SBI calls, which
+         is normally used only during boot to output printk.
+
+         If you don't know what do to here, say Y.
+
 endif # TTY
drivers/tty/hvc/Makefile +1 -0
index 6a2702be76d1..2d63bfe4a96b 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV)                += hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG)         += hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)    += hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS)             += hvcs.o
+obj-$(CONFIG_HVC_SBI)          += hvc_sbi.o
drivers/tty/hvc/hvc_sbi.c new file +102 -1
new file mode 100644
index 000000000000..e70293fb7b35
@@ -0,0 +1,102 @@
+/*
+ * RISC-V SBI interface to hvc_console.c
+ *  based on drivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/console.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+#include <linux/irq.h>
+
+#include <asm/sbi.h>
+
+#include "hvc_console.h"
+
+static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+{
+       int i;
+
+       for (i = 0; i < count; i++)
+               sbi_console_putchar(buf[i]);
+
+       return i;
+}
+
+static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+{
+       int i, c;
+
+       for (i = 0; i < count; i++) {
+               if ((c = sbi_console_getchar()) < 0)
+                       break;
+               buf[i] = c;
+       }
+
+       return i;
+}
+
+static const struct hv_ops hvc_sbi_ops = {
+       .get_chars = hvc_sbi_tty_get,
+       .put_chars = hvc_sbi_tty_put,
+};
+
+static int __init hvc_sbi_init(void)
+{
+       return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, &hvc_sbi_ops, 16));
+}
+device_initcall(hvc_sbi_init);
+
+static int __init hvc_sbi_console_init(void)
+{
+       hvc_instantiate(0, 0, &hvc_sbi_ops);
+       add_preferred_console("hvc", 0, NULL);
+
+       return 0;
+}
+console_initcall(hvc_sbi_console_init);
+
+#ifdef CONFIG_EARLY_PRINTK
+static void sbi_console_write(struct console *co, const char *buf,
+                             unsigned int n)
+{
+       int i;
+
+       for (i = 0; i < n; ++i) {
+               if (buf[i] == '\n')
+                       sbi_console_putchar('\r');
+               sbi_console_putchar(buf[i]);
+       }
+}
+
+static struct console early_console_dev __initdata = {
+       .name   = "early",
+       .write  = sbi_console_write,
+       .flags  = CON_PRINTBUFFER | CON_BOOT,
+       .index  = -1
+};
+
+static int __init setup_early_printk(char *str)
+{
+       if (early_console == NULL) {
+               early_console = &early_console_dev;
+               register_console(early_console);
+       }
+       return 0;
+}
+early_param("earlyprintk", setup_early_printk);
+#endif
--

2.13.0

#76 lore raw

Re: [PATCH 01/17] drivers: support PCIe in RISCV

In reply to Palmer Dabbelt

CC pci folks

Quoted 39 lines · Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.

---
 drivers/pci/Makefile     | 1 +
 drivers/pci/host/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/pci/Makefile +1 -0
index 462c1f5f5546..a29d9ec05d13 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o
 obj-$(CONFIG_TILE) += setup-irq.o
 obj-$(CONFIG_SPARC_LEON) += setup-irq.o
 obj-$(CONFIG_M68K) += setup-irq.o
+obj-$(CONFIG_RISCV) += setup-irq.o
 
 #
 # ACPI Related PCI FW Functions
drivers/pci/host/Kconfig +1 -2
index 7f47cd5e10a5..5148f3d3cab7 100644
@@ -71,7 +71,7 @@ config PCI_HOST_GENERIC
 
 config PCIE_XILINX
        bool "Xilinx AXI PCIe host bridge support"
-       depends on ARCH_ZYNQ || MICROBLAZE
+       depends on ARCH_ZYNQ || MICROBLAZE || RISCV
        help
          Say 'Y' here if you want kernel to support the Xilinx AXI PCIe
          Host Bridge driver.
--

2.13.0

#82 lore raw

Re: [PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt

In reply to Palmer Dabbelt

CC pci folks

Quoted 33 lines · Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

These are numbered from 1.

---
 drivers/pci/host/pcie-xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +2 -3
index 2fe2df51f9f8..8804145d399a 100644
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
                        val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
                                XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
                        generic_handle_irq(irq_find_mapping(port->leg_domain,
-                                                           val));
+                                                           val + 1));
                }
        }
 
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
                return -ENODEV;
        }
 
-       port->leg_domain = irq_domain_add_linear(pcie_intc_node, 4,
+       port->leg_domain = irq_domain_add_linear(pcie_intc_node, 5,
                                                 &intx_domain_ops,
                                                 port);
        if (!port->leg_domain) {
--

2.13.0

#95 lore raw

Re: [PATCH 04/17] Documentation: atomic_ops.txt is core-api/atomic_ops.rst

In reply to Palmer Dabbelt

CC doc folks

Quoted 32 lines · Palmer Dabbelt

I was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.

---
 Documentation/memory-barriers.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/memory-barriers.txt +5 -6
index 732f10ea382e..f1c9eaa45a57 100644
@@ -498,11 +498,11 @@ And a couple of implicit varieties:
      This means that ACQUIRE acts as a minimal "acquire" operation and
      RELEASE acts as a minimal "release" operation.
 
-A subset of the atomic operations described in atomic_ops.txt have ACQUIRE
-and RELEASE variants in addition to fully-ordered and relaxed (no barrier
-semantics) definitions.  For compound atomics performing both a load and a
-store, ACQUIRE semantics apply only to the load and RELEASE semantics apply
-only to the store portion of the operation.
+A subset of the atomic operations described in core-api/atomic_ops.rst have
+ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no
+barrier semantics) definitions.  For compound atomics performing both a load
+and a store, ACQUIRE semantics apply only to the load and RELEASE semantics
+apply only to the store portion of the operation.
 
 Memory barriers are only required where there's a possibility of interaction
 between two CPUs or between a CPU and a device.  If it can be guaranteed that
--

2.13.0

#100 lore raw

Re: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}

In reply to Palmer Dabbelt

CC pci folks

Quoted 76 lines · Palmer Dabbelt

While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.

---
 drivers/pci/Makefile |  2 +-
 drivers/pci/bios.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 drivers/pci/bios.c
drivers/pci/Makefile +1 -1
index a29d9ec05d13..fa7040915194 100644
@@ -4,7 +4,7 @@
 
 obj-y          += access.o bus.o probe.o host-bridge.o remove.o pci.o \
                        pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \
-                       irq.o vpd.o setup-bus.o vc.o mmap.o
+                       irq.o vpd.o setup-bus.o vc.o mmap.o bios.o
 obj-$(CONFIG_PROC_FS) += proc.o
 obj-$(CONFIG_SYSFS) += slot.o
 
drivers/pci/bios.c new file +42 -1
new file mode 100644
index 000000000000..ffe34c024aa8
@@ -0,0 +1,42 @@
+/*
+ * Code borrowed from arch/arm64/kernel/pci.c
+ *   which borrowed from powerpc/kernel/pci-common.c
+ *   which borrowed from arch/alpha/kernel/pci.c
+ *
+ * Extruded from code written by
+ *      Dave Rusling ([email protected])
+ *      David Mosberger ([email protected])
+ * Copyright (C) 1999 Andrea Arcangeli <[email protected]>
+ * Copyright (C) 2000 Ivan Kokshaysky <[email protected]>
+ * Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM
+ * Copyright (C) 2014 ARM Ltd.
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+/* This file contains weakly bound functions that implement pcibios functions
+ * that some architectures have copied verbatim.
+ */
+
+#include <linux/pci.h>
+
+/*
+ * Called after each bus is probed, but before its children are examined
+ */
+__attribute__ ((weak))
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+       /* nothing to do, expected to be removed in the future */
+}
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here
+ */
+__attribute__ ((weak))
+resource_size_t pcibios_align_resource(void *data, const struct resource *res,
+                                      resource_size_t size, resource_size_t align)
+{
+       return res->start;
+}
--

2.13.0

maintainer
#122 lore raw

Re: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource

In reply to Geert Uytterhoeven
Quoted 22 lines · Geert Uytterhoeven

CC clocksource folks

Quoted 19 lines · Palmer Dabbelt

The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.

---
 drivers/clocksource/Kconfig       |   8 +++
 drivers/clocksource/Makefile      |   1 +
 drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/clocksource/timer-riscv.c
drivers/clocksource/Kconfig +0 -0
index 545d541ae20e..1c2c6e7c7fab 100644
@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC
          Enable this option to use the Low Power controller timer
          as clocksource.
 
Quoted 4 lines

drivers/clocksource/Kconfig config CLKSRC_ST_LPC · line 618

Quoted 4 lines
drivers/clocksource/Kconfig +4 -0
+config CLKSRC_RISCV
+       #bool "Clocksource for the RISC-V platform"
+       def_bool y if RISCV
+       depends on RISCV

I don't like the commenting out parts of the entry. If there are no build-time dependencies, you can just make it 'default y' and still allow users to disabled the driver if they really want to (e.g. on a machine specific kernel that has a driver for another clocksource), or you just leave it 'def_bool RISCV'.

Quoted 4 lines
Quoted 4 lines
drivers/clocksource/Kconfig +4 -0
+
+static int riscv_timer_set_oneshot(struct clock_event_device *evt)
+{
+       /* no-op; only one mode */
Quoted 8 lines

drivers/clocksource/Kconfig config CLKSRC_ST_LPC

Quoted 8 lines
drivers/clocksource/Kconfig +8 -0
+       return 0;
+}
+
+static int riscv_timer_set_shutdown(struct clock_event_device *evt)
+{
+       /* can't stop the clock! */
+       return 0;
+}

I'd just leave out the empty callbacks, the callers all protect NULL pointers.

Quoted 8 lines
Quoted 8 lines
drivers/clocksource/Kconfig +8 -0
+static u64 riscv_rdtime(struct clocksource *cs)
+{
+       return get_cycles();
+}
+
+static struct clocksource riscv_clocksource = {
+       .name = "riscv_clocksource",
+       .rating = 300,
Quoted 8 lines

drivers/clocksource/Kconfig

Quoted 8 lines
drivers/clocksource/Kconfig +8 -0
+       .read = riscv_rdtime,
+#ifdef CONFIG_64BITS
+       .mask = CLOCKSOURCE_MASK(64),
+#else
+       .mask = CLOCKSOURCE_MASK(32),
+#endif /* CONFIG_64BITS */
+       .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+};

".mask = BITS_PER_LONG" maybe?

Quoted 31 lines
Quoted 31 lines
drivers/clocksource/Kconfig +31 -0
+void riscv_timer_interrupt(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *evdev = &per_cpu(clock_event, cpu);
+
+       evdev->event_handler(evdev);
+}
+
+void __init init_clockevent(void)
+{
+       int cpu = smp_processor_id();
+       struct clock_event_device *ce = &per_cpu(clock_event, cpu);
+
+       *ce = (struct clock_event_device){
+               .name = "riscv_timer_clockevent",
+               .features = CLOCK_EVT_FEAT_ONESHOT,
+               .rating = 300,
+               .cpumask = cpumask_of(cpu),
+               .set_next_event = riscv_timer_set_next_event,
+               .set_state_oneshot  = riscv_timer_set_oneshot,
+               .set_state_shutdown = riscv_timer_set_shutdown,
+       };
+
+       /* Enable timer interrupts */
+       csr_set(sie, SIE_STIE);
+
+       clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff);
+}
+
+static unsigned long __init of_timebase(void)
+{
Quoted 8 lines

drivers/clocksource/Kconfig

Quoted 8 lines
drivers/clocksource/Kconfig +8 -0
+       struct device_node *cpu;
+       const __be32 *prop;
+
+       cpu = of_find_node_by_path("/cpus");
+       if (cpu) {
+               prop = of_get_property(cpu, "timebase-frequency", NULL);
+               if (prop)
+                       return be32_to_cpu(*prop);

of_property_read_u32()

Quoted 3 lines

drivers/clocksource/Kconfig

Quoted 3 lines
drivers/clocksource/Kconfig +3 -0
+       }
+
+       return 10000000;

The default seems rather arbitrary. Any reason for this particular number? Maybe it's better to fail if the property is missing.

Arnd

maintainer
#46 lore raw

Re: [PATCH 5/7] RISC-V: arch/riscv/lib

In reply to Palmer Dabbelt
Quoted 52 lines · Palmer Dabbelt
Quoted 34 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann

On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:

Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).

Quoted 6 lines

Makes sense. I think this should do it

https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776

but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark

Quoted 7 lines

+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }

You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.

Quoted 8 lines

The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is

Quoted 1 line

=2ms, so the division won't cost much in comparison.

The normal case should have no division in it.

I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.

Quoted 7 lines

I think the intention originally was to avoid overflowing the 32-bit argument in

void __delay(unsigned long cycles)

If you need to delay for more than 4 billion clocksource cycles, your code is still broken.

Maybe I'm crazy, but I thought the goal was to avoid overflowing on the multiply. Specifically, the code looks like

  udelay(long input) {
    long a = input * MUL_VAL;
    long b = a >> SHIFT_VAL;
    __delay(b);
  }
Quoted 4 lines

so the place there's extra overflow is at computing a, not b (the input to __delay). When I modified the ARM code I went and recalculated the point at which the multiply would overflow and it matched the value from the ARM code, which is 2000us.

Ah, that's right. But then you might run into the next overflow at a larger delay interval.

Quoted 3 lines

While I can buy the argument that 2000us is still too long, the real reason I wrote the code this way is because I thought it was easier than having an error case. If you think the error is better then I'll do it that way.

It's probably ok as long as the complexity is not in the inline wrapper, and you avoid the division for small delays.

Arnd

maintainer
#128 lore raw

Re: [PATCH 10/17] irqchip: New RISC-V PLIC Driver

In reply to Geert Uytterhoeven
Quoted 3 lines · Geert Uytterhoeven

drivers/irqchip/irq-riscv-plic.c line 54

Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3 -0
+struct plic_enable_context {
+       atomic_t mask[32]; // 32-bit * 32-entry
+};

You use many '//' style comments in this file, please change them all to '/* */' for consistency with kernel coding style.

Quoted 17 lines
Quoted 17 lines
drivers/irqchip/irq-riscv-plic.c new file +17 -0
+
+struct plic_priority {
+       u32 prio[MAX_DEVICES];
+};
+
+struct plic_data {
+       struct irq_chip         chip;
+       struct irq_domain       *domain;
+       u32                     ndev;
+       void __iomem            *reg;
+       int                     handlers;
+       struct plic_handler     *handler;
+       char                    name[30];
+};
+
+struct plic_handler {
+       struct plic_hart_context        *context;
Quoted 8 lines

drivers/irqchip/irq-riscv-plic.c line 79

Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c new file +8 -0
+       struct plic_data                *data;
+};
+
+static inline
+struct plic_hart_context *plic_hart_context(struct plic_data *data, size_t i)
+{
+       return (struct plic_hart_context *)((char *)data->reg + HART_BASE + HART_SIZE*i);
+}

'data->reg' is an __iomem pointer, so when you build-test this with 'make C=1', you should get a valid warning from sparse about an address space mismatch. Please address all the warning from sparse.

Quoted 6 lines

drivers/irqchip/irq-riscv-plic.c line 98

Quoted 6 lines
drivers/irqchip/irq-riscv-plic.c new file +6 -0
+static void plic_disable(struct plic_data *data, int i, int hwirq)
+{
+       struct plic_enable_context *enable = plic_enable_context(data, i);
+
+       atomic_and(~(1 << (hwirq % 32)), &enable->mask[hwirq / 32]);
+}

In particular, you must not do atomic operations on MMIO pointers. On most architectures these are explicitly disallowed and trap for a good reason, as the hardware implementation behind atomics tend to rely on the cache controller, while mmio registers are required to be uncached.

Quoted 1 line
Quoted 1 line

+ iowrite32(1, &priority->prio[d->hwirq]);

I would normally use 'readl' instead of 'iowrite32'. They may be the same on riscv, but they have slightly different meaning in portable drivers.

Arnd

maintainer
#139 lore raw

Re: [PATCH 12/17] tty: New RISC-V SBI Console Driver

In reply to Geert Uytterhoeven
Quoted 27 lines · Geert Uytterhoeven

CC (hypervisor) console folks

Quoted 24 lines · Palmer Dabbelt

This patch adds a new driver for the console availiable via the RISC-V SBI. This console is specified to be used for early boot messages, and is designed to be a very simple (albiet somewhat slow) console that is always availiable. All RISC-V systems have an SBI console.

The SBI console is made availiable for early printk messages and is also availiable as a regular console.

---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +0 -0
index 574da15fe618..f3774adab240 100644
@@ -114,4 +114,15 @@ config HVCS
          which will also be compiled when this driver is built as a
          module.
 
Quoted 12 lines

drivers/tty/hvc/Kconfig config HVCS · line 128

Quoted 12 lines
drivers/tty/hvc/Kconfig +11 -0
+config HVC_SBI
+       bool "SBI console support"
+       depends on RISCV
+       select HVC_DRIVER
+       default y
+       help
+         This enables support for console output via RISC-V SBI calls, which
+         is normally used only during boot to output printk.
+
+         If you don't know what do to here, say Y.
+
 endif # TTY

Please move this a little higher along with the other HVC_DRIVER implementations.

Quoted 5 lines
Quoted 5 lines

+ * RISC-V SBI interface to hvc_console.c
+ * based on drivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California

2017?

Arnd

maintainer
#101 lore raw

Re: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}

In reply to Geert Uytterhoeven
Quoted 10 lines · Geert Uytterhoeven

CC pci folks

Quoted 7 lines · Palmer Dabbelt

While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.

Thanks a lot for taking care of this!

Quoted 10 lines

drivers/pci/bios.c line 4

Quoted 10 lines
drivers/pci/bios.c new file +4 -0
new file mode 100644
index 000000000000..ffe34c024aa8
@@ -0,0 +1,42 @@
+
+/* This file contains weakly bound functions that implement pcibios functions
+ * that some architectures have copied verbatim.
+ */

Instead of adding a new file, I would suggest adding the two functions next to their callers, in probe.c and setup-res.c, respectively.

Arnd

maintainer
#143 lore raw

Re: [PATCH 13/17] RISC-V: Add include subdirectory

In reply to Palmer Dabbelt
Quoted 5 lines · Palmer Dabbelt

This patch adds the include files for the RISC-V port. These are mostly based on the score port, but there are a lot of arm64-based files as well.

It might be better to split this up into several parts, as the patch is longer than
most people are willing to review at once.

The uapi should definitely be a separate patch, as it includes the parts that cannot be changed any more later. memory management (pgtable, mmu, uaccess) would be another part to split out, and possibly all the atomics in one separate patch (along with spinlocks and bitops).

Quoted 37 lines
arch/riscv/include/asm/io.h new file +37 -0
+
+/* IO barriers.  These only fence on the IO bits because they're only required
+ * to order device access.  We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering.  From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb()      __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb()      __asm__ __volatile__ ("fence io,o" : : : "memory");
+
+#define mmiowb()       __asm__ __volatile__ ("fence io,io" : : : "memory");
+
+/*
+ * Relaxed I/O memory access primitives. These follow the Device memory
+ * ordering rules but do not guarantee any ordering relative to Normal memory
+ * accesses.
+ */
+#define readb_relaxed(c)       ({ u8  __r = __raw_readb(c); __r; })
+#define readw_relaxed(c)       ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })
+#define readl_relaxed(c)       ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })
+#define readq_relaxed(c)       ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; })
+
+#define writeb_relaxed(v,c)    ((void)__raw_writeb((v),(c)))
+#define writew_relaxed(v,c)    ((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
+#define writel_relaxed(v,c)    ((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
+#define writeq_relaxed(v,c)    ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
+
+/*
+ * I/O memory access primitives. Reads are ordered relative to any
+ * following Normal memory access. Writes are ordered relative to any prior
+ * Normal memory access.
+ */
+#define readb(c)               ({ u8  __v = readb_relaxed(c); __iormb(); __v; })

arch/riscv/include/asm/io.h line 148

Quoted 10 lines
arch/riscv/include/asm/io.h new file +10 -0
+#define readw(c)               ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
+#define readl(c)               ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
+#define readq(c)               ({ u64 __v = readq_relaxed(c); __iormb(); __v; })
+
+#define writeb(v,c)            ({ __iowmb(); writeb_relaxed((v),(c)); })
+#define writew(v,c)            ({ __iowmb(); writew_relaxed((v),(c)); })
+#define writel(v,c)            ({ __iowmb(); writel_relaxed((v),(c)); })
+#define writeq(v,c)            ({ __iowmb(); writeq_relaxed((v),(c)); })
+
+#include <asm-generic/io.h>

These do not yet contain all the changes we discussed: the relaxed operations don't seem to be ordered against one another and the regular accessors are not ordered against DMA.

Arnd

Acked-by on v1 4/17
#96 lore raw

Re: [PATCH 04/17] Documentation: atomic_ops.txt is core-api/atomic_ops.rst

In reply to Palmer Dabbelt
Quoted 8 lines · Palmer Dabbelt

I was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.

---
 Documentation/memory-barriers.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Will

Quoted 24 lines
Documentation/memory-barriers.txt +5 -5
index 732f10ea382e..f1c9eaa45a57 100644
@@ -498,11 +498,11 @@ And a couple of implicit varieties:
      This means that ACQUIRE acts as a minimal "acquire" operation and
      RELEASE acts as a minimal "release" operation.
 
-A subset of the atomic operations described in atomic_ops.txt have ACQUIRE
-and RELEASE variants in addition to fully-ordered and relaxed (no barrier
-semantics) definitions.  For compound atomics performing both a load and a
-store, ACQUIRE semantics apply only to the load and RELEASE semantics apply
-only to the store portion of the operation.
+A subset of the atomic operations described in core-api/atomic_ops.rst have
+ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no
+barrier semantics) definitions.  For compound atomics performing both a load
+and a store, ACQUIRE semantics apply only to the load and RELEASE semantics
+apply only to the store portion of the operation.
 
 Memory barriers are only required where there's a possibility of interaction
 between two CPUs or between a CPU and a device.  If it can be guaranteed that
Signature · 1 line
2.13.0
#172 lore raw

Re: RISC-V Linux Port v2

In reply to Palmer Dabbelt

Hi Palmer,

Quoted 4 lines · Palmer Dabbelt

Thanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.

[...]

Quoted 1 line

[PATCH 13/17] RISC-V: Add include subdirectory

This guy is too big, and got silently dropped by the mailing list. Any chance you could split it up please, so that it can be reviewed?

Thanks,

Will

#83 lore raw

Re: [PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt

In reply to Palmer Dabbelt

+ Bjorn

Quoted 24 lines · Palmer Dabbelt

From: "Wesley W. Terpstra" <[email protected]>

These are numbered from 1.

---
 drivers/pci/host/pcie-xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +1 -1
index 2fe2df51f9f8..8804145d399a 100644
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
 			val = ((val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
 				XILINX_PCIE_RPIFR1_INTR_SHIFT) + 1;
 			generic_handle_irq(irq_find_mapping(port->leg_domain,
-							    val));
+							    val + 1));
 		}
 	}
 

drivers/pci/host/pcie-xilinx.c static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) · line 530

Quoted 8 lines
drivers/pci/host/pcie-xilinx.c +1 -1
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 		return -ENODEV;
 	}
 
-	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 4,
+	port->leg_domain = irq_domain_add_linear(pcie_intc_node, 5,
 						 &intx_domain_ops,
 						 port);
 	if (!port->leg_domain) {

This is a common problem with the current OF code that numbers INTx from 1 instead of zero (there is no 5th legacy interrupts in the PCI spec, despite what $SUBJECT says). I'd be inclined to fix this at the core level rather than papering over it in the various drivers...

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...