Lines Matching +full:virtio +full:- +full:pci
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 #include <linux/pci.h>
8 * vp_modern_map_capability - map a part of virtio pci capability
9 * @mdev: the modern virtio-pci device
25 struct pci_dev *dev = mdev->pci_dev; in vp_modern_map_capability()
39 dev_err(&dev->dev, in vp_modern_map_capability()
45 if (length - start < minlen) { in vp_modern_map_capability()
46 dev_err(&dev->dev, in vp_modern_map_capability()
52 length -= start; in vp_modern_map_capability()
55 dev_err(&dev->dev, in vp_modern_map_capability()
56 "virtio_pci: map wrap-around %u+%u\n", in vp_modern_map_capability()
63 if (offset & (align - 1)) { in vp_modern_map_capability()
64 dev_err(&dev->dev, in vp_modern_map_capability()
78 dev_err(&dev->dev, in vp_modern_map_capability()
79 "virtio_pci: map virtio %zu@%u " in vp_modern_map_capability()
88 dev_err(&dev->dev, in vp_modern_map_capability()
89 "virtio_pci: unable to map virtio %u@%u on bar %i\n", in vp_modern_map_capability()
98 * virtio_pci_find_capability - walk capabilities to find device info.
99 * @dev: the pci device
201 * vp_modern_probe: probe the modern virtio pci device, note that the
202 * caller is required to enable PCI device before calling this function.
203 * @mdev: the modern virtio-pci device
209 struct pci_dev *pci_dev = mdev->pci_dev; in vp_modern_probe()
216 mdev->pci_dev = pci_dev; in vp_modern_probe()
219 if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f) in vp_modern_probe()
220 return -ENODEV; in vp_modern_probe()
222 if (pci_dev->device < 0x1040) { in vp_modern_probe()
223 /* Transitional devices: use the PCI subsystem device id as in vp_modern_probe()
224 * virtio device id, same as legacy driver always did. in vp_modern_probe()
226 mdev->id.device = pci_dev->subsystem_device; in vp_modern_probe()
228 /* Modern devices: simply use PCI device id, but start from 0x1040. */ in vp_modern_probe()
229 mdev->id.device = pci_dev->device - 0x1040; in vp_modern_probe()
231 mdev->id.vendor = pci_dev->subsystem_vendor; in vp_modern_probe()
236 &mdev->modern_bars); in vp_modern_probe()
238 dev_info(&pci_dev->dev, in vp_modern_probe()
240 return -ENODEV; in vp_modern_probe()
246 &mdev->modern_bars); in vp_modern_probe()
249 &mdev->modern_bars); in vp_modern_probe()
251 dev_err(&pci_dev->dev, in vp_modern_probe()
254 return -EINVAL; in vp_modern_probe()
257 err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64)); in vp_modern_probe()
259 err = dma_set_mask_and_coherent(&pci_dev->dev, in vp_modern_probe()
262 …dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this migh… in vp_modern_probe()
265 * device-specific configuration. in vp_modern_probe()
269 &mdev->modern_bars); in vp_modern_probe()
271 err = pci_request_selected_regions(pci_dev, mdev->modern_bars, in vp_modern_probe()
272 "virtio-pci-modern"); in vp_modern_probe()
276 err = -EINVAL; in vp_modern_probe()
277 mdev->common = vp_modern_map_capability(mdev, common, in vp_modern_probe()
281 if (!mdev->common) in vp_modern_probe()
283 mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1, in vp_modern_probe()
286 if (!mdev->isr) in vp_modern_probe()
293 &mdev->notify_offset_multiplier); in vp_modern_probe()
310 mdev->notify_base = vp_modern_map_capability(mdev, notify, in vp_modern_probe()
313 &mdev->notify_len, in vp_modern_probe()
314 &mdev->notify_pa); in vp_modern_probe()
315 if (!mdev->notify_base) in vp_modern_probe()
318 mdev->notify_map_cap = notify; in vp_modern_probe()
325 mdev->device = vp_modern_map_capability(mdev, device, 0, 4, in vp_modern_probe()
327 &mdev->device_len, in vp_modern_probe()
329 if (!mdev->device) in vp_modern_probe()
336 if (mdev->notify_base) in vp_modern_probe()
337 pci_iounmap(pci_dev, mdev->notify_base); in vp_modern_probe()
339 pci_iounmap(pci_dev, mdev->isr); in vp_modern_probe()
341 pci_iounmap(pci_dev, mdev->common); in vp_modern_probe()
348 * vp_modern_probe: remove and cleanup the modern virtio pci device
349 * @mdev: the modern virtio-pci device
353 struct pci_dev *pci_dev = mdev->pci_dev; in vp_modern_remove()
355 if (mdev->device) in vp_modern_remove()
356 pci_iounmap(pci_dev, mdev->device); in vp_modern_remove()
357 if (mdev->notify_base) in vp_modern_remove()
358 pci_iounmap(pci_dev, mdev->notify_base); in vp_modern_remove()
359 pci_iounmap(pci_dev, mdev->isr); in vp_modern_remove()
360 pci_iounmap(pci_dev, mdev->common); in vp_modern_remove()
361 pci_release_selected_regions(pci_dev, mdev->modern_bars); in vp_modern_remove()
366 * vp_modern_get_features - get features from device
367 * @mdev: the modern virtio-pci device
373 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_features()
377 vp_iowrite32(0, &cfg->device_feature_select); in vp_modern_get_features()
378 features = vp_ioread32(&cfg->device_feature); in vp_modern_get_features()
379 vp_iowrite32(1, &cfg->device_feature_select); in vp_modern_get_features()
380 features |= ((u64)vp_ioread32(&cfg->device_feature) << 32); in vp_modern_get_features()
387 * vp_modern_get_driver_features - get driver features from device
388 * @mdev: the modern virtio-pci device
394 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_driver_features()
398 vp_iowrite32(0, &cfg->guest_feature_select); in vp_modern_get_driver_features()
399 features = vp_ioread32(&cfg->guest_feature); in vp_modern_get_driver_features()
400 vp_iowrite32(1, &cfg->guest_feature_select); in vp_modern_get_driver_features()
401 features |= ((u64)vp_ioread32(&cfg->guest_feature) << 32); in vp_modern_get_driver_features()
408 * vp_modern_set_features - set features to device
409 * @mdev: the modern virtio-pci device
415 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_set_features()
417 vp_iowrite32(0, &cfg->guest_feature_select); in vp_modern_set_features()
418 vp_iowrite32((u32)features, &cfg->guest_feature); in vp_modern_set_features()
419 vp_iowrite32(1, &cfg->guest_feature_select); in vp_modern_set_features()
420 vp_iowrite32(features >> 32, &cfg->guest_feature); in vp_modern_set_features()
425 * vp_modern_generation - get the device genreation
426 * @mdev: the modern virtio-pci device
432 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_generation()
434 return vp_ioread8(&cfg->config_generation); in vp_modern_generation()
439 * vp_modern_get_status - get the device status
440 * @mdev: the modern virtio-pci device
446 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_status()
448 return vp_ioread8(&cfg->device_status); in vp_modern_get_status()
453 * vp_modern_set_status - set status to device
454 * @mdev: the modern virtio-pci device
460 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_set_status()
462 vp_iowrite8(status, &cfg->device_status); in vp_modern_set_status()
467 * vp_modern_queue_vector - set the MSIX vector for a specific virtqueue
468 * @mdev: the modern virtio-pci device
477 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_queue_vector()
479 vp_iowrite16(index, &cfg->queue_select); in vp_modern_queue_vector()
480 vp_iowrite16(vector, &cfg->queue_msix_vector); in vp_modern_queue_vector()
482 return vp_ioread16(&cfg->queue_msix_vector); in vp_modern_queue_vector()
487 * vp_modern_config_vector - set the vector for config interrupt
488 * @mdev: the modern virtio-pci device
496 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_config_vector()
499 vp_iowrite16(vector, &cfg->msix_config); in vp_modern_config_vector()
502 return vp_ioread16(&cfg->msix_config); in vp_modern_config_vector()
507 * vp_modern_queue_address - set the virtqueue address
508 * @mdev: the modern virtio-pci device
518 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_queue_address()
520 vp_iowrite16(index, &cfg->queue_select); in vp_modern_queue_address()
522 vp_iowrite64_twopart(desc_addr, &cfg->queue_desc_lo, in vp_modern_queue_address()
523 &cfg->queue_desc_hi); in vp_modern_queue_address()
524 vp_iowrite64_twopart(driver_addr, &cfg->queue_avail_lo, in vp_modern_queue_address()
525 &cfg->queue_avail_hi); in vp_modern_queue_address()
526 vp_iowrite64_twopart(device_addr, &cfg->queue_used_lo, in vp_modern_queue_address()
527 &cfg->queue_used_hi); in vp_modern_queue_address()
532 * vp_modern_set_queue_enable - enable a virtqueue
533 * @mdev: the modern virtio-pci device
540 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_set_queue_enable()
541 vp_iowrite16(enable, &mdev->common->queue_enable); in vp_modern_set_queue_enable()
546 * vp_modern_get_queue_enable - enable a virtqueue
547 * @mdev: the modern virtio-pci device
555 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_enable()
557 return vp_ioread16(&mdev->common->queue_enable); in vp_modern_get_queue_enable()
562 * vp_modern_set_queue_size - set size for a virtqueue
563 * @mdev: the modern virtio-pci device
570 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_set_queue_size()
571 vp_iowrite16(size, &mdev->common->queue_size); in vp_modern_set_queue_size()
577 * vp_modern_get_queue_size - get size for a virtqueue
578 * @mdev: the modern virtio-pci device
586 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_size()
588 return vp_ioread16(&mdev->common->queue_size); in vp_modern_get_queue_size()
594 * vp_modern_get_num_queues - get the number of virtqueues
595 * @mdev: the modern virtio-pci device
601 return vp_ioread16(&mdev->common->num_queues); in vp_modern_get_num_queues()
606 * vp_modern_get_queue_notify_off - get notification offset for a virtqueue
607 * @mdev: the modern virtio-pci device
615 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_notify_off()
617 return vp_ioread16(&mdev->common->queue_notify_off); in vp_modern_get_queue_notify_off()
621 * vp_modern_map_vq_notify - map notification area for a
623 * @mdev: the modern virtio-pci device
634 if (mdev->notify_base) { in vp_modern_map_vq_notify()
636 if ((u64)off * mdev->notify_offset_multiplier + 2 in vp_modern_map_vq_notify()
637 > mdev->notify_len) { in vp_modern_map_vq_notify()
638 dev_warn(&mdev->pci_dev->dev, in vp_modern_map_vq_notify()
641 off, mdev->notify_offset_multiplier, in vp_modern_map_vq_notify()
642 index, mdev->notify_len); in vp_modern_map_vq_notify()
646 *pa = mdev->notify_pa + in vp_modern_map_vq_notify()
647 off * mdev->notify_offset_multiplier; in vp_modern_map_vq_notify()
648 return mdev->notify_base + off * mdev->notify_offset_multiplier; in vp_modern_map_vq_notify()
651 mdev->notify_map_cap, 2, 2, in vp_modern_map_vq_notify()
652 off * mdev->notify_offset_multiplier, 2, in vp_modern_map_vq_notify()
659 MODULE_DESCRIPTION("Modern Virtio PCI Device");