drivers/gpu/drm/xe/xe_pci_sriov.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_pci_sriov.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_pci_sriov.c
Extension
.c
Size
6897 bytes
Lines
265
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

* This is the Xe implementation of struct pci_driver.sriov_configure callback.
 *
 * This callback will be called by the PCI subsystem to enable or disable SR-IOV
 * Virtual Functions (VFs) as requested by the used via the PCI sysfs interface.
 *
 * Return: number of configured VFs or a negative error code on failure.
 */
int xe_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
{
	struct xe_device *xe = pdev_to_xe_device(pdev);

	if (!IS_SRIOV_PF(xe))
		return -ENODEV;

	if (num_vfs < 0)
		return -EINVAL;

	if (num_vfs > xe_sriov_pf_get_totalvfs(xe))
		return -ERANGE;

	if (num_vfs && pci_num_vf(pdev))
		return -EBUSY;

	guard(xe_pm_runtime)(xe);
	if (num_vfs > 0)
		return pf_enable_vfs(xe, num_vfs);
	else
		return pf_disable_vfs(xe);
}

/**
 * xe_pci_sriov_get_vf_pdev() - Lookup the VF's PCI device using the VF identifier.
 * @pdev: the PF's &pci_dev
 * @vfid: VF identifier (1-based)
 *
 * The caller must decrement the reference count by calling pci_dev_put().
 *
 * Return: the VF's &pci_dev or NULL if the VF device was not found.
 */
struct pci_dev *xe_pci_sriov_get_vf_pdev(struct pci_dev *pdev, unsigned int vfid)
{
	struct xe_device *xe = pdev_to_xe_device(pdev);

	xe_assert(xe, dev_is_pf(&pdev->dev));
	xe_assert(xe, vfid);
	xe_assert(xe, vfid <= pci_sriov_get_totalvfs(pdev));

	return pci_get_domain_bus_and_slot(pci_domain_nr(pdev->bus),
					   pdev->bus->number,
					   pci_iov_virtfn_devfn(pdev, vfid - 1));
}

Annotation

Implementation Notes