iPXE
Macros | Functions | Variables
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/acpi.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_discover_one (struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range)
 Find closest bus:dev.fn address range within a root bridge. More...
 
static int efipci_discover_any (struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
 Find closest bus:dev.fn address range within any root bridge. More...
 
static void efipci_discover (uint32_t busdevfn, struct pci_range *range)
 Find next PCI bus:dev.fn address range in system. More...
 
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. More...
 
static void efipci_root_close (EFI_HANDLE handle)
 Close 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...
 
void * efipci_ioremap (struct pci_device *pci, unsigned long bus_addr, size_t len)
 Map PCI bus address as an I/O address. More...
 
 PROVIDE_PCIAPI_INLINE (efi, pci_can_probe)
 
 PROVIDE_PCIAPI (efi, pci_discover, efipci_discover)
 
 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)
 
 PROVIDE_PCIAPI (efi, pci_ioremap, efipci_ioremap)
 
static int efipci_dma_map (struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
 Map buffer for DMA. More...
 
static void efipci_dma_unmap (struct dma_device *dma, struct dma_mapping *map)
 Unmap buffer. More...
 
static void * efipci_dma_alloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
 Allocate and map DMA-coherent buffer. More...
 
static void efipci_dma_free (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer. More...
 
static userptr_t efipci_dma_umalloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
 Allocate and map DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_ufree (struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
 Unmap and free DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask. More...
 
int efipci_open (EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
 Open EFI PCI device. More...
 
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device. More...
 
int efipci_info (EFI_HANDLE device, struct efi_pci_device *efipci)
 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...
 

Variables

static struct dma_operations efipci_dma_operations
 EFI PCI DMA operations. 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 43 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:117
#define __einfo_platformify(einfo_base, platform, desc)
Declare platform-generated error.
Definition: errno.h:193
#define EINFO_EEFI_PCI
Definition: efi_pci.c:43

Definition at line 46 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 49 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:129
#define EINFO_EEFI_PCI
Definition: efi_pci.c:43

Definition at line 50 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 53 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:43
#define EEFI_PCI_IN_USE
Definition: efi_pci.c:53
#define EEFI_PCI_NOT_PCI
Definition: efi_pci.c:49

Definition at line 54 of file efi_pci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efipci_discover_one()

static int efipci_discover_one ( struct pci_device pci,
EFI_HANDLE  handle,
struct pci_range range 
)
static

Find closest bus:dev.fn address range within a root bridge.

Parameters
pciStarting PCI device
handleEFI PCI root bridge handle
rangePCI bus:dev.fn address range to fill in
Return values
rcReturn status code

Definition at line 73 of file efi_pci.c.

74  {
76  union {
77  void *interface;
79  } root;
80  union {
81  union acpi_resource *res;
82  void *raw;
83  } acpi;
84  uint32_t best = 0;
88  unsigned int tag;
89  EFI_STATUS efirc;
90  int rc;
91 
92  /* Return empty range on error */
93  range->start = 0;
94  range->count = 0;
95 
96  /* Open root bridge I/O protocol */
97  if ( ( efirc = bs->OpenProtocol ( handle,
99  &root.interface, efi_image_handle, handle,
100  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
101  rc = -EEFI ( efirc );
102  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
103  PCI_ARGS ( pci ), efi_handle_name ( handle ),
104  strerror ( rc ) );
105  goto err_open;
106  }
107 
108  /* Get ACPI resource descriptors */
109  if ( ( efirc = root.root->Configuration ( root.root,
110  &acpi.raw ) ) != 0 ) {
111  rc = -EEFI ( efirc );
112  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
113  "%s: %s\n", PCI_ARGS ( pci ),
114  efi_handle_name ( handle ), strerror ( rc ) );
115  goto err_config;
116  }
117 
118  /* Parse resource descriptors */
119  for ( ; ( ( tag = acpi_resource_tag ( acpi.res ) ) !=
121  acpi.res = acpi_resource_next ( acpi.res ) ) {
122 
123  /* Ignore anything other than a bus number range descriptor */
125  continue;
126  if ( acpi.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
127  continue;
128 
129  /* Get range for this descriptor */
130  start = PCI_BUSDEVFN ( root.root->SegmentNumber,
131  le64_to_cpu ( acpi.res->qword.min ),
132  0, 0 );
133  count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ),
134  0, 0 );
135  DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via "
136  "%s\n", PCI_ARGS ( pci ), root.root->SegmentNumber,
137  PCI_BUS ( start ), PCI_BUS ( start + count - 1 ),
138  efi_handle_name ( handle ) );
139 
140  /* Check for a matching or new closest range */
141  index = ( pci->busdevfn - start );
142  if ( ( index < count ) || ( index > best ) ) {
143  range->start = start;
144  range->count = count;
145  best = index;
146  }
147 
148  /* Stop if this range contains the target bus:dev.fn address */
149  if ( index < count )
150  break;
151  }
152 
153  /* If no range descriptors were seen, assume that the root
154  * bridge has a single bus.
155  */
156  if ( ! range->count ) {
157  range->start = PCI_BUSDEVFN ( root.root->SegmentNumber,
158  0, 0, 0 );
159  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
160  }
161 
162  /* Success */
163  rc = 0;
164 
165  err_config:
168  err_open:
169  return rc;
170 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
#define PCI_BUS(busdevfn)
Definition: pci.h:279
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:171
struct stp_switch root
Root switch.
Definition: stp.h:26
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:152
uint32_t start
Starting offset.
Definition: netvsc.h:12
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition: acpi.h:104
An object interface.
Definition: interface.h:124
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
uint16_t count
Number of entries.
Definition: ena.h:22
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1354
static __always_inline void struct pci_range * range
Definition: pcidirect.h:46
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:810
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
Definition: acpi.h:82
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
unsigned int uint32_t
Definition: stdint.h:12
An ACPI resource descriptor.
Definition: acpi.h:85
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
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:233
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:288
__be32 raw[7]
Definition: CIB_PRM.h:28
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1999
#define le64_to_cpu(value)
Definition: byteswap.h:114
uint64_t tag
Identity tag.
Definition: edd.h:30
uint16_t handle
Handle.
Definition: smbios.h:16

References acpi, ACPI_ADDRESS_TYPE_BUS, ACPI_END_RESOURCE, ACPI_QWORD_ADDRESS_SPACE_RESOURCE, acpi_resource_next(), acpi_resource_tag(), EFI_SYSTEM_TABLE::BootServices, pci_device::busdevfn, EFI_BOOT_SERVICES::CloseProtocol, count, pci_range::count, DBGC, DBGC2, EEFI, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_pci_root_bridge_io_protocol_guid, efi_systab, handle, index, le64_to_cpu, EFI_BOOT_SERVICES::OpenProtocol, PCI_ARGS, PCI_BUS, PCI_BUSDEVFN, PCI_FMT, range, raw, rc, root, start, pci_range::start, strerror(), and tag.

Referenced by efipci_discover_any().

◆ efipci_discover_any()

static int efipci_discover_any ( struct pci_device pci,
struct pci_range range,
EFI_HANDLE handle 
)
static

Find closest bus:dev.fn address range within any root bridge.

Parameters
pciStarting PCI device
rangePCI bus:dev.fn address range to fill in
handlePCI root bridge I/O handle to fill in
Return values
rcReturn status code

Definition at line 180 of file efi_pci.c.

182  {
184  uint32_t best = 0;
185  uint32_t index;
186  struct pci_range tmp;
187  EFI_HANDLE *handles;
188  UINTN num_handles;
189  UINTN i;
190  EFI_STATUS efirc;
191  int rc;
192 
193  /* Return an empty range and no handle on error */
194  range->start = 0;
195  range->count = 0;
196  *handle = NULL;
197 
198  /* Enumerate all root bridge I/O protocol handles */
199  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
201  NULL, &num_handles, &handles ) ) != 0 ) {
202  rc = -EEFI ( efirc );
203  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
204  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
205  goto err_locate;
206  }
207 
208  /* Iterate over all root bridge I/O protocols */
209  for ( i = 0 ; i < num_handles ; i++ ) {
210 
211  /* Get matching or closest range for this root bridge */
212  if ( ( rc = efipci_discover_one ( pci, handles[i],
213  &tmp ) ) != 0 )
214  continue;
215 
216  /* Check for a matching or new closest range */
217  index = ( pci->busdevfn - tmp.start );
218  if ( ( index < tmp.count ) || ( index > best ) ) {
219  range->start = tmp.start;
220  range->count = tmp.count;
221  best = index;
222  }
223 
224  /* Stop if this range contains the target bus:dev.fn address */
225  if ( index < tmp.count ) {
226  *handle = handles[i];
227  break;
228  }
229  }
230 
231  /* Check for a range containing the target bus:dev.fn address */
232  if ( ! *handle ) {
233  rc = -ENOENT;
234  goto err_range;
235  }
236 
237  /* Success */
238  rc = 0;
239 
240  err_range:
241  bs->FreePool ( handles );
242  err_locate:
243  return rc;
244 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
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:171
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned long tmp
Definition: linux_pci.h:63
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
static __always_inline void struct pci_range * range
Definition: pcidirect.h:46
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
UINT64 UINTN
Unsigned value of native width.
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:288
static int efipci_discover_one(struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range)
Find closest bus:dev.fn address range within a root bridge.
Definition: efi_pci.c:73
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1530
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:2007

References EFI_SYSTEM_TABLE::BootServices, pci_device::busdevfn, ByProtocol, pci_range::count, DBGC, EEFI, efi_pci_root_bridge_io_protocol_guid, efi_systab, efipci_discover_one(), ENOENT, EFI_BOOT_SERVICES::FreePool, handle, index, EFI_BOOT_SERVICES::LocateHandleBuffer, NULL, PCI_ARGS, PCI_FMT, range, rc, pci_range::start, strerror(), and tmp.

Referenced by efipci_discover(), and efipci_root_open().

◆ efipci_discover()

static void efipci_discover ( uint32_t  busdevfn,
struct pci_range range 
)
static

Find next PCI bus:dev.fn address range in system.

Parameters
busdevfnStarting PCI bus:dev.fn address
rangePCI bus:dev.fn address range to fill in

Definition at line 252 of file efi_pci.c.

252  {
253  struct pci_device pci;
255 
256  /* Find range */
257  memset ( &pci, 0, sizeof ( pci ) );
258  pci_init ( &pci, busdevfn );
259  efipci_discover_any ( &pci, range, &handle );
260 }
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
static int efipci_discover_any(struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
Find closest bus:dev.fn address range within any root bridge.
Definition: efi_pci.c:180
static __always_inline void struct pci_range * range
Definition: pcidirect.h:46
A PCI device.
Definition: pci.h:206
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:334
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59
void * memset(void *dest, int character, size_t len) __nonnull

References busdevfn, efipci_discover_any(), handle, memset(), pci_init(), and range.

◆ efipci_root_open()

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

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

271  {
273  struct pci_range tmp;
274  union {
275  void *interface;
277  } u;
278  EFI_STATUS efirc;
279  int rc;
280 
281  /* Find matching root bridge I/O protocol handle */
282  if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 )
283  return rc;
284 
285  /* (Re)open PCI root bridge I/O protocol */
286  if ( ( efirc = bs->OpenProtocol ( *handle,
288  &u.interface, efi_image_handle, *handle,
289  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
290  rc = -EEFI ( efirc );
291  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
292  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
293  strerror ( rc ) );
294  return rc;
295  }
296 
297  /* Return opened protocol */
298  *root = u.root;
299 
300  return 0;
301 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
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:171
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
unsigned long tmp
Definition: linux_pci.h:63
static int efipci_discover_any(struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
Find closest bus:dev.fn address range within any root bridge.
Definition: efi_pci.c:180
An object interface.
Definition: interface.h:124
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1354
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:810
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:288
union @17 u
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1999
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_pci_root_bridge_io_protocol_guid, efi_systab, efipci_discover_any(), handle, EFI_BOOT_SERVICES::OpenProtocol, PCI_ARGS, PCI_FMT, rc, root, strerror(), tmp, and u.

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

◆ efipci_root_close()

static void efipci_root_close ( EFI_HANDLE  handle)
static

Close EFI PCI root bridge I/O protocol.

Parameters
handleEFI PCI root bridge handle

Definition at line 308 of file efi_pci.c.

308  {
310 
311  /* Close protocol */
314 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
EFI Boot Services Table.
Definition: UefiSpec.h:1930
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:288
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, efi_image_handle, efi_pci_root_bridge_io_protocol_guid, efi_systab, and handle.

Referenced by efipci_ioremap(), 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 323 of file efi_pci.c.

324  {
325 
326  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
327  PCI_SLOT ( pci->busdevfn ),
328  PCI_FUNC ( pci->busdevfn ),
329  EFIPCI_OFFSET ( location ) );
330 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:281
#define PCI_BUS(busdevfn)
Definition: pci.h:279
#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:280
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233

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 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  goto err_root;
350 
351  /* Read from configuration space */
352  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
353  efipci_address ( pci, location ), 1,
354  value ) ) != 0 ) {
355  rc = -EEFI ( efirc );
356  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
357  "failed: %s\n", PCI_ARGS ( pci ),
358  EFIPCI_OFFSET ( location ), strerror ( rc ) );
359  goto err_read;
360  }
361 
362  err_read:
364  err_root:
365  return rc;
366 }
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:171
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:308
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:270
#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:307
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:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:323
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59

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

377  {
380  EFI_STATUS efirc;
381  int rc;
382 
383  /* Open root bridge */
384  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
385  goto err_root;
386 
387  /* Read from configuration space */
388  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
389  efipci_address ( pci, location ), 1,
390  &value ) ) != 0 ) {
391  rc = -EEFI ( efirc );
392  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
393  "failed: %s\n", PCI_ARGS ( pci ),
394  EFIPCI_OFFSET ( location ), strerror ( rc ) );
395  goto err_write;
396  }
397 
398  err_write:
400  err_root:
401  return rc;
402 }
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:171
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:308
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:270
#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:307
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:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:323
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59

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_ioremap()

