Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 3 | * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 4 | * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> |
| 5 | * |
| 6 | * U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT). |
| 7 | * The CLINT block holds memory-mapped control and status registers |
| 8 | * associated with software and timer interrupts. |
| 9 | */ |
| 10 | |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 11 | #include <dm.h> |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 12 | #include <regmap.h> |
| 13 | #include <syscon.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 15 | #include <asm/io.h> |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 16 | #include <asm/smp.h> |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 17 | #include <asm/syscon.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 19 | |
| 20 | /* MSIP registers */ |
| 21 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 25 | int riscv_init_ipi(void) |
| 26 | { |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 27 | int ret; |
| 28 | struct udevice *dev; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 29 | |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 30 | ret = uclass_get_device_by_driver(UCLASS_TIMER, |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 31 | DM_DRIVER_GET(riscv_aclint_timer), &dev); |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 32 | if (ret) |
| 33 | return ret; |
| 34 | |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 35 | if (dev_get_driver_data(dev) != 0) |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 36 | gd->arch.aclint = dev_read_addr_ptr(dev); |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 37 | else |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 38 | gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT); |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 39 | |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 40 | if (!gd->arch.aclint) |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 41 | return -EINVAL; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 46 | int riscv_send_ipi(int hart) |
| 47 | { |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 48 | writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | int riscv_clear_ipi(int hart) |
| 54 | { |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 55 | writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 60 | int riscv_get_ipi(int hart, int *pending) |
| 61 | { |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 62 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 63 | |
| 64 | return 0; |
| 65 | } |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 66 | |
| 67 | static const struct udevice_id riscv_aclint_swi_ids[] = { |
Bin Meng | 9675d92 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 68 | { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT }, |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 69 | { } |
| 70 | }; |
| 71 | |
| 72 | U_BOOT_DRIVER(riscv_aclint_swi) = { |
| 73 | .name = "riscv_aclint_swi", |
| 74 | .id = UCLASS_SYSCON, |
| 75 | .of_match = riscv_aclint_swi_ids, |
| 76 | .flags = DM_FLAG_PRE_RELOC, |
| 77 | }; |