iPXE
Macros | Functions | Variables
efi_pci.c File Reference

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

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

Go to the source code of this file.

Macros

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

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int efipci_root_match (struct pci_device *pci, EFI_HANDLE handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root)
 Check for a matching PCI root bridge I/O protocol. More...
 
static int efipci_root_open (struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
 Open EFI PCI root bridge I/O protocol. More...
 
static void efipci_root_close (EFI_HANDLE handle)
 Close EFI PCI root bridge I/O protocol. More...
 
static unsigned long efipci_address (struct pci_device *pci, unsigned long location)
 Calculate EFI PCI configuration space address. More...
 
int efipci_read (struct pci_device *pci, unsigned long location, void *value)
 Read from PCI configuration space. More...
 
int efipci_write (struct pci_device *pci, unsigned long location, unsigned long value)
 Write to PCI configuration space. More...
 
void * efipci_ioremap (struct pci_device *pci, unsigned long bus_addr, size_t len)
 Map PCI bus address as an I/O address. More...
 
 PROVIDE_PCIAPI_INLINE (efi, pci_num_bus)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_dword)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_dword)
 
 PROVIDE_PCIAPI (efi, pci_ioremap, efipci_ioremap)
 
static int efipci_dma_map (struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
 Map buffer for DMA. More...
 
static void efipci_dma_unmap (struct dma_device *dma, struct dma_mapping *map)
 Unmap buffer. More...
 
static void * efipci_dma_alloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
 Allocate and map DMA-coherent buffer. More...
 
static void efipci_dma_free (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer. More...
 
static userptr_t efipci_dma_umalloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
 Allocate and map DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_ufree (struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
 Unmap and free DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask. More...
 
int efipci_open (EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
 Open EFI PCI device. More...
 
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device. More...
 
int efipci_info (EFI_HANDLE device, struct efi_pci_device *efipci)
 Get EFI PCI device information. More...
 
static int efipci_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int efipci_start (struct efi_device *efidev)
 Attach driver to device. More...
 
static void efipci_stop (struct efi_device *efidev)
 Detach driver from device. More...
 
struct efi_driver efipci_driver __efi_driver (EFI_DRIVER_NORMAL)
 EFI PCI driver. More...
 

Variables

static struct dma_operations efipci_dma_operations
 EFI PCI DMA operations. More...
 

Detailed Description

iPXE PCI I/O API for EFI

Definition in file efi_pci.c.

Macro Definition Documentation

◆ EINFO_EEFI_PCI

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

Definition at line 43 of file efi_pci.c.

◆ EINFO_EEFI_PCI_NOT_PCI

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

Definition at line 46 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 49 of file efi_pci.c.

◆ EINFO_EEFI_PCI_IN_USE

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

Definition at line 50 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 53 of file efi_pci.c.

◆ EEFI_PCI

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

Definition at line 54 of file efi_pci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efipci_root_match()

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

Check for a matching PCI root bridge I/O protocol.

Parameters
pciPCI device
handleEFI PCI root bridge handle
rootEFI PCI root bridge I/O protocol
Return values
rcReturn status code

Definition at line 73 of file efi_pci.c.

74  {
75  union {
76  union acpi_resource *res;
77  void *raw;
78  } u;
79  unsigned int segment = PCI_SEG ( pci->busdevfn );
80  unsigned int bus = PCI_BUS ( pci->busdevfn );
81  unsigned int start;
82  unsigned int end;
83  unsigned int tag;
84  EFI_STATUS efirc;
85  int rc;
86 
87  /* Check segment number */
88  if ( root->SegmentNumber != segment )
89  return -ENOENT;
90 
91  /* Get ACPI resource descriptors */
92  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
93  rc = -EEFI ( efirc );
94  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
95  "%s: %s\n", PCI_ARGS ( pci ),
96  efi_handle_name ( handle ), strerror ( rc ) );
97  return rc;
98  }
99 
100  /* Assume success if no bus number range descriptors are found */
101  rc = 0;
102 
103  /* Parse resource descriptors */
104  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
105  u.res = acpi_resource_next ( u.res ) ) {
106 
107  /* Ignore anything other than a bus number range descriptor */
109  continue;
110  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_BUS )
111  continue;
112 
113  /* Check for a matching bus number */
114  start = le64_to_cpu ( u.res->qword.min );
115  end = ( start + le64_to_cpu ( u.res->qword.len ) );
116  if ( ( bus >= start ) && ( bus < end ) )
117  return 0;
118 
119  /* We have seen at least one non-matching range
120  * descriptor, so assume failure unless we find a
121  * subsequent match.
122  */
123  rc = -ENOENT;
124  }
125 
126  return rc;
127 }
#define PCI_BUS(busdevfn)
Definition: pci.h:262
uint16_t segment
Code segment.
Definition: librm.h:252
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:162
struct stp_switch root
Root switch.
Definition: stp.h:26
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:152
uint32_t start
Starting offset.
Definition: netvsc.h:12
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition: acpi.h:104
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
Definition: acpi.h:82
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:293
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
An ACPI resource descriptor.
Definition: acpi.h:85
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:216
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
union @17 u
uint32_t end
Ending offset.
Definition: netvsc.h:18
__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
#define PCI_SEG(busdevfn)
Definition: pci.h:261
uint8_t bus
Bus.
Definition: edd.h:14

