iPXE
efi_pci.c File Reference

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

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

Go to the source code of this file.

Macros

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

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int efipci_discover_one (struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range)
 Find closest bus:dev.fn address range within a root bridge.
static int efipci_discover_any (struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
 Find closest bus:dev.fn address range within any root bridge.
static void efipci_discover (uint32_t busdevfn, struct pci_range *range)
 Find next PCI bus:dev.fn address range in system.
static int efipci_root_open (struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
 Open EFI PCI root bridge I/O protocol for ephemeral use.
static unsigned long efipci_address (struct pci_device *pci, unsigned long location)
 Calculate EFI PCI configuration space address.
int efipci_read (struct pci_device *pci, unsigned long location, void *value)
 Read from PCI configuration space.
int efipci_write (struct pci_device *pci, unsigned long location, unsigned long value)
 Write to PCI configuration space.
void * efipci_ioremap (struct pci_device *pci, unsigned long bus_addr, size_t len)
 Map PCI bus address as an I/O address.
 PROVIDE_PCIAPI_INLINE (efi, pci_can_probe)
 PROVIDE_PCIAPI (efi, pci_discover, efipci_discover)
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_byte)
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_word)
 PROVIDE_PCIAPI_INLINE (efi, pci_read_config_dword)
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_byte)
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_word)
 PROVIDE_PCIAPI_INLINE (efi, pci_write_config_dword)
 PROVIDE_PCIAPI (efi, pci_ioremap, efipci_ioremap)
 PROVIDE_PCIAPI_RUNTIME (efi, PCIAPI_PRIORITY_EFI)
static int efipci_dma_map (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len, int flags)
 Map buffer for DMA.
