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)
 
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:691
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 44 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:44

Definition at line 47 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 50 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:44

Definition at line 51 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 54 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:44
#define EEFI_PCI_IN_USE
Definition: efi_pci.c:54
#define EEFI_PCI_NOT_PCI
Definition: efi_pci.c:50

Definition at line 55 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 74 of file efi_pci.c.

75  {
77  union {
78  union acpi_resource *res;
79  void *raw;
80  } acpi;
81  uint32_t best = 0;
85  unsigned int tag;
86  EFI_STATUS efirc;
87  int rc;
88 
89  /* Return empty range on error */
90  range->start = 0;
91  range->count = 0;
92 
93  /* Open root bridge I/O protocol */
95  &root ) ) != 0 ) {
96  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
97  PCI_ARGS ( pci ), efi_handle_name ( handle ),
98  strerror ( rc ) );
99  return rc;
100  }
101 
102  /* Get ACPI resource descriptors */
103  if ( ( efirc = root->Configuration ( root, &acpi.raw ) ) != 0 ) {
104  rc = -EEFI ( efirc );
105  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
106  "%s: %s\n", PCI_ARGS ( pci ),
107  efi_handle_name ( handle ), strerror ( rc ) );
108  return rc;
109  }
110 
111  /* Parse resource descriptors */
112  for ( ; ( ( tag = acpi_resource_tag ( acpi.res ) ) !=
114  acpi.res = acpi_resource_next ( acpi.res ) ) {
115 
116  /* Ignore anything other than a bus number range descriptor */
118  continue;
119  if ( acpi.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
120  continue;
121 
122  /* Get range for this descriptor */
123  start = PCI_BUSDEVFN ( root->SegmentNumber,
124  le64_to_cpu ( acpi.res->qword.min ),
125  0, 0 );
126  count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ),
127  0, 0 );
128  DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via "
129  "%s\n", PCI_ARGS ( pci ), root->SegmentNumber,
130  PCI_BUS ( start ), PCI_BUS ( start + count - 1 ),
131  efi_handle_name ( handle ) );
132 
133  /* Check for a matching or new closest range */
134  index = ( pci->busdevfn - start );
135  if ( ( index < count ) || ( index > best ) ) {
136  range->start = start;
137  range->count = count;
138  best = index;
139  }
140 
141  /* Stop if this range contains the target bus:dev.fn address */
142  if ( index < count )
143  break;
144  }
145 
146  /* If no range descriptors were seen, assume that the root
147  * bridge has a single bus.
148  */
149  if ( ! range->count ) {
150  range->start = PCI_BUSDEVFN ( root->SegmentNumber, 0, 0, 0 );
151  range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
152  }
153 
154  return 0;
155 }
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:24
#define PCI_BUS(busdevfn)
Definition: pci.h:283
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:174
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:76
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:168
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:120
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:66
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:42
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:29
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:311
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:54
unsigned int uint32_t
Definition: stdint.h:12
An ACPI resource descriptor.
Definition: acpi.h:101
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:26
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:237
#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:314
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:316
__be32 raw[7]
Definition: CIB_PRM.h:28
#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(), 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 165 of file efi_pci.c.

167  {
169  uint32_t best = 0;
170  uint32_t index;
171  struct pci_range tmp;
172  EFI_HANDLE *handles;
173  UINTN num_handles;
174  UINTN i;
175  EFI_STATUS efirc;
176  int rc;
177 
178  /* Return an empty range and no handle on error */
179  range->start = 0;
180  range->count = 0;
181  *handle = NULL;
182 
183  /* Enumerate all root bridge I/O protocol handles */
184  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
186  NULL, &num_handles, &handles ) ) != 0 ) {
187  rc = -EEFI ( efirc );
188  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
189  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
190  goto err_locate;
191  }
192 
193  /* Iterate over all root bridge I/O protocols */
194  for ( i = 0 ; i < num_handles ; i++ ) {
195 
196  /* Get matching or closest range for this root bridge */
197  if ( ( rc = efipci_discover_one ( pci, handles[i],
198  &tmp ) ) != 0 )
199  continue;
200 
201  /* Check for a matching or new closest range */
202  index = ( pci->busdevfn - tmp.start );
203  if ( ( index < tmp.count ) || ( index > best ) ) {
204  range->start = tmp.start;
205  range->count = tmp.count;
206  best = index;
207  }
208 
209  /* Stop if this range contains the target bus:dev.fn address */
210  if ( index < tmp.count ) {
211  *handle = handles[i];
212  break;
213  }
214  }
215 
216  /* Check for a range containing the target bus:dev.fn address */
217  if ( ! *handle ) {
218  rc = -ENOENT;
219  goto err_range;
220  }
221 
222  /* Success */
223  rc = 0;
224 
225  err_range:
226  bs->FreePool ( handles );
227  err_locate:
228  return rc;
229 }
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:24
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:174
#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:64
A PCI bus:dev.fn address range.
Definition: pci_io.h:22
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:311
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:26
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:237
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:314
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:316
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:74
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:61
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 237 of file efi_pci.c.

