drm/vmwgfx: Clean- and fix up DMA mode selection
Subsystems (3)
cover drm/vmwgfx: Clean- and fix up DMA mode selection
From: Thomas Hellstrom (VMware) <[email protected]>
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 ofgit://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 <[email protected]>
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/3 drm/vmwgfx: Remove the vmw_dma_phys mode code
From: Thomas Hellstrom <[email protected]>
This mode is not used anymore. Remove the dead code.
--- 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(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -3
@@ -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 )); }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
@@ -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 */
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c +0 -9
@@ -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;
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/vmwgfx: Remove the restrict_dma_mask module parameter
In reply to Thomas Hellström (VMware)From: Thomas Hellstrom <[email protected]>
The restrict_dma_mask was mainly used for iommu functionality debugging and has no use anymore. Remove it.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -4
@@ -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 )); }
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions
In reply to Thomas Hellström (VMware)From: Thomas Hellstrom <[email protected]>
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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +11 -9
@@ -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 ));
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] drm/vmwgfx: Use coherent memory if there are dma mapping size restrictions
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Thomas Hellström (VMware)
From: Thomas Hellstrom <[email protected]>
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.
Quoted 8 lines
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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel