drivers/vdpa/vdpa.c
Source file repositories/reference/linux-study-clean/drivers/vdpa/vdpa.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vdpa/vdpa.c- Extension
.c- Size
- 40588 bytes
- Lines
- 1587
- Domain
- Driver Families
- Bucket
- drivers/vdpa
- 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/module.hlinux/idr.hlinux/slab.hlinux/vdpa.huapi/linux/vdpa.hnet/genetlink.hlinux/mod_devicetable.hlinux/virtio_ids.h
Detected Declarations
struct vdpa_dev_dump_infofunction vdpa_set_statusfunction vdpa_dev_probefunction vdpa_dev_removefunction vdpa_dev_matchfunction vdpa_release_devfunction vdpa_alloc_devicefunction vdpa_name_matchfunction __vdpa_register_devicefunction vdpa_alloc_devicefunction vdpa_alloc_devicefunction dev_delfunction vdpa_unregister_devicefunction __vdpa_register_driverfunction vdpa_unregister_driverfunction vdpa_mgmtdev_registerfunction vdpa_match_removefunction vdpa_mgmtdev_unregisterfunction vdpa_get_config_unlockedfunction vdpa_get_configfunction vdpa_set_configfunction mgmtdev_handle_matchfunction list_for_each_entryfunction vdpa_nl_mgmtdev_handle_fillfunction vdpa_mgmtdev_get_classesfunction vdpa_mgmtdev_fillfunction vdpa_nl_cmd_mgmtdev_get_doitfunction vdpa_nl_cmd_mgmtdev_get_dumpitfunction BIT_ULLfunction vdpa_nl_cmd_dev_del_set_doitfunction vdpa_dev_fillfunction vdpa_nl_cmd_dev_get_doitfunction vdpa_dev_dumpfunction vdpa_nl_cmd_dev_get_dumpitfunction vdpa_dev_net_mq_config_fillfunction vdpa_dev_net_mtu_config_fillfunction vdpa_dev_net_mac_config_fillfunction vdpa_dev_net_status_config_fillfunction vdpa_dev_net_config_fillfunction vdpa_dev_blk_capacity_config_fillfunction vdpa_dev_blk_seg_size_config_fillfunction vdpa_dev_blk_block_size_config_fillfunction vdpa_dev_blk_seg_max_config_fillfunction vdpa_dev_blk_mq_config_fillfunction vdpa_dev_blk_topology_config_fillfunction vdpa_dev_blk_discard_config_fillfunction vdpa_dev_blk_write_zeroes_config_fillfunction vdpa_dev_blk_ro_config_fill
Annotated Snippet
static int vdpa_dev_match(struct device *dev, const struct device_driver *drv)
{
int ret;
/* Check override first, and if set, only use the named driver */
ret = device_match_driver_override(dev, drv);
if (ret >= 0)
return ret;
/* Currently devices must be supported by all vDPA bus drivers */
return 1;
}
static const struct bus_type vdpa_bus = {
.name = "vdpa",
.driver_override = true,
.match = vdpa_dev_match,
.probe = vdpa_dev_probe,
.remove = vdpa_dev_remove,
};
static void vdpa_release_dev(struct device *d)
{
struct vdpa_device *vdev = dev_to_vdpa(d);
const struct vdpa_config_ops *ops = vdev->config;
if (ops->free)
ops->free(vdev);
ida_free(&vdpa_index_ida, vdev->index);
kfree(vdev);
}
/**
* __vdpa_alloc_device - allocate and initilaize a vDPA device
* This allows driver to some prepartion after device is
* initialized but before registered.
* @parent: the parent device
* @config: the bus operations that is supported by this device
* @map: the map operations that is supported by this device
* @ngroups: number of groups supported by this device
* @nas: number of address spaces supported by this device
* @size: size of the parent structure that contains private data
* @name: name of the vdpa device; optional.
* @use_va: indicate whether virtual address must be used by this device
*
* Driver should use vdpa_alloc_device() wrapper macro instead of
* using this directly.
*
* Return: Returns an error when parent/config/map is not set or fail to get
* ida.
*/
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config,
const struct virtio_map_ops *map,
unsigned int ngroups, unsigned int nas,
size_t size, const char *name,
bool use_va)
{
struct vdpa_device *vdev;
int err = -EINVAL;
if (!config)
goto err;
if (!!config->dma_map != !!config->dma_unmap)
goto err;
/* It should only work for the device that use on-chip IOMMU */
if (use_va && !(config->dma_map || config->set_map))
goto err;
err = -ENOMEM;
vdev = kzalloc(size, GFP_KERNEL);
if (!vdev)
goto err;
err = ida_alloc(&vdpa_index_ida, GFP_KERNEL);
if (err < 0)
goto err_ida;
vdev->dev.bus = &vdpa_bus;
vdev->dev.parent = parent;
vdev->dev.release = vdpa_release_dev;
vdev->index = err;
vdev->config = config;
vdev->map = map;
vdev->features_valid = false;
vdev->use_va = use_va;
vdev->ngroups = ngroups;
Annotation
- Immediate include surface: `linux/module.h`, `linux/idr.h`, `linux/slab.h`, `linux/vdpa.h`, `uapi/linux/vdpa.h`, `net/genetlink.h`, `linux/mod_devicetable.h`, `linux/virtio_ids.h`.
- Detected declarations: `struct vdpa_dev_dump_info`, `function vdpa_set_status`, `function vdpa_dev_probe`, `function vdpa_dev_remove`, `function vdpa_dev_match`, `function vdpa_release_dev`, `function vdpa_alloc_device`, `function vdpa_name_match`, `function __vdpa_register_device`, `function vdpa_alloc_device`.
- Atlas domain: Driver Families / drivers/vdpa.
- Implementation status: pattern 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.