The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
24
typedef
enum
25
{
26
PCI_IRQ_NONE
,
// no interrupt: the driver polls
27
PCI_IRQ_INTX
,
// the legacy interrupt line
28
PCI_IRQ_MSI
,
29
PCI_IRQ_MSIX
,
30
}
pci_irq_mode_t
;
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
*/
46
pci_irq_mode_t
pci_irq_attach
(
pci_device_t
*dev,
device_irq_handler_t
handler,
void
*context,
47
const
char
*name);
48
49
/**
50
* one attached handler, for /proc/interrupts.
51
*/
52
typedef
struct
53
{
54
const
char
*
name
;
55
pci_irq_mode_t
mode
;
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
59
}
pci_irq_info_t
;
60
61
/**
62
* the attached handler at an index.
63
* @return false if index is out of range.
64
*/
65
bool
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
*/
75
bool
pci_irq_set_cpu
(
uint32_t
index,
uint32_t
cpu
);
76
77
/**
78
* a short name for a mode ("MSI-X", "MSI", "INTx", "none").
79
*/
80
const
char
*
pci_irq_mode_name
(
pci_irq_mode_t
mode);
arch_irq.h
device_irq_handler_t
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
stdint.h
uint32_t
unsigned int uint32_t
Definition
fb.h:17
pci.h
PCI bus enumeration through the legacy configuration ports.
pci_irq_set_cpu
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
pci_irq_info
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_attach
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
pci_irq_mode_name
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
pci_irq_mode_t
Definition
pci_irq.h:25
PCI_IRQ_MSI
@ PCI_IRQ_MSI
Definition
pci_irq.h:28
PCI_IRQ_MSIX
@ PCI_IRQ_MSIX
Definition
pci_irq.h:29
PCI_IRQ_NONE
@ PCI_IRQ_NONE
Definition
pci_irq.h:26
PCI_IRQ_INTX
@ PCI_IRQ_INTX
Definition
pci_irq.h:27
cpu
the data of one core
Definition
cpu.h:39
pci_device_t
Definition
pci.h:47
pci_irq_info_t
one attached handler, for /proc/interrupts.
Definition
pci_irq.h:53
pci_irq_info_t::name
const char * name
Definition
pci_irq.h:54
pci_irq_info_t::number
uint32_t number
Definition
pci_irq.h:56
pci_irq_info_t::mode
pci_irq_mode_t mode
Definition
pci_irq.h:55
pci_irq_info_t::count
uint32_t count
Definition
pci_irq.h:57
pci_irq_info_t::cpu
uint32_t cpu
Definition
pci_irq.h:58
src
drivers
pci
pci_irq.h
Generated by
1.18.0