diff options
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | 19 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h | 20 |
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 | ||
475 | int __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 | |||
475 | static void *nvgpu_mem_linux_sgl_next(void *sgl) | 494 | static 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, | |||
66 | int __nvgpu_mem_create_from_pages(struct gk20a *g, struct nvgpu_mem *dest, | 66 | int __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 | */ | ||
87 | int __nvgpu_mem_create_from_phys(struct gk20a *g, struct nvgpu_mem *dest, | ||
88 | u64 src_phys, int nr_pages); | ||
69 | #endif | 89 | #endif |