pci_read_config_byte(dev, off + offsetof(struct virtio_pci_cap,
bar),
&bar);
pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, offset),
&offset);
pci_read_config_dword(dev, off + offsetof(struct virtio_pci_cap, length),
&length);
/* Check if the BAR may have changed since we requested the region. */ if (bar >= PCI_STD_NUM_BARS || !(mdev->modern_bars & (1 << bar))) {
dev_err(&dev->dev, "virtio_pci: bar unexpectedly changed to %u\n", bar); return NULL;
}
if (length <= start) {
dev_err(&dev->dev, "virtio_pci: bad capability len %u (>%u expected)\n",
length, start); return NULL;
}
if (length - start < minlen) {
dev_err(&dev->dev, "virtio_pci: bad capability len %u (>=%zu expected)\n",
length, minlen); return NULL;
}
if (offset & (align - 1)) {
dev_err(&dev->dev, "virtio_pci: offset %u not aligned to %u\n",
offset, align); return NULL;
}
if (length > size)
length = size;
if (len)
*len = length;
if (minlen + offset < minlen ||
minlen + offset > pci_resource_len(dev, bar)) {
dev_err(&dev->dev, "virtio_pci: map virtio %zu@%u " "out of range on bar %i length %lu\n",
minlen, offset,
bar, (unsignedlong)pci_resource_len(dev, bar)); return NULL;
}
p = pci_iomap_range(dev, bar, offset, length); if (!p)
dev_err(&dev->dev, "virtio_pci: unable to map virtio %u@%u on bar %i\n",
length, offset, bar); elseif (pa)
*pa = pci_resource_start(dev, bar) + offset;
/* *vp_modern_probe:probethemodernvirtiopcidevice,notethatthe *callerisrequiredtoenablePCIdevicebeforecallingthisfunction. *@mdev:themodernvirtio-pcidevice * *Return0onsucceedotherwisefail
*/ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
{ struct pci_dev *pci_dev = mdev->pci_dev; int err, common, isr, notify, device;
u32 notify_length;
u32 notify_offset; int devid;
check_offsets();
if (mdev->device_id_check) {
devid = mdev->device_id_check(pci_dev); if (devid < 0) return devid;
mdev->id.device = devid;
} else { /* We only own devices >= 0x1000 and <= 0x107f: leave the rest. */ if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f) return -ENODEV;
if (pci_dev->device < 0x1040) { /* Transitional devices: use the PCI subsystem device id as *virtiodeviceid,sameaslegacydriveralwaysdid.
*/
mdev->id.device = pci_dev->subsystem_device;
} else { /* Modern devices: simply use PCI device id, but start from 0x1040. */
mdev->id.device = pci_dev->device - 0x1040;
}
}
mdev->id.vendor = pci_dev->subsystem_vendor;
/* check for a common config: if not, use legacy mode (bar 0). */
common = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_COMMON_CFG,
IORESOURCE_IO | IORESOURCE_MEM,
&mdev->modern_bars); if (!common) {
dev_info(&pci_dev->dev, "virtio_pci: leaving for legacy driver\n"); return -ENODEV;
}
/* If common is there, these should be too... */
isr = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_ISR_CFG,
IORESOURCE_IO | IORESOURCE_MEM,
&mdev->modern_bars);
notify = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_NOTIFY_CFG,
IORESOURCE_IO | IORESOURCE_MEM,
&mdev->modern_bars); if (!isr || !notify) {
dev_err(&pci_dev->dev, "virtio_pci: missing capabilities %i/%i/%i\n",
common, isr, notify); return -EINVAL;
}
err = dma_set_mask_and_coherent(&pci_dev->dev,
mdev->dma_mask ? : DMA_BIT_MASK(64)); if (err)
err = dma_set_mask_and_coherent(&pci_dev->dev,
DMA_BIT_MASK(32)); if (err)
dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
/* Device capability is only mandatory for devices that have *device-specificconfiguration.
*/
device = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_DEVICE_CFG,
IORESOURCE_IO | IORESOURCE_MEM,
&mdev->modern_bars);
err = pci_request_selected_regions(pci_dev, mdev->modern_bars, "virtio-pci-modern"); if (err) return err;
/* We don't know how many VQs we'll map, ahead of the time. *Ifnotifylengthissmall,mapitallnow. *Otherwise,mapeachVQindividuallylater.
*/ if ((u64)notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) {
mdev->notify_base = vp_modern_map_capability(mdev, notify, 2, 2, 0, notify_length,
&mdev->notify_len,
&mdev->notify_pa); if (!mdev->notify_base) goto err_map_notify;
} else {
mdev->notify_map_cap = notify;
}
/* Again, we don't know how much we should map, but PAGE_SIZE *ismorethanenoughforallexistingdevices.
*/ if (device) {
mdev->device = vp_modern_map_capability(mdev, device, 0, 4, 0, PAGE_SIZE,
&mdev->device_len,
NULL); if (!mdev->device) goto err_map_device;
}
/* Setup the vector used for configuration events */
vp_iowrite16(vector, &cfg->msix_config); /* Verify we had enough resources to assign the vector */ /* Will also flush the write out to device */ return vp_ioread16(&cfg->msix_config);
}
EXPORT_SYMBOL_GPL(vp_modern_config_vector);
MODULE_VERSION("0.1");
MODULE_DESCRIPTION("Modern Virtio PCI Device");
MODULE_AUTHOR("Jason Wang <jasowang@redhat.com>");
MODULE_LICENSE("GPL");
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.19Bemerkung:
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.