From 29cc82844e03b6f9f0e6801169b6fa0e72d56628 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 25 Apr 2017 15:56:12 -0700 Subject: gpu: nvgpu: Split vm_area management into vm code The vm_reserve_va_node struct is essentially a special VM area that can be used for sparse mappings and fixed mappings. The name of this struct is somewhat confusing (as node is typically used for list items). Though this struct is a part of a list it doesn't really make sense to call this a list item since it's much more. Based on that the struct has been renamed to nvgpu_vm_area to capture the actual use of the struct more accurately. This also moves all of the management code of vm areas to a new file devoted solely to vm_area management. Also add a brief overview of the VM architecture. This should help other people follow along the hierachy of ownership and lifetimes in the rather complex MM code. JIRA NVGPU-12 JIRA NVGPU-30 Change-Id: If85e1cf868031d0dc265e7bed50b58a2aed2602e Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1477744 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/as.h | 10 ++--- drivers/gpu/nvgpu/include/nvgpu/vm.h | 41 +++++++++++++++++--- drivers/gpu/nvgpu/include/nvgpu/vm_area.h | 63 +++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/vm_area.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/as.h b/drivers/gpu/nvgpu/include/nvgpu/as.h index 0e784396..e3233f87 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/as.h +++ b/drivers/gpu/nvgpu/include/nvgpu/as.h @@ -17,14 +17,14 @@ struct vm_gk20a; +struct gk20a_as { + int last_share_id; /* dummy allocator for now */ +}; + struct gk20a_as_share { struct gk20a_as *as; - int id; struct vm_gk20a *vm; -}; - -struct gk20a_as { - int last_share_id; /* dummy allocator for now */ + int id; }; int gk20a_as_release_share(struct gk20a_as_share *as_share); diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h index e1ceffd4..69c08c77 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h @@ -26,11 +26,10 @@ #include struct vm_gk20a; -struct vm_reserved_va_node; +struct nvgpu_vm_area; struct buffer_attrs; struct gk20a_comptag_allocator; - /** * 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 @@ -39,6 +38,38 @@ struct gk20a_comptag_allocator; * 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). + * + * VM Architecture: + * ---------------- + * + * The VM managment in nvgpu is split up as follows: a vm_gk20a struct which + * defines an address space. Each address space is a set of page tables and a + * GPU Virtual Address (GVA) allocator. Any number of channels may bind to a VM. + * + * +----+ +----+ +----+ +-----+ +-----+ + * | C1 | | C2 | ... | Cn | | VM1 | ... | VMn | + * +-+--+ +-+--+ +-+--+ +--+--+ +--+--+ + * | | | | | + * | | +----->-----+ | + * | +---------------->-----+ | + * +------------------------>-----------------+ + * + * Each VM also manages a set of mapped buffers (struct nvgpu_mapped_buf) + * which corresponds to _user space_ buffers which have been mapped into this VM. + * Kernel space mappings (created by nvgpu_gmmu_map()) are not tracked by VMs. + * This may be an architectural bug, but for now it seems to be OK. VMs can be + * closed in various ways - refs counts hitting zero, direct calls to the remove + * routine, etc. Note: this is going to change. VM cleanup is going to be + * homogonized around ref-counts. When a VM is closed all mapped buffers in the + * VM are unmapped from the GMMU. This means that those mappings will no longer + * be valid and any subsequent access by the GPU will fault. That means one must + * ensure the VM is not in use before closing it. + * + * VMs may also contain VM areas (struct nvgpu_vm_area) which are created for + * the purpose of sparse and/or fixed mappings. If userspace wishes to create a + * fixed mapping it must first create a VM area - either with a fixed address or + * not. VM areas are reserved - other mapping operations will not use the space. + * Userspace may then create fixed mappings within that VM area. */ /* map/unmap batch state */ @@ -49,9 +80,10 @@ struct vm_gk20a_mapping_batch { struct nvgpu_mapped_buf { struct vm_gk20a *vm; + struct nvgpu_vm_area *vm_area; + struct nvgpu_rbtree_node node; struct nvgpu_list_node buffer_list; - struct vm_reserved_va_node *va_node; u64 addr; u64 size; struct dma_buf *dmabuf; @@ -102,7 +134,6 @@ struct vm_gk20a { bool big_pages; /* enable large page support */ bool enable_ctag; - bool mapped; u32 big_page_size; @@ -129,7 +160,7 @@ struct vm_gk20a { struct nvgpu_rbtree_node *mapped_buffers; - struct nvgpu_list_node reserved_va_list; + struct nvgpu_list_node vm_area_list; #ifdef CONFIG_TEGRA_GR_VIRTUALIZATION u64 handle; diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm_area.h b/drivers/gpu/nvgpu/include/nvgpu/vm_area.h new file mode 100644 index 00000000..ffe4b99b --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/vm_area.h @@ -0,0 +1,63 @@ +/* + * 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_AREA_H__ +#define __NVGPU_VM_AREA_H__ + +#include +#include + +struct vm_gk20a; +struct gk20a_as_share; +struct nvgpu_as_alloc_space_args; +struct nvgpu_as_free_space_args; + +struct nvgpu_vm_area { + /* + * Entry into the list of VM areas owned by a VM. + */ + struct nvgpu_list_node vm_area_list; + + /* + * List of buffers mapped into this vm_area. + */ + struct nvgpu_list_node buffer_list_head; + + u32 flags; + u32 pgsz_idx; + u64 addr; + u64 size; + bool sparse; +}; + +static inline struct nvgpu_vm_area * +nvgpu_vm_area_from_vm_area_list(struct nvgpu_list_node *node) +{ + return (struct nvgpu_vm_area *) + ((uintptr_t)node - offsetof(struct nvgpu_vm_area, + vm_area_list)); +}; + +int nvgpu_vm_area_alloc(struct vm_gk20a *vm, u32 pages, u32 page_size, + u64 *addr, u32 flags); +int nvgpu_vm_area_free(struct vm_gk20a *vm, u64 addr); + +struct nvgpu_vm_area *nvgpu_vm_area_find(struct vm_gk20a *vm, u64 addr); +int nvgpu_vm_area_validate_buffer(struct vm_gk20a *vm, + u64 map_offset, u64 map_size, int pgsz_idx, + struct nvgpu_vm_area **pvm_area); + +#endif -- cgit v1.2.2