/** * Get underlying PCI device information * * @v efidev EFI device * @v dev Generic device to fill in * @ret rc Return status code */ static int snpnet_pci_info ( struct efi_device *efidev, struct device *dev ) { EFI_HANDLE device = efidev->device; EFI_HANDLE pci_device; struct pci_device pci; int rc; /* Find parent PCI device */ if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid, &pci_device ) ) != 0 ) { DBGC ( device, "SNP %p %s is not a PCI device: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Get PCI device information */ if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) { DBGC ( device, "SNP %p %s could not get PCI information: %s\n", device, efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Populate SNP device information */ memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) ); snprintf ( dev->name, sizeof ( dev->name ), "SNP-%s", pci.dev.name ); return 0; }
/** * Open PCI I/O protocol and identify BARs * * @v nii NII NIC * @ret rc Return status code */ static int nii_pci_open ( struct nii_nic *nii ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = nii->efidev->device; EFI_HANDLE pci_device; union { EFI_PCI_IO_PROTOCOL *pci_io; void *interface; } pci_io; union { EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi; void *resource; } desc; unsigned int bar; EFI_STATUS efirc; int rc; /* Locate PCI I/O protocol */ if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid, &pci_device ) ) != 0 ) { DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n", nii->dev.name, strerror ( rc ) ); goto err_locate; } nii->pci_device = pci_device; /* Open PCI I/O protocol */ if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid, &pci_io.interface, efi_image_handle, device, EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ rc = -EEFI ( efirc ); DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n", nii->dev.name, strerror ( rc ) ); goto err_open; } nii->pci_io = pci_io.pci_io; /* Identify memory and I/O BARs */ nii->mem_bar = PCI_MAX_BAR; nii->io_bar = PCI_MAX_BAR; for ( bar = 0 ; bar < PCI_MAX_BAR ; bar++ ) { efirc = nii->pci_io->GetBarAttributes ( nii->pci_io, bar, NULL, &desc.resource ); if ( efirc == EFI_UNSUPPORTED ) { /* BAR not present; ignore */ continue; } if ( efirc != 0 ) { rc = -EEFI ( efirc ); DBGC ( nii, "NII %s could not get BAR %d attributes: " "%s\n", nii->dev.name, bar, strerror ( rc ) ); goto err_get_bar_attributes; } if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) { nii->mem_bar = bar; } else if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_IO ) { nii->io_bar = bar; } bs->FreePool ( desc.resource ); } DBGC ( nii, "NII %s has ", nii->dev.name ); if ( nii->mem_bar < PCI_MAX_BAR ) { DBGC ( nii, "memory BAR %d and ", nii->mem_bar ); } else { DBGC ( nii, "no memory BAR and " ); } if ( nii->io_bar < PCI_MAX_BAR ) { DBGC ( nii, "I/O BAR %d\n", nii->io_bar ); } else { DBGC ( nii, "no I/O BAR\n" ); } return 0; err_get_bar_attributes: bs->CloseProtocol ( pci_device, &efi_pci_io_protocol_guid, efi_image_handle, device ); err_open: err_locate: return rc; }