tools/testing/selftests/vfio/lib/vfio_pci_driver.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/vfio/lib/vfio_pci_driver.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/vfio/lib/vfio_pci_driver.c- Extension
.c- Size
- 2667 bytes
- Lines
- 113
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kselftest.hlibvfio.h
Detected Declarations
function vfio_pci_driver_probefunction vfio_check_driver_opfunction vfio_pci_driver_initfunction vfio_pci_driver_removefunction vfio_pci_driver_send_msifunction vfio_pci_driver_memcpy_startfunction vfio_pci_driver_memcpy_waitfunction vfio_pci_driver_memcpy
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include "kselftest.h"
#include <libvfio.h>
#ifdef __x86_64__
extern struct vfio_pci_driver_ops dsa_ops;
extern struct vfio_pci_driver_ops ioat_ops;
#endif
static struct vfio_pci_driver_ops *driver_ops[] = {
#ifdef __x86_64__
&dsa_ops,
&ioat_ops,
#endif
};
void vfio_pci_driver_probe(struct vfio_pci_device *device)
{
struct vfio_pci_driver_ops *ops;
int i;
VFIO_ASSERT_NULL(device->driver.ops);
for (i = 0; i < ARRAY_SIZE(driver_ops); i++) {
ops = driver_ops[i];
if (ops->probe(device))
continue;
device->driver.ops = ops;
}
}
static void vfio_check_driver_op(struct vfio_pci_driver *driver, void *op,
const char *op_name)
{
VFIO_ASSERT_NOT_NULL(driver->ops);
VFIO_ASSERT_NOT_NULL(op, "Driver has no %s()\n", op_name);
VFIO_ASSERT_EQ(driver->initialized, op != driver->ops->init);
VFIO_ASSERT_EQ(driver->memcpy_in_progress, op == driver->ops->memcpy_wait);
}
#define VFIO_CHECK_DRIVER_OP(_driver, _op) do { \
struct vfio_pci_driver *__driver = (_driver); \
vfio_check_driver_op(__driver, __driver->ops->_op, #_op); \
} while (0)
void vfio_pci_driver_init(struct vfio_pci_device *device)
{
struct vfio_pci_driver *driver = &device->driver;
VFIO_ASSERT_NOT_NULL(driver->region.vaddr);
VFIO_CHECK_DRIVER_OP(driver, init);
driver->ops->init(device);
driver->initialized = true;
}
void vfio_pci_driver_remove(struct vfio_pci_device *device)
{
struct vfio_pci_driver *driver = &device->driver;
VFIO_CHECK_DRIVER_OP(driver, remove);
driver->ops->remove(device);
driver->initialized = false;
}
void vfio_pci_driver_send_msi(struct vfio_pci_device *device)
{
struct vfio_pci_driver *driver = &device->driver;
VFIO_CHECK_DRIVER_OP(driver, send_msi);
driver->ops->send_msi(device);
}
void vfio_pci_driver_memcpy_start(struct vfio_pci_device *device,
iova_t src, iova_t dst, u64 size,
u64 count)
{
struct vfio_pci_driver *driver = &device->driver;
VFIO_ASSERT_LE(size, driver->max_memcpy_size);
VFIO_ASSERT_LE(count, driver->max_memcpy_count);
VFIO_CHECK_DRIVER_OP(driver, memcpy_start);
driver->ops->memcpy_start(device, src, dst, size, count);
driver->memcpy_in_progress = true;
Annotation
- Immediate include surface: `kselftest.h`, `libvfio.h`.
- Detected declarations: `function vfio_pci_driver_probe`, `function vfio_check_driver_op`, `function vfio_pci_driver_init`, `function vfio_pci_driver_remove`, `function vfio_pci_driver_send_msi`, `function vfio_pci_driver_memcpy_start`, `function vfio_pci_driver_memcpy_wait`, `function vfio_pci_driver_memcpy`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.