The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
irq.c File Reference

kernel IRQ handler manager. More...

#include "irq.h"
#include "common/stdio.h"
#include "drivers/pci/pci_irq.h"
#include "kernel/cpu/cpu.h"
#include "kernel/klog/klog.h"
#include "kernel/random/random.h"

Macros

#define IRQ_LINE_COUNT   16
#define IDLE_WAIT_SPINS   1000000u

Functions

void irq_manager_init (void)
 initialize the IRQ manager.
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.
void irq_free (irq_handle_t *handle)
 remove a previously requested handler.
void irq_handler_set_enabled (irq_handle_t *handle, bool enabled)
 enable or disable a single handler without removing it.
void irq_dump (void)
 print the registered handlers per line (debugging aid).
bool irq_set_cpu (uint32_t irq, uint32_t cpu)
 send the interrupts of an IRQ line to a core (arch_irq_set_cpu).
uint32_t irq_line_cpu (uint32_t irq)
 the core that handles an IRQ line.
void irq_spread (void)
 spread the device interrupts over the cores that run the scheduler: each IRQ line that has a handler, and each PCI device that uses MSI or MSI-X, goes to the next core in turn, as Linux gives each interrupt one core.

Detailed Description

kernel IRQ handler manager.

one dispatcher is registered with the arch layer per line; it walks that line's handler list and invokes every enabled handler. handler storage is a fixed pool so there is no allocation on the interrupt path.

Macro Definition Documentation

◆ IRQ_LINE_COUNT

#define IRQ_LINE_COUNT   16

◆ IDLE_WAIT_SPINS

#define IDLE_WAIT_SPINS   1000000u

Function Documentation

◆ irq_manager_init()

void irq_manager_init ( void )

initialize the IRQ manager.

must run before any irq_request() call.

◆ 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.

the handler starts enabled and the line is unmasked automatically.

Parameters
irqthe IRQ line.
handlerthe function to call when the line fires.
flagsreserved for future use; pass IRQ_FLAG_NONE.
nameshort human-readable owner name (for debugging), may be NULL.
Returns
a handle to the registration, or NULL if the line is full/invalid.

◆ irq_free()

void irq_free ( irq_handle_t * handle)

remove a previously requested handler.

if it was the last enabled handler on its line, the line is masked.

Parameters
handlethe handle returned by irq_request() (NULL is ignored).

◆ irq_handler_set_enabled()

void irq_handler_set_enabled ( irq_handle_t * handle,
bool enabled )

enable or disable a single handler without removing it.

masks the line when no enabled handlers remain, unmasks it otherwise.

Parameters
handlethe handler to toggle.
enabledtrue to enable, false to disable.

◆ irq_dump()

void irq_dump ( void )

print the registered handlers per line (debugging aid).

◆ 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).

Parameters
irqthe IRQ line (0 to 15).
cputhe index of the core (cpu_t.index).
Returns
false if the line cannot move; it stays on its core.

◆ irq_line_cpu()

uint32_t irq_line_cpu ( uint32_t irq)

the core that handles an IRQ line.

Parameters
irqthe IRQ line (0 to 15).
Returns
the index of the core; 0 (the boot core) until the line moves.

◆ irq_spread()

void irq_spread ( void )

spread the device interrupts over the cores that run the scheduler: each IRQ line that has a handler, and each PCI device that uses MSI or MSI-X, goes to the next core in turn, as Linux gives each interrupt one core.

IRQ 0 (the PIT) stays on the boot core. call it once, after smp_init().