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/include/nvgpu/gmmu.h | 35 +++++++- drivers/gpu/nvgpu/include/nvgpu/vm.h | 144 +++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/vm.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/gmmu.h b/drivers/gpu/nvgpu/include/nvgpu/gmmu.h index 7fb0147e..6d8aa025 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gmmu.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gmmu.h @@ -18,6 +18,9 @@ #define __NVGPU_GMMU_H__ #include +#include + +struct scatterlist; /* * This is the GMMU API visible to blocks outside of the GMMU. Basically this @@ -28,7 +31,37 @@ struct vm_gk20a; struct nvgpu_mem; -enum nvgpu_aperture; +enum gmmu_pgsz_gk20a { + gmmu_page_size_small = 0, + gmmu_page_size_big = 1, + gmmu_page_size_kernel = 2, + gmmu_nr_page_sizes = 3, +}; + +struct gk20a_mm_entry { + /* backing for */ + struct nvgpu_mem mem; + u32 woffset; /* if >0, mem is a shadow copy, owned by another entry */ + int pgsz; + struct gk20a_mm_entry *entries; + int num_entries; +}; + +struct gk20a_mmu_level { + int hi_bit[2]; + int lo_bit[2]; + int (*update_entry)(struct vm_gk20a *vm, + struct gk20a_mm_entry *pte, + u32 i, u32 gmmu_pgsz_idx, + struct scatterlist **sgl, + u64 *offset, + u64 *iova, + u32 kind_v, u64 *ctag, + bool cacheable, bool unmapped_pte, + int rw_flag, bool sparse, bool priv, + enum nvgpu_aperture aperture); + size_t entry_size; +}; /** * nvgpu_gmmu_map - Map memory into the GMMU. diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h new file mode 100644 index 00000000..1fb772d5 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h @@ -0,0 +1,144 @@ +/* + * 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_VM_H__ +#define __NVGPU_VM_H__ + +#include +#include +#include +#include +#include +#include +#include + +struct vm_gk20a; +struct mapped_buffer_node; + +/** + * This header contains the OS agnostic APIs for dealing with VMs. Most of the + * VM implementation is system specific - it must translate from a platform's + * representation of DMA'able memory to our nvgpu_mem notion. + * + * However, some stuff is platform agnostic. VM ref-counting and the VM struct + * itself are platform agnostic. Also, the initialization and destruction of + * VMs is the same across all platforms (for now). + */ + +/* map/unmap batch state */ +struct vm_gk20a_mapping_batch { + bool gpu_l2_flushed; + bool need_tlb_invalidate; +}; + +struct vm_gk20a { + struct mm_gk20a *mm; + struct gk20a_as_share *as_share; /* as_share this represents */ + + u64 va_start; + u64 va_limit; + + int num_user_mapped_buffers; + + bool big_pages; /* enable large page support */ + bool enable_ctag; + bool mapped; + + u32 big_page_size; + + bool userspace_managed; + + const struct gk20a_mmu_level *mmu_levels; + + struct kref ref; + + struct nvgpu_mutex update_gmmu_lock; + + struct gk20a_mm_entry pdb; + + /* + * These structs define the address spaces. In some cases it's possible + * to merge address spaces (user and user_lp) and in other cases it's + * not. vma[] allows the code to be agnostic to this by always using + * address spaces through this pointer array. + */ + struct nvgpu_allocator *vma[gmmu_nr_page_sizes]; + struct nvgpu_allocator kernel; + struct nvgpu_allocator user; + struct nvgpu_allocator user_lp; + + struct nvgpu_rbtree_node *mapped_buffers; + + struct nvgpu_list_node reserved_va_list; + +#ifdef CONFIG_TEGRA_GR_VIRTUALIZATION + u64 handle; +#endif + u32 gmmu_page_sizes[gmmu_nr_page_sizes]; + + /* if non-NULL, kref_put will use this batch when + unmapping. Must hold vm->update_gmmu_lock. */ + struct vm_gk20a_mapping_batch *kref_put_batch; + + /* + * Each address space needs to have a semaphore pool. + */ + struct nvgpu_semaphore_pool *sema_pool; +}; + +void nvgpu_vm_get(struct vm_gk20a *vm); +void nvgpu_vm_put(struct vm_gk20a *vm); + +/* batching eliminates redundant cache flushes and invalidates */ +void nvgpu_vm_mapping_batch_start(struct vm_gk20a_mapping_batch *batch); +void nvgpu_vm_mapping_batch_finish( + struct vm_gk20a *vm, struct vm_gk20a_mapping_batch *batch); +/* called when holding vm->update_gmmu_lock */ +void nvgpu_vm_mapping_batch_finish_locked( + struct vm_gk20a *vm, struct vm_gk20a_mapping_batch *batch); + +/* get reference to all currently mapped buffers */ +int nvgpu_vm_get_buffers(struct vm_gk20a *vm, + struct mapped_buffer_node ***mapped_buffers, + int *num_buffers); + +/* put references on the given buffers */ +void nvgpu_vm_put_buffers(struct vm_gk20a *vm, + struct mapped_buffer_node **mapped_buffers, + int num_buffers); + +/* Note: batch may be NULL if unmap op is not part of a batch */ +int nvgpu_vm_unmap_buffer(struct vm_gk20a *vm, u64 offset, + struct vm_gk20a_mapping_batch *batch); + +void nvgpu_vm_unmap_locked(struct mapped_buffer_node *mapped_buffer, + struct vm_gk20a_mapping_batch *batch); + +void nvgpu_vm_remove_support_nofree(struct vm_gk20a *vm); +void nvgpu_vm_remove_support(struct vm_gk20a *vm); + +int nvgpu_init_vm(struct mm_gk20a *mm, + struct vm_gk20a *vm, + u32 big_page_size, + u64 low_hole, + u64 kernel_reserved, + u64 aperture_size, + bool big_pages, + bool userspace_managed, + char *name); +void nvgpu_deinit_vm(struct vm_gk20a *vm); + +#endif -- cgit v1.2.2