Skip to contentSkip to conversation

RISC-V Linux Port v6

PATCH In review Palmer Dabbelt 10 participants 42 messages Jul 12, 2017 – Jul 26, 2017

Subsystems (22)
Kbuild PCI Library code RISC-V +18 more subsystems
lore
Share & tools
lore

Palmer Dabbelt

author maintainer
#0 lore raw

While it's only been a day since the last patch set (which might be a bit fast), I've generally been spinning new patch sets whenever I get through my inbox. For my other patch sets I've managed to get buried in a week's worth of email in a few hours, but for this one it appears there's been significantly less feedback so I've managed to get through everything. I'm hoping that's a good sign: either I've started to figure out what I'm doing or the code has gotten better -- hopefully it doesn't mean everyone else has given up :).

As it's been only a day, the changes are pretty minimal:

* The patch set is now based on linux-next/master, which I believe is a better base now that we're getting closer to upstream.
* EARLY_PRINTK is no longer an option. Since the SBI console is reasonable, there's no penalty to enabling it (and thus no benefit to disabling it).
* The mmap syscalls were refactored a bit.

At this point I'm not really sure how to proceed: reviews have calmed down quite a bit over the last two weeks, but I'm not familiar with the Linux development process enough to know how to get closer to upstream. Is this ready for inclusion into another tree? If so, is linux-next the right tree to work off of?

Of course, if anyone has outstanding code reviews then feel free to submit them either to this patch set or a previous one (v5 is essentially the same, and v4 is mostly some small SMP fixes). I don't want to rush anyone by re-submitting so quickly, it's just that my usual protocol has been sped up.

As usual, the patch set has been posted to our Git Hub page

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

Thanks to everyone for all your help!

[PATCH 01/17] lib: Add shared copies of some GCC library routines [PATCH 02/17] pci: Add a generic, weakly-linked
[PATCH 03/17] pci: Add a generic, weakly-linked pcibios_fixup_bus [PATCH 04/17] MAINTAINERS: Add RISC-V
[PATCH 05/17] clocksource: New RISC-V SBI timer driver [PATCH 06/17] irqchip: RISC-V Local Interrupt Controller Driver [PATCH 07/17] irqchip: New RISC-V PLIC Driver
[PATCH 08/17] tty: New RISC-V SBI console driver
[PATCH 09/17] RISC-V: Init and Halt Code
[PATCH 10/17] RISC-V: Atomic and Locking Code
[PATCH 11/17] RISC-V: Generic library routines and assembly [PATCH 12/17] RISC-V: ELF and module implementation [PATCH 13/17] RISC-V: Task implementation
[PATCH 14/17] RISC-V: Device, timer, IRQs, and the SBI [PATCH 15/17] RISC-V: Paging and MMU
[PATCH 16/17] RISC-V: User-facing API
[PATCH 17/17] RISC-V: Build Infastructure

author maintainer
#1 lore raw

PATCH 1/17 lib: Add shared copies of some GCC library routines

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_GENERIC_$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 6762529ad9e4..ee7d8bf0b7e1 100644
@@ -576,3 +576,21 @@ config PRIME_NUMBERS
 	tristate
 
 endmenu
+
+config GENERIC_ASHLDI3
+	bool
+
+config GENERIC_ASHRDI3
+	bool
+
+config GENERIC_LSHRDI3
+	bool
+
+config GENERIC_MULDI3
+	bool
+
+config GENERIC_CMPDI2
+	bool
+
+config GENERIC_UCMPDI2
+	bool
lib/Makefile +8 -0
index 678c6c38a991..dc4e7fd7bb87 100644
@@ -242,3 +242,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
#2 lore raw

PATCH 2/17 pci: Add a generic, weakly-linked pcibios_align_resource

In reply to Palmer Dabbelt

Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pcibios_align_resource and deletes the now obselete ones in a handful of ports.

The only functional change should be that a handful of ports used to export pcibios_fixup_bus. Only some architectures export this, so I just dropped it.

---
 arch/arc/kernel/pcibios.c        | 13 -------------
 arch/arm64/kernel/pci.c          | 17 -----------------
 arch/ia64/pci/pci.c              |  7 -------
 arch/microblaze/pci/pci-common.c |  7 -------
 arch/sparc/kernel/leon_pci.c     |  6 ------
 arch/sparc/kernel/pci.c          | 10 ----------
 arch/sparc/kernel/pcic.c         |  6 ------
 arch/tile/kernel/pci.c           | 10 ----------
 arch/tile/kernel/pci_gx.c        |  9 ---------
 drivers/pci/setup-res.c          | 12 ++++++++++++
 10 files changed, 12 insertions(+), 85 deletions(-)
arch/arc/kernel/pcibios.c +0 -13
index 72e1d73d0bd6..05aba5a7b5d2 100644
@@ -7,16 +7,3 @@
  */
 
 #include <linux/pci.h>
-
-/*
- * 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;
-}
-
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
arch/arm64/kernel/pci.c +0 -17
index e2b7e4f9cc31..0e2ea1c78542 100644
@@ -22,23 +22,6 @@
 #include <linux/pci-ecam.h>
 #include <linux/slab.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;
-}
-
 #ifdef CONFIG_ACPI
 /*
  * Try to assign the IRQ number when probing a new device
arch/ia64/pci/pci.c +0 -7
index 4068bde623dc..f5ec736100ee 100644
@@ -411,13 +411,6 @@ pcibios_disable_device (struct pci_dev *dev)
 		acpi_pci_irq_disable(dev);
 }
 
-resource_size_t
-pcibios_align_resource (void *data, const struct resource *res,
-		        resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 /**
  * ia64_pci_get_legacy_mem - generic legacy mem routine
  * @bus: bus to get legacy memory base address for
arch/microblaze/pci/pci-common.c +0 -7
index 404fb38d06b7..7a332e9f1de0 100644
@@ -829,13 +829,6 @@ EXPORT_SYMBOL(pcibios_fixup_bus);
  * but we want to try to avoid allocating at 0x2900-0x2bff
  * which might have be mirrored at 0x0100-0x03ff..
  */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 int pcibios_add_device(struct pci_dev *dev)
 {
 	dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
arch/sparc/kernel/leon_pci.c +0 -6
index 4371f72ff025..0eafdf3d036d 100644
@@ -94,9 +94,3 @@ void pcibios_fixup_bus(struct pci_bus *pbus)
 		}
 	}
 }
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
arch/sparc/kernel/pci.c +0 -10
index 7eceaa10836f..3f8670c92951 100644
@@ -690,16 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
 	return bus;
 }
 
-void pcibios_fixup_bus(struct pci_bus *pbus)
-{
-}
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
arch/sparc/kernel/pcic.c +0 -6
index a38787b84322..e038e343f2c1 100644
@@ -746,12 +746,6 @@ static void watchdog_reset() {
 }
 #endif
 
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *pdev, int mask)
 {
 	return 0;
arch/tile/kernel/pci.c +0 -10
index bc6656b5708b..284ed23b3914 100644
@@ -67,16 +67,6 @@ static struct pci_ops tile_cfg_ops;
 
 
 /*
- * We don't need to worry about the alignment of resources.
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-			    resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
-/*
  * Open a FD to the hypervisor PCI device.
  *
  * controller_id is the controller number, config type is 0 or 1 for
arch/tile/kernel/pci_gx.c +0 -9
index b554a68eea1b..bdc623b91f7a 100644
@@ -108,15 +108,6 @@ static struct pci_ops tile_cfg_ops;
 /* Mask of CPUs that should receive PCIe interrupts. */
 static struct cpumask intr_cpus_map;
 
-/* We don't need to worry about the alignment of resources. */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				       resource_size_t size,
-				       resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 /*
  * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #.
  * For now, we simply send interrupts to non-dataplane CPUs.
drivers/pci/setup-res.c +12 -0
index 85774b7a316a..597ed1f8b15c 100644
@@ -234,6 +234,18 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,
 	return 0;
 }
 
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here.
+ * This is marked as __weak because multiple architectures define it, it should
+ * eventually go away.
+ */
+__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;
+}
+
 static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
 		int resno, resource_size_t size, resource_size_t align)
 {
Signature · 1 line
2.13.0
author maintainer
#7 lore raw

PATCH 3/17 pci: Add a generic, weakly-linked pcibios_fixup_bus

In reply to Palmer Dabbelt

Multiple architectures define this as an empty function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pci_fixup_bios and deletes the now obselete ones in a handful of ports.

The only functional change should be that microblaze used to export pcibios_fixup_bus. None of the other architectures export this, so I just dropped it.

---
 arch/cris/arch-v32/drivers/pci/bios.c |  4 ----
 arch/microblaze/pci/pci-common.c      |  6 ------
 arch/s390/pci/pci.c                   |  4 ----
 arch/sh/drivers/pci/pci.c             |  8 --------
 arch/tile/kernel/pci.c                |  8 --------
 arch/tile/kernel/pci_gx.c             |  5 -----
 drivers/pci/probe.c                   | 10 ++++++++++
 7 files changed, 10 insertions(+), 35 deletions(-)
arch/cris/arch-v32/drivers/pci/bios.c +0 -4
index 394c2a73d5e2..5cc622c0225e 100644
@@ -2,10 +2,6 @@
 #include <linux/kernel.h>
 #include <hwregs/intr_vect.h>
 
-void pcibios_fixup_bus(struct pci_bus *b)
-{
-}
-
 void pcibios_set_master(struct pci_dev *dev)
 {
 	u8 lat;
arch/microblaze/pci/pci-common.c +0 -6
index 7a332e9f1de0..5835c09c6e26 100644
@@ -810,12 +810,6 @@ void pcibios_setup_bus_devices(struct pci_bus *bus)
 	}
 }
 
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-	/* nothing to do */
-}
-EXPORT_SYMBOL(pcibios_fixup_bus);
-
 /*
  * We need to avoid collisions with `mirrored' VGA ports
  * and other strange ISA hardware, so we always want the
arch/s390/pci/pci.c +0 -4
index 7b30af5da222..ddb9923fb45d 100644
@@ -262,10 +262,6 @@ static int zpci_cfg_store(struct zpci_dev *zdev, int offset, u32 val, u8 len)
 	return rc;
 }
 
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
 resource_size_t pcibios_align_resource(void *data, const struct resource *res,
 				       resource_size_t size,
 				       resource_size_t align)
arch/sh/drivers/pci/pci.c +0 -8
index c99ee286b69f..749642e1272e 100644
@@ -155,14 +155,6 @@ static int __init pcibios_init(void)
 subsys_initcall(pcibios_init);
 
 /*
- *  Called after each bus is probed, but before its children
- *  are examined.
- */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
-/*
  * We need to avoid collisions with `mirrored' VGA ports
  * and other strange ISA hardware, so we always want the
  * addresses to be allocated in the 0x000-0x0ff region
arch/tile/kernel/pci.c +0 -8
index 284ed23b3914..8999a20ed9d1 100644
@@ -359,14 +359,6 @@ int __init pcibios_init(void)
 }
 subsys_initcall(pcibios_init);
 
-/*
- * No bus fixups needed.
- */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-	/* Nothing needs to be done. */
-}
-
 void pcibios_set_master(struct pci_dev *dev)
 {
 	/* No special bus mastering setup handling. */
arch/tile/kernel/pci_gx.c +0 -5
index bdc623b91f7a..0a7642184a9a 100644
@@ -1029,11 +1029,6 @@ int __init pcibios_init(void)
 }
 subsys_initcall(pcibios_init);
 
-/* No bus fixups needed. */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
 /* Process any "pci=" kernel boot arguments. */
 char *__init pcibios_setup(char *str)
 {
drivers/pci/probe.c +10 -0
index c31310db0404..2ef1248bf112 100644
@@ -2288,6 +2288,16 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
 }
 EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);
 
