dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] drm/vmwgfx: Clean- and fix up DMA mode selection
@ 2019-11-14 10:56 Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 1/3] drm/vmwgfx: Remove the vmw_dma_phys mode code Thomas Hellström (VMware)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas Hellström (VMware) @ 2019-11-14 10:56 UTC (permalink / raw)
  To: dri-devel, linux-graphics-maintainer; +Cc: Christoph Hellwig, Thomas Hellstrom

From: Thomas Hellstrom (VMware) <thomas_os@shipmail.org>

Clean up and fix dma mode selection. We remove an unused mode, a largely
unused module option and finally add a check to enable dma coherent memory
in those cases streaming dma mappings are undesired or won't work.

Note that this series is intended to be applied on top of
git://people.freedesktop.org/~thomash/linux branch vmwgfx-next

meaning that the vmw_dma_select mode function would, after applying the patches
look like

static int vmw_dma_select_mode(struct vmw_private *dev_priv)
{
	static const char *names[vmw_dma_map_max] = {
		[vmw_dma_alloc_coherent] = "Using coherent TTM pages.",
		[vmw_dma_map_populate] = "Caching DMA mappings.",
		[vmw_dma_map_bind] = "Giving up DMA mappings early."};

	/*
	 * dma_max_mapping_size() != SIZE_MAX means something is going
	 * on in the dma layer that the dma_map_bind or dma_map_populate modes
	 * are not working well with, or haven't been tested with.
	 * This typically happens when the SWIOTLB is active. Fall back to
	 * coherent memory in those cases.
	 */
	if (dma_max_mapping_size(dev_priv->dev->dev) != SIZE_MAX ||
	    vmw_force_coherent)
		dev_priv->map_mode = vmw_dma_alloc_coherent;
	else if (vmw_restrict_iommu)
		dev_priv->map_mode = vmw_dma_map_bind;
	else
		dev_priv->map_mode = vmw_dma_map_populate;

        if (!IS_ENABLED(CONFIG_DRM_TTM_DMA_PAGE_POOL) &&
	    (dev_priv->map_mode == vmw_dma_alloc_coherent))
		return -EINVAL;

	DRM_INFO("DMA map mode: %s\n", names[dev_priv->map_mode]);
	return 0;
}

Cc: Christoph Hellwig <hch@infradead.org>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] drm/vmwgfx: Remove the vmw_dma_phys mode code
  2019-11-14 10:56 [PATCH 0/3] drm/vmwgfx: Clean- and fix up DMA mode selection Thomas Hellström (VMware)
