iPXE
Macros | Functions
efi_pci.c File Reference

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

#include <stdlib.h>
#include <errno.h>
#include <ipxe/pci.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/Protocol/PciIo.h>
#include <ipxe/efi/Protocol/PciRootBridgeIo.h>

Go to the source code of this file.

Macros

#define EINFO_EEFI_PCI
 
#define EINFO_EEFI_PCI_NOT_PCI
 
#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )
 
#define EINFO_EEFI_PCI_IN_USE
 
#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )
 
#define EEFI_PCI(efirc)
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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. More...
 
static unsigned long efipci_address (struct pci_device *pci, unsigned long location)
 Calculate EFI PCI configuration space address. More...
 
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...
 
 PROVIDE_PCIAPI_INLINE (efi, pci_num_bus)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_dword)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_dword)
 
int efipci_open (EFI_HANDLE device, UINT32 attributes, struct pci_device *pci)
 Open EFI PCI device. More...
 
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device. More...
 
int efipci_info (EFI_HANDLE device, struct pci_device *pci)
 Get EFI PCI device information. More...
 
static int efipci_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int efipci_start (struct efi_device *efidev)
 Attach driver to device. More...
 
static void efipci_stop (struct efi_device *efidev)
 Detach driver from device. More...
 
struct efi_driver efipci_driver __efi_driver (EFI_DRIVER_NORMAL)
 EFI PCI driver. More...
 

Detailed Description

iPXE PCI I/O API for EFI

Definition in file efi_pci.c.

Macro Definition Documentation

◆ EINFO_EEFI_PCI

#define EINFO_EEFI_PCI
Value:
"Could not open PCI I/O protocol" )
#define EINFO_EPLATFORM
Platform-generated base error.
Definition: errno.h:691
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 42 of file efi_pci.c.

◆ EINFO_EEFI_PCI_NOT_PCI

#define EINFO_EEFI_PCI_NOT_PCI
Value:
"Not a PCI device" )
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
#define __einfo_platformify(einfo_base, platform, desc)
Declare platform-generated error.
Definition: errno.h:193
#define EINFO_EEFI_PCI
Definition: efi_pci.c:42

Definition at line 45 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 48 of file efi_pci.c.

◆ EINFO_EEFI_PCI_IN_USE

#define EINFO_EEFI_PCI_IN_USE
Value:
"PCI device already has a driver" )
#define __einfo_platformify(einfo_base, platform, desc)
Declare platform-generated error.
Definition: errno.h:193
#define EFI_ACCESS_DENIED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:135
#define EINFO_EEFI_PCI
Definition: efi_pci.c:42

Definition at line 49 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 52 of file efi_pci.c.

◆ EEFI_PCI

#define EEFI_PCI (   efirc)
Value:
#define EPLATFORM(einfo_base, platform,...)
Generate an error based on an external platform error code.
Definition: errno.h:248
#define EINFO_EEFI_PCI
Definition: efi_pci.c:42
#define EEFI_PCI_IN_USE
Definition: efi_pci.c:52
#define EEFI_PCI_NOT_PCI
Definition: efi_pci.c:48

Definition at line 53 of file efi_pci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efipci_root()

static int efipci_root ( struct pci_device pci,
EFI_HANDLE handle,
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **  root 
)
static

Locate EFI PCI root bridge I/O protocol.

Parameters
pciPCI device
Return values
handleEFI PCI root bridge handle
rootEFI PCI root bridge I/O protocol, or NULL if not found
rcReturn status code

Definition at line 72 of file efi_pci.c.