References ACPI_ADDRESS_TYPE_BUS, ACPI_END_RESOURCE, ACPI_QWORD_ADDRESS_SPACE_RESOURCE, acpi_resource_next(), acpi_resource_tag(), bus, pci_device::busdevfn, DBGC, EEFI, efi_handle_name(), end, ENOENT, handle, le64_to_cpu, PCI_ARGS, PCI_BUS, PCI_FMT, PCI_SEG, raw, rc, root, segment, start, strerror(), tag, and u.

Referenced by efipci_root_open().

◆ efipci_root_open()

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

Open EFI PCI root bridge I/O protocol.

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

Definition at line 137 of file efi_pci.c.

138  {
140  EFI_HANDLE *handles;
141  UINTN num_handles;
142  union {
143  void *interface;
145  } u;
146  EFI_STATUS efirc;
147  UINTN i;
148  int rc;
149 
150  /* Enumerate all handles */
151  if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
153  NULL, &num_handles, &handles ) ) != 0 ) {
154  rc = -EEFI ( efirc );
155  DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
156  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
157  goto err_locate;
158  }
159 
160  /* Look for matching root bridge I/O protocol */
161  for ( i = 0 ; i < num_handles ; i++ ) {
162  *handle = handles[i];
163  if ( ( efirc = bs->OpenProtocol ( *handle,
165  &u.interface, efi_image_handle, *handle,
166  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
167  rc = -EEFI ( efirc );
168  DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
169  PCI_ARGS ( pci ), efi_handle_name ( *handle ),
170  strerror ( rc ) );
171  continue;
172  }
173  if ( efipci_root_match ( pci, *handle, u.root ) == 0 ) {
174  *root = u.root;
175  bs->FreePool ( handles );
176  return 0;
177  }
178  bs->CloseProtocol ( *handle,
181  }
182  DBGC ( pci, "EFIPCI " PCI_FMT " found no root bridge\n",
183  PCI_ARGS ( pci ) );
184  rc = -ENOENT;
185 
186  bs->FreePool ( handles );
187  err_locate:
188  return rc;
189 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static int efipci_root_match(struct pci_device *pci, EFI_HANDLE handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root)
Check for a matching PCI root bridge I/O protocol.
Definition: efi_pci.c:73
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:220
union @17 u
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:50
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

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

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

◆ efipci_root_close()

static void efipci_root_close ( EFI_HANDLE  handle)
static

Close EFI PCI root bridge I/O protocol.

Parameters
handleEFI PCI root bridge handle

Definition at line 196 of file efi_pci.c.

196  {
198 
199  /* Close protocol */
202 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:220
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:16

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

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

◆ efipci_address()

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

Calculate EFI PCI configuration space address.

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

Definition at line 211 of file efi_pci.c.

212  {
213 
214  return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
215  PCI_SLOT ( pci->busdevfn ),
216  PCI_FUNC ( pci->busdevfn ),
217  EFIPCI_OFFSET ( location ) );
218 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:264
#define PCI_BUS(busdevfn)
Definition: pci.h:262
#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:263
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:216

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

229  {
232  EFI_STATUS efirc;
233  int rc;
234 
235  /* Open root bridge */
236  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
237  goto err_root;
238 
239  /* Read from configuration space */
240  if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
241  efipci_address ( pci, location ), 1,
242  value ) ) != 0 ) {
243  rc = -EEFI ( efirc );
244  DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
245  "failed: %s\n", PCI_ARGS ( pci ),
246  EFIPCI_OFFSET ( location ), strerror ( rc ) );
247  goto err_read;
248  }
249 
250  err_read:
252  err_root:
253  return rc;
254 }
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:162
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:196
struct stp_switch root
Root switch.
Definition: stp.h:26
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:137
#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:293
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:50

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

