1 #ifndef _IPXE_PCI_IO_H
2 #define _IPXE_PCI_IO_H
3 
4 /** @file
5  *
6  * PCI I/O API
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <ipxe/api.h>
14 #include <ipxe/iomap.h>
15 #include <config/ioapi.h>
16 
17 /**
18  * Calculate static inline PCI I/O API function name
19  *
20  * @v _prefix		Subsystem prefix
21  * @v _api_func		API function
22  * @ret _subsys_func	Subsystem API function
23  */
24 #define PCIAPI_INLINE( _subsys, _api_func ) \
25 	SINGLE_API_INLINE ( PCIAPI_PREFIX_ ## _subsys, _api_func )
26 
27 /**
28  * Provide a PCI I/O API implementation
29  *
30  * @v _prefix		Subsystem prefix
31  * @v _api_func		API function
32  * @v _func		Implementing function
33  */
34 #define PROVIDE_PCIAPI( _subsys, _api_func, _func ) \
35 	PROVIDE_SINGLE_API ( PCIAPI_PREFIX_ ## _subsys, _api_func, _func )
36 
37 /**
38  * Provide a static inline PCI I/O API implementation
39  *
40  * @v _prefix		Subsystem prefix
41  * @v _api_func		API function
42  */
43 #define PROVIDE_PCIAPI_INLINE( _subsys, _api_func ) \
44 	PROVIDE_SINGLE_API_INLINE ( PCIAPI_PREFIX_ ## _subsys, _api_func )
45 
46 /* Include all architecture-independent I/O API headers */
47 #include <ipxe/efi/efi_pci_api.h>
48 #include <ipxe/linux/linux_pci.h>
49 
50 /* Include all architecture-dependent I/O API headers */
51 #include <bits/pci_io.h>
52 
53 /**
54  * Determine number of PCI buses within system
55  *
56  * @ret num_bus		Number of buses
57  */
58 int pci_num_bus ( void );
59 
60 /**
61  * Read byte from PCI configuration space
62  *
63  * @v pci	PCI device
64  * @v where	Location within PCI configuration space
65  * @v value	Value read
66  * @ret rc	Return status code
67  */
68 int pci_read_config_byte ( struct pci_device *pci, unsigned int where,
69 			   uint8_t *value );
70 
71 /**
72  * Read 16-bit word from PCI configuration space
73  *
74  * @v pci	PCI device
75  * @v where	Location within PCI configuration space
76  * @v value	Value read
77  * @ret rc	Return status code
78  */
79 int pci_read_config_word ( struct pci_device *pci, unsigned int where,
80 			   uint16_t *value );
81 
82 /**
83  * Read 32-bit dword from PCI configuration space
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 int pci_read_config_dword ( struct pci_device *pci, unsigned int where,
91 			    uint32_t *value );
92 
93 /**
94  * Write byte to PCI configuration space
95  *
96  * @v pci	PCI device
97  * @v where	Location within PCI configuration space
98  * @v value	Value to be written
99  * @ret rc	Return status code
100  */
101 int pci_write_config_byte ( struct pci_device *pci, unsigned int where,
102 			    uint8_t value );
103 
104 /**
105  * Write 16-bit word to PCI configuration space
106  *
107  * @v pci	PCI device
108  * @v where	Location within PCI configuration space
109  * @v value	Value to be written
110  * @ret rc	Return status code
111  */
112 int pci_write_config_word ( struct pci_device *pci, unsigned int where,
113 			    uint16_t value );
114 
115 /**
116  * Write 32-bit 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 int pci_write_config_dword ( struct pci_device *pci, unsigned int where,
124 			     uint32_t value );
125 
126 /**
127  * Map PCI bus address as an I/O address
128  *
129  * @v bus_addr		PCI bus address
130  * @v len		Length of region
131  * @ret io_addr		I/O address, or NULL on error
132  */
133 void * pci_ioremap ( struct pci_device *pci, unsigned long bus_addr,
134 		     size_t len );
135 
136 #endif /* _IPXE_PCI_IO_H */
137