RISC-V Linux Port v1
Subsystems (21)
Palmer Dabbelt
maintainerWe'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.
This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.
These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.
Albert and I will volunteer to maintain this port if it's OK with everyone.
We'd like to thank the various members of the RISC-V software community who have helped us with the port.
Thanks!
In addition to the threaded messages, our port can be found on Git Hib
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1
[PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64} [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V: arch/riscv/include
[PATCH 5/7] RISC-V: arch/riscv/lib
[PATCH 6/7] RISC-V: arch/riscv/kernel
[PATCH 7/7] RISC-V: arch/riscv/mm
Palmer Dabbelt
maintainerPATCH 1/7 RISC-V: Top-Level Makefile for riscv{32,64}
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
--- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+)
Makefile +8 -0
@@ -269,6 +269,14 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif +# Additional ARCH settings for RISC-V +ifeq ($(ARCH),riscv32) + SRCARCH := riscv +endif +ifeq ($(ARCH),riscv64) + SRCARCH := riscv +endif + # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparc
Signature · 1 line
2.13.0
Arnd Bergmann
maintainerRe: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
I don't think that does the same thing. The desired effect of this diff is:
* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.
* I can cross compile for riscv32 and riscv64. That's currently controlled by a Kconfig setting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.
* I can natively compile for riscv32 and riscv64. That uses the same Kconfig setting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.
Neither of the two Kconfig issues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do this
Makefile +2 -9
@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/ ) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------
@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif -# Additional ARCH settings for RISC-V -ifeq ($(ARCH),riscv32) - SRCARCH := riscv -endif -ifeq ($(ARCH),riscv64) - SRCARCH := riscv -endif - # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparc
then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.
Arnd Bergmann
maintainerRe: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
I don't think that does the same thing. The desired effect of this diff is:
* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.
Quoted 6 lines
* I can cross compile for riscv32 and riscv64. That's currently controlled by a
Kconfigsetting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.* I can natively compile for riscv32 and riscv64. That uses the same
Kconfigsetting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.
Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.
Quoted 35 lines
Neither of the two
Kconfigissues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do thisMakefile +2
-9@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/ ) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif -# Additional ARCH settings for RISC-V -ifeq ($(ARCH),riscv32) - SRCARCH := riscv -endif -ifeq ($(ARCH),riscv64) - SRCARCH := riscv -endif - # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparc
Quoted 2 lines
then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.
Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on CONFIG_64BIT.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
I don't think that does the same thing. The desired effect of this diff is:
* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.
Quoted 6 lines
* I can cross compile for riscv32 and riscv64. That's currently controlled by a
Kconfigsetting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.* I can natively compile for riscv32 and riscv64. That uses the same
Kconfigsetting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.
Quoted 35 lines
Neither of the two
Kconfigissues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do thisMakefile +2
-9@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/ ) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif -# Additional ARCH settings for RISC-V -ifeq ($(ARCH),riscv32) - SRCARCH := riscv -endif -ifeq ($(ARCH),riscv64) - SRCARCH := riscv -endif - # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparc
Quoted 6 lines
Quoted 2 lines
then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.
Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on
CONFIG_64BIT.
OK, I didn't know about COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.
Re: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 71 lines · Palmer Dabbelt
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
I don't think that does the same thing. The desired effect of this diff is:
* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.
Quoted 6 lines
* I can cross compile for riscv32 and riscv64. That's currently controlled by a
Kconfigsetting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.* I can natively compile for riscv32 and riscv64. That uses the same
Kconfigsetting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.
Quoted 35 lines
Neither of the two
Kconfigissues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do thisMakefile +2
-9@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/ ) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif -# Additional ARCH settings for RISC-V -ifeq ($(ARCH),riscv32) - SRCARCH := riscv -endif -ifeq ($(ARCH),riscv64) - SRCARCH := riscv -endif - # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparcQuoted 6 lines
Quoted 2 lines
then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.
Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on
CONFIG_64BIT.
Quoted 2 lines
OK, I didn't know about
COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.
Hello Palmer,
I suppose the commit:
https://github.com/riscv/riscv-linux/commit/8c826930d2a19ecd4f1036f10a380dc4fddd0da5
aims to address this, but it appears to be incomplete. It lacks the first fragment of the patch above, i.e. the conversion from the "uname -m" output (i.e. "riscv{64,32}") to the canonical arch string (i.e. "riscv"). As a result, a native build (which normally doesn't explicitly pass ARCH=riscv to make and therefore relies on the output of "uname -m") would fail.
Regards,
Karsten
Signature · 3 lines
Gem. Par. 28 Abs. 4 Bundesdatenschutzgesetz widerspreche ich der Nutzung sowie der Weitergabe meiner personenbezogenen Daten für Zwecke der Werbung sowie der Markt- oder Meinungsforschung.
Palmer Dabbelt
maintainerRe: [PATCH 1/7] RISC-V: Top-Level Makefile for riscv{32,64}
Quoted 79 lines · On Tue, 06 Jun 2017 10:39:04 PDT (-0700), [email protected] wrote:
Quoted 71 lines · Palmer Dabbelt
Quoted 63 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
RISC-V has both 32-bit and 64-bit base ISAs, but they are very similar. Like some other platforms, we'd like to share one arch directory between the two of them.
I think we mainly do the others for backwards-compatibility with ancient build scripts, and we don't need that here. Instead, you could add one more line to the 'SUBARCH:=' statement that interprets the uname output.
I don't think that does the same thing. The desired effect of this diff is:
* "uname -m" when running on a RISC-V machine returns either riscv32 or riscv64, as that's what tools like autoconf expect when trying to find tuples.
Quoted 6 lines
* I can cross compile for riscv32 and riscv64. That's currently controlled by a
Kconfigsetting, but ARCH=riscv32 vs ARCH=riscv64 controlls what defconfig sets.* I can natively compile for riscv32 and riscv64. That uses the same
Kconfigsetting, and the same ARCH=riscv32 vs ARCH=riscv64 switch for defconfig.Right, but my point is that a new architecture should not rely on 'ARCH=' to pick the defconfig, we only do that on a couple of architectures for backwards compatibility with old scripts.
Quoted 35 lines
Neither of the two
Kconfigissues is a big deal, but we de need "uname -m" to return "riscv64" or "riscv32" not "riscv". I think the only way to do that is to set SRCARCH, but I'd be happy to change it if there's a better way. I think if I just do thisMakefile +2
-9@@ -232,7 +232,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/ ) # Cross compiling and selecting different set of gcc/bin-utils # ---------------------------------------------------------------------------@@ -269,14 +270,6 @@ ifeq ($(ARCH),x86_64) SRCARCH := x86 endif -# Additional ARCH settings for RISC-V -ifeq ($(ARCH),riscv32) - SRCARCH := riscv -endif -ifeq ($(ARCH),riscv64) - SRCARCH := riscv -endif - # Additional ARCH settings for sparc ifeq ($(ARCH),sparc32) SRCARCH := sparcQuoted 6 lines
Quoted 2 lines
then I'll end up with "uname -m" as "riscv" -- I haven't tried it, but that's why we ended up with this diff in the first place.
Do you mean the "uname -m" output comes from "${SRCARCH}" at the time of the kernel build? That would be easy enough to change by simply hardcoding it depending on
CONFIG_64BIT.Quoted 2 lines
OK, I didn't know about
COMPAT_UTS_MACHINE. That's a much better solution, I'll use that.Hello Palmer,
I suppose the commit:
Quoted 8 lines
https://github.com/riscv/riscv-linux/commit/8c826930d2a19ecd4f1036f10a380dc4fddd0da5
aims to address this, but it appears to be incomplete. It lacks the first fragment of the patch above, i.e. the conversion from the "uname -m" output (i.e. "riscv{64,32}") to the canonical arch string (i.e. "riscv"). As a result, a native build (which normally doesn't explicitly pass ARCH=riscv to make and therefore relies on the output of "uname -m") would fail.
Sorry about that, I dropped the commit. I'm in the middle of bisecting to find a regression, so the patch might now show up for a bit, but it'll be fixed.
Palmer Dabbelt
maintainerPATCH 2/7 RISC-V: arch/riscv Makefile and Kconfigs
In reply to Palmer Dabbelt--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++ 7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spike
arch/riscv/.gitignore new file +35 -0
@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +# +.* +*.o +*.o.* +*.a +*.s +*.ko +*.so +*.so.dbg +*.mod.c +*.i +*.lst +*.symtypes +*.order +modules.builtin +*.elf +*.bin +*.gz +*.bz2 +*.lzma +*.xz +*.lzo +*.patch +*.gcno + +include/generated +kernel/vmlinux.lds + +# Then reinclude .gitignore. +!.gitignore
arch/riscv/Kconfig new file +300 -0
300 lines not on this page · raw message
arch/riscv/Makefile new file +64 -0
64 lines not on this page · raw message
arch/riscv/configs/riscv32_spike new file +47 -0
47 lines not on this page · raw message
arch/riscv/configs/riscv64_freedom-u new file +52 -0
52 lines not on this page · raw message
arch/riscv/configs/riscv64_qemu new file +64 -0
64 lines not on this page · raw message
arch/riscv/configs/riscv64_spike new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Hi,
Quoted 8 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++
Quoted 8 lines
7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spike
Nearly all other platforms have _defconfig in the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example, spike_defconfig, spike64_defconfig, qemu_defconfig, freedom-u_defconfig.
Not going to argue too much about the color of the shed here, but using the _defconfig naming is recommended.
Quoted 26 lines
arch/riscv/.gitignore new file +19
-0@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +# +.* +*.o +*.o.* +*.a +*.s +*.ko +*.so +*.so.dbg +*.mod.c +*.i +*.lst +*.symtypes +*.order
arch/riscv/.gitignore line 29
Quoted 10 lines
arch/riscv/.gitignore new file +10
-0+modules.builtin +*.elf +*.bin +*.gz +*.bz2 +*.lzma +*.xz +*.lzo +*.patch +*.gcno
I don't think you need to do any of this, just inherit the global one (by not having one here)?
arch/riscv/.gitignore line 31
Quoted 2 lines
arch/riscv/.gitignore new file +2
-0+ +include/generated
This is already covered by the global .gitignore.
arch/riscv/.gitignore line 32
Quoted 1 line
arch/riscv/.gitignore new file +1
-0+kernel/vmlinux.lds
And if needed this should be added to the arch/riscv/kernel/.gitignore file instead.
Quoted 105 lines
arch/riscv/Kconfig new file +99
-0@@ -0,0 +1,300 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# + +config RISCV + def_bool y + select OF + select OF_EARLY_FLATTREE + select OF_IRQ + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE + select ARCH_WANT_FRAME_POINTERS + select CLONE_BACKWARDS + select COMMON_CLK + select GENERIC_CLOCKEVENTS + select GENERIC_CPU_DEVICES + select GENERIC_IRQ_SHOW + select GENERIC_PCI_IOMAP + select GENERIC_STRNCPY_FROM_USER + select GENERIC_STRNLEN_USER + select GENERIC_SMP_IDLE_THREAD + select GENERIC_ATOMIC64 if !64BIT || !RV_ATOMIC + select ARCH_WANT_OPTIONAL_GPIOLIB + select HAVE_MEMBLOCK + select HAVE_DMA_API_DEBUG + select HAVE_DMA_CONTIGUOUS + select HAVE_GENERIC_DMA_COHERENT + select IRQ_DOMAIN + select NO_BOOTMEM + select RV_ATOMIC if SMP + select RV_SYSRISCV_ATOMIC if !RV_ATOMIC + select SPARSE_IRQ + select SYSCTL_EXCEPTION_TRACE + select HAVE_ARCH_TRACEHOOK + select MODULES_USE_ELF_RELA if MODULES + +config MMU + def_bool y + +# even on 32-bit, physical (and DMA) addresses are > 32-bits +config ARCH_PHYS_ADDR_T_64BIT + def_bool y + +config ARCH_DMA_ADDR_T_64BIT + def_bool y + +config STACKTRACE_SUPPORT + def_bool y + +config RWSEM_GENERIC_SPINLOCK + def_bool y + +config GENERIC_BUG + def_bool y + depends on BUG + select GENERIC_BUG_RELATIVE_POINTERS if 64BIT + +config GENERIC_BUG_RELATIVE_POINTERS + bool + +config GENERIC_CALIBRATE_DELAY + def_bool y + +config GENERIC_CSUM + def_bool y + +config GENERIC_HWEIGHT + def_bool y + +config PGTABLE_LEVELS + int + default 3 if 64BIT + default 2 + +config HAVE_KPROBES + def_bool n + +config DMA_NOOP_OPS + def_bool y + +menu "Platform type" + +config SMP + bool "Symmetric Multi-Processing" + help + This enables support for systems with more than one CPU. If + you say N here, the kernel will run on single and + multiprocessor machines, but will use only one CPU of a + multiprocessor machine. If you say Y here, the kernel will run + on many, but not all, single processor machines. On a single + processor machine, the kernel will run faster if you say N + here. + + If you don't know what to do here, say N. + +config NR_CPUS + int "Maximum number of CPUs (2-32)" + range 2 32 + depends on SMP
arch/riscv/Kconfig line 109
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ default "8" + +choice + prompt "CPU selection" + default CPU_RV_GENERIC + +config CPU_RV_GENERIC + bool "Generic RISC-V" + select CPU_SUPPORTS_32BIT_KERNEL + select CPU_SUPPORTS_64BIT_KERNEL
Is this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (CPU_RV_GENERIC that is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_bool y' for now.
Quoted 13 lines
arch/riscv/Kconfig new file +13
-0+ +endchoice + +config PLIC + bool "Platform-Level Interrupt Controller" + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.
arch/riscv/Kconfig line 132
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ +config CPU_SUPPORTS_32BIT_KERNEL + bool +config CPU_SUPPORTS_64BIT_KERNEL + bool + +config SBI_CONSOLE + tristate "SBI console support" + select TTY + default y
Usually you end up having a DRIVER_FOO and DRIVER_FOO_CONSOLE option to enable registering it as console.
Also, unless there's strong reason to keep it under arch/, it should probably go under drivers/tty/.
arch/riscv/Kconfig line 136
Quoted 3 lines
arch/riscv/Kconfig new file +3
-0+config RVC + bool "Use compressed instructions (RV32C or RV64C)" + default n
What does "use" here mean? Use during build, or allow userspace to use them?
arch/riscv/Kconfig line 140
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+ +config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y
Same for this.
arch/riscv/Kconfig line 152
Quoted 11 lines
arch/riscv/Kconfig new file +11
-0+config RV_SYSRISCV_ATOMIC + bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.
If it's mandatory then Kconfig language should make it so.
Quoted 22 lines
arch/riscv/Kconfig new file +22
-0+config RV_PUM + def_bool y + prompt "Protect User Memory" if EXPERT + ---help--- + Protect User Memory (PUM) prevents the kernel from inadvertently + accessing user-space memory. There is a small performance cost + and kernel size increase if this is enabled. + + If unsure, say Y. + +endmenu + +menu "Kernel type" + +choice + prompt "Kernel code model" + default 64BIT + +config 32BIT + bool "32-bit kernel" + depends on CPU_SUPPORTS_32BIT_KERNEL + help
arch/riscv/Kconfig line 185
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ Select this option to build a 32-bit kernel. + +config 64BIT + bool "64-bit kernel" + depends on CPU_SUPPORTS_64BIT_KERNEL + help + Select this option to build a 64-bit kernel. + +endchoice +
[...]
-Olof
Randy Dunlap
reviewerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 21 lines · Olof Johansson
Hi,
Quoted 8 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++Quoted 8 lines
7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spike
Quoted 8 lines
Nearly all other platforms have
_defconfigin the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example,spike_defconfig,spike64_defconfig,qemu_defconfig, freedom-u_defconfig.Not going to argue too much about the color of the shed here, but using the
_defconfignaming is recommended.
well, the top-level Makefile looks for "make *config" to indicate that there is a config-command in progress (or in process), so they usually have to end in the string "config".
Have these been tested?
Signature · 1 line
~Randy
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 28 lines · On Mon, 22 May 2017 18:31:08 PDT (-0700), [email protected] wrote:
Quoted 27 lines · Olof Johansson
Hi,
Quoted 8 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++Quoted 8 lines
7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spikeNearly all other platforms have
_defconfigin the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example,spike_defconfig,spike64_defconfig,qemu_defconfig, freedom-u_defconfig.
Quoted 8 lines
Quoted 2 lines
Not going to argue too much about the color of the shed here, but using the
_defconfignaming is recommended.well, the top-level
Makefilelooks for "make *config" to indicate that there is a config-command in progress (or in process), so they usually have to end in the string "config".Have these been tested?
Ah, that's much better -- I've just been copying them to .config :). I've already renamed them to things that end in defconfig.
Thanks!
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
In reply to Olof JohanssonQuoted 21 lines · On Mon, 22 May 2017 18:27:21 PDT (-0700), [email protected] wrote:
Hi,
Quoted 8 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++Quoted 8 lines
7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spike
Quoted 8 lines
Nearly all other platforms have
_defconfigin the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example,spike_defconfig,spike64_defconfig,qemu_defconfig, freedom-u_defconfig.Not going to argue too much about the color of the shed here, but using the
_defconfignaming is recommended.
Works for me <https://github.com/riscv/riscv-linux/commit/b1165397ba6cb54f23910537c4bf4c3488ef9aad>
I'll squash all the CR comments into a v2.
Quoted 32 lines
Quoted 32 lines
arch/riscv/.gitignore new file +24
-0@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +# +.* +*.o +*.o.* +*.a +*.s +*.ko +*.so +*.so.dbg +*.mod.c +*.i +*.lst +*.symtypes +*.order +modules.builtin +*.elf +*.bin +*.gz +*.bz2
Quoted 8 lines
arch/riscv/.gitignore line 29
Quoted 5 lines
arch/riscv/.gitignore new file +5
-0+*.lzma +*.xz +*.lzo +*.patch +*.gcnoI don't think you need to do any of this, just inherit the global one (by not having one here)?
Sorry, that's a holdover from how we used to manage our out-of-tree port and can just be deleted.
https://github.com/riscv/riscv-linux/commit/68032fb592297331a2f2caf246968da7b70373fe
Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig new file +1
-0+config CPU_RV_GENERIC
Quoted 8 lines
arch/riscv/Kconfig line 109
Quoted 3 lines
arch/riscv/Kconfig new file +3
-0+ bool "Generic RISC-V" + select CPU_SUPPORTS_32BIT_KERNEL + select CPU_SUPPORTS_64BIT_KERNELIs this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (
CPU_RV_GENERICthat is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_booly' for now.
I think this is actually broken in the opposite direction: we only support 32-bit kernels on RV32 and 64-bit kernels on RV64, not both at the same time. I don't really think it makes sense to build a kernel that supports both 32-bit and 64-bit on RISC-V (as they're different base ISAs), so I think it'd be better to just have a "base ISA" configuration.
https://github.com/riscv/riscv-linux/commit/695d428d65bf6fe1382d34393e9d07f40b74e1b2
We'll think on this a bit more and get something saner.
Quoted 10 lines
arch/riscv/Kconfig line 132
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config SBI_CONSOLE + tristate "SBI console support" + select TTY + default yUsually you end up having a
DRIVER_FOOandDRIVER_FOO_CONSOLEoption to enable registering it as console.Also, unless there's strong reason to keep it under
arch/, it should probably go underdrivers/tty/.
In this case "SBI" is the "Supervisor Binary Interface". This is a set of routines that are provided by the platform for OS use that do things like writing to the boot console or TLB shootdowns. The SBI is part of the RISC-V ISA, so there isn't a config option for turning it off. SBI_CONSOLE enables/disables the SBI's console support, so I think this option is sane.
It's in arch/riscv because the SBI is part of the RISC-V ISA -- essentially there's special SBI instructions that mean "write some register to the console" (there's some implementation tricks behind this, so it's really just a specification). That said, I'm fine moving this to drivers.
Quoted 4 lines
arch/riscv/Kconfig line 136
Quoted 3 lines
arch/riscv/Kconfig new file +3
-0+config RVC + bool "Use compressed instructions (RV32C or RV64C)" + default n
Quoted 8 lines
What does "use" here mean? Use during build, or allow userspace to use them?
arch/riscv/Kconfig line 140
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+ +config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default ySame for this.
These mean "tell the compiler that it can emit these instructions when building Linux". Userspace applications can still use these instructions either way. How does "Emit compressed instructions when building Linux" sound?
https://github.com/riscv/riscv-linux/commit/d6e65bd8b7dcfa72578d62e5eb367f680b55f5a8
Quoted 14 lines
arch/riscv/Kconfig line 152
Quoted 12 lines
arch/riscv/Kconfig new file +11
-0+config RV_SYSRISCV_ATOMIC + bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.If it's mandatory then
Kconfiglanguage should make it so.
I'm not sure what you mean by this. We have
config RISCV
...
select RV_SYSRISCV_ATOMIC if !RV_ATOMIC
Should this constraint just live within "config RV_SYSRISCV_ATOMIC"? It seems cleaner to have the constraints next to the config definitions.
Thanks!
Re: [patches] Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 102 lines · Palmer Dabbelt
Quoted 21 lines · On Mon, 22 May 2017 18:27:21 PDT (-0700), [email protected] wrote:
Hi,
Quoted 8 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++Quoted 8 lines
7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spikeQuoted 8 lines
Nearly all other platforms have
_defconfigin the config names. It might get a bit excessive to prepend riscv{32,64} to all of them though. Most other platforms have shortened it to, for example,spike_defconfig,spike64_defconfig,qemu_defconfig, freedom-u_defconfig.Not going to argue too much about the color of the shed here, but using the
_defconfignaming is recommended.Works for me <https://github.com/riscv/riscv-linux/commit/b1165397ba6cb54f23910537c4bf4c3488ef9aad>
I'll squash all the CR comments into a v2.
Quoted 32 lines
Quoted 32 lines
arch/riscv/.gitignore new file +24
-0@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +# +.* +*.o +*.o.* +*.a +*.s +*.ko +*.so +*.so.dbg +*.mod.c +*.i +*.lst +*.symtypes +*.order +modules.builtin +*.elf +*.bin +*.gz +*.bz2Quoted 8 lines
arch/riscv/.gitignore line 29
Quoted 5 lines
arch/riscv/.gitignore new file +5
-0+*.lzma +*.xz +*.lzo +*.patch +*.gcnoI don't think you need to do any of this, just inherit the global one (by not having one here)?
Sorry, that's a holdover from how we used to manage our out-of-tree port and can just be deleted.
https://github.com/riscv/riscv-linux/commit/68032fb592297331a2f2caf246968da7b70373fe
Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig new file +1
-0+config CPU_RV_GENERICQuoted 8 lines
arch/riscv/Kconfig line 109
Quoted 3 lines
arch/riscv/Kconfig new file +3
-0+ bool "Generic RISC-V" + select CPU_SUPPORTS_32BIT_KERNEL + select CPU_SUPPORTS_64BIT_KERNELIs this even needed at this point? If the only CPU you can pick supports this, you might as well not make it an option (
CPU_RV_GENERICthat is), and just make CPU_SUPPORTS_{32,64}BIT_KERNEL 'def_booly' for now.I think this is actually broken in the opposite direction: we only support 32-bit kernels on RV32 and 64-bit kernels on RV64, not both at the same time. I don't really think it makes sense to build a kernel that supports both 32-bit and 64-bit on RISC-V (as they're different base ISAs), so I think it'd be better to just have a "base ISA" configuration.
Quoted 3 lines
https://github.com/riscv/riscv-linux/commit/695d428d65bf6fe1382d34393e9d07f40b74e1b2
We'll think on this a bit more and get something saner.
Sure, sounds good overall though.
Quoted 17 lines
Quoted 10 lines
arch/riscv/Kconfig line 132
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config SBI_CONSOLE + tristate "SBI console support" + select TTY + default yUsually you end up having a
DRIVER_FOOandDRIVER_FOO_CONSOLEoption to enable registering it as console.Also, unless there's strong reason to keep it under
arch/, it should probably go underdrivers/tty/.In this case "SBI" is the "Supervisor Binary Interface". This is a set of routines that are provided by the platform for OS use that do things like writing to the boot console or TLB shootdowns. The SBI is part of the RISC-V ISA, so there isn't a config option for turning it off.
SBI_CONSOLEenables/disables the SBI's console support, so I think this option is sane.
Quoted 4 lines
It's in
arch/riscvbecause the SBI is part of the RISC-V ISA -- essentially there's special SBI instructions that mean "write some register to the console" (there's some implementation tricks behind this, so it's really just a specification). That said, I'm fine moving this to drivers.
The same is true for some other drivers. Actually, I wonder if it might be just as easy to implement a sbi backend for hvc -- see hvc_udbg.c for an example where, on power, you have a simple get/put char hypervisor call in a very similar manner.
Either way (keeping discrete sbi driver or implementing hvc backend), moving to drivers/tty is the right thing here -- we've worked hard on ARM to get rid of random drivers under arch/ and it'd be nice to not see new ones intoduced here.
Quoted 14 lines
Quoted 5 lines
arch/riscv/Kconfig line 136
Quoted 4 lines
arch/riscv/Kconfig new file +3
-0+config RVC + bool "Use compressed instructions (RV32C or RV64C)" + default nQuoted 8 lines
What does "use" here mean? Use during build, or allow userspace to use them?
arch/riscv/Kconfig line 140
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+ +config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default ySame for this.
Quoted 5 lines
These mean "tell the compiler that it can emit these instructions when building Linux". Userspace applications can still use these instructions either way. How does "Emit compressed instructions when building Linux" sound?
https://github.com/riscv/riscv-linux/commit/d6e65bd8b7dcfa72578d62e5eb367f680b55f5a8
Sounds good, you can still reference the ISA extensions if you want though.
Quoted 15 lines
Quoted 14 lines
arch/riscv/Kconfig line 152
Quoted 12 lines
arch/riscv/Kconfig new file +11
-0+config RV_SYSRISCV_ATOMIC + bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.If it's mandatory then
Kconfiglanguage should make it so.
Quoted 8 lines
I'm not sure what you mean by this. We have
config RISCV
...
selectRV_SYSRISCV_ATOMICif !RV_ATOMICShould this constraint just live within "config
RV_SYSRISCV_ATOMIC"? It seems cleaner to have the constraints next to the config definitions.
Ah, I just missed the select.
-Olof
Re: [patches] Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 4 lines · Olof Johansson
The same is true for some other drivers. Actually, I wonder if it might be just as easy to implement a sbi backend for hvc -- see
hvc_udbg.cfor an example where, on power, you have a simple get/put char hypervisor call in a very similar manner.
Rather look at hvc_opal. This is the console driver we use on native POWER servers with the OPAL firmware, and it calls into a firmware in a very similar way.
The driver lives in drivers/tty/hvc. It does call some "helpers" in the arch code that wrap the actual FW calls.
Quoted 4 lines
Either way (keeping discrete sbi driver or implementing hvc backend), moving to
drivers/ttyis the right thing here -- we've worked hard on ARM to get rid of random drivers underarch/and it'd be nice to not see new ones intoduced here.
Yup. The reason mostly is that if the tty maintainer needs to do a subsystem-wide change, he can address all drivers in drivers/tty and doesn't have to look for others elsewhere in the tree. This is the same for all subsystems.
Cheers,
Ben.
Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
In reply to Palmer Dabbelt(new top-level subthread here since this is a separate topic):
Quoted 52 lines · Palmer Dabbelt
arch/riscv/Makefile new file +46
-0@@ -0,0 +1,64 @@ +# This file is included by the global makefile so that you can add your own +# architecture-specific flags and dependencies. Remember to do have actions +# for "archclean" and "archdep" for cleaning up and making dependencies for +# this architecture +# +# This file is subject to the terms and conditions of the GNU General Public +# License. See the file "COPYING" in the main directory of this archive +# for more details. +# + +LDFLAGS := +OBJCOPYFLAGS := -O binary +LDFLAGS_vmlinux := +KBUILD_AFLAGS_MODULE += -fPIC +KBUILD_CFLAGS_MODULE += -fPIC + +ifeq ($(ARCH),riscv) + KBUILD_DEFCONFIG = riscv64_spike +else + KBUILD_DEFCONFIG = $(ARCH)_spike +endif + +export BITS +ifeq ($(CONFIG_64BIT),y) + BITS := 64 + UTS_MACHINE := riscv64 + + KBUILD_CFLAGS += -mabi=lp64 + KBUILD_AFLAGS += -mabi=lp64 + KBUILD_MARCH = rv64im + LDFLAGS += -melf64lriscv +else + BITS := 32 + UTS_MACHINE := riscv32 + + KBUILD_CFLAGS += -mabi=ilp32 + KBUILD_AFLAGS += -mabi=ilp32 + KBUILD_MARCH = rv32im + LDFLAGS += -melf32lriscv +endif + +ifeq ($(CONFIG_RV_ATOMIC),y) + KBUILD_RV_ATOMIC = a +endif + +KBUILD_CFLAGS += -Wall
arch/riscv/Makefile line 56
Quoted 10 lines
arch/riscv/Makefile new file +10
-0+ +ifeq ($(CONFIG_RVC),y) + KBUILD_RVC = c +endif + +KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC) + +KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC) +KBUILD_CFLAGS += -mno-save-restore +KBUILD_CFLAGS += -mstrict-align
I built a vanilla gcc-7.1.0 here, with 'riscv64-linux' as target, and I get:
riscv64-linux-gcc: error: unrecognized command line option '-mstrict-align'; did you mean '-Wstrict-aliasing'?
The suggestion seems completely bogus, but the error is real. Looking at the gcc sources, I only see strict-align plumbed up on rs6000, aarch64, m68k(!) and v850. Or am I missing something here?
-Olof
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 69 lines · On Mon, 22 May 2017 22:23:17 PDT (-0700), [email protected] wrote:
(new top-level subthread here since this is a separate topic):
Quoted 52 lines · Palmer Dabbelt
arch/riscv/Makefile new file +46
-0@@ -0,0 +1,64 @@ +# This file is included by the global makefile so that you can add your own +# architecture-specific flags and dependencies. Remember to do have actions +# for "archclean" and "archdep" for cleaning up and making dependencies for +# this architecture +# +# This file is subject to the terms and conditions of the GNU General Public +# License. See the file "COPYING" in the main directory of this archive +# for more details. +# + +LDFLAGS := +OBJCOPYFLAGS := -O binary +LDFLAGS_vmlinux := +KBUILD_AFLAGS_MODULE += -fPIC +KBUILD_CFLAGS_MODULE += -fPIC + +ifeq ($(ARCH),riscv) + KBUILD_DEFCONFIG = riscv64_spike +else + KBUILD_DEFCONFIG = $(ARCH)_spike +endif + +export BITS +ifeq ($(CONFIG_64BIT),y) + BITS := 64 + UTS_MACHINE := riscv64 + + KBUILD_CFLAGS += -mabi=lp64 + KBUILD_AFLAGS += -mabi=lp64 + KBUILD_MARCH = rv64im + LDFLAGS += -melf64lriscv +else + BITS := 32 + UTS_MACHINE := riscv32 + + KBUILD_CFLAGS += -mabi=ilp32 + KBUILD_AFLAGS += -mabi=ilp32 + KBUILD_MARCH = rv32im + LDFLAGS += -melf32lriscv +endif + +ifeq ($(CONFIG_RV_ATOMIC),y) + KBUILD_RV_ATOMIC = a +endif + +KBUILD_CFLAGS += -Wallarch/riscv/Makefile line 56
Quoted 10 lines
arch/riscv/Makefile new file +10
-0+ +ifeq ($(CONFIG_RVC),y) + KBUILD_RVC = c +endif + +KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC) + +KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC) +KBUILD_CFLAGS += -mno-save-restore +KBUILD_CFLAGS += -mstrict-alignI built a vanilla gcc-7.1.0 here, with 'riscv64-linux' as target, and I get:
Quoted 7 lines
riscv64-linux-gcc: error: unrecognized command line option '-mstrict-align'; did you mean '-Wstrict-aliasing'?
The suggestion seems completely bogus, but the error is real. Looking at the gcc sources, I only see strict-align plumbed up on rs6000, aarch64, m68k(!) and v850. Or am I missing something here?
We didn't get the "-mstrict-align" patch for RISC-V into the 7.1.0 release. The boot loader install machine-mode unaligned access handlers, so in theory you shouldn't need this at all -- it snuck its way in as a debugging attempt because the Radeon driver was exhibiting some weird behavior.
I'll drop this from the next patch set.
Re: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
In reply to Palmer DabbeltHi Palmer,
Quoted 5 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +1
-0@@ -0,0 +1,300 @@ +config PLIC
arch/riscv/Kconfig line 123
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Platform-Level Interrupt Controller" + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y. +
I think this symbol belongs in drivers/irqchip/Kconfig, and the corresponding driver in drivers/irqchip/.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 7 lines · On Tue, 23 May 2017 03:51:24 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 3 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +0
-0@@ -0,0 +1,300 @@
Quoted 14 lines
arch/riscv/Kconfig line 123
Quoted 11 lines
arch/riscv/Kconfig new file +11
-0+config PLIC + bool "Platform-Level Interrupt Controller" + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y. +I think this symbol belongs in
drivers/irqchip/Kconfig, and the corresponding driver indrivers/irqchip/.
OK, makes sense.
https://github.com/riscv/riscv-linux/commit/81e5c9e581c318ea99192d5c1aaf97c197e79272
I'll batch this up with all the other code review comments for a v2.
Arnd Bergmann
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
In reply to Palmer DabbeltQuoted 23 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++ 7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spikearch/riscv/.gitignore new file +0
-0
arch/riscv/.gitignore line 10
Quoted 10 lines
arch/riscv/.gitignore new file +10
-0@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +# +.* +*.o +*.o.* +*.a
This doesn't seem to belong here: There is no reason for riscv to be different from all other architectures. Is something wrong with the top-level .gitignore? If so, we should just fix it there.
Quoted 14 lines
arch/riscv/Kconfig new file +8
-0@@ -0,0 +1,300 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# + +config RISCV + def_bool y + select OF
arch/riscv/Kconfig line 18
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ select OF_EARLY_FLATTREE + select OF_IRQ + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE + select ARCH_WANT_FRAME_POINTERS + select CLONE_BACKWARDS + select COMMON_CLK + select GENERIC_CLOCKEVENTS + select GENERIC_CPU_DEVICES + select GENERIC_IRQ_SHOW + select GENERIC_PCI_IOMAP
You normally don't want GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()
arch/riscv/Kconfig line 20
Quoted 2 lines
arch/riscv/Kconfig new file +2
-0+config MMU + def_bool y
Just a general question: has there been any interest in a no-MMU version?
arch/riscv/Kconfig line 45
Quoted 6 lines
arch/riscv/Kconfig new file +6
-0+# even on 32-bit, physical (and DMA) addresses are > 32-bits +config ARCH_PHYS_ADDR_T_64BIT + def_bool y + +config ARCH_DMA_ADDR_T_64BIT + def_bool y
Are you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit dma_addr_t and phys_addr_t when possible makes some code noticeably more efficient.
arch/riscv/Kconfig line 73
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config PGTABLE_LEVELS + int + default 3 if 64BIT + default 2
With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y + +config RV_SYSRISCV_ATOMIC
arch/riscv/Kconfig line 152
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.
Just express this in Kconfig terms to prevent misconfiguration:
config RV_SYSRISCV_ATOMIC
bool "Include support for atomic operation syscalls" if RV_ATOMIC default !RV_ATOMIC
I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:
That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.
arch/riscv/Kconfig line 211
Quoted 8 lines
arch/riscv/Kconfig new file +8
-0+config PCI_DOMAINS + def_bool PCI + +config PCI_DOMAINS_GENERIC + def_bool PCI + +config PCI_SYSCALL + def_bool PCI
I don't think you want PCI_SYSCALL
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 30 lines · Arnd Bergmann
Quoted 29 lines · Palmer Dabbelt
--- arch/riscv/.gitignore | 35 ++++ arch/riscv/Kconfig | 300 +++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 64 ++++++++ arch/riscv/configs/riscv32_spike | 47 ++++++ arch/riscv/configs/riscv64_freedom-u | 52 ++++++ arch/riscv/configs/riscv64_qemu | 64 ++++++++ arch/riscv/configs/riscv64_spike | 45 ++++++ 7 files changed, 607 insertions(+) create mode 100644 arch/riscv/.gitignore create mode 100644 arch/riscv/Kconfig create mode 100644 arch/riscv/Makefile create mode 100644 arch/riscv/configs/riscv32_spike create mode 100644 arch/riscv/configs/riscv64_freedom-u create mode 100644 arch/riscv/configs/riscv64_qemu create mode 100644 arch/riscv/configs/riscv64_spikearch/riscv/.gitignore new file +6
-0@@ -0,0 +1,35 @@ +# Now un-ignore all files. +!* + +# But then re-ignore the files listed in the Linux .gitignore +# Normal rules +#
Quoted 8 lines
arch/riscv/.gitignore line 10
Quoted 4 lines
arch/riscv/.gitignore new file +4
-0+.* +*.o +*.o.* +*.aThis doesn't seem to belong here: There is no reason for riscv to be different from all other architectures. Is something wrong with the top-level .gitignore? If so, we should just fix it there.
Sorry, this snuck in from how we used to track the kernel. It's been fixed.
Quoted 19 lines
Quoted 19 lines
arch/riscv/Kconfig new file +13
-0@@ -0,0 +1,300 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# + +config RISCV + def_bool y + select OF + select OF_EARLY_FLATTREE + select OF_IRQ + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE + select ARCH_WANT_FRAME_POINTERS + select CLONE_BACKWARDS
Quoted 8 lines
arch/riscv/Kconfig line 18
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+ select COMMON_CLK + select GENERIC_CLOCKEVENTS + select GENERIC_CPU_DEVICES + select GENERIC_IRQ_SHOW + select GENERIC_PCI_IOMAPYou normally don't want
GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()
We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.
It looks like most of my candidates for patterning things after use GENERIC_PCI_IOMAP, but I ended up setting GENERIC_IOMAP and things still at least build and boot without any PCI
https://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e
I'll be sure to check if I broke PCI, as I don't actually know what's going on here.
Quoted 5 lines
arch/riscv/Kconfig line 20
Quoted 2 lines
arch/riscv/Kconfig new file +2
-0+config MMU + def_bool yJust a general question: has there been any interest in a no-MMU version?
One of the fun things about RISC-V is that there's at least some interest in _everything_... :). There hasn't been any serious interest, and I don't know of anyone building systems where no-MMU Linux would run (our DDR phy is a lot bigger than our MMU), but I wouldn't rule it out.
Quoted 11 lines
arch/riscv/Kconfig line 45
Quoted 6 lines
arch/riscv/Kconfig new file +6
-0+# even on 32-bit, physical (and DMA) addresses are > 32-bits +config ARCH_PHYS_ADDR_T_64BIT + def_bool y + +config ARCH_DMA_ADDR_T_64BIT + def_bool yAre you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit
dma_addr_tandphys_addr_twhen possible makes some code noticeably more efficient.
Quoted 8 lines
arch/riscv/Kconfig line 73
Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config PGTABLE_LEVELS + int + default 3 if 64BIT + default 2With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.
We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.
Quoted 18 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y + +config RV_SYSRISCV_ATOMICarch/riscv/Kconfig line 152
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.Just express this in
Kconfigterms to prevent misconfiguration:
Quoted 3 lines
config
RV_SYSRISCV_ATOMIC
bool "Include support for atomic operation syscalls" ifRV_ATOMICdefault !RV_ATOMIC
Done
https://github.com/riscv/riscv-linux/commit/921703e0a6639d10826e5bbad73f4998977dc244
Quoted 7 lines
I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:
That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.
I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.
The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.
I'll add it to my TODO list.
Quoted 10 lines
arch/riscv/Kconfig line 211
Quoted 8 lines
arch/riscv/Kconfig new file +8
-0+config PCI_DOMAINS + def_bool PCI + +config PCI_DOMAINS_GENERIC + def_bool PCI + +config PCI_SYSCALL + def_bool PCII don't think you want
PCI_SYSCALL
OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens
https://github.com/riscv/riscv-linux/commit/710b5bb81ab99cf1d49a74bb706f6aae179fc111
Arnd Bergmann
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 30 lines · Palmer Dabbelt
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +13
-0@@ -0,0 +1,300 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# + +config RISCV + def_bool y + select OF + select OF_EARLY_FLATTREE + select OF_IRQ + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE + select ARCH_WANT_FRAME_POINTERS + select CLONE_BACKWARDSQuoted 8 lines
arch/riscv/Kconfig line 18
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+ select COMMON_CLK + select GENERIC_CLOCKEVENTS + select GENERIC_CPU_DEVICES + select GENERIC_IRQ_SHOW + select GENERIC_PCI_IOMAPYou normally don't want
GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()
Quoted 2 lines
We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.
Ah, interesting. What is the exact behavior of that fence? (this is slightly unrelated but worth looking at anyway)
Quoted 8 lines
It looks like most of my candidates for patterning things after use
GENERIC_PCI_IOMAP, but I ended up settingGENERIC_IOMAPand things still at least build and boot without any PCIhttps://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e
I'll be sure to check if I broke PCI, as I don't actually know what's going on here.
Actually I made a mistake: GENERIC_PCI_IOMAP is fine, please use that, GENERIC_IOMAP is the option you don't want, and you already don't enable that one.
Quoted 16 lines
Quoted 16 lines
arch/riscv/Kconfig line 45
Quoted 6 lines
arch/riscv/Kconfig new file +6
-0+# even on 32-bit, physical (and DMA) addresses are > 32-bits +config ARCH_PHYS_ADDR_T_64BIT + def_bool y + +config ARCH_DMA_ADDR_T_64BIT + def_bool yAre you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit
dma_addr_tandphys_addr_twhen possible makes some code noticeably more efficient.Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config PGTABLE_LEVELS + int + default 3 if 64BIT + default 2
Quoted 7 lines
Quoted 3 lines
With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.
We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.
I'd suggest to leave it turned off initially and only use it once someone actually builds a system that makes use of the high address space.
Of course if there is already hardware that needs it, there has to be a way to turn it on.
This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:
- Every major platform gets a Kconfig option in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)
- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.
On ARM, we have a bit of both, which is not as good as being consistent one way or another.
Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y + +config RV_SYSRISCV_ATOMICarch/riscv/Kconfig line 152
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:
Quoted 3 lines
That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.
I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.
Quoted 6 lines
The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.
I'll add it to my TODO list.
This would be another variant of the question above.
Quoted 11 lines
Quoted 10 lines
arch/riscv/Kconfig line 211
Quoted 8 lines
arch/riscv/Kconfig new file +8
-0+config PCI_DOMAINS + def_bool PCI + +config PCI_DOMAINS_GENERIC + def_bool PCI + +config PCI_SYSCALL + def_bool PCII don't think you want
PCI_SYSCALL
Quoted 2 lines
OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens
I'd argue that's a user space bug that we want to fix anyway to make the code portable to other architectures.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 41 lines · Arnd Bergmann
Quoted 30 lines · Palmer Dabbelt
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
arch/riscv/Kconfig new file +13
-0@@ -0,0 +1,300 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# + +config RISCV + def_bool y + select OF + select OF_EARLY_FLATTREE + select OF_IRQ + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE + select ARCH_WANT_FRAME_POINTERS + select CLONE_BACKWARDSQuoted 8 lines
arch/riscv/Kconfig line 18
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+ select COMMON_CLK + select GENERIC_CLOCKEVENTS + select GENERIC_CPU_DEVICES + select GENERIC_IRQ_SHOW + select GENERIC_PCI_IOMAPYou normally don't want
GENERIC_PCI_IOMAP, unless your inb()/outb() uses other instructions than your readl()/writel()Quoted 2 lines
We don't have any special instructions for inb/outb, but there is a special fence to ensure ordering.
Ah, interesting. What is the exact behavior of that fence? (this is slightly unrelated but worth looking at anyway)
Quoted 4 lines
It looks like most of my candidates for patterning things after use
GENERIC_PCI_IOMAP, but I ended up settingGENERIC_IOMAPand things still at least build and boot without any PCI
Quoted 8 lines
Quoted 4 lines
https://github.com/riscv/riscv-linux/commit/c43c599b0dd9d15886c03a9dd179f8936b0cbb2e
I'll be sure to check if I broke PCI, as I don't actually know what's going on here.
Actually I made a mistake:
GENERIC_PCI_IOMAPis fine, please use that,GENERIC_IOMAPis the option you don't want, and you already don't enable that one.
Great -- I actually ended up reverting the patch already as I couldn't figure out how to make it work. That was the one big thing on my TODO list before a v2, so with any luck I'll be able to get a new patch set out soon.
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines
arch/riscv/Kconfig line 45
Quoted 6 lines
arch/riscv/Kconfig new file +6
-0+# even on 32-bit, physical (and DMA) addresses are > 32-bits +config ARCH_PHYS_ADDR_T_64BIT + def_bool y + +config ARCH_DMA_ADDR_T_64BIT + def_bool yAre you required to use 64-bit addressing for RAM on 32-bit architectures though? Using 32-bit
dma_addr_tandphys_addr_twhen possible makes some code noticeably more efficient.Quoted 4 lines
arch/riscv/Kconfig new file +4
-0+config PGTABLE_LEVELS + int + default 3 if 64BIT + default 2Quoted 7 lines
Quoted 3 lines
With 2-level page tables, you usually can't address much more than 32-bit physical memory anyway, so I'd guess that most 32-bit chips would actually put their RAM under the 4GB boundary.
We can address 34 bits of physical address space on Sv32 (the 32-bit virtual addressing scheme in RV32). If this is a meaningful performance constraint then we could always make this configurable.
Quoted 5 lines
I'd suggest to leave it turned off initially and only use it once someone actually builds a system that makes use of the high address space.
Of course if there is already hardware that needs it, there has to be a way to turn it on.
There isn't, and I'm find with 32-bit physical addresses on RV32I. I doubt anyone will be building big RV32 systems. I'll make the change for the v2.
Quoted 9 lines
This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:
- Every major platform gets a
Kconfigoption in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)
Quoted 7 lines
- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.
On ARM, we have a bit of both, which is not as good as being consistent one way or another.
This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform Kconfig menu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.
For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.
Quoted 27 lines
Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y + +config RV_SYSRISCV_ATOMICarch/riscv/Kconfig line 152
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:
Quoted 3 lines
That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.
I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.
Quoted 8 lines
Quoted 6 lines
The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.
I'll add it to my TODO list.
This would be another variant of the question above.
After talking with people a bit about this, I think the sane thing to do here is to just always provide the atomic system call (and VDSO implementation), and to default to enabling the atomic extensions. While I expect non-atomic implementations to be very much the exception, there's a stronger argument for supporting non-atomic userspace programs with reasonable performance on atomic systems -- the first round of small Linux-capable embedded systems might not support atomic (though ours will), but we don't want to wed software to a syscall in this case.
Before the VDSO was suggested I was leaning towards disabling the atomic system call by default, but since the VDSO implementation will provide very good performance for non-atomic userspace code on atomic systems I think it's best to just enable it everywhere. It's only a few bytes of binary size.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
arch/riscv/Kconfig line 211
Quoted 8 lines
arch/riscv/Kconfig new file +8
-0+config PCI_DOMAINS + def_bool PCI + +config PCI_DOMAINS_GENERIC + def_bool PCI + +config PCI_SYSCALL + def_bool PCII don't think you want
PCI_SYSCALL
Quoted 5 lines
Quoted 2 lines
OK. I'm a bit worried we need this to run DOOM, but I'll give everything a shot without it and see what happens
I'd argue that's a user space bug that we want to fix anyway to make the code portable to other architectures.
I buy it.
Arnd Bergmann
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 31 lines · Palmer Dabbelt
Quoted 11 lines · Arnd Bergmann
Quoted 1 line · Palmer Dabbelt
On Tue, 23 May 2017 04:46:22 PDT (-0700), Arnd Bergmann wrote:
This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:
- Every major platform gets a
Kconfigoption in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)Quoted 7 lines
- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.
On ARM, we have a bit of both, which is not as good as being consistent one way or another.
This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform
Kconfigmenu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.
Quoted 4 lines
For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.
Ok. Another related point, which may or may not be obvious: when you come up with platform definitions, they should not be mutually exclusive.
For instance, supporting both MMU/NOMMU, big/little-endian or 32/64-bit kernels will of course require building separate binaries, but almost every other configuration option should be backward compatible: An SMP kernel should run on a uniprocessor machine and vice versa (using only one CPU), and you should be able to run a kernel with support multiple instruction set revisions by restricting the build to the smallest subset of instructions.
On older ARM platforms and most MIPS platforms, we are still restricted to building a kernel binary that will only run on a particular SoC family and not even another SoC with the same CPU core. Fixing this for most ARM platforms required a lot of work that you should avoid by requiring them all to work with a common kernel from the start.
Similarly, ARM has an incompatibility that prevents us from running on older (ARMv4/v5) along with newer (ARMv6 or higher) instruction set versions with a single kernel. Avoiding this on RISC-V may become challenging as one of the strengths of the architecture is its flexibility: Someone may come up with their own architecture extensions that they really want to support in the kernel but can't get it to work without making the kernel binary incompatible with other implementations. Do you already have a policy for how to deal with this? Usually by the time someone ships hardware, it's too late and it becomes hard to argue for their kernel port to not get merged.
Quoted 45 lines
Quoted 27 lines
Quoted 27 lines
Quoted 20 lines
Quoted 5 lines
arch/riscv/Kconfig new file +5
-0+config RV_ATOMIC + bool "Use atomic memory instructions (RV32A or RV64A)" + default y + +config RV_SYSRISCV_ATOMICarch/riscv/Kconfig line 152
Quoted 10 lines
arch/riscv/Kconfig new file +10
-0+ bool "Include support for atomic operation syscalls" + default n + help + If atomic memory instructions are present, i.e., + CONFIG_RV_ATOMIC, this includes support for the syscall that + provides atomic accesses. This is only useful to run + binaries that require atomic access but were compiled with + -mno-atomic. + + If CONFIG_RV_ATOMIC is unset, this option is mandatory.I wonder what the cost would be of always providing the syscalls for compatibility. This is also something worth putting into a VDSO instead of exposing the syscall:
Quoted 3 lines
That way, user space that is built with -mno-atomic can call into the vdso, which depending on the hardware support will perform the atomic operation directly or enter the syscall.
I think the theory is that most Linux-capable systems are going to have the A extension, and that this is really there for educational/hobbyist use.
Quoted 8 lines
Quoted 6 lines
The actual implementation isn't that expensive: it's no-SMP-only, so it's just a disable/enable interrupts that wraps a compare+exchange. I think putting it in the VDSO is actually the right thing to do: that way non-A user code will still have reasonable performance.
I'll add it to my TODO list.
This would be another variant of the question above.
After talking with people a bit about this, I think the sane thing to do here is to just always provide the atomic system call (and VDSO implementation), and to default to enabling the atomic extensions. While I expect non-atomic implementations to be very much the exception, there's a stronger argument for supporting non-atomic userspace programs with reasonable performance on atomic systems -- the first round of small Linux-capable embedded systems might not support atomic (though ours will), but we don't want to wed software to a syscall in this case.
Quoted 4 lines
Before the VDSO was suggested I was leaning towards disabling the atomic system call by default, but since the VDSO implementation will provide very good performance for non-atomic userspace code on atomic systems I think it's best to just enable it everywhere. It's only a few bytes of binary size.
Ok.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 2/7] RISC-V: arch/riscv Makefile and Kconfigs
Quoted 40 lines · Arnd Bergmann
Quoted 31 lines · Palmer Dabbelt
Quoted 11 lines · Arnd Bergmann
Quoted 1 line · Palmer Dabbelt
On Tue, 23 May 2017 04:46:22 PDT (-0700), Arnd Bergmann wrote:
This raises a much more general question about how you want to deal with SoC implementations in the future. The two most common ways of doing this are:
- Every major platform gets a
Kconfigoption in the architecture menu, and that selects the essential drivers (irqchip, clocksource, pinctrl, clk, ...) that you need for that platform, along with architecture features (ISA level and optional features, ...)Quoted 7 lines
- The architecture code knows nothing about the SoC and just keeps to the basics (CPU architecture level selection, SMP/MMU/etc enabled, selecting drivers that everyone needs) and leaves the rest up to be selected in the defconfig file.
On ARM, we have a bit of both, which is not as good as being consistent one way or another.
This is actually an open question in RISC-V land right now. We should be spinning up a platform specification working group this summer to try and work things out. While this will have to be ironed out, I believe the plan is to define a small number of base platforms (maybe one for embedded systems with no programmable PMAs, and one for larger machines with a bit more configurability). I'd anticipate that we'll have a platform
Kconfigmenu entry for every platform that gets written down in a specification (just like we have an entry for our base ISAs) and then defconfig entries for various implementations that select the relevant platform in addition to the drivers actually on board.Quoted 4 lines
For now we've got a handful of defconfig entries for the various platforms we support (the ISA simulator and our FPGA implementation), but there's no silicon so we're not stuck with what's there. I don't anticipate we'll add more than a handful of these until the platform spec work is underway.
Ok. Another related point, which may or may not be obvious: when you come up with platform definitions, they should not be mutually exclusive.
Quoted 7 lines
For instance, supporting both MMU/NOMMU, big/little-endian or 32/64-bit kernels will of course require building separate binaries, but almost every other configuration option should be backward compatible: An SMP kernel should run on a uniprocessor machine and vice versa (using only one CPU), and you should be able to run a kernel with support multiple instruction set revisions by restricting the build to the smallest subset of instructions.
We're actually trying really hard to ensure a single binary can run anywhere:
for example, an XLEN (the RISC-V term for the general purpose register bit width) agnostic code sequence can be run that determines if you're on a 32-bit or 64-bit platform without taking any traps, then enumerate the entire set of user and supervisor extensions available. In theory one could build a kernel image that supports both RV32I and RV64I, as well as optionally supporting paging. This won't happen for Linux, but our debugger examines the target chip using this mechanism.
An explicit goal of the supervisor specification is to make it possible for one Linux image to run on every platform. Right now the only constraints we have is that SMP kernels require atomics. Specifically:
* non-SMP kernels run on multiprocessor systems, picking an arbitrary hart to run on (or hart 0 if there's no atomics).
* The kernel is always built with floating-point enabled, it just never sees the "FPU is on" bit if there's no FPU and therefor doesn't execute any F-extension instructions.
[Though of course after writing this I went to check our boot code and found it using an unguarded AMO... Luckily it was an easy fix. Thanks!]
The big hole right now is that the SBI (our version of Alpha's PAL code) isn't specified because it's part of the upcoming platform spec. We'll just have to home this isn't a problem.
Quoted 6 lines
On older ARM platforms and most MIPS platforms, we are still restricted to building a kernel binary that will only run on a particular SoC family and not even another SoC with the same CPU core. Fixing this for most ARM platforms required a lot of work that you should avoid by requiring them all to work with a common kernel from the start.
We're hoping that everyone is more amenable to play ball here after seeing how much pain it was in ARM land. We'll see how well the platform specification goes.
Quoted 11 lines
Similarly, ARM has an incompatibility that prevents us from running on older (ARMv4/v5) along with newer (ARMv6 or higher) instruction set versions with a single kernel. Avoiding this on RISC-V may become challenging as one of the strengths of the architecture is its flexibility: Someone may come up with their own architecture extensions that they really want to support in the kernel but can't get it to work without making the kernel binary incompatible with other implementations. Do you already have a policy for how to deal with this? Usually by the time someone ships hardware, it's too late and it becomes hard to argue for their kernel port to not get merged.
The RISC-V ISA defines extension mechanisms that allows new non-standard extensions to coexist, so as long as everyone is well behaved we should be safe. I believe there is some mechanism to disallow bad behavior via the RISC-V foundation and a certification process, but we'll see if that actually has any teeth.
Of course, we're hoping to only need to support standard extensions, but nothing ever goes that well :).
Palmer Dabbelt
maintainerPATCH 3/7 RISC-V: Device Tree Documentation
In reply to Palmer Dabbelt--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
@@ -0,0 +1,46 @@ +RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each +hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller. + +Required properties: +- compatible : "riscv,cpu-intc" +- #interrupt-cells : should be <1> +- interrupt-controller : Identifies the node as an interrupt controller + +Furthermore, this interrupt-controller MUST be embedded inside the cpu +definition of the hart whose CSRs control these local interrupts. + +Example: + + cpu1: cpu@1 { + clock-frequency = <1600000000>; + compatible = "riscv"; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <16384>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <16384>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + next-level-cache = <&L2>; + reg = <1>; + riscv,isa = "rv64imac"; + status = "okay"; + tlb-split; + cpu1-intc: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + };
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.13.0
Arnd Bergmann
maintainerRe: [PATCH 3/7] RISC-V: Device Tree Documentation
Quoted 3 lines · Palmer Dabbelt
--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++
The patch needs a description, and should be sent to the irqchip maintainers and the devicetree maintainers for review, along for the respective drivers/irqchip/
patch.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 3/7] RISC-V: Device Tree Documentation
Quoted 9 lines · Arnd Bergmann
Quoted 3 lines · Palmer Dabbelt
--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++The patch needs a description, and should be sent to the irqchip maintainers and the devicetree maintainers for review, along for the respective
drivers/irqchip/
patch.
OK, I'll include that as part of my v2.
Palmer Dabbelt
maintainerPATCH 4/7 RISC-V: arch/riscv/include
In reply to Palmer Dabbelt--- arch/riscv/include/asm/Kbuild | 60 ++++ arch/riscv/include/asm/asm-offsets.h | 1 + arch/riscv/include/asm/asm.h | 65 +++++ arch/riscv/include/asm/atomic.h | 349 +++++++++++++++++++++++ arch/riscv/include/asm/atomic64.h | 355 +++++++++++++++++++++++ arch/riscv/include/asm/barrier.h | 33 +++ arch/riscv/include/asm/bitops.h | 229 +++++++++++++++ arch/riscv/include/asm/bug.h | 81 ++++++ arch/riscv/include/asm/cache.h | 23 ++ arch/riscv/include/asm/cacheflush.h | 40 +++ arch/riscv/include/asm/cmpxchg.h | 125 ++++++++ arch/riscv/include/asm/csr.h | 126 +++++++++ arch/riscv/include/asm/delay.h | 29 ++ arch/riscv/include/asm/device.h | 28 ++ arch/riscv/include/asm/dma-mapping.h | 61 ++++ arch/riscv/include/asm/elf.h | 83 ++++++ arch/riscv/include/asm/io.h | 36 +++ arch/riscv/include/asm/irq.h | 32 +++ arch/riscv/include/asm/irqflags.h | 64 +++++ arch/riscv/include/asm/kprobes.h | 23 ++ arch/riscv/include/asm/linkage.h | 21 ++ arch/riscv/include/asm/mmu.h | 27 ++ arch/riscv/include/asm/mmu_context.h | 70 +++++ arch/riscv/include/asm/page.h | 138 +++++++++ arch/riscv/include/asm/pci.h | 51 ++++ arch/riscv/include/asm/pgalloc.h | 126 +++++++++ arch/riscv/include/asm/pgtable-32.h | 26 ++ arch/riscv/include/asm/pgtable-64.h | 85 ++++++ arch/riscv/include/asm/pgtable-bits.h | 49 ++++ arch/riscv/include/asm/pgtable.h | 426 ++++++++++++++++++++++++++++ arch/riscv/include/asm/processor.h | 103 +++++++ arch/riscv/include/asm/ptrace.h | 117 ++++++++ arch/riscv/include/asm/sbi.h | 101 +++++++ arch/riscv/include/asm/serial.h | 43 +++ arch/riscv/include/asm/setup.h | 20 ++ arch/riscv/include/asm/smp.h | 42 +++ arch/riscv/include/asm/spinlock.h | 156 ++++++++++ arch/riscv/include/asm/spinlock_types.h | 34 +++ arch/riscv/include/asm/string.h | 31 ++ arch/riscv/include/asm/switch_to.h | 71 +++++ arch/riscv/include/asm/syscall.h | 91 ++++++ arch/riscv/include/asm/syscalls.h | 26 ++ arch/riscv/include/asm/thread_info.h | 103 +++++++ arch/riscv/include/asm/timex.h | 55 ++++ arch/riscv/include/asm/tlb.h | 25 ++ arch/riscv/include/asm/tlbflush.h | 95 +++++++ arch/riscv/include/asm/uaccess.h | 455 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/unistd.h | 17 ++ arch/riscv/include/asm/vdso.h | 32 +++ arch/riscv/include/asm/word-at-a-time.h | 56 ++++ arch/riscv/include/uapi/asm/Kbuild | 10 + arch/riscv/include/uapi/asm/auxvec.h | 24 ++ arch/riscv/include/uapi/asm/bitsperlong.h | 25 ++ arch/riscv/include/uapi/asm/byteorder.h | 23 ++ arch/riscv/include/uapi/asm/elf.h | 83 ++++++ arch/riscv/include/uapi/asm/ptrace.h | 69 +++++ arch/riscv/include/uapi/asm/sigcontext.h | 30 ++ arch/riscv/include/uapi/asm/siginfo.h | 24 ++ arch/riscv/include/uapi/asm/unistd.h | 23 ++ 59 files changed, 4846 insertions(+) create mode 100644 arch/riscv/include/asm/Kbuild create mode 100644 arch/riscv/include/asm/asm-offsets.h create mode 100644 arch/riscv/include/asm/asm.h create mode 100644 arch/riscv/include/asm/atomic.h create mode 100644 arch/riscv/include/asm/atomic64.h create mode 100644 arch/riscv/include/asm/barrier.h create mode 100644 arch/riscv/include/asm/bitops.h create mode 100644 arch/riscv/include/asm/bug.h create mode 100644 arch/riscv/include/asm/cache.h create mode 100644 arch/riscv/include/asm/cacheflush.h create mode 100644 arch/riscv/include/asm/cmpxchg.h create mode 100644 arch/riscv/include/asm/csr.h create mode 100644 arch/riscv/include/asm/delay.h create mode 100644 arch/riscv/include/asm/device.h create mode 100644 arch/riscv/include/asm/dma-mapping.h create mode 100644 arch/riscv/include/asm/elf.h create mode 100644 arch/riscv/include/asm/io.h create mode 100644 arch/riscv/include/asm/irq.h create mode 100644 arch/riscv/include/asm/irqflags.h create mode 100644 arch/riscv/include/asm/kprobes.h create mode 100644 arch/riscv/include/asm/linkage.h create mode 100644 arch/riscv/include/asm/mmu.h create mode 100644 arch/riscv/include/asm/mmu_context.h create mode 100644 arch/riscv/include/asm/page.h create mode 100644 arch/riscv/include/asm/pci.h create mode 100644 arch/riscv/include/asm/pgalloc.h create mode 100644 arch/riscv/include/asm/pgtable-32.h create mode 100644 arch/riscv/include/asm/pgtable-64.h create mode 100644 arch/riscv/include/asm/pgtable-bits.h create mode 100644 arch/riscv/include/asm/pgtable.h create mode 100644 arch/riscv/include/asm/processor.h create mode 100644 arch/riscv/include/asm/ptrace.h create mode 100644 arch/riscv/include/asm/sbi.h create mode 100644 arch/riscv/include/asm/serial.h create mode 100644 arch/riscv/include/asm/setup.h create mode 100644 arch/riscv/include/asm/smp.h create mode 100644 arch/riscv/include/asm/spinlock.h create mode 100644 arch/riscv/include/asm/spinlock_types.h create mode 100644 arch/riscv/include/asm/string.h create mode 100644 arch/riscv/include/asm/switch_to.h create mode 100644 arch/riscv/include/asm/syscall.h create mode 100644 arch/riscv/include/asm/syscalls.h create mode 100644 arch/riscv/include/asm/thread_info.h create mode 100644 arch/riscv/include/asm/timex.h create mode 100644 arch/riscv/include/asm/tlb.h create mode 100644 arch/riscv/include/asm/tlbflush.h create mode 100644 arch/riscv/include/asm/uaccess.h create mode 100644 arch/riscv/include/asm/unistd.h create mode 100644 arch/riscv/include/asm/vdso.h create mode 100644 arch/riscv/include/asm/word-at-a-time.h create mode 100644 arch/riscv/include/uapi/asm/Kbuild create mode 100644 arch/riscv/include/uapi/asm/auxvec.h create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h create mode 100644 arch/riscv/include/uapi/asm/byteorder.h create mode 100644 arch/riscv/include/uapi/asm/elf.h create mode 100644 arch/riscv/include/uapi/asm/ptrace.h create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h create mode 100644 arch/riscv/include/uapi/asm/siginfo.h create mode 100644 arch/riscv/include/uapi/asm/unistd.h
arch/riscv/include/asm/Kbuild new file +60 -0
@@ -0,0 +1,60 @@ +generic-y += bugs.h +generic-y += cacheflush.h +generic-y += checksum.h +generic-y += clkdev.h +generic-y += cputime.h +generic-y += current.h +generic-y += div64.h +generic-y += dma.h +generic-y += emergency-restart.h +generic-y += errno.h +generic-y += exec.h +generic-y += fb.h +generic-y += fcntl.h +generic-y += ftrace.h +generic-y += futex.h +generic-y += hardirq.h +generic-y += hash.h +generic-y += hw_irq.h +generic-y += ioctl.h +generic-y += ioctls.h +generic-y += ipcbuf.h +generic-y += irq_regs.h +generic-y += irq_work.h +generic-y += kdebug.h +generic-y += kmap_types.h +generic-y += kvm_para.h +generic-y += local.h +generic-y += mm-arch-hooks.h +generic-y += mman.h +generic-y += module.h +generic-y += msgbuf.h +generic-y += mutex.h +generic-y += param.h +generic-y += percpu.h +generic-y += poll.h +generic-y += posix_types.h +generic-y += preempt.h +generic-y += resource.h +generic-y += scatterlist.h +generic-y += sections.h +generic-y += sembuf.h +generic-y += shmbuf.h +generic-y += shmparam.h +generic-y += signal.h +generic-y += socket.h +generic-y += sockios.h +generic-y += stat.h +generic-y += statfs.h +generic-y += swab.h +generic-y += termbits.h +generic-y += termios.h +generic-y += topology.h +generic-y += trace_clock.h +generic-y += types.h +generic-y += ucontext.h +generic-y += unaligned.h +generic-y += user.h +generic-y += vga.h +generic-y += vmlinux.lds.h +generic-y += xor.h
arch/riscv/include/asm/asm-offsets.h new file +1 -0
@@ -0,0 +1 @@ +#include <generated/asm-offsets.h>
arch/riscv/include/asm/asm.h new file +65 -0
65 lines not on this page · raw message
arch/riscv/include/asm/atomic.h new file +349 -0
349 lines not on this page · raw message
arch/riscv/include/asm/atomic64.h new file +355 -0
355 lines not on this page · raw message
arch/riscv/include/asm/barrier.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Based on arch/arm/include/asm/barrier.h +* +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_H + +#ifndef __ASSEMBLY__ + +#define nop () __asm__ __volatile__ ("nop") + +#define mb () __asm__ __volatile__ ("fence" : : : "memory") + +#include <asm-generic/barrier.h> + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_BARRIER_H */
arch/riscv/include/asm/bitops.h new file +229 -0
229 lines not on this page · raw message
arch/riscv/include/asm/bug.h new file +81 -0
81 lines not on this page · raw message
arch/riscv/include/asm/cache.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2017 Chen Liqin <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#endif /* _ASM_RISCV_CACHE_H */
arch/riscv/include/asm/cacheflush.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_CACHEFLUSH_H +#define _ASM_RISCV_CACHEFLUSH_H + +#include <asm-generic/cacheflush.h> + +#undef flush_icache_range +#undef flush_icache_user_range + +static inline void local_flush_icache_all (void ) +{ + asmvolatile ("fence.i" :::"memory" ); +} + +#ifndef CONFIG_SMP + +#define flush_icache_range (start, end) local_flush_icache_all() +#define flush_icache_user_range (vma, pg, addr, len) local_flush_icache_all() + +#else /* CONFIG_SMP */ + +#define flush_icache_range (start, end) sbi_remote_fence_i(0) +#define flush_icache_user_range (vma, pg, addr, len) sbi_remote_fence_i(0) + +#endif /* CONFIG_SMP */ + +#endif /* _ASM_RISCV_CACHEFLUSH_H */
arch/riscv/include/asm/cmpxchg.h new file +125 -0
125 lines not on this page · raw message
arch/riscv/include/asm/csr.h new file +126 -0
126 lines not on this page · raw message
arch/riscv/include/asm/delay.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 2009 Chen Liqin <[email protected]> +* Copyright (C) 2016 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_DELAY_H +#define _ASM_RISCV_DELAY_H + +extern unsigned long timebase; + +#define udelay udelay +extern void udelay (unsigned long usecs); + +#define ndelay ndelay +extern void ndelay (unsigned long nsecs); + +extern void __delay (unsigned long cycles); + +#endif /* _ASM_RISCV_DELAY_H */
arch/riscv/include/asm/device.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (C) 2016 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + + +#ifndef _ASM_RISCV_DEVICE_H +#define _ASM_RISCV_DEVICE_H + +#include <linux/sysfs.h> + +struct dev_archdata { +struct dma_map_ops *dma_ops; +}; + +struct pdev_archdata { +}; + +#endif /* _ASM_RISCV_DEVICE_H */
arch/riscv/include/asm/dma-mapping.h new file +61 -0
61 lines not on this page · raw message
arch/riscv/include/asm/elf.h new file +83 -0
83 lines not on this page · raw message
arch/riscv/include/asm/io.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> + +#ifdef __KERNEL__ + +#ifdef CONFIG_MMU + +extern void __iomem *ioremap (phys_addr_t offset,unsigned long size); + +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size)) + +extern void iounmap (void __iomem *addr); + +#endif /* CONFIG_MMU */ + +#endif /* __KERNEL__ */ + +#endif /* _ASM_RISCV_IO_H */
arch/riscv/include/asm/irq.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_IRQ_H +#define _ASM_RISCV_IRQ_H + +#define NR_IRQS 0 + +#define INTERRUPT_CAUSE_SOFTWARE 1 +#define INTERRUPT_CAUSE_TIMER 5 +#define INTERRUPT_CAUSE_EXTERNAL 9 + +void riscv_timer_interrupt (void ); + +#include <asm-generic/irq.h> + +/* The value of csr sie before init_traps runs (core is up) */ +DECLARE_PER_CPU (atomic_long_t, riscv_early_sie); + +#endif /* _ASM_RISCV_IRQ_H */
arch/riscv/include/asm/irqflags.h new file +64 -0
64 lines not on this page · raw message
arch/riscv/include/asm/kprobes.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + + +#ifndef ASM_RISCV_KPROBES_H +#define ASM_RISCV_KPROBES_H + +#ifdef CONFIG_KPROBES +#error "RISC-V doesn't skpport CONFIG_KPROBES" +#endif + +#endif
arch/riscv/include/asm/linkage.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2015 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_LINKAGE_H +#define _ASM_RISCV_LINKAGE_H + +#define __ALIGN .balign 4 +#define __ALIGN_STR ".balign 4" + +#endif /* _ASM_RISCV_LINKAGE_H */
arch/riscv/include/asm/mmu.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + + +#ifndef _ASM_RISCV_MMU_H +#define _ASM_RISCV_MMU_H + +#ifndef __ASSEMBLY__ + +typedef struct { +void *vdso; +}mm_context_t ; + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_MMU_H */
arch/riscv/include/asm/mmu_context.h new file +70 -0
70 lines not on this page · raw message
arch/riscv/include/asm/page.h new file +138 -0
138 lines not on this page · raw message
arch/riscv/include/asm/pci.h new file +51 -0
51 lines not on this page · raw message
arch/riscv/include/asm/pgalloc.h new file +126 -0
126 lines not on this page · raw message
arch/riscv/include/asm/pgtable-32.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_PGTABLE_32_H +#define _ASM_RISCV_PGTABLE_32_H + +#include <asm-generic/pgtable-nopmd.h> +#include <linux/const.h> + +/* Size of region mapped by a page global directory */ +#define PGDIR_SHIFT 22 +#define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) + +#endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h new file +85 -0
85 lines not on this page · raw message
arch/riscv/include/asm/pgtable-bits.h new file +49 -0
49 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h new file +426 -0
426 lines not on this page · raw message
arch/riscv/include/asm/processor.h new file +103 -0
103 lines not on this page · raw message
arch/riscv/include/asm/ptrace.h new file +117 -0
35 lines not on this page · raw message
arch/riscv/include/asm/sbi.h new file +101 -0
101 lines not on this page · raw message
arch/riscv/include/asm/serial.h new file +43 -0
43 lines not on this page · raw message
arch/riscv/include/asm/setup.h new file +20 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/smp.h new file +42 -0
42 lines not on this page · raw message
arch/riscv/include/asm/spinlock.h new file +156 -0
156 lines not on this page · raw message
arch/riscv/include/asm/spinlock_types.h new file +34 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/string.h new file +31 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/switch_to.h new file +71 -0
71 lines not on this page · raw message
arch/riscv/include/asm/syscall.h new file +91 -0
91 lines not on this page · raw message
arch/riscv/include/asm/syscalls.h new file +26 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/thread_info.h new file +103 -0
103 lines not on this page · raw message
arch/riscv/include/asm/timex.h new file +55 -0
55 lines not on this page · raw message
arch/riscv/include/asm/tlbflush.h new file +95 -0
95 lines not on this page · raw message
arch/riscv/include/asm/uaccess.h new file +455 -0
455 lines not on this page · raw message
arch/riscv/include/asm/unistd.h new file +17 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/vdso.h new file +32 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/asm/word-at-a-time.h new file +56 -0
56 lines not on this page · raw message
arch/riscv/include/uapi/asm/Kbuild new file +10 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/auxvec.h new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/bitsperlong.h new file +25 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/byteorder.h new file +23 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/elf.h new file +83 -0
83 lines not on this page · raw message
arch/riscv/include/uapi/asm/ptrace.h new file +69 -0
69 lines not on this page · raw message
arch/riscv/include/uapi/asm/sigcontext.h new file +30 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/siginfo.h new file +24 -0
Lines of this file are not shown. View the raw message.
arch/riscv/include/uapi/asm/unistd.h new file +23 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.0
Part of the diff is not shown here. View the raw message.
Arnd Bergmann
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 11 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +11
-0+/** +* atomic_read - read atomic variable +* @v: pointer of type atomic_t +* +* Atomically reads the value of @v. +*/ +static inline int atomic_read (const atomic_t *v) +{ +return *((volatile int *)(&(v->counter))); +} +/**
arch/riscv/include/asm/atomic.h line 42
Quoted 10 lines
arch/riscv/include/asm/atomic.h new file +10
-0+* atomic_set - set atomic variable +* @v: pointer of type atomic_t +* @i: required value +* +* Atomically sets the value of @v to @i. +*/ +static inline void atomic_set (atomic_t *v,int i) +{ + v->counter = i; +}
These commonly use READ_ONCE() and WRITE_ONCE, I'd recommend doing the same here to be on the safe side.
Quoted 12 lines
arch/riscv/include/asm/atomic64.h new file +12
-0+/** +* atomic64_read - read atomic64 variable +* @v: pointer of type atomic64_t +* +* Atomically reads the value of @v. +*/ +static inline s64 atomic64_read (const atomic64_t *v) +{ +return *((volatile long *)(&(v->counter))); +} + +/**
arch/riscv/include/asm/atomic64.h line 43
Quoted 10 lines
arch/riscv/include/asm/atomic64.h new file +10
-0+* atomic64_set - set atomic64 variable +* @v: pointer to type atomic64_t +* @i: required value +* +* Atomically sets the value of @v to @i. +*/ +static inline void atomic64_set (atomic64_t *v,s64 i) +{ + v->counter = i; +}
same here
arch/riscv/include/asm/bug.h line 25
Quoted 13 lines
arch/riscv/include/asm/bug.h new file +5
-0@@ -0,0 +1,81 @@ +/* +#ifndef _ASM_RISCV_BUG_H +#define _ASM_RISCV_BUG_H +#ifdef CONFIG_GENERIC_BUG +#define __BUG_INSN _AC(0x00100073, UL) /* sbreak */
Please have a look at the modifications I did for !CONFIG_BUG on x86, arm and arm64. It's generally better to define BUG to a trap even when CONFIG_BUG is disabled, otherwise you run into undefined behavior in some code, and gcc will print annoying warnings about that.
arch/riscv/include/asm/bug.h
Quoted 6 lines
arch/riscv/include/asm/bug.h new file +6
-0+#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
Is this the only valid cache line size on riscv, or just the largest one that is allowed?
arch/riscv/include/asm/bug.h
Quoted 10 lines
arch/riscv/include/asm/bug.h new file +10
-0+ +static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +return (dma_addr_t )paddr; +} + +static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +{ +return (phys_addr_t )dev_addr; +}
What do you need these for? If possible, try to remove them.
arch/riscv/include/asm/bug.h
Quoted 9 lines
arch/riscv/include/asm/bug.h new file +9
-0+static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction dir) +{ +/* +* RISC-V is cache-coherent, so this is mostly a no-op. +* However, we do need to ensure that dma_cache_sync() +* enforces order, hence the mb(). +*/ +mb (); +}
Do you even support any drivers that use
dma_alloc_noncoherent()/dma_cache_sync()?
I would guess you can just leave this out.
arch/riscv/include/asm/io.h line 18
Quoted 11 lines
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h>
I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Also, most architectures require to some synchronization after a non-relaxed readl() to prevent prefetching of DMA buffers, and before a writel() to flush write buffers when a DMA gets triggered.
arch/riscv/include/asm/io.h line 28
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9
-0+#ifdef __KERNEL__ + +#ifdef CONFIG_MMU + +extern void __iomem *ioremap (phys_addr_t offset,unsigned long size); + +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size))
Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and ioremap_wc() gets used for by memremap() for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags
Quoted 18 lines
arch/riscv/include/asm/serial.h new file +12
-0@@ -0,0 +1,43 @@ +/* +* Copyright (C) 2014 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details.
arch/riscv/include/asm/serial.h line 22
Quoted 10 lines
arch/riscv/include/asm/serial.h new file +10
-0+*/ + +#ifndef _ASM_RISCV_SERIAL_H +#define _ASM_RISCV_SERIAL_H + +/* +* FIXME: interim serial support for riscv-qemu +* +* Currently requires that the emulator itself create a hole at addresses +* 0x3f8 - 0x3ff without looking through page tables.
This sounds like something we want to fix in qemu and not have in the mainline kernel. In particular, something seems really wrong if your inb()/outb() get remapped to physical CPU address 0+offset.
Quoted 16 lines
arch/riscv/include/asm/setup.h new file +10
-0@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
arch/riscv/include/asm/setup.h line 20
Quoted 10 lines
arch/riscv/include/asm/setup.h new file +10
-0+* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_SETUP_H +#define _ASM_RISCV_SETUP_H + +#include <asm-generic/setup.h> + +#endif /* _ASM_RISCV_SETUP_H */
Can you remove this file and add it to asm/Kbuild as generic-y instead?
Quoted 4 lines
arch/riscv/include/asm/setup.h new file +4
-0+/* +* low level task data that entry.S needs immediate access to +* - this struct should fit entirely inside of one cache line +* - this struct resides at the bottom of the supervisor stack
arch/riscv/include/asm/setup.h
Quoted 10 lines
arch/riscv/include/asm/setup.h new file +10
-0+* - if the members of this struct changes, the assembly constants +* in asm-offsets.c must be updated accordingly +*/ +struct thread_info { +struct task_struct *task;/* main task structure */ +unsigned long flags;/* low level flags */ +__u32 cpu;/* current CPU */ +int preempt_count;/* 0 => preemptable, <0 => BUG */ +mm_segment_t addr_limit; +};
Please see 15f4eae70d36 ("x86: Move thread_info into task_struct") and try to do the same.
arch/riscv/include/asm/setup.h
Quoted 11 lines
arch/riscv/include/asm/setup.h new file +11
-0+#else /* !CONFIG_MMU */ + +static inline void flush_tlb_all (void ) +{ +BUG (); +} + +static inline void flush_tlb_mm (struct mm_struct *mm) +{ +BUG (); +}
The NOMMU support is rather incomplete and CONFIG_MMU is hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.
Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +0
-0
arch/riscv/include/uapi/asm/Kbuild line 10
Quoted 10 lines
arch/riscv/include/uapi/asm/Kbuild new file +10
-0@@ -0,0 +1,10 @@ +# UAPI Header export list +include include/uapi/asm-generic/Kbuild.asm + +header-y += auxvec.h +header-y += bitsperlong.h +header-y += byteorder.h +header-y += ptrace.h +header-y += sigcontext.h +header-y += siginfo.h +header-y += unistd.h
Please seefcc8487d477a ("uapi: export all headers under uapi directories")
and adapt the file accordingly
arch/riscv/include/uapi/asm/Kbuild
Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +6
-0+#include <asm-generic/unistd.h> + +#define __NR_sysriscv __NR_arch_specific_syscall +#ifndef __riscv_atomic +__SYSCALL(__NR_sysriscv, sys_sysriscv) +#endif
Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on __riscv_atomic rather than the Kconfig symbol?
Arnd
Re: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 10 lines · Arnd Bergmann
arch/riscv/include/asm/io.h line 18
Quoted 2 lines
arch/riscv/include/asm/io.h new file +2
-0+ +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.
Right, I was about to comment on that one.
The question Palmer is about the ordering semantics of non-cached storage.
What kind of ordering is provided architecturally ? Especially between cachable and non-cachable loads and stores ?
Also, you have PCIe right ? What is the behaviour of MSIs ?
Does your HW provide a guarantee that in the case of a series of DMA writes to memory by a device followed by an MSI, the CPU getting the MSI will only get it after all the previous DMA writes have reached coherency ? (Unlike LSIs where the driver is required to do an MMIO read from the device, MSIs are expected to be ordered with data).
Another things with the read*() accessors. It's not uncommon for a driver to do:
writel(1, reset_reg); readl(reset_reg); /* flush posted writes */ udelay(10); writel(0, reset_reg);
Now, in the above case, what can typically happen if you aren't careful is that the readl which is intended to "push" the previous writel, will not actually do its job because the return value hasn't been "consumed" by the processor. Thus, the CPU will stick that on some kind of load queue and won't actually wait for the return value before hitting the delay loop.
Thus you might end up in a situation where the writel of 1 to the device is itself reaching the device way after you started the delay loop, and thus end up violating the delay requirement of the HW.
On powerpc we solve that by using a special instruction construct inside the read* accessors that prevents the CPU from executing subsequent instructions until the read value has been returned.
You may want to consider something similar.
Cheers,
Ben.
Palmer Dabbelt
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 8 lines · On Tue, 23 May 2017 14:23:50 PDT (-0700), [email protected] wrote:
Quoted 7 lines · Arnd Bergmann
arch/riscv/include/asm/io.h line 18
Quoted 2 lines
arch/riscv/include/asm/io.h new file +2
-0+ +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 5 lines
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.Right, I was about to comment on that one.
Well, you're both correct: what was there just isn't correct. Our implementations were safe because they don't have aggressive MMIO systems, but that won't remain true for long.
I've gone ahead and added a proper IO implementation patterned on arm64. It'll be part of the v2 patch set. Here's the bulk of the patch, if you're curious
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
Quoted 5 lines
The question Palmer is about the ordering semantics of non-cached storage.
What kind of ordering is provided architecturally ? Especially between cachable and non-cachable loads and stores ?
The memory model on RISC-V is pretty weak. Without fences there are no ordering constraints. We provide 2 "ordering spaces" (an odd name I just made up, there's one address space): the IO space and the regular memory space. The base RISC-V ordering primitive is a fence, which takes a predecessor set and successor set. Fences can look like
fence IORW,IORW
where the left side is the predecessor set and the right side is the successor set. The fence enforces ordering between any operations in the two sets: all operations in the predecessor set must be globally visible before any operation in the successor set becomes visible anywhere.
For example, if you're emitting a DMA transaction you'd have to do something like
build_message_in_memory()
fence w,o
set_control_register()
with the fence ensuring all the memory writes are visible before the control register write.
More information can be found in the ISA manuals
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-user-2.2/riscv-spec-v2.2.pdf
https://github.com/riscv/riscv-isa-manual/releases/download/riscv-priv-1.10/riscv-privileged-v1.10.pdf
Quoted 7 lines
Also, you have PCIe right ? What is the behaviour of MSIs ?
Does your HW provide a guarantee that in the case of a series of DMA writes to memory by a device followed by an MSI, the CPU getting the MSI will only get it after all the previous DMA writes have reached coherency ? (Unlike LSIs where the driver is required to do an MMIO read from the device, MSIs are expected to be ordered with data).
We do have PCIe, but I'm not particularly familiar with it as I haven't spent any time hacking on our PCIe hardware or driver. My understanding here is that PCIe defines that MSIs must not be reordered before the DMA writes, so the implementation is required to enforce this ordering. Thus it's a problem for the PCIe controller implementation (which isn't covered by RISC-V) and therefor doesn't need any ordering enforced by the driver.
If I'm correct in the assumption that the hardware is required to enforce these ordering constraints then I think this isn't a RISC-V issue. I'll go bug our PCIe guys to make sure everything is kosher in that case, but it's an ordering constraint that is possible to enforce in our coherence protocol so it's not a fundamental problem (and just an implementation one at that).
If the hardware isn't required to enforce the ordering, then we'll need a fence before handling the data.
Quoted 19 lines
Another things with the read*() accessors. It's not uncommon for a driver to do:
writel(1, reset_reg); readl(reset_reg); /* flush posted writes */ udelay(10); writel(0, reset_reg);Now, in the above case, what can typically happen if you aren't careful is that the readl which is intended to "push" the previous writel, will not actually do its job because the return value hasn't been "consumed" by the processor. Thus, the CPU will stick that on some kind of load queue and won't actually wait for the return value before hitting the delay loop.
Thus you might end up in a situation where the writel of 1 to the device is itself reaching the device way after you started the delay loop, and thus end up violating the delay requirement of the HW.
Quoted 5 lines
On powerpc we solve that by using a special instruction construct inside the read* accessors that prevents the CPU from executing subsequent instructions until the read value has been returned.
You may want to consider something similar.
Ooh, that's a fun one :). I bugged Andrew (the ISA wizard), and this might
require some clarification in the ISA manual. The code we emit will look something like
fence io,o
st 1, RESET_REG
ld RESET_REG
fence o,io
loop:
rdtime
blt loop
fence io,o
st 0, RESET_REG
Since the fences just enforce ordering between the loads and stores, there's nothing that prevents the processor from releasing the store before the delay loop completes. I think we might be safe here because you're not allowed to make speculative writes visible, but arguably that's not a speculative write because you can predict the timer will keep increasing. The distinction is somewhat academic, though: I'm not sure what purpose that very specific sort of predictor would have aside from breaking existing code.
This issue of "how is time ordered" has come up a handful of times, most of which don't have the loop. The idea of adding the result rdtime instruction to the IO space. I've opened a spec bug
https://github.com/riscv/riscv-isa-manual/issues/78
Thanks!
Palmer Dabbelt
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
In reply to Arnd BergmannQuoted 17 lines · Arnd Bergmann
Quoted 16 lines · Palmer Dabbelt
arch/riscv/include/asm/atomic.h new file +16
-0+/** +* atomic_read - read atomic variable +* @v: pointer of type atomic_t +* +* Atomically reads the value of @v. +*/ +static inline int atomic_read (const atomic_t *v) +{ +return *((volatile int *)(&(v->counter))); +} +/** +* atomic_set - set atomic variable +* @v: pointer of type atomic_t +* @i: required value +* +* Atomically sets the value of @v to @i.
Quoted 8 lines
arch/riscv/include/asm/atomic.h line 42
Quoted 5 lines
+ */
arch/riscv/include/asm/atomic.h new file +4
-0+static inline void atomic_set (atomic_t *v,int i) +{ + v->counter = i; +}These commonly use
READ_ONCE()andWRITE_ONCE, I'd recommend doing the same here to be on the safe side.
Makes sense. https://github.com/riscv/riscv-linux/commit/77647f9e4dccab68c69a212a63c9efe1db2b7b1c
Quoted 11 lines
Quoted 10 lines
arch/riscv/include/asm/bug.h new file +3
-0@@ -0,0 +1,81 @@ +/* +#ifndef _ASM_RISCV_BUG_H +#define _ASM_RISCV_BUG_H
Quoted 8 lines
arch/riscv/include/asm/bug.h line 25
Quoted 2 lines
arch/riscv/include/asm/bug.h new file +2
-0+#ifdef CONFIG_GENERIC_BUG +#define __BUG_INSN _AC(0x00100073, UL)/* sbreak */ Please have a look at the modifications I did for !CONFIG_BUG on x86, arm and arm64. It's generally better to define BUG to a trap even when
CONFIG_BUGis disabled, otherwise you run into undefined behavior in some code, and gcc will print annoying warnings about that.
OK, seems like a good thing. https://github.com/riscv/riscv-linux/commit/67db001653614c6555424b3812d7edfba12a6d4c
Quoted 9 lines
arch/riscv/include/asm/bug.h
Quoted 6 lines
arch/riscv/include/asm/bug.h new file +6
-0+#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)Is this the only valid cache line size on riscv, or just the largest one that is allowed?
The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.
We could always make this a Kconfig parameter.
Quoted 26 lines
arch/riscv/include/asm/bug.h
Quoted 10 lines
arch/riscv/include/asm/bug.h new file +10
-0+ +static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +{ +return (dma_addr_t )paddr; +} + +static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +{ +return (phys_addr_t )dev_addr; +}What do you need these for? If possible, try to remove them.
arch/riscv/include/asm/bug.h
Quoted 9 lines
arch/riscv/include/asm/bug.h new file +9
-0+static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction dir) +{ +/* +* RISC-V is cache-coherent, so this is mostly a no-op. +* However, we do need to ensure that dma_cache_sync() +* enforces order, hence the mb(). +*/ +mb (); +}Do you even support any drivers that use
dma_alloc_noncoherent()/dma_cache_sync()?
Quoted 1 line
I would guess you can just leave this out.
These must have been vestigial code, they appear safe to remove.
https://github.com/riscv/riscv-linux/commit/d1c88783d5ff66464a25173f7a4af139f0ebf5e2
Quoted 16 lines
arch/riscv/include/asm/io.h line 18
Quoted 11 lines
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.
Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
where I think the only odd thing is our definition of mmiowb
+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define __iormb() __asm__ __volatile__ ("fence i,io" : : : "memory");
+#define __iowmb() __asm__ __volatile__ ("fence io,o" : : : "memory");
+
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");
which I think is correct.
Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/io.h new file +8
-0+#ifdef __KERNEL__ + +#ifdef CONFIG_MMU + +extern void __iomem *ioremap (phys_addr_t offset,unsigned long size); + +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size))
Quoted 8 lines
Quoted 1 line
+#define
ioremap_wt(addr, size)ioremap((addr), (size))Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and
ioremap_wc()gets used for bymemremap()for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags
This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.
Quoted 24 lines
Quoted 24 lines
arch/riscv/include/asm/serial.h new file +18
-0@@ -0,0 +1,43 @@ +/* +* Copyright (C) 2014 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#ifndef _ASM_RISCV_SERIAL_H +#define _ASM_RISCV_SERIAL_H + +/*
Quoted 8 lines
arch/riscv/include/asm/serial.h line 22
Quoted 4 lines
arch/riscv/include/asm/serial.h new file +4
-0+* FIXME: interim serial support for riscv-qemu +* +* Currently requires that the emulator itself create a hole at addresses +* 0x3f8 - 0x3ff without looking through page tables. This sounds like something we want to fix in qemu and not have in the mainline kernel. In particular, something seems really wrong if your inb()/outb() get remapped to physical CPU address 0+offset.
Sorry, we had some hacks floating around for QEMU from before we actually had any devices interfaces working (ie, before device tree and proper MMIO support). I'll go through and drop these before v2.
Quoted 20 lines
Quoted 20 lines
arch/riscv/include/asm/setup.h new file +14
-0@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ +
Quoted 8 lines
arch/riscv/include/asm/setup.h line 20
Quoted 6 lines
arch/riscv/include/asm/setup.h new file +6
-0+#ifndef _ASM_RISCV_SETUP_H +#define _ASM_RISCV_SETUP_H + +#include <asm-generic/setup.h> + +#endif /* _ASM_RISCV_SETUP_H */ Can you remove this file and add it to asm/Kbuild as generic-y instead?
Yes. https://github.com/riscv/riscv-linux/commit/8f35ce93bd1230ac0cb4aa92e5673c61e50dd862
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/setup.h new file +9
-0+/* +* low level task data that entry.S needs immediate access to +* - this struct should fit entirely inside of one cache line +* - this struct resides at the bottom of the supervisor stack +* - if the members of this struct changes, the assembly constants +* in asm-offsets.c must be updated accordingly +*/ +struct thread_info { +struct task_struct *task;/* main task structure */
Quoted 8 lines
arch/riscv/include/asm/setup.h
Quoted 5 lines
arch/riscv/include/asm/setup.h new file +5
-0+unsigned long flags;/* low level flags */ +__u32 cpu;/* current CPU */ +int preempt_count;/* 0 => preemptable, <0 => BUG */ +mm_segment_t addr_limit; +};Please see
15f4eae70d36("x86: Movethread_infointotask_struct") and try to do the same.
OK, here's my attempt
https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd
Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)
"
This is patterned more off the arm64 move than the x86 one, since we still need to have at least addr_limit to emulate FS.
The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to task_struct. thread_info must be at a 0 offset from task_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP in task_struct, but those are really acting more as extra scratch space than pemanent storage.
"
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/setup.h new file +6
-0+#else /* !CONFIG_MMU */ + +static inline void flush_tlb_all (void ) +{ +BUG (); +}
Quoted 8 lines
arch/riscv/include/asm/setup.h
Quoted 5 lines
arch/riscv/include/asm/setup.h new file +5
-0+ +static inline void flush_tlb_mm (struct mm_struct *mm) +{ +BUG (); +}The NOMMU support is rather incomplete and
CONFIG_MMUis hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.
OK. I've left in the "#ifdef CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.
https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067
Quoted 20 lines
Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +0
-0arch/riscv/include/uapi/asm/Kbuild line 10
Quoted 10 lines
arch/riscv/include/uapi/asm/Kbuild new file +10
-0@@ -0,0 +1,10 @@ +# UAPI Header export list +include include/uapi/asm-generic/Kbuild.asm + +header-y += auxvec.h +header-y += bitsperlong.h +header-y += byteorder.h +header-y += ptrace.h +header-y += sigcontext.h +header-y += siginfo.h +header-y += unistd.hPlease see
fcc8487d477a("uapi: export all headers under uapi directories")
Quoted 1 line
and adapt the file accordingly
https://github.com/riscv/riscv-linux/commit/52c5e300b498742390434891db34f9dbacd082e9
Quoted 10 lines
arch/riscv/include/uapi/asm/Kbuild
Quoted 6 lines
arch/riscv/include/uapi/asm/Kbuild new file +6
-0+#include <asm-generic/unistd.h> + +#define __NR_sysriscv __NR_arch_specific_syscall +#ifndef __riscv_atomic +__SYSCALL(__NR_sysriscv, sys_sysriscv) +#endifPlease make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on
__riscv_atomicrather than theKconfigsymbol?
I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.
I can change this to two system calls: sysriscv_cmpxchg32 and sysriscv_cmpxchg64.
Arnd Bergmann
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 14 lines · Palmer Dabbelt
Quoted 12 lines · Arnd Bergmann
arch/riscv/include/asm/cache.h line 21
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/cache.h new file +6
-0+#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)Is this the only valid cache line size on riscv, or just the largest one that is allowed?
Quoted 7 lines
The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.
We could always make this a
Kconfigparameter.
The cache line size is used in a couple of places, let's go through the most common ones to see where that abstraction might be leaky and you actually get an architectural effect:
- On SMP machines, ____cacheline_aligned_in_smp is used to annotate data structures used in lockless algorithms, typically with one CPU writing to some members of a structure, and another CPU reading from it but not writing the same members. Depending on the architecture, having a larger actual alignment than L1_CACHE_BYTES will either lead to bad performance from cache line ping pong, or actual data corruption.
- On systems with DMA masters that are not fully coherent, ____cacheline_aligned is used to annotate data structures used for DMA buffers, to make sure that the cache maintenance operations in dma_sync_*_for_*() helpers don't corrup data outside of the DMA buffer. You don't seem to support noncoherent DMA masters or the cache maintenance operations required to use those, so this might not be a problem until someone adds an extension for those.
- Depending on the bus interconnect, a coherent DMA master might not be able to update partial cache lines, so you need the same annotation.
- The kmalloc() family of memory allocators aligns data to the cache line size, for both DMA and SMP synchronization above.
- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.
Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.
Quoted 28 lines
Quoted 16 lines
arch/riscv/include/asm/io.h line 18
Quoted 11 lines
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
where I think the only odd thing is our definition of mmiowb
Quoted 12 lines
+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define__iormb()__asm____volatile__("fence i,io" : : : "memory");
+#define__iowmb()__asm____volatile__("fence io,o" : : : "memory");
Looks ok, yes.
Quoted 3 lines
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");which I think is correct.
I can never remember what exactly this one does.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
arch/riscv/include/asm/io.h new file +8
-0+#ifdef __KERNEL__ + +#ifdef CONFIG_MMU + +extern void __iomem *ioremap (phys_addr_t offset,unsigned long size); + +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size))Quoted 8 lines
Quoted 1 line
+#define
ioremap_wt(addr, size)ioremap((addr), (size))Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and
ioremap_wc()gets used for bymemremap()for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags
Quoted 5 lines
This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.
Ok. Maybe add that as a comment above these definitions then.
Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9
-0+/* +* low level task data that entry.S needs immediate access to +* - this struct should fit entirely inside of one cache line +* - this struct resides at the bottom of the supervisor stack +* - if the members of this struct changes, the assembly constants +* in asm-offsets.c must be updated accordingly +*/ +struct thread_info { +struct task_struct *task;/* main task structure */ Quoted 8 lines
arch/riscv/include/asm/io.h
Quoted 5 lines
arch/riscv/include/asm/io.h new file +5
-0+unsigned long flags;/* low level flags */ +__u32 cpu;/* current CPU */ +int preempt_count;/* 0 => preemptable, <0 => BUG */ +mm_segment_t addr_limit; +};Please see
15f4eae70d36("x86: Movethread_infointotask_struct") and try to do the same.OK, here's my attempt
https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd
Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)
"
This is patterned more off the arm64 move than the x86 one, since we still need to have at leastaddr_limitto emulate FS.
Quoted 7 lines
The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to
task_struct.thread_infomust be at a 0 offset fromtask_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP intask_struct, but those are really acting more as extra scratch space than pemanent storage.
"
I haven't looked at all the details of the x86 patch, but it seems they decided to put the arch specific members into 'struct thread_struct' rather than 'struct thread_info', so I'd suggest you do the same here for consistency, unless there is a strong reason against doing it.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6
-0+#else /* !CONFIG_MMU */ + +static inline void flush_tlb_all (void ) +{ +BUG (); +}Quoted 8 lines
arch/riscv/include/asm/io.h
Quoted 5 lines
arch/riscv/include/asm/io.h new file +5
-0+ +static inline void flush_tlb_mm (struct mm_struct *mm) +{ +BUG (); +}The NOMMU support is rather incomplete and
CONFIG_MMUis hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.
Quoted 5 lines
OK. I've left in the "#ifdef
CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067
Ok.
Quoted 11 lines
Quoted 10 lines
arch/riscv/include/asm/io.h
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6
-0+#include <asm-generic/unistd.h> + +#define __NR_sysriscv __NR_arch_specific_syscall +#ifndef __riscv_atomic +__SYSCALL(__NR_sysriscv, sys_sysriscv) +#endif Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on
__riscv_atomicrather than theKconfigsymbol?
Quoted 6 lines
I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.
I can change this to two system calls:
sysriscv_cmpxchg32andsysriscv_cmpxchg64.
Sounds good.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 27 lines · Arnd Bergmann
Quoted 14 lines · Palmer Dabbelt
Quoted 12 lines · Arnd Bergmann
arch/riscv/include/asm/cache.h line 21
Quoted 6 lines · Palmer Dabbelt
arch/riscv/include/asm/cache.h new file +6
-0+#ifndef _ASM_RISCV_CACHE_H +#define _ASM_RISCV_CACHE_H + +#define L1_CACHE_SHIFT 6 + +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)Is this the only valid cache line size on riscv, or just the largest one that is allowed?
Quoted 7 lines
The RISC-V ISA manual doesn't actually mention caches anywhere, so there's no restriction on L1 cache line size (we tried to keep microarchitecture out of the ISA specification). We provide the actual cache parameters as part of the device tree, but it looks like this needs to be known staticly in some places so we can't use that everywhere.
We could always make this a
Kconfigparameter.The cache line size is used in a couple of places, let's go through the most common ones to see where that abstraction might be leaky and you actually get an architectural effect:
Quoted 6 lines
- On SMP machines,
____cacheline_aligned_in_smpis used to annotate data structures used in lockless algorithms, typically with one CPU writing to some members of a structure, and another CPU reading from it but not writing the same members. Depending on the architecture, having a larger actual alignment thanL1_CACHE_BYTESwill either lead to bad performance from cache line ping pong, or actual data corruption.
On RISC-V it's just a performance problem, so at least it's not catastrophic.
Quoted 11 lines
- On systems with DMA masters that are not fully coherent,
____cacheline_alignedis used to annotate data structures used for DMA buffers, to make sure that the cache maintenance operations in dma_sync_*_for_*() helpers don't corrup data outside of the DMA buffer. You don't seem to support noncoherent DMA masters or the cache maintenance operations required to use those, so this might not be a problem until someone adds an extension for those.- Depending on the bus interconnect, a coherent DMA master might not be able to update partial cache lines, so you need the same annotation.
Well, our (SiFive's) bus is easy to master so hopefully we won't end up doing that. There is, of course, the rest of the world -- but that's just a bridge we'll have to cross later (if such an implementation arises).
Quoted 2 lines
- The
kmalloc()family of memory allocators aligns data to the cache line size, for both DMA and SMP synchronization above.
Ya, but luckily just a performance problem on RISC-V.
Quoted 5 lines
- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.
We actually have an implicit prefetch (loads to x0, the zero register), but it still has all the load side-effects so nothing uses it.
Quoted 3 lines
Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.
I bugged our L1 guy and he says 64-byte lines are a bit of a magic number because of how they line up with DIMMs. Since there's no spec to define this, there's no correct answer. I'd be amenable to making this a Kconfig option, but I think we'll leave it alone for now. It does match the extant implementations.
Quoted 41 lines
Quoted 28 lines
Quoted 16 lines
arch/riscv/include/asm/io.h line 18
Quoted 11 lines
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
where I think the only odd thing is our definition of mmiowb
Quoted 12 lines
+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define__iormb()__asm____volatile__("fence i,io" : : : "memory");
+#define__iowmb()__asm____volatile__("fence io,o" : : : "memory");
Quoted 7 lines
Looks ok, yes.
Quoted 3 lines
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");which I think is correct.
I can never remember what exactly this one does.
I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by
https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to use mmiowb()?
AFAICT, they're both right. Generally, mmiowb() should be used prior to unlock in a critical section whose last PIO operation is a writeX.
Thus, I think the actual fence should be at least
fence o,w
Documentation/memory-barries.txt says
"
The Linux kernel also has a special barrier for use with memory-mapped I/O writes:
mmiowb();
This is a variation on the mandatory write barrier that causes writes to weakly ordered I/O regions to be partially ordered. Its effects may go beyond the CPU->Hardware interface and actually affect the hardware at some level.
See the subsection "Acquires vs I/O accesses" for more information. "
"
ACQUIRES VS I/O ACCESSES
------------------------
Under certain circumstances (especially involving NUMA), I/O accesses within two spinlocked sections on two different CPUs may be seen as interleaved by the PCI bridge, because the PCI bridge does not necessarily participate in the cache-coherence protocol, and is therefore incapable of issuing the required read memory barriers.
For example:
CPU 1 CPU 2 =============================== =============================== spin_lock(Q) writel(0, ADDR) writel(1, DATA); spin_unlock(Q); spin_lock(Q); writel(4, ADDR); writel(5, DATA); spin_unlock(Q);
may be seen by the PCI bridge as follows:
STORE *ADDR = 0, STORE *ADDR = 4, STORE *DATA = 1, STORE *DATA = 5
which would probably cause the hardware to malfunction.
What is necessary here is to intervene with an mmiowb() before dropping the spinlock, for example:
CPU 1 CPU 2 =============================== =============================== spin_lock(Q) writel(0, ADDR) writel(1, DATA); mmiowb(); spin_unlock(Q); spin_lock(Q); writel(4, ADDR); writel(5, DATA); mmiowb(); spin_unlock(Q);
this will ensure that the two stores issued on CPU 1 appear at the PCI bridge before either of the stores issued on CPU 2.
Furthermore, following a store by a load from the same device obviates the need for the mmiowb(), because the load forces the store to complete before the load is performed:
CPU 1 CPU 2 =============================== =============================== spin_lock(Q) writel(0, ADDR) a = readl(DATA); spin_unlock(Q); spin_lock(Q); writel(4, ADDR); b = readl(DATA); spin_unlock(Q);
See Documentation/driver-api/device-io.rst for more information. "
which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
arch/riscv/include/asm/io.h line 28
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9
-0+#ifdef __KERNEL__ + +#ifdef CONFIG_MMU + +extern void __iomem *ioremap (phys_addr_t offset,unsigned long size); + +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size))Is this a hard architecture limitation? Normally you really want write-combined access on frame buffer memory and a few other cases for performance reasons, and
ioremap_wc()gets used for bymemremap()for addressing RAM in some cases, and you normally don't want to have PTEs for the same memory using cached and uncached page flags
Quoted 7 lines
Quoted 5 lines
This is currently an architecture limitation. In RISC-V these properties are known as PMAs (Physical Memory Attributes). While the supervisor spec mentions PMAs, it doesn't provide a mechanism to read or write them so they are essentially unspecified. PMAs will be properly defined as part of the platform specification, which isn't written yet.
Ok. Maybe add that as a comment above these definitions then.
OK.
Quoted 37 lines
Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
arch/riscv/include/asm/io.h new file +9
-0+/* +* low level task data that entry.S needs immediate access to +* - this struct should fit entirely inside of one cache line +* - this struct resides at the bottom of the supervisor stack +* - if the members of this struct changes, the assembly constants +* in asm-offsets.c must be updated accordingly +*/ +struct thread_info { +struct task_struct *task;/* main task structure */ Quoted 8 lines
arch/riscv/include/asm/io.h
Quoted 5 lines
arch/riscv/include/asm/io.h new file +5
-0+unsigned long flags;/* low level flags */ +__u32 cpu;/* current CPU */ +int preempt_count;/* 0 => preemptable, <0 => BUG */ +mm_segment_t addr_limit; +};Please see
15f4eae70d36("x86: Movethread_infointotask_struct") and try to do the same.OK, here's my attempt
https://github.com/riscv/riscv-linux/commit/c618553e7aa65c85564a5d0a868ec7e6cf634afd
Since there's some actual meat, I left a commit message (these are more just notes for me for my v2, I'll be squashing everything)
"
This is patterned more off the arm64 move than the x86 one, since we still need to have at leastaddr_limitto emulate FS.Quoted 7 lines
The patch itself changes sscratch from holding SP to holding TP, which contains a pointer to
task_struct.thread_infomust be at a 0 offset fromtask_struct, but it looks like that's already enforced with a big comment. We now store both the user and kernel SP intask_struct, but those are really acting more as extra scratch space than pemanent storage.
"
Quoted 4 lines
I haven't looked at all the details of the x86 patch, but it seems they decided to put the arch specific members into 'struct
thread_struct' rather than 'structthread_info', so I'd suggest you do the same here for consistency, unless there is a strong reason against doing it.
We actually can't put them in "struct thread_struct" in a sane manner. On context switches on RISC-V there are no register saved, instead we use the instructions
csrrw REG, sscratch, REG
which swaps some register (used to be sp, now tp) with the "sscratch" CSR (a register only visible to the supervisor). At this point we only have one register to work with in order to save the user state. Since "struct thread_info" is 0-offset from "struct task_struct", we're guaranteed to be able to access it using our one addressing mode (a 12-bit signed constant offset from a register).
Unfortunately, "struct thread_struct" is at a potentially large offset from the saved TP. We could do something silly like
addi tp, tp, OFFSET_1
addi tp, tp, OFFSET_2
addi tp, tp, OFFSET_3
but for an "allyesconfig" we end up with offsets of about 9KiB, which would require 4 additional instructions to find "struct thread_struct". While this is possible, I'd prefer to avoid the extra cycles. We usually handle long immediate with a two-instruction sequence
li REG, IMM31-12 (loads the high bits of REG, zeroing the low bits) addi REG, REG, IMM11-0 (loads the low bits of REG, leaving the high bits alone)
but there's no scratch register here so we can't use that. We don't have a long-immediate-add instruction.
The arguments in x86 land for moving everything to "struct thread_struct" were that they always know it's in "struct task_struct", but since that's all we're supporting on RISC-V I don't think it counts. There were also discussions of eliminating "struct thread_info", but unless there's something at the start of "struct task_struct" then RISC-V will have to pay a bunch of cycles on a context switch.
Quoted 44 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6
-0+#else /* !CONFIG_MMU */ + +static inline void flush_tlb_all (void ) +{ +BUG (); +}Quoted 8 lines
arch/riscv/include/asm/io.h
Quoted 5 lines
arch/riscv/include/asm/io.h new file +5
-0+ +static inline void flush_tlb_mm (struct mm_struct *mm) +{ +BUG (); +}The NOMMU support is rather incomplete and
CONFIG_MMUis hard-enabled, so I'd just drop any !CONFIG_MMU #ifdefs.Quoted 5 lines
OK. I've left in the "#ifdef
CONFIG_MMU" blocks as the #ifdef/#endif doesn't really add any code, but I can go ahead and drop the #ifdef if you think that's better.https://github.com/riscv/riscv-linux/commit/e98ca23adfb9422bebc87cbfb58f70d4a63cf067
Ok.
Quoted 11 lines
Quoted 10 lines
arch/riscv/include/asm/io.h
Quoted 6 lines
arch/riscv/include/asm/io.h new file +6
-0+#include <asm-generic/unistd.h> + +#define __NR_sysriscv __NR_arch_specific_syscall +#ifndef __riscv_atomic +__SYSCALL(__NR_sysriscv, sys_sysriscv) +#endif Please make this a straight cmpxchg syscall and remove the multiplexer. Why does the definition depend on
__riscv_atomicrather than theKconfigsymbol?Quoted 6 lines
I think that was just an oversight: that's not the right switch. Either you or someone else pointed out some problems with this. There's going to be an interposer in the VDSO, and then we'll always enable the system call.
I can change this to two system calls:
sysriscv_cmpxchg32andsysriscv_cmpxchg64.Sounds good.
Arnd
Arnd Bergmann
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 17 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 2 lines · Palmer Dabbelt
Quoted 1 line · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
- Many architectures have cache line prefetch, flush, zero or copy instructions that are used for important performance optimizations but that are typically defined on a cacheline granularity. I don't think you currently have any of them, but it seems likely that there will be demand for them later.
We actually have an implicit prefetch (loads to x0, the zero register), but it still has all the load side-effects so nothing uses it.
Quoted 3 lines
Having a larger than necessary alignment can waste substantial amounts of memory for arrays of cache line aligned structures (typically per-cpu arrays), but otherwise should not cause harm.
Quoted 5 lines
I bugged our L1 guy and he says 64-byte lines are a bit of a magic number because of how they line up with DIMMs. Since there's no spec to define this, there's no correct answer. I'd be amenable to making this a
Kconfigoption, but I think we'll leave it alone for now. It does match the extant implementations.
Hmm, this sounds like a hole in the architecture definition: if you have an instruction that performs a prefetch (even one that is not easily usable), I would argue that the cache line size has become a feature of the architecture and is no longer strictly an implementation detail of the microarchitecture.
Regarding the memory interface, a lot of systems use two DIMMs on each memory channel for 128-bit parallel buses, and with LP-DDRx controllers, you might have a width as small as 16 bits.
Quoted 63 lines
Quoted 41 lines
Quoted 28 lines
Quoted 16 lines
arch/riscv/include/asm/io.h line 18
Quoted 11 lines
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
where I think the only odd thing is our definition of mmiowb
Quoted 12 lines
+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define__iormb()__asm____volatile__("fence i,io" : : : "memory");
+#define__iowmb()__asm____volatile__("fence io,o" : : : "memory");Quoted 7 lines
Looks ok, yes.
Quoted 3 lines
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");which I think is correct.
I can never remember what exactly this one does.
I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by
https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to usemmiowb()?
AFAICT, they're both right. Generally,mmiowb()should be used prior to unlock in a critical section whose last PIO operation is a writeX.Thus, I think the actual fence should be at least
fence o,w
...
Quoted 2 lines
which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.
This sounds reasonable according to the documentation, but with your longer explanation of the barriers, I think the __iormb/__iowmb definitions above are wrong. What you actually need I think is
void writel(u32 v, volatile void __iomem *addr)
{
asm volatile("fence w,o" : : : "memory");
writel_relaxed(v, addr);
}u32 readl(volatile void __iomem *addr)
{
u32 ret = readl_relaxed(addr);
asm volatile("fence i,r" : : : "memory");
return ret;
}to synchronize between DMA and I/O. The barriers you listed above in contrast appear to be directed at synchronizing I/O with other I/O. We normally assume that this is not required when you have subsequent MMIO accesses on the same device (on PCI) or the same address region (per ARM architecture and others). If you do need to enforce ordering between MMIO, you might even need to add those barriers in the relaxed version to be portable with drivers written for ARM SoCs:
void writel_relaxed(u32 v, volatile void __iomem *addr)
{
__raw_writel((__force u32)cpu_to_le32(v, addr)
asm volatile("fence o,io" : : : "memory");
}u32 readl_relaxed(volatile void __iomem *addr)
{
asm volatile("fence i,io" : : : "memory");
return le32_to_cpu((__force __le32)__raw_readl(addr));
}You then end up with a barrier before and after each regular readl/writel in order to synchronize both with DMA and MMIO instrictructions, and you still need the extre mmiowb() to synchronize against the spinlock.
My memory on mmiowb is still a bit cloudy, but I think we don't need that on ARM, and while PowerPC originally needed it, it is now implied by the spin_unlock(). If this is actually right, you might want to do the same here. Very few drivers actually use mmiowb(), but there might be more drivers that would need it if your spin_unlock() doesn't synchronize against writel() or writel_relaxed(). Maybe it the mmiowb() should really be implied by writel() but not writel_relaxed()? That might be sensible, but only if we do it the same way on powerpc, which currently doesn't have writel_relaxed() any more relaxed than writel()
Quoted 6 lines
The arguments in x86 land for moving everything to "struct
thread_struct" were that they always know it's in "structtask_struct", but since that's all we're supporting on RISC-V I don't think it counts. There were also discussions of eliminating "structthread_info", but unless there's something at the start of "structtask_struct" then RISC-V will have to pay a bunch of cycles on a context switch.
Ok. Since you have THREAD_INFO_IN_TASK, it probably doesn't matter too much then, it's just a bit inconsistent with the other architectures, but the effect is the same, so just do it the way that is more efficient for you.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 4/7] RISC-V: arch/riscv/include
Quoted 110 lines · Arnd Bergmann
Quoted 67 lines · Palmer Dabbelt
Quoted 44 lines · Arnd Bergmann
Quoted 30 lines · Palmer Dabbelt
Quoted 17 lines · Arnd Bergmann
arch/riscv/include/asm/io.h line 18
Quoted 11 lines · Palmer Dabbelt
arch/riscv/include/asm/io.h new file +4
-0@@ -0,0 +1,36 @@ +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm-generic/io.h> I would recommend providing your own {read,write}{b,w,l,q}{,_relaxed} helpers using inline assembly, to prevent the compiler for breaking up accesses into byte accesses.
Quoted 3 lines
Also, most architectures require to some synchronization after a non-relaxed
readl()to prevent prefetching of DMA buffers, and before awritel()to flush write buffers when a DMA gets triggered.Makes sense. These were all OK on existing implementations (as there's no writable PMAs, so all MMIO regions are strictly ordered), but that's not actually what the RISC-V ISA says. I patterned this on arm64
https://github.com/riscv/riscv-linux/commit/e200fa29a69451ef4d575076e4d2af6b7877b1fa
where I think the only odd thing is our definition of mmiowb
Quoted 12 lines
+/* IO barriers. These only fence on the IO bits because they're only required
+ * to order device access. We're defining mmiowb because our AMO instructions
+ * (which are used to implement locks) don't specify ordering. From Chapter 7
+ * of v2.2 of the user ISA:
+ * "The bits order accesses to one of the two address domains, memory or I/O,
+ * depending on which address domain the atomic instruction is accessing. No
+ * ordering constraint is implied to accesses to the other domain, and a FENCE
+ * instruction should be used to order across both domains."
+ */
+
+#define__iormb()__asm____volatile__("fence i,io" : : : "memory");
+#define__iowmb()__asm____volatile__("fence io,o" : : : "memory");Quoted 7 lines
Looks ok, yes.
Quoted 3 lines
+#define mmiowb() __asm__ __volatile__ ("fence io,io" : : : "memory");which I think is correct.
I can never remember what exactly this one does.
I can't find the reference again, but what I found said that if your atomics (or whatever's used for locking) don't stay ordered with your MMIO accesses, then you should define mmiowb to ensure ordering. I managed to screw this up, as there's no "w" in the successor set (to actually enforce the AMO ordering). This is somewhat confirmed by
https://lkml.org/lkml/2006/8/31/174
Subject: Re: When to usemmiowb()?
AFAICT, they're both right. Generally,mmiowb()should be used prior to unlock in a critical section whose last PIO operation is a writeX.Thus, I think the actual fence should be at least
fence o,w
...
Quoted 2 lines
which matches what's above. I think "fence o,w" is sufficient for a mmiowb on RISC-V. I'll make the change.
This sounds reasonable according to the documentation, but with your longer explanation of the barriers, I think the __iormb/__iowmb definitions above are wrong. What you actually need I think is
void
writel(u32 v, volatile void __iomem *addr){ asm volatile("fence w,o" : : : "memory"); writel_relaxed(v, addr); }u32
readl(volatile void __iomem *addr){ u32 ret = readl_relaxed(addr); asm volatile("fence i,r" : : : "memory"); return ret; }to synchronize between DMA and I/O. The barriers you listed above in contrast appear to be directed at synchronizing I/O with other I/O. We normally assume that this is not required when you have subsequent MMIO accesses on the same device (on PCI) or the same address region (per ARM architecture and others). If you do need to enforce ordering between MMIO, you might even need to add those barriers in the relaxed version to be portable with drivers written for ARM SoCs:
void
writel_relaxed(u32 v, volatile void __iomem *addr){ __raw_writel((__force u32)cpu_to_le32(v, addr) asm volatile("fence o,io" : : : "memory"); }u32
readl_relaxed(volatile void __iomem *addr){ asm volatile("fence i,io" : : : "memory"); return le32_to_cpu((__force __le32)__raw_readl(addr)); }
Quoted 4 lines
You then end up with a barrier before and after each regular readl/writel in order to synchronize both with DMA and MMIO instrictructions, and you still need the extre
mmiowb()to synchronize against the spinlock.
Ah, thanks. I guess I just had those wrong. I'll fix the non-relaxed versions and add relaxed versions that have the fence.
Quoted 10 lines
My memory on mmiowb is still a bit cloudy, but I think we don't need that on ARM, and while PowerPC originally needed it, it is now implied by the
spin_unlock(). If this is actually right, you might want to do the same here. Very few drivers actually usemmiowb(), but there might be more drivers that would need it if yourspin_unlock()doesn't synchronize againstwritel()orwritel_relaxed(). Maybe it themmiowb()should really be implied bywritel()but notwritel_relaxed()? That might be sensible, but only if we do it the same way on powerpc, which currently doesn't havewritel_relaxed()any more relaxed thanwritel()
I like the idea of putting this in spin_unlock() better, particularly if PowerPC does it that way. I was worried that with mmiowb being such an esoteric thing that it would be wrong all over the place, this feels much better.
Palmer Dabbelt
maintainerPATCH 5/7 RISC-V: arch/riscv/lib
In reply to Palmer Dabbelt--- arch/riscv/lib/Makefile | 5 ++ arch/riscv/lib/ashldi3.c | 42 ++++++++++++++++ arch/riscv/lib/ashrdi3.c | 44 +++++++++++++++++ arch/riscv/lib/delay.c | 42 ++++++++++++++++ arch/riscv/lib/libgcc.h | 46 +++++++++++++++++ arch/riscv/lib/lshrdi3.c | 42 ++++++++++++++++ arch/riscv/lib/memcpy.S | 99 +++++++++++++++++++++++++++++++++++++ arch/riscv/lib/memset.S | 119 ++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/lib/uaccess.S | 125 +++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 564 insertions(+) create mode 100644 arch/riscv/lib/Makefile create mode 100644 arch/riscv/lib/ashldi3.c create mode 100644 arch/riscv/lib/ashrdi3.c create mode 100644 arch/riscv/lib/delay.c create mode 100644 arch/riscv/lib/libgcc.h create mode 100644 arch/riscv/lib/lshrdi3.c create mode 100644 arch/riscv/lib/memcpy.S create mode 100644 arch/riscv/lib/memset.S create mode 100644 arch/riscv/lib/uaccess.S
arch/riscv/lib/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +lib-y := delay.o memcpy.o memset.o uaccess.o + +ifeq ($(CONFIG_64BIT),) +lib-y += ashldi3.o ashrdi3.o lshrdi3.o +endif
arch/riscv/lib/ashldi3.c new file +42 -0
42 lines not on this page · raw message
arch/riscv/lib/ashrdi3.c new file +44 -0
44 lines not on this page · raw message
arch/riscv/lib/delay.c new file +42 -0
42 lines not on this page · raw message
arch/riscv/lib/libgcc.h new file +46 -0
46 lines not on this page · raw message
arch/riscv/lib/lshrdi3.c new file +42 -0
42 lines not on this page · raw message
arch/riscv/lib/memcpy.S new file +99 -0
99 lines not on this page · raw message
arch/riscv/lib/memset.S new file +119 -0
119 lines not on this page · raw message
arch/riscv/lib/uaccess.S new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 5/7] RISC-V: arch/riscv/lib
Hi Palmer,
Quoted 2 lines · Palmer Dabbelt
arch/riscv/lib/Makefile | 5 ++ arch/riscv/lib/ashldi3.c | 42 ++++++++++++++++
At least this one has already two identical copies in arch/score/lib/ashldi3.c and arch/sh/lib/ashldi3.c. Probably these should be moved to lib/, and built depending on a new config symbol that is selected on score, sh, and riscv.
Didn't check the others.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Palmer Dabbelt
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 11 lines · On Tue, 23 May 2017 03:47:34 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 2 lines · Palmer Dabbelt
arch/riscv/lib/Makefile | 5 ++ arch/riscv/lib/ashldi3.c | 42 ++++++++++++++++At least this one has already two identical copies in
arch/score/lib/ashldi3.candarch/sh/lib/ashldi3.c. Probably these should be moved tolib/, and built depending on a new config symbol that is selected on score, sh, and riscv.Didn't check the others.
Thanks. It looks like there's actually a lot of these on many architectures. I have another patch set to correct all of these that you're To'd on, I'll just pick up the first patch in the set for v2
Arnd Bergmann
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
In reply to Palmer DabbeltQuoted 19 lines · Palmer Dabbelt
arch/riscv/lib/Makefile new file +13
-0+ +void __delay(unsigned long cycles) +{ + u64 t0 = get_cycles(); + + while ((unsigned long)(get_cycles() - t0) < cycles) + cpu_relax(); +} + +void udelay(unsigned long usecs) +{ + u64 ucycles = (u64)usecs * timebase; + do_div(ucycles, 1000000U);
arch/riscv/lib/Makefile
Quoted 10 lines
arch/riscv/lib/Makefile new file +10
-0+ __delay((unsigned long)ucycles); +} +EXPORT_SYMBOL(udelay); + +void ndelay(unsigned long nsecs) +{ + u64 ncycles = (u64)nsecs * timebase; + do_div(ncycles, 1000000000U); + __delay((unsigned long)ncycles); +}
I'd be slightly worried about a global 'timebase' identifier that might conflict with a variable in some random driver.
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 25 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
arch/riscv/lib/Makefile new file +18
-0+ +void __delay(unsigned long cycles) +{ + u64 t0 = get_cycles(); + + while ((unsigned long)(get_cycles() - t0) < cycles) + cpu_relax(); +} + +void udelay(unsigned long usecs) +{ + u64 ucycles = (u64)usecs * timebase; + do_div(ucycles, 1000000U); + __delay((unsigned long)ucycles); +} +EXPORT_SYMBOL(udelay); + +void ndelay(unsigned long nsecs)
Quoted 8 lines
arch/riscv/lib/Makefile
Quoted 5 lines
arch/riscv/lib/Makefile new file +5
-0+{ + u64 ncycles = (u64)nsecs * timebase; + do_div(ncycles, 1000000000U); + __delay((unsigned long)ncycles); +}I'd be slightly worried about a global 'timebase' identifier that might conflict with a variable in some random driver.
Makes sense. I've renamed it to riscv_timebase
https://github.com/riscv/riscv-linux/commit/ed7d769e2c14e8809c3c125e0bba2978cb6fd37b
Quoted 3 lines
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
[ 0.048000] before 1000x usleep 1000 [ 1.060000] before 1000x nsleep 1000000 [ 2.072000] done
Quoted 1 line
Arnd
Thanks for the feedback. I'll incorporate this along with all the other feedback into a v2.
Arnd Bergmann
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
+ if (usecs > MAX_UDELAY_US) {
+ __delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }
You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
Quoted 7 lines
+ if (usecs >
MAX_UDELAY_US) {
+__delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is
Quoted 1 line
=2ms, so the division won't cost much in comparison.
The normal case should have no division in it.
I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.
Quoted 2 lines
Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.
That makes sense, I just based this blindly off the ARM version. I'll see if that lets me avoid unnecessary overflow for ndelay. If it doesn't then I'd prefer to just keep exactly the same constraints ARM has to avoid unexpected behavior.
Arnd Bergmann
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
Quoted 7 lines
+ if (usecs >
MAX_UDELAY_US) {
+__delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
Quoted 8 lines
The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is
Quoted 1 line
=2ms, so the division won't cost much in comparison.
The normal case should have no division in it.
I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.
I think the intention originally was to avoid overflowing the 32-bit argument in
void __delay(unsigned long cycles)
If you need to delay for more than 4 billion clocksource cycles, your code is still broken.
Quoted 7 lines
Quoted 2 lines
Also, you don't need to base anything on HZ, as you do not rely on the delay calibration but always use a timer.
That makes sense, I just based this blindly off the ARM version. I'll see if that lets me avoid unnecessary overflow for ndelay. If it doesn't then I'd prefer to just keep exactly the same constraints ARM has to avoid unexpected behavior.
Right, I should have been more specific here, as ARM has two implementations (loop and timer) and it gets much easier if you know you can rely on the timer to be available.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 34 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
Quoted 7 lines
+ if (usecs >
MAX_UDELAY_US) {
+__delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
Quoted 8 lines
The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is
Quoted 1 line
=2ms, so the division won't cost much in comparison.
The normal case should have no division in it.
I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.
Quoted 7 lines
I think the intention originally was to avoid overflowing the 32-bit argument in
void
__delay(unsigned long cycles)If you need to delay for more than 4 billion clocksource cycles, your code is still broken.
Maybe I'm crazy, but I thought the goal was to avoid overflowing on the multiply. Specifically, the code looks like
udelay(long input) {
long a = input * MUL_VAL;
long b = a >> SHIFT_VAL;
__delay(b);
}so the place there's extra overflow is at computing a, not b (the input to __delay). When I modified the ARM code I went and recalculated the point at which the multiply would overflow and it matched the value from the ARM code, which is 2000us.
While I can buy the argument that 2000us is still too long, the real reason I wrote the code this way is because I thought it was easier than having an error case. If you think the error is better then I'll do it that way.
Arnd Bergmann
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 52 lines · Palmer Dabbelt
Quoted 34 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
Quoted 7 lines
+ if (usecs >
MAX_UDELAY_US) {
+__delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
Quoted 8 lines
The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is
Quoted 1 line
=2ms, so the division won't cost much in comparison.
The normal case should have no division in it.
I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.
Quoted 7 lines
I think the intention originally was to avoid overflowing the 32-bit argument in
void
__delay(unsigned long cycles)If you need to delay for more than 4 billion clocksource cycles, your code is still broken.
Maybe I'm crazy, but I thought the goal was to avoid overflowing on the multiply. Specifically, the code looks like
udelay(long input) { long a = input * MUL_VAL; long b = a >> SHIFT_VAL; __delay(b); }
Quoted 4 lines
so the place there's extra overflow is at computing a, not b (the input to
__delay). When I modified the ARM code I went and recalculated the point at which the multiply would overflow and it matched the value from the ARM code, which is 2000us.
Ah, that's right. But then you might run into the next overflow at a larger delay interval.
Quoted 3 lines
While I can buy the argument that 2000us is still too long, the real reason I wrote the code this way is because I thought it was easier than having an error case. If you think the error is better then I'll do it that way.
It's probably ok as long as the complexity is not in the inline wrapper, and you avoid the division for small delays.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 5/7] RISC-V: arch/riscv/lib
Quoted 53 lines · Arnd Bergmann
Quoted 52 lines · Palmer Dabbelt
Quoted 34 lines · Arnd Bergmann
Quoted 24 lines · Palmer Dabbelt
Quoted 15 lines · Arnd Bergmann
Quoted 7 lines · Palmer Dabbelt
Quoted 5 lines · Arnd Bergmann
On Tue, May 23, 2017 at 2:41 AM, Palmer Dabbelt <[email protected]> wrote:
Also, it would be good to replace the multiply+div64 with a single multiplication here, see how x86 and arm do it (for the tsc/__timer_delay case).
Quoted 6 lines
Makes sense. I think this should do it
https://github.com/riscv/riscv-linux/commit/d397332f6ebff42f3ecb385e9cf3284fdeda6776
but I'm finding this hard to test as this only works for 2ms sleeps. It seems at least in the right ballpark
Quoted 7 lines
+ if (usecs >
MAX_UDELAY_US) {
+__delay((u64)usecs * riscv_timebase / 1000000ULL);
+ return;
+ }You still do the 64-bit division here. What I meant is to completely avoid the division and use a multiply+shift.
Quoted 8 lines
The goal here was to avoid the error case that ARM has on overflow and instead just delay for the requested time. This should only divide when the delay is
Quoted 1 line
=2ms, so the division won't cost much in comparison.
The normal case should have no division in it.
I can copy ARM's error handling if you think that's better, but it seemed more complicated than just computing the correct answer.
Quoted 7 lines
I think the intention originally was to avoid overflowing the 32-bit argument in
void
__delay(unsigned long cycles)If you need to delay for more than 4 billion clocksource cycles, your code is still broken.
Maybe I'm crazy, but I thought the goal was to avoid overflowing on the multiply. Specifically, the code looks like
udelay(long input) { long a = input * MUL_VAL; long b = a >> SHIFT_VAL; __delay(b); }
Quoted 7 lines
Quoted 4 lines
so the place there's extra overflow is at computing a, not b (the input to
__delay). When I modified the ARM code I went and recalculated the point at which the multiply would overflow and it matched the value from the ARM code, which is 2000us.Ah, that's right. But then you might run into the next overflow at a larger delay interval.
Well, that requires a huge delay as there's a (u64) cast in there. The timebase is a u32 which puts the delay at an hour, which seems unlikely :).
Quoted 7 lines
Quoted 4 lines
While I can buy the argument that 2000us is still too long, the real reason I wrote the code this way is because I thought it was easier than having an error case. If you think the error is better then I'll do it that way.
It's probably ok as long as the complexity is not in the inline wrapper, and you avoid the division for small delays.
I put an unlikely() around the comparison and it looks like the complier does well enough: there are no references to riscv_timebase outside of udelay (so it's not inline anywhere), and there's just one branch on the hot path to test for overflow (which is probably free anyway, as it's in the shadow of a mul and never taken).
Palmer Dabbelt
maintainerPATCH 6/7 RISC-V: arch/riscv/kernel
In reply to Palmer Dabbelt--- arch/riscv/kernel/Makefile | 19 ++ arch/riscv/kernel/asm-offsets.c | 113 ++++++++++ arch/riscv/kernel/cacheinfo.c | 82 ++++++++ arch/riscv/kernel/cpu.c | 81 ++++++++ arch/riscv/kernel/entry.S | 414 +++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 139 +++++++++++++ arch/riscv/kernel/irq.c | 205 ++++++++++++++++++ arch/riscv/kernel/module.c | 185 +++++++++++++++++ arch/riscv/kernel/pci.c | 36 ++++ arch/riscv/kernel/plic.c | 208 +++++++++++++++++++ arch/riscv/kernel/process.c | 130 ++++++++++++ arch/riscv/kernel/ptrace.c | 148 +++++++++++++ arch/riscv/kernel/reset.c | 33 +++ arch/riscv/kernel/riscv_ksyms.c | 16 ++ arch/riscv/kernel/sbi-con.c | 214 +++++++++++++++++++ arch/riscv/kernel/setup.c | 234 +++++++++++++++++++++ arch/riscv/kernel/signal.c | 258 +++++++++++++++++++++++ arch/riscv/kernel/smp.c | 107 ++++++++++ arch/riscv/kernel/smpboot.c | 105 ++++++++++ arch/riscv/kernel/stacktrace.c | 183 ++++++++++++++++ arch/riscv/kernel/sys_riscv.c | 85 ++++++++ arch/riscv/kernel/syscall_table.c | 26 +++ arch/riscv/kernel/time.c | 116 +++++++++++ arch/riscv/kernel/traps.c | 167 +++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++ arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 61 ++++++ arch/riscv/kernel/vdso/sigreturn.S | 25 +++ arch/riscv/kernel/vdso/vdso.S | 28 +++ arch/riscv/kernel/vdso/vdso.lds.S | 77 +++++++ arch/riscv/kernel/vmlinux.lds.S | 93 +++++++++ 31 files changed, 3714 insertions(+) create mode 100644 arch/riscv/kernel/Makefile create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/module.c create mode 100644 arch/riscv/kernel/pci.c create mode 100644 arch/riscv/kernel/plic.c create mode 100644 arch/riscv/kernel/process.c create mode 100644 arch/riscv/kernel/ptrace.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/riscv_ksyms.c create mode 100644 arch/riscv/kernel/sbi-con.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/signal.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/stacktrace.c create mode 100644 arch/riscv/kernel/sys_riscv.c create mode 100644 arch/riscv/kernel/syscall_table.c create mode 100644 arch/riscv/kernel/time.c create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/kernel/vdso/.gitignore create mode 100644 arch/riscv/kernel/vdso/Makefile create mode 100644 arch/riscv/kernel/vdso/sigreturn.S create mode 100644 arch/riscv/kernel/vdso/vdso.S create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S create mode 100644 arch/riscv/kernel/vmlinux.lds.S
arch/riscv/kernel/Makefile new file +19 -0
@@ -0,0 +1,19 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o time.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/ + +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o +obj-$(CONFIG_SBI_CONSOLE) += sbi-con.o +obj-$(CONFIG_PCI) += pci.o +obj-$(CONFIG_MODULES) += module.o +obj-$(CONFIG_PLIC) += plic.o + +clean:
arch/riscv/kernel/asm-offsets.c new file +113 -0
113 lines not on this page · raw message
arch/riscv/kernel/cacheinfo.c new file +82 -0
82 lines not on this page · raw message
arch/riscv/kernel/cpu.c new file +81 -0
81 lines not on this page · raw message
arch/riscv/kernel/entry.S new file +414 -0
414 lines not on this page · raw message
arch/riscv/kernel/head.S new file +139 -0
139 lines not on this page · raw message
arch/riscv/kernel/irq.c new file +205 -0
205 lines not on this page · raw message
arch/riscv/kernel/module.c new file +185 -0
185 lines not on this page · raw message
arch/riscv/kernel/pci.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c +* +* Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM +* Copyright (C) 2014 ARM Ltd. +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +*/ + +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/pci.h> + +/* +* Called after each bus is probed, but before its children are examined +*/ +void pcibios_fixup_bus (struct pci_bus *bus) +{ +/* nothing to do, expected to be removed in the future */ +} + +/* +* We don't have to worry about legacy ISA devices, so nothing to do here +*/ +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +}
arch/riscv/kernel/plic.c new file +208 -0
208 lines not on this page · raw message
arch/riscv/kernel/process.c new file +130 -0
130 lines not on this page · raw message
arch/riscv/kernel/ptrace.c new file +148 -0
148 lines not on this page · raw message
arch/riscv/kernel/reset.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +} + +void machine_halt (void ) +{ +} + +void machine_power_off (void ) +{ +sbi_shutdown (); +}
arch/riscv/kernel/riscv_ksyms.c new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2017 Zihao Yu +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/export.h> +#include <linux/uaccess.h> + +/* +* Assembly functions that may be used (directly or indirectly) by modules +*/ +EXPORT_SYMBOL (__copy_user); +
arch/riscv/kernel/sbi-con.c new file +214 -0
214 lines not on this page · raw message
arch/riscv/kernel/setup.c new file +234 -0
234 lines not on this page · raw message
arch/riscv/kernel/signal.c new file +258 -0
258 lines not on this page · raw message
arch/riscv/kernel/smp.c new file +107 -0
107 lines not on this page · raw message
arch/riscv/kernel/smpboot.c new file +105 -0
105 lines not on this page · raw message
arch/riscv/kernel/stacktrace.c new file +183 -0
183 lines not on this page · raw message
arch/riscv/kernel/sys_riscv.c new file +85 -0
85 lines not on this page · raw message
arch/riscv/kernel/syscall_table.c new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2009 Arnd Bergmann <[email protected]> +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/time.c new file +116 -0
116 lines not on this page · raw message
arch/riscv/kernel/traps.c new file +167 -0
167 lines not on this page · raw message
arch/riscv/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/riscv/kernel/vdso/.gitignore new file +1 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/Makefile new file +61 -0
61 lines not on this page · raw message
arch/riscv/kernel/vdso/sigreturn.S new file +25 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.S new file +28 -0
Lines of this file are not shown. View the raw message.
arch/riscv/kernel/vdso/vdso.lds.S new file +77 -0
77 lines not on this page · raw message
arch/riscv/kernel/vmlinux.lds.S new file +93 -0
93 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 56 lines · Palmer Dabbelt
--- arch/riscv/kernel/Makefile | 19 ++ arch/riscv/kernel/asm-offsets.c | 113 ++++++++++ arch/riscv/kernel/cacheinfo.c | 82 ++++++++ arch/riscv/kernel/cpu.c | 81 ++++++++ arch/riscv/kernel/entry.S | 414 +++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 139 +++++++++++++ arch/riscv/kernel/irq.c | 205 ++++++++++++++++++ arch/riscv/kernel/module.c | 185 +++++++++++++++++ arch/riscv/kernel/pci.c | 36 ++++ arch/riscv/kernel/plic.c | 208 +++++++++++++++++++ arch/riscv/kernel/process.c | 130 ++++++++++++ arch/riscv/kernel/ptrace.c | 148 +++++++++++++ arch/riscv/kernel/reset.c | 33 +++ arch/riscv/kernel/riscv_ksyms.c | 16 ++ arch/riscv/kernel/sbi-con.c | 214 +++++++++++++++++++ arch/riscv/kernel/setup.c | 234 +++++++++++++++++++++ arch/riscv/kernel/signal.c | 258 +++++++++++++++++++++++ arch/riscv/kernel/smp.c | 107 ++++++++++ arch/riscv/kernel/smpboot.c | 105 ++++++++++ arch/riscv/kernel/stacktrace.c | 183 ++++++++++++++++ arch/riscv/kernel/sys_riscv.c | 85 ++++++++ arch/riscv/kernel/syscall_table.c | 26 +++ arch/riscv/kernel/time.c | 116 +++++++++++ arch/riscv/kernel/traps.c | 167 +++++++++++++++ arch/riscv/kernel/vdso.c | 125 +++++++++++ arch/riscv/kernel/vdso/.gitignore | 1 + arch/riscv/kernel/vdso/Makefile | 61 ++++++ arch/riscv/kernel/vdso/sigreturn.S | 25 +++ arch/riscv/kernel/vdso/vdso.S | 28 +++ arch/riscv/kernel/vdso/vdso.lds.S | 77 +++++++ arch/riscv/kernel/vmlinux.lds.S | 93 +++++++++ 31 files changed, 3714 insertions(+) create mode 100644 arch/riscv/kernel/Makefile create mode 100644 arch/riscv/kernel/asm-offsets.c create mode 100644 arch/riscv/kernel/cacheinfo.c create mode 100644 arch/riscv/kernel/cpu.c create mode 100644 arch/riscv/kernel/entry.S create mode 100644 arch/riscv/kernel/head.S create mode 100644 arch/riscv/kernel/irq.c create mode 100644 arch/riscv/kernel/module.c create mode 100644 arch/riscv/kernel/pci.c create mode 100644 arch/riscv/kernel/plic.c create mode 100644 arch/riscv/kernel/process.c create mode 100644 arch/riscv/kernel/ptrace.c create mode 100644 arch/riscv/kernel/reset.c create mode 100644 arch/riscv/kernel/riscv_ksyms.c create mode 100644 arch/riscv/kernel/sbi-con.c create mode 100644 arch/riscv/kernel/setup.c create mode 100644 arch/riscv/kernel/signal.c create mode 100644 arch/riscv/kernel/smp.c create mode 100644 arch/riscv/kernel/smpboot.c create mode 100644 arch/riscv/kernel/stacktrace.c create mode 100644 arch/riscv/kernel/sys_riscv.c create mode 100644 arch/riscv/kernel/syscall_table.c create mode 100644 arch/riscv/kernel/time.c
Quoted 8 lines
create mode 100644 arch/riscv/kernel/traps.c create mode 100644 arch/riscv/kernel/vdso.c create mode 100644 arch/riscv/kernel/vdso/.gitignore create mode 100644 arch/riscv/kernel/vdso/Makefile create mode 100644 arch/riscv/kernel/vdso/sigreturn.S create mode 100644 arch/riscv/kernel/vdso/vdso.S create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S create mode 100644 arch/riscv/kernel/vmlinux.lds.S
What's missing from this patchset (ideally) is a good writeup under DOcumentation/ on expectations of system state (and/or configuration) upon entry of the kernel. For comparison, see the arm64 documentation where they were quite specific in this.
This patch is also pushing size limits, and is getting unwieldy to comment on. I'll point out a few things below with plenty of snipped out lines.
Quoted 34 lines
arch/riscv/kernel/Makefile new file +19
-0@@ -0,0 +1,19 @@ +# +# Makefile for the RISC-V Linux kernel +# + +extra-y := head.o vmlinux.lds + +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \ + signal.o syscall_table.o sys_riscv.o time.o traps.o \ + riscv_ksyms.o stacktrace.o vdso.o cacheinfo.o vdso/ + +CFLAGS_setup.o := -mcmodel=medany + +obj-$(CONFIG_SMP) += smpboot.o smp.o +obj-$(CONFIG_SBI_CONSOLE) += sbi-con.o +obj-$(CONFIG_PCI) += pci.o +obj-$(CONFIG_MODULES) += module.o +obj-$(CONFIG_PLIC) += plic.o + +clean:arch/riscv/kernel/asm-offsets.c new file +2
-0@@ -0,0 +1,113 @@ +/* +* Copyright (C) 2012 Regents of the University of California
arch/riscv/kernel/asm-offsets.c line 12
Quoted 10 lines
arch/riscv/kernel/asm-offsets.c new file +10
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details.
Hmm, I haven't seen these terms used often, but they seem to exist around the tree in a few places. arch/tile is littered with them.
I am not a lawyer, but I can't seem any reference to "good title" in the GPLv2 text.
Rather than having to go through the process of figuring out if this license header is acceptable or not, you might find it easier to just go with something more established.
Quoted 62 lines
arch/riscv/kernel/cacheinfo.c new file +56
-0@@ -0,0 +1,82 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/cacheinfo.h> +#include <linux/cpu.h> +#include <linux/of.h> +#include <linux/of_device.h> + +static void ci_leaf_init (struct cacheinfo *this_leaf, +struct device_node *node, +enum cache_type type,unsigned int level) +{ + this_leaf->of_node = node; + this_leaf->level = level; + this_leaf->type = type; + this_leaf->physical_line_partition =1 ;// not a sector cache + this_leaf->attributes =CACHE_WRITE_BACK |CACHE_READ_ALLOCATE |CACHE_WRITE_ALLOCATE ;// TODO: add to DTS +} + +static int __init_cache_level (unsigned int cpu) +{ +struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct device_node *np =of_cpu_device_node_get (cpu); +int levels =0 , leaves =0 , level; + +if (of_property_read_bool (np,"cache-size" )) ++leaves; +if (of_property_read_bool (np,"i-cache-size" )) ++leaves; +if (of_property_read_bool (np,"d-cache-size" )) ++leaves; +if (leaves >0 ) levels =1 ; + +while ((np =of_find_next_cache_node (np))) { +if (!of_device_is_compatible (np,"cache" ))break ; +if (of_property_read_u32 (np,"cache-level" , &level))break ; +if (level <= levels)break ; +if (of_property_read_bool (np,"cache-size" )) ++leaves; +if (of_property_read_bool (np,"i-cache-size" )) ++leaves; +if (of_property_read_bool (np,"d-cache-size" )) ++leaves; + levels = level; + } + + this_cpu_ci->num_levels = levels; + this_cpu_ci->num_leaves = leaves; +return 0 ; +} +
arch/riscv/kernel/cacheinfo.c line 66
Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10
-0+static int __populate_cache_leaves (unsigned int cpu) +{ +struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cacheinfo *this_leaf = this_cpu_ci->info_list; +struct device_node *np =of_cpu_device_node_get (cpu); +int levels =1 , level =1 ; + +if (of_property_read_bool (np,"cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_UNIFIED , level); +if (of_property_read_bool (np,"i-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_INST , level); +if (of_property_read_bool (np,"d-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_DATA , level);
Please run checkpatch, kernel coding style doesn't use one-line ifs (here nor elsewhere).
Quoted 43 lines
arch/riscv/kernel/cacheinfo.c new file +16
-0+ +while ((np =of_find_next_cache_node (np))) { +if (!of_device_is_compatible (np,"cache" ))break ; +if (of_property_read_u32 (np,"cache-level" , &level))break ; +if (level <= levels)break ; +if (of_property_read_bool (np,"cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_UNIFIED , level); +if (of_property_read_bool (np,"i-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_INST , level); +if (of_property_read_bool (np,"d-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_DATA , level); + levels = level; + } + +return 0 ; +} + +DEFINE_SMP_CALL_CACHE_FUNCTION (init_cache_level) +DEFINE_SMP_CALL_CACHE_FUNCTION (populate_cache_leaves)arch/riscv/kernel/cpu.c new file +21
-0@@ -0,0 +1,81 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/init.h> +#include <linux/seq_file.h> +#include <linux/of.h> + +/* Return -1 if not a valid hart */ +int riscv_of_processor_hart (struct device_node *node) +{
arch/riscv/kernel/cpu.c line 31
Quoted 10 lines
arch/riscv/kernel/cpu.c new file +10
-0+const char *isa, *status; +u32 hart; + +if (!of_device_is_compatible (node,"riscv" ))return -1 ; +if (of_property_read_u32 (node,"reg" , &hart) || hart >=NR_CPUS )return -1 ; +if (of_property_read_string (node,"status" , &status) ||strcmp (status,"okay" ))return -1 ; +if (of_property_read_string (node,"riscv,isa" , &isa) || isa[0 ] !='r' || isa[1 ] !='v' )return -1 ; + +return hart; +}
We usually prefer to see real -E<foo> returns instead of -1 in the kernel.
[...]
Quoted 207 lines
arch/riscv/kernel/head.S new file +139
-0@@ -0,0 +1,139 @@ +/* + * Copyright (C) 2012 Regents of the University of California + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for + * more details. + */ + +#include <asm/thread_info.h> +#include <asm/asm-offsets.h> +#include <asm/asm.h> +#include <linux/init.h> +#include <linux/linkage.h> +#include <asm/thread_info.h> +#include <asm/page.h> +#include <asm/csr.h> + +__INIT +ENTRY(_start) + /* Mask all interrupts */ + csrw sie, zero + + /* Disable FPU to detect illegal usage of + floating point in kernel space */ + li t0, SR_FS + csrc sstatus, t0 + +#ifndef CONFIG_RV_PUM + /* Allow access to user memory */ + li t0, SR_SUM + csrs sstatus, t0 +#endif + + /* Pick one hart to run the main boot sequence */ + la a3, hart_lottery + li a2, 1 + amoadd.w a3, a2, (a3) + bnez a3, .Lsecondary_start + + /* Save hart ID and DTB physical address */ + mv s0, a0 + mv s1, a1 + + /* Initialize page tables and relocate to virtual addresses */ + la sp, init_thread_union + THREAD_SIZE + call setup_vm + call relocate + + /* Restore C environment */ + la tp, init_thread_union + li sp, THREAD_SIZE + add sp, sp, tp + + /* Start the kernel */ + mv a0, s0 + mv a1, s1 + call sbi_save + tail start_kernel + +relocate: + /* Relocate return address */ + li a1, PAGE_OFFSET + la a0, _start + sub a1, a1, a0 + add ra, ra, a1 + + /* Point stvec to virtual address of intruction after sptbr write */ + la a0, 1f + add a0, a0, a1 + csrw stvec, a0 + + /* Compute sptbr for kernel page tables, but don't load it yet */ + la a2, swapper_pg_dir + srl a2, a2, PAGE_SHIFT + li a1, SPTBR_MODE + or a2, a2, a1 + + /* Load trampoline page directory, which will cause us to trap to + stvec if VA != PA, or simply fall through if VA == PA */ + la a0, trampoline_pg_dir + srl a0, a0, PAGE_SHIFT + or a0, a0, a1 + sfence.vma + csrw sptbr, a0 +1: + /* Set trap vector to spin forever to help debug */ + la a0, .Lsecondary_park + csrw stvec, a0 + + /* Load the global pointer */ + la gp, __global_pointer$ + + /* Switch to kernel page tables */ + csrw sptbr, a2 + + ret + +.Lsecondary_start: +#ifdef CONFIG_SMP + li a1, CONFIG_NR_CPUS + bgeu a0, a1, .Lsecondary_park + + la a1, __cpu_up_stack_pointer + slli a0, a0, LGREG + add a0, a0, a1 + +.Lwait_for_cpu_up: + REG_L sp, (a0) + beqz sp, .Lwait_for_cpu_up + fence + + /* Enable virtual memory and relocate to virtual address */ + call relocate + + /* Initialize task_struct pointer */ + li tp, -THREAD_SIZE + add tp, tp, sp + + tail smp_callin +#endif + +.Lsecondary_park: + /* We lack SMP support or have too many harts, so park this hart */ + wfi + j .Lsecondary_park +END(_start) + +__PAGE_ALIGNED_BSS + /* Empty zero page */ + .balign PAGE_SIZE +ENTRY(empty_zero_page) + .fill (empty_zero_page + PAGE_SIZE) - ., 1, 0x00 +END(empty_zero_page)arch/riscv/kernel/irq.c new file +56
-0@@ -0,0 +1,205 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqdomain.h> +#include <linux/interrupt.h> +#include <linux/ftrace.h> +#include <linux/of.h> +#include <linux/seq_file.h> + +#include <asm/ptrace.h> +#include <asm/sbi.h> +#include <asm/smp.h> + +struct riscv_irq_data { +struct irq_chip chip; +struct irq_domain *domain; +int hart; +char name[20 ]; +}; +DEFINE_PER_CPU(struct riscv_irq_data, riscv_irq_data); +DEFINE_PER_CPU (atomic_long_t, riscv_early_sie); + +static void riscv_software_interrupt (void ) +{ +#ifdef CONFIG_SMP +irqreturn_t ret; + + ret =handle_ipi (); +if (ret !=IRQ_NONE ) +return ; +#endif + +BUG (); +} + +asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs) +{ +struct pt_regs *old_regs =set_irq_regs (regs); +irq_enter (); + +/* There are three classes of interrupt: timer, software, and +external devices. We dispatch between them here. External
arch/riscv/kernel/irq.c line 66
Quoted 10 lines
arch/riscv/kernel/irq.c new file +10
-0+device interrupts use the generic IRQ mechanisms. */ +switch (cause) { +case INTERRUPT_CAUSE_TIMER : +riscv_timer_interrupt (); +break ; +case INTERRUPT_CAUSE_SOFTWARE : +riscv_software_interrupt (); +break ; +default : { +struct irq_domain *domain =per_cpu (riscv_irq_data,smp_processor_id ()).domain;
Move this up to top of function and remove the { } wrap, please.
Quoted 38 lines
arch/riscv/kernel/irq.c new file +38
-0+generic_handle_irq (irq_find_mapping (domain, cause)); +break ; + } + } + +irq_exit (); +set_irq_regs (old_regs); +} + +static int riscv_irqdomain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) +{ +struct riscv_irq_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +} + +static const struct irq_domain_ops riscv_irqdomain_ops = { + .map = riscv_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void riscv_irq_mask (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); +BUG_ON (smp_processor_id () != data->hart); +csr_clear (sie,1 << (long )d->hwirq); +} + +static void riscv_irq_unmask (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); +BUG_ON (smp_processor_id () != data->hart); +csr_set (sie,1 << (long )d->hwirq); +}
arch/riscv/kernel/irq.c line 114
Quoted 10 lines
arch/riscv/kernel/irq.c new file +10
-0+ +static void riscv_irq_enable_helper (void *d) +{ +riscv_irq_unmask (d); +} + +static void riscv_irq_enable (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); +atomic_long_or ((1 << (long )d->hwirq), &per_cpu (riscv_early_sie, data->hart));
This is a bit dense to get into without a few words of how it's expected to work.
Quoted 54 lines
arch/riscv/kernel/irq.c new file +54
-0+if (data->hart ==smp_processor_id ()) { +riscv_irq_unmask (d); + }else if (cpu_online (data->hart)) { +smp_call_function_single (data->hart, riscv_irq_enable_helper, d, true); + } +} + +static void riscv_irq_disable_helper (void *d) +{ +riscv_irq_mask (d); +} + +static void riscv_irq_disable (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); +atomic_long_and (~(1 << (long )d->hwirq), &per_cpu (riscv_early_sie, data->hart)); +if (data->hart ==smp_processor_id ()) { +riscv_irq_mask (d); + }else if (cpu_online (data->hart)) { +smp_call_function_single (data->hart, riscv_irq_disable_helper, d, true); + } +} + +static void riscv_irq_mask_noop (struct irq_data *d) { } + +static void riscv_irq_unmask_noop (struct irq_data *d) { } + +static void riscv_irq_enable_noop (struct irq_data *d) +{ +struct device_node *data =irq_data_get_irq_chip_data (d); +u32 hart; + +if (!of_property_read_u32 (data,"reg" , &hart)) { +printk ("WARNING: enabled interrupt %d for missing hart %d (this interrupt has no handler)\n" , (int )d->hwirq, hart); + } +} + +static struct irq_chip riscv_noop_chip = { + .name ="riscv,cpu-intc,noop" , + .irq_mask = riscv_irq_mask_noop, + .irq_unmask = riscv_irq_unmask_noop, + .irq_enable = riscv_irq_enable_noop, +}; + +static int riscv_irqdomain_map_noop (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) +{ +struct device_node *data = d->host_data; +irq_set_chip_and_handler (irq, &riscv_noop_chip, handle_simple_irq); +irq_set_chip_data (irq, data); +return 0 ; +} + +static const struct irq_domain_ops riscv_irqdomain_ops_noop = { + .map = riscv_irqdomain_map_noop,
arch/riscv/kernel/irq.c line 178
Quoted 10 lines
arch/riscv/kernel/irq.c new file +10
-0+ .xlate = irq_domain_xlate_onecell, +}; + +static int riscv_intc_init (struct device_node *node,struct device_node *parent) +{ +int hart; + +if (parent)return 0 ;// should have no interrupt parent + +if ((hart =riscv_of_processor_hart (node->parent)) >=0 ) {
Common pattern in kernel is to detect error instead:
hart = riscv_of_processor_hart(node->parent);
if (hart < 0) {
<from your else side here>
return 0;
}
<body if your if statement here>
return 0;Quoted 34 lines
arch/riscv/kernel/irq.c new file +27
-0+struct riscv_irq_data *data = &per_cpu (riscv_irq_data, hart); +snprintf (data->name,sizeof (data->name),"riscv,cpu_intc,%d" , hart); + data->hart = hart; + data->chip.name = data->name; + data->chip.irq_mask = riscv_irq_mask; + data->chip.irq_unmask = riscv_irq_unmask; + data->chip.irq_enable = riscv_irq_enable; + data->chip.irq_disable = riscv_irq_disable; + data->domain =irq_domain_add_linear (node,8 *sizeof (uintptr_t ), &riscv_irqdomain_ops, data); +WARN_ON (!data->domain); +printk ("%s: %d local interrupts mapped\n" , data->name,8 *(int )sizeof (uintptr_t )); + }else { +/* If a hart is disabled, create a no-op irq domain. +* Devices may still have interrupts connected to those harts. +* This is not wrong... unless they actually load a driver that needs it! +*/ +irq_domain_add_linear (node,8 *sizeof (uintptr_t ), &riscv_irqdomain_ops_noop, node->parent); + } +return 0 ; +} + +IRQCHIP_DECLARE (riscv,"riscv,cpu-intc" , riscv_intc_init); + +void __init init_IRQ (void ) +{ +irqchip_init (); +}arch/riscv/kernel/pci.c new file +0
-0
arch/riscv/kernel/pci.c line 2
Quoted 2 lines
arch/riscv/kernel/pci.c new file +2
-0@@ -0,0 +1,36 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c
So, you should add recursive reference from there (i.e. powerpc).
But in the end, there's essentially no code in this file. :)
Quoted 57 lines
arch/riscv/kernel/pci.c new file +34
-0+* +* Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM +* Copyright (C) 2014 ARM Ltd. +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +*/ + +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/pci.h> + +/* +* Called after each bus is probed, but before its children are examined +*/ +void pcibios_fixup_bus (struct pci_bus *bus) +{ +/* nothing to do, expected to be removed in the future */ +} + +/* +* We don't have to worry about legacy ISA devices, so nothing to do here +*/ +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +}arch/riscv/kernel/plic.c new file +17
-0@@ -0,0 +1,208 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/irq.h>
arch/riscv/kernel/plic.c line 27
Quoted 10 lines
arch/riscv/kernel/plic.c new file +10
-0+#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> + +#define MAX_DEVICES 1024 // 0 is reserved
Seems like an odd comment to have here (and should probably not go at the end of the line)
arch/riscv/kernel/plic.c line 38
Quoted 11 lines
arch/riscv/kernel/plic.c new file +11
-0+#define MAX_CONTEXTS 15872 + +#define PRIORITY_BASE 0 +#define ENABLE_BASE 0x2000 +#define ENABLE_SIZE 0x80 +#define HART_BASE 0x200000 +#define HART_SIZE 0x1000 + +#define PLIC_HART_CONTEXT (data, i) (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i) +#define PLIC_ENABLE_CONTEXT (data, i) (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i) +#define PLIC_PRIORITY (data) (struct plic_priority *)((char *)data->reg + PRIORITY_BASE)
Since you have typecasting and stuff here, small static inlines with appropriate return types seems slightly tidier.
Quoted 78 lines
arch/riscv/kernel/plic.c new file +78
-0+ +struct plic_hart_context { +volatile u32 threshold; +volatile u32 claim; +}; + +struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry +}; + +struct plic_priority { +volatile u32 prio[MAX_DEVICES ]; +}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ]; +}; + +struct plic_handler { +struct plic_hart_context *context; +struct plic_data *data; +}; + +static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =PLIC_ENABLE_CONTEXT (data, i); +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +static void plic_enable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =PLIC_ENABLE_CONTEXT (data, i); +atomic_or ((1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +// There is no need to mask/unmask PLIC interrupts +// They are "masked" by reading claim and "unmasked" when writing it back. +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } + +static void plic_irq_enable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =PLIC_PRIORITY (data); +int i; +iowrite32 (1 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_enable (data, i, d->hwirq); +} + +static void plic_irq_disable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =PLIC_PRIORITY (data); +int i; +iowrite32 (0 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_disable (data, i, d->hwirq); +} + +static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) +{ +struct plic_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +}
arch/riscv/kernel/plic.c line 126
Quoted 10 lines
arch/riscv/kernel/plic.c new file +10
-0+ +static const struct irq_domain_ops plic_irqdomain_ops = { + .map = plic_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void plic_chained_handle_irq (struct irq_desc *desc) +{ +struct plic_handler *handler =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc);
Whitespace.
Quoted 72 lines
arch/riscv/kernel/plic.c new file +72
-0+struct irq_domain *domain = handler->data->domain; +u32 what; + +chained_irq_enter (chip, desc); + +while ((what =ioread32 (&handler->context->claim))) { +int irq =irq_find_mapping (domain, what); +if (irq >0 ) { +generic_handle_irq (irq); + }else { +handle_bad_irq (desc); + } +iowrite32 (what, &handler->context->claim); + } + +chained_irq_exit (chip, desc); +} + +// TODO: add a /sys interface to set priority + per-hart enables for steering + +static int plic_init (struct device_node *node,struct device_node *parent) +{ +struct plic_data *data; +struct resource resource; +int i, ok =0 ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (WARN_ON (!data))return -ENOMEM ; + + data->reg =of_iomap (node,0 ); +if (WARN_ON (!data->reg))return -EIO ; + +of_property_read_u32 (node,"riscv,ndev" , &data->ndev); +if (WARN_ON (!data->ndev))return -EINVAL ; + + data->handlers =of_irq_count (node); +if (WARN_ON (!data->handlers))return -EINVAL ; + + data->handler =kzalloc (sizeof (*data->handler)*data->handlers,GFP_KERNEL ); +if (WARN_ON (!data->handler))return -ENOMEM ; + + data->domain =irq_domain_add_linear (node, data->ndev+1 , &plic_irqdomain_ops, data); +if (WARN_ON (!data->domain))return -ENOMEM ; + +of_address_to_resource (node,0 , &resource); +snprintf (data->name,sizeof (data->name),"riscv,plic0,%llx" , resource.start); + data->chip.name = data->name; + data->chip.irq_mask = plic_irq_mask; + data->chip.irq_unmask = plic_irq_unmask; + data->chip.irq_enable = plic_irq_enable; + data->chip.irq_disable = plic_irq_disable; + +for (i =0 ; i < data->handlers; ++i) { +struct plic_handler *handler = &data->handler[i]; +struct of_phandle_args parent; +int parent_irq, hwirq; + +if (of_irq_parse_one (node, i, &parent))continue ; +if (parent.args[0 ] ==-1 )continue ;// skip context holes + +// skip any contexts that lead to inactive harts +if (of_device_is_compatible (parent.np,"riscv,cpu-intc" ) && + parent.np->parent && +riscv_of_processor_hart (parent.np->parent) <0 )continue ; + + parent_irq =irq_create_of_mapping (&parent); +if (!parent_irq)continue ; + + handler->context =PLIC_HART_CONTEXT (data, i); + handler->data = data; +iowrite32 (0 , &handler->context->threshold);// hwirq prio must be > this to trigger an interrupt +for (hwirq =1 ; hwirq <= data->ndev; ++hwirq)plic_disable (data, i, hwirq);
arch/riscv/kernel/plic.c line 208
Quoted 10 lines
arch/riscv/kernel/plic.c new file +10
-0+irq_set_chained_handler_and_data (parent_irq, plic_chained_handle_irq, handler); + ++ok; + } + +printk ("%s: mapped %d interrupts to %d/%d handlers\n" , data->name, data->ndev, ok, data->handlers); +WARN_ON (!ok); +return 0 ; +} + +IRQCHIP_DECLARE (plic0,"riscv,plic0" , plic_init);
[wrapping up review of this patch at this point to keep size down]
-Olof
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 5 lines · On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:
On Mon, May 22, 2017 at 5:41 PM, Palmer Dabbelt <[email protected]> wrote:
What's missing from this patchset (ideally) is a good writeup under DOcumentation/ on expectations of system state (and/or configuration) upon entry of the kernel. For comparison, see the arm64 documentation where they were quite specific in this.
We don't have a spec written for this yet, but one is being written. Is it OK if I wait until there's a spec?
Quoted 3 lines
This patch is also pushing size limits, and is getting unwieldy to comment on. I'll point out a few things below with plenty of snipped out lines.
I'm also going to start dropping diffs, as this is very big.
Quoted 18 lines
Quoted 4 lines
+++
b/arch/riscv/kernel/asm-offsets.carch/riscv/kernel/asm-offsets.c new file +2
-0@@ -0,0 +1,113 @@ +/* +* Copyright (C) 2012 Regents of the University of California arch/riscv/kernel/asm-offsets.c line 12
Quoted 10 lines
arch/riscv/kernel/asm-offsets.c new file +10
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. Hmm, I haven't seen these terms used often, but they seem to exist around the tree in a few places.
arch/tileis littered with them.
Quoted 6 lines
I am not a lawyer, but I can't seem any reference to "good title" in the GPLv2 text.
Rather than having to go through the process of figuring out if this license header is acceptable or not, you might find it easier to just go with something more established.
This almost certainly came from Tilera: I stole our ptrace from there becuase that was the ISA I understood best, and that header must have proliferated everywhere else.
I've changed it to a header I copied from ARM
https://github.com/riscv/riscv-linux/commit/ccc4f51b40b28adf01b14ed6578bf26dc02f1425
Quoted 5 lines
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5
-0+static int __populate_cache_leaves (unsigned int cpu) +{ +struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cacheinfo *this_leaf = this_cpu_ci->info_list; +struct device_node *np =of_cpu_device_node_get (cpu);
Quoted 8 lines
arch/riscv/kernel/cacheinfo.c line 66
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5
-0+int levels =1 , level =1 ; + +if (of_property_read_bool (np,"cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_UNIFIED , level); +if (of_property_read_bool (np,"i-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_INST , level); +if (of_property_read_bool (np,"d-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_DATA , level);Please run checkpatch, kernel coding style doesn't use one-line ifs (here nor elsewhere).
I went through and fixed many of the checkpatch messages. The ones that are left fall into the following categories:
* Lots of uses of BUG/BUG_ON instead of WARN_ON. Lots of these are in boot code, but some of them can probably be fixed.
* Parens around single-statement __asm__ macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.
* Parens around macros like "#define RISCV_PTR .dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.
* Warnings about volatile in function declarations in bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.
* Definitions like ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.
* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).
* A handful of lines over 80 characters that I think are onerous to break any more.
* Some warnings about printk() not having a KERN_ prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (in show_regs, for example, where arm64 also has them).
* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.
There's also a bunch of false positives:
* The spelling of SEPC, which is correct (Supervisor Exception Program Counter).
* Fall-through warnings, probably getting confused by the break looking like "break; \" (they're in macros).
I'll make another pass on these before a v2 patch set.
Quoted 7 lines
Quoted 7 lines
arch/riscv/kernel/cpu.c new file +7
-0+/* Return -1 if not a valid hart */ +int riscv_of_processor_hart (struct device_node *node) +{ +const char *isa, *status; +u32 hart; + +if (!of_device_is_compatible (node,"riscv" ))return -1 ;
Quoted 8 lines
arch/riscv/kernel/cpu.c line 31
Quoted 6 lines
arch/riscv/kernel/cpu.c new file +6
-0+if (of_property_read_u32 (node,"reg" , &hart) || hart >=NR_CPUS )return -1 ; +if (of_property_read_string (node,"status" , &status) ||strcmp (status,"okay" ))return -1 ; +if (of_property_read_string (node,"riscv,isa" , &isa) || isa[0 ] !='r' || isa[1 ] !='v' )return -1 ; + +return hart; +}We usually prefer to see real -E<foo> returns instead of -1 in the kernel.
Makes sense. https://github.com/riscv/riscv-linux/commit/10ef72b2aa16b2b69f9f349cffc06d12e183a56e
Quoted 11 lines
Quoted 11 lines
arch/riscv/kernel/irq.c new file +11
-0+asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs) +{ +struct pt_regs *old_regs =set_irq_regs (regs); +irq_enter (); + +/* There are three classes of interrupt: timer, software, and +external devices. We dispatch between them here. External +device interrupts use the generic IRQ mechanisms. */ +switch (cause) { +case INTERRUPT_CAUSE_TIMER : +riscv_timer_interrupt ();
Quoted 8 lines
arch/riscv/kernel/irq.c line 66
Quoted 6 lines
arch/riscv/kernel/irq.c new file +6
-0+break ; +case INTERRUPT_CAUSE_SOFTWARE : +riscv_software_interrupt (); +break ; +default : { +struct irq_domain *domain =per_cpu (riscv_irq_data,smp_processor_id ()).domain;Move this up to top of function and remove the { } wrap, please.
https://github.com/riscv/riscv-linux/commit/17879136caa05ed9f686736b3343f4b2063920ab
Quoted 7 lines
arch/riscv/kernel/irq.c line 114
Quoted 4 lines
arch/riscv/kernel/irq.c new file +4
-0+static void riscv_irq_enable (struct irq_data *d) +{ +struct riscv_irq_data *data =irq_data_get_irq_chip_data (d); +atomic_long_or ((1 << (long )d->hwirq), &per_cpu (riscv_early_sie, data->hart));This is a bit dense to get into without a few words of how it's expected to work.
OK, how does this look? https://github.com/riscv/riscv-linux/commit/112fd2d882c2363508a660061da558d772a4ff0b
Quoted 9 lines
arch/riscv/kernel/irq.c line 178
Quoted 7 lines
arch/riscv/kernel/irq.c new file +7
-0+static int riscv_intc_init (struct device_node *node,struct device_node *parent) +{ +int hart; + +if (parent)return 0 ;// should have no interrupt parent + +if ((hart =riscv_of_processor_hart (node->parent)) >=0 ) {Common pattern in kernel is to detect error instead:
Quoted 8 lines
hart = riscv_of_processor_hart(node->parent);
if (hart < 0) {
<from your else side here>
return 0;
}
<body if your if statement here>
return 0;OK. I've fixed this one here
https://github.com/riscv/riscv-linux/commit/5f48d9ba0d3cd19dc0bf95f66370de4cfcd84cca
I'll try to remember to fix any others that I come across.
Quoted 11 lines
arch/riscv/kernel/pci.c line 2
Quoted 8 lines
arch/riscv/kernel/pci.c new file +2
-0@@ -0,0 +1,36 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c So, you should add recursive reference from there (i.e. powerpc).
Quoted 1 line
But in the end, there's essentially no code in this file. :)
Well, now there's more copyright notices than lines of code... :)
https://github.com/riscv/riscv-linux/commit/5ad312f755935319fdbb6739377b400ea81cd2ec
Quoted 4 lines
arch/riscv/kernel/pci.c line 3
Quoted 1 line
arch/riscv/kernel/pci.c new file +1
-0+#define MAX_DEVICES 1024 // 0 is reservedSeems like an odd comment to have here (and should probably not go at the end of the line)
Device 0 in the PLIC is reserved to mean "no device", which means "MAX_DEVICES" is a bit of an odd name (there can only be MAX_DEVICES-1 devices). I've added a larger comment to describe this better.
https://github.com/riscv/riscv-linux/commit/9d16413051dd86db0fb8a792f3d5f05ce788d145
Quoted 6 lines
arch/riscv/kernel/pci.c line 6
Quoted 3 lines
arch/riscv/kernel/pci.c new file +3
-0+#define PLIC_HART_CONTEXT (data, i) (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i) +#define PLIC_ENABLE_CONTEXT (data, i) (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i) +#define PLIC_PRIORITY (data) (struct plic_priority *)((char *)data->reg + PRIORITY_BASE)Since you have typecasting and stuff here, small static inlines with appropriate return types seems slightly tidier.
OK. https://github.com/riscv/riscv-linux/commit/c416649b203276d944be595d87caf042c998727f
Quoted 6 lines
arch/riscv/kernel/pci.c line 10
Quoted 4 lines
arch/riscv/kernel/pci.c new file +4
-0+static void plic_chained_handle_irq (struct irq_desc *desc) +{ +struct plic_handler *handler =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc);Whitespace.
These were fixed along with the other checkpatch messages.
Quoted 4 lines
[wrapping up review of this patch at this point to keep size down]
-Olof
Thanks for the comments! I'll batch these up into a v2 when I'm done with everyone's comments from this round.
Arnd Bergmann
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 5 lines · Palmer Dabbelt
On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:
* Parens around single-statement
__asm__macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.
I would generally recommend using inline functions for those, and only do macros when you need them.
Quoted 3 lines
* Parens around macros like "#define
RISCV_PTR.dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.
agreed
Quoted 3 lines
* Warnings about volatile in function declarations in
bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.
Agreed, bitops.h is one of the few headers that should use 'volatile'.
Quoted 2 lines
* Definitions like
ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.
What is the warning here? I would assume that you should leave this unchanged as well.
Quoted 2 lines
* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).
It depends. What typedefs are those? Removing the typedefs in both the kernel and the other code that uses the same types is likely the best option here.
Quoted 2 lines
* A handful of lines over 80 characters that I think are onerous to break any more.
Right, don't worry about it too much, and use common sense for this warning.
Quoted 3 lines
* Some warnings about
printk()not having aKERN_prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (inshow_regs, for example, where arm64 also has them).
KERN_CONT
Quoted 2 lines
* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.
I would try to fix those by using a header even if there is only one user. I'd actually like to get a compile-time warning for those in the long run, maybe with 'make W=1', so better don't introduce new ones.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 9 lines · Arnd Bergmann
Quoted 5 lines · Palmer Dabbelt
On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:
* Parens around single-statement
__asm__macros. For these I also get a message when they're wrapped in "do {} while (0)", so I'm not sure what else to do.I would generally recommend using inline functions for those, and only do macros when you need them.
We've tried to avoid new macros, so these are mostly from places where other architectures use macros (like mb) or where we need to use CPP token pasting (like __op_bit). Should I change things like mb?
Quoted 10 lines
Quoted 3 lines
* Parens around macros like "#define
RISCV_PTR.dword". These can't have parens because they go directly to the assembler, so I'm considering this a false-positive.agreed
Quoted 3 lines
* Warnings about volatile in function declarations in
bitops.h. These are copied from other architectures. There were a handful of other volatiles that I fixed,, but I think these should stay.
Quoted 7 lines
Agreed,
bitops.his one of the few headers that should use 'volatile'.Quoted 2 lines
* Definitions like
ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.What is the warning here? I would assume that you should leave this unchanged as well.
ERROR: #define of 'ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - use Kconfig variables or standard guards instead #2533: FILE: arch/riscv/include/asm/elf.h:79:
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
Quoted 6 lines
Quoted 2 lines
* We added new typedefs, I can remove these if that's a problem. They're there to match our other code (bootloader and simulator).
It depends. What typedefs are those? Removing the typedefs in both the kernel and the other code that uses the same types is likely the best option here.
OK, I'll add it to my TODO list.
Quoted 11 lines
Quoted 2 lines
* A handful of lines over 80 characters that I think are onerous to break any more.
Right, don't worry about it too much, and use common sense for this warning.
Quoted 3 lines
* Some warnings about
printk()not having aKERN_prefix. I fixed a handful of these, but the remaining ones I don't know how to fix (inshow_regs, for example, where arm64 also has them).
KERN_CONT
https://github.com/riscv/riscv-linux/commit/98e8fe9cb19d495180a9be03a0aa48c0183dd5be
Quoted 6 lines
Quoted 2 lines
* Extern declarations in C files, all of which link to symbols in assembly or linker scripts. These were copied from other architectures.
I would try to fix those by using a header even if there is only one user. I'd actually like to get a compile-time warning for those in the long run, maybe with 'make W=1', so better don't introduce new ones.
OK, I'll fix them.
Arnd Bergmann
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 7 lines · Palmer Dabbelt
Quoted 6 lines · Arnd Bergmann
Quoted 4 lines · Palmer Dabbelt
On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:
* Definitions like
ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.
Quoted 6 lines
Quoted 2 lines
What is the warning here? I would assume that you should leave this unchanged as well.
ERROR: #define of '
ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - useKconfigvariables or standard guards instead #2533: FILE:arch/riscv/include/asm/elf.h:79:
+#defineARCH_HAS_SETUP_ADDITIONAL_PAGES
Ok, you can definitely ignore this one. The warning is meant to prevent adding new macros like that, but the macro already exists in the other architectures, and I see no point in converting them all into a CONFIG_ symbol.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 11 lines · Arnd Bergmann
Quoted 10 lines · Palmer Dabbelt
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · Palmer Dabbelt
On Mon, 22 May 2017 19:11:35 PDT (-0700), [email protected] wrote:
* Definitions like
ARCH_HAS_SETUP_ADDITIONAL_PAGES, these are also present in other architectures.What is the warning here? I would assume that you should leave this unchanged as well.
Quoted 7 lines
Quoted 3 lines
ERROR: #define of '
ARCH_HAS_SETUP_ADDITIONAL_PAGES' is wrong - useKconfigvariables or standard guards instead #2533: FILE:arch/riscv/include/asm/elf.h:79:
+#defineARCH_HAS_SETUP_ADDITIONAL_PAGESOk, you can definitely ignore this one. The warning is meant to prevent adding new macros like that, but the macro already exists in the other architectures, and I see no point in converting them all into a
CONFIG_symbol.
Sounds good.
Arnd Bergmann
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
In reply to Palmer DabbeltQuoted 1 line
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc",
riscv_intc_init);
Please move the majority of this file into drivers/irqchip as a standalone driver.
Quoted 31 lines
arch/riscv/kernel/pci.c new file +25
-0@@ -0,0 +1,36 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c +* +* Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM +* Copyright (C) 2014 ARM Ltd. +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +*/ + +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/pci.h> + +/* +* Called after each bus is probed, but before its children are examined +*/ +void pcibios_fixup_bus (struct pci_bus *bus) +{
arch/riscv/kernel/pci.c line 35
Quoted 10 lines
arch/riscv/kernel/pci.c new file +10
-0+/* nothing to do, expected to be removed in the future */ +} +/* +* We don't have to worry about legacy ISA devices, so nothing to do here +*/ +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +}
Can you add a patch to remove the need for this, and send that to the PCI maintainers?
In the long run, I think we want both of these to be pci host bridge driver specific callbacks rather than per-architecture definitions, but for the moment, moving the empty version as a __weak copy into drivers/pci/ should be sufficient.
[note: don't ever use __weak elsewhere, the use in PCI is
only done for historic reasons and we want to get rid of that too, but for now it's more important to avoid adding yet another pointless copy]
If you don't care about LPC/ISA devices, then your PCI_MIN_IO should also be zero instead of 0x1000
arch/riscv/kernel/plic.c
Quoted 5 lines
arch/riscv/kernel/plic.c new file +0
-0
drivers/irqchip/riscv-plic.c
The file needs some work for following coding style, once that is done, please submit to the irqchip maintainers.
Quoted 6 lines
arch/riscv/kernel/plic.c new file +6
-0+#define PLIC_HART_CONTEXT (data, i) (struct plic_hart_context *)((char*)data->reg + HART_BASE + HART_SIZE*i) +#define PLIC_ENABLE_CONTEXT (data, i) (struct plic_enable_context *)((char*)data->reg + ENABLE_BASE + ENABLE_SIZE*i) +#define PLIC_PRIORITY (data) (struct plic_priority *)((char *)data->reg + PRIORITY_BASE) + +struct plic_hart_context { +volatile u32 threshold;
arch/riscv/kernel/plic.c line 51
Quoted 10 lines
arch/riscv/kernel/plic.c new file +10
-0+volatile u32 claim; +}; + +struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry +}; + +struct plic_priority { +volatile u32 prio[MAX_DEVICES ]; +};
The 'volatile' seems misplaced here. What is it for?
Quoted 1 line
+// TODO: add a /sys interface to set priority + per-hart enables for steering
No driver-private sysfs interfaces please for irqchips please.
See http://elixir.free-electrons.com/linux/latest/source/Documentation/IRQ-affinity.txt
for setting the affinity.
Quoted 20 lines
arch/riscv/kernel/reset.c new file +14
-0@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ +
arch/riscv/kernel/reset.c line 24
Quoted 10 lines
arch/riscv/kernel/reset.c new file +10
-0+#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +}
Call do_kernel_restart(cmd) here.
arch/riscv/kernel/reset.c line 28
Quoted 3 lines
arch/riscv/kernel/reset.c new file +3
-0+void machine_halt (void ) +{ +}
This should not return. Either make it call sbi_shutdown as well, or use the ARM implementation:
void machine_halt(void)
{
local_irq_disable();
smp_send_stop();
while (1);
}arch/riscv/kernel/sbi-con.c
Quoted 5 lines
arch/riscv/kernel/sbi-con.c new file +0
-0
As Olof said, move it to drivers/tty/hvc/ and use those helpers.
Quoted 36 lines
arch/riscv/kernel/sys_riscv.c new file +30
-0@@ -0,0 +1,85 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2014 Darius Rad <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/syscalls.h> +#include <asm/unistd.h> + +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, off_t, offset) +{ +if (unlikely (offset & (~PAGE_MASK ))) +return -EINVAL ; +return sys_mmap_pgoff (addr, len, prot, flags, fd, offset >>PAGE_SHIFT ); +} + +#ifndef CONFIG_64BIT +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags,
arch/riscv/kernel/sys_riscv.c line 40
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+ unsigned long, fd, off_t, offset) +{ + /* Note that the shift for mmap2 is constant (12), + regardless of PAGE_SIZE */ + if (unlikely(offset & (~PAGE_MASK >> 12))) + return -EINVAL; +return sys_mmap_pgoff (addr, len, prot, flags, fd, + offset >> (PAGE_SHIFT -12 )); +} +#endif /* !CONFIG_64BIT */
The first one should be CONFIG_64BIT only.
Quoted 16 lines
arch/riscv/kernel/sys_riscv.c new file +16
-0+#ifdef CONFIG_RV_SYSRISCV_ATOMIC +SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1, + unsigned long, arg2, unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + +switch (cmd) { +case RISCV_ATOMIC_CMPXCHG : + ptr = (unsigned int *)arg1; +if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable ();
arch/riscv/kernel/sys_riscv.c line 67
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable (); + +return unlikely (err) ? err : prev; + +case RISCV_ATOMIC_CMPXCHG64 :
Make these two separate syscalls and get rid of the wrapper (I already mentioned it in the header file comments, but it fits better here).
It may be good to have an optimized version in the vdso that does an atomic operation directly if the CPU supports it.
arch/riscv/kernel/time.c
Quoted 5 lines
arch/riscv/kernel/time.c new file +0
-0
drivers/clocksource/riscv-timer.c, and submit it to the respective maintainers.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 4 lines · Arnd Bergmann
Quoted 1 line
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc",
riscv_intc_init);Please move the majority of this file into
drivers/irqchipas a standalone driver.
OK.
https://github.com/riscv/riscv-linux/commit/549c7f5ef63d7be04c9cac7e332ef81ec6ffe103
Quoted 50 lines
Quoted 31 lines
arch/riscv/kernel/pci.c new file +25
-0@@ -0,0 +1,36 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c +* +* Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM +* Copyright (C) 2014 ARM Ltd. +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +*/ + +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/pci.h> + +/* +* Called after each bus is probed, but before its children are examined +*/ +void pcibios_fixup_bus (struct pci_bus *bus) +{arch/riscv/kernel/pci.c line 35
Quoted 10 lines
arch/riscv/kernel/pci.c new file +10
-0+/* nothing to do, expected to be removed in the future */ +} +/* +* We don't have to worry about legacy ISA devices, so nothing to do here +*/ +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +}Can you add a patch to remove the need for this, and send that to the PCI maintainers?
In the long run, I think we want both of these to be pci host bridge driver specific callbacks rather than per-architecture definitions, but for the moment, moving the empty version as a
__weakcopy intodrivers/pci/should be sufficient.
Quoted 4 lines
[note: don't ever use
__weakelsewhere, the use in PCI is
only done for historic reasons and we want to get rid of that too, but for now it's more important to avoid adding yet another pointless copy]
Sounds good
https://github.com/riscv/riscv-linux/commit/4aa540bf849b2a190e288e7d25d262dee21306b3
https://github.com/riscv/riscv-linux/commit/bb3b4c6ca4841538d101f2b9c437f5dccda0b3a7
Quoted 2 lines
If you don't care about LPC/ISA devices, then your
PCI_MIN_IOshould also be zero instead of0x1000
Sorry, but the only Google results for PCI_MIN_IO is this email. There don't appear to be any relevant references to PCI_MIN in the kernel
$ git grep PCI_MIN_ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h: ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT 0x00 drivers/ata/pata_hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt37x.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt3x2n.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ide/hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT 0x3e /* 8 bit Min_Gnt */ drivers/net/fddi/skfp/h/skfbi.h:/* PCI_MIN_GNT 8 bit Min_Gnt */ include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT 0x3e /* 8 bits */
I'm afraid that I'm not sure what to do here.
Quoted 10 lines
arch/riscv/kernel/plic.c
Quoted 5 lines
arch/riscv/kernel/plic.c new file +0
-0
drivers/irqchip/riscv-plic.cThe file needs some work for following coding style, once that is done, please submit to the irqchip maintainers.
I've addressed most of this thanks to some other code reviews, so I'm going to drop the comments that are about things I've already fixed.
Quoted 5 lines
Quoted 1 line
+// TODO: add a /sys interface to set priority + per-hart enables for steering
No driver-private sysfs interfaces please for irqchips please.
See http://elixir.free-electrons.com/linux/latest/source/Documentation/IRQ-affinity.txt
for setting the affinity.
We'll do it the right way when we add IRQ affinity control. Thanks for the heads up!
Quoted 40 lines
Quoted 20 lines
arch/riscv/kernel/reset.c new file +14
-0@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ +arch/riscv/kernel/reset.c line 24
Quoted 10 lines
arch/riscv/kernel/reset.c new file +10
-0+#include <linux/reboot.h> +#include <linux/export.h> +#include <asm/sbi.h> + +void (*pm_power_off)(void ) = machine_power_off; +EXPORT_SYMBOL (pm_power_off); + +void machine_restart (char *cmd) +{ +}Call
do_kernel_restart(cmd)here.arch/riscv/kernel/reset.c line 28
Quoted 3 lines
arch/riscv/kernel/reset.c new file +3
-0+void machine_halt (void ) +{ +}This should not return. Either make it call
sbi_shutdownas well, or use the ARM implementation:
Quoted 6 lines
void
machine_halt(void){ local_irq_disable(); smp_send_stop(); while (1); }
OK.
https://github.com/riscv/riscv-linux/commit/5f486cb73e3a0a5a218d26781e9eae651e59203f
Quoted 7 lines
arch/riscv/kernel/sbi-con.c
Quoted 5 lines
arch/riscv/kernel/sbi-con.c new file +0
-0As Olof said, move it to
drivers/tty/hvc/and use those helpers.
Ah, that's great: now there's almost no code left :)
https://github.com/riscv/riscv-linux/commit/8adad12c5525a70b8837196b8f2d4ac003a7647c
Quoted 40 lines
Quoted 40 lines
arch/riscv/kernel/sys_riscv.c new file +34
-0@@ -0,0 +1,85 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2014 Darius Rad <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or +* NON INFRINGEMENT. See the GNU General Public License for +* more details. +*/ + +#include <linux/syscalls.h> +#include <asm/unistd.h> + +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, off_t, offset) +{ +if (unlikely (offset & (~PAGE_MASK ))) +return -EINVAL ; +return sys_mmap_pgoff (addr, len, prot, flags, fd, offset >>PAGE_SHIFT ); +} + +#ifndef CONFIG_64BIT +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, off_t, offset) +{ +/* Note that the shift for mmap2 is constant (12), +regardless of PAGE_SIZE */
Quoted 8 lines
arch/riscv/kernel/sys_riscv.c line 40
Quoted 6 lines
arch/riscv/kernel/sys_riscv.c new file +6
-0+if (unlikely (offset & (~PAGE_MASK >>12 ))) +return -EINVAL ; +return sys_mmap_pgoff (addr, len, prot, flags, fd, + offset >> (PAGE_SHIFT - 12)); +} +#endif /* !CONFIG_64BIT */ The first one should be
CONFIG_64BITonly.
OK. https://github.com/riscv/riscv-linux/commit/ed7545c6765ba7d705e1bc6ce7b67bb7e8cb0926
Quoted 31 lines
Quoted 16 lines
arch/riscv/kernel/sys_riscv.c new file +16
-0+#ifdef CONFIG_RV_SYSRISCV_ATOMIC +SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1, + unsigned long, arg2, unsigned long, arg3) +{ +unsigned long flags; +unsigned long prev; +unsigned int *ptr; +unsigned int err; + +switch (cmd) { +case RISCV_ATOMIC_CMPXCHG : + ptr = (unsigned int *)arg1; +if (!access_ok (VERIFY_WRITE , ptr,sizeof (unsigned int ))) +return -EFAULT ; + +preempt_disable ();arch/riscv/kernel/sys_riscv.c line 67
Quoted 10 lines
arch/riscv/kernel/sys_riscv.c new file +10
-0+raw_local_irq_save (flags); + err =__get_user (prev, ptr); +if (likely (!err && prev == arg2)) + err =__put_user (arg3, ptr); +raw_local_irq_restore (flags); +preempt_enable (); + +return unlikely (err) ? err : prev; + +case RISCV_ATOMIC_CMPXCHG64 :Make these two separate syscalls and get rid of the wrapper (I already mentioned it in the header file comments, but it fits better here).
Quoted 3 lines
It may be good to have an optimized version in the vdso that does an atomic operation directly if the CPU supports it.
Yep. It's on the list.
Quoted 8 lines
arch/riscv/kernel/time.c
Quoted 5 lines
arch/riscv/kernel/time.c new file +0
-0
drivers/clocksource/riscv-timer.c, and submit it to the respective maintainers.
Sounds good.
https://github.com/riscv/riscv-linux/commit/d9fcab4603c158755e19663dec0040b28ea1aad1
Arnd Bergmann
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 19 lines · Palmer Dabbelt
Quoted 3 lines · Arnd Bergmann
Quoted 1 line
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc",
riscv_intc_init);If you don't care about LPC/ISA devices, then your
PCI_MIN_IOshould also be zero instead of0x1000Sorry, but the only Google results for
PCI_MIN_IOis this email. There don't appear to be any relevant references toPCI_MINin the kernel$ git grep PCI_MIN_ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h: ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT 0x00 drivers/ata/pata_hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt37x.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt3x2n.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ide/hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT 0x3e /* 8 bit Min_Gnt */ drivers/net/fddi/skfp/h/skfbi.h:/* PCI_MIN_GNT 8 bit Min_Gnt */ include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT 0x3e /* 8 bits */
Quoted 1 line
I'm afraid that I'm not sure what to do here.
Sorry, I meant PCIBIOS_MIN_IO
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 20 lines · Arnd Bergmann
Quoted 19 lines · Palmer Dabbelt
Quoted 3 lines · Arnd Bergmann
Quoted 1 line
+IRQCHIP_DECLARE(riscv, "riscv,cpu-intc",
riscv_intc_init);If you don't care about LPC/ISA devices, then your
PCI_MIN_IOshould also be zero instead of0x1000Sorry, but the only Google results for
PCI_MIN_IOis this email. There don't appear to be any relevant references toPCI_MINin the kernel$ git grep PCI_MIN_ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h: ((PCI_MAX_LATENCY << 24) | (PCI_MIN_GRANT << 16) | \ arch/mips/include/asm/mach-loongson64/cs5536/cs5536_pci.h:#define PCI_MIN_GRANT 0x00 drivers/ata/pata_hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt37x.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ata/pata_hpt3x2n.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/ide/hpt366.c: pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); drivers/net/fddi/skfp/h/skfbi.h:#define PCI_MIN_GNT 0x3e /* 8 bit Min_Gnt */ drivers/net/fddi/skfp/h/skfbi.h:/* PCI_MIN_GNT 8 bit Min_Gnt */ include/uapi/linux/pci_regs.h:#define PCI_MIN_GNT 0x3e /* 8 bits */
Quoted 3 lines
Quoted 1 line
I'm afraid that I'm not sure what to do here.
Sorry, I meant
PCIBIOS_MIN_IO
OK, fixed.
Re: [PATCH 6/7] RISC-V: arch/riscv/kernel
In reply to Palmer DabbeltHi!
arch/riscv/kernel/cacheinfo.c line 29
Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10
-0+static void ci_leaf_init (struct cacheinfo *this_leaf, +struct device_node *node, +enum cache_type type,unsigned int level) +{ + this_leaf->of_node = node; + this_leaf->level = level; + this_leaf->type = type; + this_leaf->physical_line_partition =1 ;// not a sector cache + this_leaf->attributes =CACHE_WRITE_BACK |CACHE_READ_ALLOCATE |CACHE_WRITE_ALLOCATE ;// TODO: add to DTS +}
You may want to run the patches through checkpatch. (Comment style, long lines).
Quoted 10 lines
arch/riscv/kernel/cacheinfo.c new file +10
-0+static int __populate_cache_leaves (unsigned int cpu) +{ +struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cacheinfo *this_leaf = this_cpu_ci->info_list; +struct device_node *np =of_cpu_device_node_get (cpu); +int levels =1 , level =1 ; + +if (of_property_read_bool (np,"cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_UNIFIED , level); +if (of_property_read_bool (np,"i-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_INST , level); +if (of_property_read_bool (np,"d-cache-size" ))ci_leaf_init (this_leaf++, np,CACHE_TYPE_DATA , level);
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Palmer Dabbelt
maintainerRe: [PATCH 6/7] RISC-V: arch/riscv/kernel
Quoted 5 lines · On Thu, 25 May 2017 10:05:05 PDT (-0700), [email protected] wrote:
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5
-0+static void ci_leaf_init (struct cacheinfo *this_leaf, +struct device_node *node, +enum cache_type type,unsigned int level) +{ + this_leaf->of_node = node;
Quoted 8 lines
arch/riscv/kernel/cacheinfo.c line 29
Quoted 5 lines
arch/riscv/kernel/cacheinfo.c new file +5
-0+ this_leaf->level = level; + this_leaf->type = type; + this_leaf->physical_line_partition =1 ;// not a sector cache + this_leaf->attributes =CACHE_WRITE_BACK |CACHE_READ_ALLOCATE |CACHE_WRITE_ALLOCATE ;// TODO: add to DTS +}You may want to run the patches through checkpatch. (Comment style, long lines).
Thanks. Someone else suggested this and I've fixed most of the errors. I'll submit a v2 with everyone's feedback once I get through my mail.
Palmer Dabbelt
maintainerPATCH 7/7 RISC-V: arch/riscv/mm
In reply to Palmer Dabbelt--- arch/riscv/mm/Makefile | 1 + arch/riscv/mm/extable.c | 38 +++++++ arch/riscv/mm/fault.c | 279 ++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/mm/init.c | 72 +++++++++++++ arch/riscv/mm/ioremap.c | 96 +++++++++++++++++ 5 files changed, 486 insertions(+) create mode 100644 arch/riscv/mm/Makefile create mode 100644 arch/riscv/mm/extable.c create mode 100644 arch/riscv/mm/fault.c create mode 100644 arch/riscv/mm/init.c create mode 100644 arch/riscv/mm/ioremap.c
arch/riscv/mm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y := init.o fault.o extable.o ioremap.o
arch/riscv/mm/extable.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> +* Copyright (C) 2013 Regents of the University of California +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see the file COPYING, or write +* to the Free Software Foundation, Inc., +* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#include <linux/extable.h> +#include <linux/module.h> +#include <linux/uaccess.h> + +int fixup_exception (struct pt_regs *regs) +{ +const struct exception_table_entry *fixup; + + fixup =search_exception_tables (regs->sepc); +if (fixup) { + regs->sepc = fixup->fixup; +return 1 ; + } +return 0 ; +}
arch/riscv/mm/fault.c new file +279 -0
279 lines not on this page · raw message
arch/riscv/mm/init.c new file +72 -0
72 lines not on this page · raw message
arch/riscv/mm/ioremap.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.13.0
Randy Dunlap
reviewerRe: [PATCH 7/7] RISC-V: arch/riscv/mm
arch/riscv/mm/fault.c line 4
Quoted 11 lines
arch/riscv/mm/fault.c new file +4
-0@@ -0,0 +1,279 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]>
is "sunplusct.com" correct? They don't have a web server?
Signature · 1 line
~Randy
Re: [PATCH 7/7] RISC-V: arch/riscv/mm
Quoted 13 lines · Randy Dunlap
arch/riscv/mm/fault.c line 4
Quoted 11 lines
arch/riscv/mm/fault.c new file +4
-0@@ -0,0 +1,279 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> is "sunplusct.com" correct? They don't have a web server?
Seems to come from arch/score/ contents. Looks like true genealogy is from MIPS though.
-Olof
Palmer Dabbelt
maintainerRe: [PATCH 7/7] RISC-V: arch/riscv/mm
Quoted 15 lines · On Mon, 22 May 2017 19:17:52 PDT (-0700), [email protected] wrote:
Quoted 13 lines · Randy Dunlap
arch/riscv/mm/fault.c line 4
Quoted 11 lines
arch/riscv/mm/fault.c new file +4
-0@@ -0,0 +1,279 @@ +/* +* Copyright (C) 2009 Sunplus Core Technology Co., Ltd. +* Lennox Wu <[email protected]> +* Chen Liqin <[email protected]> is "sunplusct.com" correct? They don't have a web server?
Quoted 2 lines
Seems to come from
arch/score/contents. Looks like true genealogy is from MIPS though.
Albert based the original port on score, so I copied their license header files and appended to them.
Hi Palmer,
Quoted 11 lines · Palmer Dabbelt
We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.
This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.
Quoted 8 lines
These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.
Time is right for review and eventual merge of this. Whether it makes 4.13 depends on how much discussion ensues. :)
Quoted 1 line
Albert and I will volunteer to maintain this port if it's OK with everyone.
It always makes sense to have architecture-knowledge people maintain it; no complaints from me.
What we've seen been useful on other platforms (i.e. arm/arm64) is to offload the per-vendor stuff to a separate tree. It might or might not be needed here; likely to start out it won't be enough material to need it.
Quoted 9 lines
We'd like to thank the various members of the RISC-V software community who have helped us with the port.
Thanks!
In addition to the threaded messages, our port can be found on Git Hib
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1
Quoted 7 lines
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mm
So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add Makefile contents that refers to directories not yet introduced).
While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.
Also, none of the patches seem to have any descriptions. Adding some high-level descriptions of what's in each patch in the patch itself is useful both for reviewing now, and for educating anyone coming along later on trying to learn about the code and why it's been implemented as it has.
I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.
-Olof
Randy Dunlap
reviewerQuoted 16 lines · Olof Johansson
Hi Palmer,
Quoted 11 lines · Palmer Dabbelt
In addition to the threaded messages, our port can be found on Git Hib
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mm
Quoted 8 lines
So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add
Makefilecontents that refers to directories not yet introduced).While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.
Neither the email patches nor the git tree have any Signed-off-by:
entries AFAICT.
Signature · 1 line
~Randy
Palmer Dabbelt
maintainerQuoted 21 lines · On Mon, 22 May 2017 18:25:41 PDT (-0700), [email protected] wrote:
Quoted 20 lines · Olof Johansson
Hi Palmer,
Quoted 11 lines · Palmer Dabbelt
In addition to the threaded messages, our port can be found on Git Hib
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mmSo, one overall comment on this patchset is that it's not bisectable (i.e. early patches add
Makefilecontents that refers to directories not yet introduced).
Quoted 7 lines
Quoted 4 lines
While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.
Neither the email patches nor the git tree have any Signed-off-by:
entries AFAICT.
Makes sense. I went through and checked everything for copyright, so I'll sign off on the next patch set.
Thanks!
Palmer Dabbelt
maintainerQuoted 28 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 11 lines · Palmer Dabbelt
We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.
This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.
Quoted 8 lines
These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.
Time is right for review and eventual merge of this. Whether it makes 4.13 depends on how much discussion ensues. :)
Quoted 1 line
Albert and I will volunteer to maintain this port if it's OK with everyone.
Quoted 7 lines
It always makes sense to have architecture-knowledge people maintain it; no complaints from me.
What we've seen been useful on other platforms (i.e. arm/arm64) is to offload the per-vendor stuff to a separate tree. It might or might not be needed here; likely to start out it won't be enough material to need it.
I'm OK with that. We've been using http://github.com/riscv to hold all our other "riscv-next" branches, but if you think another place is more appropriate then I'm OK with that as well.
Quoted 17 lines
Quoted 9 lines
We'd like to thank the various members of the RISC-V software community who have helped us with the port.
Thanks!
In addition to the threaded messages, our port can be found on Git Hib
https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v1
Quoted 7 lines
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mm
Quoted 8 lines
So, one overall comment on this patchset is that it's not bisectable (i.e. early patches add
Makefilecontents that refers to directories not yet introduced).While it's not overly important to really split up a new architecture introduction into small incremental patches, we generally strive to have the tree fully buildable at any given commit. Some minor rearranging would alleviate these problems.
I only really split things up so they'll get through the various mailing lists, I think of this as one logical commit so I didn't really worry about ordering. I'll swizzle them around next time so everything always builds.
Quoted 5 lines
Also, none of the patches seem to have any descriptions. Adding some high-level descriptions of what's in each patch in the patch itself is useful both for reviewing now, and for educating anyone coming along later on trying to learn about the code and why it's been implemented as it has.
I guess I just wasn't really sure what to say in the big code dumps. I'll look through and try to come up with something better for next time.
Quoted 6 lines
I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.
OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.
Thanks!
Hi Palmer,
Quoted 21 lines · Palmer Dabbelt
Quoted 20 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:
Quoted 19 lines · Palmer Dabbelt
We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.
This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.
These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.
[...]
Quoted 8 lines
Quoted 5 lines
I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.
OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.
You might want to Cc [email protected] on future iterations of this patchset where there's less "noise" than on LKML and the relevant people are more likely to notice ;) Likewise, the device-tree specific bits (e.g. the bindings documentation) should probably be Cc'ed to [email protected]
Tobias
Palmer Dabbelt
maintainerQuoted 33 lines · On Mon, 22 May 2017 23:45:34 PDT (-0700), [email protected] wrote:
Hi Palmer,
Quoted 21 lines · Palmer Dabbelt
Quoted 20 lines · On Mon, 22 May 2017 18:16:20 PDT (-0700), [email protected] wrote:
Quoted 19 lines · Palmer Dabbelt
We'd like to submit for inclusion in Linux a port for the RISC-V architecture. While it is doubtlessly not complete, we think it is far enough along to start the upstreaming process. Our binutils and GCC ports have been accepted and released, and we plan on submitting glibc patches soon.
This port targets Version 1.10 of the RISC-V Privileged ISA, and supports both the RV32 and RV64 user ISAs. The RISC-V community and the 60-some member companies of the RISC-V Foundation are quite eager to have a single, standard Linux port. We thank you in advance for your help in this process and for your feedback on the software contribution itself.
These patches build and boot on top of 4.12-rc2. I understand that the merge window is closed, but it was suggested that the best time to submit a new architecture port would be right after an RC2 as the earliest point at which the tree is usually generally churn-free enough. While we optimistically hope that we can get the port in for the 4.13 merge window, we're also eager to ensure that the user-visible ABI is sane so we can proceed with our glibc port. We'd like to at least get any user ABI issues shaken out as soon as possible, even if we don't make it into 4.13.
[...]
Quoted 6 lines
Quoted 5 lines
I'll add more comments on some of the individual patches; expect this review to take a little while. Reposting once or twice a week to show incorporated changes can be useful; more than that and it can be harder to follow along in the discussion. It all depends on how much comments you end up receiving.
Quoted 8 lines
Quoted 2 lines
OK. I'll incorporate all the feedback I get over the next week or so into a v2 patch set.
You might want to Cc [email protected] on future iterations of this patchset where there's less "noise" than on LKML and the relevant people are more likely to notice ;) Likewise, the device-tree specific bits (e.g. the bindings documentation) should probably be Cc'ed to [email protected]
OK, thanks. I'll do that for the v2.
Randy Dunlap
reviewerQuoted 8 lines · Palmer Dabbelt
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mm
Now at patch 0004-riscv.patch
Warning: trailing whitespace in line 3 of arch/riscv/include/asm/asm.h
Warning: trailing whitespace in line 115 of arch/riscv/include/asm/spinlock.h
Now at patch 0006-riscv.patch
Warning: trailing whitespace in line 271 of arch/riscv/kernel/entry.S
Warning: trailing whitespace in line 77 of arch/riscv/kernel/process.c
Warning: trailing whitespace in line 78 of arch/riscv/kernel/smpboot.c
Signature · 1 line
~Randy
Palmer Dabbelt
maintainerQuoted 11 lines · On Mon, 22 May 2017 19:16:43 PDT (-0700), [email protected] wrote:
Quoted 8 lines · Palmer Dabbelt
[PATCH 1/7] RISC-V: Top-Level
Makefilefor riscv{32,64} [PATCH 2/7] RISC-V:arch/riscvMakefileand Kconfigs [PATCH 3/7] RISC-V: Device Tree Documentation [PATCH 4/7] RISC-V:arch/riscv/include
[PATCH 5/7] RISC-V:arch/riscv/lib
[PATCH 6/7] RISC-V:arch/riscv/kernel
[PATCH 7/7] RISC-V:arch/riscv/mm
Quoted 8 lines
Now at patch 0004-riscv.patch
Warning: trailing whitespace in line 3 ofarch/riscv/include/asm/asm.h
Warning: trailing whitespace in line 115 ofarch/riscv/include/asm/spinlock.hNow at patch 0006-riscv.patch
Warning: trailing whitespace in line 271 ofarch/riscv/kernel/entry.S
Warning: trailing whitespace in line 77 ofarch/riscv/kernel/process.c
Warning: trailing whitespace in line 78 ofarch/riscv/kernel/smpboot.c
Sorry about that, I'll fix these for v2.
Palmer Dabbelt
maintainerRISC-V Linux Port v2
In reply to Palmer DabbeltThanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
A highlight of the changes since the v1 patch set includes:
* We've split out our drivers into the right places, which means now there's a lot more patches. I'll be submitting these patches to various subsystem maintainers and including them in any future RISC-V patch sets until they've been merged.
* The SBI console driver has been completely rewritten to use the HVC helpers and is now significantly smaller.
* We've begun to use weaker barries as opposed to just the big "fence". There's still some work to do here, specifically:
- We need fences in the realxed MMIO functions.
- The non-relaxed MMIO functions are missing R/W bits on their fences.
- Many AMOs need the aq and rl bits set.
* We now have thread_info in task_struct. As a result, sscratch now contains TP instead of SP. This was necessary because thread_info is no longer on the stack.
* A few shared routines have been added that we use instead of creating another arch copy.
Here's my TODO list
* The memory model changes indicated above.
* I need to go through checkpatch again to make sure none of the messages are valid problems.
* Put an implementation of atomic compare/exchange in the VDSO when atomic instructions are enabled, otherwise insert stubs to the cmpxchg syscall.
* Remove the extra multiplexing in the cmpxchg syscall.
Aside from those two releatively minor ABI issues, I think our ABI is in good shape. Unless there are any other issues that crop up I'd like to begin our glibc submission early next week.
[PATCH 01/17] drivers: support PCIe in RISCV
[PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt [PATCH 03/17] base: fix order of OF initialization [PATCH 04/17] Documentation: atomic_ops.txt is
[PATCH 05/17] MAINTAINERS: Add RISC-V
[PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource} [PATCH 07/17] lib: Add shared copies of some GCC library routines [PATCH 08/17] dts: include documentation for the RISC-V interrupt [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource [PATCH 10/17] irqchip: New RISC-V PLIC Driver
[PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver [PATCH 12/17] tty: New RISC-V SBI Console Driver
[PATCH 13/17] RISC-V: Add include subdirectory
[PATCH 14/17] RISC-V: lib files
[PATCH 15/17] RISC-V: Add mm subdirectory
[PATCH 16/17] RISC-V: Add kernel subdirectory
[PATCH 17/17] RISC-V: Makefile and Kconfig
Palmer Dabbelt
maintainerRISC-V Linux Port v2
In reply to Palmer DabbeltThanks to everyone who has participated in the review process so far. We've made a lot of changes since the v1 and while this isn't ready to go yet, I finally managed to get through everything in my inbox so I thought it would be a good time to submit a v2 so everyone is on the same page.
A highlight of the changes since the v1 patch set includes:
* We've split out our drivers into the right places, which means now there's a lot more patches. I'll be submitting these patches to various subsystem maintainers and including them in any future RISC-V patch sets until they've been merged.
* The SBI console driver has been completely rewritten to use the HVC helpers and is now significantly smaller.
* We've begun to use weaker barries as opposed to just the big "fence". There's still some work to do here, specifically:
- We need fences in the realxed MMIO functions.
- The non-relaxed MMIO functions are missing R/W bits on their fences.
- Many AMOs need the aq and rl bits set.
* We now have thread_info in task_struct. As a result, sscratch now contains TP instead of SP. This was necessary because thread_info is no longer on the stack.
* A few shared routines have been added that we use instead of creating another arch copy.
Here's my TODO list
* The memory model changes indicated above.
* I need to go through checkpatch again to make sure none of the messages are valid problems.
* Put an implementation of atomic compare/exchange in the VDSO when atomic instructions are enabled, otherwise insert stubs to the cmpxchg syscall.
* Remove the extra multiplexing in the cmpxchg syscall.
Aside from those two releatively minor ABI issues, I think our ABI is in good shape. Unless there are any other issues that crop up I'd like to begin our glibc submission early next week.
[PATCH 01/17] drivers: support PCIe in RISCV
[PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt [PATCH 03/17] base: fix order of OF initialization [PATCH 04/17] Documentation: atomic_ops.txt is
[PATCH 05/17] MAINTAINERS: Add RISC-V
[PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource} [PATCH 07/17] lib: Add shared copies of some GCC library routines [PATCH 08/17] dts: include documentation for the RISC-V interrupt [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource [PATCH 10/17] irqchip: New RISC-V PLIC Driver
[PATCH 11/17] irqchip: RISC-V Local Interrupt Controller Driver [PATCH 12/17] tty: New RISC-V SBI Console Driver
[PATCH 13/17] RISC-V: Add include subdirectory
[PATCH 14/17] RISC-V: lib files
[PATCH 15/17] RISC-V: Add mm subdirectory
[PATCH 16/17] RISC-V: Add kernel subdirectory
[PATCH 17/17] RISC-V: Makefile and Kconfig
Palmer Dabbelt
maintainerPATCH 1/17 drivers: support PCIe in RISCV
From: "Wesley W. Terpstra" <[email protected]>
There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.
--- drivers/pci/Makefile | 1 + drivers/pci/host/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/pci/Makefile +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o obj-$(CONFIG_TILE) += setup-irq.o obj-$(CONFIG_SPARC_LEON) += setup-irq.o obj-$(CONFIG_M68K) += setup-irq.o +obj-$(CONFIG_RISCV) += setup-irq.o # # ACPI Related PCI FW Functions
drivers/pci/host/Kconfig +1 -1
@@ -71,7 +71,7 @@ config PCI_HOST_GENERIC config PCIE_XILINX bool "Xilinx AXI PCIe host bridge support" - depends on ARCH_ZYNQ || MICROBLAZE + depends on ARCH_ZYNQ || MICROBLAZE || RISCV help Say 'Y' here if you want kernel to support the Xilinx AXI PCIe Host Bridge driver.
Signature · 1 line
2.13.0
Re: [PATCH 01/17] drivers: support PCIe in RISCV
CC pci folks
Quoted 39 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/Makefile | 1 + drivers/pci/host/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/pci/Makefile +1
-0@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o obj-$(CONFIG_TILE) += setup-irq.o obj-$(CONFIG_SPARC_LEON) += setup-irq.o obj-$(CONFIG_M68K) += setup-irq.o +obj-$(CONFIG_RISCV) += setup-irq.o # # ACPI Related PCI FW Functionsdrivers/pci/host/Kconfig +1
-2@@ -71,7 +71,7 @@ config PCI_HOST_GENERIC config PCIE_XILINX bool "Xilinx AXI PCIe host bridge support" - depends on ARCH_ZYNQ || MICROBLAZE + depends on ARCH_ZYNQ || MICROBLAZE || RISCV help Say 'Y' here if you want kernel to support the Xilinx AXI PCIe Host Bridge driver. --2.13.0
Re: [PATCH 01/17] drivers: support PCIe in RISCV
In reply to Palmer DabbeltQuoted 17 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/Makefile | 1 + drivers/pci/host/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/pci/Makefile +0
-0
drivers/pci/Makefile obj-$(CONFIG_MIPS) += setup-irq.o · line 44
Quoted 4 lines
drivers/pci/Makefile +1
-0@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o obj-$(CONFIG_TILE) += setup-irq.o obj-$(CONFIG_SPARC_LEON) += setup-irq.o obj-$(CONFIG_M68K) += setup-irq.o +obj-$(CONFIG_RISCV) += setup-irq.o
Can we do a cleanup here and add a ARCH_USE_GENERIC_PCI_SETUP Kconfig symbol that all these architectures can select?
drivers/pci/host/Kconfig config PCI_HOST_GENERIC · line 74
Quoted 13 lines
drivers/pci/Makefile +0
-0# # ACPI Related PCI FW Functionsdrivers/pci/host/Kconfig +1
-1@@ -71,7 +71,7 @@ config PCI_HOST_GENERIC config PCIE_XILINX bool "Xilinx AXI PCIe host bridge support" - depends on ARCH_ZYNQ || MICROBLAZE + depends on ARCH_ZYNQ || MICROBLAZE || RISCV
What about of arch support does this driver need? It seems to compile just fine on x86 for me, so maybe we should just drop the arch dependency entirely.
A message that is not in the archive (sent off-list or not yet received): CAMgXwTjXZ5dsxmJ2FyWhCRWo-3nyvKUDfhfV0nNC+oakF=AEsA@mail.gmail.com
Re: [PATCH 01/17] drivers: support PCIe in RISCV
Quoted 31 lines · Wesley Terpstra
On Jun 7, 2017 7:26 AM, "Christoph Hellwig" <[email protected]> wrote:
Quoted 17 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/Makefile | 1 + drivers/pci/host/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/pci/Makefile +0
-0drivers/pci/Makefile obj-$(CONFIG_MIPS) += setup-irq.o · line 44
Quoted 4 lines
drivers/pci/Makefile +1
-0@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o obj-$(CONFIG_TILE) += setup-irq.o obj-$(CONFIG_SPARC_LEON) += setup-irq.o obj-$(CONFIG_M68K) += setup-irq.o +obj-$(CONFIG_RISCV) += setup-irq.oCan we do a cleanup here and add a
ARCH_USE_GENERIC_PCI_SETUPKconfigsymbol that all these architectures can select?
Quoted 2 lines
That would probably be better. I did not want to touch other
arch/folders in our changes.
I understand that approach when you're doing things in your tree early, but in this case (and at this phase in submission/merging), don't be afraid to touch other architectures and refactor/clean up.
Please do the refactor in a separate preceding patch and submit it separate/soon instead of keeping it just in the series and bundled with your addition. That way it can go in when ready even if the rest of the series is spinning.
-Olof
Palmer Dabbelt
maintainerRe: [patches] Re: [PATCH 01/17] drivers: support PCIe in RISCV
Quoted 35 lines · Olof Johansson
Quoted 31 lines · Wesley Terpstra
On Jun 7, 2017 7:26 AM, "Christoph Hellwig" <[email protected]> wrote:
Quoted 17 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
There are RISC-V systems that have been mapped to Xilinx FPGAs that have their PCIe controllers on chip. These build system changes allow RISC-V systems to enable the Xilinx PCIe controller, and to setup PCIe IRQs.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/Makefile | 1 + drivers/pci/host/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/pci/Makefile +0
-0drivers/pci/Makefile obj-$(CONFIG_MIPS) += setup-irq.o · line 44
Quoted 4 lines
drivers/pci/Makefile +1
-0@@ -41,6 +41,7 @@ obj-$(CONFIG_MIPS) += setup-irq.o obj-$(CONFIG_TILE) += setup-irq.o obj-$(CONFIG_SPARC_LEON) += setup-irq.o obj-$(CONFIG_M68K) += setup-irq.o +obj-$(CONFIG_RISCV) += setup-irq.oCan we do a cleanup here and add a
ARCH_USE_GENERIC_PCI_SETUPKconfigsymbol that all these architectures can select?Quoted 2 lines
That would probably be better. I did not want to touch other
arch/folders in our changes.
Quoted 8 lines
I understand that approach when you're doing things in your tree early, but in this case (and at this phase in submission/merging), don't be afraid to touch other architectures and refactor/clean up.
Please do the refactor in a separate preceding patch and submit it separate/soon instead of keeping it just in the series and bundled with your addition. That way it can go in when ready even if the rest of the series is spinning.
Makes sense. I've started submitting the various smaller patches so we can get them all in to make our patch set smaller.
Palmer Dabbelt
maintainerPATCH 2/17 pcie-xilinx: add missing 5th legacy interrupt
In reply to Palmer DabbeltFrom: "Wesley W. Terpstra" <[email protected]>
These are numbered from 1.
--- drivers/pci/host/pcie-xilinx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +2 -2
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) val = ((val &XILINX_PCIE_RPIFR1_INTR_MASK ) >>XILINX_PCIE_RPIFR1_INTR_SHIFT ) +1 ;generic_handle_irq (irq_find_mapping (port->leg_domain, - val)); + val +1 )); } }
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)return -ENODEV ; } - port->leg_domain =irq_domain_add_linear (pcie_intc_node,4 , + port->leg_domain =irq_domain_add_linear (pcie_intc_node,5 , &intx_domain_ops, port);if (!port->leg_domain) {
Signature · 1 line
2.13.0
Re: [PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt
CC pci folks
Quoted 33 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
These are numbered from 1.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/host/pcie-xilinx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/host/pcie-xilinx.c +2
-3@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) val = ((val &XILINX_PCIE_RPIFR1_INTR_MASK ) >>XILINX_PCIE_RPIFR1_INTR_SHIFT ) +1 ;generic_handle_irq (irq_find_mapping (port->leg_domain, - val)); + val +1 )); } }@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)return -ENODEV ; } - port->leg_domain =irq_domain_add_linear (pcie_intc_node,4 , + port->leg_domain =irq_domain_add_linear (pcie_intc_node,5 , &intx_domain_ops, port);if (!port->leg_domain) { --2.13.0
Re: [PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt
In reply to Palmer Dabbelt+ Bjorn
Quoted 24 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
These are numbered from 1.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/host/pcie-xilinx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/host/pcie-xilinx.c +1
-1@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) val = ((val &XILINX_PCIE_RPIFR1_INTR_MASK ) >>XILINX_PCIE_RPIFR1_INTR_SHIFT ) +1 ;generic_handle_irq (irq_find_mapping (port->leg_domain, - val)); + val +1 )); } }
drivers/pci/host/pcie-xilinx.c static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) · line 530
Quoted 8 lines
drivers/pci/host/pcie-xilinx.c +1
-1@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)return -ENODEV ; } - port->leg_domain =irq_domain_add_linear (pcie_intc_node,4 , + port->leg_domain =irq_domain_add_linear (pcie_intc_node,5 , &intx_domain_ops, port);if (!port->leg_domain) {
This is a common problem with the current OF code that numbers INTx from 1 instead of zero (there is no 5th legacy interrupts in the PCI spec, despite what $SUBJECT says). I'd be inclined to fix this at the core level rather than papering over it in the various drivers...
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 02/17] pcie-xilinx: add missing 5th legacy interrupt
Quoted 4 lines · Marc Zyngier
This is a common problem with the current OF code that numbers INTx from 1 instead of zero (there is no 5th legacy interrupts in the PCI spec, despite what $SUBJECT says). I'd be inclined to fix this at the core level rather than papering over it in the various drivers...
While I agree that it's a problem with OF, every other driver has already been changed to paper over the issue. This patch just brings this one remaining OF-PCIe driver to the same level as the others. Without the patch, the driver doesn't work at all if there is a bridge chip on the other end of the controller, so this is not just a hypothetical concern for us.
Couldn't the eventual OF fix just refactor this driver along with all of the others? Doing such a sweeping OF change is outside my current comfort zone. I am not familiar enough with the code to understand all the parts that would need to be touched.
Palmer Dabbelt
maintainerPATCH 2/17 pcie-xilinx: add missing 5th legacy interrupt
In reply to Palmer DabbeltFrom: "Wesley W. Terpstra" <[email protected]>
These are numbered from 1.
--- drivers/pci/host/pcie-xilinx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-xilinx.c +2 -2
@@ -443,7 +443,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) val = ((val &XILINX_PCIE_RPIFR1_INTR_MASK ) >>XILINX_PCIE_RPIFR1_INTR_SHIFT ) +1 ;generic_handle_irq (irq_find_mapping (port->leg_domain, - val)); + val +1 )); } }
@@ -524,7 +524,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)return -ENODEV ; } - port->leg_domain =irq_domain_add_linear (pcie_intc_node,4 , + port->leg_domain =irq_domain_add_linear (pcie_intc_node,5 , &intx_domain_ops, port);if (!port->leg_domain) {
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 3/17 base: fix order of OF initialization
In reply to Palmer DabbeltFrom: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating of_node link
... which you get for every CPU on all architectures with a OF cpu/ node.
This affects riscv, nios, etc.
--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/init.c +1 -1
@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init (); -of_core_init (); }
Signature · 1 line
2.13.0
Re: [PATCH 03/17] base: fix order of OF initialization
CC devicetree folks
Quoted 29 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.This affects riscv, nios, etc.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/base/init.c +1
-2@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init (); -of_core_init (); } --2.13.0
Mark Rutland
reviewerRe: [PATCH 03/17] base: fix order of OF initialization
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.
I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
Thanks,
Mark.
Quoted 21 lines
Quoted 21 lines
This affects riscv, nios, etc.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/base/init.c +1
-0@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init ();
Quoted 8 lines
Quoted 4 lines
drivers/base/init.c +0
-2-of_core_init (); } --2.13.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/17] base: fix order of OF initialization
It was a while ago that I debugged this. I already reported this bug to Benjamin Herrenschmidt (now in CC), and I believe he has a patch of his own to fix the same issue.
As I understand it, of_core_init sets up the OF entries in /sys/firmware/devicetree. During platform bringup, when the system describes the cpu + cache hierarchy, it also makes an of_node symlink into that directory. However, if it doesn't exist yet, you get the warning.
# ls -l /sys/devices/system/cpu/cpu3/of_node lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/devices/system/cpu/cpu3/of_node -> ../../../../firmware/devicetree/base/cpus/cpu@3
Quoted 48 lines · Mark Rutland
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
Thanks,
Mark.Quoted 29 lines
Quoted 24 lines
This affects riscv, nios, etc.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/base/init.c +1
-2@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init (); -of_core_init (); } --Quoted 1 line
2.13.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/17] base: fix order of OF initialization
Quoted 9 lines · Wesley Terpstra
It was a while ago that I debugged this. I already reported this bug to Benjamin Herrenschmidt (now in CC), and I believe he has a patch of his own to fix the same issue.
As I understand it,
of_core_initsets up the OF entries in/sys/firmware/devicetree. During platform bringup, when the system describes the cpu + cache hierarchy, it also makes anof_nodesymlink into that directory. However, if it doesn't exist yet, you get the warning.
Ugh... yes I did a patch for that and I think it fell through the cracks, I can't even find it anymore...
The patch quoted here is fine I think. Everything in the device model can potentially use OF bits these days, it makes sense to have them initialized earlier.
Cheers,
Ben.
Quoted 55 lines
# ls -l /sys/devices/system/cpu/cpu3/of_node lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/devices/system/cpu/cpu3/of_node -> ../../../../firmware/devicetree/base/cpus/cpu@3Quoted 49 lines · Mark Rutland
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
Thanks,
Mark.Quoted 30 lines
Quoted 24 lines
This affects riscv, nios, etc.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/base/init.c +1
-2@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init (); -of_core_init (); } --Quoted 1 line
2.13.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/17] base: fix order of OF initialization
In reply to Wesley TerpstraQuoted 10 lines · Wesley Terpstra
It was a while ago that I debugged this. I already reported this bug to Benjamin Herrenschmidt (now in CC), and I believe he has a patch of his own to fix the same issue.
As I understand it,
of_core_initsets up the OF entries in/sys/firmware/devicetree. During platform bringup, when the system describes the cpu + cache hierarchy, it also makes anof_nodesymlink into that directory. However, if it doesn't exist yet, you get the warning.
Quoted 21 lines
# ls -l /sys/devices/system/cpu/cpu3/of_node lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/devices/system/cpu/cpu3/of_node -> ../../../../firmware/devicetree/base/cpus/cpu@3Quoted 15 lines · Mark Rutland
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
On the surface, the patch looks reasonable. But it is not obvious to me why the error message is occurring. I would like to understand the cause before saying the patch is good.
What kernel version is showing the error? For a specific architecture (the patch lists 'riscv, nios, etc'), which config and device tree source?
And again, what is the calling path?
- Frank
Quoted 34 lines
Quoted 33 lines
Thanks,
Mark.Quoted 29 lines
Quoted 24 lines
This affects riscv, nios, etc.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/base/init.c +1
-2@@ -31,9 +31,9 @@ void __init driver_init(void)/* These are also core pieces, but must come after the * core core pieces. */ +of_core_init ();platform_bus_init ();cpu_dev_init ();memory_dev_init ();container_dev_init (); -of_core_init (); } --Quoted 1 line
2.13.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/17] base: fix order of OF initialization
Quoted 37 lines · Frank Rowand
Quoted 10 lines · Wesley Terpstra
It was a while ago that I debugged this. I already reported this bug to Benjamin Herrenschmidt (now in CC), and I believe he has a patch of his own to fix the same issue.
As I understand it,
of_core_initsets up the OF entries in/sys/firmware/devicetree. During platform bringup, when the system describes the cpu + cache hierarchy, it also makes anof_nodesymlink into that directory. However, if it doesn't exist yet, you get the warning.Quoted 21 lines
# ls -l /sys/devices/system/cpu/cpu3/of_node lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/devices/system/cpu/cpu3/of_node -> ../../../../firmware/devicetree/base/cpus/cpu@3Quoted 15 lines · Mark Rutland
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
On the surface, the patch looks reasonable. But it is not obvious to me why the error message is occurring. I would like to understand the cause before saying the patch is good.
Quoted 6 lines
What kernel version is showing the error? For a specific architecture (the patch lists 'riscv, nios, etc'), which config and device tree source?
And again, what is the calling path?
From having grepped around, I think this affects architectures which
select CONFIG_GENERIC_CPU_DEVICES, which includes nios2.
In that case, driver_init() calls cpu_dev_init() before calling of_core_init(). Then we get the callchain:
cpu_dev_init()
-> cpu_dev_register_generic()
-> register_cpu(cpu, i)
-> device_register(&cpu->dev)
-> device_add(dev)
-> device_add_class_symlinks(dev)
... in device_add_class_symlinks, we we dev->of_node, and call sysfs_create_link(), which fails because we haven't called of_core_init() to register the sysfs devicetree directory yet.
Given that, this patch makes sense to me.
FWIW, with the commit message updated to describe the particular ordering problem:
Thanks,
Mark.
Frank Rowand
Acked-byRe: [PATCH 03/17] base: fix order of OF initialization
Quoted 38 lines · Mark Rutland
Quoted 37 lines · Frank Rowand
Quoted 10 lines · Wesley Terpstra
It was a while ago that I debugged this. I already reported this bug to Benjamin Herrenschmidt (now in CC), and I believe he has a patch of his own to fix the same issue.
As I understand it,
of_core_initsets up the OF entries in/sys/firmware/devicetree. During platform bringup, when the system describes the cpu + cache hierarchy, it also makes anof_nodesymlink into that directory. However, if it doesn't exist yet, you get the warning.Quoted 21 lines
# ls -l /sys/devices/system/cpu/cpu3/of_node lrwxrwxrwx 1 root root 0 Jan 1 00:00 /sys/devices/system/cpu/cpu3/of_node -> ../../../../firmware/devicetree/base/cpus/cpu@3Quoted 15 lines · Mark Rutland
Quoted 7 lines · Geert Uytterhoeven
CC devicetree folks
Quoted 4 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
This fixes: [ 0.010000] cpu cpu0: Error -2 creating
of_nodelink
... which you get for every CPU on all architectures with a OF cpu/ node.I take it this means a /cpus node? Or the /cpus/cpu@* nodes?
I'm not seeing this on arm64 when booting v4.12-rc4 with DT, so clearly this doesn't affect all such architectures.
What path are these errors happening in?
On the surface, the patch looks reasonable. But it is not obvious to me why the error message is occurring. I would like to understand the cause before saying the patch is good.
Quoted 7 lines
Quoted 6 lines
What kernel version is showing the error? For a specific architecture (the patch lists 'riscv, nios, etc'), which config and device tree source?
And again, what is the calling path?
From having grepped around, I think this affects architectures which
select
CONFIG_GENERIC_CPU_DEVICES, which includes nios2.
Thanks Mark! The "#ifdef CONFIG_GENERIC_CPU_DEVICES" in cpu_dev_register_generic() explains why we don't see the error on ARM, ARM64, etc. Without the CONFIG option, register_cpu(cpu, i) is not called.
Quoted 14 lines
In that case,
driver_init()callscpu_dev_init()before callingof_core_init(). Then we get the callchain:cpu_dev_init()->
cpu_dev_register_generic()
->register_cpu(cpu, i)
->device_register(&cpu->dev)
->device_add(dev)
->device_add_class_symlinks(dev)... in
device_add_class_symlinks, we wedev->of_node, and callsysfs_create_link(), which fails because we haven't calledof_core_init()to register the sysfs devicetree directory yet.
Quoted 6 lines
Given that, this patch makes sense to me.
FWIW, with the commit message updated to describe the particular ordering problem:
Acked-by Mark Rutland <[email protected]>
Agree with Mark's request to update the commit message, and also I would like to see this shaken out in the -next tree.
Quoted 4 lines
Thanks,
Mark.
Palmer Dabbelt
maintainerPATCH 4/17 Documentation: atomic_ops.txt is core-api/atomic_ops.rst
In reply to Palmer DabbeltI was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.
--- Documentation/memory-barriers.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/memory-barriers.txt +5 -5
@@ -498,11 +498,11 @@ And a couple of implicit varieties: This means that ACQUIRE acts as a minimal "acquire" operation and RELEASE acts as a minimal "release" operation. -A subset of the atomic operations described in atomic_ops.txt have ACQUIRE -and RELEASE variants in addition to fully-ordered and relaxed (no barrier -semantics) definitions. For compound atomics performing both a load and a -store, ACQUIRE semantics apply only to the load and RELEASE semantics apply -only to the store portion of the operation. +A subset of the atomic operations described in core-api/atomic_ops.rst have +ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no +barrier semantics) definitions. For compound atomics performing both a load +and a store, ACQUIRE semantics apply only to the load and RELEASE semantics +apply only to the store portion of the operation. Memory barriers are only required where there's a possibility of interaction between two CPUs or between a CPU and a device. If it can be guaranteed that
Signature · 1 line
2.13.0
Re: [PATCH 04/17] Documentation: atomic_ops.txt is core-api/atomic_ops.rst
CC doc folks
Quoted 32 lines · Palmer Dabbelt
I was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.
Signed-off-by Palmer Dabbelt <[email protected]>--- Documentation/memory-barriers.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)Documentation/memory-barriers.txt +5
-6@@ -498,11 +498,11 @@ And a couple of implicit varieties: This means that ACQUIRE acts as a minimal "acquire" operation and RELEASE acts as a minimal "release" operation. -A subset of the atomic operations described in atomic_ops.txt have ACQUIRE -and RELEASE variants in addition to fully-ordered and relaxed (no barrier -semantics) definitions. For compound atomics performing both a load and a -store, ACQUIRE semantics apply only to the load and RELEASE semantics apply -only to the store portion of the operation. +A subset of the atomic operations described in core-api/atomic_ops.rst have +ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no +barrier semantics) definitions. For compound atomics performing both a load +and a store, ACQUIRE semantics apply only to the load and RELEASE semantics +apply only to the store portion of the operation. Memory barriers are only required where there's a possibility of interaction between two CPUs or between a CPU and a device. If it can be guaranteed that --2.13.0
Re: [PATCH 04/17] Documentation: atomic_ops.txt is core-api/atomic_ops.rst
In reply to Palmer DabbeltQuoted 8 lines · Palmer Dabbelt
I was reading the memory barries documentation in order to make sure the RISC-V barries were correct, and I found a broken link to the atomic operations documentation.
Signed-off-by Palmer Dabbelt <[email protected]>--- Documentation/memory-barriers.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Will
Quoted 24 lines
Documentation/memory-barriers.txt +5
-5@@ -498,11 +498,11 @@ And a couple of implicit varieties: This means that ACQUIRE acts as a minimal "acquire" operation and RELEASE acts as a minimal "release" operation. -A subset of the atomic operations described in atomic_ops.txt have ACQUIRE -and RELEASE variants in addition to fully-ordered and relaxed (no barrier -semantics) definitions. For compound atomics performing both a load and a -store, ACQUIRE semantics apply only to the load and RELEASE semantics apply -only to the store portion of the operation. +A subset of the atomic operations described in core-api/atomic_ops.rst have +ACQUIRE and RELEASE variants in addition to fully-ordered and relaxed (no +barrier semantics) definitions. For compound atomics performing both a load +and a store, ACQUIRE semantics apply only to the load and RELEASE semantics +apply only to the store portion of the operation. Memory barriers are only required where there's a possibility of interaction between two CPUs or between a CPU and a device. If it can be guaranteed thatSignature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 5/17 MAINTAINERS: Add RISC-V
In reply to Palmer DabbeltFrom: 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
@@ -10877,6 +10877,14 @@ M: Maxim Levitsky <[email protected]> S: Maintained F: drivers/memstick/host/r592.* +RISC-V ARCHITECTURE +M: Palmer Dabbelt <[email protected]> +M: Albert Ou <[email protected]> +L: [email protected] +T: git https://github.com/riscv/riscv-linux +S: Supported +F: arch/riscv/ + ROCCAT DRIVERS M: Stefan Achatz <[email protected]> W: http://sourceforge.net/projects/roccat/
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 5/17 MAINTAINERS: Add RISC-V
In reply to Palmer DabbeltFrom: 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
@@ -10877,6 +10877,14 @@ M: Maxim Levitsky <[email protected]> S: Maintained F: drivers/memstick/host/r592.* +RISC-V ARCHITECTURE +M: Palmer Dabbelt <[email protected]> +M: Albert Ou <[email protected]> +L: [email protected] +T: git https://github.com/riscv/riscv-linux +S: Supported +F: arch/riscv/ + ROCCAT DRIVERS M: Stefan Achatz <[email protected]> W: http://sourceforge.net/projects/roccat/
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 6/17 pci: Add generic pcibios_{fixup_bus,align_resource}
In reply to Palmer DabbeltWhile upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.
--- drivers/pci/Makefile | 2 +- drivers/pci/bios.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/bios.c
drivers/pci/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-y += access.o bus.o probe.o host-bridge.o remove.o pci.o \ pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \ - irq.o vpd.o setup-bus.o vc.o mmap.o + irq.o vpd.o setup-bus.o vc.o mmap.o bios.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += slot.o
drivers/pci/bios.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
CC pci folks
Quoted 76 lines · Palmer Dabbelt
While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/pci/Makefile | 2 +- drivers/pci/bios.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/bios.cdrivers/pci/Makefile +1
-1@@ -4,7 +4,7 @@ obj-y += access.o bus.o probe.o host-bridge.o remove.o pci.o \ pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \ - irq.o vpd.o setup-bus.o vc.o mmap.o + irq.o vpd.o setup-bus.o vc.o mmap.o bios.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += slot.odrivers/pci/bios.c new file +42
-1@@ -0,0 +1,42 @@ +/* +* Code borrowed from arch/arm64/kernel/pci.c +* which borrowed from powerpc/kernel/pci-common.c +* which borrowed from arch/alpha/kernel/pci.c +* +* Extruded from code written by +* Dave Rusling ([email protected]) +* David Mosberger ([email protected]) +* Copyright (C) 1999 Andrea Arcangeli <[email protected]> +* Copyright (C) 2000 Ivan Kokshaysky <[email protected]> +* Copyright (C) 2003 Anton Blanchard <[email protected]>, IBM +* Copyright (C) 2014 ARM Ltd. +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +/* This file contains weakly bound functions that implement pcibios functions +* that some architectures have copied verbatim. +*/ + +#include <linux/pci.h> + +/* +* Called after each bus is probed, but before its children are examined +*/ +__attribute__ ((weak)) +void pcibios_fixup_bus (struct pci_bus *bus) +{ +/* nothing to do, expected to be removed in the future */ +} +/* +* We don't have to worry about legacy ISA devices, so nothing to do here +*/ +__attribute__ ((weak)) +resource_size_t pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) +{ +return res->start; +} --2.13.0
Arnd Bergmann
maintainerRe: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
Quoted 10 lines · Geert Uytterhoeven
CC pci folks
Quoted 7 lines · Palmer Dabbelt
While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.
Signed-off-by Palmer Dabbelt <[email protected]>
Thanks a lot for taking care of this!
Quoted 10 lines
drivers/pci/bios.c line 4
Quoted 10 lines
drivers/pci/bios.c new file +4
-0@@ -0,0 +1,42 @@ + +/* This file contains weakly bound functions that implement pcibios functions +* that some architectures have copied verbatim. +*/
Instead of adding a new file, I would suggest adding the two functions next to their callers, in probe.c and setup-res.c, respectively.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Geert Uytterhoeven
CC pci folks
Quoted 6 lines · Palmer Dabbelt
While upstreaming the RISC-V port, it was pointed out that multiple architectures (arc, arm64, cris, microblaze, sh, tile) have copied the mostly empty versions of at least one of these functions. This defines weakly bound versions of the common functions so other architetures can use them.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Palmer Dabbelt <[email protected]>Thanks a lot for taking care of this!
No problem.
Quoted 14 lines
Quoted 11 lines
drivers/pci/bios.c line 4
Quoted 11 lines
drivers/pci/bios.c new file +4
-0@@ -0,0 +1,42 @@ + +/* This file contains weakly bound functions that implement pcibios functions +* that some architectures have copied verbatim. +*/ Instead of adding a new file, I would suggest adding the two functions next to their callers, in
probe.candsetup-res.c, respectively.
I've split this out into another patch set.
Re: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
In reply to Geert UytterhoevenQuoted 1 line · Geert Uytterhoeven
CC pci folks
Ok, replying with pci folks in Cc then :)
Weak symbols have (rightly) gotten a bad reputation, so maybe we should approach this without them.
It seems we have a large number of emptry pcibios_fixup_bus calls alreayd, so I think we should simply have the architectures that do define it define a Kconfig or header symbol and not call it at all otherwise.
For the ones that exist as lot just seem to call pci_read_bridge_bases and/or pcibios_fixup_device_resources in one form or another, and I wonder why we even need the arch indirection for that.
Similarly for pcibios_align_resource: a lot of architetures seem to have a noop, and the once that don't mostly seem copy and paste code, so we should again have a symbol for architectures to opt into it, and we probably should have a generic helper for the VGA window mirroring code instead of duplicating it multiple times.
Arnd Bergmann
maintainerRe: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · Geert Uytterhoeven
CC pci folks
Ok, replying with pci folks in Cc then :)
Weak symbols have (rightly) gotten a bad reputation, so maybe we should approach this without them.
Agreed, I would almost never recommend using a __weak symbol, but they are already widely used in the PCI subsystem, so I suggested using them here for consistency.
We have a struct pci_host_bridge now, and we should eventually move most of the 38 pci specific weak per-architecture symbols into per-host driver callbacks, but that I think that would be too much to ask for when adding an architecture port.
Quoted 4 lines
It seems we have a large number of emptry
pcibios_fixup_buscalls alreayd, so I think we should simply have the architectures that do define it define aKconfigor header symbol and not call it at all otherwise.
I would argue that most of them should not be per-architecture in the first place, the current state is mostly an artifact of the times when each architecture had just one PCI implementation.
The ones that have multiple implementations (arm, powerpc, ...) tend to actually override the weak functions with their own per-host multiplexers again.
Quoted 10 lines
For the ones that exist as lot just seem to call
pci_read_bridge_basesand/orpcibios_fixup_device_resourcesin one form or another, and I wonder why we even need the arch indirection for that.Similarly for
pcibios_align_resource: a lot of architetures seem to have a noop, and the once that don't mostly seem copy and paste code, so we should again have a symbol for architectures to opt into it, and we probably should have a generic helper for the VGA window mirroring code instead of duplicating it multiple times.
I now remember that we already have a host_bridge->align_resource callback pointer, so the generic function should definitely try to use that.
We could just use the version from arch/mips/pci/pci-generic.c and remove that in the process. I'm not sure about why mips calls pci_read_bridge_bases() in pcibios_fixup_bus() though, or whether this make sense to put in the generic version.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 06/17] pci: Add generic pcibios_{fixup_bus,align_resource}
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · Geert Uytterhoeven
CC pci folks
Ok, replying with pci folks in Cc then :)
Weak symbols have (rightly) gotten a bad reputation, so maybe we should approach this without them.
Quoted 8 lines
Agreed, I would almost never recommend using a
__weaksymbol, but they are already widely used in the PCI subsystem, so I suggested using them here for consistency.We have a struct
pci_host_bridgenow, and we should eventually move most of the 38 pci specific weak per-architecture symbols into per-host driver callbacks, but that I think that would be too much to ask for when adding an architecture port.
I agree :)
Quoted 24 lines
Quoted 4 lines
It seems we have a large number of emptry
pcibios_fixup_buscalls alreayd, so I think we should simply have the architectures that do define it define aKconfigor header symbol and not call it at all otherwise.I would argue that most of them should not be per-architecture in the first place, the current state is mostly an artifact of the times when each architecture had just one PCI implementation.
The ones that have multiple implementations (arm, powerpc, ...) tend to actually override the weak functions with their own per-host multiplexers again.
Quoted 10 lines
For the ones that exist as lot just seem to call
pci_read_bridge_basesand/orpcibios_fixup_device_resourcesin one form or another, and I wonder why we even need the arch indirection for that.Similarly for
pcibios_align_resource: a lot of architetures seem to have a noop, and the once that don't mostly seem copy and paste code, so we should again have a symbol for architectures to opt into it, and we probably should have a generic helper for the VGA window mirroring code instead of duplicating it multiple times.
Quoted 8 lines
I now remember that we already have a
host_bridge->align_resourcecallback pointer, so the generic function should definitely try to use that.We could just use the version from
arch/mips/pci/pci-generic.cand remove that in the process. I'm not sure about why mips callspci_read_bridge_bases()inpcibios_fixup_bus()though, or whether this make sense to put in the generic version.
I'm splitting this off into another patch set and sending it to a bunch of PCI people.
Palmer Dabbelt
maintainerPATCH 7/17 lib: Add shared copies of some GCC library routines
In reply to Palmer DabbeltMany ports (m32r, microblaze, mips, parisc, score, and sparc) use functionally identical copies of various GCC library routine files, which came up as we were submitting the RISC-V port (which also uses some of these).
This patch adds a new copy of these library routine files, which are functionally identical to the various other copies. These are availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't used anywhere.
--- include/lib/libgcc.h | 44 ++++++++++++++++++++++++++++++++ lib/Kconfig | 18 +++++++++++++ lib/Makefile | 8 ++++++ lib/ashldi3.c | 45 ++++++++++++++++++++++++++++++++ lib/ashrdi3.c | 46 +++++++++++++++++++++++++++++++++ lib/cmpdi2.c | 42 ++++++++++++++++++++++++++++++ lib/lshrdi3.c | 45 ++++++++++++++++++++++++++++++++ lib/muldi3.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ucmpdi2.c | 35 +++++++++++++++++++++++++ 9 files changed, 355 insertions(+) create mode 100644 include/lib/libgcc.h create mode 100644 lib/ashldi3.c create mode 100644 lib/ashrdi3.c create mode 100644 lib/cmpdi2.c create mode 100644 lib/lshrdi3.c create mode 100644 lib/muldi3.c create mode 100644 lib/ucmpdi2.c
include/lib/libgcc.h new file +44 -0
@@ -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
@@ -565,3 +565,21 @@ config PRIME_NUMBERS tristate endmenu + +config GENERIC_ASHLDI3 + def_bool n + +config GENERIC_ASHRDI3 + def_bool n + +config GENERIC_LSHRDI3 + def_bool n + +config GENERIC_MULDI3 + def_bool n + +config GENERIC_CMPDI2 + def_bool n + +config GENERIC_UCMPDI2 + def_bool n
lib/Makefile +8 -0
@@ -243,3 +243,11 @@ UBSAN_SANITIZE_ubsan.o := n obj-$(CONFIG_SBITMAP) += sbitmap.o obj-$(CONFIG_PARMAN) += parman.o + +# GCC library routines +obj-$(CONFIG_GENERIC_ASHLDI3) += ashldi3.o +obj-$(CONFIG_GENERIC_ASHRDI3) += ashrdi3.o +obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o +obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o +obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o +obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
lib/ashldi3.c new file +45 -0
45 lines not on this page · raw message
lib/ashrdi3.c new file +46 -0
46 lines not on this page · raw message
lib/cmpdi2.c new file +42 -0
42 lines not on this page · raw message
lib/lshrdi3.c new file +45 -0
45 lines not on this page · raw message
lib/muldi3.c new file +72 -0
72 lines not on this page · raw message
lib/ucmpdi2.c new file +35 -0
@@ -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
Palmer Dabbelt
maintainerPATCH 7/17 lib: Add shared copies of some GCC library routines
In reply to Palmer DabbeltMany ports (m32r, microblaze, mips, parisc, score, and sparc) use functionally identical copies of various GCC library routine files, which came up as we were submitting the RISC-V port (which also uses some of these).
This patch adds a new copy of these library routine files, which are functionally identical to the various other copies. These are availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't used anywhere.
--- include/lib/libgcc.h | 44 ++++++++++++++++++++++++++++++++ lib/Kconfig | 18 +++++++++++++ lib/Makefile | 8 ++++++ lib/ashldi3.c | 45 ++++++++++++++++++++++++++++++++ lib/ashrdi3.c | 46 +++++++++++++++++++++++++++++++++ lib/cmpdi2.c | 42 ++++++++++++++++++++++++++++++ lib/lshrdi3.c | 45 ++++++++++++++++++++++++++++++++ lib/muldi3.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ucmpdi2.c | 35 +++++++++++++++++++++++++ 9 files changed, 355 insertions(+) create mode 100644 include/lib/libgcc.h create mode 100644 lib/ashldi3.c create mode 100644 lib/ashrdi3.c create mode 100644 lib/cmpdi2.c create mode 100644 lib/lshrdi3.c create mode 100644 lib/muldi3.c create mode 100644 lib/ucmpdi2.c
include/lib/libgcc.h new file +44 -0
@@ -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
@@ -565,3 +565,21 @@ config PRIME_NUMBERS tristate endmenu + +config GENERIC_ASHLDI3 + def_bool n + +config GENERIC_ASHRDI3 + def_bool n + +config GENERIC_LSHRDI3 + def_bool n + +config GENERIC_MULDI3 + def_bool n + +config GENERIC_CMPDI2 + def_bool n + +config GENERIC_UCMPDI2 + def_bool n
lib/Makefile +8 -0
@@ -243,3 +243,11 @@ UBSAN_SANITIZE_ubsan.o := n obj-$(CONFIG_SBITMAP) += sbitmap.o obj-$(CONFIG_PARMAN) += parman.o + +# GCC library routines +obj-$(CONFIG_GENERIC_ASHLDI3) += ashldi3.o +obj-$(CONFIG_GENERIC_ASHRDI3) += ashrdi3.o +obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o +obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o +obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o +obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
lib/ashldi3.c new file +45 -0
45 lines not on this page · raw message
lib/ashrdi3.c new file +46 -0
46 lines not on this page · raw message
lib/cmpdi2.c new file +42 -0
42 lines not on this page · raw message
lib/lshrdi3.c new file +45 -0
45 lines not on this page · raw message
lib/muldi3.c new file +72 -0
72 lines not on this page · raw message
lib/ucmpdi2.c new file +35 -0
@@ -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
Palmer Dabbelt
maintainerPATCH 8/17 dts: include documentation for the RISC-V interrupt controllers
In reply to Palmer DabbeltFrom: "Wesley W. Terpstra" <[email protected]>
--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
@@ -0,0 +1,46 @@ +RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each +hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller. + +Required properties: +- compatible : "riscv,cpu-intc" +- #interrupt-cells : should be <1> +- interrupt-controller : Identifies the node as an interrupt controller + +Furthermore, this interrupt-controller MUST be embedded inside the cpu +definition of the hart whose CSRs control these local interrupts. + +Example: + + cpu1: cpu@1 { + clock-frequency = <1600000000>; + compatible = "riscv"; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <16384>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <16384>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + next-level-cache = <&L2>; + reg = <1>; + riscv,isa = "rv64imac"; + status = "okay"; + tlb-split; + cpu1-intc: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + };
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
CC irqchip and devicetree folks
Quoted 114 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
Signed-off-by Palmer Dabbelt <[email protected]>--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txtDocumentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46
-0@@ -0,0 +1,46 @@ +RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each +hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller. + +Required properties: +- compatible : "riscv,cpu-intc" +- #interrupt-cells : should be <1> +- interrupt-controller : Identifies the node as an interrupt controller + +Furthermore, this interrupt-controller MUST be embedded inside the cpu +definition of the hart whose CSRs control these local interrupts. + +Example: + + cpu1: cpu@1 { + clock-frequency = <1600000000>; + compatible = "riscv"; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <16384>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <16384>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + next-level-cache = <&L2>; + reg = <1>; + riscv,isa = "rv64imac"; + status = "okay"; + tlb-split; + cpu1-intc: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + };Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44
-1@@ -0,0 +1,44 @@ +RISC-V Platform-Level Interrupt Controller (PLIC) +------------------------------------------------- + +RISC-V cores typically include a PLIC, which route interrupts from multiple +devices to multiple hart contexts. The PLIC is connected to the interrupt +controller embedded in a RISC-V core via the interrupt-related CSRs. + +A hart context is a priviledge mode in a hardware execution thread. For +example, in an 4 core system with 2-way SMT, you have 8 harts and probably +at least two priviledge modes per hart; machine mode and supervisor mode. + +Each interrupt can be enabled on per-context basis. Any context can claim +a pending enabled interrupt and then release it once it has been handled. + +Each interrupt has a configurable priority. Higher priority interrupts are +serviced firs. Each context can specify a priority threshold. Interrupts +with priority below this threshold will not cause the PLIC to raise its +interrupt line leading to the context. + +Required properties: +- compatible : "riscv,plic0" +- #address-cells : should be <0> +- #interrupt-cells : should be <1> +- interrupt-controller : Identifies the node as an interrupt controller +- reg : Should contain 1 register range (address and length) +- riscv,ndev : Specifies the number of interrupts attached to the PLIC +- interrupts-extended : Specifies which contexts are connected to the PLIC + +Example: + + plic: interrupt-controller@c000000 { + #address-cells = <0>; + #interrupt-cells = <1>; + compatible = "riscv,plic0"; + interrupt-controller; + interrupts-extended = < + &cpu0-intc 11 + &cpu1-intc 11 &cpu1-intc 9 + &cpu2-intc 11 &cpu2-intc 9 + &cpu3-intc 11 &cpu3-intc 9 + &cpu4-intc 11 &cpu4-intc 9>; + reg = <0xc000000 0x4000000>; + riscv,ndev = <10>; + }; --2.13.0
Mark Rutland
reviewerRe: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
Quoted 1 line · Geert Uytterhoeven
CC irqchip and devicetree folks
Thanks Geert.
Palmer, in future, you can ensure (most) relevant parties are Cc'd by using scripts/get_maintainer.pl to find them, and adding Cc: lines to the relevant patches.
You can either hand that a patch or a path, e.g.
[mark@leverpostej:~/src/linux]% ./scripts/get_maintainer.pl -f Documentation/devicetree/bindings/interrupt-controller/ Thomas Gleixner <[email protected]> (maintainer:IRQCHIP DRIVERS)
Jason Cooper <[email protected]> (maintainer:IRQCHIP DRIVERS)
Marc Zyngier <[email protected]> (maintainer:IRQCHIP DRIVERS)
Rob Herring <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Mark Rutland <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS) [email protected] (open list:IRQCHIP DRIVERS)
[email protected] (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Otherwise, I have a few comments inline below.
Quoted 11 lines · Palmer Dabbelt
Quoted 10 lines
From: "Wesley W. Terpstra" <[email protected]>
Signed-off-by Palmer Dabbelt <[email protected]>--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Quoted 15 lines
Quoted 6 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +0
-0Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +9
-0@@ -0,0 +1,46 @@ +RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each +hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller.
So IIUC those interrupts are routed directly to the HLIC, and are (only) controlled thought the HLIC?
Is the HLIC architecturally mandated? i.e. is this guaranteed to be present on any RISC-V implementation?
Does the presence of the HLIC imply the presence of a PLIC (or vice/versa)? Typically, the per-cpu and platform-wide parts of the top-level interrupt controller are fairly intimately coupled.
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 12
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +3
-0+ +Required properties: +- compatible : "riscv,cpu-intc"
You'll need to allocate the "riscv" vendor prefix in Documentation/devicetree/bindings/vendor-prefixes.txt
... if that was done in some other patch, I didn't receive it.
Quoted 1 line
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 13
Quoted 1 line
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +1
-0+- #interrupt-cells : should be <1>
What about the flags?
Are all HLIC interrupts edge triggered (or level triggered)?
Quoted 19 lines
Quoted 19 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +19
-0+- interrupt-controller : Identifies the node as an interrupt controller + +Furthermore, this interrupt-controller MUST be embedded inside the cpu +definition of the hart whose CSRs control these local interrupts. + +Example: + + cpu1: cpu@1 { + clock-frequency = <1600000000>; + compatible = "riscv"; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <16384>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <16384>;
Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 40
Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +8
-0+ i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + next-level-cache = <&L2>; + reg = <1>; + riscv,isa = "rv64imac"; + status = "okay"; + tlb-split;
We can probably replace most of these with a "...", as they're largely irrelevany to this binding.
Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +6
-0+ cpu1-intc: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + };Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +0
-1--- /dev/null
Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 6
Quoted 8 lines
+++
b/Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txtDocumentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +6
-0@@ -0,0 +1,44 @@ +RISC-V Platform-Level Interrupt Controller (PLIC) +------------------------------------------------- + +RISC-V cores typically include a PLIC, which route interrupts from multiple +devices to multiple hart contexts. The PLIC is connected to the interrupt +controller embedded in a RISC-V core via the interrupt-related CSRs.
Do you mean that the PLIC is connected to the HLIC, or that the HLIC is also managed in part through CSRs?
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +9
-0+ +A hart context is a priviledge mode in a hardware execution thread. For +example, in an 4 core system with 2-way SMT, you have 8 harts and probably +at least two priviledge modes per hart; machine mode and supervisor mode. + +Each interrupt can be enabled on per-context basis. Any context can claim +a pending enabled interrupt and then release it once it has been handled. + +Each interrupt has a configurable priority. Higher priority interrupts are
Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 23
Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +8
-0+serviced firs. Each context can specify a priority threshold. Interrupts +with priority below this threshold will not cause the PLIC to raise its +interrupt line leading to the context. + +Required properties: +- compatible : "riscv,plic0" +- #address-cells : should be <0> +- #interrupt-cells : should be <1>
As with the HLIC, what about the flags?
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 26
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +3
-0+- interrupt-controller : Identifies the node as an interrupt controller +- reg : Should contain 1 register range (address and length) +- riscv,ndev : Specifies the number of interrupts attached to the PLIC
Why do we need to know this?
I suspect this ia actually the number of interrupts implemented in the PLIC, rather than the number of interrupts attached. i.e. the PLIC can be implemented with a subset of the potential registers/bits. Is that correct?
If so, something like "riscv,num-interrupts" would be better, along with a clearer description.
Quoted 1 line
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 27
Quoted 1 line
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +1
-0+- interrupts-extended : Specifies which contexts are connected to the PLIC
That description doesn't sound right.
I take it that these are the HLIC interrupts that the PLIC can raise?
You will need to be explicit about the order of interrupts in this property. i.e. which interrupt is routed to which context?
Is the interrupt at the HLIC well known? From the example I see that here local interrupts 11 adn 9 are used. Is that mandated, or just the case for this particular implementation?
Also, please consider how you will handle the case when the Linux logical CPU ID is not the same as the physical ID, and how you will handle physical IDs being sparse.
We went though a lot of pain trying to do something similar for the ARM PMU interrupts (see the interrupt-affinity property in Documentation/devicetree/bindings/arm/pmu.txt), and it's still painful to deal with.
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 32
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +5
-0+ +Example: + + plic: interrupt-controller@c000000 { + #address-cells = <0>;
This can go, given you don't have sub-nodes, nor a #size-cells property.
Thanks,
Mark.
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +12
-1+ #interrupt-cells = <1>; + compatible = "riscv,plic0"; + interrupt-controller; + interrupts-extended = < + &cpu0-intc 11 + &cpu1-intc 11 &cpu1-intc 9 + &cpu2-intc 11 &cpu2-intc 9 + &cpu3-intc 11 &cpu3-intc 9 + &cpu4-intc 11 &cpu4-intc 9>; + reg = <0xc000000 0x4000000>; + riscv,ndev = <10>; + }; --2.13.0
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
Quoted 4 lines · Mark Rutland
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +4
-0+RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each
Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 9
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +5
-0+hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller.So IIUC those interrupts are routed directly to the HLIC, and are (only) controlled thought the HLIC?
Yes. You can have a local interrupt that goes directly to a specific core, not via the PLIC.
Quoted 2 lines
Is the HLIC architecturally mandated? i.e. is this guaranteed to be present on any RISC-V implementation?
It's in the RISC-V privileged specification. Therefore, if a riscv core can run linux it will have these CSRs.
Quoted 2 lines
Does the presence of the HLIC imply the presence of a PLIC (or vice/versa)?
No. SiFive implementations always have a PLIC, though.
Quoted 2 lines
Typically, the per-cpu and platform-wide parts of the top-level interrupt controller are fairly intimately coupled.
They are coupled if they both exist. The privileged specification does explicitly call out interrupts 9 and 11 in the HLIC for attaching the PLIC.
Quoted 2 lines
You'll need to allocate the "riscv" vendor prefix in
Documentation/devicetree/bindings/vendor-prefixes.txt
@palmer: Can you add this?
Quoted 1 line
What about the flags?
What flags?
Quoted 1 line
Are all HLIC interrupts edge triggered (or level triggered)?
HLIC = level. PLIC = both.
Quoted 2 lines
We can probably replace most of these with a "...", as they're largely irrelevany to this binding.
Sure. I thought it would be nice to include a complete cpu example somewhere, though.
Quoted 6 lines
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 6
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +3
-0+RISC-V cores typically include a PLIC, which route interrupts from multiple +devices to multiple hart contexts. The PLIC is connected to the interrupt +controller embedded in a RISC-V core via the interrupt-related CSRs.Do you mean that the PLIC is connected to the HLIC, or that the HLIC is also managed in part through CSRs?
Both. The HLIC is entirely manager through CSRs. The PLIC is managed through a memory mapped interface. The PLIC is attached to the HLIC.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
+Required properties:
+- compatible : "riscv,plic0" +- #address-cells : should be <0> +- #interrupt-cells : should be <1>As with the HLIC, what about the flags?
Still unsure what flags we're talking about.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+- riscv,ndev : Specifies the number of interrupts attached to the PLIC
Why do we need to know this?
I suspect this ia actually the number of interrupts implemented in the PLIC, rather than the number of interrupts attached. i.e. the PLIC can be implemented with a subset of the potential registers/bits. Is that correct?
You're in principle correct, although these are probably always the same.
Quoted 2 lines
If so, something like "riscv,num-interrupts" would be better, along with a clearer description.
Uhm. I suppose we can change this. However, it would requires changes to quite a number of riscv repositories. I believe this is also included in the riscv platform specification. A better description is easy, do we really need to change the key?
Quoted 5 lines
Quoted 1 line
Quoted 1 line
+- interrupts-extended : Specifies which contexts are connected to the PLIC
That description doesn't sound right.
I take it that these are the HLIC interrupts that the PLIC can raise?
Yes.
Quoted 2 lines
You will need to be explicit about the order of interrupts in this property. i.e. which interrupt is routed to which context?
Yes. Order and position matter.
Quoted 3 lines
Is the interrupt at the HLIC well known? From the example I see that here local interrupts 11 adn 9 are used. Is that mandated, or just the case for this particular implementation?
9 and 11 are in the privileged specification.
Quoted 3 lines
Also, please consider how you will handle the case when the Linux logical CPU ID is not the same as the physical ID, and how you will handle physical IDs being sparse.
We already deal with this. If the interrupt is '-1', we skip it. That's done in plic.c:
if (parent.args[0] == -1) continue; // skip context holes
Quoted 4 lines
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 32
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +2
-0+ plic: interrupt-controller@c000000 { + #address-cells = <0>;This can go, given you don't have sub-nodes, nor a #size-cells property.
The device-tree-specification seems to indicate that this is mandatory for an interrupt-controller. Or have I understood this wrongly? When you use interrupts-extended, doesn't it use the address-cells of the interrupt controller? We should add that size-cells = 0, though.
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
Quoted 3 lines · Wesley Terpstra
Quoted 2 lines · Mark Rutland
Quoted 2 lines
Quoted 2 lines
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------
[...]
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 32
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +2
-0+ plic: interrupt-controller@c000000 { + #address-cells = <0>;This can go, given you don't have sub-nodes, nor a #size-cells property.
The device-tree-specification seems to indicate that this is mandatory for an interrupt-controller. Or have I understood this wrongly? When you use interrupts-extended, doesn't it use the address-cells of the interrupt controller? We should add that size-cells = 0, though.
It's only needed if you have an interrupt-map property AIUI. #size-cells should never be needed (unless you have child nodes of this one).
Rob
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
I've reread the relevant sections now, and you are correct. We should remove the address-cells from the PLIC's dts.
Quoted 22 lines · Rob Herring
Quoted 3 lines · Wesley Terpstra
Quoted 2 lines · Mark Rutland
Quoted 2 lines
Quoted 2 lines
+RISC-V Hart-Level Interrupt Controller (HLIC)
+---------------------------------------------[...]
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 32
Quoted 2 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +2
-0+ plic: interrupt-controller@c000000 { + #address-cells = <0>;This can go, given you don't have sub-nodes, nor a #size-cells property.
The device-tree-specification seems to indicate that this is mandatory for an interrupt-controller. Or have I understood this wrongly? When you use interrupts-extended, doesn't it use the address-cells of the interrupt controller? We should add that size-cells = 0, though.
It's only needed if you have an interrupt-map property AIUI. #size-cells should never be needed (unless you have child nodes of this one).
Rob
Mark Rutland
reviewerRe: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
In reply to Wesley TerpstraQuoted 35 lines · Wesley Terpstra
Quoted 4 lines · Mark Rutland
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +4
-0+RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to eachQuoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt line 9
Quoted 5 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +5
-0+hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller.So IIUC those interrupts are routed directly to the HLIC, and are (only) controlled thought the HLIC?
Yes. You can have a local interrupt that goes directly to a specific core, not via the PLIC.
Quoted 2 lines
Is the HLIC architecturally mandated? i.e. is this guaranteed to be present on any RISC-V implementation?
It's in the RISC-V privileged specification. Therefore, if a riscv core can run linux it will have these CSRs.
Quoted 2 lines
Does the presence of the HLIC imply the presence of a PLIC (or vice/versa)?
No. SiFive implementations always have a PLIC, though.
Quoted 2 lines
Typically, the per-cpu and platform-wide parts of the top-level interrupt controller are fairly intimately coupled.
They are coupled if they both exist. The privileged specification does explicitly call out interrupts 9 and 11 in the HLIC for attaching the PLIC.
Quoted 8 lines
Quoted 2 lines
You'll need to allocate the "riscv" vendor prefix in
Documentation/devicetree/bindings/vendor-prefixes.txt@palmer: Can you add this?
Quoted 1 line
What about the flags?
What flags?
Edge vs level, active high vs active low. Typically some of these are programmable, and are described as flags in the interrupt-specifier.
See the examples in:
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Quoted 3 lines
Quoted 1 line
Are all HLIC interrupts edge triggered (or level triggered)?
HLIC = level. PLIC = both.
Ok. Given that, flags aren't necessary for the HLIC, and the interrupt-specifier is fine as-is.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 6
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +3
-0+RISC-V cores typically include a PLIC, which route interrupts from multiple +devices to multiple hart contexts. The PLIC is connected to the interrupt +controller embedded in a RISC-V core via the interrupt-related CSRs.Do you mean that the PLIC is connected to the HLIC, or that the HLIC is also managed in part through CSRs?
Both. The HLIC is entirely manager through CSRs. The PLIC is managed through a memory mapped interface. The PLIC is attached to the HLIC.
So do any CSRs affect the state of the PLIC? If it's just MMIO, the mention of CSRs above is just a little confusing.
It might be best to just say "The PLIC is connect to the HLIC embedded in each RISC-V core".
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
+Required properties:
+- compatible : "riscv,plic0" +- #address-cells : should be <0> +- #interrupt-cells : should be <1>As with the HLIC, what about the flags?
Still unsure what flags we're talking about.
As covered above for the HLIC.
It sounds like we'd need these to distinguish edge/level interrupts, unless that's fixed at integration time and you can determine it from the PLIC itself?
Quoted 10 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+- riscv,ndev : Specifies the number of interrupts attached to the PLIC
Why do we need to know this?
I suspect this ia actually the number of interrupts implemented in the PLIC, rather than the number of interrupts attached. i.e. the PLIC can be implemented with a subset of the potential registers/bits. Is that correct?
You're in principle correct, although these are probably always the same.
For now, perhaps. Let's not embed an assumption we cannot guarantee.
Quoted 7 lines
Quoted 2 lines
If so, something like "riscv,num-interrupts" would be better, along with a clearer description.
Uhm. I suppose we can change this. However, it would requires changes to quite a number of riscv repositories. I believe this is also included in the riscv platform specification. A better description is easy, do we really need to change the key?
It's not too much of a problem, but if we end up having to change anything else from the proposed bindings, those trees are going to require updates anyway.
If we can, I would like to change this to keep things as clear as possible from the outset.
[...]
Quoted 4 lines
Quoted 2 lines
You will need to be explicit about the order of interrupts in this property. i.e. which interrupt is routed to which context?
Yes. Order and position matter.
Ok.
Please update the binding to explicitly define the ordering requirement.
[...]
Quoted 7 lines
Quoted 3 lines
Also, please consider how you will handle the case when the Linux logical CPU ID is not the same as the physical ID, and how you will handle physical IDs being sparse.
We already deal with this. If the interrupt is '-1', we skip it. That's done in
plic.c:if (parent.args[0] == -1) continue; // skip context holes
If this is what we expect people to do, it needs to be documented in the binding.
Does this mean that you expect Linux logical CPU IDs to be equal to physical CPU IDs in all cases?
That's going to be painful for very sparse ID ranges, and won't work for cases like kexec/kdump where you cannot guarantee which physical CPU will end up being CPU0 in the new kernel.
I would strongly advise that you explicitly describe the relationship using phandles to CPU nodes.
I would also advise that you try to decouple the physical CPU IDs and Linux logical IDs. While assuming they're the same might simplify things today, it will create longer term maintenance problems and get in the way of a number of features.
Thanks,
Mark.
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
Quoted 8 lines · Mark Rutland
Quoted 1 line
What flags?
Edge vs level, active high vs active low. Typically some of these are programmable, and are described as flags in the interrupt-specifier.
See the examples in:
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Ok. Those are not applicable to the PLIC.
Quoted 101 lines
Quoted 4 lines
Quoted 2 lines
Are all HLIC interrupts edge triggered (or level triggered)?
HLIC = level. PLIC = both.
Ok. Given that, flags aren't necessary for the HLIC, and the interrupt-specifier is fine as-is.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt line 6
Quoted 3 lines
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +3
-0+RISC-V cores typically include a PLIC, which route interrupts from multiple +devices to multiple hart contexts. The PLIC is connected to the interrupt +controller embedded in a RISC-V core via the interrupt-related CSRs.Do you mean that the PLIC is connected to the HLIC, or that the HLIC is also managed in part through CSRs?
Both. The HLIC is entirely manager through CSRs. The PLIC is managed through a memory mapped interface. The PLIC is attached to the HLIC.
So do any CSRs affect the state of the PLIC? If it's just MMIO, the mention of CSRs above is just a little confusing.
It might be best to just say "The PLIC is connect to the HLIC embedded in each RISC-V core".
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
+Required properties:
+- compatible : "riscv,plic0" +- #address-cells : should be <0> +- #interrupt-cells : should be <1>As with the HLIC, what about the flags?
Still unsure what flags we're talking about.
As covered above for the HLIC.
It sounds like we'd need these to distinguish edge/level interrupts, unless that's fixed at integration time and you can determine it from the PLIC itself?
Quoted 10 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+- riscv,ndev : Specifies the number of interrupts attached to the PLIC
Why do we need to know this?
I suspect this ia actually the number of interrupts implemented in the PLIC, rather than the number of interrupts attached. i.e. the PLIC can be implemented with a subset of the potential registers/bits. Is that correct?
You're in principle correct, although these are probably always the same.
For now, perhaps. Let's not embed an assumption we cannot guarantee.
Quoted 7 lines
Quoted 2 lines
If so, something like "riscv,num-interrupts" would be better, along with a clearer description.
Uhm. I suppose we can change this. However, it would requires changes to quite a number of riscv repositories. I believe this is also included in the riscv platform specification. A better description is easy, do we really need to change the key?
It's not too much of a problem, but if we end up having to change anything else from the proposed bindings, those trees are going to require updates anyway.
If we can, I would like to change this to keep things as clear as possible from the outset.
[...]
Quoted 4 lines
Quoted 2 lines
You will need to be explicit about the order of interrupts in this property. i.e. which interrupt is routed to which context?
Yes. Order and position matter.
Ok.
Please update the binding to explicitly define the ordering requirement.
[...]
Quoted 7 lines
Quoted 3 lines
Also, please consider how you will handle the case when the Linux logical CPU ID is not the same as the physical ID, and how you will handle physical IDs being sparse.
We already deal with this. If the interrupt is '-1', we skip it. That's done in
plic.c:if (parent.args[0] == -1) continue; // skip context holesIf this is what we expect people to do, it needs to be documented in the binding.
Does this mean that you expect Linux logical CPU IDs to be equal to physical CPU IDs in all cases?
That's going to be painful for very sparse ID ranges, and won't work for cases like kexec/kdump where you cannot guarantee which physical CPU will end up being CPU0 in the new kernel.
I would strongly advise that you explicitly describe the relationship using phandles to CPU nodes.
Quoted 7 lines
I would also advise that you try to decouple the physical CPU IDs and Linux logical IDs. While assuming they're the same might simplify things today, it will create longer term maintenance problems and get in the way of a number of features.
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
In reply to Mark RutlandUgh. Clicked reply without being done writing the reply!
Quoted 6 lines · Mark Rutland
Edge vs level, active high vs active low. Typically some of these are programmable, and are described as flags in the interrupt-specifier.
See the examples in:
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Ok. Those are not really relevant to the PLIC. It has a flat interrupt namespace and the way you handle all four kinds of interrupts in the driver is uniform. I don't think we want to architecturally expose this to the operating system.
Quoted 2 lines
So do any CSRs affect the state of the PLIC? If it's just MMIO, the mention of CSRs above is just a little confusing.
HLIC = CSR only. PLIC = MMIO only.
Quoted 2 lines
It might be best to just say "The PLIC is connect to the HLIC embedded in each RISC-V core".
Fair enough.
Quoted 3 lines
It sounds like we'd need these to distinguish edge/level interrupts, unless that's fixed at integration time and you can determine it from the PLIC itself?
They are fixed at integration time and the PLIC driver does not need to care.
Quoted 3 lines
It's not too much of a problem, but if we end up having to change anything else from the proposed bindings, those trees are going to require updates anyway.
I'll talk to the other stakeholders.
Quoted 1 line
Please update the binding to explicitly define the ordering requirement.
The ordering requirement is that the first interrupts-extended entry corresponds to the first context, second to second, etc. If a context is unused for some reason, that's when you need a -1. The contexts are linear and contiguous in the MMIO address map.
Quoted 2 lines
Does this mean that you expect Linux logical CPU IDs to be equal to physical CPU IDs in all cases?
No. There is no 'physical CPU ID' anyway, except the mhartid CSR which is unavailable to linux. The SBI conveys your CPU ID by passing it as the first argument to the linux kernel.
The interrupts-extended in the PLIC uses a phandle to reference the matching CPU in DTS. The num in cpu@<num> only need correspond to the first register argument to the kernel.
If for some reason there end up too many -1 holes in the PLIC (b/c you virtualized a 128-core machine down to say 2), you can always virtualize the PLIC device and provide a matching simplified DTB.
Mark Rutland
reviewerRe: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
Quoted 6 lines · Wesley Terpstra
Ugh. Clicked reply without being done writing the reply!
Quoted 3 lines · Mark Rutland
Edge vs level, active high vs active low. Typically some of these are programmable, and are described as flags in the interrupt-specifier.
Quoted 8 lines
Quoted 3 lines
See the examples in:
Documentation/devicetree/bindings/interrupt-controller/interrupts.txtOk. Those are not really relevant to the PLIC. It has a flat interrupt namespace and the way you handle all four kinds of interrupts in the driver is uniform. I don't think we want to architecturally expose this to the operating system.
Sure thing. I was just making sure I clarified my initial statement.
Quoted 8 lines
Quoted 2 lines
So do any CSRs affect the state of the PLIC? If it's just MMIO, the mention of CSRs above is just a little confusing.
HLIC = CSR only. PLIC = MMIO only.
Quoted 2 lines
It might be best to just say "The PLIC is connect to the HLIC embedded in each RISC-V core".
Quoted 7 lines
Fair enough.
Quoted 3 lines
It sounds like we'd need these to distinguish edge/level interrupts, unless that's fixed at integration time and you can determine it from the PLIC itself?
They are fixed at integration time and the PLIC driver does not need to care.
Ok.
Quoted 6 lines
Quoted 1 line
Please update the binding to explicitly define the ordering requirement.
The ordering requirement is that the first interrupts-extended entry corresponds to the first context, second to second, etc. If a context is unused for some reason, that's when you need a -1. The contexts are linear and contiguous in the MMIO address map.
Ah. It wasn't at all clear to me that the order was in relation to the MMIO space.
How is it possible to tell if an context is unused?
Are those mandated to be linear and contiguous in the address space?
How is the relationship between an MMIO context and hart determined?
I'm not sure that it makes sense to use -1 in this manner, since the first cell of each interrupts-extended tuple entry is a phandle. IIRC zero is currently de-facto invalid, and if we really need a NULL phandle, we should get that clarified in the DT spec.
It might be better to describe each MMIO context separately, and then associate IRQs with those in-order.
Quoted 11 lines
Quoted 3 lines
Does this mean that you expect Linux logical CPU IDs to be equal to physical CPU IDs in all cases?
No. There is no 'physical CPU ID' anyway, except the mhartid CSR which is unavailable to linux. The SBI conveys your CPU ID by passing it as the first argument to the linux kernel.
The interrupts-extended in the PLIC uses a phandle to reference the matching CPU in DTS. The num in cpu@<num> only need correspond to the first register argument to the kernel.
So you use the reference to the HLIC to implictly provide the CPU affinity? Or do you assume that these align with the SBI-provided CPU IDs?
Thanks,
Mark.
Re: [PATCH 08/17] dts: include documentation for the RISC-V interrupt controllers
In reply to Palmer DabbeltQuoted 3 lines · Palmer Dabbelt
From: "Wesley W. Terpstra" <[email protected]>
Signed-off-by Palmer Dabbelt <[email protected]>
Small nitpick: its rather odd you send patches From one address but not provide the SOB tag for them as well, best if you can include the SOB tag of both. This applies to other patches as well.
Luis
Palmer Dabbelt
maintainerPATCH 8/17 dts: include documentation for the RISC-V interrupt controllers
In reply to Palmer DabbeltFrom: "Wesley W. Terpstra" <[email protected]>
--- .../interrupt-controller/riscv,cpu-intc.txt | 46 ++++++++++++++++++++++ .../bindings/interrupt-controller/riscv,plic0.txt | 44 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt
Documentation/devicetree/bindings/interrupt-controller/riscv,cpu-intc.txt new file +46 -0
@@ -0,0 +1,46 @@ +RISC-V Hart-Level Interrupt Controller (HLIC) +--------------------------------------------- + +RISC-V cores include Control Status Registers (CSRs) which are local to each +hart and can be read or written by software. Some of these CSRs are used to +control local interrupts connected to the core. + +Typical examples of local interrupts on a RISC-V core include: software IPI +interrupts, timer interrupts, and a link to the PLIC interrupt controller. + +Required properties: +- compatible : "riscv,cpu-intc" +- #interrupt-cells : should be <1> +- interrupt-controller : Identifies the node as an interrupt controller + +Furthermore, this interrupt-controller MUST be embedded inside the cpu +definition of the hart whose CSRs control these local interrupts. + +Example: + + cpu1: cpu@1 { + clock-frequency = <1600000000>; + compatible = "riscv"; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <16384>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <16384>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + next-level-cache = <&L2>; + reg = <1>; + riscv,isa = "rv64imac"; + status = "okay"; + tlb-split; + cpu1-intc: interrupt-controller { + #interrupt-cells = <1>; + compatible = "riscv,cpu-intc"; + interrupt-controller; + }; + };
Documentation/devicetree/bindings/interrupt-controller/riscv,plic0.txt new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.13.0
Palmer Dabbelt
maintainerPATCH 9/17 clocksource/timer-riscv: New RISC-V Clocksource
In reply to Palmer DabbeltThe RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.c
drivers/clocksource/Kconfig +8 -0
@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource. +config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCV + help + This enables a clocksource based on the RISC-V SBI timer, which is + built in to all RISC-V systems. + endmenu
drivers/clocksource/Makefile +1 -0
@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o obj-$(CONFIG_H8300_TPU) += h8300_tpu.o obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o obj-$(CONFIG_X86_NUMACHIP) += numachip.o +obj-$(CONFIG_CLKSRC_RISCV) += timer-riscv.o
drivers/clocksource/timer-riscv.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource
CC clocksource folks
Quoted 163 lines · Palmer Dabbelt
The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.cdrivers/clocksource/Kconfig +8
-0@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource. +config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCV + help + This enables a clocksource based on the RISC-V SBI timer, which is + built in to all RISC-V systems. + endmenudrivers/clocksource/Makefile +1
-0@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o obj-$(CONFIG_H8300_TPU) += h8300_tpu.o obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o obj-$(CONFIG_X86_NUMACHIP) += numachip.o +obj-$(CONFIG_CLKSRC_RISCV) += timer-riscv.odrivers/clocksource/timer-riscv.c new file +118
-1@@ -0,0 +1,118 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clocksource.h> +#include <linux/clockchips.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/delay.h> +#include <linux/of.h> + +#include <asm/irq.h> +#include <asm/csr.h> +#include <asm/sbi.h> +#include <asm/delay.h> + +unsigned long riscv_timebase; + +static DEFINE_PER_CPU(struct clock_event_device, clock_event); + +static int riscv_timer_set_next_event (unsigned long delta, +struct clock_event_device *evdev) +{ +sbi_set_timer (get_cycles () + delta); +return 0 ; +} + +static int riscv_timer_set_oneshot (struct clock_event_device *evt) +{ +/* no-op; only one mode */ +return 0 ; +} + +static int riscv_timer_set_shutdown (struct clock_event_device *evt) +{ +/* can't stop the clock! */ +return 0 ; +} + +static u64 riscv_rdtime (struct clocksource *cs) +{ +return get_cycles (); +} + +static struct clocksource riscv_clocksource = { + .name ="riscv_clocksource" , + .rating =300 , + .read = riscv_rdtime, +#ifdef CONFIG_64BITS + .mask =CLOCKSOURCE_MASK (64 ), +#else + .mask =CLOCKSOURCE_MASK (32 ), +#endif /* CONFIG_64BITS */ + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; + +void riscv_timer_interrupt (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *evdev = &per_cpu (clock_event, cpu); + + evdev->event_handler (evdev); +} + +void __init init_clockevent (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *ce = &per_cpu (clock_event, cpu); + + *ce = (struct clock_event_device ){ + .name ="riscv_timer_clockevent" , + .features =CLOCK_EVT_FEAT_ONESHOT , + .rating =300 , + .cpumask =cpumask_of (cpu), + .set_next_event = riscv_timer_set_next_event, + .set_state_oneshot = riscv_timer_set_oneshot, + .set_state_shutdown = riscv_timer_set_shutdown, + }; + +/* Enable timer interrupts */ +csr_set (sie,SIE_STIE ); + +clockevents_config_and_register (ce, riscv_timebase,100 ,0x7fffffff ); +} + +static unsigned long __init of_timebase (void ) +{ +struct device_node *cpu; +const __be32 *prop; + + cpu =of_find_node_by_path ("/cpus" ); +if (cpu) { + prop =of_get_property (cpu,"timebase-frequency" ,NULL ); +if (prop) +return be32_to_cpu (*prop); + } + +return 10000000 ; +} + +void __init time_init (void ) +{ + riscv_timebase =of_timebase (); + lpj_fine = riscv_timebase /HZ ; + +clocksource_register_hz (&riscv_clocksource, riscv_timebase); +init_clockevent (); +} --2.13.0
Arnd Bergmann
maintainerRe: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource
Quoted 22 lines · Geert Uytterhoeven
CC clocksource folks
Quoted 19 lines · Palmer Dabbelt
The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.cdrivers/clocksource/Kconfig +0
-0@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource.
Quoted 4 lines
drivers/clocksource/Kconfig config CLKSRC_ST_LPC · line 618
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCV
I don't like the commenting out parts of the entry. If there are no build-time dependencies, you can just make it 'default y' and still allow users to disabled the driver if they really want to (e.g. on a machine specific kernel that has a driver for another clocksource), or you just leave it 'def_bool RISCV'.
Quoted 4 lines
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+ +static int riscv_timer_set_oneshot(struct clock_event_device *evt) +{ + /* no-op; only one mode */
Quoted 8 lines
drivers/clocksource/Kconfig config CLKSRC_ST_LPC
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ return 0; +} + +static int riscv_timer_set_shutdown(struct clock_event_device *evt) +{ + /* can't stop the clock! */ + return 0; +}
I'd just leave out the empty callbacks, the callers all protect NULL pointers.
Quoted 8 lines
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+static u64 riscv_rdtime(struct clocksource *cs) +{ + return get_cycles(); +} + +static struct clocksource riscv_clocksource = { + .name = "riscv_clocksource", + .rating = 300,
Quoted 8 lines
drivers/clocksource/Kconfig
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ .read = riscv_rdtime, +#ifdef CONFIG_64BITS + .mask = CLOCKSOURCE_MASK(64), +#else + .mask = CLOCKSOURCE_MASK(32), +#endif /* CONFIG_64BITS */ + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +};
".mask = BITS_PER_LONG" maybe?
Quoted 31 lines
Quoted 31 lines
drivers/clocksource/Kconfig +31
-0+void riscv_timer_interrupt(void) +{ + int cpu = smp_processor_id(); + struct clock_event_device *evdev = &per_cpu(clock_event, cpu); + + evdev->event_handler(evdev); +} + +void __init init_clockevent(void) +{ + int cpu = smp_processor_id(); + struct clock_event_device *ce = &per_cpu(clock_event, cpu); + + *ce = (struct clock_event_device){ + .name = "riscv_timer_clockevent", + .features = CLOCK_EVT_FEAT_ONESHOT, + .rating = 300, + .cpumask = cpumask_of(cpu), + .set_next_event = riscv_timer_set_next_event, + .set_state_oneshot = riscv_timer_set_oneshot, + .set_state_shutdown = riscv_timer_set_shutdown, + }; + + /* Enable timer interrupts */ + csr_set(sie, SIE_STIE); + + clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff); +} + +static unsigned long __init of_timebase(void) +{
Quoted 8 lines
drivers/clocksource/Kconfig
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ struct device_node *cpu; + const __be32 *prop; + + cpu = of_find_node_by_path("/cpus"); + if (cpu) { + prop = of_get_property(cpu, "timebase-frequency", NULL); + if (prop) + return be32_to_cpu(*prop);
of_property_read_u32()
Quoted 3 lines
drivers/clocksource/Kconfig
Quoted 3 lines
drivers/clocksource/Kconfig +3
-0+ } + + return 10000000;
The default seems rather arbitrary. Any reason for this particular number? Maybe it's better to fail if the property is missing.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource
Quoted 111 lines · Arnd Bergmann
Quoted 22 lines · Geert Uytterhoeven
CC clocksource folks
Quoted 19 lines · Palmer Dabbelt
The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.cdrivers/clocksource/Kconfig +0
-0@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource.Quoted 4 lines
drivers/clocksource/Kconfig config CLKSRC_ST_LPC · line 618
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCVI don't like the commenting out parts of the entry. If there are no build-time dependencies, you can just make it 'default y' and still allow users to disabled the driver if they really want to (e.g. on a machine specific kernel that has a driver for another clocksource), or you just leave it '
def_boolRISCV'.Quoted 4 lines
Quoted 4 lines
drivers/clocksource/Kconfig +4
-0+ +static int riscv_timer_set_oneshot(struct clock_event_device *evt) +{ + /* no-op; only one mode */Quoted 8 lines
drivers/clocksource/Kconfig config CLKSRC_ST_LPC
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ return 0; +} + +static int riscv_timer_set_shutdown(struct clock_event_device *evt) +{ + /* can't stop the clock! */ + return 0; +}I'd just leave out the empty callbacks, the callers all protect NULL pointers.
Quoted 8 lines
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+static u64 riscv_rdtime(struct clocksource *cs) +{ + return get_cycles(); +} + +static struct clocksource riscv_clocksource = { + .name = "riscv_clocksource", + .rating = 300,Quoted 8 lines
drivers/clocksource/Kconfig
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ .read = riscv_rdtime, +#ifdef CONFIG_64BITS + .mask = CLOCKSOURCE_MASK(64), +#else + .mask = CLOCKSOURCE_MASK(32), +#endif /* CONFIG_64BITS */ + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +};".mask =
BITS_PER_LONG" maybe?Quoted 31 lines
Quoted 31 lines
drivers/clocksource/Kconfig +31
-0+void riscv_timer_interrupt(void) +{ + int cpu = smp_processor_id(); + struct clock_event_device *evdev = &per_cpu(clock_event, cpu); + + evdev->event_handler(evdev); +} + +void __init init_clockevent(void) +{ + int cpu = smp_processor_id(); + struct clock_event_device *ce = &per_cpu(clock_event, cpu); + + *ce = (struct clock_event_device){ + .name = "riscv_timer_clockevent", + .features = CLOCK_EVT_FEAT_ONESHOT, + .rating = 300, + .cpumask = cpumask_of(cpu), + .set_next_event = riscv_timer_set_next_event, + .set_state_oneshot = riscv_timer_set_oneshot, + .set_state_shutdown = riscv_timer_set_shutdown, + }; + + /* Enable timer interrupts */ + csr_set(sie, SIE_STIE); + + clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fffffff); +} + +static unsigned long __init of_timebase(void) +{Quoted 8 lines
drivers/clocksource/Kconfig
Quoted 8 lines
drivers/clocksource/Kconfig +8
-0+ struct device_node *cpu; + const __be32 *prop; + + cpu = of_find_node_by_path("/cpus"); + if (cpu) { + prop = of_get_property(cpu, "timebase-frequency", NULL); + if (prop) + return be32_to_cpu(*prop);
of_property_read_u32()
Quoted 6 lines
Quoted 3 lines
drivers/clocksource/Kconfig
Quoted 3 lines
drivers/clocksource/Kconfig +3
-0+ } + + return 10000000;The default seems rather arbitrary. Any reason for this particular number? Maybe it's better to fail if the property is missing.
This was just there for compatibility with the systems before we had device tree up and running, there's no reason for it to be there any more. I've changed this to panic instead, as our delay code relies on this clock source initializing correctly. I think that's safer than just having a bogus timer.
I've included this and your other CR comments here
https://github.com/riscv/riscv-linux/commit/4b8dffa13a5d965d1aefe9f5f4fed41b0a4835d7
which I'll include in a v3 patch set.
Re: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource
In reply to Palmer DabbeltQuoted 138 lines · Palmer Dabbelt
The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.cdrivers/clocksource/Kconfig +8
-0@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource. +config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCV + help + This enables a clocksource based on the RISC-V SBI timer, which is + built in to all RISC-V systems. + endmenudrivers/clocksource/Makefile +1
-0@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o obj-$(CONFIG_H8300_TPU) += h8300_tpu.o obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o obj-$(CONFIG_X86_NUMACHIP) += numachip.o +obj-$(CONFIG_CLKSRC_RISCV) += timer-riscv.odrivers/clocksource/timer-riscv.c new file +95
-0@@ -0,0 +1,118 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clocksource.h> +#include <linux/clockchips.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/delay.h> +#include <linux/of.h> + +#include <asm/irq.h> +#include <asm/csr.h> +#include <asm/sbi.h> +#include <asm/delay.h> + +unsigned long riscv_timebase; + +static DEFINE_PER_CPU(struct clock_event_device, clock_event); + +static int riscv_timer_set_next_event (unsigned long delta, +struct clock_event_device *evdev) +{ +sbi_set_timer (get_cycles () + delta); +return 0 ; +} + +static int riscv_timer_set_oneshot (struct clock_event_device *evt) +{ +/* no-op; only one mode */ +return 0 ; +} + +static int riscv_timer_set_shutdown (struct clock_event_device *evt) +{ +/* can't stop the clock! */ +return 0 ; +} + +static u64 riscv_rdtime (struct clocksource *cs) +{ +return get_cycles (); +} + +static struct clocksource riscv_clocksource = { + .name ="riscv_clocksource" , + .rating =300 , + .read = riscv_rdtime, +#ifdef CONFIG_64BITS + .mask =CLOCKSOURCE_MASK (64 ), +#else + .mask =CLOCKSOURCE_MASK (32 ), +#endif /* CONFIG_64BITS */ + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; + +void riscv_timer_interrupt (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *evdev = &per_cpu (clock_event, cpu); + + evdev->event_handler (evdev); +} + +void __init init_clockevent (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *ce = &per_cpu (clock_event, cpu); + + *ce = (struct clock_event_device ){ + .name ="riscv_timer_clockevent" , + .features =CLOCK_EVT_FEAT_ONESHOT , + .rating =300 , + .cpumask =cpumask_of (cpu), + .set_next_event = riscv_timer_set_next_event, + .set_state_oneshot = riscv_timer_set_oneshot, + .set_state_shutdown = riscv_timer_set_shutdown, + }; + +/* Enable timer interrupts */ +csr_set (sie,SIE_STIE ); + +clockevents_config_and_register (ce, riscv_timebase,100 ,0x7fffffff ); +} +
drivers/clocksource/timer-riscv.c line 105
Quoted 10 lines
drivers/clocksource/timer-riscv.c new file +10
-0+static unsigned long __init of_timebase (void ) +{ +struct device_node *cpu; +const __be32 *prop; + + cpu =of_find_node_by_path ("/cpus" ); +if (cpu) { + prop =of_get_property (cpu,"timebase-frequency" ,NULL ); +if (prop) +return be32_to_cpu (*prop);
Consider using of_property_read_u32() instead.
drivers/clocksource/timer-riscv.c line 108
Quoted 3 lines
drivers/clocksource/timer-riscv.c new file +3
-0+ } + +return 10000000 ;
Is this an architectural guarantee? Or something that is implementation specific?
drivers/clocksource/timer-riscv.c line 118
Quoted 11 lines
drivers/clocksource/timer-riscv.c new file +10
-0+} + +void __init time_init (void ) +{ + riscv_timebase =of_timebase (); + lpj_fine = riscv_timebase /HZ ; + +clocksource_register_hz (&riscv_clocksource, riscv_timebase); +init_clockevent (); +}
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Palmer Dabbelt
maintainerRe: [PATCH 09/17] clocksource/timer-riscv: New RISC-V Clocksource
Quoted 143 lines · On Wed, 07 Jun 2017 02:43:09 PDT (-0700), [email protected] wrote:
Quoted 142 lines · Palmer Dabbelt
The RISC-V ISA defines a single RTC as well as an SBI oneshot timer. This timer is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/clocksource/Kconfig | 8 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-riscv.c | 118 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 drivers/clocksource/timer-riscv.cdrivers/clocksource/Kconfig +8
-0@@ -612,4 +612,12 @@ config CLKSRC_ST_LPC Enable this option to use the Low Power controller timer as clocksource. +config CLKSRC_RISCV + #bool "Clocksource for the RISC-V platform" + def_bool y if RISCV + depends on RISCV + help + This enables a clocksource based on the RISC-V SBI timer, which is + built in to all RISC-V systems. + endmenudrivers/clocksource/Makefile +1
-0@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o obj-$(CONFIG_H8300_TPU) += h8300_tpu.o obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o obj-$(CONFIG_X86_NUMACHIP) += numachip.o +obj-$(CONFIG_CLKSRC_RISCV) += timer-riscv.odrivers/clocksource/timer-riscv.c new file +99
-0@@ -0,0 +1,118 @@ +/* +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clocksource.h> +#include <linux/clockchips.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/delay.h> +#include <linux/of.h> + +#include <asm/irq.h> +#include <asm/csr.h> +#include <asm/sbi.h> +#include <asm/delay.h> + +unsigned long riscv_timebase; + +static DEFINE_PER_CPU(struct clock_event_device, clock_event); + +static int riscv_timer_set_next_event (unsigned long delta, +struct clock_event_device *evdev) +{ +sbi_set_timer (get_cycles () + delta); +return 0 ; +} + +static int riscv_timer_set_oneshot (struct clock_event_device *evt) +{ +/* no-op; only one mode */ +return 0 ; +} + +static int riscv_timer_set_shutdown (struct clock_event_device *evt) +{ +/* can't stop the clock! */ +return 0 ; +} + +static u64 riscv_rdtime (struct clocksource *cs) +{ +return get_cycles (); +} + +static struct clocksource riscv_clocksource = { + .name ="riscv_clocksource" , + .rating =300 , + .read = riscv_rdtime, +#ifdef CONFIG_64BITS + .mask =CLOCKSOURCE_MASK (64 ), +#else + .mask =CLOCKSOURCE_MASK (32 ), +#endif /* CONFIG_64BITS */ + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; + +void riscv_timer_interrupt (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *evdev = &per_cpu (clock_event, cpu); + + evdev->event_handler (evdev); +} + +void __init init_clockevent (void ) +{ +int cpu =smp_processor_id (); +struct clock_event_device *ce = &per_cpu (clock_event, cpu); + + *ce = (struct clock_event_device ){ + .name ="riscv_timer_clockevent" , + .features =CLOCK_EVT_FEAT_ONESHOT , + .rating =300 , + .cpumask =cpumask_of (cpu), + .set_next_event = riscv_timer_set_next_event, + .set_state_oneshot = riscv_timer_set_oneshot, + .set_state_shutdown = riscv_timer_set_shutdown, + }; + +/* Enable timer interrupts */ +csr_set (sie,SIE_STIE ); + +clockevents_config_and_register (ce, riscv_timebase,100 ,0x7fffffff ); +} + +static unsigned long __init of_timebase (void ) +{ +struct device_node *cpu; +const __be32 *prop;
Quoted 8 lines
drivers/clocksource/timer-riscv.c line 105
Quoted 6 lines
drivers/clocksource/timer-riscv.c new file +6
-0+ + cpu =of_find_node_by_path ("/cpus" ); +if (cpu) { + prop =of_get_property (cpu,"timebase-frequency" ,NULL ); +if (prop) +return be32_to_cpu (*prop);Consider using
of_property_read_u32()instead.
Thanks, that's must cleaner.
Quoted 7 lines
drivers/clocksource/timer-riscv.c line 108
Quoted 4 lines
drivers/clocksource/timer-riscv.c new file +3
-0+ } + +return 10000000 ;Is this an architectural guarantee? Or something that is implementation specific?
It was just a holdover from before we converted our port to device tree, it's been fixed.
Quoted 12 lines
drivers/clocksource/timer-riscv.c line 118
Quoted 12 lines
drivers/clocksource/timer-riscv.c new file +10
-0+} + +void __init time_init (void ) +{ + riscv_timebase =of_timebase (); + lpj_fine = riscv_timebase /HZ ; + +clocksource_register_hz (&riscv_clocksource, riscv_timebase); +init_clockevent (); +}
Thanks, I'll put these in the v3 patch set.
Palmer Dabbelt
maintainerPATCH 10/17 irqchip: New RISC-V PLIC Driver
In reply to Palmer DabbeltThis patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.
--- drivers/irqchip/Kconfig | 12 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-plic.c
drivers/irqchip/Kconfig +12 -0
@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config RISCV_PLIC + bool "Platform-Level Interrupt Controller" + depends on RISCV + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.
drivers/irqchip/Makefile +1 -0
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.o
drivers/irqchip/irq-riscv-plic.c new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
CC irqchip folks
Quoted 303 lines · Palmer Dabbelt
This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/irqchip/Kconfig | 12 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-plic.cdrivers/irqchip/Kconfig +12
-0@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config RISCV_PLIC + bool "Platform-Level Interrupt Controller" + depends on RISCV + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in + the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.drivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.odrivers/irqchip/irq-riscv-plic.c new file +253
-1@@ -0,0 +1,253 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> + +/* From the RISC-V Privlidged Spec v1.10: +* +* Global interrupt sources are assigned small unsigned integer identifiers, +* beginning at the value 1. An interrupt ID of 0 is reserved to mean “no +* interrupt”. Interrupt identifiers are also used to break ties when two or +* more interrupt sources have the same assigned priority. Smaller values of +* interrupt ID take precedence over larger values of interrupt ID. +* +* It's not defined what the largest device ID is, so we're just fixing +* MAX_DEVICES right here (which is named oddly, as there will never be a +* device 0). +*/ +#define MAX_DEVICES 1024 +#define MAX_CONTEXTS 15872 + +#define PRIORITY_BASE 0 +#define ENABLE_BASE 0x2000 +#define ENABLE_SIZE 0x80 +#define HART_BASE 0x200000 +#define HART_SIZE 0x1000 + +struct plic_hart_context { +u32 threshold; +u32 claim; +}; + +struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry +}; + +struct plic_priority { +u32 prio[MAX_DEVICES ]; +}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ]; +}; + +struct plic_handler { +struct plic_hart_context *context; +struct plic_data *data; +}; + +static inline +struct plic_hart_context *plic_hart_context (struct plic_data *data,size_t i) +{ +return (struct plic_hart_context *)((char *)data->reg +HART_BASE +HART_SIZE *i); +} + +static inline +struct plic_enable_context *plic_enable_context (struct plic_data *data,size_t i) +{ +return (struct plic_enable_context *)((char *)data->reg +ENABLE_BASE +ENABLE_SIZE *i); +} + +static inline +struct plic_priority *plic_priority (struct plic_data *data) +{ +return (struct plic_priority *)((char *)data->reg +PRIORITY_BASE ); +} + +static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +static void plic_enable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_or ((1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +// There is no need to mask/unmask PLIC interrupts +// They are "masked" by reading claim and "unmasked" when writing it back. +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } + +static void plic_irq_enable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (1 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_enable (data, i, d->hwirq); +} + +static void plic_irq_disable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (0 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_disable (data, i, d->hwirq); +} + +static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct plic_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +} + +static const struct irq_domain_ops plic_irqdomain_ops = { + .map = plic_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void plic_chained_handle_irq (struct irq_desc *desc) +{ +struct plic_handler *handler =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct irq_domain *domain = handler->data->domain; +u32 what; + +chained_irq_enter (chip, desc); + +while ((what =ioread32 (&handler->context->claim))) { +int irq =irq_find_mapping (domain, what); + +if (irq >0 ) +generic_handle_irq (irq); +else +handle_bad_irq (desc); +iowrite32 (what, &handler->context->claim); + } + +chained_irq_exit (chip, desc); +} + +static int plic_init (struct device_node *node,struct device_node *parent) +{ +struct plic_data *data; +struct resource resource; +int i, ok =0 ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (WARN_ON (!data)) +return -ENOMEM ; + + data->reg =of_iomap (node,0 ); +if (WARN_ON (!data->reg)) +return -EIO ; + +of_property_read_u32 (node,"riscv,ndev" , &data->ndev); +if (WARN_ON (!data->ndev)) +return -EINVAL ; + + data->handlers =of_irq_count (node); +if (WARN_ON (!data->handlers)) +return -EINVAL ; + + data->handler = +kcalloc (data->handlers,sizeof (*data->handler),GFP_KERNEL ); +if (WARN_ON (!data->handler)) +return -ENOMEM ; + + data->domain =irq_domain_add_linear (node, data->ndev+1 , &plic_irqdomain_ops, data); +if (WARN_ON (!data->domain)) +return -ENOMEM ; + +of_address_to_resource (node,0 , &resource); +snprintf (data->name,sizeof (data->name), +"riscv,plic0,%llx" , resource.start); + data->chip.name = data->name; + data->chip.irq_mask = plic_irq_mask; + data->chip.irq_unmask = plic_irq_unmask; + data->chip.irq_enable = plic_irq_enable; + data->chip.irq_disable = plic_irq_disable; + +for (i =0 ; i < data->handlers; ++i) { +struct plic_handler *handler = &data->handler[i]; +struct of_phandle_args parent; +int parent_irq, hwirq; + +if (of_irq_parse_one (node, i, &parent)) +continue ; +// skip context holes +if (parent.args[0 ] ==-1 ) +continue ; + +// skip any contexts that lead to inactive harts +if (of_device_is_compatible (parent.np,"riscv,cpu-intc" ) && + parent.np->parent && +riscv_of_processor_hart (parent.np->parent) <0 ) +continue ; + + parent_irq =irq_create_of_mapping (&parent); +if (!parent_irq) +continue ; + + handler->context =plic_hart_context (data, i); + handler->data = data; +// hwirq prio must be > this to trigger an interrupt +iowrite32 (0 , &handler->context->threshold); + +for (hwirq =1 ; hwirq <= data->ndev; ++hwirq) +plic_disable (data, i, hwirq); +irq_set_chained_handler_and_data (parent_irq, plic_chained_handle_irq, handler); + ++ok; + } + +printk (KERN_INFO "%s: mapped %d interrupts to %d/%d handlers\n" , + data->name, data->ndev, ok, data->handlers); +WARN_ON (!ok); +return 0 ; +} + +IRQCHIP_DECLARE (plic0,"riscv,plic0" , plic_init); --2.13.0
Arnd Bergmann
maintainerRe: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
Quoted 3 lines · Geert Uytterhoeven
drivers/irqchip/irq-riscv-plic.c line 54
Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3
-0+struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry +};
You use many '//' style comments in this file, please change them all to '/* */' for consistency with kernel coding style.
Quoted 17 lines
Quoted 17 lines
drivers/irqchip/irq-riscv-plic.c new file +17
-0+ +struct plic_priority { +u32 prio[MAX_DEVICES ]; +}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ]; +}; + +struct plic_handler { +struct plic_hart_context *context;
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c line 79
Quoted 8 lines
drivers/irqchip/irq-riscv-plic.c new file +8
-0+struct plic_data *data; +}; + +static inline +struct plic_hart_context *plic_hart_context (struct plic_data *data,size_t i) +{ +return (struct plic_hart_context *)((char *)data->reg +HART_BASE +HART_SIZE *i); +}
'data->reg' is an __iomem pointer, so when you build-test this with 'make C=1', you should get a valid warning from sparse about an address space mismatch. Please address all the warning from sparse.
Quoted 6 lines
drivers/irqchip/irq-riscv-plic.c line 98
Quoted 6 lines
drivers/irqchip/irq-riscv-plic.c new file +6
-0+static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +}
In particular, you must not do atomic operations on MMIO pointers. On most architectures these are explicitly disallowed and trap for a good reason, as the hardware implementation behind atomics tend to rely on the cache controller, while mmio registers are required to be uncached.
Quoted 1 line
Quoted 1 line
+
iowrite32(1, &priority->prio[d->hwirq]);
I would normally use 'readl' instead of 'iowrite32'. They may be the same on riscv, but they have slightly different meaning in portable drivers.
Arnd
Palmer Dabbelt
maintainerRe: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
Quoted 7 lines · Arnd Bergmann
Quoted 3 lines · Geert Uytterhoeven
drivers/irqchip/irq-riscv-plic.c line 54
Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3
-0+struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry +};You use many '//' style comments in this file, please change them all to '/* */' for consistency with kernel coding style.
OK, I fixed them here and in all our other files that had them.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/irqchip/irq-riscv-plic.c new file +21
-0+ +struct plic_priority { +u32 prio[MAX_DEVICES ]; +}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ]; +}; + +struct plic_handler { +struct plic_hart_context *context; +struct plic_data *data; +}; + +static inline
Quoted 8 lines
Quoted 4 lines
drivers/irqchip/irq-riscv-plic.c line 79
Quoted 4 lines
drivers/irqchip/irq-riscv-plic.c new file +4
-0+struct plic_hart_context *plic_hart_context (struct plic_data *data,size_t i) +{ +return (struct plic_hart_context *)((char *)data->reg +HART_BASE +HART_SIZE *i); +}'
data->reg' is an__iomempointer, so when you build-test this with 'make C=1', you should get a valid warning from sparse about an address space mismatch. Please address all the warning from sparse.
I didn't know about sparse. I'll run it on our port and fix everything.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-riscv-plic.c new file +4
-0+static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); +
Quoted 8 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ atomic_and(~(1 << (hwirq % 32)), &enable->mask[hwirq / 32]); +}In particular, you must not do atomic operations on MMIO pointers. On most architectures these are explicitly disallowed and trap for a good reason, as the hardware implementation behind atomics tend to rely on the cache controller, while mmio registers are required to be uncached.
Sorry about that: the SiFive bus actually supports AMOs natively out to the every device, even without caches, bit the RISC-V spec allows regions to be marked as not supporting AMOs. Sometimes a few SiFive-isms sneak in from before the supervisor spec was written in this particular manner. I've converted this to a spinlock instead.
https://github.com/riscv/riscv-linux/commit/79b26ca800663399ea7d9dead73f3715deee1a99
Quoted 4 lines
Quoted 1 line
Quoted 1 line
+
iowrite32(1, &priority->prio[d->hwirq]);I would normally use 'readl' instead of 'iowrite32'. They may be the same on riscv, but they have slightly different meaning in portable drivers.
I assume you meant writel? If so, that makes sense
https://github.com/riscv/riscv-linux/commit/45c968f1f068c35e0a5c8c90ba0776e7bdb6db78
Re: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
In reply to Palmer DabbeltHi Palmer,
Quoted 19 lines · Palmer Dabbelt
This patch adds a driver for the Platform Level Interrupt Controller (PLIC) specified as part of the RISC-V supervisor level ISA manual. The PLIC connocts global interrupt sources to the local interrupt controller on each hart. A PLIC is present on all RISC-V systems.
Signed-off-by Palmer Dabbelt <[email protected]>--- drivers/irqchip/Kconfig | 12 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-riscv-plic.c | 253 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/irqchip/irq-riscv-plic.cdrivers/irqchip/Kconfig +0
-0@@ -301,3 +301,15 @@ config QCOM_IRQ_COMBINER help
drivers/irqchip/Kconfig config QCOM_IRQ_COMBINER · line 311
Quoted 10 lines
drivers/irqchip/Kconfig +8
-0Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config RISCV_PLIC + bool "Platform-Level Interrupt Controller" + depends on RISCV + default y + help + This enables support for the PLIC chip found in standard RISC-V + systems. The PLIC is the top-most interrupt controller found in
nit: this seems to slightly contradict what is being said in patch #8, where the HLIC is the top-level interrupt controller.
Quoted 48 lines
drivers/irqchip/Kconfig +4
-0+ the system, connected directly to the core complex. All other + interrupt sources (MSI, GPIO, etc) are subordinate to the PLIC. + + If you don't know what to do here, say Y.drivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_RISCV_PLIC) += irq-riscv-plic.odrivers/irqchip/irq-riscv-plic.c new file +29
-0@@ -0,0 +1,253 @@ +/* +* Copyright (C) 2017 SiFive +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation, version 2. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> + +/* From the RISC-V Privlidged Spec v1.10: +* +* Global interrupt sources are assigned small unsigned integer identifiers, +* beginning at the value 1. An interrupt ID of 0 is reserved to mean “no
drivers/irqchip/irq-riscv-plic.c line 39
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+* interrupt”. Interrupt identifiers are also used to break ties when two or +* more interrupt sources have the same assigned priority. Smaller values of +* interrupt ID take precedence over larger values of interrupt ID. +* +* It's not defined what the largest device ID is, so we're just fixing +* MAX_DEVICES right here (which is named oddly, as there will never be a +* device 0). +*/ +#define MAX_DEVICES 1024 +#define MAX_CONTEXTS 15872
If those are HW properties, they should probably come from the device tree instead of being hardcoded here.
drivers/irqchip/irq-riscv-plic.c line 50
Quoted 11 lines
drivers/irqchip/irq-riscv-plic.c new file +11
-0+ +#define PRIORITY_BASE 0 +#define ENABLE_BASE 0x2000 +#define ENABLE_SIZE 0x80 +#define HART_BASE 0x200000 +#define HART_SIZE 0x1000 + +struct plic_hart_context { +u32 threshold; +u32 claim; +};
Representing HW layout as a C structure is not something we usually do in the kernel. It relies on the ABI (which may change over time), and makes it harder to quickly distinguish what is a SW concept from what's not. It also leads to some of the mistakes below...
drivers/irqchip/irq-riscv-plic.c line 53
Quoted 3 lines
drivers/irqchip/irq-riscv-plic.c new file +3
-0+ +struct plic_enable_context { +atomic_t mask[32 ];// 32-bit * 32-entry
/* */ comments please, placed above the field.
Quoted 4 lines
drivers/irqchip/irq-riscv-plic.c new file +4
-0+}; + +struct plic_priority { +u32 prio[MAX_DEVICES ];
drivers/irqchip/irq-riscv-plic.c line 67
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+}; + +struct plic_data { +struct irq_chip chip; +struct irq_domain *domain; +u32 ndev; +void __iomem *reg; +int handlers; +struct plic_handler *handler; +char name[30 ];
Why 30? #define?
drivers/irqchip/irq-riscv-plic.c line 76
Quoted 9 lines
drivers/irqchip/irq-riscv-plic.c new file +9
-0+}; + +struct plic_handler { +struct plic_hart_context *context; +struct plic_data *data; +}; + +static inline +struct plic_hart_context *plic_hart_context (struct plic_data *data,size_t i)
What is 'i' here?
drivers/irqchip/irq-riscv-plic.c line 78
Quoted 2 lines
drivers/irqchip/irq-riscv-plic.c new file +2
-0+{ +return (struct plic_hart_context *)((char *)data->reg +HART_BASE +HART_SIZE *i);
This looks dodgy on a number of levels:
- the various levels of casts are useless
- what you return is still an __iomem
Sparse would certainly shout at you if you ran it on this file.
Same comment for the two functions below.
Quoted 9 lines
drivers/irqchip/irq-riscv-plic.c new file +9
-0+} + +static inline +struct plic_enable_context *plic_enable_context (struct plic_data *data,size_t i) +{ +return (struct plic_enable_context *)((char *)data->reg +ENABLE_BASE +ENABLE_SIZE *i); +} + +static inline
drivers/irqchip/irq-riscv-plic.c line 97
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+struct plic_priority *plic_priority (struct plic_data *data) +{ +return (struct plic_priority *)((char *)data->reg +PRIORITY_BASE ); +} + +static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]);
This is still a device access, right? What does it mean to use the atomic primitives on that? What are you racing against? I thought the various context were private to an execution context...
Adding Will and PeterZ to the CC list because they will probably have their own views on this...
drivers/irqchip/irq-riscv-plic.c line 108
Quoted 11 lines
drivers/irqchip/irq-riscv-plic.c new file +11
-0+} + +static void plic_enable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_or ((1 << (hwirq %32 )), &enable->mask[hwirq /32 ]); +} + +// There is no need to mask/unmask PLIC interrupts +// They are "masked" by reading claim and "unmasked" when writing it back.
Hmmm. What you describe here is the FastEOI flow.
drivers/irqchip/irq-riscv-plic.c line 118
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } + +static void plic_irq_enable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (1 , &priority->prio[d->hwirq]);
Using iowrite is only meaningful if your architecture has an actual I/O address space that is distinct from the "normal" address space. Using the write{b,w,l}{_relaxed} accessors would make more sense if you're not in that case.
Quoted 41 lines
drivers/irqchip/irq-riscv-plic.c new file +41
-0+for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_enable (data, i, d->hwirq); +} + +static void plic_irq_disable (struct irq_data *d) +{ +struct plic_data *data =irq_data_get_irq_chip_data (d); +struct plic_priority *priority =plic_priority (data); +int i; + +iowrite32 (0 , &priority->prio[d->hwirq]); +for (i =0 ; i < data->handlers; ++i) +if (data->handler[i].context) +plic_disable (data, i, d->hwirq); +} + +static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct plic_data *data = d->host_data; + +irq_set_chip_and_handler (irq, &data->chip, handle_simple_irq); +irq_set_chip_data (irq, data); +irq_set_noprobe (irq); + +return 0 ; +} + +static const struct irq_domain_ops plic_irqdomain_ops = { + .map = plic_irqdomain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static void plic_chained_handle_irq (struct irq_desc *desc) +{ +struct plic_handler *handler =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct irq_domain *domain = handler->data->domain; +u32 what; +
drivers/irqchip/irq-riscv-plic.c line 169
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+chained_irq_enter (chip, desc); + +while ((what =ioread32 (&handler->context->claim))) { +int irq =irq_find_mapping (domain, what); + +if (irq >0 ) +generic_handle_irq (irq); +else +handle_bad_irq (desc); +iowrite32 (what, &handler->context->claim);
So this is your EOI. It should be represented as such, instead of abusing the handle_simple_irq flow.
Quoted 25 lines
drivers/irqchip/irq-riscv-plic.c new file +25
-0+ } + +chained_irq_exit (chip, desc); +} + +static int plic_init (struct device_node *node,struct device_node *parent) +{ +struct plic_data *data; +struct resource resource; +int i, ok =0 ; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (WARN_ON (!data)) +return -ENOMEM ; + + data->reg =of_iomap (node,0 ); +if (WARN_ON (!data->reg)) +return -EIO ; + +of_property_read_u32 (node,"riscv,ndev" , &data->ndev); +if (WARN_ON (!data->ndev)) +return -EINVAL ; + + data->handlers =of_irq_count (node); +if (WARN_ON (!data->handlers))
drivers/irqchip/irq-riscv-plic.c line 204
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+return -EINVAL ; + + data->handler = +kcalloc (data->handlers,sizeof (*data->handler),GFP_KERNEL ); +if (WARN_ON (!data->handler)) +return -ENOMEM ; + + data->domain =irq_domain_add_linear (node, data->ndev+1 , &plic_irqdomain_ops, data); +if (WARN_ON (!data->domain)) +return -ENOMEM ;
Memory leak of data->handler and data, data->reg is still mapped...
Quoted 40 lines
drivers/irqchip/irq-riscv-plic.c new file +39
-0+ +of_address_to_resource (node,0 , &resource); +snprintf (data->name,sizeof (data->name), +"riscv,plic0,%llx" , resource.start); + data->chip.name = data->name; + data->chip.irq_mask = plic_irq_mask; + data->chip.irq_unmask = plic_irq_unmask; + data->chip.irq_enable = plic_irq_enable; + data->chip.irq_disable = plic_irq_disable; + +for (i =0 ; i < data->handlers; ++i) { +struct plic_handler *handler = &data->handler[i]; +struct of_phandle_args parent; +int parent_irq, hwirq; + +if (of_irq_parse_one (node, i, &parent)) +continue ; +// skip context holes +if (parent.args[0 ] ==-1 ) +continue ; + +// skip any contexts that lead to inactive harts +if (of_device_is_compatible (parent.np,"riscv,cpu-intc" ) && + parent.np->parent && +riscv_of_processor_hart (parent.np->parent) <0 ) +continue ; + + parent_irq =irq_create_of_mapping (&parent); +if (!parent_irq) +continue ; + + handler->context =plic_hart_context (data, i); + handler->data = data; +// hwirq prio must be > this to trigger an interrupt +iowrite32 (0 , &handler->context->threshold); + +for (hwirq =1 ; hwirq <= data->ndev; ++hwirq) +plic_disable (data, i, hwirq); +irq_set_chained_handler_and_data (parent_irq, plic_chained_handle_irq, handler);
drivers/irqchip/irq-riscv-plic.c line 253
Quoted 10 lines
drivers/irqchip/irq-riscv-plic.c new file +10
-0+ ++ok; + } + +printk (KERN_INFO "%s: mapped %d interrupts to %d/%d handlers\n" , + data->name, data->ndev, ok, data->handlers); +WARN_ON (!ok); +return 0 ; +} + +IRQCHIP_DECLARE (plic0,"riscv,plic0" , plic_init);
In the future, please CC me (as well as Thomas Gleixner and Jason Cooper) on all the interrupt-controller related patches.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
Quoted 11 lines · Marc Zyngier
drivers/irqchip/irq-riscv-plic.c line 97
Quoted 5 lines · Palmer Dabbelt
drivers/irqchip/irq-riscv-plic.c new file +5
-0+static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]);This is still a device access, right? What does it mean to use the atomic primitives on that? What are you racing against? I thought the various context were private to an execution context...
Quoted 2 lines
Adding Will and PeterZ to the CC list because they will probably have their own views on this...
atomic_* accesses to MMIO is almost certainly a bad idea. Is this atomic because you want to allow the function to run concurrently, or is it atomic because you want some guarantees from the endpoint's view?
Will
Palmer Dabbelt
maintainerRe: [PATCH 10/17] irqchip: New RISC-V PLIC Driver
Quoted 12 lines · On Fri, 09 Jun 2017 06:47:48 PDT (-0700), [email protected] wrote:
Quoted 11 lines · Marc Zyngier
drivers/irqchip/irq-riscv-plic.c line 97
Quoted 5 lines · Palmer Dabbelt
drivers/irqchip/irq-riscv-plic.c new file +5
-0+static void plic_disable (struct plic_data *data,int i,int hwirq) +{ +struct plic_enable_context *enable =plic_enable_context (data, i); + +atomic_and (~(1 << (hwirq %32 )), &enable->mask[hwirq /32 ]);This is still a device access, right? What does it mean to use the atomic primitives on that? What are you racing against? I thought the various context were private to an execution context...
Quoted 6 lines
Quoted 2 lines
Adding Will and PeterZ to the CC list because they will probably have their own views on this...
atomic_* accesses to MMIO is almost certainly a bad idea. Is this atomic because you want to allow the function to run concurrently, or is it atomic because you want some guarantees from the endpoint's view?
Concurrency: while most operations on the PLIC are per-hart, in order to disable an interrupt you have to go clear a bit for every hart. The AMO ensure the read-modify-write cycle didn't drop some other hart disabling a different interrupt (as the bits are all in the same word).
I've done a big cleanup on this driver to avoid memory-mapped structures, use a lock instead of AMOs, and use the FastEOI flow. I'm getting close to getting through all the code reviews for my v2 RISC-V patch set (which included this, our arch support, and all our other driver patches). I'm going to split out the drivers for the next patch set, as it appears that's the better way to do it.
Hopefully I can get the cleaned up patches out tonight.
Thanks!