void* efipci_ioremap ( struct pci_device pci,
unsigned long  bus_addr,
size_t  len 
)

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

Definition at line 411 of file efi_pci.c.

412  {
413  union {
414  union acpi_resource *res;
415  void *raw;
416  } u;
419  unsigned int tag;
421  uint64_t start;
422  uint64_t end;
423  EFI_STATUS efirc;
424  int rc;
425 
426  /* Open root bridge */
427  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
428  goto err_root;
429 
430  /* Get ACPI resource descriptors */
431  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
432  rc = -EEFI ( efirc );
433  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
434  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
435  goto err_config;
436  }
437 
438  /* Parse resource descriptors */
439  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
440  u.res = acpi_resource_next ( u.res ) ) {
441 
442  /* Ignore anything other than a memory range descriptor */
444  continue;
445  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
446  continue;
447 
448  /* Ignore descriptors that do not cover this memory range */
449  offset = le64_to_cpu ( u.res->qword.offset );
450  start = ( offset + le64_to_cpu ( u.res->qword.min ) );
451  end = ( start + le64_to_cpu ( u.res->qword.len ) );
452  DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
453  "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
454  ( start - offset ), ( end - offset ) );
455  if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
456  continue;
457 
458  /* Use this address space descriptor */
459  DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
460  PCI_ARGS ( pci ), bus_addr, len );
461  bus_addr -= offset;
462  DBGC2 ( pci, "%08lx\n", bus_addr );
463  break;
464  }
465  if ( tag == ACPI_END_RESOURCE ) {
466  DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
467  "root bridge address space\n",
468  PCI_ARGS ( pci ), bus_addr, len );
469  }
470 
471  err_config:
473  err_root:
474  return ioremap ( bus_addr, len );
475 }
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:171
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:308
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:270
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
static __always_inline void unsigned long bus_addr
Definition: pcibios.h:154
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:152
uint32_t start
Starting offset.
Definition: netvsc.h:12
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition: acpi.h:104
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:307
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
An ACPI resource descriptor.
Definition: acpi.h:85
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define DBGC2(...)
Definition: compiler.h:522
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition: acpi.h:79
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
union @17 u
uint32_t end
Ending offset.
Definition: netvsc.h:18
__be32 raw[7]
Definition: CIB_PRM.h:28
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
#define le64_to_cpu(value)
Definition: byteswap.h:114
uint64_t tag
Identity tag.
Definition: edd.h:30
uint16_t handle
Handle.
Definition: smbios.h:16
uint32_t len
Length.
Definition: ena.h:14
Definition: efi.h:59

