The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_irq.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Typedefs

typedef struct trap_frame trap_frame_t
 arch-neutral hardware-interrupt (IRQ) interface.
typedef void(*) irq_handler_fn(uint32_t irq, trap_frame_t *frame)
 IRQ handler function type.
typedef void(*) device_irq_handler_t(void *context)
 a device interrupt handler (a message-signalled interrupt, or a PCI interrupt line).

Functions

bool arch_frame_is_user (const trap_frame_t *frame)
 true if the interrupt came while user code ran (CPU time accounting).
int arch_irq_register (uint32_t irq, irq_handler_fn handler)
 register a handler for a hardware IRQ line.
void arch_irq_enable (uint32_t irq)
 unmask (enable) a hardware IRQ line so it can be delivered.
void arch_irq_disable (uint32_t irq)
 mask (disable) a hardware IRQ line.
void arch_irq_ack (uint32_t irq)
 acknowledge an IRQ (end-of-interrupt) at the interrupt controller.
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 message that the device must write to raise it.
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.
bool arch_irq_set_cpu (uint32_t irq, uint32_t cpu)
 send the interrupts of an ISA IRQ line to a core.
uint64_t arch_msi_address (uint32_t cpu)
 the message address that sends a message-signalled interrupt to a core.

Typedef Documentation

◆ trap_frame_t

typedef struct trap_frame trap_frame_t

arch-neutral hardware-interrupt (IRQ) interface.

portable drivers register their line handlers through this API instead of reaching into the x86 PIC/IDT/ISR machinery. each architecture provides its own implementation that wraps whatever interrupt controller it has (8259A PIC on x86, GIC on ARM, PLIC on RISC-V). opaque saved-state handle passed to an IRQ handler.

the concrete layout is architecture-specific (on x86 it is the register dump built by the ISR stubs). portable code treats it as opaque; only arch code that knows the layout may dereference it. handlers that just need to service a device can ignore it entirely.

◆ irq_handler_fn

typedef void(*) irq_handler_fn(uint32_t irq, trap_frame_t *frame)

IRQ handler function type.

Parameters
irqthe hardware IRQ line that fired.
frameopaque saved state at the point of interruption (may be NULL to a handler that does not need it).

◆ device_irq_handler_t

typedef void(*) device_irq_handler_t(void *context)

a device interrupt handler (a message-signalled interrupt, or a PCI interrupt line).

it runs with interrupts off, after the end of interrupt is sent, so it must clear the cause in the device.

Parameters
contextthe value given when the handler was attached.

Function Documentation

◆ arch_frame_is_user()

bool arch_frame_is_user ( const trap_frame_t * frame)

true if the interrupt came while user code ran (CPU time accounting).

Parameters
framethe frame a handler was given.

◆ arch_irq_register()

int arch_irq_register ( uint32_t irq,
irq_handler_fn handler )

register a handler for a hardware IRQ line.

Parameters
irqthe IRQ line to handle.
handlerthe function to call when the line fires.
Returns
0 on success, -1 if the IRQ number is out of range.

◆ arch_irq_enable()

void arch_irq_enable ( uint32_t irq)

unmask (enable) a hardware IRQ line so it can be delivered.

Parameters
irqthe IRQ line to enable.

◆ arch_irq_disable()

void arch_irq_disable ( uint32_t irq)

mask (disable) a hardware IRQ line.

Parameters
irqthe IRQ line to disable.

◆ arch_irq_ack()

void arch_irq_ack ( uint32_t irq)

acknowledge an IRQ (end-of-interrupt) at the interrupt controller.

Parameters
irqthe IRQ line to acknowledge.

◆ arch_msi_alloc()

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 message that the device must write to raise it.

Parameters
handlerthe function to call when the message arrives.
contextpassed to the handler.
addressreceives the message address.
datareceives the message data.
Returns
false if the CPU cannot take messages (no local APIC in use) or all device vectors are in use.

◆ arch_irq_set_level()

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.

does nothing when the line is already level or when the 8259 PICs are in use (the firmware sets their trigger mode).

Parameters
irqthe IRQ line (0 to 15).

◆ arch_irq_set_cpu()

bool arch_irq_set_cpu ( uint32_t irq,
uint32_t cpu )

send the interrupts of an ISA IRQ line to a core.

the vector does not change, so an interrupt that comes during the change goes to the old core or to the new one, and both handle it.

Parameters
irqthe IRQ line (0 to 15).
cputhe index of the core (cpu_t.index).
Returns
false if the line cannot move: the line has no I/O APIC entry, or the 8259 PICs are in use (they interrupt only the boot core).

◆ arch_msi_address()

uint64_t arch_msi_address ( uint32_t cpu)

the message address that sends a message-signalled interrupt to a core.

the message data (the vector) is the same on each core.

Parameters
cputhe index of the core (cpu_t.index).
Returns
the address for the MSI or MSI-X capability of a device.