73  {
75  EFI_HANDLE *handles;
76  UINTN num_handles;
77  union {
78  void *interface;
80  } u;
81  EFI_STATUS efirc;
82  UINTN i;
83  int rc;
84 
85  /* Enumerate all handles */
86  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
88  NULL, &num_handles, &handles ) ) != 0 ) {
89  rc = -EEFI ( efirc );
90  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
91  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
92  goto err_locate;
93  }
94 
95  /* Look for matching root bridge I/O protocol */
96  for ( i = 0 ; i < num_handles ; i++ ) {
97  *handle = handles[i];
98  if ( ( efirc = bs->OpenProtocol ( *handle,
100  &u.interface, efi_image_handle, *handle,
101  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
102  rc = -EEFI ( efirc );
103  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
104  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
105  strerror ( rc ) );
106  continue;
107  }
108  if ( u.root->SegmentNumber == PCI_SEG ( pci->busdevfn ) ) {
109  *root = u.root;
110  bs->FreePool ( handles );
111  return 0;
112  }
113  bs->CloseProtocol ( *handle,
116  }
117  DBGC ( pci, "EFIPCI " PCI_FMT " found no root bridge\n",
118  PCI_ARGS ( pci ) );
119  rc = -ENOENT;
120 
121  bs->FreePool ( handles );
122  err_locate:
123  return rc;
124 }
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:159
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
An object interface.
Definition: interface.h:109
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
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:33
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210
EFI_FILE_PROTOCOL * root
EFI root directory.
Definition: efi_local.c:64
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
union @17 u
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint16_t handle
Handle.
Definition: smbios.h:16
#define PCI_SEG(busdevfn)
Definition: pci.h:255
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:55
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

References EFI_SYSTEM_TABLE::BootServices, pci_device::busdevfn, ByProtocol, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_pci_root_bridge_io_protocol_guid, efi_systab, ENOENT, EFI_BOOT_SERVICES::FreePool, handle, EFI_BOOT_SERVICES::LocateHandleBuffer, NULL, EFI_BOOT_SERVICES::OpenProtocol, PCI_ARGS, PCI_FMT, PCI_SEG, rc, root, strerror(), and u.

Referenced by efipci_read(), and efipci_write().

◆ efipci_address()

static unsigned long efipci_address ( struct pci_device pci,
unsigned long  location 
)
static

Calculate EFI PCI configuration space address.

Parameters
pciPCI device
locationEncoded offset and width
Return values
addressEFI PCI address

Definition at line 133 of file efi_pci.c.

134  {
135 
136  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
137  PCI_SLOT ( pci->busdevfn ),
138  PCI_FUNC ( pci->busdevfn ),
139  EFIPCI_OFFSET ( location ) );
140 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:258
#define PCI_BUS(busdevfn)
Definition: pci.h:256
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
#define PCI_SLOT(busdevfn)
Definition: pci.h:257
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210

References pci_device::busdevfn, EFI_PCI_ADDRESS, EFIPCI_OFFSET, PCI_BUS, PCI_FUNC, and PCI_SLOT.

Referenced by efipci_read(), and efipci_write().

◆ efipci_read()

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:159
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:33
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:159
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:33
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.

◆ PROVIDE_PCIAPI_INLINE() [1/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_num_bus   
)

◆ PROVIDE_PCIAPI_INLINE() [2/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_byte   
)

◆ PROVIDE_PCIAPI_INLINE() [3/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_word   
)

◆ PROVIDE_PCIAPI_INLINE() [4/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_dword   
)

◆ PROVIDE_PCIAPI_INLINE() [5/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_byte   
)

◆ PROVIDE_PCIAPI_INLINE() [6/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_word   
)

◆ PROVIDE_PCIAPI_INLINE() [7/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_dword   
)

◆ efipci_open()

int efipci_open ( EFI_HANDLE  device,
UINT32  attributes,
struct pci_device pci 
)

Open EFI PCI device.

Parameters
deviceEFI device handle
attributesProtocol opening attributes
pciPCI device to fill in
Return values
rcReturn status code

Definition at line 241 of file efi_pci.c.

242  {
244  union {
245  EFI_PCI_IO_PROTOCOL *pci_io;
246  void *interface;
247  } pci_io;
248  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
249  unsigned int busdevfn;
250  EFI_STATUS efirc;
251  int rc;
252 
253  /* See if device is a PCI device */
254  if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
255  &pci_io.interface, efi_image_handle,
256  device, attributes ) ) != 0 ) {
257  rc = -EEFI_PCI ( efirc );
258  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
259  efi_handle_name ( device ), strerror ( rc ) );
260  goto err_open_protocol;
261  }
262 
263  /* Get PCI bus:dev.fn address */
264  if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
265  &pci_bus, &pci_dev,
266  &pci_fn ) ) != 0 ) {
267  rc = -EEFI ( efirc );
268  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
269  efi_handle_name ( device ), strerror ( rc ) );
270  goto err_get_location;
271  }
272  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
273  pci_init ( pci, busdevfn );
274  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
275  PCI_ARGS ( pci ), efi_handle_name ( device ) );
276 
277  /* Try to enable I/O cycles, memory cycles, and bus mastering.
278  * Some platforms will 'helpfully' report errors if these bits
279  * can't be enabled (for example, if the card doesn't actually
280  * support I/O cycles). Work around any such platforms by
281  * enabling bits individually and simply ignoring any errors.
282  */
283  pci_io.pci_io->Attributes ( pci_io.pci_io,
286  pci_io.pci_io->Attributes ( pci_io.pci_io,
289  pci_io.pci_io->Attributes ( pci_io.pci_io,
292 
293  /* Populate PCI device */
294  if ( ( rc = pci_read_config ( pci ) ) != 0 ) {
295  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
296  "configuration: %s\n",
297  PCI_ARGS ( pci ), strerror ( rc ) );
298  goto err_pci_read_config;
299  }
300 
301  return 0;
302 
303  err_pci_read_config:
304  err_get_location:
307  err_open_protocol:
308  return rc;
309 }
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:159
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
#define DBGC(...)
Definition: compiler.h:505
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci.h:259
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:66
An object interface.
Definition: interface.h:109
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:67
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
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:33
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:177
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition: PciIo.h:65
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:119
#define EEFI_PCI(efirc)
Definition: efi_pci.c:53
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
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:313
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGCP, EEFI, EEFI_PCI, efi_handle_name(), efi_image_handle, EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, EFI_PCI_IO_ATTRIBUTE_IO, EFI_PCI_IO_ATTRIBUTE_MEMORY, efi_pci_io_protocol_guid, efi_systab, EfiPciIoAttributeOperationEnable, NULL, EFI_BOOT_SERVICES::OpenProtocol, PCI_ARGS, PCI_BUSDEVFN, PCI_FMT, pci_init(), pci_read_config(), rc, and strerror().

Referenced by efi_bofm_start(), efipci_info(), and efipci_start().

◆ efipci_close()

void efipci_close ( EFI_HANDLE  device)

Close EFI PCI device.

Parameters
deviceEFI device handle

Definition at line 316 of file efi_pci.c.

316  {
318 
321 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, efi_image_handle, efi_pci_io_protocol_guid, and efi_systab.

Referenced by efi_bofm_start(), efipci_info(), efipci_start(), and efipci_stop().

◆ efipci_info()

int efipci_info ( EFI_HANDLE  device,
struct pci_device pci 
)

Get EFI PCI device information.

Parameters
deviceEFI device handle
pciPCI device to fill in
Return values
rcReturn status code

Definition at line 330 of file efi_pci.c.

330  {
331  int rc;
332 
333  /* Open PCI device, if possible */
335  pci ) ) != 0 )
336  return rc;
337 
338  /* Close PCI device */
339  efipci_close ( device );
340 
341  return 0;
342 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A hardware device.
Definition: device.h:73
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct pci_device *pci)
Open EFI PCI device.
Definition: efi_pci.c:241
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:316

