aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2017-08-18 10:04:57 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-08-29 15:27:52 -0400
commita4dec819c8bba6365eb893a4ca88db4dd1210110 (patch)
tree7c5c86d283b0d027f755ad8ee947573fa4c1d63e /drivers/gpu/drm
parente719d5169f75ead3c05329b4125afb67b4f33eba (diff)
drm/ttm: Add helper functions to populate/map in one call (v2)
These functions replace a section of common code found in radeon/amdgpu drivers (and possibly others) as part of the ttm_tt_*populate() callbacks. v2: squash in fix for sw iommu from Tom Signed-off-by: Tom St Denis <tom.stdenis@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r--drivers/gpu/drm/ttm/ttm_page_alloc.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index 871599826773..6a660d196d87 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -920,6 +920,47 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)
920} 920}
921EXPORT_SYMBOL(ttm_pool_unpopulate); 921EXPORT_SYMBOL(ttm_pool_unpopulate);
922 922
923int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt)
924{
925 unsigned i;
926 int r;
927
928 r = ttm_pool_populate(&tt->ttm);
929 if (r)
930 return r;
931
932 for (i = 0; i < tt->ttm.num_pages; i++) {
933 tt->dma_address[i] = dma_map_page(dev, tt->ttm.pages[i],
934 0, PAGE_SIZE,
935 DMA_BIDIRECTIONAL);
936 if (dma_mapping_error(dev, tt->dma_address[i])) {
937 while (i--) {
938 dma_unmap_page(dev, tt->dma_address[i],
939 PAGE_SIZE, DMA_BIDIRECTIONAL);
940 tt->dma_address[i] = 0;
941 }
942 ttm_pool_unpopulate(&tt->ttm);
943 return -EFAULT;
944 }
945 }
946 return 0;
947}
948EXPORT_SYMBOL(ttm_populate_and_map_pages);
949
950void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt)
951{
952 unsigned i;
953
954 for (i = 0; i < tt->ttm.num_pages; i++) {
955 if (tt->dma_address[i]) {
956 dma_unmap_page(dev, tt->dma_address[i],
957 PAGE_SIZE, DMA_BIDIRECTIONAL);
958 }
959 }
960 ttm_pool_unpopulate(&tt->ttm);
961}
962EXPORT_SYMBOL(ttm_unmap_and_unpopulate_pages);
963
923int ttm_page_alloc_debugfs(struct seq_file *m, void *data) 964int ttm_page_alloc_debugfs(struct seq_file *m, void *data)
924{ 965{
925 struct ttm_page_pool *p; 966 struct ttm_page_pool *p;