+/*
+ * Called after each bus is probed, but before its children are examined.  This
+ * is marked as __weak because multiple architectures define it
+ */
+__attribute__ ((weak))
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+       /* nothing to do, expected to be removed in the future */
+}
+
 unsigned int pci_scan_child_bus(struct pci_bus *bus)
 {
 	unsigned int devfn, pass, max = bus->busn_res.start;
Signature · 1 line
2.13.0
author maintainer
#17 lore raw

PATCH 10/17 RISC-V: Atomic and Locking Code

In reply to Palmer Dabbelt

This contains all the code that directly interfaces with the RISC-V memory model. While this code corforms to the current RISC-V ISA specifications (user 2.2 and priv 1.10), the memory model is somewhat underspecified in those documents. There is a working group that hopes to produce a formal memory model by the end of the year, but my understanding is that the basic definitions we're relying on here won't change significantly.

---
 arch/riscv/include/asm/atomic.h         | 328 ++++++++++++++++++++++++++++++++
 arch/riscv/include/asm/barrier.h        |  68 +++++++
 arch/riscv/include/asm/bitops.h         | 216 +++++++++++++++++++++
 arch/riscv/include/asm/cacheflush.h     |  39 ++++
 arch/riscv/include/asm/cmpxchg.h        | 134 +++++++++++++
 arch/riscv/include/asm/io.h             | 180 ++++++++++++++++++
 arch/riscv/include/asm/spinlock.h       | 165 ++++++++++++++++
 arch/riscv/include/asm/spinlock_types.h |  33 ++++
 arch/riscv/include/asm/tlb.h            |  24 +++
 arch/riscv/include/asm/tlbflush.h       |  64 +++++++
 10 files changed, 1251 insertions(+)
 create mode 100644 arch/riscv/include/asm/atomic.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/cacheflush.h
 create mode 100644 arch/riscv/include/asm/cmpxchg.h
 create mode 100644 arch/riscv/include/asm/io.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/tlb.h
 create mode 100644 arch/riscv/include/asm/tlbflush.h
arch/riscv/include/asm/atomic.h new file +328 -0
new file mode 100644
index 000000000000..ee3ab06e492b
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * 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 Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_RISCV_ATOMIC_H
+#define _ASM_RISCV_ATOMIC_H
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+# include <asm-generic/atomic64.h>
+#else
+# if (__riscv_xlen < 64)
+#  error "64-bit atomics require XLEN to be at least 64"
+# endif
+#endif
+
+#include <asm/cmpxchg.h>
+#include <asm/barrier.h>
+
+#define ATOMIC_INIT(i)	{ (i) }
+static __always_inline int atomic_read(const atomic_t *v)
+{
+	return READ_ONCE(v->counter);
+}
+static __always_inline void atomic_set(atomic_t *v, int i)
+{
+	WRITE_ONCE(v->counter, i);
+}
+
+#ifndef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC64_INIT(i) { (i) }
+static __always_inline int atomic64_read(const atomic64_t *v)
+{
+	return READ_ONCE(v->counter);
+}
+static __always_inline void atomic64_set(atomic64_t *v, int i)
+{
+	WRITE_ONCE(v->counter, i);
+}
+#endif
+
+/*
+ * First, the atomic ops that have no ordering constraints and therefor don't
+ * have the AQ or RL bits set.  These don't return anything, so there's only
+ * one version to worry about.
+ */
+#define ATOMIC_OP(op, asm_op, c_op, I, asm_type, c_type, prefix)				\
+static __always_inline void atomic##prefix##_##op(c_type i, atomic##prefix##_t *v)		\
+{												\
+	__asm__ __volatile__ (									\
+		"amo" #asm_op "." #asm_type " zero, %1, %0"					\
+		: "+A" (v->counter)								\
+		: "r" (I)									\
+		: "memory");									\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, asm_op, c_op, I)			\
+        ATOMIC_OP (op, asm_op, c_op, I, w,  int,   )
+#else
+#define ATOMIC_OPS(op, asm_op, c_op, I)			\
+        ATOMIC_OP (op, asm_op, c_op, I, w,  int,   )	\
+        ATOMIC_OP (op, asm_op, c_op, I, d, long, 64)
+#endif
+
+ATOMIC_OPS(add, add, +,  i)
+ATOMIC_OPS(sub, add, +, -i)
+ATOMIC_OPS(and, and, &,  i)
+ATOMIC_OPS( or,  or, |,  i)
+ATOMIC_OPS(xor, xor, ^,  i)
+
+#undef ATOMIC_OP
+#undef ATOMIC_OPS
+
+/*
+ * Atomic ops that have ordered, relaxed, acquire, and relese variants.
+ * There's two flavors of these: the arithmatic ops have both fetch and return
+ * versions, while the logical ops only have fetch versions.
+ */
+#define ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, asm_type, c_type, prefix)			\
+static __always_inline c_type atomic##prefix##_fetch_##op##c_or(c_type i, atomic##prefix##_t *v)	\
+{													\
+	register c_type ret;										\
+	__asm__ __volatile__ (										\
+		"amo" #asm_op "." #asm_type #asm_or " %1, %2, %0"					\
+		: "+A" (v->counter), "=r" (ret)								\
+		: "r" (I)										\
+		: "memory");										\
+	return ret;											\
+}
+
+#define ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, asm_type, c_type, prefix)			\
+static __always_inline c_type atomic##prefix##_##op##_return##c_or(int i, atomic##prefix##_t *v)	\
+{													\
+        return atomic##prefix##_fetch_##op##c_or(i, v) c_op I;						\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or)				\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, w,  int,   )	\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, w,  int,   )
+#else
+#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or)				\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, w,  int,   )	\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, w,  int,   )	\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I, asm_or, c_or, d, long, 64)	\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I, asm_or, c_or, d, long, 64)
+#endif
+
+ATOMIC_OPS(add, add, +,  i,      , _relaxed)
+ATOMIC_OPS(add, add, +,  i, .aq  , _acquire)
+ATOMIC_OPS(add, add, +,  i, .rl  , _release)
+ATOMIC_OPS(add, add, +,  i, .aqrl,         )
+
+ATOMIC_OPS(sub, add, +, -i,      , _relaxed)
+ATOMIC_OPS(sub, add, +, -i, .aq  , _acquire)
+ATOMIC_OPS(sub, add, +, -i, .rl  , _release)
+ATOMIC_OPS(sub, add, +, -i, .aqrl,         )
+
+#undef ATOMIC_OPS
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or)				\
+        ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, w,  int,   )
+#else
+#define ATOMIC_OPS(op, asm_op, c_op, I, asm_or, c_or)				\
+        ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, w,  int,   )		\
+        ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, d, long, 64)
+#endif
+
+ATOMIC_OPS(and, and, &,  i,      , _relaxed)
+ATOMIC_OPS(and, and, &,  i, .aq  , _acquire)
+ATOMIC_OPS(and, and, &,  i, .rl  , _release)
+ATOMIC_OPS(and, and, &,  i, .aqrl,         )
+
+ATOMIC_OPS( or,  or, |,  i,      , _relaxed)
+ATOMIC_OPS( or,  or, |,  i, .aq  , _acquire)
+ATOMIC_OPS( or,  or, |,  i, .rl  , _release)
+ATOMIC_OPS( or,  or, |,  i, .aqrl,         )
+
+ATOMIC_OPS(xor, xor, ^,  i,      , _relaxed)
+ATOMIC_OPS(xor, xor, ^,  i, .aq  , _acquire)
+ATOMIC_OPS(xor, xor, ^,  i, .rl  , _release)
+ATOMIC_OPS(xor, xor, ^,  i, .aqrl,         )
+
+#undef ATOMIC_OPS
+
+#undef ATOMIC_FETCH_OP
+#undef ATOMIC_OP_RETURN
+
+/*
+ * The extra atomic operations that are constructed from one of the core
+ * AMO-based operations above (aside from sub, which is easier to fit above).
+ * These are required to perform a barrier, but they're OK this way because
+ * atomic_*_return is also required to perform a barrier.
+ */
+#define ATOMIC_OP(op, func_op, comp_op, I, c_type, prefix)			\
+static __always_inline bool atomic##prefix##_##op(c_type i, atomic##prefix##_t *v) \
+{										\
+	return atomic##prefix##_##func_op##_return(i, v) comp_op I;		\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, func_op, comp_op, I)			\
+        ATOMIC_OP (op, func_op, comp_op, I,  int,   )
+#else
+#define ATOMIC_OPS(op, func_op, comp_op, I)			\
+        ATOMIC_OP (op, func_op, comp_op, I,  int,   )		\
+        ATOMIC_OP (op, func_op, comp_op, I, long, 64)
+#endif
+
+ATOMIC_OPS(add_and_test, add, ==, 0)
+ATOMIC_OPS(sub_and_test, sub, ==, 0)
+ATOMIC_OPS(add_negative, add,  <, 0)
+
+#undef ATOMIC_OP
+#undef ATOMIC_OPS
+
+#define ATOMIC_OP(op, func_op, c_op, I, prefix)					\
+static __always_inline void atomic##prefix##_##op(atomic##prefix##_t *v)	\
+{										\
+	atomic##prefix##_##func_op(I, v);					\
+}
+
+#define ATOMIC_FETCH_OP(op, func_op, c_op, I, prefix)				\
+static __always_inline int atomic##prefix##_fetch_##op(atomic##prefix##_t *v)	\
+{										\
+	return atomic##prefix##_fetch_##func_op(I, v);				\
+}
+
+#define ATOMIC_OP_RETURN(op, asm_op, c_op, I, prefix)				\
+static __always_inline int atomic##prefix##_##op##_return(atomic##prefix##_t *v) \
+{										\
+        return atomic##prefix##_fetch_##op(v) c_op I;				\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, asm_op, c_op, I)						\
+        ATOMIC_OP       (op, asm_op, c_op, I,   )				\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I,   )				\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I,   )
+#else
+#define ATOMIC_OPS(op, asm_op, c_op, I)						\
+        ATOMIC_OP       (op, asm_op, c_op, I,   )				\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I,   )				\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I,   )				\
+        ATOMIC_OP       (op, asm_op, c_op, I, 64)				\
+        ATOMIC_FETCH_OP (op, asm_op, c_op, I, 64)				\
+        ATOMIC_OP_RETURN(op, asm_op, c_op, I, 64)
+#endif
+
+ATOMIC_OPS(inc, add, +,  1)
+ATOMIC_OPS(dec, add, +, -1)
+
+#undef ATOMIC_OPS
+#undef ATOMIC_OP
+#undef ATOMIC_FETCH_OP
+#undef ATOMIC_OP_RETURN
+
+#define ATOMIC_OP(op, func_op, comp_op, I, prefix)				\
+static __always_inline bool atomic##prefix##_##op(atomic##prefix##_t *v)	\
+{										\
+	return atomic##prefix##_##func_op##_return(v) comp_op I;		\
+}
+
+ATOMIC_OP(inc_and_test, inc, ==, 0,   )
+ATOMIC_OP(dec_and_test, dec, ==, 0,   )
+#ifndef CONFIG_GENERIC_ATOMIC64
+ATOMIC_OP(inc_and_test, inc, ==, 0, 64)
+ATOMIC_OP(dec_and_test, dec, ==, 0, 64)
+#endif
+
+#undef ATOMIC_OP
+
+/* This is required to provide a barrier on success. */
+static __always_inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+       register int prev, rc;
+
+	__asm__ __volatile__ (
+		"0:\n\t"
+		"lr.w.aqrl %0, %2\n\t"
+		"beq       %0, %4, 1f\n\t"
+		"add       %1, %0, %3\n\t"
+		"sc.w.aqrl %1, %1, %2\n\t"
+		"bnez      %1, 0b\n\t"
+		"1:"
+		: "=&r" (prev), "=&r" (rc), "+A" (v->counter)
+		: "r" (a), "r" (u)
+		: "memory");
+	return prev;
+}
+
+#ifndef CONFIG_GENERIC_ATOMIC64
+static __always_inline long atomic64_add_unless(atomic64_t *v, long a, long u)
+{
+       register long prev, rc;
+
+	__asm__ __volatile__ (
+		"0:\n\t"
+		"lr.d.aqrl %0, %2\n\t"
+		"beq       %0, %4, 1f\n\t"
+		"add       %1, %0, %3\n\t"
+		"sc.d.aqrl %1, %1, %2\n\t"
+		"bnez      %1, 0b\n\t"
+		"1:"
+		: "=&r" (prev), "=&r" (rc), "+A" (v->counter)
+		: "r" (a), "r" (u)
+		: "memory");
+	return prev;
+}
+#endif
+
+/*
+ * The extra atomic operations that are constructed from one of the core
+ * LR/SC-based operations above.
+ */
+static __always_inline int atomic_inc_not_zero(atomic_t *v)
+{
+        return __atomic_add_unless(v, 1, 0);
+}
+
+#ifndef CONFIG_GENERIC_ATOMIC64
+static __always_inline int atomic64_inc_not_zero(atomic64_t *v)
+{
+        return atomic64_add_unless(v, 1, 0);
+}
+#endif
+
+/*
+ * atomic_{cmp,}xchg is required to have exactly the same ordering semantics as
+ * {cmp,}xchg and the operations that return, so they need a barrier.  We just
+ * use the other implementations directly.
+ */
+#define ATOMIC_OP(c_t, prefix, c_or, size, asm_or)						\
+static __always_inline c_t atomic##prefix##_cmpxchg##c_or(atomic##prefix##_t *v, c_t o, c_t n) 	\
+{												\
+	return __cmpxchg(&(v->counter), o, n, size, asm_or, asm_or);				\
+}												\
+static __always_inline c_t atomic##prefix##_xchg##c_or(atomic##prefix##_t *v, c_t n) 		\
+{												\
+	return __xchg(n, &(v->counter), size, asm_or);						\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(c_or, asm_or)			\
+	ATOMIC_OP( int,   , c_or, 4, asm_or)
+#else
+#define ATOMIC_OPS(c_or, asm_or)			\
+	ATOMIC_OP( int,   , c_or, 4, asm_or)		\
+	ATOMIC_OP(long, 64, c_or, 8, asm_or)
+#endif
+
+ATOMIC_OPS(        , .aqrl)
+ATOMIC_OPS(_acquire,   .aq)
+ATOMIC_OPS(_release,   .rl)
+ATOMIC_OPS(_relaxed,      )
+
+#undef ATOMIC_OPS
+#undef ATOMIC_OP
+
+#endif /* _ASM_RISCV_ATOMIC_H */
arch/riscv/include/asm/barrier.h new file +68 -0

68 lines not on this page · raw message

arch/riscv/include/asm/bitops.h new file +216 -0

216 lines not on this page · raw message

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 +134 -0

134 lines not on this page · raw message

arch/riscv/include/asm/io.h new file +180 -0

180 lines not on this page · raw message

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

165 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
@@ -0,0 +1,33 @@
+/*
+ * 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_SPINLOCK_TYPES_H
+#define _ASM_RISCV_SPINLOCK_TYPES_H
+
+#ifndef __LINUX_SPINLOCK_TYPES_H
+# error "please don't include this file directly"
+#endif
+
+typedef struct {
+	volatile unsigned int lock;
+} arch_spinlock_t;
+
+#define __ARCH_SPIN_LOCK_UNLOCKED	{ 0 }
+
+typedef struct {
+	volatile unsigned int lock;
+} arch_rwlock_t;
+
+#define __ARCH_RW_LOCK_UNLOCKED		{ 0 }
+
+#endif
arch/riscv/include/asm/tlb.h new file +24 -0
new file mode 100644
index 000000000000..c229509288ea
@@ -0,0 +1,24 @@
+/*
+ * 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_TLB_H
+#define _ASM_RISCV_TLB_H
+
+#include <asm-generic/tlb.h>
+
+static inline void tlb_flush(struct mmu_gather *tlb)
+{
+	flush_tlb_mm(tlb->mm);
+}
+
+#endif /* _ASM_RISCV_TLB_H */
arch/riscv/include/asm/tlbflush.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#24 lore raw

PATCH 12/17 RISC-V: ELF and module implementation

In reply to Palmer Dabbelt

This patch contains the code that interfaces with ELF objects on RISC-V systems, the vast majority of which is present to load kernel modules.

---
 arch/riscv/include/asm/compat.h | 29 ++++++++++++++
 arch/riscv/include/asm/elf.h    | 84 +++++++++++++++++++++++++++++++++++++++++
 arch/riscv/include/asm/hwcap.h  | 37 ++++++++++++++++++
 arch/riscv/mm/extable.c         | 37 ++++++++++++++++++
 4 files changed, 187 insertions(+)
 create mode 100644 arch/riscv/include/asm/compat.h
 create mode 100644 arch/riscv/include/asm/elf.h
 create mode 100644 arch/riscv/include/asm/hwcap.h
 create mode 100644 arch/riscv/mm/extable.c
arch/riscv/include/asm/compat.h new file +29 -0
new file mode 100644
index 000000000000..044aecff8854
@@ -0,0 +1,29 @@
+/*
+ * 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 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 /*__ASM_COMPAT_H*/
arch/riscv/include/asm/elf.h new file +84 -0

84 lines not on this page · raw message

arch/riscv/include/asm/hwcap.h new file +37 -0
new file mode 100644
index 000000000000..8a4ed7bbcbea
@@ -0,0 +1,37 @@
+/*
+ * Copied from arch/arm64/include/asm/hwcap.h
+ *
+ * Copyright (C) 2012 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 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_HWCAP_H
+#define __ASM_HWCAP_H
+
+#include <uapi/asm/hwcap.h>
+
+#ifndef __ASSEMBLY__
+/*
+ * This yields a mask that user programs can use to figure out what
+ * instruction set this cpu supports.
+ */
+#define ELF_HWCAP		(elf_hwcap)
+
+enum {
+	CAP_HWCAP = 1,
+};
+
+extern unsigned long elf_hwcap;
+#endif
+#endif
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;
+}
Signature · 1 line
2.13.0
author maintainer
#25 lore raw

PATCH 13/17 RISC-V: Task implementation

In reply to Palmer Dabbelt

This patch contains the implementation of tasks on RISC-V, most of which is involved in task switching.

---
 arch/riscv/include/asm/asm-offsets.h |   1 +
 arch/riscv/include/asm/current.h     |  45 ++++
 arch/riscv/include/asm/kprobes.h     |  22 ++
 arch/riscv/include/asm/processor.h   |  97 ++++++++
 arch/riscv/include/asm/switch_to.h   |  69 ++++++
 arch/riscv/include/asm/thread_info.h |  93 +++++++
 arch/riscv/kernel/asm-offsets.c      | 322 ++++++++++++++++++++++++
 arch/riscv/kernel/entry.S            | 457 +++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/process.c          | 129 ++++++++++
 9 files changed, 1235 insertions(+)
 create mode 100644 arch/riscv/include/asm/asm-offsets.h
 create mode 100644 arch/riscv/include/asm/current.h
 create mode 100644 arch/riscv/include/asm/kprobes.h
 create mode 100644 arch/riscv/include/asm/processor.h
 create mode 100644 arch/riscv/include/asm/switch_to.h
 create mode 100644 arch/riscv/include/asm/thread_info.h
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/process.c
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/current.h new file +45 -0

45 lines not on this page · raw message

arch/riscv/include/asm/kprobes.h new file +22 -0
new file mode 100644
index 000000000000..c7eb010d1528
@@ -0,0 +1,22 @@
+/*
+ * Copied from arch/arm64/include/asm/kprobes.h
+ *
+ * Copyright (C) 2013 Linaro Limited
+ * 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 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 _RISCV_KPROBES_H
+#define _RISCV_KPROBES_H
+
+#include <asm-generic/kprobes.h>
+
+#endif /* _RISCV_KPROBES_H */
arch/riscv/include/asm/processor.h new file +97 -0

97 lines not on this page · 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/thread_info.h new file +93 -0

93 lines not on this page · raw message

arch/riscv/kernel/asm-offsets.c new file +322 -0

322 lines not on this page · raw message

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

457 lines not on this page · raw message

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

129 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#27 lore raw

PATCH 15/17 RISC-V: Paging and MMU

In reply to Palmer Dabbelt

This patch contains code to manage the RISC-V MMU, including definitions of the page tables and the page walking code.

---
 arch/riscv/include/asm/mmu_context.h  |  69 ++++++
 arch/riscv/include/asm/page.h         | 134 +++++++++++
 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      | 430 ++++++++++++++++++++++++++++++++++
 arch/riscv/mm/fault.c                 | 282 ++++++++++++++++++++++
 8 files changed, 1196 insertions(+)
 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/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/mm/fault.c
arch/riscv/include/asm/mmu_context.h new file +69 -0
new file mode 100644
index 000000000000..de1fc1631fc4
@@ -0,0 +1,69 @@
+/*
+ * 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_CONTEXT_H
+#define _ASM_RISCV_MMU_CONTEXT_H
+
+#include <asm-generic/mm_hooks.h>
+
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <asm/tlbflush.h>
+
+static inline void enter_lazy_tlb(struct mm_struct *mm,
+	struct task_struct *task)
+{
+}
+
+/* Initialize context-related info for a new mm_struct */
+static inline int init_new_context(struct task_struct *task,
+	struct mm_struct *mm)
+{
+	return 0;
+}
+
+static inline void destroy_context(struct mm_struct *mm)
+{
+}
+
+static inline pgd_t *current_pgdir(void)
+{
+	return pfn_to_virt(csr_read(sptbr) & SPTBR_PPN);
+}
+
+static inline void set_pgdir(pgd_t *pgd)
+{
+	csr_write(sptbr, virt_to_pfn(pgd) | SPTBR_MODE);
+}
+
+static inline void switch_mm(struct mm_struct *prev,
+	struct mm_struct *next, struct task_struct *task)
+{
+	if (likely(prev != next)) {
+		set_pgdir(next->pgd);
+		local_flush_tlb_all();
+	}
+}
+
+static inline void activate_mm(struct mm_struct *prev,
+			       struct mm_struct *next)
+{
+	switch_mm(prev, next, NULL);
+}
+
+static inline void deactivate_mm(struct task_struct *task,
+	struct mm_struct *mm)
+{
+}
+
+#endif /* _ASM_RISCV_MMU_CONTEXT_H */
arch/riscv/include/asm/page.h new file +134 -0