◆ efipci_write()

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

Write to PCI configuration space.

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

Definition at line 264 of file efi_pci.c.

265  {
268  EFI_STATUS efirc;
269  int rc;
270 
271  /* Open root bridge */
272  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
273  goto err_root;
274 
275  /* Read from configuration space */
276  if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
277  efipci_address ( pci, location ), 1,
278  &value ) ) != 0 ) {
279  rc = -EEFI ( efirc );
280  DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
281  "failed: %s\n", PCI_ARGS ( pci ),
282  EFIPCI_OFFSET ( location ), strerror ( rc ) );
283  goto err_write;
284  }
285 
286  err_write:
288  err_root:
289  return rc;
290 }
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:162
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:196
struct stp_switch root
Root switch.
Definition: stp.h:26
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:137
#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:293
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:50

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

◆ efipci_ioremap()

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

Map PCI bus address as an I/O address.

Parameters
bus_addrPCI bus address
lenLength of region
Return values
io_addrI/O address, or NULL on error

Definition at line 299 of file efi_pci.c.

300  {
301  union {
302  union acpi_resource *res;
303  void *raw;
304  } u;
307  unsigned int tag;
309  uint64_t start;
310  uint64_t end;
311  EFI_STATUS efirc;
312  int rc;
313 
314  /* Open root bridge */
315  if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
316  goto err_root;
317 
318  /* Get ACPI resource descriptors */
319  if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
320  rc = -EEFI ( efirc );
321  DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
322  "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
323  goto err_config;
324  }
325 
326  /* Parse resource descriptors */
327  for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
328  u.res = acpi_resource_next ( u.res ) ) {
329 
330  /* Ignore anything other than a memory range descriptor */
332  continue;
333  if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
334  continue;
335 
336  /* Ignore descriptors that do not cover this memory range */
337  offset = le64_to_cpu ( u.res->qword.offset );
338  start = ( offset + le64_to_cpu ( u.res->qword.min ) );
339  end = ( start + le64_to_cpu ( u.res->qword.len ) );
340  DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
341  "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
342  ( start - offset ), ( end - offset ) );
343  if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
344  continue;
345 
346  /* Use this address space descriptor */
347  DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
348  PCI_ARGS ( pci ), bus_addr, len );
349  bus_addr -= offset;
350  DBGC2 ( pci, "%08lx\n", bus_addr );
351  break;
352  }
353  if ( tag == ACPI_END_RESOURCE ) {
354  DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
355  "root bridge address space\n",
356  PCI_ARGS ( pci ), bus_addr, len );
357  }
358 
359  err_config:
361  err_root:
362  return ioremap ( bus_addr, len );
363 }
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:162
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:196
struct stp_switch root
Root switch.
Definition: stp.h:26
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol.
Definition: efi_pci.c:137
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition: acpi.h:152
uint32_t start
Starting offset.
Definition: netvsc.h:12
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition: acpi.h:104
static __always_inline void unsigned long bus_addr
Definition: linux_pci.h:150
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
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:293
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
An ACPI resource descriptor.
Definition: acpi.h:85
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition: acpi.h:79
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
union @17 u
uint32_t end
Ending offset.
Definition: netvsc.h:18
__be32 raw[7]
Definition: CIB_PRM.h:28
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:50

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