@ 2019-11-14 10:56 ` Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 2/3] drm/vmwgfx: Remove the restrict_dma_mask module parameter Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions Thomas Hellström (VMware)
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström (VMware) @ 2019-11-14 10:56 UTC (permalink / raw)
  To: dri-devel, linux-graphics-maintainer; +Cc: Thomas Hellstrom

From: Thomas Hellstrom <thellstrom@vmware.com>

This mode is not used anymore. Remove the dead code.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c        | 4 +---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h        | 1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 9 ---------
 3 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e962048f65d2..60ef03120917 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -564,7 +564,6 @@ static void vmw_get_initial_size(struct vmw_private *dev_priv)
 static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 {
 	static const char *names[vmw_dma_map_max] = {
-		[vmw_dma_phys] = "Using physical TTM page addresses.",
 		[vmw_dma_alloc_coherent] = "Using coherent TTM pages.",
 		[vmw_dma_map_populate] = "Caching DMA mappings.",
 		[vmw_dma_map_bind] = "Giving up DMA mappings early."};
@@ -598,8 +597,7 @@ static int vmw_dma_masks(struct vmw_private *dev_priv)
 	int ret = 0;
 
 	ret = dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(64));
-	if (dev_priv->map_mode != vmw_dma_phys &&
-	    (sizeof(unsigned long) == 4 || vmw_restrict_dma_mask)) {
+	if (sizeof(unsigned long) == 4 || vmw_restrict_dma_mask) {
 		DRM_INFO("Restricting DMA addresses to 44 bits.\n");
 		return dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(44));
 	}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index b18842f73081..761dbd424749 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -281,7 +281,6 @@ struct vmw_res_cache_entry {
  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  */
 enum vmw_dma_map_mode {
-	vmw_dma_phys,           /* Use physical page addresses */
 	vmw_dma_alloc_coherent, /* Use TTM coherent pages */
 	vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
 	vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index d8ea3dd10af0..8c0135f1c346 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -295,11 +295,6 @@ static struct page *__vmw_piter_non_sg_page(struct vmw_piter *viter)
  * pointed to by @viter. Functions are selected depending on the
  * current mapping mode.
  */
-static dma_addr_t __vmw_piter_phys_addr(struct vmw_piter *viter)
-{
-	return page_to_phys(viter->pages[viter->i]);
-}
-
 static dma_addr_t __vmw_piter_dma_addr(struct vmw_piter *viter)
 {
 	return viter->addrs[viter->i];
@@ -329,10 +324,6 @@ void vmw_piter_start(struct vmw_piter *viter, const struct vmw_sg_table *vsgt,
 	viter->page = &__vmw_piter_non_sg_page;
 	viter->pages = vsgt->pages;
 	switch (vsgt->mode) {
-	case vmw_dma_phys:
-		viter->next = &__vmw_piter_non_sg_next;
-		viter->dma_address = &__vmw_piter_phys_addr;
-		break;
 	case vmw_dma_alloc_coherent:
 		viter->next = &__vmw_piter_non_sg_next;
 		viter->dma_address = &__vmw_piter_dma_addr;
-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] drm/vmwgfx: Remove the restrict_dma_mask module parameter
  2019-11-14 10:56 [PATCH 0/3] drm/vmwgfx: Clean- and fix up DMA mode selection Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 1/3] drm/vmwgfx: Remove the vmw_dma_phys mode code Thomas Hellström (VMware)
@ 2019-11-14 10:56 ` Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions Thomas Hellström (VMware)
  2 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström (VMware) @ 2019-11-14 10:56 UTC (permalink / raw)
  To: dri-devel, linux-graphics-maintainer; +Cc: Thomas Hellstrom

From: Thomas Hellstrom <thellstrom@vmware.com>

The restrict_dma_mask was mainly used for iommu functionality debugging
and has no use anymore. Remove it.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 60ef03120917..8d479a411cdd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -255,7 +255,6 @@ static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
 static int vmw_force_iommu;
 static int vmw_restrict_iommu;
 static int vmw_force_coherent;
-static int vmw_restrict_dma_mask;
 static int vmw_assume_16bpp;
 
 static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
@@ -270,8 +269,6 @@ MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
 module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
 MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
 module_param_named(force_coherent, vmw_force_coherent, int, 0600);
-MODULE_PARM_DESC(restrict_dma_mask, "Restrict DMA mask to 44 bits with IOMMU");
-module_param_named(restrict_dma_mask, vmw_restrict_dma_mask, int, 0600);
 MODULE_PARM_DESC(assume_16bpp, "Assume 16-bpp when filtering modes");
 module_param_named(assume_16bpp, vmw_assume_16bpp, int, 0600);
 
@@ -597,7 +594,7 @@ static int vmw_dma_masks(struct vmw_private *dev_priv)
 	int ret = 0;
 
 	ret = dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(64));
-	if (sizeof(unsigned long) == 4 || vmw_restrict_dma_mask) {
+	if (sizeof(unsigned long) == 4) {
 		DRM_INFO("Restricting DMA addresses to 44 bits.\n");
 		return dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(44));
 	}