134 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 +430 -0

430 lines not on this page · raw message

arch/riscv/mm/fault.c new file +282 -0

282 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#33 lore raw

PATCH 17/17 RISC-V: Build Infastructure

In reply to Palmer Dabbelt

This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and Kconfig files. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.

---
 Makefile                                  |   3 +-
 arch/riscv/Kconfig                        | 283 ++++++++++++++++++++++++++++++
 arch/riscv/Makefile                       |  64 +++++++
 arch/riscv/configs/freedom-u500_defconfig |  52 ++++++
 arch/riscv/configs/spike32_defconfig      |  50 ++++++
 arch/riscv/configs/spike64_defconfig      |  46 +++++
 arch/riscv/include/asm/Kbuild             |  61 +++++++
 arch/riscv/kernel/.gitignore              |   1 +
 arch/riscv/kernel/Makefile                |  33 ++++
 arch/riscv/kernel/vmlinux.lds.S           |  92 ++++++++++
 arch/riscv/lib/Makefile                   |   6 +
 arch/riscv/mm/Makefile                    |   4 +
 12 files changed, 694 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
 create mode 100644 arch/riscv/include/asm/Kbuild
 create mode 100644 arch/riscv/kernel/.gitignore
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S
 create mode 100644 arch/riscv/lib/Makefile
 create mode 100644 arch/riscv/mm/Makefile
Makefile +2 -1
index 1d6695ec3138..9830fdcbe2ef 100644
@@ -225,7 +225,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 +283 -0

283 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 +52 -0

52 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

arch/riscv/include/asm/Kbuild new file +61 -0

61 lines not on this page · raw message

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 +33 -0
new file mode 100644
index 000000000000..ab8baf7bd142
@@ -0,0 +1,33 @@
+#
+# Makefile for the RISC-V Linux kernel
+#
+
+extra-y += head.o
+extra-y += vmlinux.lds
+
+obj-y	+= cpu.o
+obj-y	+= cpufeature.o
+obj-y	+= entry.o
+obj-y	+= irq.o
+obj-y	+= process.o
+obj-y	+= ptrace.o
+obj-y	+= reset.o
+obj-y	+= setup.o
+obj-y	+= signal.o
+obj-y	+= syscall_table.o
+obj-y	+= sys_riscv.o
+obj-y	+= time.o
+obj-y	+= traps.o
+obj-y	+= riscv_ksyms.o
+obj-y	+= stacktrace.o
+obj-y	+= vdso.o
+obj-y	+= cacheinfo.o
+obj-y	+= vdso/
+
+CFLAGS_setup.o := -mcmodel=medany
+
+obj-$(CONFIG_SMP)		+= smpboot.o
+obj-$(CONFIG_SMP)		+= smp.o
+obj-$(CONFIG_MODULES)		+= module.o
+
+clean:
arch/riscv/kernel/vmlinux.lds.S new file +92 -0

92 lines not on this page · raw message

arch/riscv/lib/Makefile new file +6 -0
new file mode 100644
index 000000000000..596c2ca40d63
@@ -0,0 +1,6 @@
+lib-y	+= delay.o
+lib-y	+= memcpy.o
+lib-y	+= memset.o
+lib-y	+= uaccess.o
+
+lib-$(CONFIG_32BIT) += udivdi3.o
arch/riscv/mm/Makefile new file +4 -0
new file mode 100644
index 000000000000..81f7d9ce6d88
@@ -0,0 +1,4 @@
+obj-y += init.o
+obj-y += fault.o
+obj-y += extable.o
+obj-y += ioremap.o
Signature · 1 line
2.13.0
author maintainer
#28 lore raw

PATCH 16/17 RISC-V: User-facing API

In reply to Palmer Dabbelt

This patch contains code that is in some way visible to the user:
including via system calls, the VDSO, module loading and signal handling. It also contains some generic code that is ABI visible.

---
 arch/riscv/include/asm/mmu.h              |  26 +++
 arch/riscv/include/asm/ptrace.h           | 116 ++++++++++++
 arch/riscv/include/asm/syscall.h          |  90 ++++++++++
 arch/riscv/include/asm/unistd.h           |  16 ++
 arch/riscv/include/asm/vdso.h             |  32 ++++
 arch/riscv/include/uapi/asm/Kbuild        |   5 +
 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/hwcap.h       |  36 ++++
 arch/riscv/include/uapi/asm/ptrace.h      |  90 ++++++++++
 arch/riscv/include/uapi/asm/sigcontext.h  |  30 ++++
 arch/riscv/include/uapi/asm/siginfo.h     |  24 +++
 arch/riscv/include/uapi/asm/ucontext.h    |  35 ++++
 arch/riscv/kernel/cpufeature.c            |  61 +++++++
 arch/riscv/kernel/module.c                | 217 ++++++++++++++++++++++
 arch/riscv/kernel/ptrace.c                | 125 +++++++++++++
 arch/riscv/kernel/riscv_ksyms.c           |  15 ++
 arch/riscv/kernel/signal.c                | 289 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/sys_riscv.c             |  49 +++++
 arch/riscv/kernel/syscall_table.c         |  25 +++
 arch/riscv/kernel/vdso/.gitignore         |   2 +
 arch/riscv/kernel/vdso/Makefile           |  64 +++++++
 arch/riscv/kernel/vdso/rt_sigreturn.S     |  24 +++
 arch/riscv/kernel/vdso/vdso.S             |  27 +++
 arch/riscv/kernel/vdso/vdso.lds.S         |  77 ++++++++
 27 files changed, 1630 insertions(+)
 create mode 100644 arch/riscv/include/asm/mmu.h
 create mode 100644 arch/riscv/include/asm/ptrace.h
 create mode 100644 arch/riscv/include/asm/syscall.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/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/hwcap.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/ucontext.h
 create mode 100644 arch/riscv/kernel/cpufeature.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/signal.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/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/rt_sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S
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/ptrace.h new file +116 -0

