iPXE
pcidirect.h
Go to the documentation of this file.
1#ifndef _PCIDIRECT_H
2#define _PCIDIRECT_H
3
4FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
5FILE_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
25struct pci_device;
26
27extern 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 */
35static inline __always_inline int
36PCIAPI_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 */
46static 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 */
63static inline __always_inline int
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 */
80static inline __always_inline int
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 */
97static inline __always_inline int
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 */
114static inline __always_inline int
116 unsigned int where,
117 uint8_t value ) {
118 pcidirect_prepare ( pci, where );
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 */
131static inline __always_inline int
133 unsigned int where,
134 uint16_t value ) {
135 pcidirect_prepare ( pci, where );
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 */
148static inline __always_inline int
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 */
164static inline __always_inline void *
166 unsigned long bus_addr, size_t len ) {
167 return ioremap ( bus_addr, len );
168}
169
170#endif /* _PCIDIRECT_H */
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
#define __always_inline
Declare a function to be always inline.
Definition compiler.h:611
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
iPXE I/O API
#define inw(io_addr)
Definition io.h:292
#define outb(data, io_addr)
Definition io.h:310
#define outw(data, io_addr)
Definition io.h:320
#define inl(io_addr)
Definition io.h:301
#define outl(data, io_addr)
Definition io.h:330
#define inb(io_addr)
Definition io.h:283
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#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.
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_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
#define PCIAPI_INLINE(_subsys, _api_func)
Calculate static inline PCI I/O API function name.
Definition pci_io.h:41
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156
static __always_inline int unsigned int where
Definition pcibios.h:57
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
#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
A PCI device.
Definition pci.h:211
A PCI bus:dev.fn address range.
Definition pci_io.h:23