iPXE
pcidirect.h
Go to the documentation of this file.
1 #ifndef _PCIDIRECT_H
2 #define _PCIDIRECT_H
3 
4 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5 
6 #include <stdint.h>
7 #include <ipxe/io.h>
8 
9 #ifdef PCIAPI_DIRECT
10 #define PCIAPI_PREFIX_direct
11 #else
12 #define PCIAPI_PREFIX_direct __direct_
13 #endif
14 
15 /** @file
16  *
17  * PCI configuration space access via Type 1 accesses
18  *
19  */
20 
21 #define PCIDIRECT_CONFIG_ADDRESS 0xcf8
22 #define PCIDIRECT_CONFIG_DATA 0xcfc
23 
24 struct pci_device;
25 
26 extern void pcidirect_prepare ( struct pci_device *pci, int where );
27 
28 /**
29  * Check if PCI bus probing is allowed
30  *
31  * @ret ok Bus probing is allowed
32  */
33 static inline __always_inline int
34 PCIAPI_INLINE ( direct, pci_can_probe ) ( void ) {
35  return 1;
36 }
37 
38 /**
39  * Find next PCI bus:dev.fn address range in system
40  *
41  * @v busdevfn Starting PCI bus:dev.fn address
42  * @v range PCI bus:dev.fn address range to fill in
43  */
44 static inline __always_inline void
46  struct pci_range *range ) {
47 
48  /* Scan first bus and rely on bridge detection to find higher buses */
49  range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
50  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
51 }
52 
53 /**
54  * Read byte from PCI configuration space via Type 1 access
55  *
56  * @v pci PCI device
57  * @v where Location within PCI configuration space
58  * @v value Value read
59  * @ret rc Return status code
60  */
61 static inline __always_inline int
62 PCIAPI_INLINE ( direct, pci_read_config_byte ) ( struct pci_device *pci,
63  unsigned int where,
65  pcidirect_prepare ( pci, where );
66  *value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
67  return 0;
68 }
69 
70 /**
71  * Read word from PCI configuration space via Type 1 access
72  *
73  * @v pci PCI device
74  * @v where Location within PCI configuration space
75  * @v value Value read
76  * @ret rc Return status code
77  */
78 static inline __always_inline int
79 PCIAPI_INLINE ( direct, pci_read_config_word ) ( struct pci_device *pci,
80  unsigned int where,
81  uint16_t *value ) {
82  pcidirect_prepare ( pci, where );
83  *value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
84  return 0;
85 }
86 
87 /**
88  * Read dword from PCI configuration space via Type 1 access
89  *
90  * @v pci PCI device
91  * @v where Location within PCI configuration space
92  * @v value Value read
93  * @ret rc Return status code
94  */
95 static inline __always_inline int
96 PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
97  unsigned int where,
98  uint32_t *value ) {
99  pcidirect_prepare ( pci, where );
101  return 0;
102 }
103 
104 /**
105  * Write byte to PCI configuration space via Type 1 access
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 static inline __always_inline int
113 PCIAPI_INLINE ( direct, pci_write_config_byte ) ( struct pci_device *pci,
114  unsigned int where,
115  uint8_t value ) {
116  pcidirect_prepare ( pci, where );
117  outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
118  return 0;
119 }
120 
121 /**
122  * Write word to PCI configuration space via Type 1 access
123  *
124  * @v pci PCI device
125  * @v where Location within PCI configuration space
126  * @v value Value to be written
127  * @ret rc Return status code
128  */
129 static inline __always_inline int
130 PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
131  unsigned int where,
132  uint16_t value ) {
133  pcidirect_prepare ( pci, where );
134  outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
135  return 0;
136 }
137 
138 /**
139  * Write dword to PCI configuration space via Type 1 access
140  *
141  * @v pci PCI device
142  * @v where Location within PCI configuration space
143  * @v value Value to be written
144  * @ret rc Return status code
145  */
146 static inline __always_inline int
147 PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
148  unsigned int where,
149  uint32_t value ) {
150  pcidirect_prepare ( pci, where );
152  return 0;
153 }
154 
155 /**
156  * Map PCI bus address as an I/O address
157  *
158  * @v bus_addr PCI bus address
159  * @v len Length of region
160  * @ret io_addr I/O address, or NULL on error
161  */
162 static inline __always_inline void *
163 PCIAPI_INLINE ( direct, pci_ioremap ) ( struct pci_device *pci __unused,
164  unsigned long bus_addr, size_t len ) {
165  return ioremap ( bus_addr, len );
166 }
167 
168 extern struct pci_api pcidirect_api;
169 
170 #endif /* _PCIDIRECT_H */
struct pci_api pcidirect_api
Definition: pcidirect.c:58
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
iPXE I/O API
unsigned short uint16_t
Definition: stdint.h:11
outw(value, PCIDIRECT_CONFIG_DATA+(where &2))
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
outl(value, PCIDIRECT_CONFIG_DATA)
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
int pci_can_probe(void)
Check if PCI bus probing is allowed.
static __always_inline int PCIAPI_INLINE(direct, pci_can_probe)(void)
Check if PCI bus probing is allowed.
Definition: pcidirect.h:34
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
static __always_inline void unsigned long bus_addr
Definition: pcidirect.h:164
#define PCIDIRECT_CONFIG_DATA
Definition: pcidirect.h:22
void pcidirect_prepare(struct pci_device *pci, int where)
Prepare for Type 1 PCI configuration space access.
Definition: pcidirect.c:41
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
outb(value, PCIDIRECT_CONFIG_DATA+(where &3))
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
static __always_inline void struct pci_range * range
Definition: pcidirect.h:46
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
A PCI device.
Definition: pci.h:206
A runtime selectable PCI I/O API.
Definition: pci_io.h:162
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
unsigned char uint8_t
Definition: stdint.h:10
static __always_inline void unsigned long size_t len
Definition: pcidirect.h:164
uint8_t inb(volatile uint8_t *io_addr)
Read byte from I/O-mapped device.
unsigned int uint32_t
Definition: stdint.h:12
static __always_inline int unsigned int where
Definition: pcidirect.h:63
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint32_t inl(volatile uint32_t *io_addr)
Read 32-bit dword from I/O-mapped device.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
static __always_inline int unsigned int uint8_t * value
Definition: pcidirect.h:64
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.