116 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/unistd.h new file +16 -0
new file mode 100644
index 000000000000..9f250ed007cd
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+#define __ARCH_HAVE_MMU
+#define __ARCH_WANT_SYS_CLONE
+#include <uapi/asm/unistd.h>
arch/riscv/include/asm/vdso.h new file +32 -0
new file mode 100644
index 000000000000..95768a3810a7
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ * 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 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_VDSO_H
+#define _ASM_RISCV_VDSO_H
+
+#include <linux/types.h>
+
+struct vdso_data {
+};
+
+#define VDSO_SYMBOL(base, name)					\
+({								\
+	extern const char __vdso_##name[];			\
+	(void __user *)((unsigned long)(base) + __vdso_##name);	\
+})
+
+#endif /* _ASM_RISCV_VDSO_H */
arch/riscv/include/uapi/asm/Kbuild new file +5 -0
new file mode 100644
index 000000000000..a20ed2ccc5ae
@@ -0,0 +1,5 @@
+# UAPI Header export list
+include include/uapi/asm-generic/Kbuild.asm
+
+generic-y += setup.h
+generic-y += unistd.h
arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
new file mode 100644
index 000000000000..1376515547cd
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * 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 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 _UAPI_ASM_RISCV_AUXVEC_H
+#define _UAPI_ASM_RISCV_AUXVEC_H
+
+/* vDSO location */
+#define AT_SYSINFO_EHDR 33
+
+#endif /* _UAPI_ASM_RISCV_AUXVEC_H */
arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
new file mode 100644
index 000000000000..0b3cb52fd29d
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * 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 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 _UAPI_ASM_RISCV_BITSPERLONG_H
+#define _UAPI_ASM_RISCV_BITSPERLONG_H
+
+#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8)
+
+#include <asm-generic/bitsperlong.h>
+
+#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
new file mode 100644
index 000000000000..4ca38af2cd32
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * 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 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 _UAPI_ASM_RISCV_BYTEORDER_H
+#define _UAPI_ASM_RISCV_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* _UAPI_ASM_RISCV_BYTEORDER_H */
arch/riscv/include/uapi/asm/elf.h new file +83 -0

83 lines not on this page · raw message

arch/riscv/include/uapi/asm/hwcap.h new file +36 -0
new file mode 100644
index 000000000000..f333221c9ab2
@@ -0,0 +1,36 @@
+/*
+ * Copied from arch/arm64/include/asm/hwcap.h
+ *
+ * Copyright (C) 2012 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 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 __UAPI_ASM_HWCAP_H
+#define __UAPI_ASM_HWCAP_H
+
+/*
+ * Linux saves the floating-point registers according to the ISA Linux is
+ * executing on, as opposed to the ISA the user program is compiled for.  This
+ * is necessary for a handful of esoteric use cases: for example, userpsace
+ * threading libraries must be able to examine the actual machine state in
+ * order to fully reconstruct the state of a thread.
+ */
+#define COMPAT_HWCAP_ISA_I	(1 << ('I' - 'A'))
+#define COMPAT_HWCAP_ISA_M	(1 << ('M' - 'A'))
+#define COMPAT_HWCAP_ISA_A	(1 << ('A' - 'A'))
+#define COMPAT_HWCAP_ISA_F	(1 << ('F' - 'A'))
+#define COMPAT_HWCAP_ISA_D	(1 << ('D' - 'A'))
+#define COMPAT_HWCAP_ISA_C	(1 << ('C' - 'A'))
+
+#endif
arch/riscv/include/uapi/asm/ptrace.h new file +90 -0

90 lines not on this page · raw message

arch/riscv/include/uapi/asm/sigcontext.h new file +30 -0
new file mode 100644
index 000000000000..ed7372b277fa
@@ -0,0 +1,30 @@
+/*
+ * 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 _UAPI_ASM_RISCV_SIGCONTEXT_H
+#define _UAPI_ASM_RISCV_SIGCONTEXT_H
+
+#include <asm/ptrace.h>
+
+/*
+ * Signal context structure
+ *
+ * This contains the context saved before a signal handler is invoked;
+ * it is restored by sys_sigreturn / sys_rt_sigreturn.
+ */
+struct sigcontext {
+	struct user_regs_struct sc_regs;
+	union __riscv_fp_state sc_fpregs;
+};
+
+#endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */
arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
new file mode 100644
index 000000000000..f96849aac662
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 SiFive, Inc.
+ *
+ * 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_SIGINFO_H
+#define __ASM_SIGINFO_H
+
+#define __ARCH_SI_PREAMBLE_SIZE	(__SIZEOF_POINTER__ == 4 ? 12 : 16)
+
+#include <asm-generic/siginfo.h>
+
+#endif
arch/riscv/include/uapi/asm/ucontext.h new file +35 -0
new file mode 100644
index 000000000000..52eff9febcfd
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2017 SiFive, Inc.
+ *
+ * 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/>.
+ *
+ * This file was copied from arch/arm64/include/uapi/asm/ucontext.h
+ */
+#ifndef _UAPI__ASM_UCONTEXT_H
+#define _UAPI__ASM_UCONTEXT_H
+
+#include <linux/types.h>
+
+struct ucontext {
+	unsigned long	  uc_flags;
+	struct ucontext	 *uc_link;
+	stack_t		  uc_stack;
+	sigset_t	  uc_sigmask;
+	/* glibc uses a 1024-bit sigset_t */
+	__u8		  __unused[1024 / 8 - sizeof(sigset_t)];
+	/* last for future expansion */
+	struct sigcontext uc_mcontext;
+};
+
+#endif /* _UAPI__ASM_UCONTEXT_H */
arch/riscv/kernel/cpufeature.c new file +61 -0

61 lines not on this page · raw message

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

217 lines not on this page · raw message

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

125 lines not on this page · raw message

arch/riscv/kernel/riscv_ksyms.c new file +15 -0
new file mode 100644
index 000000000000..23cc81ec9e94
@@ -0,0 +1,15 @@
+/*
+ * 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/signal.c new file +289 -0

289 lines not on this page · raw message

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

49 lines not on this page · raw message

arch/riscv/kernel/syscall_table.c new file +25 -0
new file mode 100644
index 000000000000..4e30dc5fb593
@@ -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/linkage.h>
+#include <linux/syscalls.h>
+#include <asm-generic/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/vdso/.gitignore new file +2 -0
new file mode 100644
index 000000000000..97c2d69d0289
@@ -0,0 +1,2 @@
+vdso.lds
+*.tmp
arch/riscv/kernel/vdso/Makefile new file +64 -0

64 lines not on this page · raw message

arch/riscv/kernel/vdso/rt_sigreturn.S new file +24 -0
new file mode 100644
index 000000000000..f5aa3d72acfb
@@ -0,0 +1,24 @@
+/*
+ * 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.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+	.text
+ENTRY(__vdso_rt_sigreturn)
+	.cfi_startproc
+	.cfi_signal_frame
+	li a7, __NR_rt_sigreturn
+	scall
+	.cfi_endproc
+ENDPROC(__vdso_rt_sigreturn)
arch/riscv/kernel/vdso/vdso.S new file +27 -0
new file mode 100644
index 000000000000..7055de5f9174
@@ -0,0 +1,27 @@
+/*
+ * 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.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/linkage.h>
+#include <asm/page.h>
+
+	__PAGE_ALIGNED_DATA
+
+	.globl vdso_start, vdso_end
+	.balign PAGE_SIZE
+vdso_start:
+	.incbin "arch/riscv/kernel/vdso/vdso.so"
+	.balign PAGE_SIZE
+vdso_end:
+
+	.previous
arch/riscv/kernel/vdso/vdso.lds.S new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#12 lore raw

PATCH 5/17 clocksource: New RISC-V SBI timer driver

In reply to Palmer Dabbelt

The RISC-V ISA defines a per-hart real-time clock and timer, which is present on all systems. The clock is accessed via the 'rdtime' pseudo-instruction (which reads a CSR), and the timer is set via an SBI call.

This driver attempts to split out the RISC-V ISA specific mechanisms of accessing the hardware from the clocksource driver by taking a pair of function pointers to issue the actual RISC-V specific instructions.

---
 drivers/clocksource/Kconfig       |  8 +++++
 drivers/clocksource/Makefile      |  1 +
 drivers/clocksource/riscv_timer.c | 64 +++++++++++++++++++++++++++++++++++++++
 include/linux/timer_riscv.h       | 41 +++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
 create mode 100644 drivers/clocksource/riscv_timer.c
 create mode 100644 include/linux/timer_riscv.h
drivers/clocksource/Kconfig +8 -0
index fcae5ca6ac92..a5829c0b3ae4 100644
@@ -607,4 +607,12 @@ config CLKSRC_ST_LPC
 	  Enable this option to use the Low Power controller timer
 	  as clocksource.
 
+config RISCV_TIMER
+	bool "Timer for the RISC-V platform" if COMPILE_TEST
+	depends on RISCV
+	help
+	  This enables the per-hart timer built into all RISC-V systems, which
+	  is accessed via both the SBI and the rdcycle instruction.  This is
+	  required for all RISC-V systems.
+
 endmenu
drivers/clocksource/Makefile +1 -0
index 6df949402dfc..20d75b3f22e4 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_RISCV_TIMER)		+= riscv_timer.o
drivers/clocksource/riscv_timer.c new file +64 -0

64 lines not on this page · raw message

include/linux/timer_riscv.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#26 lore raw

PATCH 14/17 RISC-V: Device, timer, IRQs, and the SBI

In reply to Palmer Dabbelt

This patch contains code that interfaces with devices that are mandated by the RISC-V supervisor specification and that don't have explicit drivers anywhere else in the tree. This includes the staticly defined interrupts, the CSR-mapped timer, and virtualized SBI devices.

---
 arch/riscv/include/asm/delay.h       |  28 +++++++++
 arch/riscv/include/asm/dma-mapping.h |  38 ++++++++++++
 arch/riscv/include/asm/irq.h         |  28 +++++++++
 arch/riscv/include/asm/irqflags.h    |  63 ++++++++++++++++++++
 arch/riscv/include/asm/pci.h         |  48 +++++++++++++++
 arch/riscv/include/asm/sbi.h         | 100 +++++++++++++++++++++++++++++++
 arch/riscv/include/asm/timex.h       |  59 +++++++++++++++++++
 arch/riscv/lib/delay.c               | 110 +++++++++++++++++++++++++++++++++++
 arch/riscv/mm/ioremap.c              |  92 +++++++++++++++++++++++++++++
 9 files changed, 566 insertions(+)
 create mode 100644 arch/riscv/include/asm/delay.h
 create mode 100644 arch/riscv/include/asm/dma-mapping.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/pci.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/timex.h
 create mode 100644 arch/riscv/lib/delay.c
 create mode 100644 arch/riscv/mm/ioremap.c
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/dma-mapping.h new file +38 -0
new file mode 100644
index 000000000000..3eec1000196d
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2004 Hewlett-Packard Co
+ *	David Mosberger-Tang <[email protected]>
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 SiFive, Inc.
+ *
+ * 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_DMA_MAPPING_H
+#define __ASM_RISCV_DMA_MAPPING_H
+
+/* Use ops->dma_mapping_error (if it exists) or assume success */
+// #undef DMA_ERROR_CODE
+
+static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
+{
+	return &dma_noop_ops;
+}
+
+static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
+{
+	if (!dev->dma_mask)
+		return false;
+
+	return addr + size - 1 <= *dev->dma_mask;
+}
+
+#endif	/* __ASM_RISCV_DMA_MAPPING_H */
arch/riscv/include/asm/irq.h new file +28 -0
new file mode 100644
index 000000000000..4dee9d4c13c0
@@ -0,0 +1,28 @@
+/*
+ * 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>
+
+#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/pci.h new file +48 -0

48 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/timex.h new file +59 -0

59 lines not on this page · raw message

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

110 lines not on this page · raw message

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

92 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#16 lore raw

PATCH 9/17 RISC-V: Init and Halt Code

In reply to Palmer Dabbelt

This contains the various __init C functions, the initial assembly kernel entry point, and the code to reset the system. When a file was init-related this patch contains the entire file.

---
 arch/riscv/include/asm/bug.h   |  88 +++++++++++++++
 arch/riscv/include/asm/cache.h |  22 ++++
 arch/riscv/include/asm/smp.h   |  52 +++++++++
 arch/riscv/kernel/cacheinfo.c  | 105 ++++++++++++++++++
 arch/riscv/kernel/cpu.c        |  89 +++++++++++++++
 arch/riscv/kernel/head.S       | 151 +++++++++++++++++++++++++
 arch/riscv/kernel/irq.c        |  20 ++++
 arch/riscv/kernel/reset.c      |  36 ++++++
 arch/riscv/kernel/setup.c      | 246 +++++++++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/smp.c        | 110 ++++++++++++++++++
 arch/riscv/kernel/smpboot.c    | 112 +++++++++++++++++++
 arch/riscv/kernel/time.c       |  76 +++++++++++++
 arch/riscv/kernel/traps.c      | 180 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/vdso.c       | 125 +++++++++++++++++++++
 arch/riscv/mm/init.c           |  70 ++++++++++++
 15 files changed, 1482 insertions(+)
 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/smp.h
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.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/mm/init.c
arch/riscv/include/asm/bug.h new file +88 -0
new file mode 100644
index 000000000000..c3e13764a943
@@ -0,0 +1,88 @@
+/*
+ * 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_BUG_H
+#define _ASM_RISCV_BUG_H
+
+#include <linux/compiler.h>
+#include <linux/const.h>
+#include <linux/types.h>
+
+#include <asm/asm.h>
+
+#ifdef CONFIG_GENERIC_BUG
+#define __BUG_INSN	_AC(0x00100073, UL) /* ebreak */
+
+#ifndef __ASSEMBLY__
+typedef u32 bug_insn_t;
+
+#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
+#define __BUG_ENTRY_ADDR	INT " 1b - 2b"
+#define __BUG_ENTRY_FILE	INT " %0 - 2b"
+#else
+#define __BUG_ENTRY_ADDR	RISCV_PTR " 1b"
+#define __BUG_ENTRY_FILE	RISCV_PTR " %0"
+#endif
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __BUG_ENTRY			\
+	__BUG_ENTRY_ADDR "\n\t"		\
+	__BUG_ENTRY_FILE "\n\t"		\
+	SHORT " %1"
+#else
+#define __BUG_ENTRY			\
+	__BUG_ENTRY_ADDR
+#endif
+
+#define BUG()							\
+do {								\
+	__asm__ __volatile__ (					\
+		"1:\n\t"					\
+			"ebreak\n"				\
+			".pushsection __bug_table,\"a\"\n\t"	\
+		"2:\n\t"					\
+			__BUG_ENTRY "\n\t"			\
+			".org 2b + %2\n\t"			\
+			".popsection"				\
+		:						\
+		: "i" (__FILE__), "i" (__LINE__),		\
+		  "i" (sizeof(struct bug_entry)));		\
+	unreachable();						\
+} while (0)
+#endif /* !__ASSEMBLY__ */
+#else /* CONFIG_GENERIC_BUG */
+#ifndef __ASSEMBLY__
+#define BUG()							\
+do {								\
+	__asm__ __volatile__ ("ebreak\n");			\
+	unreachable();						\
+} while (0)
+#endif /* !__ASSEMBLY__ */
+#endif /* CONFIG_GENERIC_BUG */
+
+#define HAVE_ARCH_BUG
+
+#include <asm-generic/bug.h>
+
+#ifndef __ASSEMBLY__
+
+struct pt_regs;
+struct task_struct;
+
+extern void die(struct pt_regs *regs, const char *str);
+extern void do_trap(struct pt_regs *regs, int signo, int code,
+	unsigned long addr, struct task_struct *tsk);
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_RISCV_BUG_H */
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/smp.h new file +52 -0

52 lines not on this page · raw message

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

105 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/head.S new file +151 -0

151 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/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/setup.c new file +246 -0

246 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 +112 -0

112 lines not on this page · raw message

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

76 lines not on this page · raw message

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

180 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/mm/init.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#23 lore raw

PATCH 11/17 RISC-V: Generic library routines and assembly

In reply to Palmer Dabbelt

This patch contains code that is more specific to the RISC-V ISA than it is to Linux. It contains string and math operations, C wrappers for various assembly instructions, stack walking code, and uaccess.

---
 arch/riscv/include/asm/asm.h            |  76 +++++
 arch/riscv/include/asm/csr.h            | 125 ++++++++
 arch/riscv/include/asm/linkage.h        |  20 ++
 arch/riscv/include/asm/string.h         |  26 ++
 arch/riscv/include/asm/uaccess.h        | 513 ++++++++++++++++++++++++++++++++
 arch/riscv/include/asm/word-at-a-time.h |  55 ++++
 arch/riscv/kernel/stacktrace.c          | 177 +++++++++++
 arch/riscv/lib/memcpy.S                 | 115 +++++++
 arch/riscv/lib/memset.S                 | 120 ++++++++
 arch/riscv/lib/uaccess.S                | 117 ++++++++
 arch/riscv/lib/udivdi3.S                |  38 +++
 11 files changed, 1382 insertions(+)
 create mode 100644 arch/riscv/include/asm/asm.h
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/linkage.h
 create mode 100644 arch/riscv/include/asm/string.h
 create mode 100644 arch/riscv/include/asm/uaccess.h
 create mode 100644 arch/riscv/include/asm/word-at-a-time.h
 create mode 100644 arch/riscv/kernel/stacktrace.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/include/asm/asm.h new file +76 -0
new file mode 100644
index 000000000000..6cbbb6a68d76
@@ -0,0 +1,76 @@
+/*
+ * 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_ASM_H
+#define _ASM_RISCV_ASM_H
+
+#ifdef __ASSEMBLY__
+#define __ASM_STR(x)	x
+#else
+#define __ASM_STR(x)	#x
+#endif
+
+#if __riscv_xlen == 64
+#define __REG_SEL(a, b)	__ASM_STR(a)
+#elif __riscv_xlen == 32
+#define __REG_SEL(a, b)	__ASM_STR(b)
+#else
+#error "Unexpected __riscv_xlen"
+#endif
+
+#define REG_L		__REG_SEL(ld, lw)
+#define REG_S		__REG_SEL(sd, sw)
+#define SZREG		__REG_SEL(8, 4)
+#define LGREG		__REG_SEL(3, 2)
+
+#if __SIZEOF_POINTER__ == 8
+#ifdef __ASSEMBLY__
+#define RISCV_PTR		.dword
+#define RISCV_SZPTR		8
+#define RISCV_LGPTR		3
+#else
+#define RISCV_PTR		".dword"
+#define RISCV_SZPTR		"8"
+#define RISCV_LGPTR		"3"
+#endif
+#elif __SIZEOF_POINTER__ == 4
+#ifdef __ASSEMBLY__
+#define RISCV_PTR		.word
+#define RISCV_SZPTR		4
+#define RISCV_LGPTR		2
+#else
+#define RISCV_PTR		".word"
+#define RISCV_SZPTR		"4"
+#define RISCV_LGPTR		"2"
+#endif
+#else
+#error "Unexpected __SIZEOF_POINTER__"
+#endif
+
+#if (__SIZEOF_INT__ == 4)
+#define INT		__ASM_STR(.word)
+#define SZINT		__ASM_STR(4)
+#define LGINT		__ASM_STR(2)
+#else
+#error "Unexpected __SIZEOF_INT__"
+#endif
+
+#if (__SIZEOF_SHORT__ == 2)
+#define SHORT		__ASM_STR(.half)
+#define SZSHORT		__ASM_STR(2)
+#define LGSHORT		__ASM_STR(1)
+#else
+#error "Unexpected __SIZEOF_SHORT__"
+#endif
+
+#endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/csr.h new file +125 -0

125 lines not on this page · raw message

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/string.h new file +26 -0
new file mode 100644
index 000000000000..9210fcf4ff52
@@ -0,0 +1,26 @@
+/*
+ * 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.  See the
+ *   GNU General Public License for more details.
+ */
+
+#ifndef _ASM_RISCV_STRING_H
+#define _ASM_RISCV_STRING_H
+
+#include <linux/types.h>
+#include <linux/linkage.h>
+
+#define __HAVE_ARCH_MEMSET
+extern asmlinkage void *memset(void *, int, size_t);
+
+#define __HAVE_ARCH_MEMCPY
+extern asmlinkage void *memcpy(void *, const void *, size_t);
+
+#endif /* _ASM_RISCV_STRING_H */
arch/riscv/include/asm/uaccess.h new file +513 -0

513 lines not on this page · 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/kernel/stacktrace.c new file +177 -0

177 lines not on this page · raw message

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

115 lines not on this page · raw message

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

120 lines not on this page · raw message

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

117 lines not on this page · raw message

arch/riscv/lib/udivdi3.S new file +38 -0
new file mode 100644
index 000000000000..cb01ae5b181a
@@ -0,0 +1,38 @@
+/*
+ * 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
#8 lore raw

PATCH 4/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 2af3ab3f7702..3f39f16046dd 100644
@@ -11246,6 +11246,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
#15 lore raw

PATCH 8/17 tty: New RISC-V SBI console driver

In reply to Palmer Dabbelt

The RISC-V ISA defines a simple console that is availiable via SBI calls on all systems. This patch adds a driver for this console interface that can act as both a target for early printk and as the system console.

---
 drivers/tty/hvc/Kconfig   |  11 +++++
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c
drivers/tty/hvc/Kconfig +11 -0
index b8d5ea0ae26b..24cbaaf47d8d 100644
@@ -97,6 +97,17 @@ config HVC_BFIN_JTAG
 	 the HVC driver.  If you don't have JTAG, then you probably don't
 	 want this option.
 
+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.
+
 config HVCS
 	tristate "IBM Hypervisor Virtual Console Server support"
 	depends on PPC_PSERIES && HVC_CONSOLE
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 +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#14 lore raw

PATCH 7/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          |  13 ++
 drivers/irqchip/Makefile         |   1 +
 drivers/irqchip/irq-riscv-plic.c | 370 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 384 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +13 -0
index 7923d3fa8fae..ae5e27f090ec 100644
@@ -307,6 +307,19 @@ config QCOM_IRQ_COMBINER
 	  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 controls devices interrupts and connects them to
+	   each core's local interrupt controller.  Aside from timer and
+	   software interrupts, all other 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"
drivers/irqchip/Makefile +1 -0
index b1aa9114afc4..7880c9cec40e 100644
@@ -78,4 +78,5 @@ obj-$(CONFIG_EZNPS_GIC)			+= irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)		+= irq-aspeed-vic.o irq-aspeed-i2c-ic.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-plic.c new file +370 -0

370 lines not on this page · raw message

Signature · 1 line
2.13.0
author maintainer
#13 lore raw

PATCH 6/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 | 213 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/Kconfig +14 -0
index f1fd5f44d1d4..7923d3fa8fae 100644
@@ -306,3 +306,17 @@ config QCOM_IRQ_COMBINER
 	help
 	  Say yes here to add support for the IRQ combiner devices embedded
 	  in Qualcomm Technologies chips.
+
+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 e88d856cc09c..b1aa9114afc4 100644
@@ -78,3 +78,4 @@ obj-$(CONFIG_EZNPS_GIC)			+= irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)		+= irq-aspeed-vic.o irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI) 		+= irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)		+= qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_INTC)		+= irq-riscv-intc.o
drivers/irqchip/irq-riscv-intc.c new file +213 -0

213 lines not on this page · raw message

Signature · 1 line
2.13.0
#38 lore raw
In reply to Palmer Dabbelt
Quoted 7 lines · Palmer Dabbelt

While it's only been a day since the last patch set (which might be a bit fast), I've generally been spinning new patch sets whenever I get through my inbox. For my other patch sets I've managed to get buried in a week's worth of email in a few hours, but for this one it appears there's been significantly less feedback so I've managed to get through everything. I'm hoping that's a good sign: either I've started to figure out what I'm doing or the code has gotten better -- hopefully it doesn't mean everyone else has given up :).

I don't seem have received the last few versions, but I did get this one, good to see the progress!

A few general notes for the next version:

- please always include the patch version in the subject for each patch, as 'git format-patch -v 7' will do.

- In the introductory mail, list the entire history since v1 if you can reconstruct it. I'm pretty lost now keeping track of earlier versions and what has changed compared to this one, so I'd have to start reviewing from scratch.

Quoted 4 lines

As it's been only a day, the changes are pretty minimal:

* The patch set is now based on linux-next/master, which I believe is a better base now that we're getting closer to upstream.

It's not entirely clear though. Until the end of the merge window, this is fine, as stuff in linux-next today is likely to end up in 4.13-rc1 on Sunday. However, once -rc1 is out, you should base your patches on that to get a bisectable patch series once it is merged. If there are conflicts or dependencies on other trees that get scheduled for 4.14, we have to see how to resolve them one at a time.

Quoted 5 lines

At this point I'm not really sure how to proceed: reviews have calmed down quite a bit over the last two weeks, but I'm not familiar with the Linux development process enough to know how to get closer to upstream. Is this ready for inclusion into another tree? If so, is linux-next the right tree to work off of?

Without having looked at the current state of the patch series, I would guess that next week is a good time to ask for inclusion *in* linux-next, while continuing the review.

This should exclude the device driver patches (irqchip, clocksource, tty) that get merged by other maintainers as they see fit, but I would include the lib/ patch in your series, which is a build-time requirement.

For the pci patch, ask Bjorn if he has a preference whether he wants to merge the patch or have you put it into your tree with his 'Acked-by' tag.

Are there any remaining review comments that you got for the arch/riscv/* patches? If not, I'll try to do another full review soon and provide my own Ack for any patch that I feel qualified as a reviewer. The patches that got lots of review comments from others should ideally also get an Ack from those reviewers.

Once you you have enough Acks, you can then change your operational mode from modifying the commits in place, to only adding patches on top for addressing further changes.

In the long run, the way this usually works is that you have one stable tree that only gets patches on top, while new features are developed on separate branches and then applied or merged to that branch once they are done.

You may also want to have separate 'fixes' and 'next' branches that are both public. The 'fixes' branch is what you send to Linus between the merge windows when you find bugs, while the 'next' branch is part of linux-next and it gets tagged for the pull request that you send at the beginning of each merge window.

Quoted 8 lines

Of course, if anyone has outstanding code reviews then feel free to submit them either to this patch set or a previous one (v5 is essentially the same, and v4 is mostly some small SMP fixes). I don't want to rush anyone by re-submitting so quickly, it's just that my usual protocol has been sped up.

As usual, the patch set has been posted to our Git Hub page

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

There are a couple of downsides to hosting the git tree on github, so as you get nearer to inclusion, you should decide whether to have your own git server on riscv.org or sifive.com, or to get an account on kernel.org.

You should also make sure you get your gpg key signed by other kernel maintainers so you can properly sign git tags for pull requests. The signatures are a requirement for an account on kernel.org but are generally a good idea even when you have the tree on github or your own site. https://www.kernel.org/doc/ksmap/ shows some people that are closeby.

Arnd

#29 lore raw

Re: [PATCH 16/17] RISC-V: User-facing API

In reply to Palmer Dabbelt
Quoted 12 lines · Palmer Dabbelt
arch/riscv/include/asm/unistd.h new file +6 -0
new file mode 100644
index 000000000000..9f250ed007cd
@@ -0,0 +1,16 @@
+/*
+ * 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.

arch/riscv/include/asm/unistd.h line 16

Quoted 10 lines
arch/riscv/include/asm/unistd.h new file +10 -0
+ *
+ *   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.
+ */
+
+#define __ARCH_HAVE_MMU
+#define __ARCH_WANT_SYS_CLONE
+#include <uapi/asm/unistd.h>

It might be worth keeping arch/risc/include/uapi/asm/unistd.h around, even if it only includes asm-generic/unistd.h, as it'll only get added again the next time a syscall is deprecated from the default list in order to add the appropriate __ARCH_WANT_RENAMEAT-like define, but yeh no big deal.

Quoted 20 lines
arch/riscv/kernel/ptrace.c new file +13 -0
new file mode 100644
index 000000000000..ba3e80712797
@@ -0,0 +1,125 @@
 
+static int riscv_gpr_get(struct task_struct *target,
+			 const struct user_regset *regset,
+			 unsigned int pos, unsigned int count,
+			 void *kbuf, void __user *ubuf)
+{
+	struct pt_regs *regs;
+
+	regs = task_pt_regs(target);
+	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, regs, 0, -1);
+}
+
+static int riscv_gpr_set(struct task_struct *target,
+			 const struct user_regset *regset,

arch/riscv/kernel/ptrace.c line 55

Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10 -0
+			 unsigned int pos, unsigned int count,
+			 const void *kbuf, const void __user *ubuf)
+{
+	int ret;
+	struct pt_regs *regs;
+
+	regs = task_pt_regs(target);
+	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &regs, 0, -1);
+	return ret;
+}