References EFI_OPEN_PROTOCOL_GET_PROTOCOL, efipci_close(), efipci_open(), and rc.

Referenced by efi_bofm_supported(), efi_pci_info(), and efipci_supported().

◆ efipci_supported()

static int efipci_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 357 of file efi_pci.c.

357  {
358  struct pci_device pci;
359  int rc;
360 
361  /* Get PCI device information */
362  if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
363  return rc;
364 
365  /* Look for a driver */
366  if ( ( rc = pci_find_driver ( &pci ) ) != 0 ) {
367  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
368  "has no driver\n", PCI_ARGS ( &pci ), pci.vendor,
369  pci.device, pci.class );
370  return rc;
371  }
372  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
373  "\"%s\"\n", PCI_ARGS ( &pci ), pci.vendor, pci.device,
374  pci.class, pci.id->name );
375 
376  return 0;
377 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:254
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:73
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
A PCI device.
Definition: pci.h:187
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
int efipci_info(EFI_HANDLE device, struct pci_device *pci)
Get EFI PCI device information.
Definition: efi_pci.c:330

References pci_device::class, DBGC, pci_device::device, efipci_info(), pci_device::id, pci_device_id::name, PCI_ARGS, pci_find_driver(), PCI_FMT, rc, and pci_device::vendor.

