Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / linux / linux_pci.h
1 #ifndef _IPXE_LINUX_PCI_H
2 #define _IPXE_LINUX_PCI_H
3
4 /** @file
5  *
6  * iPXE PCI API for Linux
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #ifdef PCIAPI_LINUX
13 #define PCIAPI_PREFIX_linux
14 #else
15 #define PCIAPI_PREFIX_linux __linux_
16 #endif
17
18 struct pci_device;
19
20 extern int linux_pci_read ( struct pci_device *pci, unsigned long where,
21                             unsigned long *value, size_t len );
22 extern int linux_pci_write ( struct pci_device *pci, unsigned long where,
23                              unsigned long value, size_t len );
24
25 /**
26  * Read byte from PCI configuration space
27  *
28  * @v pci       PCI device
29  * @v where     Location within PCI configuration space
30  * @v value     Value read
31  * @ret rc      Return status code
32  */
33 static inline __always_inline int
34 PCIAPI_INLINE ( linux, pci_read_config_byte ) ( struct pci_device *pci,
35                                                 unsigned int where,
36                                                 uint8_t *value ) {
37         int rc;
38         unsigned long tmp;
39
40         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
41         *value = tmp;
42         return rc;
43 }
44
45 /**
46  * Read word from PCI configuration space
47  *
48  * @v pci       PCI device
49  * @v where     Location within PCI configuration space
50  * @v value     Value read
51  * @ret rc      Return status code
52  */
53 static inline __always_inline int
54 PCIAPI_INLINE ( linux, pci_read_config_word ) ( struct pci_device *pci,
55                                                 unsigned int where,
56                                                 uint16_t *value ) {
57         int rc;
58         unsigned long tmp;
59
60         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
61         *value = tmp;
62         return rc;
63 }
64
65 /**
66  * Read dword from PCI configuration space
67  *
68  * @v pci       PCI device
69  * @v where     Location within PCI configuration space
70  * @v value     Value read
71  * @ret rc      Return status code
72  */
73 static inline __always_inline int
74 PCIAPI_INLINE ( linux, pci_read_config_dword ) ( struct pci_device *pci,
75                                                  unsigned int where,
76                                                  uint32_t *value ) {
77         int rc;
78         unsigned long tmp;
79
80         rc = linux_pci_read ( pci, where, &tmp, sizeof ( *value ) );
81         *value = tmp;
82         return rc;
83 }
84
85 /**
86  * Write byte to PCI configuration space
87  *
88  * @v pci       PCI device
89  * @v where     Location within PCI configuration space
90  * @v value     Value to be written
91  * @ret rc      Return status code
92  */
93 static inline __always_inline int
94 PCIAPI_INLINE ( linux, pci_write_config_byte ) ( struct pci_device *pci,
95                                                  unsigned int where,
96                                                  uint8_t value ) {
97         return linux_pci_write ( pci, where, value, sizeof ( value ) );
98 }
99
100 /**
101  * Write word to PCI configuration space
102  *
103  * @v pci       PCI device
104  * @v where     Location within PCI configuration space
105  * @v value     Value to be written
106  * @ret rc      Return status code
107  */
108 static inline __always_inline int
109 PCIAPI_INLINE ( linux, pci_write_config_word ) ( struct pci_device *pci,
110                                                  unsigned int where,
111                                                  uint16_t value ) {
112         return linux_pci_write ( pci, where, value, sizeof ( value ) );
113 }
114
115 /**
116  * Write dword to PCI configuration space
117  *
118  * @v pci       PCI device
119  * @v where     Location within PCI configuration space
120  * @v value     Value to be written
121  * @ret rc      Return status code
122  */
123 static inline __always_inline int
124 PCIAPI_INLINE ( linux, pci_write_config_dword ) ( struct pci_device *pci,
125                                                   unsigned int where,
126                                                   uint32_t value ) {
127         return linux_pci_write ( pci, where, value, sizeof ( value ) );
128 }
129
130 #endif /* _IPXE_LINUX_PCI_H */