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  * Find next PCI bus:dev.fn address range in system
30  *
31  * @v busdevfn Starting PCI bus:dev.fn address
32  * @v range PCI bus:dev.fn address range to fill in
33  */
34 static inline __always_inline void
36  struct pci_range *range ) {
37 
38  /* Scan first bus and rely on bridge detection to find higher buses */
39  range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
40  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
41 }
42 
43 /**
44  * Read byte from PCI configuration space via Type 1 access
45  *
46  * @v pci PCI device
47  * @v where Location within PCI configuration space
48  * @v value Value read
49  * @ret rc Return status code
50  */
51 static inline __always_inline int
52 PCIAPI_INLINE ( direct, pci_read_config_byte ) ( struct pci_device *pci,
53  unsigned int where,
55  pcidirect_prepare ( pci, where );
56  *value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
57  return 0;
58 }
59 
60 /**
61  * Read word from PCI configuration space via Type 1 access
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 static inline __always_inline int
69 PCIAPI_INLINE ( direct, pci_read_config_word ) ( struct pci_device *pci,
70  unsigned int where,
71  uint16_t *value ) {
72  pcidirect_prepare ( pci, where );
73  *value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
74  return 0;
75 }
76 
77 /**
78  * Read dword from PCI configuration space via Type 1 access
79  *
80  * @v pci PCI device
81  * @v where Location within PCI configuration space
82  * @v value Value read
83  * @ret rc Return status code
84  */
85 static inline __always_inline int
86 PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
87  unsigned int where,
88  uint32_t *value ) {
89  pcidirect_prepare ( pci, where );
91  return 0;
92 }
93 
94 /**
95  * Write byte to PCI configuration space via Type 1 access
96  *
97  * @v pci PCI device
98  * @v where Location within PCI configuration space
99  * @v value Value to be written
100  * @ret rc Return status code
101  */
102 static inline __always_inline int
103 PCIAPI_INLINE ( direct, pci_write_config_byte ) ( struct pci_device *pci,
104  unsigned int where,
105  uint8_t value ) {
106  pcidirect_prepare ( pci, where );
107  outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
108  return 0;
109 }
110 
111 /**
112  * Write word to PCI configuration space via Type 1 access
113  *
114  * @v pci PCI device
115  * @v where Location within PCI configuration space
116  * @v value Value to be written
117  * @ret rc Return status code
118  */
119 static inline __always_inline int
120 PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
121  unsigned int where,
122  uint16_t value ) {
123  pcidirect_prepare ( pci, where );
124  outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
125  return 0;
126 }
127 
128 /**
129  * Write dword to PCI configuration space via Type 1 access
130  *
131  * @v pci PCI device
132  * @v where Location within PCI configuration space
133  * @v value Value to be written
134  * @ret rc Return status code
135  */
136 static inline __always_inline int
137 PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
138  unsigned int where,
139  uint32_t value ) {
140  pcidirect_prepare ( pci, where );
142  return 0;
143 }
144 
145 /**
146  * Map PCI bus address as an I/O address
147  *
148  * @v bus_addr PCI bus address
149  * @v len Length of region
150  * @ret io_addr I/O address, or NULL on error
151  */
152 static inline __always_inline void *
153 PCIAPI_INLINE ( direct, pci_ioremap ) ( struct pci_device *pci __unused,
154  unsigned long bus_addr, size_t len ) {
155  return ioremap ( bus_addr, len );
156 }
157 
158 extern struct pci_api pcidirect_api;
159 
160 #endif /* _PCIDIRECT_H */
struct pci_api pcidirect_api
Definition: pcidirect.c:57
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_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:154
#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.
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
static __always_inline void struct pci_range * range
Definition: pcidirect.h:36
#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:154
#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:154
static __always_inline void PCIAPI_INLINE(direct, pci_discover)(uint32_t busdevfn __unused
Find next PCI bus:dev.fn address range in system.
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:53
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.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
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:54
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.