◆ PROVIDE_PCIAPI_INLINE() [1/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_num_bus   
)

◆ PROVIDE_PCIAPI_INLINE() [2/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_byte   
)

◆ PROVIDE_PCIAPI_INLINE() [3/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_word   
)

◆ PROVIDE_PCIAPI_INLINE() [4/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_read_config_dword   
)

◆ PROVIDE_PCIAPI_INLINE() [5/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_byte   
)

◆ PROVIDE_PCIAPI_INLINE() [6/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_word   
)

◆ PROVIDE_PCIAPI_INLINE() [7/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_write_config_dword   
)

◆ PROVIDE_PCIAPI()

PROVIDE_PCIAPI ( efi  ,
pci_ioremap  ,
efipci_ioremap   
)

◆ efipci_dma_map()

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

Map buffer for DMA.

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

Definition at line 391 of file efi_pci.c.

392  {
393  struct efi_pci_device *efipci =
394  container_of ( dma, struct efi_pci_device, pci.dma );
395  struct pci_device *pci = &efipci->pci;
396  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
399  UINTN count;
400  VOID *mapping;
401  EFI_STATUS efirc;
402  int rc;
403 
404  /* Sanity check */
405  assert ( map->dma == NULL );
406  assert ( map->offset == 0 );
407  assert ( map->token == NULL );
408 
409  /* Determine operation */
410  switch ( flags ) {
411  case DMA_TX:
413  break;
414  case DMA_RX:
416  break;
417  default:
419  break;
420  }
421 
422  /* Map buffer (if non-zero length) */
423  count = len;
424  if ( len ) {
425  if ( ( efirc = pci_io->Map ( pci_io, op, phys_to_virt ( addr ),
426  &count, &bus, &mapping ) ) != 0 ) {
427  rc = -EEFI ( efirc );
428  DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %08lx+%zx: "
429  "%s\n", PCI_ARGS ( pci ), addr, len,
430  strerror ( rc ) );
431  goto err_map;
432  }
433  } else {
434  bus = addr;
435  mapping = NULL;
436  }
437 
438  /* Check that full length was mapped. The UEFI specification
439  * allows for multiple mappings to be required, but even the
440  * EDK2 PCI device drivers will fail if a platform ever
441  * requires this.
442  */
443  if ( count != len ) {
444  DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
445  "%08lx+%zx\n", PCI_ARGS ( pci ), addr, len );
446  rc = -ENOTSUP;
447  goto err_len;
448  }
449 
450  /* Populate mapping */
451  map->dma = dma;
452  map->offset = ( bus - addr );
453  map->token = mapping;
454 
455  /* Increment mapping count (for debugging) */
456  if ( DBG_LOG )
457  dma->mapped++;
458 
459  return 0;
460 
461  err_len:
462  pci_io->Unmap ( pci_io, mapping );
463  err_map:
464  return rc;
465 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:195
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
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:89
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:532
#define DBGC(...)
Definition: compiler.h:505
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:56
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h:299
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:132
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:533
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:293
A PCI device.
Definition: pci.h:191
u32 addr
Definition: sky2.h:8
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:98
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define VOID
Undeclared type.
Definition: Base.h:319
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:85
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:135
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
void * token
Platform mapping token.
Definition: dma.h:43
uint16_t count
Number of entries.
Definition: ena.h:22
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
A write operation from system memory by a bus master.
Definition: PciIo.h:93
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint8_t bus
Bus.
Definition: edd.h:14
uint8_t flags
Flags.
Definition: ena.h:18

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

Referenced by efipci_dma_alloc().

◆ efipci_dma_unmap()

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

Unmap buffer.

Parameters
dmaDMA device
mapDMA mapping

Definition at line 473 of file efi_pci.c.

474  {
475  struct efi_pci_device *efipci =
476  container_of ( dma, struct efi_pci_device, pci.dma );
477  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
478 
479  /* Unmap buffer (if non-zero length) */
480  if ( map->token )
481  pci_io->Unmap ( pci_io, map->token );
482 
483  /* Clear mapping */
484  map->dma = NULL;
485  map->offset = 0;
486  map->token = NULL;
487 
488  /* Decrement mapping count (for debugging) */
489  if ( DBG_LOG )
490  dma->mapped--;
491 }
struct dma_device dma
DMA device.
Definition: pci.h:195
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:533
physaddr_t offset
Address offset.
Definition: dma.h:39
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
void * token
Platform mapping token.
Definition: dma.h:43
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