237  {
238  struct pci_device pci;
240 
241  /* Find range */
242  memset ( &pci, 0, sizeof ( pci ) );
243  pci_init ( &pci, busdevfn );
244  efipci_discover_any ( &pci, range, &handle );
245 }
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:165
A PCI device.
Definition: pci.h:210
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:340
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:61
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 255 of file efi_pci.c.

256  {
257  struct pci_range tmp;
258  int rc;
259 
260  /* Find matching root bridge I/O protocol handle */
261  if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 )
262  return rc;
263 
264  /* Open PCI root bridge I/O protocol */
266  root ) ) != 0 ) {
267  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
268  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
269  strerror ( rc ) );
270  return rc;
271  }
272 
273  return 0;
274 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
unsigned long tmp
Definition: linux_pci.h:64
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:165
A PCI bus:dev.fn address range.
Definition: pci_io.h:22
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:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:314
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:316
uint16_t handle
Handle.
Definition: smbios.h:16

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

284  {
285 
286  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
287  PCI_SLOT ( pci->busdevfn ),
288  PCI_FUNC ( pci->busdevfn ),
289  EFIPCI_OFFSET ( location ) );
290 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:285
#define PCI_BUS(busdevfn)
Definition: pci.h:283
#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:284
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:237

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

301  {
304  EFI_STATUS efirc;
305  int rc;
306 
307  /* Open root bridge */
308  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
309  return rc;
310 
311  /* Read from configuration space */
312  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
313  efipci_address ( pci, location ), 1,
314  value ) ) != 0 ) {
315  rc = -EEFI ( efirc );
316  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
317  "failed: %s\n", PCI_ARGS ( pci ),
318  EFIPCI_OFFSET ( location ), strerror ( rc ) );
319  return rc;
320  }
321 
322  return 0;
323 }
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:174
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 for ephemeral use.
Definition: efi_pci.c:255
#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:311
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:314
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:283
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:61

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

334  {
337  EFI_STATUS efirc;
338  int rc;
339 
340  /* Open root bridge */
341  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
342  return rc;
343 
344  /* Read from configuration space */
345  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
346  efipci_address ( pci, location ), 1,
347  &value ) ) != 0 ) {
348  rc = -EEFI ( efirc );
349  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
350  "failed: %s\n", PCI_ARGS ( pci ),
351  EFIPCI_OFFSET ( location ), strerror ( rc ) );
352  return rc;
353  }
354 
355  return 0;
356 }
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:174
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 for ephemeral use.
Definition: efi_pci.c:255
#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:311
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:314
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:283
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:61

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

366  {
367  union {
368  union acpi_resource *res;
369  void *raw;
370  } u;
373  unsigned int tag;
375  uint64_t start;
376  uint64_t end;
377  EFI_STATUS efirc;
378  int rc;
379 
380  /* Open root bridge */
381  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
382  goto err_root;
383 
384  /* Get ACPI resource descriptors */
385  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
386  rc = -EEFI ( efirc );
387  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
388  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
389  goto err_config;
390  }
391 
392  /* Parse resource descriptors */
393  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
394  u.res = acpi_resource_next ( u.res ) ) {
395 
396  /* Ignore anything other than a memory range descriptor */
398  continue;
399  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
400  continue;
401 
402  /* Ignore descriptors that do not cover this memory range */
403  offset = le64_to_cpu ( u.res->qword.offset );
404  start = ( offset + le64_to_cpu ( u.res->qword.min ) );
405  end = ( start + le64_to_cpu ( u.res->qword.len ) );
406  DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
407  "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
408  ( start - offset ), ( end - offset ) );
409  if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
410  continue;
411 
412  /* Use this address space descriptor */
413  DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
414  PCI_ARGS ( pci ), bus_addr, len );
415  bus_addr -= offset;
416  DBGC2 ( pci, "%08lx\n", bus_addr );
417  break;
418  }
419  if ( tag == ACPI_END_RESOURCE ) {
420  DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
421  "root bridge address space\n",
422  PCI_ARGS ( pci ), bus_addr, len );
423  }
424 
425  err_config:
426  err_root:
427  return ioremap ( bus_addr, len );
428 }
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:174
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 for ephemeral use.
Definition: efi_pci.c:255
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:76
#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:155
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:168
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:120
ring len
Length.
Definition: dwmac.h:231
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:311
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:54
An ACPI resource descriptor.
Definition: acpi.h:101
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:36
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:314
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
Definition: efi.h:61

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