-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions
  2019-11-14 10:56 [PATCH 0/3] drm/vmwgfx: Clean- and fix up DMA mode selection Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 1/3] drm/vmwgfx: Remove the vmw_dma_phys mode code Thomas Hellström (VMware)
  2019-11-14 10:56 ` [PATCH 2/3] drm/vmwgfx: Remove the restrict_dma_mask module parameter Thomas Hellström (VMware)
@ 2019-11-14 10:56 ` Thomas Hellström (VMware)
       [not found]   ` <20191114124001.GB11619@infradead.org>
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas Hellström (VMware) @ 2019-11-14 10:56 UTC (permalink / raw)
  To: dri-devel, linux-graphics-maintainer
  Cc: Christoph Hellwig, Thomas Hellstrom, Brian Paul

From: Thomas Hellstrom <thellstrom@vmware.com>

We're gradually moving towards using DMA coherent memory in most
situations, although TTM interactions with the DMA layers is still a
work-in-progress. Meanwhile, use coherent memory when there are size
restrictions meaning that there is a chance that streaming dma mapping
of large buffer objects may fail.

Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 8d479a411cdd..24f8d88d4b28 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -565,7 +565,15 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 		[vmw_dma_map_populate] = "Caching DMA mappings.",
 		[vmw_dma_map_bind] = "Giving up DMA mappings early."};
 
-	if (vmw_force_coherent)
+	/*
+	 * dma_max_mapping_size() != SIZE_MAX means something is going
+	 * on in the dma layer that the dma_map_bind or dma_map_populate modes
+	 * are not working well with, or haven't been tested with.
+	 * This typically happens when the SWIOTLB is active. Fall back to
+	 * coherent memory in those cases.
+	 */
+	if (dma_max_mapping_size(dev_priv->dev->dev) != SIZE_MAX ||
+	    vmw_force_coherent)
 		dev_priv->map_mode = vmw_dma_alloc_coherent;
 	else if (vmw_restrict_iommu)
 		dev_priv->map_mode = vmw_dma_map_bind;
@@ -668,10 +676,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 		dev_priv->capabilities2 = vmw_read(dev_priv, SVGA_REG_CAP2);
 	}
 
-
-	ret = vmw_dma_select_mode(dev_priv);
-	if (unlikely(ret != 0)) {
-		DRM_INFO("Restricting capabilities due to IOMMU setup.\n");
+	if (vmw_dma_masks(dev_priv) || vmw_dma_select_mode(dev_priv)) {
+		DRM_WARN("Refusing DMA due to lack of DMA support.");
 		refuse_dma = true;
 	}
 
@@ -740,10 +746,6 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	if (dev_priv->capabilities & SVGA_CAP_CAP2_REGISTER)
 		vmw_print_capabilities2(dev_priv->capabilities2);
 
-	ret = vmw_dma_masks(dev_priv);
-	if (unlikely(ret != 0))
-		goto out_err0;
-
 	dma_set_max_seg_size(dev->dev, min_t(unsigned int, U32_MAX & PAGE_MASK,
 					     SCATTERLIST_MAX_SEGMENT));
 
-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions
       [not found]   ` <20191114124001.GB11619@infradead.org>
@ 2019-11-14 12:42     ` Thomas Hellström (VMware)
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström (VMware) @ 2019-11-14 12:42 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Brian Paul, Thomas Hellstrom, linux-graphics-maintainer, dri-devel

On 11/14/19 1:40 PM, Christoph Hellwig wrote:
> On Thu, Nov 14, 2019 at 11:56:45AM +0100, Thomas Hellström (VMware) wrote:
>> From: Thomas Hellstrom <thellstrom@vmware.com>
>>
>> We're gradually moving towards using DMA coherent memory in most
>> situations, although TTM interactions with the DMA layers is still a
>> work-in-progress. Meanwhile, use coherent memory when there are size
>> restrictions meaning that there is a chance that streaming dma mapping
>> of large buffer objects may fail.
> Unofrtunately that dma mapping size check really is completely
> broken.  For example the sparc32 iommus have mapping size limitations
> (which we just haven't wired up yet), but will never bounce buffer.
>
> Let me cook up a real API for you instead.  dma_addressing_limited()
> is fundamentally the right call for this, we just need to make it
> handle the corner cases you mentioned in reply to the last version of
> your patch.

Sounds great!

Thanks,

Thomas


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-11-14 12:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14 10:56 [PATCH 0/3] drm/vmwgfx: Clean- and fix up DMA mode selection Thomas Hellström (VMware)
2019-11-14 10:56 ` [PATCH 1/3] drm/vmwgfx: Remove the vmw_dma_phys mode code Thomas Hellström (VMware)
2019-11-14 10:56 ` [PATCH 2/3] drm/vmwgfx: Remove the restrict_dma_mask module parameter Thomas Hellström (VMware)
2019-11-14 10:56 ` [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions Thomas Hellström (VMware)
     [not found]   ` <20191114124001.GB11619@infradead.org>
2019-11-14 12:42     ` Thomas Hellström (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).