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_discover)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_dword)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_byte)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_word)
 
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_dword)
 
 PROVIDE_PCIAPI (efi, pci_ioremap, efipci_ioremap)
 
static int efipci_dma_map (struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
 Map buffer for DMA. More...
 
static void efipci_dma_unmap (struct dma_device *dma, struct dma_mapping *map)
 Unmap buffer. More...
 
static void * efipci_dma_alloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused)
 Allocate and map DMA-coherent buffer. More...
 
static void efipci_dma_free (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer. More...
 
static userptr_t efipci_dma_umalloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
 Allocate and map DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_ufree (struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len)
 Unmap and free DMA-coherent buffer from external (user) memory. More...
 
static void efipci_dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask. More...
 
int efipci_open (EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
 Open EFI PCI device. More...
 
void efipci_close (EFI_HANDLE device)
 Close EFI PCI device. More...
 
int efipci_info (EFI_HANDLE device, struct efi_pci_device *efipci)
 Get EFI PCI device information. More...
 
static int efipci_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int efipci_start (struct efi_device *efidev)
 Attach driver to device. More...
 
static void efipci_stop (struct efi_device *efidev)
 Detach driver from device. More...
 
struct efi_driver efipci_driver __efi_driver (EFI_DRIVER_NORMAL)
 EFI PCI driver. More...
 

Variables

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

Detailed Description

iPXE PCI I/O API for EFI

Definition in file efi_pci.c.

Macro Definition Documentation

◆ EINFO_EEFI_PCI

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

Definition at line 43 of file efi_pci.c.

◆ EINFO_EEFI_PCI_NOT_PCI

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

Definition at line 46 of file efi_pci.c.

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 49 of file efi_pci.c.

◆ EINFO_EEFI_PCI_IN_USE

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

Definition at line 50 of file efi_pci.c.

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 53 of file efi_pci.c.

◆ EEFI_PCI

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

Definition at line 54 of file efi_pci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efipci_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:279
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:171
struct stp_switch root
Root switch.
Definition: stp.h:26
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
Definition: acpi.h:54
#define DBGC(...)
Definition: compiler.h:505
#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:808
#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:307
#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:233
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
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:278
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:2081
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
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:1344
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
UINT64 UINTN
Unsigned value of native width.
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:287
union @17 u
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1520
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1994

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:2081
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
Definition: efi_guid.c:287
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:281
#define PCI_BUS(busdevfn)
Definition: pci.h:279
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
#define EFIPCI_OFFSET(_location)
Definition: efi_pci_api.h:25
#define PCI_SLOT(busdevfn)
Definition: pci.h:280
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:233

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

Referenced by efipci_read(), and efipci_write().

◆ efipci_read()

int efipci_read ( struct pci_device pci,
unsigned long  location,
void *  value 
)

Read from PCI configuration space.

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

Definition at line 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:171
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:307
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59

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

◆ efipci_write()

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

Write to PCI configuration space.

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

Definition at line 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:171
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:307
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
#define EFIPCI_WIDTH(_location)
Definition: efi_pci_api.h:26
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition: efi_pci.c:211
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59

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

◆ efipci_ioremap()

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

Map PCI bus address as an I/O address.

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

Definition at line 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:171
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 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:307
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
Definition: acpi.h:32
An ACPI resource descriptor.
Definition: acpi.h:85
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
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:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
union @17 u
uint32_t end
Ending offset.
Definition: netvsc.h:18
__be32 raw[7]
Definition: CIB_PRM.h:28
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
static __always_inline void unsigned long bus_addr
Definition: ecam_io.h:135
uint64_t tag
Identity tag.
Definition: edd.h:30
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:59

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

◆ PROVIDE_PCIAPI_INLINE() [1/7]

PROVIDE_PCIAPI_INLINE ( efi  ,
pci_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()

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:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
A read operation from system memory by a bus master.
Definition: PciIo.h:83
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:525
#define DBGC(...)
Definition: compiler.h:505
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:52
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
Definition: uaccess.h: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:526
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
physaddr_t offset
Address offset.
Definition: dma.h:39
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
A PCI device.
Definition: pci.h:206
u32 addr
Definition: sky2.h:8
UINT64 UINTN
Unsigned value of native width.
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:92
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
#define VOID
Undeclared type.
Definition: Base.h:271
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:79
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:135
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
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:310
A write operation from system memory by a bus master.
Definition: PciIo.h:87
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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:210
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:526
physaddr_t offset
Address offset.
Definition: dma.h:39
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
void * token
Platform mapping token.
Definition: dma.h:43
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by efipci_dma_alloc(), and efipci_dma_free().

◆ efipci_dma_alloc()

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

Allocate and map DMA-coherent buffer.

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

Definition at line 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  /* Clear buffer */
528  memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
529 
530  /* Map buffer */
531  if ( ( rc = efipci_dma_map ( dma, map, virt_to_phys ( addr ),
532  ( pages * EFI_PAGE_SIZE ),
533  DMA_BI ) ) != 0 )
534  goto err_map;
535 
536  /* Increment allocation count (for debugging) */
537  if ( DBG_LOG )
538  dma->allocated++;
539 
540  return addr;
541 
542  efipci_dma_unmap ( dma, map );
543  err_map:
544  pci_io->FreeBuffer ( pci_io, pages, addr );
545  err_alloc:
546  return NULL;
547 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c: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:527
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:307
A PCI device.
Definition: pci.h:206
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:271
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:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
Allocate any available range of pages that satisfies the request.
Definition: UefiSpec.h:35
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition: PciIo.h:528
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by efipci_dma_umalloc().

◆ efipci_dma_free()

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

Unmap and free DMA-coherent buffer.

Parameters
dmaDMA device
mapDMA mapping
addrBuffer address
lenLength of buffer

Definition at line 557 of file efi_pci.c.

558  {
559  struct efi_pci_device *efipci =
560  container_of ( dma, struct efi_pci_device, pci.dma );
561  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
562  unsigned int pages;
563 
564  /* Calculate number of pages */
565  pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
566 
567  /* Unmap buffer */
568  efipci_dma_unmap ( dma, map );
569 
570  /* Free buffer */
571  pci_io->FreeBuffer ( pci_io, pages, addr );
572 
573  /* Decrement allocation count (for debugging) */
574  if ( DBG_LOG )
575  dma->allocated--;
576 }
#define EFI_PAGE_SIZE
Definition: UefiBaseType.h:187
struct dma_device dma
DMA device.
Definition: pci.h:210
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
Definition: efi_pci.c: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:528
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define DBG_LOG
Definition: compiler.h:317

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

589  {
590  void *addr;
591 
593  return virt_to_user ( addr );
594 }
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 604 of file efi_pci.c.

605  {
606 
607  efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len );
608 }
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:557

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

616  {
617  struct efi_pci_device *efipci =
618  container_of ( dma, struct efi_pci_device, pci.dma );
619  struct pci_device *pci = &efipci->pci;
620  EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
622  UINT64 attrs;
623  int is64;
624  EFI_STATUS efirc;
625  int rc;
626 
627  /* Set dual address cycle attribute for 64-bit capable devices */
628  is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
632  if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
633  rc = -EEFI ( efirc );
634  DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
635  PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
636  strerror ( rc ) );
637  /* Ignore failure: errors will manifest in mapping attempts */
638  return;
639  }
640 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
Definition: PciIo.h:101
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition: PciIo.h:531
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
A PCI device.
Definition: pci.h:206
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition: PciIo.h:66
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:117
unsigned long long UINT64
Definition: ProcessorBind.h:96
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition: PciIo.h:113
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI PCI device.
Definition: efi_pci.h:21
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

◆ efipci_open()

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

Open EFI PCI device.

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

Definition at line 668 of file efi_pci.c.

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

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

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

◆ efipci_close()

void efipci_close ( EFI_HANDLE  device)

Close EFI PCI device.

Parameters
deviceEFI device handle

Definition at line 745 of file efi_pci.c.

745  {
747 
750 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:283
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
A hardware device.
Definition: device.h:73
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
EFI_SYSTEM_TABLE * efi_systab

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

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

◆ efipci_info()

int efipci_info ( EFI_HANDLE  device,
struct efi_pci_device efipci 
)

Get EFI PCI device information.

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

Definition at line 759 of file efi_pci.c.

759  {
760  int rc;
761 
762  /* Open PCI device, if possible */
764  efipci ) ) != 0 )
765  return rc;
766 
767  /* Close PCI device */
768  efipci_close ( device );
769 
770  return 0;
771 }
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:668
A hardware device.
Definition: device.h:73
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:745

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