459  {
460  struct efi_pci_device *efipci =
461  container_of ( dma, struct efi_pci_device, pci.dma );
462  struct pci_device *pci = &efipci->pci;
463  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
466  UINTN count;
467  VOID *mapping;
469  EFI_STATUS efirc;
470  int rc;
471 
472  /* Sanity check */
473  assert ( map->dma == NULL );
474  assert ( map->offset == 0 );
475  assert ( map->token == NULL );
476 
477  /* Determine operation */
478  switch ( flags ) {
479  case DMA_TX:
481  break;
482  case DMA_RX:
484  break;
485  default:
487  break;
488  }
489 
490  /* Map buffer (if non-zero length) */
491  phys = virt_to_phys ( addr );
492  count = len;
493  if ( len ) {
494  if ( ( efirc = pci_io->Map ( pci_io, op, addr, &count, &bus,
495  &mapping ) ) != 0 ) {
496  rc = -EEFI ( efirc );
497  DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %p+%zx: "
498  "%s\n", PCI_ARGS ( pci ), addr, len,
499  strerror ( rc ) );
500  goto err_map;
501  }
502  } else {
503  bus = phys;
504  mapping = NULL;
505  }
506 
507  /* Check that full length was mapped. The UEFI specification
508  * allows for multiple mappings to be required, but even the
509  * EDK2 PCI device drivers will fail if a platform ever
510  * requires this.
511  */
512  if ( count != len ) {
513  DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
514  "%p+%zx\n", PCI_ARGS ( pci ), addr, len );
515  rc = -ENOTSUP;
516  goto err_len;
517  }
518 
519  /* Populate mapping */
520  map->dma = dma;
521  map->offset = ( bus - phys );
522  map->token = mapping;
523 
524  /* Increment mapping count (for debugging) */
525  if ( DBG_LOG )
526  dma->mapped++;
527 
528  return 0;
529 
530  err_len:
531  pci_io->Unmap ( pci_io, mapping );
532  err_map:
533  return rc;
534 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:134
struct dma_device dma
DMA device.
Definition: pci.h:214
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
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
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:137
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 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:35
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: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:311
A PCI device.
Definition: pci.h:210
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:92
#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
unsigned long physaddr_t
Definition: stdint.h:20
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
void * token
Platform mapping token.
Definition: dma.h:43
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:314
A write operation from system memory by a bus master.
Definition: PciIo.h:87
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
uint8_t bus
Bus.
Definition: edd.h:14
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 543 of file efi_pci.c.

544  {
545  struct efi_pci_device *efipci =
546  container_of ( dma, struct efi_pci_device, pci.dma );
547  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
548 
549  /* Unmap buffer (if non-zero length) */
550  if ( map->token )
551  pci_io->Unmap ( pci_io, map->token );
552 
553  /* Clear mapping */
554  map->dma = NULL;
555  map->offset = 0;
556  map->token = NULL;
557 
558  /* Decrement mapping count (for debugging) */
559  if ( DBG_LOG )
560  dma->mapped--;
561 }
struct dma_device dma
DMA device.
Definition: pci.h:214
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
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
void * token
Platform mapping token.
Definition: dma.h:43
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
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 572 of file efi_pci.c.

