iPXE
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)
#define EFIPCI_OFFSET(_location)
#define EFIPCI_WIDTH(_location)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int efipci_read (struct pci_device *pci, unsigned long location, void *value)
 Read from PCI configuration space.
int efipci_write (struct pci_device *pci, unsigned long location, unsigned long value)
 Write to PCI configuration space.
static __always_inline int PCIAPI_INLINE (efi, pci_can_probe)(struct pci_device *pci __unused)
 Check if PCI bus probing is allowed.
static __always_inline int PCIAPI_INLINE (efi, pci_read_config_byte)(struct pci_device *pci
 Read byte from PCI configuration space via EFI.
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.
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.
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.
static __always_inline int PCIAPI_INLINE (efi, pci_write_config_word)(struct pci_device *pci
 Write word to PCI configuration space via EFI.
static __always_inline int PCIAPI_INLINE (efi, pci_write_config_dword)(struct pci_device *pci
 Write dword to PCI configuration space via EFI.

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 16 of file efi_pci_api.h.

◆ EFIPCI_WIDTH_BYTE

#define EFIPCI_WIDTH_BYTE   0

Definition at line 20 of file efi_pci_api.h.

Referenced by efipci_read(), and PCIAPI_INLINE().

◆ EFIPCI_WIDTH_WORD

#define EFIPCI_WIDTH_WORD   1

Definition at line 21 of file efi_pci_api.h.

Referenced by efipci_read(), and PCIAPI_INLINE().

◆ EFIPCI_WIDTH_DWORD

#define EFIPCI_WIDTH_DWORD   2

Definition at line 22 of file efi_pci_api.h.

Referenced by efipci_read(), and PCIAPI_INLINE().

◆ EFIPCI_LOCATION

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

Definition at line 24 of file efi_pci_api.h.

24#define EFIPCI_LOCATION( _offset, _width ) \
25 ( (_offset) | ( (_width) << 16 ) )

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

◆ EFIPCI_OFFSET

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

Definition at line 26 of file efi_pci_api.h.

Referenced by efipci_address(), efipci_read(), and efipci_write().

◆ EFIPCI_WIDTH

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

Definition at line 27 of file efi_pci_api.h.

Referenced by efipci_read(), and efipci_write().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efipci_read() [1/4]

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

Read from PCI configuration space.

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

Definition at line 307 of file efi_pci.c.

308 {
311 EFI_STATUS efirc;
312 int rc;
313
314 /* Open root bridge */
315 if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
316 return rc;
317
318 /* Read from configuration space */
319 if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
320 efipci_address ( pci, location ), 1,
321 value ) ) != 0 ) {
322 rc = -EEFI ( efirc );
323 DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
324 "failed: %s\n", PCI_ARGS ( pci ),
325 EFIPCI_OFFSET ( location ), strerror ( rc ) );
326 return rc;
327 }
328
329 return 0;
330}
struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition efi_pci.c:290
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 for ephemeral use.
Definition efi_pci.c:256
#define EFIPCI_OFFSET(_location)
Definition efi_pci_api.h:26
#define EFIPCI_WIDTH(_location)
Definition efi_pci_api.h:27
#define DBGC(...)
Definition compiler.h:505
#define EFI_HANDLE
Definition efi.h:53
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
uint16_t handle
Handle.
Definition smbios.h:5
#define PCI_FMT
PCI device debug message format.
Definition pci.h:312
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition pci.h:315
struct stp_switch root
Root switch.
Definition stp.h:15
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

References DBGC, EEFI, EFI_HANDLE, efipci_address(), EFIPCI_OFFSET, 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 )
extern

Write to PCI configuration space.

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

Definition at line 340 of file efi_pci.c.

341 {
344 EFI_STATUS efirc;
345 int rc;
346
347 /* Open root bridge */
348 if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
349 return rc;
350
351 /* Read from configuration space */
352 if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
353 efipci_address ( pci, location ), 1,
354 &value ) ) != 0 ) {
355 rc = -EEFI ( efirc );
356 DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
357 "failed: %s\n", PCI_ARGS ( pci ),
358 EFIPCI_OFFSET ( location ), strerror ( rc ) );
359 return rc;
360 }
361
362 return 0;
363}

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

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

◆ PCIAPI_INLINE() [1/7]

__always_inline int PCIAPI_INLINE ( efi ,
pci_can_probe  )
inlinestatic

Check if PCI bus probing is allowed.

Parameters
pciPCI device
Return values
okBus probing is allowed

Definition at line 43 of file efi_pci_api.h.

43 {
44 return 0;
45}

References __unused, and pci_can_probe().

◆ PCIAPI_INLINE() [2/7]

__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

References pci_read_config_byte().

◆ efipci_read() [2/4]

◆ PCIAPI_INLINE() [3/7]

__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

References pci_read_config_word(), value, and where.

◆ efipci_read() [3/4]

◆ PCIAPI_INLINE() [4/7]

__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

References pci_read_config_dword(), value, and where.

◆ efipci_read() [4/4]

◆ PCIAPI_INLINE() [5/7]

__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

References EFIPCI_LOCATION, EFIPCI_WIDTH_BYTE, efipci_write(), pci_write_config_byte(), value, and where.

◆ PCIAPI_INLINE() [6/7]

__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

References EFIPCI_LOCATION, EFIPCI_WIDTH_WORD, efipci_write(), pci_write_config_word(), value, and where.

◆ PCIAPI_INLINE() [7/7]

__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

References EFIPCI_LOCATION, EFIPCI_WIDTH_DWORD, efipci_write(), pci_write_config_dword(), value, and where.

Variable Documentation

◆ where

__always_inline int unsigned int where

Definition at line 57 of file efi_pci_api.h.

◆ value

__always_inline int unsigned int uint32_t value
Initial value:
{
*value = 0xff

Definition at line 58 of file efi_pci_api.h.