MOS Source Code
Loading...
Searching...
No Matches
ipi.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/assert.h"
4
5#include <mos/interrupt/ipi.h>
7#include <mos/syslog/printk.h>
8#include <mos/types.h>
9
10#if MOS_CONFIG(MOS_SMP)
11#include "mos/tasks/schedule.h"
12
13static void ipi_handler_halt(ipi_type_t type)
14{
15 MOS_UNUSED(type);
16 pr_info("halt IPI received");
18}
19
20static void ipi_handler_invalidate_tlb(ipi_type_t type)
21{
22 MOS_UNUSED(type);
23 pr_dinfo2(ipi, "Received invalidate TLB IPI");
25}
26
27static void ipi_handler_reschedule(ipi_type_t type)
28{
29 MOS_UNUSED(type);
30 pr_dinfo2(ipi, "Received reschedule IPI");
31 spinlock_acquire(&current_thread->state_lock);
32 reschedule();
33}
34
35#define IPI_ENTRY(_type, _handler) [_type] = { .handle = _handler, .nr = PER_CPU_VAR_INIT }
36
37static struct
38{
39 void (*handle)(ipi_type_t type);
40 PER_CPU_DECLARE(size_t, nr);
41} ipi_handlers[IPI_TYPE_MAX] = {
42 IPI_ENTRY(IPI_TYPE_HALT, ipi_handler_halt),
43 IPI_ENTRY(IPI_TYPE_INVALIDATE_TLB, ipi_handler_invalidate_tlb),
44 IPI_ENTRY(IPI_TYPE_RESCHEDULE, ipi_handler_reschedule),
45};
46
47void ipi_send(u8 target, ipi_type_t type)
48{
49 pr_dinfo2(ipi, "Sending IPI to %d of type %d", target, type);
50 platform_ipi_send(target, type);
51}
52
53void ipi_send_all(ipi_type_t type)
54{
55 pr_dinfo2(ipi, "Sending IPI to all of type %d", type);
57}
58
60{
61 pr_dinfo2(ipi, "Handling IPI of type %d", type);
62
63 if (type >= IPI_TYPE_MAX)
64 {
65 mos_warn("IPI type %d is out of range", type);
66 return;
67 }
68
69 if (ipi_handlers[type].handle == NULL)
70 {
71 mos_warn("No handler for IPI type %d", type);
72 return;
73 }
74
75 (*per_cpu(ipi_handlers[type].nr))++;
76 ipi_handlers[type].handle(type);
77}
78#else
79// clang-format off
80#define STUB_FUNCTION(func, ...) void func(__VA_ARGS__){}
81#define STUB_FUNCTION_UNREACHABLE(func, ...) void func(__VA_ARGS__){ MOS_UNREACHABLE(); }
82// clang-format on
83
88#endif
void platform_invalidate_tlb(ptr_t vaddr)
Definition mm.c:72
void platform_halt_cpu(void)
Definition mm.c:65
#define mos_warn(fmt,...)
Definition assert.h:23
MOSAPI void(1, 2) fatal_abort(const char *fmt
void ipi_send(u8 __maybe_unused target, ipi_type_t __maybe_unused type)
Definition ipi.c:84
void ipi_do_handle(ipi_type_t __maybe_unused type)
Definition ipi.c:87
#define STUB_FUNCTION_UNREACHABLE(func,...)
Definition ipi.c:81
void ipi_init()
Definition ipi.c:86
void ipi_send_all(ipi_type_t __maybe_unused type)
Definition ipi.c:85
#define STUB_FUNCTION(func,...)
Definition ipi.c:80
ipi_type_t
The type of IPI to send.
Definition ipi.h:12
@ IPI_TYPE_RESCHEDULE
Definition ipi.h:15
@ IPI_TYPE_MAX
Definition ipi.h:16
@ IPI_TYPE_HALT
Definition ipi.h:13
@ IPI_TYPE_INVALIDATE_TLB
Definition ipi.h:14
#define TARGET_CPU_ALL
Definition ipi.h:21
#define MOS_UNUSED(x)
Definition mos_global.h:64
#define __maybe_unused
Definition mos_global.h:33
#define NULL
Definition pb_syshdr.h:46
#define PER_CPU_DECLARE(type, name)
Definition platform.h:23
#define current_thread
Definition platform.h:30
#define per_cpu(var)
Definition platform.h:25
#define pr_info(fmt,...)
Definition printk.h:35
#define pr_dinfo2(feat, fmt,...)
Definition printk.h:27
void platform_ipi_send(u8 target_cpu, ipi_type_t type)
void reschedule(void)
reschedule.
Definition schedule.c:107
#define spinlock_acquire(lock)
Definition spinlock.h:61
unsigned char u8
Definition types.h:19