Skip to contentSkip to conversation

drm/vmwgfx: Fix setting of dma masks

PATCH In review Thomas Hellstrom 2 participants 3 messages Jan 29, 2019 – Jan 31, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/vmwgfx: Fix setting of dma masks

Previously we set only the dma mask and not the coherent mask. Fix that. Also, for clarity, make sure both are initially set to 64 bits.

Fixes 0d00c488f3de: ("drm/vmwgfx: Fix the driver for large dma addresses")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +6 -3
index 3e2bcff34032..ae9df4432bfc 100644
@@ -600,13 +600,16 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 static int vmw_dma_masks(struct vmw_private *dev_priv)
 {
 	struct drm_device *dev = dev_priv->dev;
+	int ret = 0;
 
-	if (intel_iommu_enabled &&
+	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)) {
 		DRM_INFO("Restricting DMA addresses to 44 bits.\n");
-		return dma_set_mask(dev->dev, DMA_BIT_MASK(44));
+		return dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(44));
 	}
-	return 0;
+
+	return ret;
 }
 
 static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
Signature · 6 lines
2.19.0.rc1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v2 2/2 drm/vmwgfx: Improve on IOMMU detection

instead of relying on intel_iommu_enabled, use the fact that the dma_map_ops::map_page != dma_direct_map_page.

---
v2: Merge fixes and typo fix in commit message. Also check for ops being non-NULL before dereferencing it.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +17 -2
index ae9df4432bfc..7ef5dcb06104 100644
@@ -26,6 +26,7 @@
  **************************************************************************/
 #include <linux/module.h>
 #include <linux/console.h>
+#include <linux/dma-mapping.h>
 
 #include <drm/drmP.h>
 #include "vmwgfx_drv.h"
@@ -34,7 +35,6 @@
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_module.h>
-#include <linux/intel-iommu.h>
 
 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
 #define VMWGFX_CHIP_SVGAII 0
@@ -545,6 +545,21 @@ static void vmw_get_initial_size(struct vmw_private *dev_priv)
 	dev_priv->initial_height = height;
 }
 
+/**
+ * vmw_assume_iommu - Figure out whether coherent dma-remapping might be
+ * taking place.
+ * @dev: Pointer to the struct drm_device.
+ *
+ * Return: true if iommu present, false otherwise.
+ */
+static bool vmw_assume_iommu(struct drm_device *dev)
+{
+	const struct dma_map_ops *ops = get_dma_ops(dev->dev);
+
+	return !dma_is_direct(ops) && ops &&
+		ops->map_page != dma_direct_map_page;
+}
+
 /**
  * vmw_dma_select_mode - Determine how DMA mappings should be set up for this
  * system.
@@ -568,7 +583,7 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 
 	if (vmw_force_coherent)
 		dev_priv->map_mode = vmw_dma_alloc_coherent;
-	else if (intel_iommu_enabled)
+	else if (vmw_assume_iommu(dev_priv->dev))
 		dev_priv->map_mode = vmw_dma_map_populate;
 	else if (!vmw_force_iommu)
 		dev_priv->map_mode = vmw_dma_phys;
Signature · 6 lines
2.19.0.rc1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#2 lore raw
In reply to Thomas Hellstrom

For the series

Quoted 37 lines · Thomas Hellstrom

Previously we set only the dma mask and not the coherent mask. Fix that.
Also, for clarity, make sure both are initially set to 64 bits.

Fixes 0d00c488f3de: ("drm/vmwgfx: Fix the driver for large dma

addresses")

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +6 -3
index 3e2bcff34032..ae9df4432bfc 100644
@@ -600,13 +600,16 @@ static int vmw_dma_select_mode(struct
 vmw_private *dev_priv)
 static int vmw_dma_masks(struct vmw_private *dev_priv)
 {
 	struct drm_device *dev = dev_priv->dev;
+	int ret = 0;
 
-	if (intel_iommu_enabled &&
+	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)) {
 		DRM_INFO("Restricting DMA addresses to 44 bits.\n");
-		return dma_set_mask(dev->dev, DMA_BIT_MASK(44));
+		return dma_set_mask_and_coherent(dev->dev,
 DMA_BIT_MASK(44));
 	}
-	return 0;
+
+	return ret;
 }
Quoted 2 lines

static int vmw_driver_load(struct drm_device *dev, unsigned long
chipset)

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel