aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv/kernel/clint.c
blob: 3647980d14c3c9c853c3541b0907a951c8ef4716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
}