virtio: allow caller to override device DMA mask in vp_modern
authorShannon Nelson <shannon.nelson@amd.com>
Fri, 19 May 2023 21:56:23 +0000 (14:56 -0700)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 27 Jun 2023 14:47:08 +0000 (10:47 -0400)
To add a bit of vendor flexibility with various virtio based devices,
allow the caller to specify a different DMA mask.  This adds a dma_mask
field to struct virtio_pci_modern_device.  If defined by the driver,
this mask will be used in a call to dma_set_mask_and_coherent() instead
of the traditional DMA_BIT_MASK(64).  This allows limiting the DMA space
on vendor devices with address limitations.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230519215632.12343-3-shannon.nelson@amd.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_pci_modern_dev.c
include/linux/virtio_pci_modern.h

index 9b2d6614de674c8b5c020ac6d65619989081fbeb..aad7d9296e772063f8a15757cdf33c0ba1b2fc7d 100644 (file)
@@ -268,7 +268,8 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
                return -EINVAL;
        }
 
-       err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64));
+       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));
index e7b1db1dd0bb0a61c24fa1eb0596861947a2f3bf..067ac1d789bcb64917c5cbef40791f4a04b50380 100644 (file)
@@ -41,6 +41,9 @@ struct virtio_pci_modern_device {
 
        /* optional check for vendor virtio device, returns dev_id or -ERRNO */
        int (*device_id_check)(struct pci_dev *pdev);
+
+       /* optional mask for devices with limited DMA space */
+       u64 dma_mask;
 };
 
 /*