The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
pci_irq.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file pci_irq.h
5 * @brief interrupts for PCI devices: MSI-X, MSI, or the legacy INTx line.
6 *
7 * a driver attaches one handler to its device. pci_irq_attach uses the
8 * best way the device and the CPU support: MSI-X (entry 0), then MSI (one
9 * message), then the interrupt line the firmware routed (INTx, shared,
10 * level-triggered). MSI and MSI-X need the local APIC; with the 8259 PICs
11 * only INTx is possible.
12 *
13 * limits: without an AML interpreter the kernel cannot read the ACPI _PRT,
14 * so INTx uses the ISA line from the configuration space (irq_line). this
15 * works with the 8259 PICs and on QEMU with the I/O APIC, but on real
16 * machines with the I/O APIC a device without MSI can stay without
17 * interrupts. drivers must keep a polled path for this case.
18 */
19
20#include "common/stdint.h"
21#include "arch/arch_irq.h"
22#include "drivers/pci/pci.h"
23
24typedef enum
25{
26 PCI_IRQ_NONE, // no interrupt: the driver polls
27 PCI_IRQ_INTX, // the legacy interrupt line
31
32// how many device handlers the kernel keeps
33#define PCI_IRQ_MAX 16
34
35/**
36 * attach an interrupt handler to a device and enable its interrupt.
37 * call it once per device, before the device is told to raise interrupts.
38 * @param dev the device.
39 * @param handler the function to call; it must clear the cause in the
40 * device, and for INTx it must return quickly when its device has
41 * nothing to report (the line can be shared).
42 * @param context passed to the handler.
43 * @param name a short name for /proc/interrupts.
44 * @return the mode in use, or PCI_IRQ_NONE if no interrupt is possible.
45 */
47 const char *name);
48
49/**
50 * one attached handler, for /proc/interrupts.
51 */
52typedef struct
53{
54 const char *name;
56 uint32_t number; // the vector (MSI, MSI-X) or the IRQ line (INTx)
57 uint32_t count; // interrupts handled
58 uint32_t cpu; // the index of the core that handles them
60
61/**
62 * the attached handler at an index.
63 * @return false if index is out of range.
64 */
65bool pci_irq_info(uint32_t index, pci_irq_info_t *info);
66
67/**
68 * send the messages of an attached handler to a core. an INTx handler
69 * does not move here: its line moves with irq_set_cpu().
70 * @param index the index of the handler, as for pci_irq_info().
71 * @param cpu the index of the core (cpu_t.index).
72 * @return false if index is out of range or the handler does not use MSI
73 * or MSI-X.
74 */
76
77/**
78 * a short name for a mode ("MSI-X", "MSI", "INTx", "none").
79 */
80const char *pci_irq_mode_name(pci_irq_mode_t mode);
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
unsigned int uint32_t
Definition fb.h:17
PCI bus enumeration through the legacy configuration ports.
bool pci_irq_set_cpu(uint32_t index, uint32_t cpu)
send the messages of an attached handler to a core.
Definition pci_irq.c:258
bool pci_irq_info(uint32_t index, pci_irq_info_t *info)
the attached handler at an index.
Definition pci_irq.c:243
pci_irq_mode_t pci_irq_attach(pci_device_t *dev, device_irq_handler_t handler, void *context, const char *name)
attach an interrupt handler to a device and enable its interrupt.
Definition pci_irq.c:203
const char * pci_irq_mode_name(pci_irq_mode_t mode)
a short name for a mode ("MSI-X", "MSI", "INTx", "none").
Definition pci_irq.c:294
pci_irq_mode_t
Definition pci_irq.h:25
@ PCI_IRQ_MSI
Definition pci_irq.h:28
@ PCI_IRQ_MSIX
Definition pci_irq.h:29
@ PCI_IRQ_NONE
Definition pci_irq.h:26
@ PCI_IRQ_INTX
Definition pci_irq.h:27
the data of one core
Definition cpu.h:39
Definition pci.h:47
one attached handler, for /proc/interrupts.
Definition pci_irq.h:53
const char * name
Definition pci_irq.h:54
uint32_t number
Definition pci_irq.h:56
pci_irq_mode_t mode
Definition pci_irq.h:55
uint32_t count
Definition pci_irq.h:57
uint32_t cpu
Definition pci_irq.h:58