Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / efi / efi_pci_api.h
1 #ifndef _IPXE_EFI_PCI_API_H
2 #define _IPXE_EFI_PCI_API_H
3
4 /** @file
5  *
6  * iPXE PCI I/O API for EFI
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #ifdef PCIAPI_EFI
13 #define PCIAPI_PREFIX_efi
14 #else
15 #define PCIAPI_PREFIX_efi __efi_
16 #endif
17
18 /* EFI PCI width codes defined by EFI spec */
19 #define EFIPCI_WIDTH_BYTE 0
20 #define EFIPCI_WIDTH_WORD 1
21 #define EFIPCI_WIDTH_DWORD 2
22
23 #define EFIPCI_LOCATION( _offset, _width ) \
24         ( (_offset) | ( (_width) << 16 ) )
25 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
26 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
27
28 struct pci_device;
29
30 extern int efipci_read ( struct pci_device *pci, unsigned long location,
31                          void *value );
32 extern int efipci_write ( struct pci_device *pci, unsigned long location,
33                           unsigned long value );
34
35 /**
36  * Determine number of PCI buses within system
37  *
38  * @ret num_bus         Number of buses
39  */
40 static inline __always_inline int
41 PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
42         /* EFI does not want us to scan the PCI bus ourselves */
43         return 0;
44 }
45
46 /**
47  * Read byte from PCI configuration space via EFI
48  *
49  * @v pci       PCI device
50  * @v where     Location within PCI configuration space
51  * @v value     Value read
52  * @ret rc      Return status code
53  */
54 static inline __always_inline int
55 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
56                                               unsigned int where,
57                                               uint8_t *value ) {
58         *value = 0xff;
59         return efipci_read ( pci,
60                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
61                              value );
62 }
63
64 /**
65  * Read word from PCI configuration space via EFI
66  *
67  * @v pci       PCI device
68  * @v where     Location within PCI configuration space
69  * @v value     Value read
70  * @ret rc      Return status code
71  */
72 static inline __always_inline int
73 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
74                                               unsigned int where,
75                                               uint16_t *value ) {
76         *value = 0xffff;
77         return efipci_read ( pci,
78                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
79                              value );
80 }
81
82 /**
83  * Read dword from PCI configuration space via EFI
84  *
85  * @v pci       PCI device
86  * @v where     Location within PCI configuration space
87  * @v value     Value read
88  * @ret rc      Return status code
89  */
90 static inline __always_inline int
91 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
92                                                unsigned int where,
93                                                uint32_t *value ) {
94         *value = 0xffffffffUL;
95         return efipci_read ( pci,
96                              EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
97                              value );
98 }
99
100 /**
101  * Write byte to PCI configuration space via EFI
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 ( efi, pci_write_config_byte ) ( struct pci_device *pci,
110                                                unsigned int where,
111                                                uint8_t value ) {
112         return efipci_write ( pci,
113                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_BYTE ),
114                               value );
115 }
116
117 /**
118  * Write word to PCI configuration space via EFI
119  *
120  * @v pci       PCI device
121  * @v where     Location within PCI configuration space
122  * @v value     Value to be written
123  * @ret rc      Return status code
124  */
125 static inline __always_inline int
126 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
127                                                unsigned int where,
128                                                uint16_t value ) {
129         return efipci_write ( pci,
130                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_WORD ),
131                               value );
132 }
133
134 /**
135  * Write dword to PCI configuration space via EFI
136  *
137  * @v pci       PCI device
138  * @v where     Location within PCI configuration space
139  * @v value     Value to be written
140  * @ret rc      Return status code
141  */
142 static inline __always_inline int
143 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
144                                                 unsigned int where,
145                                                 uint32_t value ) {
146         return efipci_write ( pci,
147                               EFIPCI_LOCATION ( where, EFIPCI_WIDTH_DWORD ),
148                               value );
149 }
150
151 #endif /* _IPXE_EFI_PCI_API_H */