static void efipci_dma_unmap (struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
 Unmap buffer.
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.
static void efipci_dma_free (struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer.
static void efipci_dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask.
int efipci_info (EFI_HANDLE device, struct efi_pci_device *efipci)
 Get EFI PCI device information.
static int efipci_supported (EFI_HANDLE device)
 Check to see if driver supports a device.
static int efipci_exclude (EFI_HANDLE device)
 Exclude existing drivers.
static int efipci_start (struct efi_device *efidev)
 Attach driver to device.
static void efipci_stop (struct efi_device *efidev)
 Detach driver from device.
struct efi_driver efipci_driver __efi_driver (EFI_DRIVER_HARDWARE)
 EFI PCI driver.

Variables

static struct dma_operations efipci_dma_operations
 EFI PCI DMA operations.

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_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition errno.h:181
#define EINFO_EPLATFORM
Platform-generated base error.
Definition errno.h:692

Definition at line 45 of file efi_pci.c.

45#define EINFO_EEFI_PCI \
46 __einfo_uniqify ( EINFO_EPLATFORM, 0x01, \
47 "Could not open PCI I/O protocol" )

◆ EINFO_EEFI_PCI_NOT_PCI

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

Definition at line 48 of file efi_pci.c.

48#define EINFO_EEFI_PCI_NOT_PCI \
49 __einfo_platformify ( EINFO_EEFI_PCI, EFI_UNSUPPORTED, \
50 "Not a PCI device" )

◆ EEFI_PCI_NOT_PCI

#define EEFI_PCI_NOT_PCI   __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )

Definition at line 51 of file efi_pci.c.

◆ EINFO_EEFI_PCI_IN_USE

#define EINFO_EEFI_PCI_IN_USE
Value:
"PCI device already has a driver" )
#define EFI_ACCESS_DENIED
Enumeration of EFI_STATUS.

Definition at line 52 of file efi_pci.c.

52#define EINFO_EEFI_PCI_IN_USE \
53 __einfo_platformify ( EINFO_EEFI_PCI, EFI_ACCESS_DENIED, \
54 "PCI device already has a driver" )

◆ EEFI_PCI_IN_USE

#define EEFI_PCI_IN_USE   __einfo_error ( EINFO_EEFI_PCI_IN_USE )

Definition at line 55 of file efi_pci.c.

◆ EEFI_PCI

#define EEFI_PCI ( efirc)
Value:
#define EEFI_PCI_IN_USE
Definition efi_pci.c:55
#define EEFI_PCI_NOT_PCI
Definition efi_pci.c:51
#define EPLATFORM(einfo_base, platform,...)
Generate an error based on an external platform error code.
Definition errno.h:249

Definition at line 56 of file efi_pci.c.

56#define EEFI_PCI( efirc ) \
57 EPLATFORM ( EINFO_EEFI_PCI, efirc, \
58 EEFI_PCI_NOT_PCI, EEFI_PCI_IN_USE )

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efipci_discover_one()

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

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

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

Definition at line 75 of file efi_pci.c.

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

References acpi, ACPI_ADDRESS_TYPE_BUS, ACPI_END_RESOURCE, ACPI_QWORD_ADDRESS_SPACE_RESOURCE, acpi_resource_next(), acpi_resource_tag(), pci_device::busdevfn, count, DBGC, DBGC2, EEFI, EFI_HANDLE, efi_handle_name(), efi_open, efi_pci_root_bridge_io_protocol_guid, handle, index, le64_to_cpu, PCI_ARGS, PCI_BUS, PCI_BUSDEVFN, PCI_FMT, range, raw, rc, root, start, strerror(), and tag.

Referenced by efipci_discover_any().

◆ efipci_discover_any()

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

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

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

Definition at line 166 of file efi_pci.c.

168 {
169 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
170 uint32_t best = 0;
172 struct pci_range tmp;
173 EFI_HANDLE *handles;
174 UINTN num_handles;
175 UINTN i;
176 EFI_STATUS efirc;
177 int rc;
178
179 /* Return an empty range and no handle on error */
180 range->start = 0;
181 range->count = 0;
182 *handle = NULL;
183
184 /* Enumerate all root bridge I/O protocol handles */
185 if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
187 NULL, &num_handles, &handles ) ) != 0 ) {
188 rc = -EEFI ( efirc );
189 DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
190 "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
191 goto err_locate;
192 }
193
194 /* Iterate over all root bridge I/O protocols */
195 for ( i = 0 ; i < num_handles ; i++ ) {
196
197 /* Get matching or closest range for this root bridge */
198 if ( ( rc = efipci_discover_one ( pci, handles[i],
199 &tmp ) ) != 0 )
200 continue;
201
202 /* Check for a matching or new closest range */
203 index = ( pci->busdevfn - tmp.start );
204 if ( ( index < tmp.count ) || ( index > best ) ) {
205 range->start = tmp.start;
206 range->count = tmp.count;
207 best = index;
208 }
209
210 /* Stop if this range contains the target bus:dev.fn address */
211 if ( index < tmp.count ) {
212 *handle = handles[i];
213 break;
214 }
215 }
216
217 /* Check for a range containing the target bus:dev.fn address */
218 if ( ! *handle ) {
219 rc = -ENOENT;
220 goto err_range;
221 }
222
223 /* Success */
224 rc = 0;
225
226 err_range:
227 bs->FreePool ( handles );
228 err_locate:
229 return rc;
230}
UINT64 UINTN
Unsigned value of native width.
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
@ ByProtocol
Retrieve the set of handles from the handle database that support a specified protocol.
Definition UefiSpec.h:1531
static int efipci_discover_one(struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range)
Find closest bus:dev.fn address range within a root bridge.
Definition efi_pci.c:75
#define ENOENT
No such file or directory.
Definition errno.h:515
#define EFI_HANDLE
Definition efi.h:53
EFI_SYSTEM_TABLE * efi_systab
unsigned long tmp
Definition linux_pci.h:65
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_FREE_POOL FreePool
Definition UefiSpec.h:1950
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition UefiSpec.h:2008
A PCI bus:dev.fn address range.
Definition pci_io.h:23

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

Referenced by efipci_discover(), and efipci_root_open().

◆ efipci_discover()

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

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

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

Definition at line 238 of file efi_pci.c.

238 {
239 struct pci_device pci;
241
242 /* Find range */
243 memset ( &pci, 0, sizeof ( pci ) );
244 pci_init ( &pci, busdevfn );
245 efipci_discover_any ( &pci, range, &handle );
246}
static int efipci_discover_any(struct pci_device *pci, struct pci_range *range, EFI_HANDLE *handle)
Find closest bus:dev.fn address range within any root bridge.
Definition efi_pci.c:166
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
void * memset(void *dest, int character, size_t len) __nonnull
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition pci.h:341
A PCI device.
Definition pci.h:211

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

