drivers/vfio/iommufd.c
Source file repositories/reference/linux-study-clean/drivers/vfio/iommufd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/iommufd.c- Extension
.c- Size
- 7552 bytes
- Lines
- 304
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/vfio.hlinux/iommufd.hvfio.h
Detected Declarations
function vfio_iommufd_device_has_compat_ioasfunction vfio_df_iommufd_bindfunction vfio_iommufd_compat_attach_ioasfunction vfio_df_iommufd_unbindfunction vfio_iommufd_device_idfunction vfio_iommufd_get_dev_idfunction vfio_register_group_devfunction vfio_iommufd_physical_unbindfunction vfio_iommufd_physical_attach_ioasfunction vfio_iommufd_physical_detach_ioasfunction vfio_iommufd_physical_pasid_attach_ioasfunction vfio_iommufd_physical_pasid_detach_ioasfunction vfio_register_emulated_iommu_devfunction vfio_iommufd_emulated_bindfunction vfio_iommufd_emulated_unbindfunction vfio_iommufd_emulated_attach_ioasfunction vfio_iommufd_emulated_detach_ioasexport vfio_iommufd_device_ictxexport vfio_iommufd_get_dev_idexport vfio_iommufd_physical_bindexport vfio_iommufd_physical_unbindexport vfio_iommufd_physical_attach_ioasexport vfio_iommufd_physical_detach_ioasexport vfio_iommufd_physical_pasid_attach_ioasexport vfio_iommufd_physical_pasid_detach_ioasexport vfio_iommufd_emulated_bindexport vfio_iommufd_emulated_unbindexport vfio_iommufd_emulated_attach_ioasexport vfio_iommufd_emulated_detach_ioas
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES
*/
#include <linux/vfio.h>
#include <linux/iommufd.h>
#include "vfio.h"
MODULE_IMPORT_NS("IOMMUFD");
MODULE_IMPORT_NS("IOMMUFD_VFIO");
bool vfio_iommufd_device_has_compat_ioas(struct vfio_device *vdev,
struct iommufd_ctx *ictx)
{
u32 ioas_id;
return !iommufd_vfio_compat_ioas_get_id(ictx, &ioas_id);
}
int vfio_df_iommufd_bind(struct vfio_device_file *df)
{
struct vfio_device *vdev = df->device;
struct iommufd_ctx *ictx = df->iommufd;
lockdep_assert_held(&vdev->dev_set->lock);
/* Returns 0 to permit device opening under noiommu mode */
if (vfio_device_is_noiommu(vdev))
return 0;
return vdev->ops->bind_iommufd(vdev, ictx, &df->devid);
}
int vfio_iommufd_compat_attach_ioas(struct vfio_device *vdev,
struct iommufd_ctx *ictx)
{
u32 ioas_id;
int ret;
lockdep_assert_held(&vdev->dev_set->lock);
/* compat noiommu does not need to do ioas attach */
if (vfio_device_is_noiommu(vdev))
return 0;
ret = iommufd_vfio_compat_ioas_get_id(ictx, &ioas_id);
if (ret)
return ret;
/* The legacy path has no way to return the selected pt_id */
return vdev->ops->attach_ioas(vdev, &ioas_id);
}
void vfio_df_iommufd_unbind(struct vfio_device_file *df)
{
struct vfio_device *vdev = df->device;
lockdep_assert_held(&vdev->dev_set->lock);
if (vfio_device_is_noiommu(vdev))
return;
if (vdev->ops->unbind_iommufd)
vdev->ops->unbind_iommufd(vdev);
}
struct iommufd_ctx *vfio_iommufd_device_ictx(struct vfio_device *vdev)
{
if (vdev->iommufd_device)
return iommufd_device_to_ictx(vdev->iommufd_device);
return NULL;
}
EXPORT_SYMBOL_GPL(vfio_iommufd_device_ictx);
static int vfio_iommufd_device_id(struct vfio_device *vdev)
{
if (vdev->iommufd_device)
return iommufd_device_to_id(vdev->iommufd_device);
return -EINVAL;
}
/*
* Return devid for a device.
* valid ID for the device that is owned by the ictx
* -ENOENT = device is owned but there is no ID
* -ENODEV or other error = device is not owned
*/
int vfio_iommufd_get_dev_id(struct vfio_device *vdev, struct iommufd_ctx *ictx)
{
Annotation
- Immediate include surface: `linux/vfio.h`, `linux/iommufd.h`, `vfio.h`.
- Detected declarations: `function vfio_iommufd_device_has_compat_ioas`, `function vfio_df_iommufd_bind`, `function vfio_iommufd_compat_attach_ioas`, `function vfio_df_iommufd_unbind`, `function vfio_iommufd_device_id`, `function vfio_iommufd_get_dev_id`, `function vfio_register_group_dev`, `function vfio_iommufd_physical_unbind`, `function vfio_iommufd_physical_attach_ioas`, `function vfio_iommufd_physical_detach_ioas`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.