1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Fraunhofer AISEC,
4 * Lukas Auer <lukas.auer@aisec.fraunhofer.de>
10 #include <asm/barrier.h>
13 DECLARE_GLOBAL_DATA_PTR;
15 static int send_ipi_many(struct ipi_data *ipi, int wait)
21 cpus = ofnode_path("/cpus");
22 if (!ofnode_valid(cpus)) {
23 pr_err("Can't find cpus node!\n");
27 ofnode_for_each_subnode(node, cpus) {
28 /* skip if hart is marked as not available in the device tree */
29 if (!ofnode_is_available(node))
32 /* read hart ID of CPU */
33 ret = ofnode_read_u32(node, "reg", ®);
37 /* skip if it is the hart we are running on */
38 if (reg == gd->arch.boot_hart)
41 if (reg >= CONFIG_NR_CPUS) {
42 pr_err("Hart ID %d is out of range, increase CONFIG_NR_CPUS\n",
48 /* skip if hart is not available */
49 if (!(gd->arch.available_harts & (1 << reg)))
53 gd->arch.ipi[reg].addr = ipi->addr;
54 gd->arch.ipi[reg].arg0 = ipi->arg0;
55 gd->arch.ipi[reg].arg1 = ipi->arg1;
57 ret = riscv_send_ipi(reg);
59 pr_err("Cannot send IPI to hart %d\n", reg);
66 ret = riscv_get_ipi(reg, &pending);
76 void handle_ipi(ulong hart)
79 void (*smp_function)(ulong hart, ulong arg0, ulong arg1);
81 if (hart >= CONFIG_NR_CPUS)
86 smp_function = (void (*)(ulong, ulong, ulong))gd->arch.ipi[hart].addr;
87 invalidate_icache_all();
90 * Clear the IPI to acknowledge the request before jumping to the
93 ret = riscv_clear_ipi(hart);
95 pr_err("Cannot clear IPI of hart %ld (error %d)\n", hart, ret);
99 smp_function(hart, gd->arch.ipi[hart].arg0, gd->arch.ipi[hart].arg1);
102 int smp_call_function(ulong addr, ulong arg0, ulong arg1, int wait)
104 struct ipi_data ipi = {
110 return send_ipi_many(&ipi, wait);