Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RISC-V: Remove CLINT related code from timer and arch

Right now the RISC-V timer driver is convoluted to support:
1. Linux RISC-V S-mode (with MMU) where it will use TIME CSR for
clocksource and SBI timer calls for clockevent device.
2. Linux RISC-V M-mode (without MMU) where it will use CLINT MMIO
counter register for clocksource and CLINT MMIO compare register
for clockevent device.

We now have a separate CLINT timer driver which also provide CLINT
based IPI operations so let's remove CLINT MMIO related code from
arch/riscv directory and RISC-V timer driver.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Tested-by: Emil Renner Berhing <kernel@esmil.dk>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>

authored by

Anup Patel and committed by
Palmer Dabbelt
2bc3fc87 2ac6795f

+16 -126
+1 -1
arch/riscv/Kconfig
··· 81 81 select PCI_DOMAINS_GENERIC if PCI 82 82 select PCI_MSI if PCI 83 83 select RISCV_INTC 84 - select RISCV_TIMER 84 + select RISCV_TIMER if RISCV_SBI 85 85 select SPARSEMEM_STATIC if 32BIT 86 86 select SPARSE_IRQ 87 87 select SYSCTL_EXCEPTION_TRACE
+2
arch/riscv/Kconfig.socs
··· 12 12 13 13 config SOC_VIRT 14 14 bool "QEMU Virt Machine" 15 + select CLINT_TIMER if RISCV_M_MODE 15 16 select POWER_RESET 16 17 select POWER_RESET_SYSCON 17 18 select POWER_RESET_SYSCON_POWEROFF ··· 25 24 config SOC_KENDRYTE 26 25 bool "Kendryte K210 SoC" 27 26 depends on !MMU 27 + select CLINT_TIMER if RISCV_M_MODE 28 28 select SERIAL_SIFIVE if TTY 29 29 select SERIAL_SIFIVE_CONSOLE if TTY 30 30 select SIFIVE_PLIC
+2 -5
arch/riscv/configs/nommu_virt_defconfig
··· 26 26 CONFIG_SLOB=y 27 27 # CONFIG_SLAB_MERGE_DEFAULT is not set 28 28 # CONFIG_MMU is not set 29 + CONFIG_SOC_VIRT=y 29 30 CONFIG_MAXPHYSMEM_2GB=y 30 31 CONFIG_SMP=y 31 32 CONFIG_CMDLINE="root=/dev/vda rw earlycon=uart8250,mmio,0x10000000,115200n8 console=ttyS0" ··· 50 49 # CONFIG_SERIO is not set 51 50 # CONFIG_LEGACY_PTYS is not set 52 51 # CONFIG_LDISC_AUTOLOAD is not set 53 - # CONFIG_DEVMEM is not set 54 52 CONFIG_SERIAL_8250=y 55 53 # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set 56 54 CONFIG_SERIAL_8250_CONSOLE=y ··· 57 57 CONFIG_SERIAL_8250_RUNTIME_UARTS=1 58 58 CONFIG_SERIAL_OF_PLATFORM=y 59 59 # CONFIG_HW_RANDOM is not set 60 + # CONFIG_DEVMEM is not set 60 61 # CONFIG_HWMON is not set 61 - # CONFIG_LCD_CLASS_DEVICE is not set 62 - # CONFIG_BACKLIGHT_CLASS_DEVICE is not set 63 62 # CONFIG_VGA_CONSOLE is not set 64 63 # CONFIG_HID is not set 65 64 # CONFIG_USB_SUPPORT is not set 66 65 CONFIG_VIRTIO_MMIO=y 67 66 CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y 68 - CONFIG_SIFIVE_PLIC=y 69 - # CONFIG_VALIDATE_FS_PARSER is not set 70 67 CONFIG_EXT2_FS=y 71 68 # CONFIG_DNOTIFY is not set 72 69 # CONFIG_INOTIFY_USER is not set
-14
arch/riscv/include/asm/clint.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _ASM_RISCV_CLINT_H 3 - #define _ASM_RISCV_CLINT_H 1 4 - 5 - #include <linux/io.h> 6 - #include <linux/smp.h> 7 - 8 - #ifdef CONFIG_RISCV_M_MODE 9 - void clint_init_boot_cpu(void); 10 - #else /* CONFIG_RISCV_M_MODE */ 11 - #define clint_init_boot_cpu() do { } while (0) 12 - #endif /* CONFIG_RISCV_M_MODE */ 13 - 14 - #endif /* _ASM_RISCV_CLINT_H */
+7 -21
arch/riscv/include/asm/timex.h
··· 7 7 #define _ASM_RISCV_TIMEX_H 8 8 9 9 #include <asm/csr.h> 10 - #include <asm/mmio.h> 11 10 12 11 typedef unsigned long cycles_t; 13 12 14 - extern u64 __iomem *riscv_time_val; 15 - extern u64 __iomem *riscv_time_cmp; 16 - 17 - #ifdef CONFIG_64BIT 18 - #define mmio_get_cycles() readq_relaxed(riscv_time_val) 19 - #else 20 - #define mmio_get_cycles() readl_relaxed(riscv_time_val) 21 - #define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1) 22 - #endif 23 - 24 13 static inline cycles_t get_cycles(void) 25 14 { 26 - if (IS_ENABLED(CONFIG_RISCV_SBI)) 27 - return csr_read(CSR_TIME); 28 - return mmio_get_cycles(); 15 + return csr_read(CSR_TIME); 29 16 } 30 17 #define get_cycles get_cycles 18 + 19 + static inline u32 get_cycles_hi(void) 20 + { 21 + return csr_read(CSR_TIMEH); 22 + } 23 + #define get_cycles_hi get_cycles_hi 31 24 32 25 #ifdef CONFIG_64BIT 33 26 static inline u64 get_cycles64(void) ··· 28 35 return get_cycles(); 29 36 } 30 37 #else /* CONFIG_64BIT */ 31 - static inline u32 get_cycles_hi(void) 32 - { 33 - if (IS_ENABLED(CONFIG_RISCV_SBI)) 34 - return csr_read(CSR_TIMEH); 35 - return mmio_get_cycles_hi(); 36 - } 37 - 38 38 static inline u64 get_cycles64(void) 39 39 { 40 40 u32 hi, lo;
+1 -1
arch/riscv/kernel/Makefile
··· 31 31 obj-y += patch.o 32 32 obj-$(CONFIG_MMU) += vdso.o vdso/ 33 33 34 - obj-$(CONFIG_RISCV_M_MODE) += clint.o traps_misaligned.o 34 + obj-$(CONFIG_RISCV_M_MODE) += traps_misaligned.o 35 35 obj-$(CONFIG_FPU) += fpu.o 36 36 obj-$(CONFIG_SMP) += smpboot.o 37 37 obj-$(CONFIG_SMP) += smp.o
-63
arch/riscv/kernel/clint.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Copyright (c) 2019 Christoph Hellwig. 4 - */ 5 - 6 - #include <linux/io.h> 7 - #include <linux/of_address.h> 8 - #include <linux/smp.h> 9 - #include <linux/types.h> 10 - #include <asm/clint.h> 11 - #include <asm/csr.h> 12 - #include <asm/timex.h> 13 - 14 - /* 15 - * This is the layout used by the SiFive clint, which is also shared by the qemu 16 - * virt platform, and the Kendryte KD210 at least. 17 - */ 18 - #define CLINT_IPI_OFF 0 19 - #define CLINT_TIME_CMP_OFF 0x4000 20 - #define CLINT_TIME_VAL_OFF 0xbff8 21 - 22 - u32 __iomem *clint_ipi_base; 23 - 24 - static void clint_send_ipi(const struct cpumask *target) 25 - { 26 - unsigned int cpu; 27 - 28 - for_each_cpu(cpu, target) 29 - writel(1, clint_ipi_base + cpuid_to_hartid_map(cpu)); 30 - } 31 - 32 - static void clint_clear_ipi(void) 33 - { 34 - writel(0, clint_ipi_base + cpuid_to_hartid_map(smp_processor_id())); 35 - } 36 - 37 - static struct riscv_ipi_ops clint_ipi_ops = { 38 - .ipi_inject = clint_send_ipi, 39 - .ipi_clear = clint_clear_ipi, 40 - }; 41 - 42 - void clint_init_boot_cpu(void) 43 - { 44 - struct device_node *np; 45 - void __iomem *base; 46 - 47 - np = of_find_compatible_node(NULL, NULL, "riscv,clint0"); 48 - if (!np) { 49 - panic("clint not found"); 50 - return; 51 - } 52 - 53 - base = of_iomap(np, 0); 54 - if (!base) 55 - panic("could not map CLINT"); 56 - 57 - clint_ipi_base = base + CLINT_IPI_OFF; 58 - riscv_time_cmp = base + CLINT_TIME_CMP_OFF; 59 - riscv_time_val = base + CLINT_TIME_VAL_OFF; 60 - 61 - clint_clear_ipi(); 62 - riscv_set_ipi_ops(&clint_ipi_ops); 63 - }
-2
arch/riscv/kernel/setup.c
··· 18 18 #include <linux/swiotlb.h> 19 19 #include <linux/smp.h> 20 20 21 - #include <asm/clint.h> 22 21 #include <asm/cpu_ops.h> 23 22 #include <asm/setup.h> 24 23 #include <asm/sections.h> ··· 78 79 #else 79 80 unflatten_device_tree(); 80 81 #endif 81 - clint_init_boot_cpu(); 82 82 83 83 #ifdef CONFIG_SWIOTLB 84 84 swiotlb_init(1);
-1
arch/riscv/kernel/smp.c
··· 18 18 #include <linux/delay.h> 19 19 #include <linux/irq_work.h> 20 20 21 - #include <asm/clint.h> 22 21 #include <asm/sbi.h> 23 22 #include <asm/tlbflush.h> 24 23 #include <asm/cacheflush.h>
-1
arch/riscv/kernel/smpboot.c
··· 24 24 #include <linux/of.h> 25 25 #include <linux/sched/task_stack.h> 26 26 #include <linux/sched/mm.h> 27 - #include <asm/clint.h> 28 27 #include <asm/cpu_ops.h> 29 28 #include <asm/irq.h> 30 29 #include <asm/mmu_context.h>
+1 -2
drivers/clocksource/Kconfig
··· 653 653 This option enables support for the Andestech ATCPIT100 timers. 654 654 655 655 config RISCV_TIMER 656 - bool "Timer for the RISC-V platform" 656 + bool "Timer for the RISC-V platform" if COMPILE_TEST 657 657 depends on GENERIC_SCHED_CLOCK && RISCV 658 - default y 659 658 select TIMER_PROBE 660 659 select TIMER_OF 661 660 help
+2 -15
drivers/clocksource/timer-riscv.c
··· 19 19 #include <linux/of_irq.h> 20 20 #include <asm/smp.h> 21 21 #include <asm/sbi.h> 22 - 23 - u64 __iomem *riscv_time_cmp; 24 - u64 __iomem *riscv_time_val; 25 - 26 - static inline void mmio_set_timer(u64 val) 27 - { 28 - void __iomem *r; 29 - 30 - r = riscv_time_cmp + cpuid_to_hartid_map(smp_processor_id()); 31 - writeq_relaxed(val, r); 32 - } 22 + #include <asm/timex.h> 33 23 34 24 static int riscv_clock_next_event(unsigned long delta, 35 25 struct clock_event_device *ce) 36 26 { 37 27 csr_set(CSR_IE, IE_TIE); 38 - if (IS_ENABLED(CONFIG_RISCV_SBI)) 39 - sbi_set_timer(get_cycles64() + delta); 40 - else 41 - mmio_set_timer(get_cycles64() + delta); 28 + sbi_set_timer(get_cycles64() + delta); 42 29 return 0; 43 30 } 44 31