504  {
505  struct efi_pci_device *efipci =
506  container_of ( dma, struct efi_pci_device, pci.dma );
507  struct pci_device *pci = &efipci->pci;
508  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
509  unsigned int pages;
510  VOID *addr;
511  EFI_STATUS efirc;
512  int rc;
513 
514  /* Calculate number of pages */
515  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
516 
517  /* Allocate (page-aligned) buffer */
518  if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
519  EfiBootServicesData, pages,
520  &addr, 0 ) ) != 0 ) {
521  rc = -EEFI ( efirc );
522  DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
523  "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
524  goto err_alloc;
525  }
526 
527  /* Map buffer */
528  if ( ( rc = efipci_dma_map ( dma, map, virt_to_phys ( addr ),
529  ( pages * EFI_PAGE_SIZE ),
530  DMA_BI ) ) != 0 )
531  goto err_map;
532 
533  /* Increment allocation count (for debugging) */
534  if ( DBG_LOG )
535  dma->allocated++;
536 
537  return addr;
538 
539  efipci_dma_unmap ( dma, map );
540  err_map:
541  pci_io->FreeBuffer ( pci_io, pages, addr );
542  err_alloc:
543  return NULL;
544 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:191
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:195
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:391
#define DBGC(...)
Definition: compiler.h:505
#define DMA_BI
Device will both read data from and write data to host memory.
Definition: dma.h:138
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition: PciIo.h:534
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:473
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
A PCI device.
Definition: pci.h:191
u32 addr
Definition: sky2.h:8
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define VOID
Undeclared type.
Definition: Base.h:319
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:38
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:535
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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, NULL, efi_pci_device::pci, PCI_ARGS, PCI_FMT, rc, strerror(), virt_to_phys(), and VOID.

Referenced by efipci_dma_umalloc().

◆ efipci_dma_free()

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

Unmap and free DMA-coherent buffer.

Parameters
dmaDMA device
mapDMA mapping
addrBuffer address
lenLength of buffer

Definition at line 554 of file efi_pci.c.

555  {
556  struct efi_pci_device *efipci =
557  container_of ( dma, struct efi_pci_device, pci.dma );
558  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
559  unsigned int pages;
560 
561  /* Calculate number of pages */
562  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
563 
564  /* Unmap buffer */
565  efipci_dma_unmap ( dma, map );
566 
567  /* Free buffer */
568  pci_io->FreeBuffer ( pci_io, pages, addr );
569 
570  /* Decrement allocation count (for debugging) */
571  if ( DBG_LOG )
572  dma->allocated--;
573 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:191
struct dma_device dma
DMA device.
Definition: pci.h:195
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:473
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
u32 addr
Definition: sky2.h:8
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
uint32_t len
Length.
Definition: ena.h:14
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:535
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define DBG_LOG
Definition: compiler.h:317

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

Referenced by efipci_dma_ufree().

◆ efipci_dma_umalloc()

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

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

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

Definition at line 584 of file efi_pci.c.

586  {
587  void *addr;
588 
590  return virt_to_user ( addr );
591 }
static __always_inline void struct dma_mapping size_t size_t align
Definition: dma.h:222
u32 addr
Definition: sky2.h:8
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
uint32_t len
Length.
Definition: ena.h:14
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
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:502

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

◆ efipci_dma_ufree()

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

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

Parameters
dmaDMA device
mapDMA mapping
addrBuffer address
lenLength of buffer

Definition at line 601 of file efi_pci.c.

602  {
603 
604  efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
605 }
u32 addr
Definition: sky2.h:8
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
uint32_t len
Length.
Definition: ena.h:14
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
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:554

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

◆ efipci_dma_set_mask()

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

Set addressable space mask.

Parameters
dmaDMA device
maskAddressable space mask

Definition at line 613 of file efi_pci.c.

613  {
614  struct efi_pci_device *efipci =
615  container_of ( dma, struct efi_pci_device, pci.dma );
616  struct pci_device *pci = &efipci->pci;
617  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
619  UINT64 attrs;
620  int is64;
621  EFI_STATUS efirc;
622  int rc;
623 
624  /* Set dual address cycle attribute for 64-bit capable devices */
625  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
629  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
630  rc = -EEFI ( efirc );
631  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
632  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
633  strerror ( rc ) );
634  /* Ignore failure: errors will manifest in mapping attempts */
635  return;
636  }
637 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:195
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
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:107
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:538
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
A PCI device.
Definition: pci.h:191
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition: PciIo.h:72
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:123
unsigned long long UINT64
Definition: ProcessorBind.h:54
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:119
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:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

