iPXE
Macros | Functions | Variables
efi_pci_api.h File Reference

iPXE PCI I/O API for EFI More...

Go to the source code of this file.

Macros

#define PCIAPI_PREFIX_efi   __efi_
 
#define EFIPCI_WIDTH_BYTE   0
 
#define EFIPCI_WIDTH_WORD   1
 
#define EFIPCI_WIDTH_DWORD   2
 
#define EFIPCI_LOCATION(_offset, _width)   ( (_offset) | ( (_width) << 16 ) )
 
#define EFIPCI_OFFSET(_location)   ( (_location) & 0xffff )
 
#define EFIPCI_WIDTH(_location)   ( (_location) >> 16 )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efipci_read (struct pci_device *pci, unsigned long location, void *value)
 Read from PCI configuration space. More...
 
int efipci_write (struct pci_device *pci, unsigned long location, unsigned long value)
 Write to PCI configuration space. More...
 
static __always_inline int PCIAPI_INLINE (efi, pci_num_bus)(void)
 Determine number of PCI buses within system. More...
 
static __always_inline int PCIAPI_INLINE (efi, pci_read_config_byte)(struct pci_device *pci
 Read byte from PCI configuration space via EFI. More...
 
return efipci_read (pci, EFIPCI_LOCATION(where, EFIPCI_WIDTH_BYTE), value)
 
static __always_inline int PCIAPI_INLINE (efi, pci_read_config_word)(struct pci_device *pci
 Read word from PCI configuration space via EFI. More...
 
return efipci_read (pci, EFIPCI_LOCATION(where, EFIPCI_WIDTH_WORD), value)
 
static __always_inline int PCIAPI_INLINE (efi, pci_read_config_dword)(struct pci_device *pci
 Read dword from PCI configuration space via EFI. More...
 
return efipci_read (pci, EFIPCI_LOCATION(where, EFIPCI_WIDTH_DWORD), value)
 
static __always_inline int PCIAPI_INLINE (efi, pci_write_config_byte)(struct pci_device *pci
 Write byte to PCI configuration space via EFI. More...
 
static __always_inline int PCIAPI_INLINE (efi, pci_write_config_word)(struct pci_device *pci
 Write word to PCI configuration space via EFI. More...
 
static __always_inline int PCIAPI_INLINE (efi, pci_write_config_dword)(struct pci_device *pci
 Write dword to PCI configuration space via EFI. More...
 

Variables

static __always_inline int unsigned int where
 
static __always_inline int unsigned int uint8_tvalue
 

Detailed Description

iPXE PCI I/O API for EFI

Definition in file efi_pci_api.h.

Macro Definition Documentation

◆ PCIAPI_PREFIX_efi

#define PCIAPI_PREFIX_efi   __efi_

Definition at line 15 of file efi_pci_api.h.

◆ EFIPCI_WIDTH_BYTE

#define EFIPCI_WIDTH_BYTE   0

Definition at line 19 of file efi_pci_api.h.

◆ EFIPCI_WIDTH_WORD

#define EFIPCI_WIDTH_WORD   1

Definition at line 20 of file efi_pci_api.h.

◆ EFIPCI_WIDTH_DWORD

#define EFIPCI_WIDTH_DWORD   2

Definition at line 21 of file efi_pci_api.h.

◆ EFIPCI_LOCATION

#define EFIPCI_LOCATION (   _offset,
  _width 
)    ( (_offset) | ( (_width) << 16 ) )

Definition at line 23 of file efi_pci_api.h.

◆ EFIPCI_OFFSET

#define EFIPCI_OFFSET (   _location)    ( (_location) & 0xffff )

Definition at line 25 of file efi_pci_api.h.

◆ EFIPCI_WIDTH

#define EFIPCI_WIDTH (   _location)    ( (_location) >> 16 )

Definition at line 26 of file efi_pci_api.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efipci_read() [1/4]

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

Read from PCI configuration space.

Parameters
pciPCI device
locationEncoded offset and width
Return values
valueValue
rcReturn status code

Definition at line 228 of file efi_pci.c.

229  {
232  EFI_STATUS efirc;
233  int rc;
234 
235  /* Open root bridge */
236  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
237  goto err_root;
238 
239  /* Read from configuration space */
240  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
241  efipci_address ( pci, location ), 1,
242  value ) ) != 0 ) {
243  rc = -EEFI ( efirc );
244  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
245  "failed: %s\n", PCI_ARGS ( pci ),
246  EFIPCI_OFFSET ( location ), strerror ( rc ) );
247  goto err_read;
248  }
249 
250  err_read:
252  err_root:
253  return rc;
254 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:196
struct stp_switch root
Root switch.
Definition: stp.h:26
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:137
#define DBGC(...)
Definition: compiler.h:505
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:50

References DBGC, EEFI, efipci_address(), EFIPCI_OFFSET, efipci_root_close(), efipci_root_open(), EFIPCI_WIDTH, handle, PCI_ARGS, PCI_FMT, rc, root, strerror(), and value.

◆ efipci_write()

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

Write to PCI configuration space.

Parameters
pciPCI device
locationEncoded offset and width
valueValue
Return values
rcReturn status code

Definition at line 264 of file efi_pci.c.

265  {
268  EFI_STATUS efirc;
269  int rc;
270 
271  /* Open root bridge */
272  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
273  goto err_root;
274 
275  /* Read from configuration space */
276  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
277  efipci_address ( pci, location ), 1,
278  &value ) ) != 0 ) {
279  rc = -EEFI ( efirc );
280  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
281  "failed: %s\n", PCI_ARGS ( pci ),
282  EFIPCI_OFFSET ( location ), strerror ( rc ) );
283  goto err_write;
284  }
285 
286  err_write:
288  err_root:
289  return rc;
290 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:196
struct stp_switch root
Root switch.
Definition: stp.h:26
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:137
#define DBGC(...)
Definition: compiler.h:505
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:50

