iPXE
Macros | Functions | Variables
efi_pci.c File Reference

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

#include <stdlib.h>
#include <string.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)
 
 FILE_SECBOOT (PERMITTED)
 
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 for ephemeral use. 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)
 
 PROVIDE_PCIAPI_RUNTIME (efi, PCIAPI_PRIORITY_EFI)
 
static int efipci_dma_map (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len, int flags)
 Map buffer for DMA. More...
 
static void efipci_dma_unmap (struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
 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 void efipci_dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask. 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_exclude (EFI_HANDLE device)
 Exclude existing drivers. 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_HARDWARE)
 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:692
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 45 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:118
#define __einfo_platformify(einfo_base, platform, desc)
Declare platform-generated error.
Definition: errno.h:194
#define EINFO_EEFI_PCI
Definition: efi_pci.c:45

Definition at line 48 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 51 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:194
#define EFI_ACCESS_DENIED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:130
#define EINFO_EEFI_PCI
Definition: efi_pci.c:45

Definition at line 52 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 55 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:249
#define EINFO_EEFI_PCI
Definition: efi_pci.c:45
#define EEFI_PCI_IN_USE
Definition: efi_pci.c:55
#define EEFI_PCI_NOT_PCI
Definition: efi_pci.c:51

Definition at line 56 of file efi_pci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

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

76  {
78  union {
79  union acpi_resource *res;
80  void *raw;
81  } acpi;
82  uint32_t best = 0;
86  unsigned int tag;
87  EFI_STATUS efirc;
88  int rc;
89 
90  /* Return empty range on error */
91  range->start = 0;
92  range->count = 0;
93 
94  /* Open root bridge I/O protocol */
96  &root ) ) != 0 ) {
97  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
98  PCI_ARGS ( pci ), efi_handle_name ( handle ),
99  strerror ( rc ) );
100  return rc;
101  }
102 
103  /* Get ACPI resource descriptors */
104  if ( ( efirc = root->Configuration ( root, &acpi.raw ) ) != 0 ) {
105  rc = -EEFI ( efirc );
106  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
107  "%s: %s\n", PCI_ARGS ( pci ),
108  efi_handle_name ( handle ), strerror ( rc ) );
109  return rc;
110  }
111 
112  /* Parse resource descriptors */
113  for ( ; ( ( tag = acpi_resource_tag ( acpi.res ) ) !=
115  acpi.res = acpi_resource_next ( acpi.res ) ) {
116 
117  /* Ignore anything other than a bus number range descriptor */
119  continue;
120  if ( acpi.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
121  continue;
122 
123  /* Get range for this descriptor */
124  start = PCI_BUSDEVFN ( root->SegmentNumber,
125  le64_to_cpu ( acpi.res->qword.min ),
126  0, 0 );
127  count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ),
128  0, 0 );
129  DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via "
130  "%s\n", PCI_ARGS ( pci ), root->SegmentNumber,
131  PCI_BUS ( start ), PCI_BUS ( start + count - 1 ),
132  efi_handle_name ( handle ) );
133 
134  /* Check for a matching or new closest range */
135  index = ( pci->busdevfn - start );
136  if ( ( index < count ) || ( index > best ) ) {
137  range->start = start;
138  range->count = count;
139  best = index;
140  }
141 
142  /* Stop if this range contains the target bus:dev.fn address */
143  if ( index < count )
144  break;
145  }
146 
147  /* If no range descriptors were seen, assume that the root
148  * bridge has a single bus.
149  */
150  if ( ! range->count ) {
151  range->start = PCI_BUSDEVFN ( root->SegmentNumber, 0, 0, 0 );
152  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
153  }
154 
155  return 0;
156 }
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:25
#define PCI_BUS(busdevfn)
Definition: pci.h:284
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
struct stp_switch root
Root switch.
Definition: stp.h:27
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:77
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:169
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:121
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:67
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
Definition: acpi.h:43
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:30
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:55
unsigned int uint32_t
Definition: stdint.h:12
An ACPI resource descriptor.
Definition: acpi.h:102
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:27
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:238
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:317
__be32 raw[7]
Definition: CIB_PRM.h:28
#define le64_to_cpu(value)
Definition: byteswap.h:115
uint64_t tag
Identity tag.
Definition: edd.h:31
uint16_t handle
Handle.
Definition: smbios.h:17

