Skip to content

Commit 22be5f2

Browse files
committed
[WIP] arch: riscv: smp: add PLIC-based IPI implementation
Add PLIC-based IPI implementation. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 0ad110d commit 22be5f2

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

arch/riscv/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ choice RISCV_SMP_IPI_IMPL
4141
prompt "RISC-V SMP IPI implementation"
4242
depends on SMP
4343
default RISCV_SMP_IPI_CLINT if DT_HAS_SIFIVE_CLINT0_ENABLED
44+
default RISCV_SMP_IPI_PLIC if PLIC_SUPPORTS_SOFT_INTERRUPT && PLIC_IRQ_AFFINITY
4445
default RISCV_SMP_IPI_CUSTOM
4546

4647
config RISCV_SMP_IPI_CLINT
@@ -49,6 +50,13 @@ config RISCV_SMP_IPI_CLINT
4950
help
5051
Use CLINT-based IPI implementation.
5152

53+
config RISCV_SMP_IPI_PLIC
54+
bool "PLIC-based IPI"
55+
depends on PLIC_SUPPORTS_SOFT_INTERRUPT
56+
depends on PLIC_IRQ_AFFINITY
57+
help
58+
Use PLIC-based IPI implementation.
59+
5260
config RISCV_SMP_IPI_CUSTOM
5361
bool "Custom IPI implementation"
5462
help

arch/riscv/core/ipi_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ void z_riscv_sched_ipi_handler(unsigned int cpu_id);
1111

1212
#ifdef CONFIG_RISCV_SMP_IPI_CLINT
1313
#include "ipi_clint.h"
14+
#elif defined(CONFIG_RISCV_SMP_IPI_PLIC)
15+
#include "ipi_plic.h"
1416
#else /* CONFIG_RISCV_SMP_IPI_CUSTOM */
1517
inline void z_riscv_ipi_send(unsigned int cpu);
1618
inline void z_riscv_ipi_clear(unsigned int cpu);

arch/riscv/core/ipi_plic.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2024 Meta Platforms
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_ARCH_RISCV_CORE_IPI_PLIC_H_
8+
#define ZEPHYR_ARCH_RISCV_CORE_IPI_PLIC_H_
9+
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/drivers/interrupt_controller/riscv_plic.h>
12+
#include <zephyr/irq_multilevel.h>
13+
#include <zephyr/kernel.h>
14+
#include <zephyr/sys/util.h>
15+
16+
#define DT_DRV_COMPAT zephyr_ipi_plic
17+
18+
#define IPI_PLIC_IRQS(n, _) DT_INST_IRQN_BY_IDX(0, n)
19+
20+
/* Should get this from the devicetree, placeholder now */
21+
static const uint32_t ipi_irqs[CONFIG_MP_MAX_NUM_CPUS] = {
22+
LISTIFY(CONFIG_MP_MAX_NUM_CPUS, IPI_PLIC_IRQS, (,)),
23+
};
24+
25+
static ALWAYS_INLINE void z_riscv_ipi_send(unsigned int cpu)
26+
{
27+
riscv_plic_irq_set_pending(ipi_irqs[cpu]);
28+
}
29+
30+
static ALWAYS_INLINE void z_riscv_ipi_clear(unsigned int cpu)
31+
{
32+
ARG_UNUSED(cpu);
33+
/* IRQ will be cleared by PLIC */
34+
}
35+
36+
static void sched_ipi_handler(const void *arg)
37+
{
38+
unsigned int cpu_id = POINTER_TO_UINT(arg);
39+
40+
z_riscv_sched_ipi_handler(cpu_id);
41+
}
42+
43+
#define IPI_PLIC_IRQ_CONNECT(n, _) \
44+
IRQ_CONNECT(DT_INST_IRQN_BY_IDX(0, n), 1, sched_ipi_handler, UINT_TO_POINTER(n), 0); \
45+
irq_enable(n); \
46+
riscv_plic_irq_set_affinity(n, BIT(n))
47+
48+
int arch_smp_init(void)
49+
{
50+
LISTIFY(CONFIG_MP_MAX_NUM_CPUS, IPI_PLIC_IRQ_CONNECT, (;));
51+
52+
return 0;
53+
}
54+
55+
#endif /* ZEPHYR_ARCH_RISCV_CORE_IPI_PLIC_H_ */

boards/andestech/adp_xc7k_ae350/adp_xc7k_ae350.dts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@
140140
zephyr,code = <INPUT_KEY_6>;
141141
};
142142
};
143+
144+
ipi_plic: ipi_plic {
145+
compatible = "zephyr,ipi-plic";
146+
interrupt-parent = <&plic_sw>;
147+
interrupts = <1 1>, /* CPU 0 */
148+
<2 1>, /* CPU 1 */
149+
<3 1>, /* CPU 2 */
150+
<4 1>, /* CPU 3 */
151+
<5 1>, /* CPU 4 */
152+
<6 1>, /* CPU 5 */
153+
<7 1>, /* CPU 6 */
154+
<8 1>; /* CPU 7 */
155+
};
143156
};
144157

145158
&l2_cache {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2024 Meta Platforms
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: IPI PLIC pseudo device
5+
6+
compatible: "zephyr,ipi-plic"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
interrupt-parent:
12+
required: true
13+
14+
interrupts:
15+
required: true

0 commit comments

Comments
 (0)