iPXE
ecam_io.h File Reference

PCI I/O API for Enhanced Configuration Access Mechanism (ECAM) More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define PCIAPI_PREFIX_ecam   __ecam_
#define ECAM_LOC(where, len)
 Construct ECAM location.
#define ECAM_WHERE(location)
 Extract offset from ECAM location.
#define ECAM_LEN(location)
 Extract length from ECAM location.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int ecam_read (struct pci_device *pci, unsigned int location, void *value)
 Read from PCI configuration space.
int ecam_write (struct pci_device *pci, unsigned int location, unsigned long value)
 Write to PCI configuration space.
static __always_inline int PCIAPI_INLINE (ecam, pci_read_config_byte)(struct pci_device *pci
 Read byte from PCI configuration space via ECAM.
static __always_inline int PCIAPI_INLINE (ecam, pci_read_config_word)(struct pci_device *pci
 Read word from PCI configuration space via ECAM.
static __always_inline int PCIAPI_INLINE (ecam, pci_read_config_dword)(struct pci_device *pci
 Read dword from PCI configuration space via ECAM.
static __always_inline int PCIAPI_INLINE (ecam, pci_write_config_byte)(struct pci_device *pci
 Write byte to PCI configuration space via ECAM.
static __always_inline int PCIAPI_INLINE (ecam, pci_write_config_word)(struct pci_device *pci
 Write word to PCI configuration space via ECAM.
static __always_inline int PCIAPI_INLINE (ecam, pci_write_config_dword)(struct pci_device *pci
 Write dword to PCI configuration space via ECAM.
static __always_inline void * PCIAPI_INLINE (ecam, pci_ioremap)(struct pci_device *pci __unused
 Map PCI bus address as an I/O address.
static __always_inline int PCIAPI_INLINE (ecam, pci_can_probe)(struct pci_device *pci __unused)
 Check if PCI bus probing is allowed.

Variables

static __always_inline int unsigned int where
static __always_inline int unsigned int uint8_tvalue
static __always_inline void unsigned long bus_addr
static __always_inline void unsigned long size_t len

Detailed Description

PCI I/O API for Enhanced Configuration Access Mechanism (ECAM)

Definition in file ecam_io.h.

Macro Definition Documentation

◆ PCIAPI_PREFIX_ecam

#define PCIAPI_PREFIX_ecam   __ecam_

Definition at line 18 of file ecam_io.h.

◆ ECAM_LOC

#define ECAM_LOC ( where,
len )
Value:
( ( (len) << 16 ) | where )
ring len
Length.
Definition dwmac.h:226
static __always_inline int unsigned int where
Definition pcibios.h:57

Construct ECAM location.

Definition at line 24 of file ecam_io.h.

Referenced by PCIAPI_INLINE(), PCIAPI_INLINE(), PCIAPI_INLINE(), PCIAPI_INLINE(), and PCIAPI_INLINE().

◆ ECAM_WHERE

#define ECAM_WHERE ( location)
Value:
( (location) & 0xffff )

Extract offset from ECAM location.

Definition at line 27 of file ecam_io.h.

Referenced by ecam_read(), and ecam_write().

◆ ECAM_LEN

#define ECAM_LEN ( location)
Value:
( (location) >> 16 )

Extract length from ECAM location.

Definition at line 30 of file ecam_io.h.

Referenced by ecam_read(), and ecam_write().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ecam_read()

int ecam_read ( struct pci_device * pci,
unsigned int location,
void * value )
extern

Read from PCI configuration space.

Parameters
pciPCI device
locationOffset and length within PCI configuration space
valueValue read
Return values
rcReturn status code

Definition at line 190 of file ecam.c.

190 {
191 unsigned int where = ECAM_WHERE ( location );
192 unsigned int len = ECAM_LEN ( location );
193 unsigned int index;
194 void *addr;
195 int rc;
196
197 /* Return all-ones on error */
198 memset ( value, 0xff, len );
199
200 /* Access configuration space */
201 if ( ( rc = ecam_access ( pci ) ) != 0 )
202 return rc;
203
204 /* Read from address */
205 index = ( pci->busdevfn - ecam.range.start );
206 addr = ( ecam.regs + ( index * ECAM_SIZE ) + where );
207 switch ( len ) {
208 case 4:
209 *( ( uint32_t *) value ) = readl ( addr );
210 break;
211 case 2:
212 *( ( uint16_t *) value ) = readw ( addr );
213 break;
214 case 1:
215 *( ( uint8_t *) value ) = readb ( addr );
216 break;
217 default:
218 assert ( 0 );
219 }
220
221 return 0;
222}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
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
long index
Definition bigint.h:65
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint32_t addr
Buffer address.
Definition dwmac.h:9
static int ecam_access(struct pci_device *pci)
Access configuration space for PCI device.
Definition ecam.c:117
static struct ecam_mapping ecam
Cached mapped ECAM allocation.
Definition ecam.c:37
#define ECAM_SIZE
Enhanced Configuration Access Mechanism per-device size.
Definition ecam.h:16
#define ECAM_WHERE(location)
Extract offset from ECAM location.
Definition ecam_io.h:27
#define ECAM_LEN(location)
Extract length from ECAM location.
Definition ecam_io.h:30
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238
#define readl
Definition w89c840.c:157
#define readb
Definition w89c840.c:155
#define readw
Definition w89c840.c:156

References addr, assert, pci_device::busdevfn, ecam, ecam_access(), ECAM_LEN, ECAM_SIZE, ECAM_WHERE, index, len, memset(), rc, readb, readl, readw, value, and where.

Referenced by ecam_write(), PCIAPI_INLINE(), and PCIAPI_INLINE().

◆ ecam_write()

int ecam_write ( struct pci_device * pci,
unsigned int location,
unsigned long value )
extern

Write to PCI configuration space.

Parameters
pciPCI device
locationOffset and length within PCI configuration space
valueValue to write
Return values
rcReturn status code

Definition at line 232 of file ecam.c.

233 {
234 unsigned int where = ECAM_WHERE ( location );
235 unsigned int len = ECAM_LEN ( location );
236 unsigned int index;
237 void *addr;
238 int rc;
239
240 /* Access configuration space */
241 if ( ( rc = ecam_access ( pci ) ) != 0 )
242 return rc;
243
244 /* Write to address */
245 index = ( pci->busdevfn - ecam.range.start );
246 addr = ( ecam.regs + ( index * ECAM_SIZE ) + where );
247 switch ( len ) {
248 case 4:
249 writel ( value, addr );
250 break;
251 case 2:
252 writew ( value, addr );
253 break;
254 case 1:
255 writeb ( value, addr );
256 break;
257 default:
258 assert ( 0 );
259 }
260
261 /* Read from address, to guarantee completion of the write
262 *
263 * PCIe configuration space registers may not have read side
264 * effects. Reading back is therefore always safe to do, and
265 * guarantees that the write has reached the device.
266 */
267 mb();
268 ecam_read ( pci, location, &value );
269
270 return 0;
271}
int ecam_read(struct pci_device *pci, unsigned int location, void *value)
Read from PCI configuration space.
Definition ecam.c:190
void mb(void)
Memory barrier.
#define writel
Definition w89c840.c:160
#define writew
Definition w89c840.c:159
#define writeb
Definition w89c840.c:158

References addr, assert, pci_device::busdevfn, ecam, ecam_access(), ECAM_LEN, ecam_read(), ECAM_SIZE, ECAM_WHERE, index, len, mb(), rc, value, where, writeb, writel, and writew.

Referenced by PCIAPI_INLINE(), PCIAPI_INLINE(), and PCIAPI_INLINE().

◆ PCIAPI_INLINE() [1/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_read_config_byte  )
inlinestatic

Read byte from PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

References ecam, and pci_read_config_byte().

◆ PCIAPI_INLINE() [2/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_read_config_word  )
inlinestatic

Read word from PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

References ecam, ECAM_LOC, ecam_read(), pci_read_config_word(), value, and where.

◆ PCIAPI_INLINE() [3/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_read_config_dword  )
inlinestatic

Read dword from PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue read
Return values
rcReturn status code

References ecam, ECAM_LOC, ecam_read(), pci_read_config_dword(), value, and where.

◆ PCIAPI_INLINE() [4/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_write_config_byte  )
inlinestatic

Write byte to PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

References ecam, ECAM_LOC, ecam_write(), pci_write_config_byte(), value, and where.

◆ PCIAPI_INLINE() [5/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_write_config_word  )
inlinestatic

Write word to PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

References ecam, ECAM_LOC, ecam_write(), pci_write_config_word(), value, and where.

◆ PCIAPI_INLINE() [6/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_write_config_dword  )
inlinestatic

Write dword to PCI configuration space via ECAM.

Parameters
pciPCI device
whereLocation within PCI configuration space
valueValue to be written
Return values
rcReturn status code

References ecam, ECAM_LOC, ecam_write(), pci_write_config_dword(), value, and where.

◆ PCIAPI_INLINE() [7/8]

__always_inline void * PCIAPI_INLINE ( ecam ,
pci_ioremap  )
inlinestatic

Map PCI bus address as an I/O address.

Parameters
bus_addrPCI bus address
lenLength of region
Return values
io_addrI/O address, or NULL on error

References __unused, ecam, and pci_ioremap().

◆ PCIAPI_INLINE() [8/8]

__always_inline int PCIAPI_INLINE ( ecam ,
pci_can_probe  )
inlinestatic

Check if PCI bus probing is allowed.

Parameters
pciPCI device
Return values
okBus probing is allowed

Definition at line 147 of file ecam_io.h.

147 {
148 return 1;
149}

References __unused, ecam, and pci_can_probe().

Variable Documentation

◆ where

__always_inline int unsigned int where

Definition at line 47 of file ecam_io.h.

◆ value

__always_inline int unsigned int uint32_t value
Initial value:
{
return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value )
#define ECAM_LOC(where, len)
Construct ECAM location.
Definition ecam_io.h:24

Definition at line 48 of file ecam_io.h.

◆ bus_addr

__always_inline void unsigned long bus_addr

Definition at line 136 of file ecam_io.h.

◆ len

__always_inline void unsigned long size_t len
Initial value:
{
return ioremap ( bus_addr, len )
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156

Definition at line 136 of file ecam_io.h.