drivers/vfio/cdx/main.c
Source file repositories/reference/linux-study-clean/drivers/vfio/cdx/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/cdx/main.c- Extension
.c- Size
- 9352 bytes
- Lines
- 363
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/vfio.hlinux/cdx/cdx_bus.hprivate.h
Detected Declarations
function Copyrightfunction vfio_cdx_release_devfunction vfio_cdx_open_devicefunction vfio_cdx_close_devicefunction vfio_cdx_bm_ctrlfunction vfio_cdx_ioctl_featurefunction vfio_cdx_ioctl_get_infofunction vfio_cdx_ioctl_get_region_infofunction vfio_cdx_ioctl_get_irq_infofunction vfio_cdx_ioctl_set_irqsfunction vfio_cdx_ioctlfunction vfio_cdx_mmap_mmiofunction vfio_cdx_mmapfunction vfio_cdx_probefunction vfio_cdx_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
*/
#include <linux/vfio.h>
#include <linux/cdx/cdx_bus.h>
#include "private.h"
static int vfio_cdx_init_dev(struct vfio_device *core_vdev)
{
struct vfio_cdx_device *vdev =
container_of(core_vdev, struct vfio_cdx_device, vdev);
mutex_init(&vdev->cdx_irqs_lock);
return 0;
}
static void vfio_cdx_release_dev(struct vfio_device *core_vdev)
{
struct vfio_cdx_device *vdev =
container_of(core_vdev, struct vfio_cdx_device, vdev);
mutex_destroy(&vdev->cdx_irqs_lock);
}
static int vfio_cdx_open_device(struct vfio_device *core_vdev)
{
struct vfio_cdx_device *vdev =
container_of(core_vdev, struct vfio_cdx_device, vdev);
struct cdx_device *cdx_dev = to_cdx_device(core_vdev->dev);
int count = cdx_dev->res_count;
int i, ret;
vdev->regions = kzalloc_objs(struct vfio_cdx_region, count,
GFP_KERNEL_ACCOUNT);
if (!vdev->regions)
return -ENOMEM;
for (i = 0; i < count; i++) {
struct resource *res = &cdx_dev->res[i];
vdev->regions[i].addr = res->start;
vdev->regions[i].size = resource_size(res);
vdev->regions[i].type = res->flags;
/*
* Only regions addressed with PAGE granularity may be
* MMAP'ed securely.
*/
if (!(vdev->regions[i].addr & ~PAGE_MASK) &&
!(vdev->regions[i].size & ~PAGE_MASK))
vdev->regions[i].flags |=
VFIO_REGION_INFO_FLAG_MMAP;
vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_READ;
if (!(cdx_dev->res[i].flags & IORESOURCE_READONLY))
vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_WRITE;
}
ret = cdx_dev_reset(core_vdev->dev);
if (ret) {
kfree(vdev->regions);
vdev->regions = NULL;
return ret;
}
ret = cdx_clear_master(cdx_dev);
if (ret)
vdev->flags &= ~BME_SUPPORT;
else
vdev->flags |= BME_SUPPORT;
return 0;
}
static void vfio_cdx_close_device(struct vfio_device *core_vdev)
{
struct vfio_cdx_device *vdev =
container_of(core_vdev, struct vfio_cdx_device, vdev);
kfree(vdev->regions);
cdx_dev_reset(core_vdev->dev);
vfio_cdx_irqs_cleanup(vdev);
}
static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags,
void __user *arg, size_t argsz)
{
size_t minsz =
offsetofend(struct vfio_device_feature_bus_master, op);
struct vfio_cdx_device *vdev =
container_of(core_vdev, struct vfio_cdx_device, vdev);
Annotation
- Immediate include surface: `linux/vfio.h`, `linux/cdx/cdx_bus.h`, `private.h`.
- Detected declarations: `function Copyright`, `function vfio_cdx_release_dev`, `function vfio_cdx_open_device`, `function vfio_cdx_close_device`, `function vfio_cdx_bm_ctrl`, `function vfio_cdx_ioctl_feature`, `function vfio_cdx_ioctl_get_info`, `function vfio_cdx_ioctl_get_region_info`, `function vfio_cdx_ioctl_get_irq_info`, `function vfio_cdx_ioctl_set_irqs`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.