blob: fc7c9b37516f1b13be505d8c95558deeb9241637 [file] [log] [blame]
Bin Meng2fab2e92018-09-26 06:55:14 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4 */
5
6#include <common.h>
Bin Meng39cad5b2018-12-12 06:12:34 -08007#include <cpu.h>
Bin Mengaef59e52018-12-12 06:12:38 -08008#include <dm.h>
Bin Meng39cad5b2018-12-12 06:12:34 -08009#include <log.h>
Bin Meng2fab2e92018-09-26 06:55:14 -070010#include <asm/csr.h>
Bin Mengaef59e52018-12-12 06:12:38 -080011#include <dm/uclass-internal.h>
Bin Meng2fab2e92018-09-26 06:55:14 -070012
Lukas Auer5d8b2e72018-11-22 11:26:29 +010013/*
14 * prior_stage_fdt_address must be stored in the data section since it is used
15 * before the bss section is available.
16 */
17phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
18
Bin Meng2fab2e92018-09-26 06:55:14 -070019static inline bool supports_extension(char ext)
20{
Bin Mengaef59e52018-12-12 06:12:38 -080021#ifdef CONFIG_CPU
22 struct udevice *dev;
23 char desc[32];
24
25 uclass_find_first_device(UCLASS_CPU, &dev);
26 if (!dev) {
27 debug("unable to find the RISC-V cpu device\n");
28 return false;
29 }
30 if (!cpu_get_desc(dev, desc, sizeof(desc))) {
31 /* skip the first 4 characters (rv32|rv64) */
32 if (strchr(desc + 4, ext))
33 return true;
34 }
35
36 return false;
37#else /* !CONFIG_CPU */
38#ifdef CONFIG_RISCV_MMODE
Bin Meng2fab2e92018-09-26 06:55:14 -070039 return csr_read(misa) & (1 << (ext - 'a'));
Bin Mengaef59e52018-12-12 06:12:38 -080040#else /* !CONFIG_RISCV_MMODE */
41#warning "There is no way to determine the available extensions in S-mode."
42#warning "Please convert your board to use the RISC-V CPU driver."
43 return false;
44#endif /* CONFIG_RISCV_MMODE */
45#endif /* CONFIG_CPU */
Bin Meng2fab2e92018-09-26 06:55:14 -070046}
47
Bin Meng39cad5b2018-12-12 06:12:34 -080048static int riscv_cpu_probe(void)
49{
50#ifdef CONFIG_CPU
51 int ret;
52
53 /* probe cpus so that RISC-V timer can be bound */
54 ret = cpu_probe_all();
55 if (ret)
56 return log_msg_ret("RISC-V cpus probe failed\n", ret);
57#endif
58
59 return 0;
60}
61
62int arch_cpu_init_dm(void)
63{
64 return riscv_cpu_probe();
65}
66
67int arch_early_init_r(void)
68{
69 return riscv_cpu_probe();
70}