summaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorseshendra Gadagottu <sgadagottu@nvidia.com>2017-10-02 14:03:05 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-10-13 18:19:11 -0400
commit017a9f57756f120cb492fc6c66d8588a2c1626d8 (patch)
tree1215d9baee83f293c23ebfe56beb030b1c8b3e22 /drivers/gpu
parentceaab0595c0af8dfe4b71ca4014a9b44a862a0ef (diff)
gpu: nvgpu: add API to create nvgpu_mem from phys
Added new memory API _nvgpu_mem_create_from_phys for creating nvgpu_mem from physical memory aperture. With this new API, avoided usage of linux specific "struct page" in general code and moved this code to common linux code. This API internally uses __nvgpu_mem_create_from_pages for creating nvgpu_mem from physical pages. JIRA GPUT19X-2 Change-Id: Iaf0193a7c33e71422e4ddabde01edf46f5a81794 Signed-off-by: seshendra Gadagottu <sgadagottu@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1571073 Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: Alex Waterman <alexw@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/nvgpu/common/linux/nvgpu_mem.c19
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h20
2 files changed, 39 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c
index 9b9f58e1..eb51676c 100644
--- a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c
+++ b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c
@@ -472,6 +472,25 @@ int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest,
472 return 0; 472 return 0;
473} 473}
474 474
475int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest,
476 u64 src_phys, int nr_pages)
477{
478 struct page **pages =
479 nvgpu_kmalloc(g, sizeof(struct page *) * nr_pages);
480 int i, ret = 0;
481
482 if (!pages)
483 return -ENOMEM;
484
485 for (i = 0; i < nr_pages; i++)
486 pages[i] = phys_to_page(src_phys + PAGE_SIZE * i);
487
488 ret = __nvgpu_mem_create_from_pages(g, dest, pages, nr_pages);
489 nvgpu_kfree(g, pages);
490
491 return ret;
492}
493
475static void *nvgpu_mem_linux_sgl_next(void *sgl) 494static void *nvgpu_mem_linux_sgl_next(void *sgl)
476{ 495{
477 return sg_next((struct scatterlist *)sgl); 496 return sg_next((struct scatterlist *)sgl);
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h
index 517d834c..e5f5031a 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h
@@ -66,4 +66,24 @@ struct nvgpu_sgt *nvgpu_linux_sgt_create(struct gk20a *g,
66int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest, 66int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest,
67 struct page **pages, int nr_pages); 67 struct page **pages, int nr_pages);
68 68
69/**
70 * __nvgpu_mem_create_from_phys - Create an nvgpu_mem from physical mem.
71 *
72 * @g - The GPU.
73 * @dest - nvgpu_mem to initialize.
74 * @src_phys - start address of physical mem
75 * @nr_pages - The number of pages in phys.
76 *
77 * Create a new nvgpu_mem struct from a physical memory aperure. The physical
78 * memory aperture needs to be contiguous for requested @nr_pages. This API
79 * only works for SYSMEM.
80 *
81 * The resulting nvgpu_mem should be released with the nvgpu_dma_free() or the
82 * nvgpu_dma_unmap_free() function depending on whether or not the resulting
83 * nvgpu_mem has been mapped.
84 *
85 * Returns 0 on success, or a relevant error otherwise.
86 */
87int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest,
88 u64 src_phys, int nr_pages);
69#endif 89#endif