summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-10-18 16:24:53 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-11-10 18:46:54 -0500
commitee4970a33f41b56f2ada6a0b5ab6f9c400e39d88 (patch)
tree65d26ac7fd8667ac10cee8330a7647e9e72a745c /drivers/gpu/nvgpu/common/mm/nvgpu_mem.c
parent6911b4d48c414279731580f1212e29e4b691b04c (diff)
gpu: nvgpu: Make buf alignment generic
Drastically simplify and move the aligment computation for buffers getting mapped into the SGT code. An SGT is all that is needed for computing the alignment. However, this did require that a new SGT op was added: nvgpu_sgt_iommuable() This function returns true if the passed SGT is IOMMU'able and must be implemented by an SGT implementation that has IOMMU'able buffers. If this function is left as NULL then it is assumed that the buffer is not IOMMU'able. Also cleanup the parameter ordering convention among all nvgpu_sgt functions. Previously there was a mishmash of different parameter orderings. This patch now standardizes on the gk20a first approach seen everywhere else in the driver. JIRA NVGPU-30 JIRA NVGPU-246 JIRA NVGPU-71 Change-Id: Ic4ab7b752847cf795c7cfafed5a07818217bba86 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1583985 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/nvgpu_mem.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/nvgpu_mem.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c b/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c
index 9f677058..b4e718b4 100644
--- a/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c
+++ b/drivers/gpu/nvgpu/common/mm/nvgpu_mem.c
@@ -47,13 +47,20 @@ u64 nvgpu_sgt_get_length(struct nvgpu_sgt *sgt, void *sgl)
47 return sgt->ops->sgl_length(sgl); 47 return sgt->ops->sgl_length(sgl);
48} 48}
49 49
50u64 nvgpu_sgt_get_gpu_addr(struct nvgpu_sgt *sgt, struct gk20a *g, void *sgl, 50u64 nvgpu_sgt_get_gpu_addr(struct gk20a *g, struct nvgpu_sgt *sgt, void *sgl,
51 struct nvgpu_gmmu_attrs *attrs) 51 struct nvgpu_gmmu_attrs *attrs)
52{ 52{
53 return sgt->ops->sgl_gpu_addr(g, sgl, attrs); 53 return sgt->ops->sgl_gpu_addr(g, sgl, attrs);
54} 54}
55 55
56void nvgpu_sgt_free(struct nvgpu_sgt *sgt, struct gk20a *g) 56bool nvgpu_sgt_iommuable(struct gk20a *g, struct nvgpu_sgt *sgt)
57{
58 if (sgt->ops->sgt_iommuable)
59 return sgt->ops->sgt_iommuable(g, sgt);
60 return false;
61}
62
63void nvgpu_sgt_free(struct gk20a *g, struct nvgpu_sgt *sgt)
57{ 64{
58 if (sgt && sgt->ops->sgt_free) 65 if (sgt && sgt->ops->sgt_free)
59 sgt->ops->sgt_free(g, sgt); 66 sgt->ops->sgt_free(g, sgt);
@@ -69,3 +76,44 @@ u64 nvgpu_mem_iommu_translate(struct gk20a *g, u64 phys)
69 76
70 return phys; 77 return phys;
71} 78}
79
80/*
81 * Determine alignment for a passed buffer. Necessary since the buffer may
82 * appear big enough to map with large pages but the SGL may have chunks that
83 * are not aligned on a 64/128kB large page boundary. There's also the
84 * possibility chunks are odd sizes which will necessitate small page mappings
85 * to correctly glue them together into a contiguous virtual mapping.
86 */
87u64 nvgpu_sgt_alignment(struct gk20a *g, struct nvgpu_sgt *sgt)
88{
89 u64 align = 0, chunk_align = 0;
90 void *sgl;
91
92 /*
93 * If this SGT is iommuable and we want to use the IOMMU address then
94 * the SGT's first entry has the IOMMU address. We will align on this
95 * and double check length of buffer later. Also, since there's an
96 * IOMMU we know that this DMA address is contiguous.
97 */
98 if (!g->mm.bypass_smmu &&
99 nvgpu_sgt_iommuable(g, sgt) &&
100 nvgpu_sgt_get_dma(sgt, sgt->sgl))
101 return 1ULL << __ffs(nvgpu_sgt_get_dma(sgt, sgt->sgl));
102
103 /*
104 * Otherwise the buffer is not iommuable (VIDMEM, for example) or we are
105 * bypassing the IOMMU and need to use the underlying physical entries
106 * of the SGT.
107 */
108 nvgpu_sgt_for_each_sgl(sgl, sgt) {
109 chunk_align = 1ULL << __ffs(nvgpu_sgt_get_phys(sgt, sgl) |
110 nvgpu_sgt_get_length(sgt, sgl));
111
112 if (align)
113 align = min(align, chunk_align);
114 else
115 align = chunk_align;
116 }
117
118 return align;
119}