drivers/virtio/virtio_pci_legacy_dev.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio_pci_legacy_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio_pci_legacy_dev.c- Extension
.c- Size
- 6221 bytes
- Lines
- 223
- Domain
- Driver Families
- Bucket
- drivers/virtio
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/virtio_pci.hlinux/virtio_pci_legacy.hlinux/module.hlinux/pci.h
Detected Declarations
function vp_legacy_probefunction vp_legacy_removefunction vp_legacy_get_featuresfunction vp_legacy_get_driver_featuresfunction vp_legacy_set_featuresfunction vp_legacy_get_statusfunction vp_legacy_set_statusfunction vp_legacy_queue_vectorfunction vp_legacy_config_vectorfunction vp_legacy_set_queue_addressfunction vp_legacy_get_queue_enablefunction vp_legacy_get_queue_sizeexport vp_legacy_probeexport vp_legacy_removeexport vp_legacy_get_featuresexport vp_legacy_get_driver_featuresexport vp_legacy_set_featuresexport vp_legacy_get_statusexport vp_legacy_set_statusexport vp_legacy_queue_vectorexport vp_legacy_config_vectorexport vp_legacy_set_queue_addressexport vp_legacy_get_queue_enableexport vp_legacy_get_queue_size
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
#include "linux/virtio_pci.h"
#include <linux/virtio_pci_legacy.h>
#include <linux/module.h>
#include <linux/pci.h>
/*
* vp_legacy_probe: probe the legacy virtio pci device, note that the
* caller is required to enable PCI device before calling this function.
* @ldev: the legacy virtio-pci device
*
* Return 0 on succeed otherwise fail
*/
int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
{
struct pci_dev *pci_dev = ldev->pci_dev;
int rc;
/* We only own devices >= 0x1000 and <= 0x103f: leave the rest. */
if (pci_dev->device < 0x1000 || pci_dev->device > 0x103f)
return -ENODEV;
if (pci_dev->revision != VIRTIO_PCI_ABI_VERSION)
return -ENODEV;
rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
if (rc) {
rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
} else {
/*
* The virtio ring base address is expressed as a 32-bit PFN,
* with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
*/
dma_set_coherent_mask(&pci_dev->dev,
DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
}
if (rc)
dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
if (rc)
return rc;
ldev->ioaddr = pci_iomap(pci_dev, 0, 0);
if (!ldev->ioaddr) {
rc = -EIO;
goto err_iomap;
}
ldev->isr = ldev->ioaddr + VIRTIO_PCI_ISR;
ldev->id.vendor = pci_dev->subsystem_vendor;
ldev->id.device = pci_dev->subsystem_device;
return 0;
err_iomap:
pci_release_region(pci_dev, 0);
return rc;
}
EXPORT_SYMBOL_GPL(vp_legacy_probe);
/*
* vp_legacy_probe: remove and cleanup the legacy virtio pci device
* @ldev: the legacy virtio-pci device
*/
void vp_legacy_remove(struct virtio_pci_legacy_device *ldev)
{
struct pci_dev *pci_dev = ldev->pci_dev;
pci_iounmap(pci_dev, ldev->ioaddr);
pci_release_region(pci_dev, 0);
}
EXPORT_SYMBOL_GPL(vp_legacy_remove);
/*
* vp_legacy_get_features - get features from device
* @ldev: the legacy virtio-pci device
*
* Returns the features read from the device
*/
u64 vp_legacy_get_features(struct virtio_pci_legacy_device *ldev)
{
return ioread32(ldev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
}
EXPORT_SYMBOL_GPL(vp_legacy_get_features);
Annotation
- Immediate include surface: `linux/virtio_pci.h`, `linux/virtio_pci_legacy.h`, `linux/module.h`, `linux/pci.h`.
- Detected declarations: `function vp_legacy_probe`, `function vp_legacy_remove`, `function vp_legacy_get_features`, `function vp_legacy_get_driver_features`, `function vp_legacy_set_features`, `function vp_legacy_get_status`, `function vp_legacy_set_status`, `function vp_legacy_queue_vector`, `function vp_legacy_config_vector`, `function vp_legacy_set_queue_address`.
- Atlas domain: Driver Families / drivers/virtio.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.