Referenced by PROVIDE_PCIAPI().

◆ efipci_root_open()

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

Open EFI PCI root bridge I/O protocol for ephemeral use.

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

Definition at line 256 of file efi_pci.c.

257 {
258 static struct {
259 struct pci_range range;
261 } cache;
262 int rc;
263
264 /* Find and cache matching root bridge I/O protocol handle, if any */
265 if ( ( pci->busdevfn - cache.range.start ) >= cache.range.count )
266 efipci_discover_any ( pci, &cache.range, &cache.handle );
267 if ( ! cache.handle )
268 return -ENOENT;
269 *handle = cache.handle;
270
271 /* Open PCI root bridge I/O protocol */
273 root ) ) != 0 ) {
274 DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
275 PCI_ARGS ( pci ), efi_handle_name ( *handle ),
276 strerror ( rc ) );
277 return rc;
278 }
279
280 return 0;
281}

References pci_device::busdevfn, DBGC, EFI_HANDLE, efi_handle_name(), efi_open, efi_pci_root_bridge_io_protocol_guid, efipci_discover_any(), ENOENT, handle, PCI_ARGS, PCI_FMT, range, rc, root, and strerror().

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

◆ efipci_address()

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

291 {
292
293 return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
294 PCI_SLOT ( pci->busdevfn ),
295 PCI_FUNC ( pci->busdevfn ),
296 EFIPCI_OFFSET ( location ) );
297}
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
#define EFIPCI_OFFSET(_location)
Definition efi_pci_api.h:26
#define PCI_FUNC(busdevfn)
Definition pci.h:286
#define PCI_SLOT(busdevfn)
Definition pci.h:285

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

308 {
311 EFI_STATUS efirc;
312 int rc;
313
314 /* Open root bridge */
315 if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
316 return rc;
317
318 /* Read from configuration space */
319 if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
320 efipci_address ( pci, location ), 1,
321 value ) ) != 0 ) {
322 rc = -EEFI ( efirc );
323 DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
324 "failed: %s\n", PCI_ARGS ( pci ),
325 EFIPCI_OFFSET ( location ), strerror ( rc ) );
326 return rc;
327 }
328
329 return 0;
330}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
Definition efi_pci.c:290
static int efipci_root_open(struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root)
Open EFI PCI root bridge I/O protocol for ephemeral use.
Definition efi_pci.c:256
#define EFIPCI_WIDTH(_location)
Definition efi_pci_api.h:27

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

◆ efipci_write()

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

Write to PCI configuration space.

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

Definition at line 340 of file efi_pci.c.

341 {
344 EFI_STATUS efirc;
345 int rc;
346
347 /* Open root bridge */
348 if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
349 return rc;
350
351 /* Read from configuration space */
352 if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
353 efipci_address ( pci, location ), 1,
354 &value ) ) != 0 ) {
355 rc = -EEFI ( efirc );
356 DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
357 "failed: %s\n", PCI_ARGS ( pci ),
358 EFIPCI_OFFSET ( location ), strerror ( rc ) );
359 return rc;
360 }
361
362 return 0;
363}

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

Referenced by PCIAPI_INLINE(), PCIAPI_INLINE(), and PCIAPI_INLINE().

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

373 {
374 union {
375 union acpi_resource *res;
376 void *raw;
377 } u;
380 unsigned int tag;
384 EFI_STATUS efirc;
385 int rc;
386
387 /* Open root bridge */
388 if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
389 goto err_root;
390
391 /* Get ACPI resource descriptors */
392 if ( ( efirc = root->Configuration ( root, &u.raw ) ) != 0 ) {
393 rc = -EEFI ( efirc );
394 DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration: "
395 "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
396 goto err_config;
397 }
398
399 /* Parse resource descriptors */
400 for ( ; ( ( tag = acpi_resource_tag ( u.res ) ) != ACPI_END_RESOURCE ) ;
401 u.res = acpi_resource_next ( u.res ) ) {
402
403 /* Ignore anything other than a memory range descriptor */
405 continue;
406 if ( u.res->qword.type != ACPI_ADDRESS_TYPE_MEM )
407 continue;
408
409 /* Ignore descriptors that do not cover this memory range */
410 offset = le64_to_cpu ( u.res->qword.offset );
411 start = ( offset + le64_to_cpu ( u.res->qword.min ) );
412 end = ( start + le64_to_cpu ( u.res->qword.len ) );
413 DBGC2 ( pci, "EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
414 "-> [%08llx,%08llx)\n", PCI_ARGS ( pci ), start, end,
415 ( start - offset ), ( end - offset ) );
416 if ( ( bus_addr < start ) || ( ( bus_addr + len ) > end ) )
417 continue;
418
419 /* Use this address space descriptor */
420 DBGC2 ( pci, "EFIPCI " PCI_FMT " %08lx+%zx -> ",
421 PCI_ARGS ( pci ), bus_addr, len );
422 bus_addr -= offset;
423 DBGC2 ( pci, "%08lx\n", bus_addr );
424 break;
425 }
426 if ( tag == ACPI_END_RESOURCE ) {
427 DBGC ( pci, "EFIPCI " PCI_FMT " %08lx+%zx is not within "
428 "root bridge address space\n",
429 PCI_ARGS ( pci ), bus_addr, len );
430 }
431
432 err_config:
433 err_root:
434 return ioremap ( bus_addr, len );
435}
unsigned long long uint64_t
Definition stdint.h:13
uint16_t offset
Offset to command line.
Definition bzimage.h:3
union @104331263140136355135267063077374276003064103115 u
ring len
Length.
Definition dwmac.h:226
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition acpi.h:37
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
uint32_t end
Ending offset.
Definition netvsc.h:7
static __always_inline void unsigned long bus_addr
Definition pcibios.h:156

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

Referenced by PROVIDE_PCIAPI().

◆ PROVIDE_PCIAPI_INLINE() [1/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_can_probe  )

References pci_can_probe().

◆ PROVIDE_PCIAPI() [1/2]

PROVIDE_PCIAPI ( efi ,
pci_discover ,
efipci_discover  )

◆ PROVIDE_PCIAPI_INLINE() [2/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_read_config_byte  )

◆ PROVIDE_PCIAPI_INLINE() [3/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_read_config_word  )

◆ PROVIDE_PCIAPI_INLINE() [4/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_read_config_dword  )

◆ PROVIDE_PCIAPI_INLINE() [5/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_write_config_byte  )

◆ PROVIDE_PCIAPI_INLINE() [6/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_write_config_word  )

◆ PROVIDE_PCIAPI_INLINE() [7/7]

PROVIDE_PCIAPI_INLINE ( efi ,
pci_write_config_dword  )

◆ PROVIDE_PCIAPI() [2/2]

PROVIDE_PCIAPI ( efi ,
pci_ioremap ,
efipci_ioremap  )

References efipci_ioremap(), and pci_ioremap().

◆ PROVIDE_PCIAPI_RUNTIME()

PROVIDE_PCIAPI_RUNTIME ( efi ,
PCIAPI_PRIORITY_EFI  )

References PCIAPI_PRIORITY_EFI.

◆ efipci_dma_map()

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

Map buffer for DMA.

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

Definition at line 465 of file efi_pci.c.

466 {
467 struct efi_pci_device *efipci =
469 struct pci_device *pci = &efipci->pci;
470 EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
473 UINTN count;
474 VOID *mapping;
476 EFI_STATUS efirc;
477 int rc;
478
479 /* Sanity check */
480 assert ( map->dma == NULL );
481 assert ( map->offset == 0 );
482 assert ( map->token == NULL );
483
484 /* Determine operation */
485 switch ( flags ) {
486 case DMA_TX:
488 break;
489 case DMA_RX:
491 break;
492 default:
494 break;
495 }
496
497 /* Map buffer (if non-zero length) */
498 phys = virt_to_phys ( addr );
499 count = len;
500 if ( len ) {
501 if ( ( efirc = pci_io->Map ( pci_io, op, addr, &count, &bus,
502 &mapping ) ) != 0 ) {
503 rc = -EEFI ( efirc );
504 DBGC ( pci, "EFIPCI " PCI_FMT " cannot map %p+%zx: "
505 "%s\n", PCI_ARGS ( pci ), addr, len,
506 strerror ( rc ) );
507 goto err_map;
508 }
509 } else {
510 bus = phys;
511 mapping = NULL;
512 }
513
514 /* Check that full length was mapped. The UEFI specification
515 * allows for multiple mappings to be required, but even the
516 * EDK2 PCI device drivers will fail if a platform ever
517 * requires this.
518 */
519 if ( count != len ) {
520 DBGC ( pci, "EFIPCI " PCI_FMT " attempted split mapping for "
521 "%p+%zx\n", PCI_ARGS ( pci ), addr, len );
522 rc = -ENOTSUP;
523 goto err_len;
524 }
525
526 /* Populate mapping */
527 map->dma = dma;
528 map->offset = ( bus - phys );
529 map->token = mapping;
530
531 /* Increment mapping count (for debugging) */
532 if ( DBG_LOG )
533 dma->mapped++;
534
535 return 0;
536
537 err_len:
538 pci_io->Unmap ( pci_io, mapping );
539 err_map:
540 return rc;
541}
#define VOID
Undeclared type.
Definition Base.h:272
EFI_PCI_IO_PROTOCOL_OPERATION
Definition PciIo.h:80
@ EfiPciIoOperationBusMasterWrite
A write operation from system memory by a bus master.
Definition PciIo.h:88
@ EfiPciIoOperationBusMasterRead
A read operation from system memory by a bus master.
Definition PciIo.h:84
@ EfiPciIoOperationBusMasterCommonBuffer
Provides both read and write access to system memory by both the processor and a bus master.
Definition PciIo.h:93
struct _EFI_PCI_IO_PROTOCOL EFI_PCI_IO_PROTOCOL
Definition PciIo.h:24
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
unsigned long physaddr_t
Definition stdint.h:20
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t bus
Bus.
Definition edd.h:1
uint8_t flags
Flags.
Definition ena.h:7
static signed char phys[4]
Definition epic100.c:88
#define DBG_LOG
Definition compiler.h:317
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define DMA_TX
Device will read data from host memory.
Definition dma.h:135
#define DMA_RX
Device will write data to host memory.
Definition dma.h:138
static __always_inline int struct dma_mapping * map
Definition dma.h:184
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition PciIo.h:527
EFI_PCI_IO_PROTOCOL_MAP Map
Definition PciIo.h:526
An EFI PCI device.
Definition efi_pci.h:22
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition efi_pci.h:26
struct pci_device pci
PCI device.
Definition efi_pci.h:24
struct dma_device dma
DMA device.
Definition pci.h:215

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

Referenced by efipci_dma_alloc().

◆ efipci_dma_unmap()

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

Unmap buffer.

Parameters
dmaDMA device
mapDMA mapping
lenUsed length

Definition at line 550 of file efi_pci.c.

551 {
552 struct efi_pci_device *efipci =
554 EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
555
556 /* Unmap buffer (if non-zero length) */
557 if ( map->token )
558 pci_io->Unmap ( pci_io, map->token );
559
560 /* Clear mapping */
561 map->dma = NULL;
562 map->offset = 0;
563 map->token = NULL;
564
565 /* Decrement mapping count (for debugging) */
566 if ( DBG_LOG )
567 dma->mapped--;
568}

References __unused, container_of, DBG_LOG, dma(), pci_device::dma, efi_pci_device::io, len, map, NULL, efi_pci_device::pci, and _EFI_PCI_IO_PROTOCOL::Unmap.

Referenced by efipci_dma_alloc(), and efipci_dma_free().

◆ efipci_dma_alloc()

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

