Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Sean Anderson | 52a1db7 | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 3 | * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com> |
Bin Meng | b6ee5e1 | 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 | |
| 11 | #include <common.h> |
| 12 | #include <dm.h> |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 13 | #include <regmap.h> |
| 14 | #include <syscon.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 16 | #include <asm/io.h> |
Sean Anderson | 52a1db7 | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 17 | #include <asm/smp.h> |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 18 | #include <asm/syscon.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 20 | |
| 21 | /* MSIP registers */ |
| 22 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 26 | int riscv_init_ipi(void) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 27 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 28 | int ret; |
| 29 | struct udevice *dev; |
Bin Meng | 257875d | 2020-07-19 23:17:07 -0700 | [diff] [blame] | 30 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 31 | ret = uclass_get_device_by_driver(UCLASS_TIMER, |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 32 | DM_DRIVER_GET(riscv_aclint_timer), &dev); |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 33 | if (ret) |
| 34 | return ret; |
| 35 | |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 36 | if (dev_get_driver_data(dev) != 0) |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 37 | gd->arch.aclint = dev_read_addr_ptr(dev); |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 38 | else |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 39 | gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT); |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 40 | |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 41 | if (!gd->arch.aclint) |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 42 | return -EINVAL; |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 47 | int riscv_send_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 48 | { |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 49 | writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 54 | int riscv_clear_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 55 | { |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 56 | writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 60 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 61 | int riscv_get_ipi(int hart, int *pending) |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 62 | { |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 63 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart)); |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 67 | |
| 68 | static const struct udevice_id riscv_aclint_swi_ids[] = { |
Bin Meng | b5f0372 | 2023-06-21 23:11:46 +0800 | [diff] [blame] | 69 | { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT }, |
Bin Meng | 08b8d26 | 2023-06-21 23:11:45 +0800 | [diff] [blame] | 70 | { } |
| 71 | }; |
| 72 | |
| 73 | U_BOOT_DRIVER(riscv_aclint_swi) = { |
| 74 | .name = "riscv_aclint_swi", |
| 75 | .id = UCLASS_SYSCON, |
| 76 | .of_match = riscv_aclint_swi_ids, |
| 77 | .flags = DM_FLAG_PRE_RELOC, |
| 78 | }; |