References ACPI_ADDRESS_TYPE_MEM, ACPI_END_RESOURCE, ACPI_QWORD_ADDRESS_SPACE_RESOURCE, acpi_resource_next(), acpi_resource_tag(), bus_addr, DBGC, DBGC2, EEFI, efipci_root_close(), efipci_root_open(), end, handle, ioremap(), le64_to_cpu, len, offset, PCI_ARGS, PCI_FMT, raw, rc, root, start, strerror(), tag, and u.

◆ PROVIDE_PCIAPI_INLINE() [1/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_can_probe   
)

◆ PROVIDE_PCIAPI() [1/2]

PROVIDE_PCIAPI ( efi  ,
pci_discover  ,
efipci_discover   
)

◆ 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   
)

◆ PROVIDE_PCIAPI() [2/2]

PROVIDE_PCIAPI ( efi  ,
pci_ioremap  ,
efipci_ioremap   
)

◆ efipci_dma_map()

static int efipci_dma_map ( struct dma_device dma,
struct dma_mapping map,
physaddr_t  addr,
size_t  len,
int  flags 
)
static

Map buffer for DMA.

Parameters
dmaDMA device
mapDMA mapping to fill in
addrBuffer address
lenLength of buffer
flagsMapping flags
Return values
rcReturn status code