References DBGC, EEFI, efipci_address(), EFIPCI_OFFSET, efipci_root_close(), efipci_root_open(), EFIPCI_WIDTH, handle, PCI_ARGS, PCI_FMT, rc, root, strerror(), and value.

◆ PCIAPI_INLINE() [1/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_num_bus   
)
inlinestatic

Determine number of PCI buses within system.

Return values
num_busNumber of buses

Definition at line 41 of file efi_pci_api.h.

41  {
42  /* EFI does not want us to scan the PCI bus ourselves */
43  return 0;
44 }

◆ PCIAPI_INLINE() [2/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_read_config_byte   
)
inlinestatic

Read byte from PCI configuration space via EFI.

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

◆ efipci_read() [2/4]

return efipci_read ( pci  ,
EFIPCI_LOCATION(where, EFIPCI_WIDTH_BYTE ,
value   
)

◆ PCIAPI_INLINE() [3/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_read_config_word   
)
inlinestatic

Read word from PCI configuration space via EFI.

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

◆ efipci_read() [3/4]

return efipci_read ( pci  ,
EFIPCI_LOCATION(where, EFIPCI_WIDTH_WORD ,
value   
)

◆ PCIAPI_INLINE() [4/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_read_config_dword   
)
inlinestatic

Read dword from PCI configuration space via EFI.

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

◆ efipci_read() [4/4]

return efipci_read ( pci  ,
EFIPCI_LOCATION(where, EFIPCI_WIDTH_DWORD ,
value   
)

◆ PCIAPI_INLINE() [5/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_write_config_byte   
)
inlinestatic

Write byte to PCI configuration space via EFI.

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 ( efi  ,
pci_write_config_word   
)
inlinestatic

Write word to PCI configuration space via EFI.

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

◆ PCIAPI_INLINE() [7/7]

static __always_inline int PCIAPI_INLINE ( efi  ,
pci_write_config_dword   
)
inlinestatic

Write dword to PCI configuration space via EFI.

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

Variable Documentation

◆ where

static __always_inline int unsigned int where

Definition at line 56 of file efi_pci_api.h.

Referenced by pcidirect_prepare().

◆ value

__always_inline int unsigned int uint32_t value
Initial value:
{
*value = 0xff
static __always_inline int unsigned int uint8_t * value
Definition: efi_pci_api.h:57

Definition at line 57 of file efi_pci_api.h.