References acpi, ACPI_ADDRESS_TYPE_BUS, ACPI_END_RESOURCE, ACPI_QWORD_ADDRESS_SPACE_RESOURCE, acpi_resource_next(), acpi_resource_tag(), pci_device::busdevfn, pci_range::count, count, DBGC, DBGC2, EEFI, efi_handle_name(), efi_open, efi_pci_root_bridge_io_protocol_guid, handle, index, le64_to_cpu, 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 166 of file efi_pci.c.

168  {
170  uint32_t best = 0;
171  uint32_t index;
172  struct pci_range tmp;
173  EFI_HANDLE *handles;
174  UINTN num_handles;
175  UINTN i;
176  EFI_STATUS efirc;
177  int rc;
178 
179  /* Return an empty range and no handle on error */
180  range->start = 0;
181  range->count = 0;
182  *handle = NULL;
183 
184  /* Enumerate all root bridge I/O protocol handles */
185  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
187  NULL, &num_handles, &handles ) ) != 0 ) {
188  rc = -EEFI ( efirc );
189  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
190  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
191  goto err_locate;
192  }
193 
194  /* Iterate over all root bridge I/O protocols */
195  for ( i = 0 ; i < num_handles ; i++ ) {
196 
197  /* Get matching or closest range for this root bridge */
198  if ( ( rc = efipci_discover_one ( pci, handles[i],
199  &tmp ) ) != 0 )
200  continue;
201 
202  /* Check for a matching or new closest range */
203  index = ( pci->busdevfn - tmp.start );
204  if ( ( index < tmp.count ) || ( index > best ) ) {
205  range->start = tmp.start;
206  range->count = tmp.count;
207  best = index;
208  }
209 
210  /* Stop if this range contains the target bus:dev.fn address */
211  if ( index < tmp.count ) {
212  *handle = handles[i];
213  break;
214  }
215  }
216 
217  /* Check for a range containing the target bus:dev.fn address */
218  if ( ! *handle ) {
219  rc = -ENOENT;
220  goto err_range;
221  }
222 
223  /* Success */
224  rc = 0;
225 
226  err_range:
227  bs->FreePool ( handles );
228  err_locate:
229  return rc;
230 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2099
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
#define ENOENT
No such file or directory.
Definition: errno.h:515
unsigned long tmp
Definition: linux_pci.h:65
A PCI bus:dev.fn address range.
Definition: pci_io.h:23
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
EFI Boot Services Table.
Definition: UefiSpec.h:1931
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
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:27
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1950
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:238
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:317
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:75
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1531
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
Definition: efi.h:62
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:2008

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

238  {
239  struct pci_device pci;
241 
242  /* Find range */
243  memset ( &pci, 0, sizeof ( pci ) );
244  pci_init ( &pci, busdevfn );
245  efipci_discover_any ( &pci, range, &handle );
246 }
struct pci_range range
PCI bus:dev.fn address range.
Definition: pcicloud.c:40
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:166
A PCI device.
Definition: pci.h:211
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:341
uint16_t handle
Handle.
Definition: smbios.h:17
Definition: efi.h:62
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 for ephemeral use.

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

257  {
258  struct pci_range tmp;
259  int rc;
260 
261  /* Find matching root bridge I/O protocol handle */
262  if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 )
263  return rc;
264 
265  /* Open PCI root bridge I/O protocol */
267  root ) ) != 0 ) {
268  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
269  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
270  strerror ( rc ) );
271  return rc;
272  }
273 
274  return 0;
275 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct stp_switch root
Root switch.
Definition: stp.h:27
#define DBGC(...)
Definition: compiler.h:505
unsigned long tmp
Definition: linux_pci.h:65
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:166
A PCI bus:dev.fn address range.
Definition: pci_io.h:23
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:317
uint16_t handle
Handle.
Definition: smbios.h:17

