Lines Matching +full:virtio +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * vp_modern_map_capability - map a part of virtio pci capability
10 * @mdev: the modern virtio-pci device
26 struct pci_dev *dev = mdev->pci_dev; in vp_modern_map_capability()
40 if (bar >= PCI_STD_NUM_BARS || !(mdev->modern_bars & (1 << bar))) { in vp_modern_map_capability()
41 dev_err(&dev->dev, in vp_modern_map_capability()
47 dev_err(&dev->dev, in vp_modern_map_capability()
53 if (length - start < minlen) { in vp_modern_map_capability()
54 dev_err(&dev->dev, in vp_modern_map_capability()
60 length -= start; in vp_modern_map_capability()
63 dev_err(&dev->dev, in vp_modern_map_capability()
64 "virtio_pci: map wrap-around %u+%u\n", in vp_modern_map_capability()
71 if (offset & (align - 1)) { in vp_modern_map_capability()
72 dev_err(&dev->dev, in vp_modern_map_capability()
86 dev_err(&dev->dev, in vp_modern_map_capability()
87 "virtio_pci: map virtio %zu@%u " in vp_modern_map_capability()
96 dev_err(&dev->dev, in vp_modern_map_capability()
97 "virtio_pci: unable to map virtio %u@%u on bar %i\n", in vp_modern_map_capability()
106 * virtio_pci_find_capability - walk capabilities to find device info.
107 * @dev: the pci device
209 * vp_modern_probe: probe the modern virtio pci device, note that the
210 * caller is required to enable PCI device before calling this function.
211 * @mdev: the modern virtio-pci device
217 struct pci_dev *pci_dev = mdev->pci_dev; in vp_modern_probe()
218 int err, common, isr, notify, device; in vp_modern_probe() local
225 if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f) in vp_modern_probe()
226 return -ENODEV; in vp_modern_probe()
228 if (pci_dev->device < 0x1040) { in vp_modern_probe()
229 /* Transitional devices: use the PCI subsystem device id as in vp_modern_probe()
230 * virtio device id, same as legacy driver always did. in vp_modern_probe()
232 mdev->id.device = pci_dev->subsystem_device; in vp_modern_probe()
234 /* Modern devices: simply use PCI device id, but start from 0x1040. */ in vp_modern_probe()
235 mdev->id.device = pci_dev->device - 0x1040; in vp_modern_probe()
237 mdev->id.vendor = pci_dev->subsystem_vendor; in vp_modern_probe()
242 &mdev->modern_bars); in vp_modern_probe()
244 dev_info(&pci_dev->dev, in vp_modern_probe()
246 return -ENODEV; in vp_modern_probe()
252 &mdev->modern_bars); in vp_modern_probe()
255 &mdev->modern_bars); in vp_modern_probe()
257 dev_err(&pci_dev->dev, in vp_modern_probe()
260 return -EINVAL; in vp_modern_probe()
263 err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64)); in vp_modern_probe()
265 err = dma_set_mask_and_coherent(&pci_dev->dev, in vp_modern_probe()
268 …dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this migh… in vp_modern_probe()
270 /* Device capability is only mandatory for devices that have in vp_modern_probe()
271 * device-specific configuration. in vp_modern_probe()
273 device = virtio_pci_find_capability(pci_dev, VIRTIO_PCI_CAP_DEVICE_CFG, in vp_modern_probe()
275 &mdev->modern_bars); in vp_modern_probe()
277 err = pci_request_selected_regions(pci_dev, mdev->modern_bars, in vp_modern_probe()
278 "virtio-pci-modern"); in vp_modern_probe()
282 err = -EINVAL; in vp_modern_probe()
283 mdev->common = vp_modern_map_capability(mdev, common, in vp_modern_probe()
287 if (!mdev->common) in vp_modern_probe()
289 mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1, in vp_modern_probe()
292 if (!mdev->isr) in vp_modern_probe()
299 &mdev->notify_offset_multiplier); in vp_modern_probe()
316 mdev->notify_base = vp_modern_map_capability(mdev, notify, in vp_modern_probe()
319 &mdev->notify_len, in vp_modern_probe()
320 &mdev->notify_pa); in vp_modern_probe()
321 if (!mdev->notify_base) in vp_modern_probe()
324 mdev->notify_map_cap = notify; in vp_modern_probe()
330 if (device) { in vp_modern_probe()
331 mdev->device = vp_modern_map_capability(mdev, device, 0, 4, in vp_modern_probe()
333 &mdev->device_len, in vp_modern_probe()
335 if (!mdev->device) in vp_modern_probe()
342 if (mdev->notify_base) in vp_modern_probe()
343 pci_iounmap(pci_dev, mdev->notify_base); in vp_modern_probe()
345 pci_iounmap(pci_dev, mdev->isr); in vp_modern_probe()
347 pci_iounmap(pci_dev, mdev->common); in vp_modern_probe()
349 pci_release_selected_regions(pci_dev, mdev->modern_bars); in vp_modern_probe()
355 * vp_modern_remove: remove and cleanup the modern virtio pci device
356 * @mdev: the modern virtio-pci device
360 struct pci_dev *pci_dev = mdev->pci_dev; in vp_modern_remove()
362 if (mdev->device) in vp_modern_remove()
363 pci_iounmap(pci_dev, mdev->device); in vp_modern_remove()
364 if (mdev->notify_base) in vp_modern_remove()
365 pci_iounmap(pci_dev, mdev->notify_base); in vp_modern_remove()
366 pci_iounmap(pci_dev, mdev->isr); in vp_modern_remove()
367 pci_iounmap(pci_dev, mdev->common); in vp_modern_remove()
368 pci_release_selected_regions(pci_dev, mdev->modern_bars); in vp_modern_remove()
373 * vp_modern_get_features - get features from device
374 * @mdev: the modern virtio-pci device
376 * Returns the features read from the device
380 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_features()
384 vp_iowrite32(0, &cfg->device_feature_select); in vp_modern_get_features()
385 features = vp_ioread32(&cfg->device_feature); in vp_modern_get_features()
386 vp_iowrite32(1, &cfg->device_feature_select); in vp_modern_get_features()
387 features |= ((u64)vp_ioread32(&cfg->device_feature) << 32); in vp_modern_get_features()
394 * vp_modern_get_driver_features - get driver features from device
395 * @mdev: the modern virtio-pci device
397 * Returns the driver features read from the device
401 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_driver_features()
405 vp_iowrite32(0, &cfg->guest_feature_select); in vp_modern_get_driver_features()
406 features = vp_ioread32(&cfg->guest_feature); in vp_modern_get_driver_features()
407 vp_iowrite32(1, &cfg->guest_feature_select); in vp_modern_get_driver_features()
408 features |= ((u64)vp_ioread32(&cfg->guest_feature) << 32); in vp_modern_get_driver_features()
415 * vp_modern_set_features - set features to device
416 * @mdev: the modern virtio-pci device
417 * @features: the features set to device
422 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_set_features()
424 vp_iowrite32(0, &cfg->guest_feature_select); in vp_modern_set_features()
425 vp_iowrite32((u32)features, &cfg->guest_feature); in vp_modern_set_features()
426 vp_iowrite32(1, &cfg->guest_feature_select); in vp_modern_set_features()
427 vp_iowrite32(features >> 32, &cfg->guest_feature); in vp_modern_set_features()
432 * vp_modern_generation - get the device genreation
433 * @mdev: the modern virtio-pci device
435 * Returns the genreation read from device
439 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_generation()
441 return vp_ioread8(&cfg->config_generation); in vp_modern_generation()
446 * vp_modern_get_status - get the device status
447 * @mdev: the modern virtio-pci device
449 * Returns the status read from device
453 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_get_status()
455 return vp_ioread8(&cfg->device_status); in vp_modern_get_status()
460 * vp_modern_set_status - set status to device
461 * @mdev: the modern virtio-pci device
462 * @status: the status set to device
467 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_set_status()
470 * Per memory-barriers.txt, wmb() is not needed to guarantee in vp_modern_set_status()
474 vp_iowrite8(status, &cfg->device_status); in vp_modern_set_status()
479 * vp_modern_get_queue_reset - get the queue reset status
480 * @mdev: the modern virtio-pci device
487 cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common; in vp_modern_get_queue_reset()
489 vp_iowrite16(index, &cfg->cfg.queue_select); in vp_modern_get_queue_reset()
490 return vp_ioread16(&cfg->queue_reset); in vp_modern_get_queue_reset()
495 * vp_modern_set_queue_reset - reset the queue
496 * @mdev: the modern virtio-pci device
503 cfg = (struct virtio_pci_modern_common_cfg __iomem *)mdev->common; in vp_modern_set_queue_reset()
505 vp_iowrite16(index, &cfg->cfg.queue_select); in vp_modern_set_queue_reset()
506 vp_iowrite16(1, &cfg->queue_reset); in vp_modern_set_queue_reset()
508 while (vp_ioread16(&cfg->queue_reset)) in vp_modern_set_queue_reset()
511 while (vp_ioread16(&cfg->cfg.queue_enable)) in vp_modern_set_queue_reset()
517 * vp_modern_queue_vector - set the MSIX vector for a specific virtqueue
518 * @mdev: the modern virtio-pci device
522 * Returns the config vector read from the device
527 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_queue_vector()
529 vp_iowrite16(index, &cfg->queue_select); in vp_modern_queue_vector()
530 vp_iowrite16(vector, &cfg->queue_msix_vector); in vp_modern_queue_vector()
531 /* Flush the write out to device */ in vp_modern_queue_vector()
532 return vp_ioread16(&cfg->queue_msix_vector); in vp_modern_queue_vector()
537 * vp_modern_config_vector - set the vector for config interrupt
538 * @mdev: the modern virtio-pci device
541 * Returns the config vector read from the device
546 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_config_vector()
549 vp_iowrite16(vector, &cfg->msix_config); in vp_modern_config_vector()
551 /* Will also flush the write out to device */ in vp_modern_config_vector()
552 return vp_ioread16(&cfg->msix_config); in vp_modern_config_vector()
557 * vp_modern_queue_address - set the virtqueue address
558 * @mdev: the modern virtio-pci device
562 * @device_addr: address of the device area
568 struct virtio_pci_common_cfg __iomem *cfg = mdev->common; in vp_modern_queue_address()
570 vp_iowrite16(index, &cfg->queue_select); in vp_modern_queue_address()
572 vp_iowrite64_twopart(desc_addr, &cfg->queue_desc_lo, in vp_modern_queue_address()
573 &cfg->queue_desc_hi); in vp_modern_queue_address()
574 vp_iowrite64_twopart(driver_addr, &cfg->queue_avail_lo, in vp_modern_queue_address()
575 &cfg->queue_avail_hi); in vp_modern_queue_address()
576 vp_iowrite64_twopart(device_addr, &cfg->queue_used_lo, in vp_modern_queue_address()
577 &cfg->queue_used_hi); in vp_modern_queue_address()
582 * vp_modern_set_queue_enable - enable a virtqueue
583 * @mdev: the modern virtio-pci device
590 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_set_queue_enable()
591 vp_iowrite16(enable, &mdev->common->queue_enable); in vp_modern_set_queue_enable()
596 * vp_modern_get_queue_enable - enable a virtqueue
597 * @mdev: the modern virtio-pci device
605 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_enable()
607 return vp_ioread16(&mdev->common->queue_enable); in vp_modern_get_queue_enable()
612 * vp_modern_set_queue_size - set size for a virtqueue
613 * @mdev: the modern virtio-pci device
620 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_set_queue_size()
621 vp_iowrite16(size, &mdev->common->queue_size); in vp_modern_set_queue_size()
627 * vp_modern_get_queue_size - get size for a virtqueue
628 * @mdev: the modern virtio-pci device
636 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_size()
638 return vp_ioread16(&mdev->common->queue_size); in vp_modern_get_queue_size()
644 * vp_modern_get_num_queues - get the number of virtqueues
645 * @mdev: the modern virtio-pci device
651 return vp_ioread16(&mdev->common->num_queues); in vp_modern_get_num_queues()
656 * vp_modern_get_queue_notify_off - get notification offset for a virtqueue
657 * @mdev: the modern virtio-pci device
665 vp_iowrite16(index, &mdev->common->queue_select); in vp_modern_get_queue_notify_off()
667 return vp_ioread16(&mdev->common->queue_notify_off); in vp_modern_get_queue_notify_off()
671 * vp_modern_map_vq_notify - map notification area for a
673 * @mdev: the modern virtio-pci device
684 if (mdev->notify_base) { in vp_modern_map_vq_notify()
686 if ((u64)off * mdev->notify_offset_multiplier + 2 in vp_modern_map_vq_notify()
687 > mdev->notify_len) { in vp_modern_map_vq_notify()
688 dev_warn(&mdev->pci_dev->dev, in vp_modern_map_vq_notify()
691 off, mdev->notify_offset_multiplier, in vp_modern_map_vq_notify()
692 index, mdev->notify_len); in vp_modern_map_vq_notify()
696 *pa = mdev->notify_pa + in vp_modern_map_vq_notify()
697 off * mdev->notify_offset_multiplier; in vp_modern_map_vq_notify()
698 return mdev->notify_base + off * mdev->notify_offset_multiplier; in vp_modern_map_vq_notify()
701 mdev->notify_map_cap, 2, 2, in vp_modern_map_vq_notify()
702 off * mdev->notify_offset_multiplier, 2, in vp_modern_map_vq_notify()
709 MODULE_DESCRIPTION("Modern Virtio PCI Device");