MOS Source Code
Loading...
Searching...
No Matches
ipi.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/assert.hpp"
4
8#include <mos/types.hpp>
9
10#if MOS_CONFIG(MOS_SMP)
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.cpp:72
void platform_halt_cpu(void)
Definition mm.cpp:65
#define mos_warn(fmt,...)
Definition assert.hpp: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.cpp:84
void ipi_do_handle(ipi_type_t __maybe_unused type)
Definition ipi.cpp:87
#define STUB_FUNCTION_UNREACHABLE(func,...)
Definition ipi.cpp:81
void ipi_init()
Definition ipi.cpp:86
void ipi_send_all(ipi_type_t __maybe_unused type)
Definition ipi.cpp:85
#define STUB_FUNCTION(func,...)
Definition ipi.cpp:80
ipi_type_t
The type of IPI to send.
Definition ipi.hpp:13
@ IPI_TYPE_RESCHEDULE
Definition ipi.hpp:16
@ IPI_TYPE_MAX
Definition ipi.hpp:17
@ IPI_TYPE_HALT
Definition ipi.hpp:14
@ IPI_TYPE_INVALIDATE_TLB
Definition ipi.hpp:15
void ipi_send_all(ipi_type_t type)
#define TARGET_CPU_ALL
Definition ipi.hpp:22
void ipi_do_handle(ipi_type_t type)
void ipi_send(u8 target, ipi_type_t type)
#define MOS_UNUSED(x)
Definition mos_global.h:65
#define __maybe_unused
Definition mos_global.h:33
#define NULL
Definition pb_syshdr.h:46
#define PER_CPU_DECLARE(type, name)
Definition platform.hpp:25
#define current_thread
Definition platform.hpp:32
#define per_cpu(var)
Definition platform.hpp:27
#define pr_info(fmt,...)
Definition printk.hpp:35
#define pr_dinfo2(feat, fmt,...)
Definition printk.hpp:27
void platform_ipi_send(u8 target_cpu, ipi_type_t type)
void reschedule(void)
reschedule.
Definition schedule.cpp:107
#define spinlock_acquire(lock)
Definition spinlock.hpp:64
unsigned char u8
Definition types.h:15