References DBGC, efi_handle_name(), efi_open, efi_pci_root_bridge_io_protocol_guid, efipci_discover_any(), handle, PCI_ARGS, PCI_FMT, rc, root, strerror(), and tmp.

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

285  {
286 
287  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
288  PCI_SLOT ( pci->busdevfn ),
289  PCI_FUNC ( pci->busdevfn ),
290  EFIPCI_OFFSET ( location ) );
291 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:286
#define PCI_BUS(busdevfn)
Definition: pci.h:284
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:26
#define PCI_SLOT(busdevfn)
Definition: pci.h:285
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:238

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

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

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

◆ efipci_write()

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

Write to PCI configuration space.

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

Definition at line 334 of file efi_pci.c.

335  {
338  EFI_STATUS efirc;
339  int rc;
340 
341  /* Open root bridge */
342  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
343  return rc;
344 
345  /* Read from configuration space */
346  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
347  efipci_address ( pci, location ), 1,
348  &value ) ) != 0 ) {
349  rc = -EEFI ( efirc );
350  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
351  "failed: %s\n", PCI_ARGS ( pci ),
352  EFIPCI_OFFSET ( location ), strerror ( rc ) );
353  return rc;
354  }
355 
356  return 0;
357 }
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:175
struct stp_switch root
Root switch.
Definition: stp.h:27
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol for ephemeral use.
Definition: efi_pci.c:256
#define DBGC(...)
Definition: compiler.h:505
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:26
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
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:27
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:284
uint16_t handle
Handle.
Definition: smbios.h:17
Definition: efi.h:62

References DBGC, EEFI, efipci_address(), EFIPCI_OFFSET, 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 366 of file efi_pci.c.

367  {
368  union {
369  union acpi_resource *res;
370  void *raw;
371  } u;
374  unsigned int tag;
376  uint64_t start;
377  uint64_t end;
378  EFI_STATUS efirc;
379  int rc;
380 
381  /* Open root bridge */
382  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
383  goto err_root;
384 
385  /* Get ACPI resource descriptors */
386  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
387  rc = -EEFI ( efirc );
388  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
389  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
390  goto err_config;
391  }
392 
393  /* Parse resource descriptors */
394  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
395  u.res = acpi_resource_next ( u.res ) ) {
396 
397  /* Ignore anything other than a memory range descriptor */
399  continue;
400  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
401  continue;
402 
403  /* Ignore descriptors that do not cover this memory range */
404  offset = le64_to_cpu ( u.res->qword.offset );
405  start = ( offset + le64_to_cpu ( u.res->qword.min ) );
406  end = ( start + le64_to_cpu ( u.res->qword.len ) );
407  DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
408  "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
409  ( start - offset ), ( end - offset ) );
410  if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
411  continue;
412 
413  /* Use this address space descriptor */
414  DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
415  PCI_ARGS ( pci ), bus_addr, len );
416  bus_addr -= offset;
417  DBGC2 ( pci, "%08lx\n", bus_addr );
418  break;
419  }
420  if ( tag == ACPI_END_RESOURCE ) {
421  DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
422  "root bridge address space\n",
423  PCI_ARGS ( pci ), bus_addr, len );
424  }
425 
426  err_config:
427  err_root:
428  return ioremap ( bus_addr, len );
429 }
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:175
struct stp_switch root
Root switch.
Definition: stp.h:27
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol for ephemeral use.
Definition: efi_pci.c:256
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:77
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
union @18 u
static __always_inline void unsigned long bus_addr
Definition: pcibios.h:156
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:169
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:121
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:55
An ACPI resource descriptor.
Definition: acpi.h:102
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:37
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
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:115
uint64_t tag
Identity tag.
Definition: edd.h:31
uint16_t handle
Handle.
Definition: smbios.h:17
Definition: efi.h:62

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