Definition at line 504 of file efi_pci.c.

505  {
506  struct efi_pci_device *efipci =
507  container_of ( dma, struct efi_pci_device, pci.dma );
508  struct pci_device *pci = &efipci->pci;
509  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
512  UINTN count;
513  VOID *mapping;
514  EFI_STATUS efirc;
515  int rc;
516 
517  /* Sanity check */
518  assert ( map->dma == NULL );
519  assert ( map->offset == 0 );
520  assert ( map->token == NULL );
521 
522  /* Determine operation */
523  switch ( flags ) {
524  case DMA_TX:
526  break;
527  case DMA_RX:
529  break;
530  default:
532  break;
533  }
534 
535  /* Map buffer (if non-zero length) */
536  count = len;
537  if ( len ) {
538  if ( ( efirc = pci_io->Map ( pci_io, op, phys_to_virt ( addr ),
539  &count, &bus, &mapping ) ) != 0 ) {
540  rc = -EEFI ( efirc );
541  DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %08lx+%zx: "
542  "%s\n", PCI_ARGS ( pci ), addr, len,
543  strerror ( rc ) );
544  goto err_map;
545  }
546  } else {
547  bus = addr;
548  mapping = NULL;
549  }
550 
551  /* Check that full length was mapped. The UEFI specification
552  * allows for multiple mappings to be required, but even the
553  * EDK2 PCI device drivers will fail if a platform ever
554  * requires this.
555  */
556  if ( count != len ) {
557  DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
558  "%08lx+%zx\n", PCI_ARGS ( pci ), addr, len );
559  rc = -ENOTSUP;
560  goto err_len;
561  }
562 
563  /* Populate mapping */
564  map->dma = dma;
565  map->offset = ( bus - addr );
566  map->token = mapping;
567 
568  /* Increment mapping count (for debugging) */
569  if ( DBG_LOG )
570  dma->mapped++;
571 
572  return 0;
573 
574  err_len:
575  pci_io->Unmap ( pci_io, mapping );
576  err_map:
577  return rc;
578 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
A read operation from system memory by a bus master.
Definition: PciIo.h:83
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:525
#define DBGC(...)
Definition: compiler.h:505
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:52
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h:373
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:132
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:526
uint8_t flags
Flags.
Definition: ena.h:18
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
physaddr_t offset
Address offset.
Definition: dma.h:39
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
A PCI device.
Definition: pci.h:206
UINT64 UINTN
Unsigned value of native width.
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:92
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define VOID
Undeclared type.
Definition: Base.h:271
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:79
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:135
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
u32 addr
Definition: sky2.h:8
void * token
Platform mapping token.
Definition: dma.h:43
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
A write operation from system memory by a bus master.
Definition: PciIo.h:87
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t bus
Bus.
Definition: edd.h:14