574  {
575  struct efi_pci_device *efipci =
576  container_of ( dma, struct efi_pci_device, pci.dma );
577  struct pci_device *pci = &efipci->pci;
578  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
579  unsigned int pages;
580  VOID *addr;
581  EFI_STATUS efirc;
582  int rc;
583 
584  /* Calculate number of pages */
585  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
586 
587  /* Allocate (page-aligned) buffer */
588  if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
589  EfiBootServicesData, pages,
590  &addr, 0 ) ) != 0 ) {
591  rc = -EEFI ( efirc );
592  DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
593  "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
594  goto err_alloc;
595  }
596 
597  /* Clear buffer */
598  memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
599 
600  /* Map buffer */
601  if ( ( rc = efipci_dma_map ( dma, map, addr, ( pages * EFI_PAGE_SIZE ),
602  DMA_BI ) ) != 0 )
603  goto err_map;
604 
605  /* Increment allocation count (for debugging) */
606  if ( DBG_LOG )
607  dma->allocated++;
608 
609  return addr;
610 
611  efipci_dma_unmap ( dma, map, len );
612  err_map:
613  pci_io->FreeBuffer ( pci_io, pages, addr );
614  err_alloc:
615  return NULL;
616 }
#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:214
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
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:458
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define DBGC(...)
Definition: compiler.h:505
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition: PciIo.h:527
#define DMA_BI
Device will both read data from and write data to host memory.
Definition: dma.h:140
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
ring len
Length.
Definition: dwmac.h:231
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:311
A PCI device.
Definition: pci.h:210
uint32_t addr
Buffer address.
Definition: dwmac.h:20
#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
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
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:314
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 void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:543
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
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 626 of file efi_pci.c.

627  {
628  struct efi_pci_device *efipci =
629  container_of ( dma, struct efi_pci_device, pci.dma );
630  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
631  unsigned int pages;
632 
633  /* Calculate number of pages */
634  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
635 
636  /* Unmap buffer */
637  efipci_dma_unmap ( dma, map, len );
638 
639  /* Free buffer */
640  pci_io->FreeBuffer ( pci_io, pages, addr );
641 
642  /* Decrement allocation count (for debugging) */
643  if ( DBG_LOG )
644  dma->allocated--;
645 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
struct dma_device dma
DMA device.
Definition: pci.h:214
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
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:25
An EFI PCI device.
Definition: efi_pci.h:21
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:528
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:543
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
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 653 of file efi_pci.c.

653  {
654  struct efi_pci_device *efipci =
655  container_of ( dma, struct efi_pci_device, pci.dma );
656  struct pci_device *pci = &efipci->pci;
657  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
659  UINT64 attrs;
660  int is64;
661  EFI_STATUS efirc;
662  int rc;
663 
664  /* Set dual address cycle attribute for 64-bit capable devices */
665  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
669  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
670  rc = -EEFI ( efirc );
671  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
672  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
673  strerror ( rc ) );
674  /* Ignore failure: errors will manifest in mapping attempts */
675  return;
676  }
677 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:214
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
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
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:311
A PCI device.
Definition: pci.h:210
#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:314
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
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 704 of file efi_pci.c.

704  {
705  EFI_PCI_IO_PROTOCOL *pci_io;
706  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
707  unsigned int busdevfn;
708  EFI_STATUS efirc;
709  int rc;
710 
711  /* See if device is a PCI device */
713  &pci_io ) ) != 0 ) {
714  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
715  efi_handle_name ( device ), strerror ( rc ) );
716  return rc;
717  }
718  efipci->io = pci_io;
719 
720  /* Get PCI bus:dev.fn address */
721  if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus,
722  &pci_dev, &pci_fn ) ) != 0 ) {
723  rc = -EEFI ( efirc );
724  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
725  efi_handle_name ( device ), strerror ( rc ) );
726  return rc;
727  }
728  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
729  pci_init ( &efipci->pci, busdevfn );
730  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
731  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
732  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
733 
734  /* Try to enable I/O cycles, memory cycles, and bus mastering.
735  * Some platforms will 'helpfully' report errors if these bits
736  * can't be enabled (for example, if the card doesn't actually
737  * support I/O cycles). Work around any such platforms by
738  * enabling bits individually and simply ignoring any errors.
739  */
746 
747  /* Populate PCI device */
748  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
749  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
750  "configuration: %s\n",
751  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
752  return rc;
753  }
754 
755  return 0;
756 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:214
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
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:312
#define DBGC(...)
Definition: compiler.h:505
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
A hardware device.
Definition: device.h:76
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:60
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:531
EFI_PCI_IO_PROTOCOL_GET_LOCATION GetLocation
Definition: PciIo.h:530
#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:652
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:29
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:311
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:268
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
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
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:453
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:314
#define DBGCP(...)
Definition: compiler.h:539
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:680
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:340
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, 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 771 of file efi_pci.c.