◆ PROVIDE_PCIAPI_RUNTIME()

PROVIDE_PCIAPI_RUNTIME ( efi  ,
PCIAPI_PRIORITY_EFI   
)

◆ efipci_dma_map()

static int efipci_dma_map ( struct dma_device dma,
struct dma_mapping map,
void *  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 459 of file efi_pci.c.

460  {
461  struct efi_pci_device *efipci =
462  container_of ( dma, struct efi_pci_device, pci.dma );
463  struct pci_device *pci = &efipci->pci;
464  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
467  UINTN count;
468  VOID *mapping;
470  EFI_STATUS efirc;
471  int rc;
472 
473  /* Sanity check */
474  assert ( map->dma == NULL );
475  assert ( map->offset == 0 );
476  assert ( map->token == NULL );
477 
478  /* Determine operation */
479  switch ( flags ) {
480  case DMA_TX:
482  break;
483  case DMA_RX:
485  break;
486  default:
488  break;
489  }
490 
491  /* Map buffer (if non-zero length) */
492  phys = virt_to_phys ( addr );
493  count = len;
494  if ( len ) {
495  if ( ( efirc = pci_io->Map ( pci_io, op, addr, &count, &bus,
496  &mapping ) ) != 0 ) {
497  rc = -EEFI ( efirc );
498  DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %p+%zx: "
499  "%s\n", PCI_ARGS ( pci ), addr, len,
500  strerror ( rc ) );
501  goto err_map;
502  }
503  } else {
504  bus = phys;
505  mapping = NULL;
506  }
507 
508  /* Check that full length was mapped. The UEFI specification
509  * allows for multiple mappings to be required, but even the
510  * EDK2 PCI device drivers will fail if a platform ever
511  * requires this.
512  */
513  if ( count != len ) {
514  DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
515  "%p+%zx\n", PCI_ARGS ( pci ), addr, len );
516  rc = -ENOTSUP;
517  goto err_len;
518  }
519 
520  /* Populate mapping */
521  map->dma = dma;
522  map->offset = ( bus - phys );
523  map->token = mapping;
524 
525  /* Increment mapping count (for debugging) */
526  if ( DBG_LOG )
527  dma->mapped++;
528 
529  return 0;
530 
531  err_len:
532  pci_io->Unmap ( pci_io, mapping );
533  err_map:
534  return rc;
535 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:135
struct dma_device dma
DMA device.
Definition: pci.h:215
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:42
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
A read operation from system memory by a bus master.
Definition: PciIo.h:84
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:138
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:526
#define DBGC(...)
Definition: compiler.h:505
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:53
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
static signed char phys[4]
Definition: epic100.c:88
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:527
uint8_t flags
Flags.
Definition: ena.h:18
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
physaddr_t offset
Address offset.
Definition: dma.h:40
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
A PCI device.
Definition: pci.h:211
uint32_t addr
Buffer address.
Definition: dwmac.h:20
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:93
#define VOID
Undeclared type.
Definition: Base.h:272
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:80
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
unsigned long physaddr_t
Definition: stdint.h:20
An EFI PCI device.
Definition: efi_pci.h:22
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
void * token
Platform mapping token.
Definition: dma.h:44
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
A write operation from system memory by a bus master.
Definition: PciIo.h:88
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

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, 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,
size_t len  __unused 
)
static

Unmap buffer.

Parameters
dmaDMA device
mapDMA mapping
lenUsed length

Definition at line 544 of file efi_pci.c.

545  {
546  struct efi_pci_device *efipci =
547  container_of ( dma, struct efi_pci_device, pci.dma );
548  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
549 
550  /* Unmap buffer (if non-zero length) */
551  if ( map->token )
552  pci_io->Unmap ( pci_io, map->token );
553 
554  /* Clear mapping */
555  map->dma = NULL;
556  map->offset = 0;
557  map->token = NULL;
558 
559  /* Decrement mapping count (for debugging) */
560  if ( DBG_LOG )
561  dma->mapped--;
562 }
struct dma_device dma
DMA device.
Definition: pci.h:215
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:42
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:527
physaddr_t offset
Address offset.
Definition: dma.h:40
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
An EFI PCI device.
Definition: efi_pci.h:22
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
void * token
Platform mapping token.
Definition: dma.h:44
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

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

