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  * @v pci PCI device
32  * @ret ok Bus probing is allowed
33  */
34 static inline __always_inline int
35 PCIAPI_INLINE ( direct, pci_can_probe ) ( struct pci_device *pci __unused ) {
36  return 1;
37 }
38 
39 /**
40  * Find next PCI bus:dev.fn address range in system
41  *
42  * @v busdevfn Starting PCI bus:dev.fn address
43  * @v range PCI bus:dev.fn address range to fill in
44  */
45 static inline __always_inline void
47  struct pci_range *range ) {
48 
49  /* Scan first bus and rely on bridge detection to find higher buses */
50  range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
51  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
52 }
53 
54 /**
55  * Read byte from PCI configuration space via Type 1 access
56  *
57  * @v pci PCI device
58  * @v where Location within PCI configuration space
59  * @v value Value read
60  * @ret rc Return status code
61  */
62 static inline __always_inline int
63 PCIAPI_INLINE ( direct, pci_read_config_byte ) ( struct pci_device *pci,
64  unsigned int where,
66  pcidirect_prepare ( pci, where );
67  *value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
68  return 0;
69 }
70 
71 /**
72  * Read word from PCI configuration space via Type 1 access
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 static inline __always_inline int
80 PCIAPI_INLINE ( direct, pci_read_config_word ) ( struct pci_device *pci,
81  unsigned int where,
82  uint16_t *value ) {
83  pcidirect_prepare ( pci, where );
84  *value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
85  return 0;
86 }
87 
88 /**
89  * Read dword from PCI configuration space via Type 1 access
90  *
91  * @v pci PCI device
92  * @v where Location within PCI configuration space
93  * @v value Value read
94  * @ret rc Return status code
95  */
96 static inline __always_inline int
97 PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
98  unsigned int where,
99  uint32_t *value ) {
100  pcidirect_prepare ( pci, where );
102  return 0;
103 }
104 
105 /**
106  * Write byte to PCI configuration space via Type 1 access
107  *
108  * @v pci PCI device
109  * @v where Location within PCI configuration space
110  * @v value Value to be written
111  * @ret rc Return status code
112  */
113 static inline __always_inline int
114 PCIAPI_INLINE ( direct, pci_write_config_byte ) ( struct pci_device *pci,
115  unsigned int where,
116  uint8_t value ) {
117  pcidirect_prepare ( pci, where );
118  outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
119  return 0;
120 }
121 
122 /**
123  * Write word to PCI configuration space via Type 1 access
124  *
125  * @v pci PCI device
126  * @v where Location within PCI configuration space
127  * @v value Value to be written
128  * @ret rc Return status code
129  */
130 static inline __always_inline int
131 PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
132  unsigned int where,
133  uint16_t value ) {
134  pcidirect_prepare ( pci, where );
135  outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
136  return 0;
137 }
138 
139 /**
140  * Write dword to PCI configuration space via Type 1 access
141  *
142  * @v pci PCI device
143  * @v where Location within PCI configuration space
144  * @v value Value to be written
145  * @ret rc Return status code
146  */
147 static inline __always_inline int
148 PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
149  unsigned int where,
150  uint32_t value ) {
151  pcidirect_prepare ( pci, where );
153  return 0;
154 }
155 
156 /**
157  * Map PCI bus address as an I/O address
158  *
159  * @v bus_addr PCI bus address
160  * @v len Length of region
161  * @ret io_addr I/O address, or NULL on error
162  */
163 static inline __always_inline void *
164 PCIAPI_INLINE ( direct, pci_ioremap ) ( struct pci_device *pci __unused,
165  unsigned long bus_addr, size_t len ) {
166  return ioremap ( bus_addr, len );
167 }
168 
169 #endif /* _PCIDIRECT_H */
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:24
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.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
outl(value, PCIDIRECT_CONFIG_DATA)
static __always_inline int PCIAPI_INLINE(direct, pci_can_probe)(struct pci_device *pci __unused)
Check if PCI bus probing is allowed.
Definition: pcidirect.h:35
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_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:165
#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:22
static __always_inline void struct pci_range * range
Definition: pcidirect.h:47
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:29
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:210
#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:165
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:64
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:26
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:65
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.