◆ efipci_open()

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

Open EFI PCI device.

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

Definition at line 665 of file efi_pci.c.

666  {
668  union {
669  EFI_PCI_IO_PROTOCOL *pci_io;
670  void *interface;
671  } pci_io;
672  UINTN pci_segment, pci_bus, pci_dev, pci_fn;
673  unsigned int busdevfn;
674  EFI_STATUS efirc;
675  int rc;
676 
677  /* See if device is a PCI device */
678  if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
679  &pci_io.interface, efi_image_handle,
680  device, attributes ) ) != 0 ) {
681  rc = -EEFI_PCI ( efirc );
682  DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
683  efi_handle_name ( device ), strerror ( rc ) );
684  goto err_open_protocol;
685  }
686  efipci->io = pci_io.pci_io;
687 
688  /* Get PCI bus:dev.fn address */
689  if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
690  &pci_bus, &pci_dev,
691  &pci_fn ) ) != 0 ) {
692  rc = -EEFI ( efirc );
693  DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
694  efi_handle_name ( device ), strerror ( rc ) );
695  goto err_get_location;
696  }
697  busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
698  pci_init ( &efipci->pci, busdevfn );
699  dma_init ( &efipci->pci.dma, &efipci_dma_operations );
700  DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
701  PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
702 
703  /* Try to enable I/O cycles, memory cycles, and bus mastering.
704  * Some platforms will 'helpfully' report errors if these bits
705  * can't be enabled (for example, if the card doesn't actually
706  * support I/O cycles). Work around any such platforms by
707  * enabling bits individually and simply ignoring any errors.
708  */
709  pci_io.pci_io->Attributes ( pci_io.pci_io,
712  pci_io.pci_io->Attributes ( pci_io.pci_io,
715  pci_io.pci_io->Attributes ( pci_io.pci_io,
718 
719  /* Populate PCI device */
720  if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
721  DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
722  "configuration: %s\n",
723  PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
724  goto err_pci_read_config;
725  }
726 
727  return 0;
728 
729  err_pci_read_config:
730  err_get_location:
733  err_open_protocol:
734  return rc;
735 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:195
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
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:216
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition: dma.h:461
#define DBGC(...)
Definition: compiler.h:505
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci.h:265
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition: PciIo.h:66
An object interface.
Definition: interface.h:124
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition: PciIo.h:67
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:177
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition: PciIo.h:65
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:119
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define EEFI_PCI(efirc)
Definition: efi_pci.c:54
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition: efi_pci.c:640
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:319
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

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

◆ efipci_close()

void efipci_close ( EFI_HANDLE  device)

Close EFI PCI device.

Parameters
deviceEFI device handle

Definition at line 742 of file efi_pci.c.

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

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

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

◆ efipci_info()

int efipci_info ( EFI_HANDLE  device,
struct 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 756 of file efi_pci.c.

756  {
757  int rc;
758 
759  /* Open PCI device, if possible */
761  efipci ) ) != 0 )
762  return rc;
763 
764  /* Close PCI device */
765  efipci_close ( device );
766 
767  return 0;
768 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:665
A hardware device.
Definition: device.h:73
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:742

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

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

◆ efipci_supported()

static int efipci_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 783 of file efi_pci.c.

783  {
784  struct efi_pci_device efipci;
785  int rc;
786 
787  /* Get PCI device information */
788  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
789  return rc;
790 
791  /* Look for a driver */
792  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
793  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
794  "has no driver\n", PCI_ARGS ( &efipci.pci ),
795  efipci.pci.vendor, efipci.pci.device,
796  efipci.pci.class );
797  return rc;
798  }
799  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
800  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
801  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
802 
803  return 0;
804 }
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:756
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:277
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:73
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
An EFI PCI device.
Definition: efi_pci.h:21
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296

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

