drm: add func to get max iomem address v2
Subsystems (3)
PATCH 1/3 drm: add func to get max iomem address v2
it will be used to check if the driver needs swiotlb
v2: Don't use inline, instead, move function to drm_memory.c (Mechel Daenzer <[email protected]>)
--- drivers/gpu/drm/drm_memory.c | 13 +++++++++++++ include/drm/drm_cache.h | 2 ++ 2 files changed, 15 insertions(+)
drivers/gpu/drm/drm_memory.c +13 -0
@@ -149,3 +149,16 @@ void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev)iounmap (map->handle); }EXPORT_SYMBOL (drm_legacy_ioremapfree); + +u64 drm_get_max_iomem (void ) +{ +struct resource *tmp; +u64 max_iomem =0 ; + +for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) { + max_iomem =max (max_iomem, tmp->end); + } + +return max_iomem; +} +EXPORT_SYMBOL (drm_get_max_iomem);
include/drm/drm_cache.h +2 -0
@@ -38,6 +38,8 @@void drm_clflush_pages (struct page *pages[],unsigned long num_pages);void drm_clflush_sg (struct sg_table *st);void drm_clflush_virt_range (void *addr,unsigned long length); +u64 drm_get_max_iomem (void ); +static inline bool drm_arch_can_wc_memory (void ) {
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/amdgpu: only enable swiotlb alloc when need v2
get the max io mapping address of system memory to see if it is over our card accessing range.
v2: move checking later
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 ++ 6 files changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -1437,6 +1437,7 @@ struct amdgpu_device {const struct amdgpu_asic_funcs *asic_funcs;bool shutdown;bool need_dma32; +bool need_swiotlb;bool accel_working;struct work_struct reset_work;struct notifier_block acpi_nb;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
@@ -1018,7 +1018,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm, }#ifdef CONFIG_SWIOTLB -if (swiotlb_nr_tbl ()) { +if (adev->need_swiotlb &&swiotlb_nr_tbl ()) {return ttm_dma_populate (>t->ttm, adev->dev, ctx); }#endif
@@ -1045,7 +1045,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm) adev =amdgpu_ttm_adev (ttm->bdev);#ifdef CONFIG_SWIOTLB -if (swiotlb_nr_tbl ()) { +if (adev->need_swiotlb &&swiotlb_nr_tbl ()) {ttm_dma_unpopulate (>t->ttm, adev->dev);return ; }
@@ -2007,7 +2007,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev) count =ARRAY_SIZE (amdgpu_ttm_debugfs_list);#ifdef CONFIG_SWIOTLB -if (!swiotlb_nr_tbl ()) +if (!(adev->need_swiotlb &&swiotlb_nr_tbl ())) --count;#endif
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2 -0
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> #include <drm/drmP.h> +#include <drm/drm_cache.h> #include "amdgpu.h" #include "gmc_v6_0.h" #include "amdgpu_ucode.h"
@@ -866,6 +867,7 @@ static int gmc_v6_0_sw_init(void *handle)pci_set_consistent_dma_mask (adev->pdev,DMA_BIT_MASK (32 ));dev_warn (adev->dev,"amdgpu: No coherent DMA available.\n" ); } + adev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits); r =gmc_v6_0_init_microcode (adev);if (r) {
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -0
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> #include <drm/drmP.h> +#include <drm/drm_cache.h> #include "amdgpu.h" #include "cikd.h" #include "cik.h"
@@ -1014,6 +1015,7 @@ static int gmc_v7_0_sw_init(void *handle)pci_set_consistent_dma_mask (adev->pdev,DMA_BIT_MASK (32 ));pr_warn ("amdgpu: No coherent DMA available\n" ); } + adev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits); r =gmc_v7_0_init_microcode (adev);if (r) {
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -0
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> #include <drm/drmP.h> +#include <drm/drm_cache.h> #include "amdgpu.h" #include "gmc_v8_0.h" #include "amdgpu_ucode.h"
@@ -1101,6 +1102,7 @@ static int gmc_v8_0_sw_init(void *handle)*/ adev->need_dma32 = false; dma_bits = adev->need_dma32 ?32 :40 ; + adev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits); r =pci_set_dma_mask (adev->pdev,DMA_BIT_MASK (dma_bits));if (r) { adev->need_dma32 = true;
@@ -1112,6 +1114,7 @@ static int gmc_v8_0_sw_init(void *handle)pci_set_consistent_dma_mask (adev->pdev,DMA_BIT_MASK (32 ));pr_warn ("amdgpu: No coherent DMA available\n" ); } + adev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits); r =gmc_v8_0_init_microcode (adev);if (r) {
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
@@ -21,6 +21,7 @@* */ #include <linux/firmware.h> +#include <drm/drm_cache.h> #include "amdgpu.h" #include "gmc_v9_0.h" #include "amdgpu_atomfirmware.h"
@@ -890,6 +891,7 @@ static int gmc_v9_0_sw_init(void *handle)pci_set_consistent_dma_mask (adev->pdev,DMA_BIT_MASK (32 ));printk (KERN_WARNING "amdgpu: No coherent DMA available.\n" ); } + adev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits); r =gmc_v9_0_mc_init (adev);if (r)
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/radeon: only enable swiotlb path when need v2
In reply to Chunming Zhouswiotlb expands our card accessing range, but its path always is slower than ttm pool allocation.
So add condition to use it.
v2: move a bit later
--- drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_device.c | 2 ++ drivers/gpu/drm/radeon/radeon_ttm.c | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
@@ -2387,6 +2387,7 @@ struct radeon_device {struct radeon_dummy_page dummy_page;bool shutdown;bool need_dma32; +bool need_swiotlb;bool accel_working;bool fastfb_working;/* IGP feature*/ bool needs_reset, in_reset;
drivers/gpu/drm/radeon/radeon_device.c +2 -0
@@ -29,6 +29,7 @@#include <linux/slab.h> #include <drm/drmP.h> #include <drm/drm_crtc_helper.h> +#include <drm/drm_cache.h> #include <drm/radeon_drm.h> #include <linux/pm_runtime.h> #include <linux/vgaarb.h>
@@ -1378,6 +1379,7 @@ int radeon_device_init(struct radeon_device *rdev,pci_set_consistent_dma_mask (rdev->pdev,DMA_BIT_MASK (32 ));pr_warn ("radeon: No coherent DMA available\n" ); } + rdev->need_swiotlb =drm_get_max_iomem () > ((u64 )1 << dma_bits);/* Registers mapping */ /* TODO: block userspace mapping of io register */
drivers/gpu/drm/radeon/radeon_ttm.c +3 -3
@@ -756,7 +756,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,#endif #ifdef CONFIG_SWIOTLB -if (swiotlb_nr_tbl ()) { +if (rdev->need_swiotlb &&swiotlb_nr_tbl ()) {return ttm_dma_populate (>t->ttm, rdev->dev, ctx); }#endif
@@ -788,7 +788,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)#endif #ifdef CONFIG_SWIOTLB -if (swiotlb_nr_tbl ()) { +if (rdev->need_swiotlb &&swiotlb_nr_tbl ()) {ttm_dma_unpopulate (>t->ttm, rdev->dev);return ; }
@@ -1155,7 +1155,7 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev) count =ARRAY_SIZE (radeon_ttm_debugfs_list);#ifdef CONFIG_SWIOTLB -if (!swiotlb_nr_tbl ()) +if (!(rdev->need_swiotlb &&swiotlb_nr_tbl ())) --count;#endif
Signature · 6 lines
2.14.1 _______________________________________________ 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]
Michel Dänzer
Reviewed-byQuoted 2 lines · Chunming Zhou
it will be used to check if the driver needs swiotlb
v2: Don't use inline, instead, move function todrm_memory.c(Mechel Daenzer <[email protected]>)
Typo in my first name. With that fixed,
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoting Chunming Zhou (2018-02-09 02:44:08)
Quoted 18 lines
it will be used to check if the driver needs swiotlb
v2: Don't use inline, instead, move function todrm_memory.c(Mechel Daenzer <[email protected]>)Change-Id Idbe47af8f12032d4803bb3d47273e807f19169c3Signed-off-by Chunming Zhou <[email protected]>Reviewed-by Monk Liu <[email protected]>Reviewed-by Christian König <[email protected]>--- drivers/gpu/drm/drm_memory.c | 13 +++++++++++++ include/drm/drm_cache.h | 2 ++ 2 files changed, 15 insertions(+)drivers/gpu/drm/drm_memory.c +0
-0@@ -149,3 +149,16 @@ void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev)iounmap (map->handle);
drivers/gpu/drm/drm_memory.c void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev) · line 159
Quoted 10 lines
drivers/gpu/drm/drm_memory.c +8
-0}EXPORT_SYMBOL (drm_legacy_ioremapfree); + +u64 drm_get_max_iomem (void ) +{ +struct resource *tmp; +u64 max_iomem =0 ; + +for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) { + max_iomem =max (max_iomem, tmp->end);
Note that resource.end is of type resource_size_t which is not u64 on 32b.
Either use max_t(u64) or resource_size_t max_iomem with the implicit cast on the return.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 33 lines · Chris Wilson
Quoting Chunming Zhou (2018-02-09 02:44:08)
Quoted 18 lines
it will be used to check if the driver needs swiotlb
v2: Don't use inline, instead, move function todrm_memory.c(Mechel Daenzer <[email protected]>)Change-Id Idbe47af8f12032d4803bb3d47273e807f19169c3Signed-off-by Chunming Zhou <[email protected]>Reviewed-by Monk Liu <[email protected]>Reviewed-by Christian König <[email protected]>--- drivers/gpu/drm/drm_memory.c | 13 +++++++++++++ include/drm/drm_cache.h | 2 ++ 2 files changed, 15 insertions(+)drivers/gpu/drm/drm_memory.c +0
-0@@ -149,3 +149,16 @@ void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev)iounmap (map->handle);drivers/gpu/drm/drm_memory.c void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev) · line 159
Quoted 10 lines
drivers/gpu/drm/drm_memory.c +8
-0}EXPORT_SYMBOL (drm_legacy_ioremapfree); + +u64 drm_get_max_iomem (void ) +{ +struct resource *tmp; +u64 max_iomem =0 ; + +for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) { + max_iomem =max (max_iomem, tmp->end);Note that resource.end is of type
resource_size_twhich is not u64 on 32b.
Quoted 2 lines
Either use
max_t(u64)orresource_size_tmax_iomemwith the implicit cast on the return.
Yeah linux-next spotted that one too, pls fix in a follow-up with the other things I've raised (lack of kerneldoc mostly). -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel