From 017a9f57756f120cb492fc6c66d8588a2c1626d8 Mon Sep 17 00:00:00 2001 From: seshendra Gadagottu Date: Mon, 2 Oct 2017 11:03:05 -0700 Subject: 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 Reviewed-on: https://git-master.nvidia.com/r/1571073 Reviewed-by: svc-mobile-coverity Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | 19 +++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'drivers') 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, return 0; } +int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest, + u64 src_phys, int nr_pages) +{ + struct page **pages = + nvgpu_kmalloc(g, sizeof(struct page *) * nr_pages); + int i, ret = 0; + + if (!pages) + return -ENOMEM; + + for (i = 0; i < nr_pages; i++) + pages[i] = phys_to_page(src_phys + PAGE_SIZE * i); + + ret = __nvgpu_mem_create_from_pages(g, dest, pages, nr_pages); + nvgpu_kfree(g, pages); + + return ret; +} + static void *nvgpu_mem_linux_sgl_next(void *sgl) { 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, int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest, struct page **pages, int nr_pages); +/** + * __nvgpu_mem_create_from_phys - Create an nvgpu_mem from physical mem. + * + * @g - The GPU. + * @dest - nvgpu_mem to initialize. + * @src_phys - start address of physical mem + * @nr_pages - The number of pages in phys. + * + * Create a new nvgpu_mem struct from a physical memory aperure. The physical + * memory aperture needs to be contiguous for requested @nr_pages. This API + * only works for SYSMEM. + * + * The resulting nvgpu_mem should be released with the nvgpu_dma_free() or the + * nvgpu_dma_unmap_free() function depending on whether or not the resulting + * nvgpu_mem has been mapped. + * + * Returns 0 on success, or a relevant error otherwise. + */ +int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest, + u64 src_phys, int nr_pages); #endif -- cgit v1.2.2