From 59e4089278bd052b440293356605ce524e4944db Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Thu, 17 Aug 2017 16:16:49 -0700 Subject: gpu: nvgpu: Separate vidmem alloc from Linux code Split the core vidmem allocation from the Linux component of vidmem allocation. The core vidmem allocation allocates the nvgpu_mem struct that defines the vidmem buffer in the core MM code. The Linux code now allocates some Linux specific stuff (dma_buf, etc) and also allocates the core vidmem buf. JIRA NVGPU-30 JIRA NVGPU-138 Change-Id: I88e87e0abd5ec714610eacc6eac17e148bcee3ce Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1540708 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h | 60 ++++++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/vidmem.h | 70 +++++++++++++++----------- 2 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h new file mode 100644 index 00000000..76bbb05b --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vidmem.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NVGPU_LINUX_VIDMEM_H__ +#define __NVGPU_LINUX_VIDMEM_H__ + +#include + +struct dma_buf; + +struct gk20a; + +#ifdef CONFIG_GK20A_VIDMEM +struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf); +int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes); + +int nvgpu_vidmem_buf_access_memory(struct gk20a *g, struct dma_buf *dmabuf, + void *buffer, u64 offset, u64 size, u32 cmd); + +#else /* !CONFIG_GK20A_VIDMEM */ +static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf) +{ + return NULL; +} + +static inline int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes) +{ + return -ENOSYS; +} + +static inline int nvgpu_vidmem_buf_access_memory(struct gk20a *g, + struct dma_buf *dmabuf, + void *buffer, u64 offset, + u64 size, u32 cmd) +{ + return -ENOSYS; +} + +#endif + +struct nvgpu_vidmem_linux { + struct dma_buf *dmabuf; + void *dmabuf_priv; + void (*dmabuf_priv_delete)(void *); +}; + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/vidmem.h b/drivers/gpu/nvgpu/include/nvgpu/vidmem.h index 1b250f90..b89c710d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vidmem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vidmem.h @@ -25,9 +25,9 @@ #include #include +#include struct scatterlist; -struct dma_buf; struct work_struct; struct gk20a; @@ -35,37 +35,58 @@ struct mm_gk20a; struct nvgpu_mem; struct nvgpu_vidmem_buf { - struct gk20a *g; - struct nvgpu_mem *mem; - struct dma_buf *dmabuf; - void *dmabuf_priv; - void (*dmabuf_priv_delete)(void *); + /* + * Must be a pointer since control of this mem is passed over to the + * vidmem background clearing thread when the vidmem buf is freed. + */ + struct nvgpu_mem *mem; + + struct gk20a *g; + + /* + * Filled in by each OS - this holds the necessary data to export this + * buffer to userspace. This will eventually be replaced by a struct + * which shall be defined in the OS specific vidmem.h header file. + */ + void *priv; }; #if defined(CONFIG_GK20A_VIDMEM) +/** + * nvgpu_vidmem_user_alloc - Allocates a vidmem buffer for userspace + * + * @g - The GPU. + * @bytes - Size of the buffer in bytes. + * + * Allocate a generic (OS agnostic) vidmem buffer. This does not allocate the OS + * specific interfacing for userspace sharing. Instead is is expected that the + * OS specific code will allocate that OS specific data and add it to this + * buffer. + * + * The buffer allocated here is intended to use used by userspace, hence the + * extra struct over nvgpu_mem. If a vidmem buffer is needed by the kernel + * driver only then a simple nvgpu_dma_alloc_vid() or the like is sufficient. + * + * Returns a pointer to a vidmem buffer on success, 0 otherwise. + */ +struct nvgpu_vidmem_buf *nvgpu_vidmem_user_alloc(struct gk20a *g, size_t bytes); + +void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf); + struct nvgpu_page_alloc *nvgpu_vidmem_get_page_alloc(struct scatterlist *sgl); void nvgpu_vidmem_set_page_alloc(struct scatterlist *sgl, u64 addr); bool nvgpu_addr_is_vidmem_page_alloc(u64 addr); -int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes); int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space); struct nvgpu_mem *nvgpu_vidmem_get_pending_alloc(struct mm_gk20a *mm); void nvgpu_vidmem_destroy(struct gk20a *g); int nvgpu_vidmem_init(struct mm_gk20a *mm); -int nvgpu_vidmem_clear_all(struct gk20a *g); void nvgpu_vidmem_clear_mem_worker(struct work_struct *work); int nvgpu_vidmem_clear(struct gk20a *g, struct nvgpu_mem *mem); -/* - * Will need to be moved later on once we have the Linux vidmem.h file. - */ -struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf); -int nvgpu_vidmem_buf_access_memory(struct gk20a *g, struct dma_buf *dmabuf, - void *buffer, u64 offset, u64 size, u32 cmd); - #else /* !defined(CONFIG_GK20A_VIDMEM) */ /* @@ -91,6 +112,12 @@ static inline int nvgpu_vidmem_buf_alloc(struct gk20a *g, size_t bytes) { return -ENOSYS; } + +static inline void nvgpu_vidmem_buf_free(struct gk20a *g, + struct nvgpu_vidmem_buf *buf) +{ +} + static inline int nvgpu_vidmem_get_space(struct gk20a *g, u64 *space) { return -ENOSYS; @@ -121,19 +148,6 @@ static inline int nvgpu_vidmem_clear(struct gk20a *g, return -ENOSYS; } -static inline struct gk20a *nvgpu_vidmem_buf_owner(struct dma_buf *dmabuf) -{ - return NULL; -} - -static inline int nvgpu_vidmem_buf_access_memory(struct gk20a *g, - struct dma_buf *dmabuf, - void *buffer, u64 offset, - u64 size, u32 cmd) -{ - return -ENOSYS; -} - #endif /* !defined(CONFIG_GK20A_VIDMEM) */ #endif /* __NVGPU_VIDMEM_H__ */ -- cgit v1.2.2