This is looking much safer now (the caller at least seems to always check pos + count is in range).

Quoted 10 lines
arch/riscv/kernel/signal.c new file +3 -0
new file mode 100644
index 000000000000..e0a1b89583ef
@@ -0,0 +1,289 @@
 
+static long setup_sigcontext(struct rt_sigframe __user *frame,
+	struct pt_regs *regs)
+{

arch/riscv/kernel/signal.c line 134

Quoted 10 lines
arch/riscv/kernel/signal.c new file +10 -0
+	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
+	long err;
+	size_t i;
+	/* sc_regs is structured the same as the start of pt_regs */
+	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
+	/* Save the floating-point state. */
+	err |= save_d_state(regs, &sc->sc_fpregs.d);
+	/* We support no other extension state at this time. */
+	for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
+		err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]);

How should userland determine how to interpret sc_fpregs? It looks like you couldn't add f or q state without using one of these reserved fields, so why not just specify a field up front to say which fp format (if any) to interpret?

That would allow userland wanting to interpret it to safely check that field in a forward and backward compatible way without assuming a specific format is in use.

Cheers
James

#9 lore raw

Re: [PATCH 04/17] MAINTAINERS: Add RISC-V

In reply to Palmer Dabbelt
Quoted 15 lines · 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 +0 -0
index 2af3ab3f7702..3f39f16046dd 100644

MAINTAINERS M: Maxim Levitsky <[email protected]> · line 11255

Quoted 10 lines
MAINTAINERS +7 -0
@@ -11246,6 +11246,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/

Should this include other tightly riscv specific drivers outside of arch/riscv/ (or maybe they should have their own MAINTAINERS entries if they aren't so tightly bound to the architecture or are maintained separately)?

drivers/clocksource/riscv_timer.c
drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/irq-riscv-plic.c
drivers/tty/hvc/hvc_sbi.c
include/linux/timer_riscv.h

Cheers
James

Quoted 7 lines
MAINTAINERS +1 -0
+
 ROCCAT DRIVERS
 M:	Stefan Achatz <[email protected]>
 W:	http://sourceforge.net/projects/roccat/
Signature · 1 line
2.13.0
#10 lore raw

Re: [PATCH 04/17] MAINTAINERS: Add RISC-V

Quoted 32 lines · James Hogan
Quoted 15 lines · 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 +0 -0
index 2af3ab3f7702..3f39f16046dd 100644

MAINTAINERS M: Maxim Levitsky <[email protected]> · line 11255

Quoted 10 lines
MAINTAINERS +7 -0
@@ -11246,6 +11246,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/

Should this include other tightly riscv specific drivers outside of arch/riscv/ (or maybe they should have their own MAINTAINERS entries if they aren't so tightly bound to the architecture or are maintained separately)?

Quoted 6 lines

drivers/clocksource/riscv_timer.c
drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/irq-riscv-plic.c
drivers/tty/hvc/hvc_sbi.c
include/linux/timer_riscv.h

I would suggest including a

K: riscv

keyword line that should catch the closely related drivers, and have separate entries for the rest. Maybe rename the hvc_sbi file to fall within that keyword match.

Arnd

#18 lore raw

Re: [PATCH 10/17] RISC-V: Atomic and Locking Code

In reply to Palmer Dabbelt

On Tue, Jul 11, 2017 at 06:31:23PM -0700, Palmer Dabbelt wrote:
[...]

Quoted 45 lines
arch/riscv/include/asm/bitops.h new file +39 -0
new file mode 100644
index 000000000000..b0a0c76e966a
@@ -0,0 +1,216 @@
+/*
+ * 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_BITOPS_H
+#define _ASM_RISCV_BITOPS_H
+
+#ifndef _LINUX_BITOPS_H
+#error "Only <linux/bitops.h> can be included directly"
+#endif /* _LINUX_BITOPS_H */
+
+#include <linux/compiler.h>
+#include <linux/irqflags.h>
+#include <asm/barrier.h>
+#include <asm/bitsperlong.h>
+
+#ifndef smp_mb__before_clear_bit
+#define smp_mb__before_clear_bit()  smp_mb()
+#define smp_mb__after_clear_bit()   smp_mb()
+#endif /* smp_mb__before_clear_bit */
+
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/ffs.h>
+

arch/riscv/include/asm/bitops.h line 49

Quoted 10 lines
arch/riscv/include/asm/bitops.h new file +10 -0
+#include <asm-generic/bitops/hweight.h>
+
+#if (BITS_PER_LONG == 64)
+#define __AMO(op)	"amo" #op ".d"
+#elif (BITS_PER_LONG == 32)
+#define __AMO(op)	"amo" #op ".w"
+#else
+#error "Unexpected BITS_PER_LONG"
+#endif
+

So the test_and_{set,change,clear}_bit() have the similar semantics as cmpxchg(), so

arch/riscv/include/asm/bitops.h line 55

Quoted 6 lines
arch/riscv/include/asm/bitops.h new file +6 -0
+#define __test_and_op_bit(op, mod, nr, addr)			\
+({								\
+	unsigned long __res, __mask;				\
+	__mask = BIT_MASK(nr);					\
+	__asm__ __volatile__ (					\
+		__AMO(op) " %0, %2, %1"				\

... "aqrl" bit is needed here, and

arch/riscv/include/asm/bitops.h line 57

Quoted 2 lines
arch/riscv/include/asm/bitops.h new file +2 -0
+		: "=r" (__res), "+A" (addr[BIT_WORD(nr)])	\
+		: "r" (mod(__mask)));				\

... "memory" clobber is needed here.

Quoted 50 lines
arch/riscv/include/asm/bitops.h new file +50 -0
+	((__res & __mask) != 0);				\
+})
+
+#define __op_bit(op, mod, nr, addr)				\
+	__asm__ __volatile__ (					\
+		__AMO(op) " zero, %1, %0"			\
+		: "+A" (addr[BIT_WORD(nr)])			\
+		: "r" (mod(BIT_MASK(nr))))
+
+/* Bitmask modifiers */
+#define __NOP(x)	(x)
+#define __NOT(x)	(~(x))
+
+/**
+ * test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It may be reordered on other architectures than x86.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+	return __test_and_op_bit(or, __NOP, nr, addr);
+}
+
+/**
+ * test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It can be reordered on other architectures other than x86.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
+{
+	return __test_and_op_bit(and, __NOT, nr, addr);
+}
+
+/**
+ * test_and_change_bit - Change a bit and return its old value
+ * @nr: Bit to change
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_change_bit(int nr, volatile unsigned long *addr)

arch/riscv/include/asm/bitops.h line 117

Quoted 10 lines
arch/riscv/include/asm/bitops.h new file +10 -0
+{
+	return __test_and_op_bit(xor, __NOP, nr, addr);
+}
+
+/**
+ * set_bit - Atomically set a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This function is atomic and may not be reordered.  See __set_bit()

This is incorrect, {set,change,clear}_bit() can be reordered, see Documentation/memory-barriers.txt, they are just relaxed atomics. But I think you just copy this from x86 code, so maybe x86 code needs help too, at least claim that's only x86-specific guarantee.

Quoted 46 lines
arch/riscv/include/asm/bitops.h new file +46 -0
+ * if you do not require the atomic guarantees.
+ *
+ * Note: there are no guarantees that this function will not be reordered
+ * on non x86 architectures, so if you are writing portable code,
+ * make sure not to rely on its reordering guarantees.
+ *
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */
+static inline void set_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(or, __NOP, nr, addr);
+}
+
+/**
+ * clear_bit - Clears a bit in memory
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
+ *
+ * clear_bit() is atomic and may not be reordered.  However, it does
+ * not contain a memory barrier, so if it is used for locking purposes,
+ * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
+ * in order to ensure changes are visible on other processors.
+ */
+static inline void clear_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(and, __NOT, nr, addr);
+}
+
+/**
+ * change_bit - Toggle a bit in memory
+ * @nr: Bit to change
+ * @addr: Address to start counting from
+ *
+ * change_bit() is atomic and may not be reordered. It may be
+ * reordered on other architectures than x86.
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */
+static inline void change_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(xor, __NOP, nr, addr);
+}
+
+/**
+ * test_and_set_bit_lock - Set a bit and return its old value, for lock

arch/riscv/include/asm/bitops.h line 173

Quoted 10 lines
arch/riscv/include/asm/bitops.h new file +10 -0
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and provides acquire barrier semantics.
+ * It can be used to implement bit locks.
+ */
+static inline int test_and_set_bit_lock(
+	unsigned long nr, volatile unsigned long *addr)
+{
+	return test_and_set_bit(nr, addr);

If you want, you can open code an "amoor.aq" here, because test_and_set_bit_lock() only needs an acquire barrier.

arch/riscv/include/asm/bitops.h line 185

Quoted 12 lines
arch/riscv/include/asm/bitops.h new file +12 -0
+}
+
+/**
+ * clear_bit_unlock - Clear a bit in memory, for unlock
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This operation is atomic and provides release barrier semantics.
+ */
+static inline void clear_bit_unlock(
+	unsigned long nr, volatile unsigned long *addr)
+{

You need a smp_mb__before_atomic() here, because clear_bit() is only relaxed atomic. And clear_bit_unlock() is a release.

Regards,
Boqun

Quoted 31 lines
arch/riscv/include/asm/bitops.h new file +31 -0
+	clear_bit(nr, addr);
+}
+
+/**
+ * __clear_bit_unlock - Clear a bit in memory, for unlock
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This operation is like clear_bit_unlock, however it is not atomic.
+ * It does provide release barrier semantics so it can be used to unlock
+ * a bit lock, however it would only be used if no other CPU can modify
+ * any bits in the memory until the lock is released (a good example is
+ * if the bit lock itself protects access to the other bits in the word).
+ */
+static inline void __clear_bit_unlock(
+	unsigned long nr, volatile unsigned long *addr)
+{
+	clear_bit(nr, addr);
+}
+
+#undef __test_and_op_bit
+#undef __op_bit
+#undef __NOP
+#undef __NOT
+#undef __AMO
+
+#include <asm-generic/bitops/non-atomic.h>
+#include <asm-generic/bitops/le.h>
+#include <asm-generic/bitops/ext2-atomic.h>
+
+#endif /* _ASM_RISCV_BITOPS_H */

[...]

#19 lore raw

Re: [PATCH 10/17] RISC-V: Atomic and Locking Code

On Wed, Jul 12, 2017 at 08:40:49PM +0800, Boqun Feng wrote:
[...]

Quoted 7 lines
Quoted 6 lines

