-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: provide native clint access for M-mode
RISC-V has the concept of a cpu level interrupt controller. The interface for it is split between a standardized part that is exposed as bits in the mstatus/sstatus register and the mie/mip/sie/sip CRS. But the bit to actually trigger IPIs is not standardized and just mentioned as implementable using MMIO. Add support for IPIs using MMIO using the SiFive clint layout (which is also shared by Ariane, Kendryte and the Qemu virt platform). Additionally the MMIO block also supports the time value and timer compare registers, so they are also set up using the same OF node. Support for other layouts should also be relatively easy to add in the future. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Anup Patel <anup@brainfault.org> [paul.walmsley@sifive.com: update include guard format; fix checkpatch issues; minor commit message cleanup] Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
- Loading branch information
Christoph Hellwig
authored and
Paul Walmsley
committed
Nov 17, 2019
1 parent
4f9bbce
commit fcdc653
Showing
7 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_RISCV_CLINT_H | ||
#define _ASM_RISCV_CLINT_H 1 | ||
|
||
#include <linux/io.h> | ||
#include <linux/smp.h> | ||
|
||
#ifdef CONFIG_RISCV_M_MODE | ||
extern u32 __iomem *clint_ipi_base; | ||
|
||
void clint_init_boot_cpu(void); | ||
|
||
static inline void clint_send_ipi_single(unsigned long hartid) | ||
{ | ||
writel(1, clint_ipi_base + hartid); | ||
} | ||
|
||
static inline void clint_send_ipi_mask(const struct cpumask *hartid_mask) | ||
{ | ||
int hartid; | ||
|
||
for_each_cpu(hartid, hartid_mask) | ||
clint_send_ipi_single(hartid); | ||
} | ||
|
||
static inline void clint_clear_ipi(unsigned long hartid) | ||
{ | ||
writel(0, clint_ipi_base + hartid); | ||
} | ||
#else /* CONFIG_RISCV_M_MODE */ | ||
#define clint_init_boot_cpu() do { } while (0) | ||
|
||
/* stubs to for code is only reachable under IS_ENABLED(CONFIG_RISCV_M_MODE): */ | ||
void clint_send_ipi_single(unsigned long hartid); | ||
void clint_send_ipi_mask(const struct cpumask *hartid_mask); | ||
void clint_clear_ipi(unsigned long hartid); | ||
#endif /* CONFIG_RISCV_M_MODE */ | ||
|
||
#endif /* _ASM_RISCV_CLINT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (c) 2019 Christoph Hellwig. | ||
*/ | ||
|
||
#include <linux/io.h> | ||
#include <linux/of_address.h> | ||
#include <linux/types.h> | ||
#include <asm/clint.h> | ||
#include <asm/csr.h> | ||
#include <asm/timex.h> | ||
#include <asm/smp.h> | ||
|
||
/* | ||
* This is the layout used by the SiFive clint, which is also shared by the qemu | ||
* virt platform, and the Kendryte KD210 at least. | ||
*/ | ||
#define CLINT_IPI_OFF 0 | ||
#define CLINT_TIME_CMP_OFF 0x4000 | ||
#define CLINT_TIME_VAL_OFF 0xbff8 | ||
|
||
u32 __iomem *clint_ipi_base; | ||
|
||
void clint_init_boot_cpu(void) | ||
{ | ||
struct device_node *np; | ||
void __iomem *base; | ||
|
||
np = of_find_compatible_node(NULL, NULL, "riscv,clint0"); | ||
if (!np) { | ||
panic("clint not found"); | ||
return; | ||
} | ||
|
||
base = of_iomap(np, 0); | ||
if (!base) | ||
panic("could not map CLINT"); | ||
|
||
clint_ipi_base = base + CLINT_IPI_OFF; | ||
riscv_time_cmp = base + CLINT_TIME_CMP_OFF; | ||
riscv_time_val = base + CLINT_TIME_VAL_OFF; | ||
|
||
clint_clear_ipi(boot_cpu_hartid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters