45#define EINFO_EEFI_PCI \
46 __einfo_uniqify ( EINFO_EPLATFORM, 0x01, \
47 "Could not open PCI I/O protocol" )
48#define EINFO_EEFI_PCI_NOT_PCI \
49 __einfo_platformify ( EINFO_EEFI_PCI, EFI_UNSUPPORTED, \
51#define EEFI_PCI_NOT_PCI __einfo_error ( EINFO_EEFI_PCI_NOT_PCI )
52#define EINFO_EEFI_PCI_IN_USE \
53 __einfo_platformify ( EINFO_EEFI_PCI, EFI_ACCESS_DENIED, \
54 "PCI device already has a driver" )
55#define EEFI_PCI_IN_USE __einfo_error ( EINFO_EEFI_PCI_IN_USE )
56#define EEFI_PCI( efirc ) \
57 EPLATFORM ( EINFO_EEFI_PCI, efirc, \
58 EEFI_PCI_NOT_PCI, EEFI_PCI_IN_USE )
97 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot open %s: %s\n",
104 if ( ( efirc =
root->Configuration (
root, &
acpi.raw ) ) != 0 ) {
106 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot get configuration for "
129 DBGC2 ( pci,
"EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via "
150 if ( !
range->count ) {
187 NULL, &num_handles, &handles ) ) != 0 ) {
189 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot locate root bridges: "
195 for ( i = 0 ; i < num_handles ; i++ ) {
243 memset ( &pci, 0,
sizeof ( pci ) );
265 if ( ( pci->
busdevfn - cache.range.start ) >= cache.range.count )
267 if ( ! cache.handle )
274 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot open %s: %s\n",
291 unsigned long location ) {
323 DBGC ( pci,
"EFIPCI " PCI_FMT " config read from offset %02lx "
341 unsigned long value ) {
356 DBGC ( pci,
"EFIPCI " PCI_FMT " config write to offset %02lx "
392 if ( ( efirc =
root->Configuration (
root, &
u.raw ) ) != 0 ) {
394 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot get configuration: "
413 DBGC2 ( pci,
"EFIPCI " PCI_FMT " found range [%08llx,%08llx) "
427 DBGC ( pci,
"EFIPCI " PCI_FMT " %08lx+%zx is not within "
428 "root bridge address space\n",
502 &mapping ) ) != 0 ) {
504 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot map %p+%zx: "
520 DBGC ( pci,
"EFIPCI " PCI_FMT " attempted split mapping for "
529 map->token = mapping;
538 pci_io->
Unmap ( pci_io, mapping );
558 pci_io->
Unmap ( pci_io,
map->token );
597 &
addr, 0 ) ) != 0 ) {
599 DBGC ( pci,
"EFIPCI " PCI_FMT " could not allocate %zd bytes: "
672 is64 = ( ( ( (
uint64_t ) mask ) + 1 ) == 0 );
678 DBGC ( pci,
"EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
679 PCI_ARGS ( pci ), ( is64 ?
"en" :
"dis" ),
713 UINTN pci_segment, pci_bus, pci_dev, pci_fn;
721 DBGCP (
device,
"EFIPCI %s cannot open PCI protocols: %s\n",
728 if ( ( efirc = pci_io->
GetLocation ( pci_io, &pci_segment, &pci_bus,
729 &pci_dev, &pci_fn ) ) != 0 ) {
731 DBGC (
device,
"EFIPCI %s could not get PCI location: %s\n",
757 "configuration: %s\n",
823 DBGC (
device,
"EFIPCI %s could not exclude drivers: %s\n",
843 efipci =
zalloc (
sizeof ( *efipci ) );
855 &efipci->
io ) ) != 0 ) {
856 DBGC (
device,
"EFIPCI %s could not open PCI device: %s\n",
866 goto err_find_driver;
UINT64 UINTN
Unsigned value of native width.
unsigned long long UINT64
8-byte unsigned value.
#define NULL
NULL pointer (VOID *)
#define VOID
Undeclared type.
EFI PCI I/O Protocol provides the basic Memory, I/O, PCI configuration, and DMA interfaces that a dri...
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
@ EfiPciIoAttributeOperationDisable
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
@ EfiPciIoAttributeOperationEnable
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
EFI_PCI_IO_PROTOCOL_OPERATION
@ EfiPciIoOperationBusMasterWrite
A write operation from system memory by a bus master.
@ EfiPciIoOperationBusMasterRead
A read operation from system memory by a bus master.
@ EfiPciIoOperationBusMasterCommonBuffer
Provides both read and write access to system memory by both the processor and a bus master.
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
struct _EFI_PCI_IO_PROTOCOL EFI_PCI_IO_PROTOCOL
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
PCI Root Bridge I/O protocol as defined in the UEFI 2.0 specification.
struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
@ EfiBootServicesData
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
@ ByProtocol
Retrieve the set of handles from the handle database that support a specified protocol.
@ AllocateAnyPages
Allocate any available range of pages that satisfies the request.
struct arbelprm_rc_send_wqe rc
pseudo_bit_t value[0x00020]
unsigned long long uint64_t
#define assert(condition)
Assert a condition at run-time.
uint16_t offset
Offset to command line.
union @104331263140136355135267063077374276003064103115 u
uint32_t addr
Buffer address.
uint64_t tag
Identity tag.
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
#define EFI_DRIVER_HARDWARE
Hardware drivers.
#define __efi_driver(order)
Declare an EFI driver.
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
static int efipci_start(struct efi_device *efidev)
Attach driver to device.
static void efipci_dma_free(struct dma_device *dma, struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
static void efipci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
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 int efipci_supported(EFI_HANDLE device)
Check to see if driver supports a device.
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.
void * efipci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
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_exclude(EFI_HANDLE device)
Exclude existing drivers.
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
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 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_stop(struct efi_device *efidev)
Detach driver from device.
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 void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map, size_t len __unused)
Unmap buffer.
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
#define EFIPCI_OFFSET(_location)
#define EFIPCI_WIDTH(_location)
uint16_t busdevfn
PCI bus:dev.fn address.
static signed char phys[4]
#define __unused
Declare a variable or data structure as unused.
uint32_t start
Starting offset.
static unsigned int count
Number of entries.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define ENOENT
No such file or directory.
#define ENOMEM
Not enough space.
#define ENOTSUP
Operation not supported.
#define ENOTTY
Inappropriate I/O control operation.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define le64_to_cpu(value)
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
#define DBGC_EFI_OPENERS(...)
EFI_SYSTEM_TABLE * efi_systab
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
#define PCIAPI_PRIORITY_EFI
EFI PCI I/O protocols.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define PCI_BUSDEVFN(segment, bus, slot, func)
#define PROVIDE_PCIAPI_RUNTIME(subsys, priority)
Provide a runtime selectable PCI I/O API.
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
#define PROVIDE_PCIAPI(_subsys, _api_func, _func)
Provide a PCI I/O API implementation.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define PROVIDE_PCIAPI_INLINE(_subsys, _api_func)
Provide a static inline PCI I/O API implementation.
void * memset(void *dest, int character, size_t len) __nonnull
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
#define DMA_TX
Device will read data from host memory.
#define DMA_BI
Device will both read data from and write data to host memory.
#define DMA_RX
Device will write data to host memory.
static __always_inline int struct dma_mapping * map
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define list_del(list)
Delete an entry from a list.
#define list_add(new, head)
Add a new entry to the head of a list.
void * zalloc(size_t size)
Allocate cleared memory.
uint32_t end
Ending offset.
static uint16_t struct vmbus_xfer_pages_operations * op
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
int pci_probe(struct pci_device *pci)
Probe a PCI device.
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
void pci_remove(struct pci_device *pci)
Remove a PCI device.
#define PCI_FMT
PCI device debug message format.
#define PCI_FUNC(busdevfn)
#define PCI_BUS(busdevfn)
#define PCI_ARGS(pci)
PCI device debug message arguments.
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
#define PCI_HEADER_TYPE_MASK
Header type mask.
#define PCI_HEADER_TYPE_NORMAL
Normal header.
#define PCI_SLOT(busdevfn)
static __always_inline void unsigned long bus_addr
struct pci_range range
PCI bus:dev.fn address range.
static void(* free)(struct refcnt *refcnt))
#define container_of(ptr, type, field)
Get containing structure.
struct stp_switch root
Root switch.
uint16_t protocol
Protocol ID.
char * strerror(int errno)
Retrieve string representation of error number.
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
EFI_PCI_IO_PROTOCOL_GET_LOCATION GetLocation
EFI_PCI_IO_PROTOCOL_FREE_BUFFER FreeBuffer
EFI_PCI_IO_PROTOCOL_MAP Map
struct device * parent
Bus device.
struct list_head children
Devices attached to this device.
struct list_head siblings
Devices on the same bus.
unsigned int mapped
Total number of mappings (for debugging)
unsigned int allocated
Total number of allocations (for debugging)
EFI_HANDLE device
EFI device handle.
struct device dev
Generic device.
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
struct pci_device pci
PCI device.
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
uint32_t class
Device class.
uint8_t hdrtype
Header type.
struct device dev
Generic device.
struct pci_device_id * id
Driver device ID.
uint16_t vendor
Vendor ID.
uint16_t device
Device ID.
struct dma_device dma
DMA device.
A PCI bus:dev.fn address range.
An ACPI resource descriptor.