+/**
+ * set_bit - Atomically set a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This function is atomic and may not be reordered. See __set_bit()

Quoted 11 lines

This is incorrect, {set,change,clear}_bit() can be reordered, see Documentation/memory-barriers.txt, they are just relaxed atomics. But I think you just copy this from x86 code, so maybe x86 code needs help too, at least claim that's only x86-specific guarantee.

Quoted 6 lines

+ * if you do not require the atomic guarantees.
+ *
+ * Note: there are no guarantees that this function will not be reordered
+ * on non x86 architectures, so if you are writing portable code,
+ * make sure not to rely on its reordering guarantees.
+ *

Hmmm.. the claim is right here ;-/

As your implementation is relax semantics, you'd better rewrite the comment ;-)

Regards,
Boqun

maintainer
#20 lore raw

Re: [PATCH 10/17] RISC-V: Atomic and Locking Code

In reply to Boqun Feng
Quoted 11 lines · Boqun Feng
Quoted 6 lines

+/**
+ * set_bit - Atomically set a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This function is atomic and may not be reordered. See __set_bit()

This is incorrect, {set,change,clear}_bit() can be reordered, see Documentation/memory-barriers.txt, they are just relaxed atomics. But I think you just copy this from x86 code, so maybe x86 code needs help too, at least claim that's only x86-specific guarantee.

Yeah, I suspect that's an x86 special (all our atomics are fully ordered).

Quoted 16 lines

arch/riscv/include/asm/bitops.h line 173

Quoted 12 lines
arch/riscv/include/asm/bitops.h new file +12 -0
+/**
+ * test_and_set_bit_lock - Set a bit and return its old value, for lock
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and provides acquire barrier semantics.
+ * It can be used to implement bit locks.
+ */
+static inline int test_and_set_bit_lock(
+	unsigned long nr, volatile unsigned long *addr)
+{
+	return test_and_set_bit(nr, addr);

If you want, you can open code an "amoor.aq" here, because test_and_set_bit_lock() only needs an acquire barrier.

Quoted 15 lines

arch/riscv/include/asm/bitops.h line 185

Quoted 12 lines
arch/riscv/include/asm/bitops.h new file +12 -0
+}
+
+/**
+ * clear_bit_unlock - Clear a bit in memory, for unlock
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This operation is atomic and provides release barrier semantics.
+ */
+static inline void clear_bit_unlock(
+	unsigned long nr, volatile unsigned long *addr)
+{

You need a smp_mb__before_atomic() here, because clear_bit() is only relaxed atomic. And clear_bit_unlock() is a release.

alternatively you can do "amoand.rl".

#22 lore raw

Re: [PATCH 10/17] RISC-V: Atomic and Locking Code

In reply to Palmer Dabbelt

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

Quoted 10 lines · Palmer Dabbelt
arch/riscv/include/asm/io.h new file +10 -0
+/*
+ * FIXME: I'm flip-flopping on whether or not we should keep this or enforce
+ * the ordering with I/O on spinlocks.  The worry is that drivers won't get
+ * this correct, but I also don't want to introduce a fence into the lock code
+ * that otherwise only uses AMOs and LR/SC.   For now I'm leaving this here:
+ * "w,o" is sufficient to ensure that all writes to the device has completed
+ * before the write to the spinlock is allowed to commit.  I surmised this from
+ * reading "ACQUIRES VS I/O ACCESSES" in memory-barriers.txt.
+ */
+#define mmiowb()       __asm__ __volatile__ ("fence o,w" : : : "memory");

Not sure if this has been discussed before, but have you considered doing it like powerpc with a per-cpu flag that gets checked by spin_unlock()?

Quoted 15 lines
arch/riscv/include/asm/io.h new file +15 -0
+/*
+ * Relaxed I/O memory access primitives. These follow the Device memory
+ * ordering rules but do not guarantee any ordering relative to Normal memory
+ * accesses.  The memory barriers here are necessary as RISC-V doesn't define
+ * any ordering constraints on accesses to the device I/O space.  These are
+ * defined to order the indicated access (either a read or write) with all
+ * other I/O memory accesses.
+ */
+/*
+ * FIXME: The platform spec will define the default Linux-capable platform to
+ * have some extra IO ordering constraints that will make these fences
+ * unnecessary.
+ */
+#define __iorrmb()     __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iorwmb()     __asm__ __volatile__ ("fence io,o" : : : "memory");

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

Quoted 10 lines
arch/riscv/include/asm/io.h new file +10 -0
+
+#define readb_relaxed(c)       ({ u8  __v = readb_cpu(c); __iorrmb(); __v; })
+#define readw_relaxed(c)       ({ u16 __v = readw_cpu(c); __iorrmb(); __v; })
+#define readl_relaxed(c)       ({ u32 __v = readl_cpu(c); __iorrmb(); __v; })
+#define readq_relaxed(c)       ({ u64 __v = readq_cpu(c); __iorrmb(); __v; })
+
+#define writeb_relaxed(v,c)    ({ __iorwmb(); writeb_cpu((v),(c)); })
+#define writew_relaxed(v,c)    ({ __iorwmb(); writew_cpu((v),(c)); })
+#define writel_relaxed(v,c)    ({ __iorwmb(); writel_cpu((v),(c)); })
+#define writeq_relaxed(v,c)    ({ __iorwmb(); writeq_cpu((v),(c)); })

What are the ordering rules for a write followed by a read? You say that there are no ordering constraints on I/O access at all, but you don't add any barriers between that pair, which is probably the most important to get right.

Also, can you say here why the architecture is defined like this? I'm sure that there have been very careful considerations on what the semantics should be, yet it appears that MMIO access is defined to be so relaxed purely as an optimization that as a consequence leads to much slower I/O than a more typical definition as the operating system has to add much heavier barriers than would otherwise be needed.

Quoted 11 lines
arch/riscv/include/asm/io.h new file +11 -0
+/*
+ * 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.  The memory barriers here are necessary as RISC-V
+ * doesn't define any ordering between the memory space and the I/O space.
+ * They may be stronger than necessary ("i,r" and "w,o" might be sufficient),
+ * but I feel kind of queasy making these weaker in any manner than the relaxed
+ * versions above.
+ */
+#define __iormb()      __asm__ __volatile__ ("fence i,ior" : : : "memory");
+#define __iowmb()      __asm__ __volatile__ ("fence iow,o" : : : "memory");

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

Quoted 10 lines
arch/riscv/include/asm/io.h new file +10 -0
+
+#define readb(c)               ({ u8  __v = readb_cpu(c); __iormb(); __v; })
+#define readw(c)               ({ u16 __v = readw_cpu(c); __iormb(); __v; })
+#define readl(c)               ({ u32 __v = readl_cpu(c); __iormb(); __v; })
+#define readq(c)               ({ u64 __v = readq_cpu(c); __iormb(); __v; })
+
+#define writeb(v,c)            ({ __iowmb(); writeb_cpu((v),(c)); })
+#define writew(v,c)            ({ __iowmb(); writew_cpu((v),(c)); })
+#define writel(v,c)            ({ __iowmb(); writel_cpu((v),(c)); })
+#define writeq(v,c)            ({ __iowmb(); writeq_cpu((v),(c)); })

These look good to me (once the _relaxed version has been clarified, the same question applies here as well). I see that you don't override the PCI I/O space accessors (inb/outb etc), which have even stricter ordering requirements.
I think you also need a barrier after outb/outw/outl to ensure that the write has completed on the bus before anything else happens.

Finally, I think you also need to override the string functions (readsl/writesl/insl/outsl) that are lacking barriers in the asm-generic version.

Arnd

Reviewed-by on v1 2/17
#3 lore raw

Re: [PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

In reply to Palmer Dabbelt
Quoted 8 lines · Palmer Dabbelt

Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pcibios_align_resource and deletes the now obselete ones in a handful of ports.

The only functional change should be that a handful of ports used to export pcibios_fixup_bus. Only some architectures export this, so I just dropped it.

And for architectures that do use the routine in drivers they provide the export. This is the case for x86 and the intel i915 driver.

Quoted 1 line

As I noted with the other PCI patch, these should have addressed Bjorn Helgaas <[email protected]> and [email protected]. You seem to have forgotten to do that this time again.

Provided you address the minor issues below here's a:

Also, FWIW the 2 PCI patches you have are independent and could be split off and merged, but it obviously would make sense to keep them in a series if this is going in for this merge window. If your tree is not being merged in this merge window then at least you could try to get these 2 patches merged into Bjorn or Andrew's tree if its not too late.

This patch however still needs refactoring, and since you will also touch the next PCI patch that as well. Notes below.

Quoted 24 lines
---
 arch/arc/kernel/pcibios.c        | 13 -------------
 arch/arm64/kernel/pci.c          | 17 -----------------
 arch/ia64/pci/pci.c              |  7 -------
 arch/microblaze/pci/pci-common.c |  7 -------
 arch/sparc/kernel/leon_pci.c     |  6 ------
 arch/sparc/kernel/pci.c          | 10 ----------
 arch/sparc/kernel/pcic.c         |  6 ------
 arch/tile/kernel/pci.c           | 10 ----------
 arch/tile/kernel/pci_gx.c        |  9 ---------
 drivers/pci/setup-res.c          | 12 ++++++++++++
 10 files changed, 12 insertions(+), 85 deletions(-)
arch/arc/kernel/pcibios.c +0 -3
index 72e1d73d0bd6..05aba5a7b5d2 100644
@@ -7,16 +7,3 @@
  */
 
 #include <linux/pci.h>
-
-/*
- * We don't have to worry about legacy ISA devices, so nothing to do here

arch/arc/kernel/pcibios.c line 22

Quoted 10 lines
arch/arc/kernel/pcibios.c +0 -10
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}

You've mixed removing pcibios_fixup_bus() in this patch whereas you have another patch which does this removal for you after this. Please split these removals out into that patch.

Quoted 9 lines
arch/arm64/kernel/pci.c +0 -1
index e2b7e4f9cc31..0e2ea1c78542 100644
@@ -22,23 +22,6 @@
 #include <linux/pci-ecam.h>
 #include <linux/slab.h>
 
-/*

arch/arm64/kernel/pci.c line 35

Quoted 10 lines
arch/arm64/kernel/pci.c +0 -10
- * 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
- */

Here is another one.

Quoted 64 lines
arch/arm64/kernel/pci.c +0 -6
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 #ifdef CONFIG_ACPI
 /*
  * Try to assign the IRQ number when probing a new device
arch/ia64/pci/pci.c +0 -7
index 4068bde623dc..f5ec736100ee 100644
@@ -411,13 +411,6 @@ pcibios_disable_device (struct pci_dev *dev)
 		acpi_pci_irq_disable(dev);
 }
 
-resource_size_t
-pcibios_align_resource (void *data, const struct resource *res,
-		        resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 /**
  * ia64_pci_get_legacy_mem - generic legacy mem routine
  * @bus: bus to get legacy memory base address for
arch/microblaze/pci/pci-common.c +0 -7
index 404fb38d06b7..7a332e9f1de0 100644
@@ -829,13 +829,6 @@ EXPORT_SYMBOL(pcibios_fixup_bus);
  * but we want to try to avoid allocating at 0x2900-0x2bff
  * which might have be mirrored at 0x0100-0x03ff..
  */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 int pcibios_add_device(struct pci_dev *dev)
 {
 	dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
arch/sparc/kernel/leon_pci.c +0 -6
index 4371f72ff025..0eafdf3d036d 100644
@@ -94,9 +94,3 @@ void pcibios_fixup_bus(struct pci_bus *pbus)
 		}
 	}
 }
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
arch/sparc/kernel/pci.c +0 -0
index 7eceaa10836f..3f8670c92951 100644

arch/sparc/kernel/pci.c struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm, · line 696

Quoted 7 lines
arch/sparc/kernel/pci.c +0 -4
@@ -690,16 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
 	return bus;
 }
 
-void pcibios_fixup_bus(struct pci_bus *pbus)
-{
-}
-

And another one.

Luis

Quoted 94 lines
arch/sparc/kernel/pci.c +0 -6
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
arch/sparc/kernel/pcic.c +0 -6
index a38787b84322..e038e343f2c1 100644
@@ -746,12 +746,6 @@ static void watchdog_reset() {
 }
 #endif
 
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *pdev, int mask)
 {
 	return 0;
arch/tile/kernel/pci.c +0 -10
index bc6656b5708b..284ed23b3914 100644
@@ -67,16 +67,6 @@ static struct pci_ops tile_cfg_ops;
 
 
 /*
- * We don't need to worry about the alignment of resources.
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-			    resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
-/*
  * Open a FD to the hypervisor PCI device.
  *
  * controller_id is the controller number, config type is 0 or 1 for
arch/tile/kernel/pci_gx.c +0 -9
index b554a68eea1b..bdc623b91f7a 100644
@@ -108,15 +108,6 @@ static struct pci_ops tile_cfg_ops;
 /* Mask of CPUs that should receive PCIe interrupts. */
 static struct cpumask intr_cpus_map;
 
-/* We don't need to worry about the alignment of resources. */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				       resource_size_t size,
-				       resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 /*
  * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #.
  * For now, we simply send interrupts to non-dataplane CPUs.
drivers/pci/setup-res.c +12 -0
index 85774b7a316a..597ed1f8b15c 100644
@@ -234,6 +234,18 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,
 	return 0;
 }
 
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here.
+ * This is marked as __weak because multiple architectures define it, it should
+ * eventually go away.
+ */
+__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;
+}
+
 static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
 		int resno, resource_size_t size, resource_size_t align)
 {
Signature · 1 line
2.13.0
Signature · 2 lines
Luis Rodriguez, SUSE LINUX GmbH
Maxfeldstrasse 5; D-90409 Nuernberg
#39 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann
Quoted 5 lines · Palmer Dabbelt

At this point I'm not really sure how to proceed: reviews have calmed down quite a bit over the last two weeks, but I'm not familiar with the Linux development process enough to know how to get closer to upstream. Is this ready for inclusion into another tree? If so, is linux-next the right tree to work off of?

For the pci patch, ask Bjorn if he has a preference whether he wants to merge the patch or have you put it into your tree with his 'Acked-by' tag.

There is one pending issue with these patches, but other than the above possibility the other one is to see if Bjorn is OK for these 2 PCI patches to go through Andrew's tree for the current merge window with his Acked-by.

Quoted 9 lines
Quoted 8 lines

Of course, if anyone has outstanding code reviews then feel free to submit them either to this patch set or a previous one (v5 is essentially the same, and v4 is mostly some small SMP fixes). I don't want to rush anyone by re-submitting so quickly, it's just that my usual protocol has been sped up.

As usual, the patch set has been posted to our Git Hub page

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

Quoted 7 lines

There are a couple of downsides to hosting the git tree on github, so as you get nearer to inclusion, you should decide whether to have your own git server on riscv.org or sifive.com, or to get an account on kernel.org.

You should also make sure you get your gpg key signed by other kernel maintainers so you can properly sign git tags for pull requests.

I've met Palmer in person, and at the sifive offices and signed his key. Recently Chris Metcalf <[email protected]> also signed his key.

Indeed a kernel.org tree would be nicer, Palmer have you requested an account yet?

Luis

#11 lore raw

Re: [patches] Re: [PATCH 04/17] MAINTAINERS: Add RISC-V

In reply to Arnd Bergmann
Quoted 2 lines · Arnd Bergmann
Quoted 1 line · James Hogan

On Tue, Jul 11, 2017 at 06:31:17PM -0700, Palmer Dabbelt wrote:

[...]

Quoted 22 lines
Quoted 13 lines

MAINTAINERS M: Maxim Levitsky <[email protected]> · line 11255

Quoted 7 lines
MAINTAINERS +7 -0
+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/

Should this include other tightly riscv specific drivers outside of arch/riscv/ (or maybe they should have their own MAINTAINERS entries if they aren't so tightly bound to the architecture or are maintained separately)?

Quoted 6 lines

drivers/clocksource/riscv_timer.c
drivers/irqchip/irq-riscv-intc.c
drivers/irqchip/irq-riscv-plic.c
drivers/tty/hvc/hvc_sbi.c
include/linux/timer_riscv.h

I would suggest including a

Quoted 7 lines

K: riscv

keyword line that should catch the closely related drivers, and have separate entries for the rest. Maybe rename the hvc_sbi file to fall within that keyword match.

Arnd

All good suggestions. Palmer, would you mind to take this patch from here, to reduce the communication overhead? (Besides, you know better than I what to include, anyway)

Jonathan

author maintainer
#30 lore raw

Re: [PATCH 16/17] RISC-V: User-facing API

In reply to James Hogan
Quoted 21 lines · On Wed, 12 Jul 2017 04:07:51 PDT (-0700), [email protected] wrote:
Quoted 20 lines · Palmer Dabbelt
arch/riscv/include/asm/unistd.h new file +14 -0
new file mode 100644
index 000000000000..9f250ed007cd
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+#define __ARCH_HAVE_MMU
Quoted 8 lines

arch/riscv/include/asm/unistd.h line 16

Quoted 2 lines
arch/riscv/include/asm/unistd.h new file +2 -0
+#define __ARCH_WANT_SYS_CLONE
+#include <uapi/asm/unistd.h>

It might be worth keeping arch/risc/include/uapi/asm/unistd.h around, even if it only includes asm-generic/unistd.h, as it'll only get added again the next time a syscall is deprecated from the default list in order to add the appropriate __ARCH_WANT_RENAMEAT-like define, but yeh no big deal.

That makes sense, but since it's gone I'll juts add it later -- I figure it's always better to have less code when possible :).

Quoted 52 lines
Quoted 21 lines
arch/riscv/kernel/ptrace.c new file +13 -0
new file mode 100644
index 000000000000..ba3e80712797
@@ -0,0 +1,125 @@
 
+static int riscv_gpr_get(struct task_struct *target,
+			 const struct user_regset *regset,
+			 unsigned int pos, unsigned int count,
+			 void *kbuf, void __user *ubuf)
+{
+	struct pt_regs *regs;
+
+	regs = task_pt_regs(target);
+	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, regs, 0, -1);
+}
+
+static int riscv_gpr_set(struct task_struct *target,
+			 const struct user_regset *regset,

arch/riscv/kernel/ptrace.c line 55

Quoted 10 lines
arch/riscv/kernel/ptrace.c new file +10 -0
+			 unsigned int pos, unsigned int count,
+			 const void *kbuf, const void __user *ubuf)
+{
+	int ret;
+	struct pt_regs *regs;
+
+	regs = task_pt_regs(target);
+	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &regs, 0, -1);
+	return ret;
+}

This is looking much safer now (the caller at least seems to always check pos + count is in range).

Quoted 17 lines
arch/riscv/kernel/signal.c new file +10 -0
new file mode 100644
index 000000000000..e0a1b89583ef
@@ -0,0 +1,289 @@
 
+static long setup_sigcontext(struct rt_sigframe __user *frame,
+	struct pt_regs *regs)
+{
+	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
+	long err;
+	size_t i;
+	/* sc_regs is structured the same as the start of pt_regs */
+	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
+	/* Save the floating-point state. */
+	err |= save_d_state(regs, &sc->sc_fpregs.d);
Quoted 8 lines

arch/riscv/kernel/signal.c line 134

Quoted 3 lines
arch/riscv/kernel/signal.c new file +3 -0
+	/* We support no other extension state at this time. */
+	for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
+		err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]);

How should userland determine how to interpret sc_fpregs? It looks like you couldn't add f or q state without using one of these reserved fields, so why not just specify a field up front to say which fp format (if any) to interpret?

We considered that, but didn't want to tie ourserves to an extension mechanism right now because we don't know what the vector extension is going to look like.

Quoted 3 lines

That would allow userland wanting to interpret it to safely check that field in a forward and backward compatible way without assuming a specific format is in use.

We set ELF_HWCAP (which percolates to userspace via the auxvec. This contains the entire set of extensions the kernel supports on the current machine, which allows userspace to figure out what the format of the floating-point state is.

#31 lore raw

Re: [PATCH 16/17] RISC-V: User-facing API

Quoted 32 lines · Palmer Dabbelt
Quoted 18 lines · On Wed, 12 Jul 2017 04:07:51 PDT (-0700), [email protected] wrote:
Quoted 17 lines · Palmer Dabbelt
arch/riscv/kernel/signal.c new file +10 -0
new file mode 100644
index 000000000000..e0a1b89583ef
@@ -0,0 +1,289 @@
 
+static long setup_sigcontext(struct rt_sigframe __user *frame,
+	struct pt_regs *regs)
+{
+	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
+	long err;
+	size_t i;
+	/* sc_regs is structured the same as the start of pt_regs */
+	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
+	/* Save the floating-point state. */
+	err |= save_d_state(regs, &sc->sc_fpregs.d);
Quoted 8 lines

arch/riscv/kernel/signal.c line 134

Quoted 3 lines
arch/riscv/kernel/signal.c new file +3 -0
+	/* We support no other extension state at this time. */
+	for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
+		err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]);

How should userland determine how to interpret sc_fpregs? It looks like you couldn't add f or q state without using one of these reserved fields, so why not just specify a field up front to say which fp format (if any) to interpret?

We considered that, but didn't want to tie ourserves to an extension mechanism right now because we don't know what the vector extension is going to look like.

Quoted 7 lines
Quoted 3 lines

That would allow userland wanting to interpret it to safely check that field in a forward and backward compatible way without assuming a specific format is in use.

