From d37e8f7dcf190f31f9c0c12583db2bb0c0d313c0 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Mon, 17 Apr 2017 16:26:28 -0700 Subject: gpu: nvgpu: Split VM interface out This patch begins the major rework of the GPU's virtual memory manager (VMM). The VMM is the piece of code that handles the userspace interface to buffers and their mappings into the GMMU. The core data structure is the VM - for now still known as 'struct vm_gk20a'. Each one of these structs represents one addres space to which channels or TSGs may bind themselves to. The VMM splits the interface up into two broad categories. First there's the common, OS independent interfaces; and second there's the OS specific interfaces. OS independent -------------- This is the code that manages the lifetime of VMs, the buffers inside VMs (search, batch mapping) creation, destruction, etc. OS Specific ----------- This handles mapping of buffers represented as they are represented by the OS (dma_buf's for example on Linux). This patch is by no means complete. There's still Linux specific functions scattered in ostensibly OS independent code. This is the first step. A patch that rewrites everything in one go would simply be too big to effectively review. Instead the goal of this change is to simply separate out the basic OS specific and OS agnostic interfaces into their own header files. The next series of patches will start to pull the relevant implementations into OS specific C files and common C files. JIRA NVGPU-12 JIRA NVGPU-30 Change-Id: I242c7206047b6c769296226d855b7e44d5c4bfa8 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1464939 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/ioctl_as.c | 21 ++++++----- drivers/gpu/nvgpu/common/linux/vm_priv.h | 62 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/linux/vm_priv.h (limited to 'drivers/gpu/nvgpu/common/linux') diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_as.c b/drivers/gpu/nvgpu/common/linux/ioctl_as.c index 4bbcedda..7a24a14f 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_as.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.c @@ -28,6 +28,7 @@ #include "gk20a/gk20a.h" #include "gk20a/platform_gk20a.h" #include "ioctl_as.h" +#include "vm_priv.h" static int gk20a_as_ioctl_bind_channel( struct gk20a_as_share *as_share, @@ -72,7 +73,7 @@ static int gk20a_as_ioctl_map_buffer_ex( { gk20a_dbg_fn(""); - return gk20a_vm_map_buffer(as_share->vm, args->dmabuf_fd, + return nvgpu_vm_map_buffer(as_share->vm, args->dmabuf_fd, &args->offset, args->flags, args->kind, args->buffer_offset, @@ -85,7 +86,7 @@ static int gk20a_as_ioctl_map_buffer( struct nvgpu_as_map_buffer_args *args) { gk20a_dbg_fn(""); - return gk20a_vm_map_buffer(as_share->vm, args->dmabuf_fd, + return nvgpu_vm_map_buffer(as_share->vm, args->dmabuf_fd, &args->o_a.offset, args->flags, NV_KIND_DEFAULT, 0, 0, NULL); @@ -97,7 +98,7 @@ static int gk20a_as_ioctl_unmap_buffer( struct nvgpu_as_unmap_buffer_args *args) { gk20a_dbg_fn(""); - return gk20a_vm_unmap_buffer(as_share->vm, args->offset, NULL); + return nvgpu_vm_unmap_buffer(as_share->vm, args->offset, NULL); } static int gk20a_as_ioctl_map_buffer_batch( @@ -123,7 +124,7 @@ static int gk20a_as_ioctl_map_buffer_batch( args->num_maps > g->gpu_characteristics.map_buffer_batch_limit) return -EINVAL; - gk20a_vm_mapping_batch_start(&batch); + nvgpu_vm_mapping_batch_start(&batch); for (i = 0; i < args->num_unmaps; ++i) { struct nvgpu_as_unmap_buffer_args unmap_args; @@ -134,14 +135,14 @@ static int gk20a_as_ioctl_map_buffer_batch( break; } - err = gk20a_vm_unmap_buffer(as_share->vm, unmap_args.offset, + err = nvgpu_vm_unmap_buffer(as_share->vm, unmap_args.offset, &batch); if (err) break; } if (err) { - gk20a_vm_mapping_batch_finish(as_share->vm, &batch); + nvgpu_vm_mapping_batch_finish(as_share->vm, &batch); args->num_unmaps = i; args->num_maps = 0; @@ -158,7 +159,7 @@ static int gk20a_as_ioctl_map_buffer_batch( break; } - err = gk20a_vm_map_buffer( + err = nvgpu_vm_map_buffer( as_share->vm, map_args.dmabuf_fd, &map_args.offset, map_args.flags, map_args.kind, @@ -169,7 +170,7 @@ static int gk20a_as_ioctl_map_buffer_batch( break; } - gk20a_vm_mapping_batch_finish(as_share->vm, &batch); + nvgpu_vm_mapping_batch_finish(as_share->vm, &batch); if (err) args->num_maps = i; @@ -228,7 +229,7 @@ static int gk20a_as_ioctl_get_buffer_compbits_info( struct nvgpu_as_get_buffer_compbits_info_args *args) { gk20a_dbg_fn(""); - return gk20a_vm_get_compbits_info(as_share->vm, + return nvgpu_vm_get_compbits_info(as_share->vm, args->mapping_gva, &args->compbits_win_size, &args->compbits_win_ctagline, @@ -241,7 +242,7 @@ static int gk20a_as_ioctl_map_buffer_compbits( struct nvgpu_as_map_buffer_compbits_args *args) { gk20a_dbg_fn(""); - return gk20a_vm_map_compbits(as_share->vm, + return nvgpu_vm_map_compbits(as_share->vm, args->mapping_gva, &args->compbits_win_gva, &args->mapping_iova, diff --git a/drivers/gpu/nvgpu/common/linux/vm_priv.h b/drivers/gpu/nvgpu/common/linux/vm_priv.h new file mode 100644 index 00000000..c0fb0ffe --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/vm_priv.h @@ -0,0 +1,62 @@ +/* + * 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 __COMMON_LINUX_VM_PRIV_H__ +#define __COMMON_LINUX_VM_PRIV_H__ + +#include + +struct sg_table; +struct dma_buf; + +struct vm_gk20a; +struct vm_gk20a_mapping_batch; + +u64 nvgpu_vm_map(struct vm_gk20a *vm, + struct dma_buf *dmabuf, + u64 offset_align, + u32 flags /*NVGPU_AS_MAP_BUFFER_FLAGS_*/, + int kind, + struct sg_table **sgt, + bool user_mapped, + int rw_flag, + u64 buffer_offset, + u64 mapping_size, + struct vm_gk20a_mapping_batch *mapping_batch); + +int nvgpu_vm_map_compbits(struct vm_gk20a *vm, + u64 mapping_gva, + u64 *compbits_win_gva, + u64 *mapping_iova, + u32 flags); + +/* Note: batch may be NULL if map op is not part of a batch */ +int nvgpu_vm_map_buffer(struct vm_gk20a *vm, + int dmabuf_fd, + u64 *offset_align, + u32 flags, /* NVGPU_AS_MAP_BUFFER_FLAGS_ */ + int kind, + u64 buffer_offset, + u64 mapping_size, + struct vm_gk20a_mapping_batch *batch); + +void nvgpu_vm_unmap(struct vm_gk20a *vm, u64 offset); + +/* find buffer corresponding to va */ +int nvgpu_vm_find_buffer(struct vm_gk20a *vm, u64 gpu_va, + struct dma_buf **dmabuf, + u64 *offset); +#endif -- cgit v1.2.2