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> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 14 | #include <asm/io.h> |
Sean Anderson | 52a1db7 | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 15 | #include <asm/smp.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 16 | #include <linux/err.h> |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 17 | |
| 18 | /* MSIP registers */ |
| 19 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 23 | int riscv_init_ipi(void) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 24 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 25 | int ret; |
| 26 | struct udevice *dev; |
Bin Meng | 257875d | 2020-07-19 23:17:07 -0700 | [diff] [blame] | 27 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 28 | ret = uclass_get_device_by_driver(UCLASS_TIMER, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 29 | DM_DRIVER_GET(sifive_clint), &dev); |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | gd->arch.clint = dev_read_addr_ptr(dev); |
| 34 | if (!gd->arch.clint) |
| 35 | return -EINVAL; |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 40 | int riscv_send_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 41 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 42 | writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
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_clear_ipi(int hart) |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 48 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 49 | writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 53 | |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 54 | int riscv_get_ipi(int hart, int *pending) |
Sean Anderson | b1d0cb3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 55 | { |
Sean Anderson | 272ab20 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 56 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
Bin Meng | b6ee5e1 | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |