iPXE
Macros | Functions | Variables
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)   ( ( (len) << 16 ) | where )
 Construct ECAM location. More...
 
#define ECAM_WHERE(location)   ( (location) & 0xffff )
 Extract offset from ECAM location. More...
 
#define ECAM_LEN(location)   ( (location) >> 16 )
 Extract length from ECAM location. More...
 

Functions

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

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 17 of file ecam_io.h.

◆ ECAM_LOC

#define ECAM_LOC (   where,
  len 
)    ( ( (len) << 16 ) | where )

Construct ECAM location.

Definition at line 23 of file ecam_io.h.

◆ ECAM_WHERE

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

Extract offset from ECAM location.

Definition at line 26 of file ecam_io.h.

◆ ECAM_LEN

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

Extract length from ECAM location.

Definition at line 29 of file ecam_io.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ecam_read()

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

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 184 of file ecam.c.

184  {
185  unsigned int where = ECAM_WHERE ( location );
186  unsigned int len = ECAM_LEN ( location );
187  unsigned int index;
188  void *addr;
189  int rc;
190 
191  /* Return all-ones on error */
192  memset ( value, 0xff, len );
193 
194  /* Access configuration space */
195  if ( ( rc = ecam_access ( pci ) ) != 0 )
196  return rc;
197 
198  /* Read from address */
199  index = ( pci->busdevfn - ecam.range.start );
200  addr = ( ecam.regs + ( index * ECAM_SIZE ) + where );
201  switch ( len ) {
202  case 4:
203  *( ( uint32_t *) value ) = readl ( addr );
204  break;
205  case 2:
206  *( ( uint16_t *) value ) = readw ( addr );
207  break;
208  case 1:
209  *( ( uint8_t *) value ) = readb ( addr );
210  break;
211  default:
212  assert ( 0 );
213  }
214 
215  return 0;
216 }
static int ecam_access(struct pci_device *pci)
Access configuration space for PCI device.
Definition: ecam.c:123
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
struct pci_range range
PCI bus:dev.fn address range.
Definition: ecam.h:50
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static struct ecam_mapping ecam
Cached mapped ECAM allocation.
Definition: ecam.c:37
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void * regs
MMIO base address.
Definition: ecam.h:52
u32 addr
Definition: sky2.h:8
unsigned char uint8_t
Definition: stdint.h:10
#define ECAM_LEN(location)
Extract length from ECAM location.
Definition: ecam_io.h:29
unsigned int uint32_t
Definition: stdint.h:12
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
uint32_t len
Length.
Definition: ena.h:14
#define ECAM_SIZE
Enhanced Configuration Access Mechanism per-device size.
Definition: ecam.h:16
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define ECAM_WHERE(location)
Extract offset from ECAM location.
Definition: ecam_io.h:26
static __always_inline int unsigned int where
Definition: ecam_io.h:46
void * memset(void *dest, int character, size_t len) __nonnull

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

◆ ecam_write()

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

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 226 of file ecam.c.

227  {
228  unsigned int where = ECAM_WHERE ( location );
229  unsigned int len = ECAM_LEN ( location );
230  unsigned int index;
231  void *addr;
232  int rc;
233 
234  /* Access configuration space */
235  if ( ( rc = ecam_access ( pci ) ) != 0 )
236  return rc;
237 
238  /* Read from address */
239  index = ( pci->busdevfn - ecam.range.start );
240  addr = ( ecam.regs + ( index * ECAM_SIZE ) + where );
241  switch ( len ) {
242  case 4:
243  writel ( value, addr );
244  break;
245  case 2:
246  writew ( value, addr );
247  break;
248  case 1:
249  writeb ( value, addr );
250  break;
251  default:
252  assert ( 0 );
253  }
254 
255  return 0;
256 }
static int ecam_access(struct pci_device *pci)
Access configuration space for PCI device.
Definition: ecam.c:123
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct pci_range range
PCI bus:dev.fn address range.
Definition: ecam.h:50
static struct ecam_mapping ecam
Cached mapped ECAM allocation.
Definition: ecam.c:37
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void * regs
MMIO base address.
Definition: ecam.h:52
u32 addr
Definition: sky2.h:8
#define ECAM_LEN(location)
Extract length from ECAM location.
Definition: ecam_io.h:29
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
uint32_t len
Length.
Definition: ena.h:14
#define writew
Definition: w89c840.c:159
#define ECAM_SIZE
Enhanced Configuration Access Mechanism per-device size.
Definition: ecam.h:16
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define ECAM_WHERE(location)
Extract offset from ECAM location.
Definition: ecam_io.h:26
static __always_inline int unsigned int where
Definition: ecam_io.h:46

References addr, assert(), pci_device::busdevfn, ecam, ecam_access(), ECAM_LEN, ECAM_SIZE, ECAM_WHERE, index, len, ecam_mapping::range, rc, ecam_mapping::regs, pci_range::start, value, where, writeb(), writel(), and writew.

◆ PCIAPI_INLINE() [1/7]

static __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

◆ PCIAPI_INLINE() [2/7]

static __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

◆ PCIAPI_INLINE() [3/7]

static __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

◆ PCIAPI_INLINE() [4/7]

static __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

◆ PCIAPI_INLINE() [5/7]

static __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

◆ PCIAPI_INLINE() [6/7]

static __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

◆ PCIAPI_INLINE() [7/7]

static __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

Variable Documentation

◆ where

static __always_inline int unsigned int where

◆ value

__always_inline int unsigned int uint32_t value
Initial value:
{
return ecam_read ( pci, ECAM_LOC ( where, sizeof ( *value ) ), value )
static __always_inline int unsigned int uint8_t * value
Definition: ecam_io.h:47
#define ECAM_LOC(where, len)
Construct ECAM location.
Definition: ecam_io.h:23
static __always_inline int unsigned int where
Definition: ecam_io.h:46
int ecam_read(struct pci_device *pci, unsigned int location, void *value)
Read from PCI configuration space.
Definition: ecam.c:184

Definition at line 47 of file ecam_io.h.

◆ bus_addr

__always_inline void unsigned long bus_addr

Definition at line 135 of file ecam_io.h.

Referenced by bus_to_virt(), efipci_ioremap(), IOAPI_INLINE(), ioremap_pages(), and pcicloud_ioremap().

◆ len

__always_inline void unsigned long size_t len
Initial value:
{
return ioremap ( bus_addr, len )
static __always_inline void unsigned long size_t len
Definition: ecam_io.h:135
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: ecam_io.h:135

Definition at line 135 of file ecam_io.h.