581 {
582 struct efi_pci_device *efipci =
584 struct pci_device *pci = &efipci->pci;
585 EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
586 unsigned int pages;
587 VOID *addr;
588 EFI_STATUS efirc;
589 int rc;
590
591 /* Calculate number of pages */
592 pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
593
594 /* Allocate (page-aligned) buffer */
595 if ( ( efirc = pci_io->AllocateBuffer ( pci_io, AllocateAnyPages,
596 EfiBootServicesData, pages,
597 &addr, 0 ) ) != 0 ) {
598 rc = -EEFI ( efirc );
599 DBGC ( pci, "EFIPCI " PCI_FMT " could not allocate %zd bytes: "
600 "%s\n", PCI_ARGS ( pci ), len, strerror ( rc ) );
601 goto err_alloc;
602 }
603
604 /* Clear buffer */
605 memset ( addr, 0, ( pages * EFI_PAGE_SIZE ) );
606
607 /* Map buffer */
608 if ( ( rc = efipci_dma_map ( dma, map, addr, ( pages * EFI_PAGE_SIZE ),
609 DMA_BI ) ) != 0 )
610 goto err_map;
611
612 /* Increment allocation count (for debugging) */
613 if ( DBG_LOG )
614 dma->allocated++;
615
616 return addr;
617
619 err_map:
620 pci_io->FreeBuffer ( pci_io, pages, addr );
621 err_alloc:
622 return NULL;
623}
#define EFI_PAGE_SIZE
@ EfiBootServicesData
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
@ AllocateAnyPages
Allocate any available range of pages that satisfies the request.
Definition UefiSpec.h:36
static int efipci_dma_map(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len, int flags)
Map buffer for DMA.
Definition efi_pci.c:465
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
Definition efi_pci.c:550
#define DMA_BI
Device will both read data from and write data to host memory.
Definition dma.h:141
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
Definition PciIo.h:528
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
Definition PciIo.h:529

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

◆ efipci_dma_free()

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

634 {
635 struct efi_pci_device *efipci =
637 EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
638 unsigned int pages;
639
640 /* Calculate number of pages */
641 pages = ( ( len + EFI_PAGE_SIZE - 1 ) / EFI_PAGE_SIZE );
642
643 /* Unmap buffer */
645
646 /* Free buffer */
647 pci_io->FreeBuffer ( pci_io, pages, addr );
648
649 /* Decrement allocation count (for debugging) */
650 if ( DBG_LOG )
651 dma->allocated--;
652}

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

◆ efipci_dma_set_mask()

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

660 {
661 struct efi_pci_device *efipci =
663 struct pci_device *pci = &efipci->pci;
664 EFI_PCI_IO_PROTOCOL *pci_io = efipci->io;
666 UINT64 attrs;
667 int is64;
668 EFI_STATUS efirc;
669 int rc;
670
671 /* Set dual address cycle attribute for 64-bit capable devices */
672 is64 = ( ( ( ( uint64_t ) mask ) + 1 ) == 0 );
676 if ( ( efirc = pci_io->Attributes ( pci_io, op, attrs, NULL ) ) != 0 ) {
677 rc = -EEFI ( efirc );
678 DBGC ( pci, "EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
679 PCI_ARGS ( pci ), ( is64 ? "en" : "dis" ),
680 strerror ( rc ) );
681 /* Ignore failure: errors will manifest in mapping attempts */
682 return;
683 }
684}
unsigned long long UINT64
8-byte unsigned value.
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
Definition PciIo.h:67
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
Definition PciIo.h:102
@ EfiPciIoAttributeOperationDisable
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition PciIo.h:118
@ EfiPciIoAttributeOperationEnable
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
Definition PciIo.h:114
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
Definition PciIo.h:532

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

◆ efipci_info()

int efipci_info ( EFI_HANDLE device,
struct efi_pci_device * efipci )

Get EFI PCI device information.

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

Definition at line 711 of file efi_pci.c.