◆ efipci_start()

static int efipci_start ( struct efi_device efidev)
static

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 812 of file efi_pci.c.

812  {
813  EFI_HANDLE device = efidev->device;
814  struct efi_pci_device *efipci;
815  int rc;
816 
817  /* Allocate PCI device */
818  efipci = zalloc ( sizeof ( *efipci ) );
819  if ( ! efipci ) {
820  rc = -ENOMEM;
821  goto err_alloc;
822  }
823 
824  /* Open PCI device */
827  efipci ) ) != 0 ) {
828  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
829  efi_handle_name ( device ), strerror ( rc ) );
831  goto err_open;
832  }
833 
834  /* Find driver */
835  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
836  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
837  PCI_ARGS ( &efipci->pci ) );
838  goto err_find_driver;
839  }
840 
841  /* Mark PCI device as a child of the EFI device */
842  efipci->pci.dev.parent = &efidev->dev;
843  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
844 
845  /* Probe driver */
846  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
847  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
848  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
849  efipci->pci.id->name, strerror ( rc ) );
850  goto err_probe;
851  }
852  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
853  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
854 
855  efidev_set_drvdata ( efidev, efipci );
856  return 0;
857 
858  pci_remove ( &efipci->pci );
859  err_probe:
860  list_del ( &efipci->pci.dev.siblings );
861  err_find_driver:
862  efipci_close ( device );
863  err_open:
864  free ( efipci );
865  err_alloc:
866  return rc;
867 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:277
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:216
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:665
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:286
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device * parent
Bus device.
Definition: device.h:85
struct device dev
Generic device.
Definition: pci.h:193
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:293
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:331
const char * name
Name.
Definition: pci.h:157
An EFI PCI device.
Definition: efi_pci.h:21
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:742
struct list_head children
Devices attached to this device.
Definition: device.h:83
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:296
struct pci_device_id * id
Driver device ID.
Definition: pci.h:226
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:72
struct device dev
Generic device.
Definition: efi_driver.h:19
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:309
Definition: efi.h:50

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

◆ efipci_stop()

static void efipci_stop ( struct efi_device efidev)
static

Detach driver from device.

Parameters
efidevEFI device

Definition at line 874 of file efi_pci.c.

874  {
875  struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
876  EFI_HANDLE device = efidev->device;
877 
878  pci_remove ( &efipci->pci );
879  list_del ( &efipci->pci.dev.siblings );
880  assert ( efipci->pci.dma.mapped == 0 );
881  assert ( efipci->pci.dma.allocated == 0 );
882  efipci_close ( device );
883  free ( efipci );
884 }
struct dma_device dma
DMA device.
Definition: pci.h:195
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device dev
Generic device.
Definition: pci.h:193
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:73
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:331
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:53
An EFI PCI device.
Definition: efi_pci.h:21
unsigned int allocated
Total number of allocations (for debugging)
Definition: dma.h:55
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:742
Definition: efi.h:50

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

◆ __efi_driver()

struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI PCI driver.

Variable Documentation

◆ efipci_dma_operations

struct dma_operations efipci_dma_operations
static
Initial value:
= {
.unmap = efipci_dma_unmap,
.alloc = efipci_dma_alloc,
.free = efipci_dma_free,
.umalloc = efipci_dma_umalloc,
.ufree = efipci_dma_ufree,
.set_mask = efipci_dma_set_mask,
}
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c:391
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c:473
static void efipci_dma_ufree(struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:601
static userptr_t efipci_dma_umalloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer from external (user) memory.
Definition: efi_pci.c:584
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:613
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:554
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:502

EFI PCI DMA operations.

Definition at line 640 of file efi_pci.c.

Referenced by efipci_open().