786  {
787  struct efi_pci_device efipci;
788  uint8_t hdrtype;
789  int rc;
790 
791  /* Get PCI device information */
792  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
793  return rc;
794 
795  /* Do not attempt to drive bridges */
796  hdrtype = efipci.pci.hdrtype;
797  if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
798  DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
799  PCI_ARGS ( &efipci.pci ), hdrtype,
801  return -ENOTTY;
802  }
803 
804  /* Look for a driver */
805  if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
806  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
807  "has no driver\n", PCI_ARGS ( &efipci.pci ),
808  efipci.pci.vendor, efipci.pci.device,
809  efipci.pci.class );
810  return rc;
811  }
812  DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
813  "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
814  efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
815 
816  return 0;
817 }
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:759
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:292
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition: pci.h:57
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:73
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition: pci.h:54
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:307
unsigned char uint8_t
Definition: stdint.h:10
An EFI PCI device.
Definition: efi_pci.h:21
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310

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

◆ efipci_start()

static int efipci_start ( struct efi_device efidev)
static

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 825 of file efi_pci.c.

825  {
826  EFI_HANDLE device = efidev->device;
827  struct efi_pci_device *efipci;
828  int rc;
829 
830  /* Allocate PCI device */
831  efipci = zalloc ( sizeof ( *efipci ) );
832  if ( ! efipci ) {
833  rc = -ENOMEM;
834  goto err_alloc;
835  }
836 
837  /* Open PCI device */
840  efipci ) ) != 0 ) {
841  DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
842  efi_handle_name ( device ), strerror ( rc ) );
844  goto err_open;
845  }
846 
847  /* Find driver */
848  if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
849  DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
850  PCI_ARGS ( &efipci->pci ) );
851  goto err_find_driver;
852  }
853 
854  /* Mark PCI device as a child of the EFI device */
855  efipci->pci.dev.parent = &efidev->dev;
856  list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
857 
858  /* Probe driver */
859  if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
860  DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
861  "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
862  efipci->pci.id->name, strerror ( rc ) );
863  goto err_probe;
864  }
865  DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
866  PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
867 
868  efidev_set_drvdata ( efidev, efipci );
869  return 0;
870 
871  pci_remove ( &efipci->pci );
872  err_probe:
873  list_del ( &efipci->pci.dev.siblings );
874  err_find_driver:
875  efipci_close ( device );
876  err_open:
877  free ( efipci );
878  err_alloc:
879  return rc;
880 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition: pci.c:292
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:283
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:668
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:321
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
struct device * parent
Bus device.
Definition: device.h:85
struct device dev
Generic device.
Definition: pci.h:208
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
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:307
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition: pci.c:346
const char * name
Name.
Definition: pci.h:172
An EFI PCI device.
Definition: efi_pci.h:21
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:745
struct list_head children
Devices attached to this device.
Definition: device.h:83
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:310
struct pci_device_id * id
Driver device ID.
Definition: pci.h:243
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:74
struct device dev
Generic device.
Definition: efi_driver.h:19
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition: pci.c:324
Definition: efi.h:59

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

◆ efipci_stop()

static void efipci_stop ( struct efi_device efidev)
static

Detach driver from device.

Parameters
efidevEFI device

Definition at line 887 of file efi_pci.c.

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

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

◆ __efi_driver()

struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_NORMAL  )

EFI PCI driver.

Variable Documentation

◆ efipci_dma_operations

struct dma_operations efipci_dma_operations
static
Initial value:
= {
.unmap = efipci_dma_unmap,
.alloc = efipci_dma_alloc,
.free = efipci_dma_free,
.umalloc = efipci_dma_umalloc,
.ufree = efipci_dma_ufree,
.set_mask = efipci_dma_set_mask,
}
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
Definition: efi_pci.c: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:604
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:587
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition: efi_pci.c:616
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:557
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 643 of file efi_pci.c.

Referenced by efipci_open().