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 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'drivers/gpu/nvgpu/common/linux') 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); -- cgit v1.2.2