References addr, assert(), bus, container_of, count, DBG_LOG, DBGC, dma_mapping::dma, pci_device::dma, dma(), DMA_RX, DMA_TX, EEFI, EfiPciIoOperationBusMasterCommonBuffer, EfiPciIoOperationBusMasterRead, EfiPciIoOperationBusMasterWrite, ENOTSUP, flags, efi_pci_device::io, len, map, _EFI_PCI_IO_PROTOCOL::Map, NULL, dma_mapping::offset, op, efi_pci_device::pci, PCI_ARGS, PCI_FMT, phys_to_virt(), rc, strerror(), dma_mapping::token, _EFI_PCI_IO_PROTOCOL::Unmap, and VOID.

Referenced by efipci_dma_alloc().

◆ efipci_dma_unmap()

static void efipci_dma_unmap ( struct dma_device dma,
struct dma_mapping map 
)
static

Unmap buffer.

Parameters
dmaDMA device
mapDMA mapping

Definition at line 586 of file efi_pci.c.

587  {
588  struct efi_pci_device *efipci =
589  container_of ( dma, struct efi_pci_device, pci.dma );
590  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
591 
592  /* Unmap buffer (if non-zero length) */
593  if ( map->token )
594  pci_io->Unmap ( pci_io, map->token );
595 
596  /* Clear mapping */
597  map->dma = NULL;
598  map->offset = 0;
599  map->token = NULL;
600 
601  /* Decrement mapping count (for debugging) */
602  if ( DBG_LOG )
603  dma->mapped--;
604 }
struct dma_device dma
DMA device.
Definition: pci.h:210
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:526
physaddr_t offset
Address offset.
Definition: dma.h:39
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
void * token
Platform mapping token.
Definition: dma.h:43
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References container_of, DBG_LOG, dma_mapping::dma, pci_device::dma, dma(), efi_pci_device::io, map, NULL, dma_mapping::offset, efi_pci_device::pci, dma_mapping::token, and _EFI_PCI_IO_PROTOCOL::Unmap.

Referenced by efipci_dma_alloc(), and efipci_dma_free().

◆ efipci_dma_alloc()

static void* efipci_dma_alloc ( struct dma_device dma,
struct dma_mapping map,
size_t  len,
size_t align  __unused 
)
static

Allocate and map DMA-coherent buffer.

Parameters
dmaDMA device
mapDMA mapping to fill in
lenLength of buffer
alignPhysical alignment
Return values
addrBuffer address, or NULL on error

Definition at line 615 of file efi_pci.c.

