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