[pci] Add support for PCI MSI-X interrupts
[ipxe.git] / src / include / ipxe / pcimsix.h
1 #ifndef _IPXE_PCIMSIX_H
2 #define _IPXE_PCIMSIX_H
3
4 /** @file
5 *
6 * PCI MSI-X interrupts
7 *
8 */
9
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12 #include <ipxe/pci.h>
13
14 /** MSI-X BAR mapped length */
15 #define PCI_MSIX_LEN 0x1000
16
17 /** MSI-X vector offset */
18 #define PCI_MSIX_VECTOR(n) ( (n) * 0x10 )
19
20 /** MSI-X vector address low 32 bits */
21 #define PCI_MSIX_ADDRESS_LO 0x0
22
23 /** MSI-X vector address high 32 bits */
24 #define PCI_MSIX_ADDRESS_HI 0x4
25
26 /** MSI-X vector data */
27 #define PCI_MSIX_DATA 0x8
28
29 /** MSI-X vector control */
30 #define PCI_MSIX_CONTROL 0xc
31 #define PCI_MSIX_CONTROL_MASK 0x00000001 /**< Vector is masked */
32
33 /** PCI MSI-X capability */
34 struct pci_msix {
35 /** Capability offset */
36 unsigned int cap;
37 /** Number of vectors */
38 unsigned int count;
39 /** MSI-X table */
40 void *table;
41 /** Pending bit array */
42 void *pba;
43 };
44
45 extern int pci_msix_enable ( struct pci_device *pci, struct pci_msix *msix );
46 extern void pci_msix_disable ( struct pci_device *pci, struct pci_msix *msix );
47 extern void pci_msix_map ( struct pci_msix *msix, unsigned int vector,
48 physaddr_t address, uint32_t data );
49 extern void pci_msix_control ( struct pci_msix *msix, unsigned int vector,
50 uint32_t mask );
51 extern void pci_msix_dump ( struct pci_msix *msix, unsigned int vector );
52
53 /**
54 * Mask MSI-X interrupt vector
55 *
56 * @v msix MSI-X capability
57 * @v vector MSI-X vector
58 */
59 static inline __attribute__ (( always_inline )) void
60 pci_msix_mask ( struct pci_msix *msix, unsigned int vector ) {
61
62 pci_msix_control ( msix, vector, PCI_MSIX_CONTROL_MASK );
63 }
64
65 /**
66 * Unmask MSI-X interrupt vector
67 *
68 * @v msix MSI-X capability
69 * @v vector MSI-X vector
70 */
71 static inline __attribute__ (( always_inline )) void
72 pci_msix_unmask ( struct pci_msix *msix, unsigned int vector ) {
73
74 pci_msix_control ( msix, vector, 0 );
75 }
76
77 #endif /* _IPXE_PCIMSIX_H */