diff mbox series

[v5,virtio,02/11] virtio: allow caller to override device DMA mask in vp_modern

Message ID 20230503181240.14009-3-shannon.nelson@amd.com (mailing list archive)
State Superseded
Headers show
Series pds_vdpa driver | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Nelson, Shannon May 3, 2023, 6:12 p.m. UTC
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>
---
 drivers/virtio/virtio_pci_modern_dev.c | 3 ++-
 include/linux/virtio_pci_modern.h      | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Jason Wang May 15, 2023, 2:54 a.m. UTC | #1
在 2023/5/4 02:12, Shannon Nelson 写道:
> 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>

Thanks


> ---
>   drivers/virtio/virtio_pci_modern_dev.c | 3 ++-
>   include/linux/virtio_pci_modern.h      | 3 +++
>   2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
> index 9b2d6614de67..aad7d9296e77 100644
> --- a/drivers/virtio/virtio_pci_modern_dev.c
> +++ b/drivers/virtio/virtio_pci_modern_dev.c
> @@ -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));
> diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
> index e7b1db1dd0bb..067ac1d789bc 100644
> --- a/include/linux/virtio_pci_modern.h
> +++ b/include/linux/virtio_pci_modern.h
> @@ -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;
>   };
>   
>   /*
diff mbox series

Patch

diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 9b2d6614de67..aad7d9296e77 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -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));
diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
index e7b1db1dd0bb..067ac1d789bc 100644
--- a/include/linux/virtio_pci_modern.h
+++ b/include/linux/virtio_pci_modern.h
@@ -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;
 };
 
 /*