ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/sys/irq.zcomponent/irqdesc.cxxm
3/// @brief Generic IRQ descriptor table
4
5export module zxfoundation.sys.irq.core;
6import zxfoundation.base.types;
7import arch.s390x.cpu.irq;
8import lib.error;
9import std;
10
11export {
12
13namespace zxfoundation::sys::irq {
14
15 using handler_fn = auto (*)(
16 u16 irq,
17 arch::s390x::cpu::irq::irq_frame* frame,
18 void* data
19 ) noexcept -> void;
20
21 /// @brief Dispatch an IRQ — called from C interrupt entry stubs (trap.cxxm).
22 /// @param[in] irq Vector number inside [0,IRQ_NR_MAX]
23 /// @param[in] frame Pointer to the saved interrupt frame (entry.S layout).
24 /// @param[in] cls Architectural interruption class (PoP §6 "Interruption
25 /// Definitions"). Determines IRQ-nesting accounting width.
26 auto irq_dispatch(
27 u16 irq,
28 arch::s390x::cpu::irq::irq_frame* frame,
29 arch::s390x::cpu::irq::irq_class cls
30 ) noexcept -> void;
31
32 /// @brief Register a handler for a vector.
33 /// @param[in] irq Vector slot within the relevant IRQ_BASE_* span.
34 /// @param[in] handler Cancellable handler. Must not block indefinitely;
35 /// the dispatch path is IRQ-disabled.
36 /// @param[in] data Opaque handler-private cookie.
37 /// @param[in] flags Bitmask of @c IRQF_* values.
38 [[nodiscard]] auto irq_register(
39 u16 irq,
40 handler_fn handler,
41 void* data = nullptr,
42 u32 flags = 0
43 ) noexcept -> std::expected<void, lib::kernel_error>;
44
45 /// @brief Unregister the handler for a vector and release the SCOMS slot.
46 /// @param[in] irq Vector slot to clear.
47 auto irq_unregister(u16 irq) noexcept -> void;
48
49 /// @brief Initialize the IRQ subsystem with the SCOMS scoms_table.
50 /// @note Idempotent — safe to invoke from `main` after `printk::init()`.
51 auto init() noexcept -> void;
52
53 /// @brief Set one deferred-work bit on the calling CPU's
54 /// @c percpu::s390x_percpu_data::deferred_pending field.
55 /// @param[in] bit One of @c DEFERRED_*_BIT masks above.
56 /// @note Memory order is release so the bit set is visible before any
57 /// IRQ return path context restore.
58 auto deferred_set(u32 bit) noexcept -> void;
59
60 /// @brief Test-and-clear a deferred-work bit.
61 /// @return @c true if the bit was set (and is now cleared).
62 /// @note Drains the bit atomically so the caller cannot accidentally
63 /// re-process work after a context switch.
64 [[nodiscard]] auto deferred_test_clear(u32 bit) noexcept -> bool;
65
66} // namespace zxfoundation::sys::irq
67
68} // end export