711 {
712 EFI_PCI_IO_PROTOCOL *pci_io;
713 UINTN pci_segment, pci_bus, pci_dev, pci_fn;
714 unsigned int busdevfn;
715 EFI_STATUS efirc;
716 int rc;
717
718 /* See if device is a PCI device */
720 &pci_io ) ) != 0 ) {
721 DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
723 return rc;
724 }
725 efipci->io = pci_io;
726
727 /* Get PCI bus:dev.fn address */
728 if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus,
729 &pci_dev, &pci_fn ) ) != 0 ) {
730 rc = -EEFI ( efirc );
731 DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
733 return rc;
734 }
735 busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
736 pci_init ( &efipci->pci, busdevfn );
737 dma_init ( &efipci->pci.dma, &efipci_dma_operations );
738 DBGCP ( device, "EFIPCI " PCI_FMT " is %s\n",
739 PCI_ARGS ( &efipci->pci ), efi_handle_name ( device ) );
740
741 /* Try to enable I/O cycles, memory cycles, and bus mastering.
742 * Some platforms will 'helpfully' report errors if these bits
743 * can't be enabled (for example, if the card doesn't actually
744 * support I/O cycles). Work around any such platforms by
745 * enabling bits individually and simply ignoring any errors.
746 */
753
754 /* Populate PCI device */
755 if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) {
756 DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
757 "configuration: %s\n",
758 PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
759 return rc;
760 }
761
762 return 0;
763}
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
Definition PciIo.h:62
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
Definition PciIo.h:61
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
Definition PciIo.h:60
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition efi_guid.c:313
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
Definition efi_pci.c:687
#define DBGCP(...)
Definition compiler.h:539
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
Definition dma.h:454
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition pci.c:269
EFI_PCI_IO_PROTOCOL_GET_LOCATION GetLocation
Definition PciIo.h:531
A hardware device.
Definition device.h:77

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

Referenced by efi_bofm_start(), efi_bofm_supported(), efi_device_info_pci(), efipci_start(), and efipci_supported().

◆ efipci_supported()

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

778 {
779 struct efi_pci_device efipci;
780 uint8_t hdrtype;
781 int rc;
782
783 /* Get PCI device information */
784 if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
785 return rc;
786
787 /* Do not attempt to drive bridges */
788 hdrtype = efipci.pci.hdrtype;
789 if ( ( hdrtype & PCI_HEADER_TYPE_MASK ) != PCI_HEADER_TYPE_NORMAL ) {
790 DBGC ( device, "EFIPCI " PCI_FMT " type %02x is not type %02x\n",
791 PCI_ARGS ( &efipci.pci ), hdrtype,
793 return -ENOTTY;
794 }
795
796 /* Look for a driver */
797 if ( ( rc = pci_find_driver ( &efipci.pci ) ) != 0 ) {
798 DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) "
799 "has no driver\n", PCI_ARGS ( &efipci.pci ),
800 efipci.pci.vendor, efipci.pci.device,
801 efipci.pci.class );
802 return rc;
803 }
804 DBGC ( device, "EFIPCI " PCI_FMT " (%04x:%04x class %06x) has driver "
805 "\"%s\"\n", PCI_ARGS ( &efipci.pci ), efipci.pci.vendor,
806 efipci.pci.device, efipci.pci.class, efipci.pci.id->name );
807
808 return 0;
809}
unsigned char uint8_t
Definition stdint.h:10
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition efi_pci.c:711
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:595
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
Definition pci.c:386
#define PCI_HEADER_TYPE_MASK
Header type mask.
Definition pci.h:58
#define PCI_HEADER_TYPE_NORMAL
Normal header.
Definition pci.h:55

References pci_device::class, DBGC, pci_device::device, EFI_HANDLE, 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.

Referenced by __efi_driver().

◆ efipci_exclude()

int efipci_exclude ( EFI_HANDLE device)
static

Exclude existing drivers.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 817 of file efi_pci.c.

817 {
819 int rc;
820
821 /* Exclude existing PCI I/O protocol drivers */
822 if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
823 DBGC ( device, "EFIPCI %s could not exclude drivers: %s\n",
825 return rc;
826 }
827
828 return 0;
829}
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition efi_driver.c:438
uint16_t protocol
Protocol ID.
Definition stp.h:7

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

Referenced by __efi_driver().

◆ efipci_start()

int efipci_start ( struct efi_device * efidev)
static

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 837 of file efi_pci.c.