575  {
576  struct efi_pci_device *efipci =
577  container_of ( dma, struct efi_pci_device, pci.dma );
578  struct pci_device *pci = &efipci->pci;
579  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
580  unsigned int pages;
581  VOID *addr;
582  EFI_STATUS efirc;
583  int rc;
584 
585  /* Calculate number of pages */
586  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
587 
588  /* Allocate (page-aligned) buffer */
589  if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
590  EfiBootServicesData, pages,
591  &addr, 0 ) ) != 0 ) {
592  rc = -EEFI ( efirc );
593  DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
594  "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
595  goto err_alloc;
596  }
597 
598  /* Clear buffer */
599  memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
600 
601  /* Map buffer */
602  if ( ( rc = efipci_dma_map ( dma, map, addr, ( pages * EFI_PAGE_SIZE ),
603  DMA_BI ) ) != 0 )
604  goto err_map;
605 
606  /* Increment allocation count (for debugging) */
607  if ( DBG_LOG )
608  dma->allocated++;
609 
610  return addr;
611 
612  efipci_dma_unmap ( dma, map, len );
613  err_map:
614  pci_io->FreeBuffer ( pci_io, pages, addr );
615  err_alloc:
616  return NULL;
617 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:188
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:215
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:459
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
#define DBGC(...)
Definition: compiler.h:505
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition: PciIo.h:528
#define DMA_BI
Device will both read data from and write data to host memory.
Definition: dma.h:141
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
A PCI device.
Definition: pci.h:211
uint32_t addr
Buffer address.
Definition: dwmac.h:20
#define VOID
Undeclared type.
Definition: Base.h:272
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
An EFI PCI device.
Definition: efi_pci.h:22
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:36
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:529
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:544
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
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(), and VOID.

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

628  {
629  struct efi_pci_device *efipci =
630  container_of ( dma, struct efi_pci_device, pci.dma );
631  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
632  unsigned int pages;
633 
634  /* Calculate number of pages */
635  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
636 
637  /* Unmap buffer */
638  efipci_dma_unmap ( dma, map, len );
639 
640  /* Free buffer */
641  pci_io->FreeBuffer ( pci_io, pages, addr );
642 
643  /* Decrement allocation count (for debugging) */
644  if ( DBG_LOG )
645  dma->allocated--;
646 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:188
struct dma_device dma
DMA device.
Definition: pci.h:215
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
uint32_t addr
Buffer address.
Definition: dwmac.h:20
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
An EFI PCI device.
Definition: efi_pci.h:22
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:529
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:544
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define DBG_LOG
Definition: compiler.h:317
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

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.

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

654  {
655  struct efi_pci_device *efipci =
656  container_of ( dma, struct efi_pci_device, pci.dma );
657  struct pci_device *pci = &efipci->pci;
658  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
660  UINT64 attrs;
661  int is64;
662  EFI_STATUS efirc;
663  int rc;
664 
665  /* Set dual address cycle attribute for 64-bit capable devices */
666  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
670  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
671  rc = -EEFI ( efirc );
672  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
673  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
674  strerror ( rc ) );
675  /* Ignore failure: errors will manifest in mapping attempts */
676  return;
677  }
678 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:215
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
#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:36
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
Definition: PciIo.h:102
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:532
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
A PCI device.
Definition: pci.h:211
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition: PciIo.h:67
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:118
unsigned long long UINT64
Definition: ProcessorBind.h:97
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:114
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
An EFI PCI device.
Definition: efi_pci.h:22
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:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

References _EFI_PCI_IO_PROTOCOL::Attributes, 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_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 705 of file efi_pci.c.