We set ELF_HWCAP (which percolates to userspace via the auxvec. This contains the entire set of extensions the kernel supports on the current machine, which allows userspace to figure out what the format of the floating-point state is.

But then (as far as I understand it) software written now could break once support for that extension is made available and the format suddenly changes (or to avoid that breakage you may need to split up vector values, which is not what the current union describes). Wouldn't it be better to define it now in such a way that you hopefully don't need to worry about such ABI breakage in future?

E.g. does it make sense to have the fp state as an fcsr and an array of 32 unions, each of which can contain a 32bit, 64-bit, or 128-bit quantity. That assumes the vector state aliases the FP state, such that an FP program on a kernel with vector extensions continues to work, but a program using vector extensions can use the same sigcontext sensibly.

Thats how the MIPS SIMD Architecture (MSA) would ideally have worked, but there wasn't space in the fpregs fields, so the upper 64-bits of each vector register needed to be added separately in the sigcontext as an extension, but the lower 64-bits (aliasing FP state) remaining in the fpregs array.

Alternatively if even larger vector extensions are expected it might make sense to abstract further and specify the stride between fp registers as another field so it can be made larger in future without breaking software that properly uses the stride, but admitedly that adds complexity.

Cheers
James

author maintainer
#21 lore raw

Re: [PATCH 10/17] RISC-V: Atomic and Locking Code

In reply to Boqun Feng
Quoted 132 lines · On Wed, 12 Jul 2017 05:40:49 PDT (-0700), [email protected] wrote:

On Tue, Jul 11, 2017 at 06:31:23PM -0700, Palmer Dabbelt wrote:
[...]

Quoted 45 lines
arch/riscv/include/asm/bitops.h new file +39 -0
new file mode 100644
index 000000000000..b0a0c76e966a
@@ -0,0 +1,216 @@
+/*
+ * 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_BITOPS_H
+#define _ASM_RISCV_BITOPS_H
+
+#ifndef _LINUX_BITOPS_H
+#error "Only <linux/bitops.h> can be included directly"
+#endif /* _LINUX_BITOPS_H */
+
+#include <linux/compiler.h>
+#include <linux/irqflags.h>
+#include <asm/barrier.h>
+#include <asm/bitsperlong.h>
+
+#ifndef smp_mb__before_clear_bit
+#define smp_mb__before_clear_bit()  smp_mb()
+#define smp_mb__after_clear_bit()   smp_mb()
+#endif /* smp_mb__before_clear_bit */
+
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/ffs.h>
+

arch/riscv/include/asm/bitops.h line 49

Quoted 10 lines
arch/riscv/include/asm/bitops.h new file +10 -0
+#include <asm-generic/bitops/hweight.h>
+
+#if (BITS_PER_LONG == 64)
+#define __AMO(op)	"amo" #op ".d"
+#elif (BITS_PER_LONG == 32)
+#define __AMO(op)	"amo" #op ".w"
+#else
+#error "Unexpected BITS_PER_LONG"
+#endif
+

So the test_and_{set,change,clear}_bit() have the similar semantics as cmpxchg(), so

arch/riscv/include/asm/bitops.h line 55

Quoted 6 lines
arch/riscv/include/asm/bitops.h new file +6 -0
+#define __test_and_op_bit(op, mod, nr, addr)			\
+({								\
+	unsigned long __res, __mask;				\
+	__mask = BIT_MASK(nr);					\
+	__asm__ __volatile__ (					\
+		__AMO(op) " %0, %2, %1"				\

... "aqrl" bit is needed here, and

arch/riscv/include/asm/bitops.h line 57

Quoted 2 lines
arch/riscv/include/asm/bitops.h new file +2 -0
+		: "=r" (__res), "+A" (addr[BIT_WORD(nr)])	\
+		: "r" (mod(__mask)));				\

... "memory" clobber is needed here.

Quoted 57 lines
arch/riscv/include/asm/bitops.h new file +57 -0
+	((__res & __mask) != 0);				\
+})
+
+#define __op_bit(op, mod, nr, addr)				\
+	__asm__ __volatile__ (					\
+		__AMO(op) " zero, %1, %0"			\
+		: "+A" (addr[BIT_WORD(nr)])			\
+		: "r" (mod(BIT_MASK(nr))))
+
+/* Bitmask modifiers */
+#define __NOP(x)	(x)
+#define __NOT(x)	(~(x))
+
+/**
+ * test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It may be reordered on other architectures than x86.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+	return __test_and_op_bit(or, __NOP, nr, addr);
+}
+
+/**
+ * test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It can be reordered on other architectures other than x86.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
+{
+	return __test_and_op_bit(and, __NOT, nr, addr);
+}
+
+/**
+ * test_and_change_bit - Change a bit and return its old value
+ * @nr: Bit to change
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It also implies a memory barrier.
+ */
+static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
+{
+	return __test_and_op_bit(xor, __NOP, nr, addr);
+}
+
+/**
+ * set_bit - Atomically set a bit in memory
+ * @nr: the bit to set
Quoted 8 lines

arch/riscv/include/asm/bitops.h line 117

Quoted 3 lines
arch/riscv/include/asm/bitops.h new file +3 -0
+ * @addr: the address to start counting from
+ *
+ * This function is atomic and may not be reordered.  See __set_bit()

This is incorrect, {set,change,clear}_bit() can be reordered, see Documentation/memory-barriers.txt, they are just relaxed atomics. But I think you just copy this from x86 code, so maybe x86 code needs help too, at least claim that's only x86-specific guarantee.

I went ahead and fixed our comments.

https://github.com/riscv/riscv-linux/commit/38d727b99b9eb76fac533cebc23f89d364b7d60d

Quoted 61 lines
Quoted 47 lines
arch/riscv/include/asm/bitops.h new file +46 -0
+ * if you do not require the atomic guarantees.
+ *
+ * Note: there are no guarantees that this function will not be reordered
+ * on non x86 architectures, so if you are writing portable code,
+ * make sure not to rely on its reordering guarantees.
+ *
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */
+static inline void set_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(or, __NOP, nr, addr);
+}
+
+/**
+ * clear_bit - Clears a bit in memory
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
+ *
+ * clear_bit() is atomic and may not be reordered.  However, it does
+ * not contain a memory barrier, so if it is used for locking purposes,
+ * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
+ * in order to ensure changes are visible on other processors.
+ */
+static inline void clear_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(and, __NOT, nr, addr);
+}
+
+/**
+ * change_bit - Toggle a bit in memory
+ * @nr: Bit to change
+ * @addr: Address to start counting from
+ *
+ * change_bit() is atomic and may not be reordered. It may be
+ * reordered on other architectures than x86.
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */
+static inline void change_bit(int nr, volatile unsigned long *addr)
+{
+	__op_bit(xor, __NOP, nr, addr);
+}
+
+/**
+ * test_and_set_bit_lock - Set a bit and return its old value, for lock

arch/riscv/include/asm/bitops.h line 173

Quoted 10 lines
arch/riscv/include/asm/bitops.h new file +10 -0
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is atomic and provides acquire barrier semantics.
+ * It can be used to implement bit locks.
+ */
+static inline int test_and_set_bit_lock(
+	unsigned long nr, volatile unsigned long *addr)
+{
+	return test_and_set_bit(nr, addr);

If you want, you can open code an "amoor.aq" here, because test_and_set_bit_lock() only needs an acquire barrier.

Quoted 15 lines

arch/riscv/include/asm/bitops.h line 185

Quoted 12 lines
arch/riscv/include/asm/bitops.h new file +12 -0
+}
+
+/**
+ * clear_bit_unlock - Clear a bit in memory, for unlock
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * This operation is atomic and provides release barrier semantics.
+ */
+static inline void clear_bit_unlock(
+	unsigned long nr, volatile unsigned long *addr)
+{

You need a smp_mb__before_atomic() here, because clear_bit() is only relaxed atomic. And clear_bit_unlock() is a release.

Makes sense. I went ahead and added the aq and rl bits to the AMOs already in these two:

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

#40 lore raw
In reply to Arnd Bergmann
Quoted 40 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt

While it's only been a day since the last patch set (which might be a bit fast), I've generally been spinning new patch sets whenever I get through my inbox. For my other patch sets I've managed to get buried in a week's worth of email in a few hours, but for this one it appears there's been significantly less feedback so I've managed to get through everything. I'm hoping that's a good sign: either I've started to figure out what I'm doing or the code has gotten better -- hopefully it doesn't mean everyone else has given up :).

I don't seem have received the last few versions, but I did get this one, good to see the progress!

A few general notes for the next version:

- please always include the patch version in the subject for each patch, as 'git format-patch -v 7' will do.

- In the introductory mail, list the entire history since v1 if you can reconstruct it. I'm pretty lost now keeping track of earlier versions and what has changed compared to this one, so I'd have to start reviewing from scratch.

Quoted 4 lines

As it's been only a day, the changes are pretty minimal:

* The patch set is now based on linux-next/master, which I believe is a better base now that we're getting closer to upstream.

It's not entirely clear though. Until the end of the merge window, this is fine, as stuff in linux-next today is likely to end up in 4.13-rc1 on Sunday. However, once -rc1 is out, you should base your patches on that to get a bisectable patch series once it is merged. If there are conflicts or dependencies on other trees that get scheduled for 4.14, we have to see how to resolve them one at a time.

Quoted 5 lines

At this point I'm not really sure how to proceed: reviews have calmed down quite a bit over the last two weeks, but I'm not familiar with the Linux development process enough to know how to get closer to upstream. Is this ready for inclusion into another tree? If so, is linux-next the right tree to work off of?

Quoted 3 lines

Without having looked at the current state of the patch series, I would guess that next week is a good time to ask for inclusion *in* linux-next, while continuing the review.

My only concern about getting this into -next is that is sets expectations that this is going to land in the next merge window, but we're unable to review much of the atomics, barriers and locking code because the architecture document is being rewritten and is not yet available:

https://marc.info/?i=8709419e3d964b86b025bb35a6b55440%40HQMAIL105.nvidia.com

Will

#41 lore raw
Quoted 6 lines · Will Deacon
Quoted 4 lines · Arnd Bergmann

On Wed, Jul 12, 2017 at 3:31 AM, Palmer Dabbelt <[email protected]> wrote:
Without having looked at the current state of the patch series, I would guess that next week is a good time to ask for inclusion *in* linux-next, while continuing the review.

Quoted 6 lines

My only concern about getting this into -next is that is sets expectations that this is going to land in the next merge window, but we're unable to review much of the atomics, barriers and locking code because the architecture document is being rewritten and is not yet available:

https://marc.info/?i=8709419e3d964b86b025bb35a6b55440%40HQMAIL105.nvidia.com

I don't see that as a show-stopper for the merge: yes, the kernel port will need to conform to the architecture once we know what it is, but overall, this seems like a detail that can easily be fixed after the merge as no ABI is involved.

The worst case here is that the initial release is a bit unstable, slow or both and this will get fixed later. I would expect this to be the case even if the atomics are all correct ;-)

Arnd

#4 lore raw

Re: [PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

In reply to Palmer Dabbelt
Quoted 10 lines · Palmer Dabbelt

Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pcibios_align_resource and deletes the now obselete ones in a handful of ports.

The only functional change should be that a handful of ports used to export pcibios_fixup_bus. Only some architectures export this, so I just dropped it.

Quoted 12 lines
---
 arch/arc/kernel/pcibios.c        | 13 -------------
 arch/arm64/kernel/pci.c          | 17 -----------------
 arch/ia64/pci/pci.c              |  7 -------
 arch/microblaze/pci/pci-common.c |  7 -------
 arch/sparc/kernel/leon_pci.c     |  6 ------
 arch/sparc/kernel/pci.c          | 10 ----------
 arch/sparc/kernel/pcic.c         |  6 ------
 arch/tile/kernel/pci.c           | 10 ----------
 arch/tile/kernel/pci_gx.c        |  9 ---------
 drivers/pci/setup-res.c          | 12 ++++++++++++
 10 files changed, 12 insertions(+), 85 deletions(-)

I think you're making your life harder by including these cleanup patches in your RISC-V support. This patch makes sense (after sorting out the issues Luis pointed out), but I think the simplest thing to expedite merging is to add the empty stubs for RISC-V like everybody else does, then come back after RISC-V gets merged and do the cleanup. Then the cleanup clearly goes via the PCI tree and isn't entangled with anything else.

Bjorn

Quoted 204 lines
arch/arc/kernel/pcibios.c +0 -13
index 72e1d73d0bd6..05aba5a7b5d2 100644
@@ -7,16 +7,3 @@
  */
 
 #include <linux/pci.h>
-
-/*
- * 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;
-}
-
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
arch/arm64/kernel/pci.c +0 -17
index e2b7e4f9cc31..0e2ea1c78542 100644
@@ -22,23 +22,6 @@
 #include <linux/pci-ecam.h>
 #include <linux/slab.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;
-}
-
 #ifdef CONFIG_ACPI
 /*
  * Try to assign the IRQ number when probing a new device
arch/ia64/pci/pci.c +0 -7
index 4068bde623dc..f5ec736100ee 100644
@@ -411,13 +411,6 @@ pcibios_disable_device (struct pci_dev *dev)
 		acpi_pci_irq_disable(dev);
 }
 
-resource_size_t
-pcibios_align_resource (void *data, const struct resource *res,
-		        resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 /**
  * ia64_pci_get_legacy_mem - generic legacy mem routine
  * @bus: bus to get legacy memory base address for
arch/microblaze/pci/pci-common.c +0 -7
index 404fb38d06b7..7a332e9f1de0 100644
@@ -829,13 +829,6 @@ EXPORT_SYMBOL(pcibios_fixup_bus);
  * but we want to try to avoid allocating at 0x2900-0x2bff
  * which might have be mirrored at 0x0100-0x03ff..
  */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 int pcibios_add_device(struct pci_dev *dev)
 {
 	dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
arch/sparc/kernel/leon_pci.c +0 -6
index 4371f72ff025..0eafdf3d036d 100644
@@ -94,9 +94,3 @@ void pcibios_fixup_bus(struct pci_bus *pbus)
 		}
 	}
 }
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
arch/sparc/kernel/pci.c +0 -10
index 7eceaa10836f..3f8670c92951 100644
@@ -690,16 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
 	return bus;
 }
 
