The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_irq.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * arch-neutral hardware-interrupt (IRQ) interface.
5 *
6 * portable drivers register their line handlers through this API instead of
7 * reaching into the x86 PIC/IDT/ISR machinery. each architecture provides its
8 * own implementation that wraps whatever interrupt controller it has (8259A
9 * PIC on x86, GIC on ARM, PLIC on RISC-V).
10 */
11
12#include "common/stdint.h"
13
14/**
15 * opaque saved-state handle passed to an IRQ handler.
16 *
17 * the concrete layout is architecture-specific (on x86 it is the register
18 * dump built by the ISR stubs). portable code treats it as opaque; only
19 * arch code that knows the layout may dereference it. handlers that just
20 * need to service a device can ignore it entirely.
21 */
22typedef struct trap_frame trap_frame_t;
23
24/**
25 * IRQ handler function type.
26 * @param irq the hardware IRQ line that fired.
27 * @param frame opaque saved state at the point of interruption (may be NULL
28 * to a handler that does not need it).
29 */
30typedef void (*irq_handler_fn)(uint32_t irq, trap_frame_t *frame);
31
32/**
33 * true if the interrupt came while user code ran (CPU time accounting).
34 * @param frame the frame a handler was given.
35 */
36bool arch_frame_is_user(const trap_frame_t *frame);
37
38/**
39 * register a handler for a hardware IRQ line.
40 * @param irq the IRQ line to handle.
41 * @param handler the function to call when the line fires.
42 * @return 0 on success, -1 if the IRQ number is out of range.
43 */
45
46/**
47 * unmask (enable) a hardware IRQ line so it can be delivered.
48 * @param irq the IRQ line to enable.
49 */
51
52/**
53 * mask (disable) a hardware IRQ line.
54 * @param irq the IRQ line to disable.
55 */
57
58/**
59 * acknowledge an IRQ (end-of-interrupt) at the interrupt controller.
60 * @param irq the IRQ line to acknowledge.
61 */
62void arch_irq_ack(uint32_t irq);
63
64/**
65 * a device interrupt handler (a message-signalled interrupt, or a PCI
66 * interrupt line). it runs with interrupts off, after the end of interrupt
67 * is sent, so it must clear the cause in the device.
68 * @param context the value given when the handler was attached.
69 */
70typedef void (*device_irq_handler_t)(void *context);
71
72/**
73 * allocate an interrupt vector for a message-signalled interrupt (PCI MSI
74 * or MSI-X) and give the message that the device must write to raise it.
75 * @param handler the function to call when the message arrives.
76 * @param context passed to the handler.
77 * @param address receives the message address.
78 * @param data receives the message data.
79 * @return false if the CPU cannot take messages (no local APIC in use) or
80 * all device vectors are in use.
81 */
82bool arch_msi_alloc(device_irq_handler_t handler, void *context, uint64_t *address, uint32_t *data);
83
84/**
85 * make an ISA IRQ line level-triggered, for a PCI interrupt line that the
86 * firmware routed to it. does nothing when the line is already level or
87 * when the 8259 PICs are in use (the firmware sets their trigger mode).
88 * @param irq the IRQ line (0 to 15).
89 */
91
92/**
93 * send the interrupts of an ISA IRQ line to a core. the vector does not
94 * change, so an interrupt that comes during the change goes to the old
95 * core or to the new one, and both handle it.
96 * @param irq the IRQ line (0 to 15).
97 * @param cpu the index of the core (cpu_t.index).
98 * @return false if the line cannot move: the line has no I/O APIC entry,
99 * or the 8259 PICs are in use (they interrupt only the boot core).
100 */
102
103/**
104 * the message address that sends a message-signalled interrupt to a core.
105 * the message data (the vector) is the same on each core.
106 * @param cpu the index of the core (cpu_t.index).
107 * @return the address for the MSI or MSI-X capability of a device.
108 */
void arch_irq_set_level(uint32_t irq)
make an ISA IRQ line level-triggered, for a PCI interrupt line that the firmware routed to it.
Definition msi.c:77
void arch_irq_disable(uint32_t irq)
mask (disable) a hardware IRQ line.
Definition arch_irq_x86.c:73
void(*) device_irq_handler_t(void *context)
a device interrupt handler (a message-signalled interrupt, or a PCI interrupt line).
Definition arch_irq.h:70
struct trap_frame trap_frame_t
arch-neutral hardware-interrupt (IRQ) interface.
Definition arch_irq.h:22
void(*) irq_handler_fn(uint32_t irq, trap_frame_t *frame)
IRQ handler function type.
Definition arch_irq.h:30
bool arch_irq_set_cpu(uint32_t irq, uint32_t cpu)
send the interrupts of an ISA IRQ line to a core.
Definition arch_irq_x86.c:101
uint64_t arch_msi_address(uint32_t cpu)
the message address that sends a message-signalled interrupt to a core.
Definition msi.c:72
bool arch_frame_is_user(const trap_frame_t *frame)
true if the interrupt came while user code ran (CPU time accounting).
Definition arch_irq_x86.c:115
bool arch_msi_alloc(device_irq_handler_t handler, void *context, uint64_t *address, uint32_t *data)
allocate an interrupt vector for a message-signalled interrupt (PCI MSI or MSI-X) and give the messag...
Definition msi.c:46
int arch_irq_register(uint32_t irq, irq_handler_fn handler)
register a handler for a hardware IRQ line.
Definition arch_irq_x86.c:45
void arch_irq_enable(uint32_t irq)
unmask (enable) a hardware IRQ line so it can be delivered.
Definition arch_irq_x86.c:57
void arch_irq_ack(uint32_t irq)
acknowledge an IRQ (end-of-interrupt) at the interrupt controller.
Definition arch_irq_x86.c:89
unsigned int uint32_t
Definition fb.h:17
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
the data of one core
Definition cpu.h:39