◆ efipci_start()

static int efipci_start ( struct efi_device efidev)
static

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 385 of file efi_pci.c.

385  {
386  EFI_HANDLE device = efidev->device;
387  struct pci_device *pci;
388  int rc;
389 
390  /* Allocate PCI device */
391  pci = zalloc ( sizeof ( *pci ) );
392  if ( ! pci ) {
393  rc = -ENOMEM;
394  goto err_alloc;
395  }
396 
397  /* Open PCI device */
400  pci ) ) != 0 ) {
401  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
402  efi_handle_name ( device ), strerror ( rc ) );
404  goto err_open;
405  }
406 
407  /* Find driver */
408  if ( ( rc = pci_find_driver ( pci ) ) != 0 ) {
409  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
410  PCI_ARGS ( pci ) );
411  goto err_find_driver;
412  }
413 
414  /* Mark PCI device as a child of the EFI device */
415  pci->dev.parent = &efidev->dev;
416  list_add ( &pci->dev.siblings, &efidev->dev.children );
417 
418  /* Probe driver */
419  if ( ( rc = pci_probe ( pci ) ) != 0 ) {
420  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
421  "\"%s\": %s\n", PCI_ARGS ( pci ), pci->id->name,
422  strerror ( rc ) );
423  goto err_probe;
424  }
425  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
426  PCI_ARGS ( pci ), pci->id->name );
427 
428  efidev_set_drvdata ( efidev, pci );
429  return 0;
430 
431  pci_remove ( pci );
432  err_probe:
433  list_del ( &pci->dev.siblings );
434  err_find_driver:
435  efipci_close ( device );
436  err_open:
437  free ( pci );
438  err_alloc:
439  return rc;
440 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:254
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:262
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device * parent
Bus device.
Definition: device.h:85
struct device dev
Generic device.
Definition: pci.h:189
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct pci_device *pci)
Open EFI PCI device.
Definition: efi_pci.c:241
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
A PCI device.
Definition: pci.h:187
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:308
const char * name
Name.
Definition: pci.h:153
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:316
struct list_head children
Devices attached to this device.
Definition: device.h:83
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
struct pci_device_id * id
Driver device ID.
Definition: pci.h:220
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:72
struct device dev
Generic device.
Definition: efi_driver.h:19
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:286
Definition: efi.h:55

References device::children, DBGC, DBGC_EFI_OPENERS, efi_device::dev, pci_device::dev, efi_device::device, efi_handle_name(), EFI_OPEN_PROTOCOL_BY_DRIVER, EFI_OPEN_PROTOCOL_EXCLUSIVE, efi_pci_io_protocol_guid, efidev_set_drvdata(), efipci_close(), efipci_open(), ENOMEM, free, pci_device::id, list_add, list_del, pci_device_id::name, device::parent, PCI_ARGS, pci_find_driver(), PCI_FMT, pci_probe(), pci_remove(), rc, device::siblings, strerror(), and zalloc().

◆ efipci_stop()

static void efipci_stop ( struct efi_device efidev)
static

Detach driver from device.

Parameters
efidevEFI device

Definition at line 447 of file efi_pci.c.

447  {
448  struct pci_device *pci = efidev_get_drvdata ( efidev );
449  EFI_HANDLE device = efidev->device;
450 
451  pci_remove ( pci );
452  list_del ( &pci->dev.siblings );
453  efipci_close ( device );
454  free ( pci );
455 }
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device dev
Generic device.
Definition: pci.h:189
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:73
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
A PCI device.
Definition: pci.h:187
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:308
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:316
Definition: efi.h:55

References pci_device::dev, efi_device::device, efidev_get_drvdata(), efipci_close(), free, list_del, pci_remove(), and device::siblings.

◆ __efi_driver()

struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI PCI driver.