The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
irq.h
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* @file irq.h
5
* @brief kernel IRQ handler manager: shared lines, per-handler control.
6
*
7
* sits on top of the arch-neutral IRQ primitives (arch/arch_irq.h). where the
8
* arch layer allows one handler per line, this manager keeps a list of
9
* handlers per line so several devices can share an IRQ, lets each handler be
10
* enabled/disabled independently, and tracks a name per handler for debugging.
11
*
12
* drivers call irq_request()/irq_free() instead of arch_irq_register()
13
* directly. the manager owns line masking: a line is unmasked while it has at
14
* least one enabled handler and masked otherwise.
15
*/
16
17
#include "
common/stdint.h
"
18
#include "
arch/arch_irq.h
"
19
20
// how many handlers may share a single IRQ line.
21
#define IRQ_MAX_SHARED 4
22
23
// opaque handle to a registered handler; NULL means "no handler".
24
typedef
struct
irq_handler_entry
irq_handle_t
;
25
26
// flags for irq_request(). currently only the default (0) is defined; the
27
// argument exists so future options (edge/level, exclusive, etc.) don't change
28
// the signature.
29
#define IRQ_FLAG_NONE 0u
30
31
/**
32
* initialize the IRQ manager. must run before any irq_request() call.
33
*/
34
void
irq_manager_init
(
void
);
35
36
/**
37
* register a handler on an IRQ line, sharing it with any existing handlers.
38
* the handler starts enabled and the line is unmasked automatically.
39
* @param irq the IRQ line.
40
* @param handler the function to call when the line fires.
41
* @param flags reserved for future use; pass IRQ_FLAG_NONE.
42
* @param name short human-readable owner name (for debugging), may be NULL.
43
* @return a handle to the registration, or NULL if the line is full/invalid.
44
*/
45
irq_handle_t
*
irq_request
(
uint32_t
irq,
irq_handler_fn
handler,
uint32_t
flags
,
const
char
*name);
46
47
/**
48
* remove a previously requested handler. if it was the last enabled handler
49
* on its line, the line is masked.
50
* @param handle the handle returned by irq_request() (NULL is ignored).
51
*/
52
void
irq_free
(
irq_handle_t
*handle);
53
54
/**
55
* enable or disable a single handler without removing it.
56
* masks the line when no enabled handlers remain, unmasks it otherwise.
57
* @param handle the handler to toggle.
58
* @param enabled true to enable, false to disable.
59
*/
60
void
irq_handler_set_enabled
(
irq_handle_t
*handle,
bool
enabled);
61
62
/**
63
* print the registered handlers per line (debugging aid).
64
*/
65
void
irq_dump
(
void
);
66
67
/**
68
* send the interrupts of an IRQ line to a core (arch_irq_set_cpu).
69
* @param irq the IRQ line (0 to 15).
70
* @param cpu the index of the core (cpu_t.index).
71
* @return false if the line cannot move; it stays on its core.
72
*/
73
bool
irq_set_cpu
(
uint32_t
irq,
uint32_t
cpu
);
74
75
/**
76
* the core that handles an IRQ line.
77
* @param irq the IRQ line (0 to 15).
78
* @return the index of the core; 0 (the boot core) until the line moves.
79
*/
80
uint32_t
irq_line_cpu
(
uint32_t
irq);
81
82
/**
83
* spread the device interrupts over the cores that run the scheduler: each
84
* IRQ line that has a handler, and each PCI device that uses MSI or MSI-X,
85
* goes to the next core in turn, as Linux gives each interrupt one core.
86
* IRQ 0 (the PIT) stays on the boot core. call it once, after smp_init().
87
*/
88
void
irq_spread
(
void
);
arch_irq.h
irq_handler_fn
void(*) irq_handler_fn(uint32_t irq, trap_frame_t *frame)
IRQ handler function type.
Definition
arch_irq.h:30
stdint.h
flags
uint8_t flags
Definition
idt.c:3
irq_manager_init
void irq_manager_init(void)
initialize the IRQ manager.
Definition
irq.c:92
irq_request
irq_handle_t * irq_request(uint32_t irq, irq_handler_fn handler, uint32_t flags, const char *name)
register a handler on an IRQ line, sharing it with any existing handlers.
Definition
irq.c:107
irq_free
void irq_free(irq_handle_t *handle)
remove a previously requested handler.
Definition
irq.c:133
irq_line_cpu
uint32_t irq_line_cpu(uint32_t irq)
the core that handles an IRQ line.
Definition
irq.c:186
irq_handler_set_enabled
void irq_handler_set_enabled(irq_handle_t *handle, bool enabled)
enable or disable a single handler without removing it.
Definition
irq.c:147
irq_dump
void irq_dump(void)
print the registered handlers per line (debugging aid).
Definition
irq.c:158
irq_spread
void irq_spread(void)
spread the device interrupts over the cores that run the scheduler: each IRQ line that has a handler,...
Definition
irq.c:210
irq_set_cpu
bool irq_set_cpu(uint32_t irq, uint32_t cpu)
send the interrupts of an IRQ line to a core (arch_irq_set_cpu).
Definition
irq.c:176
irq_handle_t
struct irq_handler_entry irq_handle_t
Definition
irq.h:24
uint32_t
unsigned int uint32_t
Definition
fb.h:17
cpu
the data of one core
Definition
cpu.h:39
src
kernel
irq
irq.h
Generated by
1.18.0