617  {
618  struct efi_pci_device *efipci =
619  container_of ( dma, struct efi_pci_device, pci.dma );
620  struct pci_device *pci = &efipci->pci;
621  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
622  unsigned int pages;
623  VOID *addr;
624  EFI_STATUS efirc;
625  int rc;
626 
627  /* Calculate number of pages */
628  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
629 
630  /* Allocate (page-aligned) buffer */
631  if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
632  EfiBootServicesData, pages,
633  &addr, 0 ) ) != 0 ) {
634  rc = -EEFI ( efirc );
635  DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
636  "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
637  goto err_alloc;
638  }
639 
640  /* Clear buffer */
641  memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
642 
643  /* Map buffer */
644  if ( ( rc = efipci_dma_map ( dma, map, virt_to_phys ( addr ),
645  ( pages * EFI_PAGE_SIZE ),
646  DMA_BI ) ) != 0 )
647  goto err_map;
648 
649  /* Increment allocation count (for debugging) */
650  if ( DBG_LOG )
651  dma->allocated++;
652 
653  return addr;
654 
655  efipci_dma_unmap ( dma, map );
656  err_map:
657  pci_io->FreeBuffer ( pci_io, pages, addr );
658  err_alloc:
659  return NULL;
660 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:504
#define DBGC(...)
Definition: compiler.h:505
#define DMA_BI
Device will both read data from and write data to host memory.
Definition: dma.h:138
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition: PciIo.h:527
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:361
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:586
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
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:307
A PCI device.
Definition: pci.h:206
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define VOID
Undeclared type.
Definition: Base.h:271
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
u32 addr
Definition: sky2.h:8
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:35
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:528
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

References addr, AllocateAnyPages, _EFI_PCI_IO_PROTOCOL::AllocateBuffer, container_of, DBG_LOG, DBGC, pci_device::dma, dma(), DMA_BI, EEFI, EFI_PAGE_SIZE, EfiBootServicesData, efipci_dma_map(), efipci_dma_unmap(), _EFI_PCI_IO_PROTOCOL::FreeBuffer, efi_pci_device::io, len, map, memset(), NULL, efi_pci_device::pci, PCI_ARGS, PCI_FMT, rc, strerror(), virt_to_phys(), and VOID.

Referenced by efipci_dma_umalloc().

◆ efipci_dma_free()

static void efipci_dma_free ( struct dma_device dma,
struct dma_mapping map,
void *  addr,
size_t  len 
)
static

Unmap and free DMA-coherent buffer.

Parameters
dmaDMA device
mapDMA mapping
addrBuffer address
lenLength of buffer

Definition at line 670 of file efi_pci.c.