705  {
706  EFI_PCI_IO_PROTOCOL *pci_io;
707  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
708  unsigned int busdevfn;
709  EFI_STATUS efirc;
710  int rc;
711 
712  /* See if device is a PCI device */
714  &pci_io ) ) != 0 ) {
715  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
716  efi_handle_name ( device ), strerror ( rc ) );
717  return rc;
718  }
719  efipci->io = pci_io;
720 
721  /* Get PCI bus:dev.fn address */
722  if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus,
723  &pci_dev, &pci_fn ) ) != 0 ) {
724  rc = -EEFI ( efirc );
725  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
726  efi_handle_name ( device ), strerror ( rc ) );
727  return rc;
728  }
729  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
730  pci_init ( &efipci->pci, busdevfn );
731  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
732  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
733  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
734 
735  /* Try to enable I/O cycles, memory cycles, and bus mastering.
736  * Some platforms will 'helpfully' report errors if these bits
737  * can't be enabled (for example, if the card doesn't actually
738  * support I/O cycles). Work around any such platforms by
739  * enabling bits individually and simply ignoring any errors.
740  */
747 
748  /* Populate PCI device */
749  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
750  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
751  "configuration: %s\n",
752  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
753  return rc;
754  }
755 
756  return 0;
757 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:215
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:313
#define DBGC(...)
Definition: compiler.h:505
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
A hardware device.
Definition: device.h:77
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:61
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:532
EFI_PCI_IO_PROTOCOL_GET_LOCATION GetLocation
Definition: PciIo.h:531
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:62
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:30
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:269
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
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:60
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:114
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:454
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
#define DBGCP(...)
Definition: compiler.h:539
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:681
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:341
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:519
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References _EFI_PCI_IO_PROTOCOL::Attributes, busdevfn, DBGC, DBGCP, pci_device::dma, dma_init(), EEFI, efi_handle_name(), efi_open, EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, EFI_PCI_IO_ATTRIBUTE_IO, EFI_PCI_IO_ATTRIBUTE_MEMORY, efi_pci_io_protocol_guid, efipci_dma_operations, EfiPciIoAttributeOperationEnable, _EFI_PCI_IO_PROTOCOL::GetLocation, efi_pci_device::io, NULL, efi_pci_device::pci, PCI_ARGS, PCI_BUSDEVFN, PCI_FMT, pci_init(), pci_read_config(), rc, and strerror().

Referenced by efi_bofm_start(), efi_bofm_supported(), efi_device_info_pci(), efipci_start(), 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 772 of file efi_pci.c.

772  {
773  struct efi_pci_device efipci;
774  uint8_t hdrtype;
775  int rc;
776 
777  /* Get PCI device information */
778  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
779  return rc;
780 
781  /* Do not attempt to drive bridges */
782  hdrtype = efipci.pci.hdrtype;
783  if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
784  DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
785  PCI_ARGS ( &efipci.pci ), hdrtype,
787  return -ENOTTY;
788  }
789 
790  /* Look for a driver */
791  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
792  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
793  "has no driver\n", PCI_ARGS ( &efipci.pci ),
794  efipci.pci.vendor, efipci.pci.device,
795  efipci.pci.class );
796  return rc;
797  }
798  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
799  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
800  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
801 
802  return 0;
803 }
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:705
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:379
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:58
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:77
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition: pci.h:55
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
unsigned char uint8_t
Definition: stdint.h:10
An EFI PCI device.
Definition: efi_pci.h:22
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:595
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315

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

static int efipci_exclude ( EFI_HANDLE  device)
static

Exclude existing drivers.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 811 of file efi_pci.c.

811  {
813  int rc;
814 
815  /* Exclude existing PCI I/O protocol drivers */
816  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
817  DBGC ( device, "EFIPCI %s could not exclude drivers: %s\n",
818  efi_handle_name ( device ), strerror ( rc ) );
819  return rc;
820  }
821 
822  return 0;
823 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:313
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:77
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:438
uint16_t protocol
Protocol ID.
Definition: stp.h:19