-void pcibios_fixup_bus(struct pci_bus *pbus)
-{
-}
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
arch/sparc/kernel/pcic.c +0 -6
index a38787b84322..e038e343f2c1 100644
@@ -746,12 +746,6 @@ static void watchdog_reset() {
 }
 #endif
 
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *pdev, int mask)
 {
 	return 0;
arch/tile/kernel/pci.c +0 -10
index bc6656b5708b..284ed23b3914 100644
@@ -67,16 +67,6 @@ static struct pci_ops tile_cfg_ops;
 
 
 /*
- * We don't need to worry about the alignment of resources.
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-			    resource_size_t size, resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
-/*
  * Open a FD to the hypervisor PCI device.
  *
  * controller_id is the controller number, config type is 0 or 1 for
arch/tile/kernel/pci_gx.c +0 -9
index b554a68eea1b..bdc623b91f7a 100644
@@ -108,15 +108,6 @@ static struct pci_ops tile_cfg_ops;
 /* Mask of CPUs that should receive PCIe interrupts. */
 static struct cpumask intr_cpus_map;
 
-/* We don't need to worry about the alignment of resources. */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-				       resource_size_t size,
-				       resource_size_t align)
-{
-	return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 /*
  * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #.
  * For now, we simply send interrupts to non-dataplane CPUs.
drivers/pci/setup-res.c +12 -0
index 85774b7a316a..597ed1f8b15c 100644
@@ -234,6 +234,18 @@ static int pci_revert_fw_address(struct resource *res, struct pci_dev *dev,
 	return 0;
 }
 
+/*
+ * We don't have to worry about legacy ISA devices, so nothing to do here.
+ * This is marked as __weak because multiple architectures define it, it should
+ * eventually go away.
+ */
+__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;
+}
+
 static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
 		int resno, resource_size_t size, resource_size_t align)
 {
Signature · 1 line
2.13.0
author maintainer
#5 lore raw

Re: [PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

Quoted 24 lines · On Wed, 12 Jul 2017 15:50:42 PDT (-0700), [email protected] wrote:
Quoted 10 lines · Palmer Dabbelt

Multiple architectures define this as trivial function, and I'm adding another one as part of the RISC-V port. This adds a __weak version of pcibios_align_resource and deletes the now obselete ones in a handful of ports.

The only functional change should be that a handful of ports used to export pcibios_fixup_bus. Only some architectures export this, so I just dropped it.

Quoted 12 lines
---
 arch/arc/kernel/pcibios.c        | 13 -------------
 arch/arm64/kernel/pci.c          | 17 -----------------
 arch/ia64/pci/pci.c              |  7 -------
 arch/microblaze/pci/pci-common.c |  7 -------
 arch/sparc/kernel/leon_pci.c     |  6 ------
 arch/sparc/kernel/pci.c          | 10 ----------
 arch/sparc/kernel/pcic.c         |  6 ------
 arch/tile/kernel/pci.c           | 10 ----------
 arch/tile/kernel/pci_gx.c        |  9 ---------
 drivers/pci/setup-res.c          | 12 ++++++++++++
 10 files changed, 12 insertions(+), 85 deletions(-)
Quoted 7 lines

I think you're making your life harder by including these cleanup patches in your RISC-V support. This patch makes sense (after sorting out the issues Luis pointed out), but I think the simplest thing to expedite merging is to add the empty stubs for RISC-V like everybody else does, then come back after RISC-V gets merged and do the cleanup. Then the cleanup clearly goes via the PCI tree and isn't entangled with anything else.

Works for me.

author maintainer
#32 lore raw

Re: [PATCH 16/17] RISC-V: User-facing API

In reply to James Hogan
Quoted 48 lines · On Wed, 12 Jul 2017 10:09:55 PDT (-0700), [email protected] wrote:
Quoted 32 lines · Palmer Dabbelt
Quoted 18 lines · On Wed, 12 Jul 2017 04:07:51 PDT (-0700), [email protected] wrote:
Quoted 17 lines · Palmer Dabbelt
arch/riscv/kernel/signal.c new file +10 -0
new file mode 100644
index 000000000000..e0a1b89583ef
@@ -0,0 +1,289 @@
 
+static long setup_sigcontext(struct rt_sigframe __user *frame,
+	struct pt_regs *regs)
+{
+	struct sigcontext __user *sc = &frame->uc.uc_mcontext;
+	long err;
+	size_t i;
+	/* sc_regs is structured the same as the start of pt_regs */
+	err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
+	/* Save the floating-point state. */
+	err |= save_d_state(regs, &sc->sc_fpregs.d);
Quoted 8 lines

arch/riscv/kernel/signal.c line 134

Quoted 3 lines
arch/riscv/kernel/signal.c new file +3 -0
+	/* We support no other extension state at this time. */
+	for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
+		err |= __put_user(0, &sc->sc_fpregs.q.reserved[i]);

How should userland determine how to interpret sc_fpregs? It looks like you couldn't add f or q state without using one of these reserved fields, so why not just specify a field up front to say which fp format (if any) to interpret?

We considered that, but didn't want to tie ourserves to an extension mechanism right now because we don't know what the vector extension is going to look like.

Quoted 7 lines
Quoted 3 lines

That would allow userland wanting to interpret it to safely check that field in a forward and backward compatible way without assuming a specific format is in use.

We set ELF_HWCAP (which percolates to userspace via the auxvec. This contains the entire set of extensions the kernel supports on the current machine, which allows userspace to figure out what the format of the floating-point state is.

But then (as far as I understand it) software written now could break once support for that extension is made available and the format suddenly changes (or to avoid that breakage you may need to split up vector values, which is not what the current union describes). Wouldn't it be better to define it now in such a way that you hopefully don't need to worry about such ABI breakage in future?

Quoted 5 lines

E.g. does it make sense to have the fp state as an fcsr and an array of 32 unions, each of which can contain a 32bit, 64-bit, or 128-bit quantity. That assumes the vector state aliases the FP state, such that an FP program on a kernel with vector extensions continues to work, but a program using vector extensions can use the same sigcontext sensibly.

We considered the strided vesion, but it imposes a cost on the common case:
extra cache lines will be pulled in on D systems.

Quoted 11 lines

Thats how the MIPS SIMD Architecture (MSA) would ideally have worked, but there wasn't space in the fpregs fields, so the upper 64-bits of each vector register needed to be added separately in the sigcontext as an extension, but the lower 64-bits (aliasing FP state) remaining in the fpregs array.

Alternatively if even larger vector extensions are expected it might make sense to abstract further and specify the stride between fp registers as another field so it can be made larger in future without breaking software that properly uses the stride, but admitedly that adds complexity.

The V extension won't alias with the state of the F, D, and Q extensions (which do alias each other). We're planning on adding a whole extra block to the end of sigcontext that contains the V extension state.

#6 lore raw

Re: [PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

In reply to Palmer Dabbelt
url: https://github.com/0day-ci/linux/commits/Palmer-Dabbelt/lib-Add-shared-copies-of-some-GCC-library-routines/20170713-012253 config: arm64-defconfig (attached as .config) compiler…

Hi Palmer,

[auto build test ERROR on linus/master]
[also build test ERROR on next-20170713]
[cannot apply to v4.12]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Palmer-Dabbelt/lib-Add-shared-copies-of-some-GCC-library-routines/20170713-012253
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

Note: the linux-review/Palmer-Dabbelt/lib-Add-shared-copies-of-some-GCC-library-routines/20170713-012253 HEAD ce846a13375e664242eedad789cb6e1c46d5ddd6 builds fine.
It only hurts bisectibility.

All errors (new ones prefixed by >>):

drivers/pci/probe.o: In function `pci_scan_child_bus':

>> drivers/pci/probe.c:2311: undefined reference to `pcibios_fixup_bus'

drivers/pci/probe.c:2311:(.text+0x2ffc): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `pcibios_fixup_bus'

vim +2311 drivers/pci/probe.c

b03e7495a Jon Mason      2011-07-20  2290  
15856ad50 Bill Pemberton 2012-11-21  2291  unsigned int pci_scan_child_bus(struct pci_bus *bus)
^1da177e4 Linus Torvalds 2005-04-16  2292  {
b918c62e0 Yinghai Lu     2012-05-17  2293  	unsigned int devfn, pass, max = bus->busn_res.start;
^1da177e4 Linus Torvalds 2005-04-16  2294  	struct pci_dev *dev;
^1da177e4 Linus Torvalds 2005-04-16  2295  
0207c356e Bjorn Helgaas  2009-11-04  2296  	dev_dbg(&bus->dev, "scanning bus\n");
^1da177e4 Linus Torvalds 2005-04-16  2297  
^1da177e4 Linus Torvalds 2005-04-16  2298  	/* Go find them, Rover! */
^1da177e4 Linus Torvalds 2005-04-16  2299  	for (devfn = 0; devfn < 0x100; devfn += 8)
^1da177e4 Linus Torvalds 2005-04-16  2300  		pci_scan_slot(bus, devfn);
^1da177e4 Linus Torvalds 2005-04-16  2301  
a28724b0f Yu Zhao        2009-03-20  2302  	/* Reserve buses for SR-IOV capability. */
a28724b0f Yu Zhao        2009-03-20  2303  	max += pci_iov_bus_range(bus);
a28724b0f Yu Zhao        2009-03-20  2304  
^1da177e4 Linus Torvalds 2005-04-16  2305  	/*
^1da177e4 Linus Torvalds 2005-04-16  2306  	 * After performing arch-dependent fixup of the bus, look behind
^1da177e4 Linus Torvalds 2005-04-16  2307  	 * all PCI-to-PCI bridges on this bus.
^1da177e4 Linus Torvalds 2005-04-16  2308  	 */
74710ded8 Alex Chiang    2009-03-20  2309  	if (!bus->is_added) {
0207c356e Bjorn Helgaas  2009-11-04  2310  		dev_dbg(&bus->dev, "fixups for bus\n");
^1da177e4 Linus Torvalds 2005-04-16 @2311  		pcibios_fixup_bus(bus);
74710ded8 Alex Chiang    2009-03-20  2312  		bus->is_added = 1;
74710ded8 Alex Chiang    2009-03-20  2313  	}
74710ded8 Alex Chiang    2009-03-20  2314  
^1da177e4 Linus Torvalds 2005-04-16  2315  	for (pass = 0; pass < 2; pass++)
^1da177e4 Linus Torvalds 2005-04-16  2316  		list_for_each_entry(dev, &bus->devices, bus_list) {
6788a51fe Yijing Wang    2014-05-04  2317  			if (pci_is_bridge(dev))
^1da177e4 Linus Torvalds 2005-04-16  2318  				max = pci_scan_bridge(bus, dev, max, pass);
^1da177e4 Linus Torvalds 2005-04-16  2319  		}
^1da177e4 Linus Torvalds 2005-04-16  2320  
^1da177e4 Linus Torvalds 2005-04-16  2321  	/*
e16b46605 Keith Busch    2016-07-21  2322  	 * Make sure a hotplug bridge has at least the minimum requested
e16b46605 Keith Busch    2016-07-21  2323  	 * number of buses.
e16b46605 Keith Busch    2016-07-21  2324  	 */
e16b46605 Keith Busch    2016-07-21  2325  	if (bus->self && bus->self->is_hotplug_bridge && pci_hotplug_bus_size) {
e16b46605 Keith Busch    2016-07-21  2326  		if (max - bus->busn_res.start < pci_hotplug_bus_size - 1)
e16b46605 Keith Busch    2016-07-21  2327  			max = bus->busn_res.start + pci_hotplug_bus_size - 1;
e16b46605 Keith Busch    2016-07-21  2328  	}
e16b46605 Keith Busch    2016-07-21  2329  
e16b46605 Keith Busch    2016-07-21  2330  	/*
^1da177e4 Linus Torvalds 2005-04-16  2331  	 * We've scanned the bus and so we know all about what's on
^1da177e4 Linus Torvalds 2005-04-16  2332  	 * the other side of any bridges that may be on this bus plus
^1da177e4 Linus Torvalds 2005-04-16  2333  	 * any devices.
^1da177e4 Linus Torvalds 2005-04-16  2334  	 *
^1da177e4 Linus Torvalds 2005-04-16  2335  	 * Return how far we've got finding sub-buses.
^1da177e4 Linus Torvalds 2005-04-16  2336  	 */
0207c356e Bjorn Helgaas  2009-11-04  2337  	dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max);
^1da177e4 Linus Torvalds 2005-04-16  2338  	return max;
^1da177e4 Linus Torvalds 2005-04-16  2339  }
b7fe94342 Ryan Desfosses 2014-04-25  2340  EXPORT_SYMBOL_GPL(pci_scan_child_bus);
^1da177e4 Linus Torvalds 2005-04-16  2341  

:::::: The code at line 2311 was first introduced by commit :::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#34 lore raw

Re: [patches] [PATCH 17/17] RISC-V: Build Infastructure

In reply to Palmer Dabbelt
Quoted 8 lines · Palmer Dabbelt

This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and Kconfig files. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.

---

[...]

arch/riscv/Kconfig line 139

Quoted 2 lines
arch/riscv/Kconfig new file +2 -0
+config ISA_C
+	bool "Emit compressed instructions when building Linux"

As a user, I'd prefer to have slightly more globally-recognisable names than ISA_<single letter> for RISC-V instruction set architecture extensions. A quick "git grep -A2 'config ISA'" shows the following Kconfig symbols:

* ISA, ISA_BUS_API, ISA_DMA_API, ISAPNP:
Settings related to the historic ISA bus.
* ISA_ARCOMPACT/ISA_ARCV2 (arch/arc), ISA_M32R/ISA_M32R2/ISA_DSP_LEVEL2/ISA_DUAL_ISSUE (arch/m32r):
Instruction set options.

Four out of the six instruction set options have ARC/M32R in the name, and I think that makes things slightly more readable. Therefore I humbly propose something longer, and with a hint of RISC-V in the name, such as ISA_RVC.

(Take this with a grain of salt, perhaps.)

Jonathan Neuschäfer

author maintainer
#35 lore raw

Re: [patches] [PATCH 17/17] RISC-V: Build Infastructure

Quoted 24 lines · On Tue, 25 Jul 2017 19:57:17 PDT (-0700), [email protected] wrote:
Quoted 8 lines · Palmer Dabbelt

This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and Kconfig files. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.

---

[...]

arch/riscv/Kconfig line 139

Quoted 2 lines
arch/riscv/Kconfig new file +2 -0
+config ISA_C
+	bool "Emit compressed instructions when building Linux"

As a user, I'd prefer to have slightly more globally-recognisable names than ISA_<single letter> for RISC-V instruction set architecture extensions. A quick "git grep -A2 'config ISA'" shows the following Kconfig symbols:

* ISA, ISA_BUS_API, ISA_DMA_API, ISAPNP:
Settings related to the historic ISA bus.
* ISA_ARCOMPACT/ISA_ARCV2 (arch/arc), ISA_M32R/ISA_M32R2/ISA_DSP_LEVEL2/ISA_DUAL_ISSUE (arch/m32r):
Instruction set options.

Quoted 6 lines

Four out of the six instruction set options have ARC/M32R in the name, and I think that makes things slightly more readable. Therefore I humbly propose something longer, and with a hint of RISC-V in the name, such as ISA_RVC.

(Take this with a grain of salt, perhaps.)

Good timing: I was about to submit a v6 patch set. I'm cool with CONFIG_ISA_RVC and friends, do you mind submitting a patch?

#36 lore raw

Re: [patches] [PATCH 17/17] RISC-V: Build Infastructure

Quoted 14 lines · Palmer Dabbelt
Quoted 13 lines · On Tue, 25 Jul 2017 19:57:17 PDT (-0700), [email protected] wrote:
Quoted 8 lines · Palmer Dabbelt

This patch contains all the build infastructure that actually enables the RISC-V port. This includes Makefiles, linker scripts, and Kconfig files. It also contains the only top-level change, which adds RISC-V to the list of architectures that need a sed run to produce the ARCH variable when building locally.

---

[...]

Quoted 2 lines
arch/riscv/Kconfig new file +2 -0
+config ISA_C
+    bool "Emit compressed instructions when building Linux"
Quoted 7 lines
Quoted 4 lines

As a user, I'd prefer to have slightly more globally-recognisable names than ISA_<single letter> for RISC-V instruction set architecture extensions. A quick "git grep -A2 'config ISA'" shows the following Kconfig symbols:

Good timing: I was about to submit a v6 patch set. I'm cool with CONFIG_ISA_RVC and friends, do you mind submitting a patch?

I'd generally prefix those highly architecture specific ones with the architecture name, e.g. CONFIG_RISCV_ISA_C

Arnd

#37 lore raw

Re: [patches] [PATCH 17/17] RISC-V: Build Infastructure

In reply to Palmer Dabbelt
Quoted 2 lines · Palmer Dabbelt
Quoted 1 line · On Tue, 25 Jul 2017 19:57:17 PDT (-0700), [email protected] wrote:

On Tue, Jul 11, 2017 at 06:31:30PM -0700, Palmer Dabbelt wrote:

[...]

Quoted 19 lines
Quoted 19 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+config ISA_C
+	bool "Emit compressed instructions when building Linux"

As a user, I'd prefer to have slightly more globally-recognisable names than ISA_<single letter> for RISC-V instruction set architecture extensions. A quick "git grep -A2 'config ISA'" shows the following Kconfig symbols:

* ISA, ISA_BUS_API, ISA_DMA_API, ISAPNP:
Settings related to the historic ISA bus.
* ISA_ARCOMPACT/ISA_ARCV2 (arch/arc), ISA_M32R/ISA_M32R2/ISA_DSP_LEVEL2/ISA_DUAL_ISSUE (arch/m32r):
Instruction set options.

Four out of the six instruction set options have ARC/M32R in the name, and I think that makes things slightly more readable. Therefore I humbly propose something longer, and with a hint of RISC-V in the name, such as ISA_RVC.

Quoted 4 lines
Quoted 1 line

(Take this with a grain of salt, perhaps.)

Good timing: I was about to submit a v6 patch set. I'm cool with CONFIG_ISA_RVC and friends, do you mind submitting a patch?

I'm not sure about ISA_A, because as I understand the mails in one of the previous review threads, RVA is now required by Linux, so there shouldn't be a need for CONFIG_ISA_A (or an equivalent option).

CONFIG_RISCV_ISA_C (which Arnd suggested) makes it even clearer that these are RISC-V related options.

Here's my patch, for reference (untested, because I currently don't have a riscv compiler installed):

Subject: [PATCH] RISC-V: Rename CONFIG_ISA_C to CONFIG_ISA_RVC

To make it clearer that ISA_C is a RISC-V related option, rename it to ISA_RVC.

---
 arch/riscv/Kconfig  | 2 +-
 arch/riscv/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/riscv/Kconfig +1 -1
index cc274bbc29a7..8c43e5c73892 100644
@@ -135,7 +135,7 @@ config TUNE_GENERIC
 
 endchoice
 
-config ISA_C
+config ISA_RVC
 	bool "Emit compressed instructions when building Linux"
 	default n
 	help
arch/riscv/Makefile +1 -1
index 66c4a5e383f9..7ac91bcf9fe7 100644
@@ -40,7 +40,7 @@ KBUILD_CFLAGS += -Wall
 ifeq ($(CONFIG_ISA_A),y)
 	KBUILD_ARCH_A = a
 endif
-ifeq ($(CONFIG_ISA_C),y)
+ifeq ($(CONFIG_ISA_RVC),y)
 	KBUILD_ARCH_C = c
 endif
 
Signature · 1 line
2.11.0