671  {
672  struct efi_pci_device *efipci =
673  container_of ( dma, struct efi_pci_device, pci.dma );
674  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
675  unsigned int pages;
676 
677  /* Calculate number of pages */
678  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
679 
680  /* Unmap buffer */
681  efipci_dma_unmap ( dma, map );
682 
683  /* Free buffer */
684  pci_io->FreeBuffer ( pci_io, pages, addr );
685 
686  /* Decrement allocation count (for debugging) */
687  if ( DBG_LOG )
688  dma->allocated--;
689 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
struct dma_device dma
DMA device.
Definition: pci.h:210
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:586
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
u32 addr
Definition: sky2.h:8
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:528
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
uint32_t len
Length.
Definition: ena.h:14

References addr, container_of, DBG_LOG, pci_device::dma, dma(), EFI_PAGE_SIZE, efipci_dma_unmap(), _EFI_PCI_IO_PROTOCOL::FreeBuffer, efi_pci_device::io, len, map, and efi_pci_device::pci.

Referenced by efipci_dma_ufree().

◆ efipci_dma_umalloc()

static userptr_t efipci_dma_umalloc ( struct dma_device dma,
struct dma_mapping map,
size_t  len,
size_t  align 
)
static

Allocate and map DMA-coherent buffer from external (user) memory.

Parameters
dmaDMA device
mapDMA mapping to fill in
lenLength of buffer
alignPhysical alignment
Return values
addrBuffer address, or NULL on error

Definition at line 700 of file efi_pci.c.

702  {
703  void *addr;
704 
706  return virt_to_user ( addr );
707 }
static __always_inline void struct dma_mapping size_t size_t align
Definition: dma.h:222
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
u32 addr
Definition: sky2.h:8
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
uint32_t len
Length.
Definition: ena.h:14
static void * efipci_dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
Allocate and map DMA-coherent buffer.
Definition: efi_pci.c:615

References addr, align, dma(), efipci_dma_alloc(), len, map, and virt_to_user().

◆ efipci_dma_ufree()

static void efipci_dma_ufree ( struct dma_device dma,
struct dma_mapping map,
userptr_t  addr,
size_t  len 
)
static

Unmap and free DMA-coherent buffer from external (user) memory.

Parameters
dmaDMA device
mapDMA mapping
addrBuffer address
lenLength of buffer

Definition at line 717 of file efi_pci.c.

718  {
719 
720  efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
721 }
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
u32 addr
Definition: sky2.h:8
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
uint32_t len
Length.
Definition: ena.h:14
static void efipci_dma_free(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
Definition: efi_pci.c:670

References addr, dma(), efipci_dma_free(), len, map, and user_to_virt().

◆ efipci_dma_set_mask()

static void efipci_dma_set_mask ( struct dma_device dma,
physaddr_t  mask 
)
static

Set addressable space mask.

Parameters
dmaDMA device
maskAddressable space mask

Definition at line 729 of file efi_pci.c.

729  {
730  struct efi_pci_device *efipci =
731  container_of ( dma, struct efi_pci_device, pci.dma );
732  struct pci_device *pci = &efipci->pci;
733  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
735  UINT64 attrs;
736  int is64;
737  EFI_STATUS efirc;
738  int rc;
739 
740  /* Set dual address cycle attribute for 64-bit capable devices */
741  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
745  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
746  rc = -EEFI ( efirc );
747  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
748  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
749  strerror ( rc ) );
750  /* Ignore failure: errors will manifest in mapping attempts */
751  return;
752  }
753 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
Definition: PciIo.h:101
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:531
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
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:307
A PCI device.
Definition: pci.h:206
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition: PciIo.h:66
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:117
unsigned long long UINT64
Definition: ProcessorBind.h:96
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:113
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _EFI_PCI_IO_PROTOCOL::Attributes, attrs, container_of, DBGC, pci_device::dma, dma(), EEFI, EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE, EfiPciIoAttributeOperationDisable, EfiPciIoAttributeOperationEnable, efi_pci_device::io, NULL, op, efi_pci_device::pci, PCI_ARGS, PCI_FMT, rc, and strerror().

◆ efipci_open()

int efipci_open ( EFI_HANDLE  device,
UINT32  attributes,
struct efi_pci_device efipci 
)

Open EFI PCI device.

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

Definition at line 781 of file efi_pci.c.

782  {
784  union {
785  EFI_PCI_IO_PROTOCOL *pci_io;
786  void *interface;
787  } pci_io;
788  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
789  unsigned int busdevfn;
790  EFI_STATUS efirc;
791  int rc;
792 
793  /* See if device is a PCI device */
794  if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
795  &pci_io.interface, efi_image_handle,
796  device, attributes ) ) != 0 ) {
797  rc = -EEFI_PCI ( efirc );
798  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
799  efi_handle_name ( device ), strerror ( rc ) );
800  goto err_open_protocol;
801  }
802  efipci->io = pci_io.pci_io;
803 
804  /* Get PCI bus:dev.fn address */
805  if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
806  &pci_bus, &pci_dev,
807  &pci_fn ) ) != 0 ) {
808  rc = -EEFI ( efirc );
809  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
810  efi_handle_name ( device ), strerror ( rc ) );
811  goto err_get_location;
812  }
813  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
814  pci_init ( &efipci->pci, busdevfn );
815  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
816  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
817  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
818 
819  /* Try to enable I/O cycles, memory cycles, and bus mastering.
820  * Some platforms will 'helpfully' report errors if these bits
821  * can't be enabled (for example, if the card doesn't actually
822  * support I/O cycles). Work around any such platforms by
823  * enabling bits individually and simply ignoring any errors.
824  */
825  pci_io.pci_io->Attributes ( pci_io.pci_io,
828  pci_io.pci_io->Attributes ( pci_io.pci_io,
831  pci_io.pci_io->Attributes ( pci_io.pci_io,
834 
835  /* Populate PCI device */
836  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
837  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
838  "configuration: %s\n",
839  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
840  goto err_pci_read_config;
841  }
842 
843  return 0;
844 
845  err_pci_read_config:
846  err_get_location:
849  err_open_protocol:
850  return rc;
851 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:284
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:461
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
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:60
An object interface.
Definition: interface.h:124
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:61
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:810
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:182
UINT64 UINTN
Unsigned value of native width.
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition: PciIo.h:59
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:113
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define EEFI_PCI(efirc)
Definition: efi_pci.c:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:756
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1999
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:334
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, busdevfn, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGCP, pci_device::dma, dma_init(), 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, efipci_dma_operations, EfiPciIoAttributeOperationEnable, efi_pci_device::io, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_pci_device::pci, 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 858 of file efi_pci.c.

858  {
860 
863 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:284
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
A hardware device.
Definition: device.h:73
EFI Boot Services Table.
Definition: UefiSpec.h:1930
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
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 efi_pci_device efipci 
)

Get EFI PCI device information.

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

Definition at line 872 of file efi_pci.c.

872  {
873  int rc;
874 
875  /* Open PCI device, if possible */
877  efipci ) ) != 0 )
878  return rc;
879 
880  /* Close PCI device */
881  efipci_close ( device );
882 
883  return 0;
884 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:781
A hardware device.
Definition: device.h:73
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1354
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:858

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

