From 17c581d75514c32d1e8c1e416beb33b3ccce22a5 Mon Sep 17 00:00:00 2001 From: Sunny He Date: Tue, 15 Aug 2017 12:01:04 -0700 Subject: gpu: nvgpu: SGL passthrough implementation The basic nvgpu_mem_sgl implementation provides support for OS specific scatter-gather list implementations by simply copying them node by node. This is inefficient, taking extra time and memory. This patch implements an nvgpu_mem_sgt struct to act as a header which is inserted at the front of any scatter- gather list implementation. This labels every struct with a set of ops which can be used to interact with the attached scatter gather list. Since nvgpu common code only has to interact with these function pointers, any sgl implementation can be used. Initialization only requires the allocation of a single struct, removing the need to copy or iterate through the sgl being converted. Jira NVGPU-186 Change-Id: I2994f804a4a4cc141b702e987e9081d8560ba2e8 Signed-off-by: Sunny He Reviewed-on: https://git-master.nvidia.com/r/1541426 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h | 7 +- drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 80 ++++++++++++++++------- drivers/gpu/nvgpu/include/nvgpu/page_allocator.h | 4 +- 3 files changed, 64 insertions(+), 27 deletions(-) (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h index f96c2801..517d834c 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/nvgpu_mem.h @@ -20,6 +20,7 @@ struct page; struct sg_table; struct scatterlist; +struct nvgpu_sgt; struct gk20a; struct nvgpu_mem; @@ -32,9 +33,11 @@ struct nvgpu_mem_priv { }; u64 nvgpu_mem_get_addr_sgl(struct gk20a *g, struct scatterlist *sgl); -struct nvgpu_mem_sgl *nvgpu_mem_sgl_create(struct gk20a *g, +struct nvgpu_sgt *nvgpu_mem_linux_sgt_create(struct gk20a *g, + struct sg_table *sgt); +void nvgpu_mem_linux_sgt_free(struct gk20a *g, struct nvgpu_sgt *sgt); +struct nvgpu_sgt *nvgpu_linux_sgt_create(struct gk20a *g, struct sg_table *sgt); - /** * __nvgpu_mem_create_from_pages - Create an nvgpu_mem from physical pages. * diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index 7d19cf81..beffbfe8 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h @@ -46,12 +46,41 @@ enum nvgpu_aperture { APERTURE_VIDMEM }; +struct nvgpu_sgt_ops { + void *(*sgl_next)(void *sgl); + u64 (*sgl_phys)(void *sgl); + u64 (*sgl_dma)(void *sgl); + u64 (*sgl_length)(void *sgl); + u64 (*sgl_gpu_addr)(struct gk20a *g, void *sgl, + struct nvgpu_gmmu_attrs *attrs); + /* + * Note: this operates on the whole SGT not a specific SGL entry. + */ + void (*sgt_free)(struct gk20a *g, struct nvgpu_sgt *sgt); +}; + +/* + * Scatter gather table: this is a list of scatter list entries and the ops for + * interacting with those entries. + */ +struct nvgpu_sgt { + /* + * Ops for interacting with the underlying scatter gather list entries. + */ + const struct nvgpu_sgt_ops *ops; + + /* + * The first node in the scatter gather list. + */ + void *sgl; +}; + /* * This struct holds the necessary information for describing a struct * nvgpu_mem's scatter gather list. * - * These are created in a platform dependent way. As a result the function - * definition for allocating these lives in the file. + * Not all nvgpu_sgt's use this particular implementation. Nor is a given OS + * required to use this at all. */ struct nvgpu_mem_sgl { /* @@ -164,6 +193,32 @@ static inline bool nvgpu_mem_is_valid(struct nvgpu_mem *mem) } +/* + * Create a nvgpu_sgt of the default implementation + */ +struct nvgpu_sgt *nvgpu_sgt_create(struct gk20a *g); + +/** + * nvgpu_mem_sgt_create_from_mem - Create a scatter list from an nvgpu_mem. + * + * @g - The GPU. + * @mem - The source memory allocation to use. + * + * Create a scatter gather table from the passed @mem struct. This list lets the + * calling code iterate across each chunk of a DMA allocation for when that DMA + * allocation is not completely contiguous. + */ +struct nvgpu_sgt *nvgpu_sgt_create_from_mem(struct gk20a *g, + struct nvgpu_mem *mem); + +void *nvgpu_sgt_get_next(struct nvgpu_sgt *sgt, void *sgl); +u64 nvgpu_sgt_get_phys(struct nvgpu_sgt *sgt, void *sgl); +u64 nvgpu_sgt_get_dma(struct nvgpu_sgt *sgt, void *sgl); +u64 nvgpu_sgt_get_length(struct nvgpu_sgt *sgt, void *sgl); +u64 nvgpu_sgt_get_gpu_addr(struct nvgpu_sgt *sgt, struct gk20a *g, void *sgl, + struct nvgpu_gmmu_attrs *attrs); +void nvgpu_sgt_free(struct nvgpu_sgt *sgt, struct gk20a *g); + /** * nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one. * @@ -200,27 +255,6 @@ int nvgpu_mem_create_from_mem(struct gk20a *g, struct nvgpu_mem *dest, struct nvgpu_mem *src, int start_page, int nr_pages); -/** - * nvgpu_mem_sgl_create_from_mem - Create a scatter list from an nvgpu_mem. - * - * @g - The GPU. - * @mem - The source memory allocation to use. - * - * Create a scatter gather list from the passed @mem struct. This list lets the - * calling code iterate across each chunk of a DMA allocation for when that DMA - * allocation is not completely contiguous. - */ -struct nvgpu_mem_sgl *nvgpu_mem_sgl_create_from_mem(struct gk20a *g, - struct nvgpu_mem *mem); -void nvgpu_mem_sgl_free(struct gk20a *g, struct nvgpu_mem_sgl *sgl); - -struct nvgpu_mem_sgl *nvgpu_mem_sgl_next(struct nvgpu_mem_sgl *sgl); -u64 nvgpu_mem_sgl_phys(struct nvgpu_mem_sgl *sgl); -u64 nvgpu_mem_sgl_dma(struct nvgpu_mem_sgl *sgl); -u64 nvgpu_mem_sgl_length(struct nvgpu_mem_sgl *sgl); -u64 nvgpu_mem_sgl_gpu_addr(struct gk20a *g, struct nvgpu_mem_sgl *sgl, - struct nvgpu_gmmu_attrs *attrs); - /* * Buffer accessors - wrap between begin() and end() if there is no permanent * kernel mapping for this buffer. diff --git a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h index de83ca7f..b22c55d0 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h +++ b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h @@ -91,10 +91,10 @@ page_alloc_slab_page_from_list_entry(struct nvgpu_list_node *node) */ struct nvgpu_page_alloc { /* - * nvgpu_mem_sgl for describing the actual allocation. Convenient for + * nvgpu_sgt for describing the actual allocation. Convenient for * GMMU mapping. */ - struct nvgpu_mem_sgl *sgl; + struct nvgpu_sgt sgt; int nr_chunks; u64 length; -- cgit v1.2.2