837 {
838 EFI_HANDLE device = efidev->device;
839 struct efi_pci_device *efipci;
840 int rc;
841
842 /* Allocate PCI device */
843 efipci = zalloc ( sizeof ( *efipci ) );
844 if ( ! efipci ) {
845 rc = -ENOMEM;
846 goto err_alloc;
847 }
848
849 /* Get PCI device information */
850 if ( ( rc = efipci_info ( device, efipci ) ) != 0 )
851 goto err_info;
852
853 /* Open PCI I/O protocol */
855 &efipci->io ) ) != 0 ) {
856 DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
859 goto err_open;
860 }
861
862 /* Find driver */
863 if ( ( rc = pci_find_driver ( &efipci->pci ) ) != 0 ) {
864 DBGC ( device, "EFIPCI " PCI_FMT " has no driver\n",
865 PCI_ARGS ( &efipci->pci ) );
866 goto err_find_driver;
867 }
868
869 /* Mark PCI device as a child of the EFI device */
870 efipci->pci.dev.parent = &efidev->dev;
871 list_add ( &efipci->pci.dev.siblings, &efidev->dev.children );
872
873 /* Probe driver */
874 if ( ( rc = pci_probe ( &efipci->pci ) ) != 0 ) {
875 DBGC ( device, "EFIPCI " PCI_FMT " could not probe driver "
876 "\"%s\": %s\n", PCI_ARGS ( &efipci->pci ),
877 efipci->pci.id->name, strerror ( rc ) );
878 goto err_probe;
879 }
880 DBGC ( device, "EFIPCI " PCI_FMT " using driver \"%s\"\n",
881 PCI_ARGS ( &efipci->pci ), efipci->pci.id->name );
882
883 efidev_set_drvdata ( efidev, efipci );
884 return 0;
885
886 pci_remove ( &efipci->pci );
887 err_probe:
888 list_del ( &efipci->pci.dev.siblings );
889 err_find_driver:
891 err_open:
892 err_info:
893 free ( efipci );
894 err_alloc:
895 return rc;
896}
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition efi_driver.h:87
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition efi_open.c:279
#define ENOMEM
Not enough space.
Definition errno.h:535
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition efi.h:474
#define DBGC_EFI_OPENERS(...)
Definition efi.h:345
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
int pci_probe(struct pci_device *pci)
Probe a PCI device.
Definition pci.c:418
void pci_remove(struct pci_device *pci)
Remove a PCI device.
Definition pci.c:440
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
struct device * parent
Bus device.
Definition device.h:89
struct list_head children
Devices attached to this device.
Definition device.h:87
struct list_head siblings
Devices on the same bus.
Definition device.h:85
EFI_HANDLE device
EFI device handle.
Definition efi_driver.h:22
struct device dev
Generic device.
Definition efi_driver.h:20
const char * name
Name.
Definition pci.h:177
struct device dev
Generic device.
Definition pci.h:213
struct pci_device_id * id
Driver device ID.
Definition pci.h:248

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

Referenced by __efi_driver().

◆ efipci_stop()

void efipci_stop ( struct efi_device * efidev)
static

Detach driver from device.

Parameters
efidevEFI device

Definition at line 903 of file efi_pci.c.

903 {
904 struct efi_pci_device *efipci = efidev_get_drvdata ( efidev );
905 EFI_HANDLE device = efidev->device;
906
907 pci_remove ( &efipci->pci );
908 list_del ( &efipci->pci.dev.siblings );
909 assert ( efipci->pci.dma.mapped == 0 );
910 assert ( efipci->pci.dma.allocated == 0 );
912 free ( efipci );
913}
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition efi_driver.h:98
unsigned int mapped
Total number of mappings (for debugging)
Definition dma.h:54
unsigned int allocated
Total number of allocations (for debugging)
Definition dma.h:56

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

Referenced by __efi_driver().

◆ __efi_driver()

struct efi_driver efipci_driver __efi_driver ( EFI_DRIVER_HARDWARE )

Variable Documentation

◆ efipci_dma_operations

struct dma_operations efipci_dma_operations
static
Initial value:
= {
.unmap = efipci_dma_unmap,
.alloc = efipci_dma_alloc,
.free = efipci_dma_free,
.umalloc = efipci_dma_alloc,
.ufree = efipci_dma_free,
.set_mask = efipci_dma_set_mask,
}
static 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:633
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
Definition efi_pci.c:660
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:579

EFI PCI DMA operations.

Definition at line 687 of file efi_pci.c.

687 {
688 .map = efipci_dma_map,
689 .unmap = efipci_dma_unmap,
690 .alloc = efipci_dma_alloc,
691 .free = efipci_dma_free,
692 .umalloc = efipci_dma_alloc,
693 .ufree = efipci_dma_free,
694 .set_mask = efipci_dma_set_mask,
695};

Referenced by efipci_info().