43 #define EINFO_EEFI_PCI \ 44 __einfo_uniqify ( EINFO_EPLATFORM, 0x01, \ 45 "Could not open PCI I/O protocol" ) 46 #define EINFO_EEFI_PCI_NOT_PCI \ 47 __einfo_platformify ( EINFO_EEFI_PCI, EFI_UNSUPPORTED, \ 49 #define EEFI_PCI_NOT_PCI __einfo_error ( EINFO_EEFI_PCI_NOT_PCI ) 50 #define EINFO_EEFI_PCI_IN_USE \ 51 __einfo_platformify ( EINFO_EEFI_PCI, EFI_ACCESS_DENIED, \ 52 "PCI device already has a driver" ) 53 #define EEFI_PCI_IN_USE __einfo_error ( EINFO_EEFI_PCI_IN_USE ) 54 #define EEFI_PCI( efirc ) \ 55 EPLATFORM ( EINFO_EEFI_PCI, efirc, \ 56 EEFI_PCI_NOT_PCI, EEFI_PCI_IN_USE ) 102 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot open %s: %s\n",
109 if ( ( efirc =
root.root->Configuration (
root.root,
110 &
acpi.raw ) ) != 0 ) {
112 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot get configuration for " 135 DBGC2 ( pci,
"EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via " 201 NULL, &num_handles, &handles ) ) != 0 ) {
203 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot locate root bridges: " 209 for ( i = 0 ; i < num_handles ; i++ ) {
257 memset ( &pci, 0,
sizeof ( pci ) );
291 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot open %s: %s\n",
324 unsigned long location ) {
356 DBGC ( pci,
"EFIPCI " PCI_FMT " config read from offset %02lx " 377 unsigned long value ) {
392 DBGC ( pci,
"EFIPCI " PCI_FMT " config write to offset %02lx " 431 if ( ( efirc =
root->Configuration (
root, &
u.raw ) ) != 0 ) {
433 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot get configuration: " 452 DBGC2 ( pci,
"EFIPCI " PCI_FMT " found range [%08llx,%08llx) " 466 DBGC ( pci,
"EFIPCI " PCI_FMT " %08lx+%zx is not within " 467 "root bridge address space\n",
541 DBGC ( pci,
"EFIPCI " PCI_FMT " cannot map %08lx+%zx: " 557 DBGC ( pci,
"EFIPCI " PCI_FMT " attempted split mapping for " 575 pci_io->
Unmap ( pci_io, mapping );
633 &
addr, 0 ) ) != 0 ) {
635 DBGC ( pci,
"EFIPCI " PCI_FMT " could not allocate %zd bytes: " 741 is64 = ( ( ( (
uint64_t ) mask ) + 1 ) == 0 );
747 DBGC ( pci,
"EFIPCI " PCI_FMT " could not %sable DAC: %s\n",
748 PCI_ARGS ( pci ), ( is64 ?
"en" :
"dis" ),
788 UINTN pci_segment, pci_bus, pci_dev, pci_fn;
796 device, attributes ) ) != 0 ) {
798 DBGCP (
device,
"EFIPCI %s cannot open PCI protocols: %s\n",
800 goto err_open_protocol;
802 efipci->
io = pci_io.pci_io;
805 if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment,
809 DBGC (
device,
"EFIPCI %s could not get PCI location: %s\n",
811 goto err_get_location;
825 pci_io.pci_io->Attributes ( pci_io.pci_io,
828 pci_io.pci_io->Attributes ( pci_io.pci_io,
831 pci_io.pci_io->Attributes ( pci_io.pci_io,
838 "configuration: %s\n",
840 goto err_pci_read_config;
944 efipci =
zalloc (
sizeof ( *efipci ) );
954 DBGC (
device,
"EFIPCI %s could not open PCI device: %s\n",
964 goto err_find_driver;
int(* map)(struct dma_device *dma, struct dma_mapping *map, physaddr_t addr, size_t len, int flags)
Map buffer for DMA.
#define PCI_FUNC(busdevfn)
static __always_inline void struct dma_mapping size_t size_t align
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
uint32_t start
Starting bus:dev.fn address.
#define PCI_BUS(busdevfn)
struct arbelprm_rc_send_wqe rc
#define EFI_PCI_ADDRESS(bus, dev, func, reg)
struct dma_device dma
DMA device.
static void efipci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
int pci_find_driver(struct pci_device *pci)
Find driver for PCI device.
static void efipci_root_close(EFI_HANDLE handle)
Close EFI PCI root bridge I/O protocol.
struct dma_device * dma
DMA device (if unmapping is required)
struct pci_device pci
PCI device.
struct stp_switch root
Root switch.
uint32_t class
Device class.
#define list_add(new, head)
Add a new entry to the head of a list.
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
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.
A read operation from system memory by a bus master.
static int efipci_start(struct efi_device *efidev)
Attach driver to device.
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.
static __always_inline void dma_init(struct dma_device *dma, struct dma_operations *op)
Initialise DMA device.
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE
An ACPI QWORD address space resource descriptor.
#define PCI_HEADER_TYPE_MASK
Header type mask.
EFI_PCI_IO_PROTOCOL_MAP Map
struct efi_driver efipci_driver __efi_driver(EFI_DRIVER_NORMAL)
EFI PCI driver.
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
#define DMA_BI
Device will both read data from and write data to host memory.
int pci_can_probe(void)
Check if PCI bus probing is allowed.
#define ENOENT
No such file or directory.
#define EFI_OPEN_PROTOCOL_BY_DRIVER
unsigned long long uint64_t
EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
#define EFIPCI_OFFSET(_location)
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define DBGC_EFI_OPENERS(...)
EFI_HANDLE device
EFI device handle.
EFI_CLOSE_PROTOCOL CloseProtocol
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
struct device * parent
Bus device.
static __always_inline void unsigned long bus_addr
struct device dev
Generic device.
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
static void efipci_dma_unmap(struct dma_device *dma, struct dma_mapping *map)
Unmap buffer.
#define ENOTSUP
Operation not supported.
uint32_t start
Starting offset.
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
static __always_inline void * phys_to_virt(unsigned long phys_addr)
Convert physical address to a virtual address.
#define list_del(list)
Delete an entry from a list.
uint16_t busdevfn
PCI bus:dev.fn address.
#define ENOMEM
Not enough space.
#define EFI_PCI_IO_ATTRIBUTE_MEMORY
Enable the Memory decode bit in the PCI Config Header.
void * efipci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
uint32_t userptr_t
A pointer to a user buffer.
uint16_t device
Device ID.
#define PCI_HEADER_TYPE_NORMAL
Normal header.
PROVIDE_PCIAPI(efi, pci_discover, efipci_discover)
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.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
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.
pseudo_bit_t value[0x00020]
#define __unused
Declare a variable or data structure as unused.
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
A PCI bus:dev.fn address range.
EFI_PCI_IO_PROTOCOL_ATTRIBUTES Attributes
#define DMA_TX
Device will read data from host memory.
uint16_t count
Number of entries.
#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER
Enable the DMA bit in the PCI Config Header.
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.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static void efipci_stop(struct efi_device *efidev)
Detach driver from device.
uint32_t attrs
Extended attributes (optional)
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
static __always_inline void struct pci_range * range
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
#define ACPI_ADDRESS_TYPE_BUS
A bus number address space type.
#define PCI_BUSDEVFN(segment, bus, slot, func)
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
uint8_t hdrtype
Header type.
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
physaddr_t offset
Address offset.
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
void * zalloc(size_t size)
Allocate cleared memory.
#define PCI_FMT
PCI device debug message format.
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
#define PCI_SLOT(busdevfn)
struct list_head siblings
Devices on the same bus.
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE
Clear for PCI controllers that can not genrate a DAC.
void pci_remove(struct pci_device *pci)
Remove a PCI device.
#define ACPI_END_RESOURCE
An ACPI end resource descriptor.
static int efipci_supported(EFI_HANDLE device)
Check to see if driver supports a device.
UINT64 UINTN
Unsigned value of native width.
Disable the attributes specified by the bits that are set in Attributes for this PCI controller.
Provides both read and write access to system memory by both the processor and a bus master.
static __always_inline int struct dma_mapping * map
#define EFI_PCI_IO_ATTRIBUTE_IO
Enable the I/O decode bit in the PCI Config Header.
#define VOID
Undeclared type.
An ACPI resource descriptor.
unsigned long long UINT64
unsigned int count
Number of bus:dev.fn addresses within this range.
EFI_PCI_IO_PROTOCOL_OPERATION
uint16_t vendor
Vendor ID.
PROVIDE_PCIAPI_INLINE(efi, pci_can_probe)
Enable the attributes specified by the bits that are set in Attributes for this PCI controller.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
#define DMA_RX
Device will write data to host memory.
Provides the basic Memory, I/O, PCI configuration, and DMA interfaces that are used to abstract acces...
unsigned int mapped
Total number of mappings (for debugging)
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
static uint16_t struct vmbus_xfer_pages_operations * op
unsigned int allocated
Total number of allocations (for debugging)
#define EFIPCI_WIDTH(_location)
#define ENOTTY
Inappropriate I/O control operation.
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct list_head children
Devices attached to this device.
PCI Root Bridge I/O protocol as defined in the UEFI 2.0 specification.
void * token
Platform mapping token.
#define PCI_ARGS(pci)
PCI device debug message arguments.
struct pci_device_id * id
Driver device ID.
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
EFI_GUID efi_pci_root_bridge_io_protocol_guid
PCI root bridge I/O protocol GUID.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
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.
Allocate any available range of pages that satisfies the request.
uint32_t end
Ending offset.
Retrieve the set of handles from the handle database that support a specified protocol.
uint16_t offset
Offset to command line.
EFI_SYSTEM_TABLE * efi_systab
static struct dma_operations efipci_dma_operations
EFI PCI DMA operations.
EFI_OPEN_PROTOCOL OpenProtocol
A write operation from system memory by a bus master.
static void efipci_dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
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
static unsigned long efipci_address(struct pci_device *pci, unsigned long location)
Calculate EFI PCI configuration space address.
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
EFI PCI I/O Protocol provides the basic Memory, I/O, PCI configuration, and DMA interfaces that a dri...
#define le64_to_cpu(value)
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
uint64_t tag
Identity tag.
struct device dev
Generic 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.
#define NULL
NULL pointer (VOID *)
int pci_probe(struct pci_device *pci)
Probe a PCI device.
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.
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
void * memset(void *dest, int character, size_t len) __nonnull
#define EFI_DRIVER_NORMAL
Normal drivers.
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.