References DBGC, efi_driver_exclude(), efi_handle_name(), efi_pci_io_protocol_guid, protocol, rc, and strerror().

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

831  {
832  EFI_HANDLE device = efidev->device;
833  struct efi_pci_device *efipci;
834  int rc;
835 
836  /* Allocate PCI device */
837  efipci = zalloc ( sizeof ( *efipci ) );
838  if ( ! efipci ) {
839  rc = -ENOMEM;
840  goto err_alloc;
841  }
842 
843  /* Get PCI device information */
844  if ( ( rc = efipci_info ( device, efipci ) ) != 0 )
845  goto err_info;
846 
847  /* Open PCI I/O protocol */
849  &efipci->io ) ) != 0 ) {
850  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
851  efi_handle_name ( device ), strerror ( rc ) );
853  goto err_open;
854  }
855 
856  /* Find driver */
857  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
858  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
859  PCI_ARGS ( &efipci->pci ) );
860  goto err_find_driver;
861  }
862 
863  /* Mark PCI device as a child of the EFI device */
864  efipci->pci.dev.parent = &efidev->dev;
865  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
866 
867  /* Probe driver */
868  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
869  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
870  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
871  efipci->pci.id->name, strerror ( rc ) );
872  goto err_probe;
873  }
874  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
875  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
876 
877  efidev_set_drvdata ( efidev, efipci );
878  return 0;
879 
880  pci_remove ( &efipci->pci );
881  err_probe:
882  list_del ( &efipci->pci.dev.siblings );
883  err_find_driver:
885  err_open:
886  err_info:
887  free ( efipci );
888  err_alloc:
889  return rc;
890 }
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:705
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:379
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:313
#define DBGC(...)
Definition: compiler.h:505
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:345
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
struct device * parent
Bus device.
Definition: device.h:89
struct device dev
Generic device.
Definition: pci.h:213
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
A hardware device.
Definition: device.h:77
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:474
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:312
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:433
const char * name
Name.
Definition: pci.h:177
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:26
An EFI PCI device.
Definition: efi_pci.h:22
struct list_head children
Devices attached to this device.
Definition: device.h:87
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:315
struct pci_device_id * id
Driver device ID.
Definition: pci.h:248
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:84
struct device dev
Generic device.
Definition: efi_driver.h:20
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:411
Definition: efi.h:62

References device::children, DBGC, DBGC_EFI_OPENERS, efi_device::dev, pci_device::dev, efi_device::device, efi_close_by_driver(), efi_handle_name(), efi_open_by_driver, efi_pci_io_protocol_guid, efidev_set_drvdata(), efipci_info(), ENOMEM, free, pci_device::id, efi_pci_device::io, 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 897 of file efi_pci.c.

897  {
898  struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
899  EFI_HANDLE device = efidev->device;
900 
901  pci_remove ( &efipci->pci );
902  list_del ( &efipci->pci.dev.siblings );
903  assert ( efipci->pci.dma.mapped == 0 );
904  assert ( efipci->pci.dma.allocated == 0 );
906  free ( efipci );
907 }
struct dma_device dma
DMA device.
Definition: pci.h:215
struct pci_device pci
PCI device.
Definition: efi_pci.h:24
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:313
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
struct device dev
Generic device.
Definition: pci.h:213
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A hardware device.
Definition: device.h:77
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:95
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:433
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:54
An EFI PCI device.
Definition: efi_pci.h:22
unsigned int allocated
Total number of allocations (for debugging)
Definition: dma.h:56
Definition: efi.h:62

References dma_device::allocated, assert(), pci_device::dev, efi_device::device, pci_device::dma, efi_close_by_driver(), efi_pci_io_protocol_guid, efidev_get_drvdata(), 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_HARDWARE  )

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_alloc,
.ufree = efipci_dma_free,
.set_mask = efipci_dma_set_mask,
}
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:459
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:654
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:544
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:627
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:573

EFI PCI DMA operations.

Definition at line 681 of file efi_pci.c.

Referenced by efipci_info().