771  {
772  struct efi_pci_device efipci;
773  uint8_t hdrtype;
774  int rc;
775 
776  /* Get PCI device information */
777  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
778  return rc;
779 
780  /* Do not attempt to drive bridges */
781  hdrtype = efipci.pci.hdrtype;
782  if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
783  DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
784  PCI_ARGS ( &efipci.pci ), hdrtype,
786  return -ENOTTY;
787  }
788 
789  /* Look for a driver */
790  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
791  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
792  "has no driver\n", PCI_ARGS ( &efipci.pci ),
793  efipci.pci.vendor, efipci.pci.device,
794  efipci.pci.class );
795  return rc;
796  }
797  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
798  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
799  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
800 
801  return 0;
802 }
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:704
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:378
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:57
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition: pci.h:54
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
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:314

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

810  {
812  int rc;
813 
814  /* Exclude existing PCI I/O protocol drivers */
815  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
816  DBGC ( device, "EFIPCI %s could not exclude drivers: %s\n",
817  efi_handle_name ( device ), strerror ( rc ) );
818  return rc;
819  }
820 
821  return 0;
822 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:312
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
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:78
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:437
uint16_t protocol
Protocol ID.
Definition: stp.h:18

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

830  {
831  EFI_HANDLE device = efidev->device;
832  struct efi_pci_device *efipci;
833  int rc;
834 
835  /* Allocate PCI device */
836  efipci = zalloc ( sizeof ( *efipci ) );
837  if ( ! efipci ) {
838  rc = -ENOMEM;
839  goto err_alloc;
840  }
841 
842  /* Get PCI device information */
843  if ( ( rc = efipci_info ( device, efipci ) ) != 0 )
844  goto err_info;
845 
846  /* Open PCI I/O protocol */
848  &efipci->io ) ) != 0 ) {
849  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
850  efi_handle_name ( device ), strerror ( rc ) );
852  goto err_open;
853  }
854 
855  /* Find driver */
856  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
857  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
858  PCI_ARGS ( &efipci->pci ) );
859  goto err_find_driver;
860  }
861 
862  /* Mark PCI device as a child of the EFI device */
863  efipci->pci.dev.parent = &efidev->dev;
864  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
865 
866  /* Probe driver */
867  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
868  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
869  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
870  efipci->pci.id->name, strerror ( rc ) );
871  goto err_probe;
872  }
873  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
874  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
875 
876  efidev_set_drvdata ( efidev, efipci );
877  return 0;
878 
879  pci_remove ( &efipci->pci );
880  err_probe:
881  list_del ( &efipci->pci.dev.siblings );
882  err_find_driver:
884  err_open:
885  err_info:
886  free ( efipci );
887  err_alloc:
888  return rc;
889 }
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:704
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:378
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:312
#define DBGC(...)
Definition: compiler.h:505
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:344
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device * parent
Bus device.
Definition: device.h:88
struct device dev
Generic device.
Definition: pci.h:212
#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:76
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:473
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:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:311
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:432
const char * name
Name.
Definition: pci.h:176
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
struct list_head children
Devices attached to this device.
Definition: device.h:86
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:314
struct pci_device_id * id
Driver device ID.
Definition: pci.h:247
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:83
struct device dev
Generic device.
Definition: efi_driver.h:19
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:410
Definition: efi.h:61

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

896  {
897  struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
898  EFI_HANDLE device = efidev->device;
899 
900  pci_remove ( &efipci->pci );
901  list_del ( &efipci->pci.dev.siblings );
902  assert ( efipci->pci.dma.mapped == 0 );
903  assert ( efipci->pci.dma.allocated == 0 );
905  free ( efipci );
906 }
struct dma_device dma
DMA device.
Definition: pci.h:214
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:312
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device dev
Generic device.
Definition: pci.h:212
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:76
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:278
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:94
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:432
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
Definition: efi.h:61

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:458
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:653
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition: efi_pci.c:543
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:626
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:572

EFI PCI DMA operations.

Definition at line 680 of file efi_pci.c.

Referenced by efipci_info().