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 150 of file efi_pci.c.

151  {
155  EFI_STATUS efirc;
156  int rc;
157 
158  /* Identify root bridge */
159  if ( ( rc = efipci_root ( pci, &handle, &root ) ) != 0 )
160  goto err_root;
161 
162  /* Read from configuration space */
163  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
164  efipci_address ( pci, location ), 1,
165  value ) ) != 0 ) {
166  rc = -EEFI ( efirc );
167  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
168  "failed: %s\n", PCI_ARGS ( pci ),
169  EFIPCI_OFFSET ( location ), strerror ( rc ) );
170  goto err_read;
171  }
172 
173  err_read:
176  err_root:
177  return rc;
178 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static int efipci_root(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Locate EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:72
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
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:290
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:220
EFI_SYSTEM_TABLE * efi_systab
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:133
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:55

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_image_handle, efi_pci_root_bridge_io_protocol_guid, efi_systab, efipci_address(), EFIPCI_OFFSET, efipci_root(), 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 188 of file efi_pci.c.

189  {
193  EFI_STATUS efirc;
194  int rc;
195 
196  /* Identify root bridge */
197  if ( ( rc = efipci_root ( pci, &handle, &root ) ) != 0 )
198  goto err_root;
199 
200  /* Read from configuration space */
201  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
202  efipci_address ( pci, location ), 1,
203  &value ) ) != 0 ) {
204  rc = -EEFI ( efirc );
205  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
206  "failed: %s\n", PCI_ARGS ( pci ),
207  EFIPCI_OFFSET ( location ), strerror ( rc ) );
208  goto err_write;
209  }
210 
211  err_write:
214  err_root:
215  return rc;
216 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static int efipci_root(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Locate EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:72
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
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:290
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:220
EFI_SYSTEM_TABLE * efi_systab
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:133
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:55

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_image_handle, efi_pci_root_bridge_io_protocol_guid, efi_systab, efipci_address(), EFIPCI_OFFSET, efipci_root(), 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.