899  {
900  struct efi_pci_device efipci;
901  uint8_t hdrtype;
902  int rc;
903 
904  /* Get PCI device information */
905  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
906  return rc;
907 
908  /* Do not attempt to drive bridges */
909  hdrtype = efipci.pci.hdrtype;
910  if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
911  DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
912  PCI_ARGS ( &efipci.pci ), hdrtype,
914  return -ENOTTY;
915  }
916 
917  /* Look for a driver */
918  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
919  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
920  "has no driver\n", PCI_ARGS ( &efipci.pci ),
921  efipci.pci.vendor, efipci.pci.device,
922  efipci.pci.class );
923  return rc;
924  }
925  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
926  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
927  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
928 
929  return 0;
930 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition: efi_pci.c:872
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:292
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:57
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:73
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition: pci.h:54
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
unsigned char uint8_t
Definition: stdint.h:10
An EFI PCI device.
Definition: efi_pci.h:21
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310

References pci_device::class, DBGC, pci_device::device, efipci_info(), ENOTTY, pci_device::hdrtype, pci_device::id, pci_device_id::name, efi_pci_device::pci, PCI_ARGS, pci_find_driver(), PCI_FMT, PCI_HEADER_TYPE_MASK, PCI_HEADER_TYPE_NORMAL, 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 938 of file efi_pci.c.

938  {
939  EFI_HANDLE device = efidev->device;
940  struct efi_pci_device *efipci;
941  int rc;
942 
943  /* Allocate PCI device */
944  efipci = zalloc ( sizeof ( *efipci ) );
945  if ( ! efipci ) {
946  rc = -ENOMEM;
947  goto err_alloc;
948  }
949 
950  /* Open PCI device */
953  efipci ) ) != 0 ) {
954  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
955  efi_handle_name ( device ), strerror ( rc ) );
957  goto err_open;
958  }
959 
960  /* Find driver */
961  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
962  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
963  PCI_ARGS ( &efipci->pci ) );
964  goto err_find_driver;
965  }
966 
967  /* Mark PCI device as a child of the EFI device */
968  efipci->pci.dev.parent = &efidev->dev;
969  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
970 
971  /* Probe driver */
972  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
973  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
974  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
975  efipci->pci.id->name, strerror ( rc ) );
976  goto err_probe;
977  }
978  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
979  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
980 
981  efidev_set_drvdata ( efidev, efipci );
982  return 0;
983 
984  pci_remove ( &efipci->pci );
985  err_probe:
986  list_del ( &efipci->pci.dev.siblings );
987  err_find_driver:
988  efipci_close ( device );
989  err_open:
990  free ( efipci );
991  err_alloc:
992  return rc;
993 }
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:292
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#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:284
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:781
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1357
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1358
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:322
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:208
#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
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:810
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:640
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:346
const char * name
Name.
Definition: pci.h:172
An EFI PCI device.
Definition: efi_pci.h:21
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:858
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:310
struct pci_device_id * id
Driver device ID.
Definition: pci.h:243
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:74
struct device dev
Generic device.
Definition: efi_driver.h:19
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:324
Definition: efi.h:59

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, efi_pci_device::pci, 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 1000 of file efi_pci.c.

1000  {
1001  struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
1002  EFI_HANDLE device = efidev->device;
1003 
1004  pci_remove ( &efipci->pci );
1005  list_del ( &efipci->pci.dev.siblings );
1006  assert ( efipci->pci.dma.mapped == 0 );
1007  assert ( efipci->pci.dma.allocated == 0 );
1008  efipci_close ( device );
1009  free ( efipci );
1010 }
struct dma_device dma
DMA device.
Definition: pci.h:210
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device dev
Generic device.
Definition: pci.h:208
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:73
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:85
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:346
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:53
An EFI PCI device.
Definition: efi_pci.h:21
unsigned int allocated
Total number of allocations (for debugging)
Definition: dma.h:55
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:858
Definition: efi.h:59

References dma_device::allocated, assert(), pci_device::dev, efi_device::device, pci_device::dma, efidev_get_drvdata(), efipci_close(), free, list_del, dma_device::mapped, efi_pci_device::pci, pci_remove(), and device::siblings.

◆ __efi_driver()

struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI PCI driver.

Variable Documentation

◆ efipci_dma_operations

struct dma_operations efipci_dma_operations
static
Initial value:
= {
.unmap = efipci_dma_unmap,
.alloc = efipci_dma_alloc,
.free = efipci_dma_free,
.umalloc = efipci_dma_umalloc,
.ufree = efipci_dma_ufree,
.set_mask = efipci_dma_set_mask,
}
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:504
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:586
static void efipci_dma_ufree(struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:717
static userptr_t efipci_dma_umalloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:700
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:729
static void efipci_dma_free(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
Definition: efi_pci.c:670
static void * efipci_dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
Allocate and map DMA-coherent buffer.
Definition: efi_pci.c:615

EFI PCI DMA operations.

Definition at line 756 of file efi_pci.c.

Referenced by efipci_open().