From c2b63150cd947557b8d17637258b988459b8e0ec Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 10 May 2017 00:41:18 +0100 Subject: gpu: nvgpu: Unify vm_init for vGPU and regular GPU Unify the initialization routines for the vGPU and regular GPU paths. This helps avoid any further code divergence. This also assumes that the code running on the regular GPU essentially works for the vGPU. The only addition is that the regular GPU path calls an API in the vGPU code that sends the necessary RM server message. JIRA NVGPU-12 JIRA NVGPU-30 Change-Id: I37af1993fd8b50f666ae27524d382cce49cf28f7 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1480226 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/as.c | 63 +++++++++++++++++++++++++++++++++++++++- drivers/gpu/nvgpu/common/mm/vm.c | 27 ++++++++++++++--- 2 files changed, 85 insertions(+), 5 deletions(-) (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/as.c b/drivers/gpu/nvgpu/common/as.c index 3182642a..481fb807 100644 --- a/drivers/gpu/nvgpu/common/as.c +++ b/drivers/gpu/nvgpu/common/as.c @@ -16,8 +16,10 @@ #include #include +#include #include "gk20a/gk20a.h" +#include "gk20a/platform_gk20a.h" /* dumb allocator... */ static int generate_as_share_id(struct gk20a_as *as) @@ -32,6 +34,51 @@ static void release_as_share_id(struct gk20a_as *as, int id) return; } +/* address space interfaces for the gk20a module */ +static int gk20a_vm_alloc_share(struct gk20a_as_share *as_share, + u32 big_page_size, u32 flags) +{ + struct gk20a_as *as = as_share->as; + struct gk20a *g = gk20a_from_as(as); + struct mm_gk20a *mm = &g->mm; + struct vm_gk20a *vm; + char name[32]; + int err; + const bool userspace_managed = + (flags & NVGPU_GPU_IOCTL_ALLOC_AS_FLAGS_USERSPACE_MANAGED) != 0; + + gk20a_dbg_fn(""); + + if (big_page_size == 0) { + big_page_size = + gk20a_get_platform(g->dev)->default_big_page_size; + } else { + if (!is_power_of_2(big_page_size)) + return -EINVAL; + + if (!(big_page_size & g->gpu_characteristics.available_big_page_sizes)) + return -EINVAL; + } + + vm = nvgpu_kzalloc(g, sizeof(*vm)); + if (!vm) + return -ENOMEM; + + as_share->vm = vm; + vm->as_share = as_share; + vm->enable_ctag = true; + + snprintf(name, sizeof(name), "as_%d", as_share->id); + + err = nvgpu_init_vm(mm, vm, big_page_size, + big_page_size << 10, + mm->channel.kernel_size, + mm->channel.user_size + mm->channel.kernel_size, + !mm->disable_bigpage, userspace_managed, name); + + return err; +} + int gk20a_as_alloc_share(struct gk20a *g, u32 big_page_size, u32 flags, struct gk20a_as_share **out) @@ -56,7 +103,7 @@ int gk20a_as_alloc_share(struct gk20a *g, err = gk20a_busy(g); if (err) goto failed; - err = g->ops.mm.vm_alloc_share(as_share, big_page_size, flags); + err = gk20a_vm_alloc_share(as_share, big_page_size, flags); gk20a_idle(g); if (err) @@ -70,6 +117,20 @@ failed: return err; } +int gk20a_vm_release_share(struct gk20a_as_share *as_share) +{ + struct vm_gk20a *vm = as_share->vm; + + gk20a_dbg_fn(""); + + vm->as_share = NULL; + as_share->vm = NULL; + + nvgpu_vm_put(vm); + + return 0; +} + /* * channels and the device nodes call this to release. * once the ref_cnt hits zero the share is deleted. diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index b957e755..171a67ca 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -24,6 +24,8 @@ #include #include +#include + #include "gk20a/gk20a.h" #include "gk20a/mm_gk20a.h" @@ -209,10 +211,11 @@ static int nvgpu_init_sema_pool(struct vm_gk20a *vm) * @vm - The VM to init. * @big_page_size - Size of big pages associated with this VM. * @low_hole - The size of the low hole (unaddressable memory at the bottom of - * the address space. + * the address space). * @kernel_reserved - Space reserved for kernel only allocations. * @aperture_size - Total size of the aperture. - * @big_pages - Ignored. Will be set based on other passed params. + * @big_pages - If true then big pages are possible in the VM. Note this does + * not guarantee that big pages will be possible. * @name - Name of the address space. * * This function initializes an address space according to the following map: @@ -284,10 +287,21 @@ int nvgpu_init_vm(struct mm_gk20a *mm, vm->userspace_managed = userspace_managed; vm->mmu_levels = g->ops.mm.get_mmu_levels(g, vm->big_page_size); +#ifdef CONFIG_TEGRA_GR_VIRTUALIZATION + if (g->is_virtual && userspace_managed) { + nvgpu_err(g, "vGPU: no userspace managed addr space support"); + return -ENOSYS; + } + if (g->is_virtual && vgpu_vm_init(g, vm)) { + nvgpu_err(g, "Failed to init vGPU VM!"); + return -ENOMEM; + } +#endif + /* Initialize the page table data structures. */ err = nvgpu_vm_init_page_tables(vm); if (err) - return err; + goto clean_up_vgpu_vm; /* Setup vma limits. */ if (kernel_reserved + low_hole < aperture_size) { @@ -445,6 +459,11 @@ clean_up_page_tables: /* Cleans up nvgpu_vm_init_page_tables() */ nvgpu_vfree(g, vm->pdb.entries); free_gmmu_pages(vm, &vm->pdb); +clean_up_vgpu_vm: +#ifdef CONFIG_TEGRA_GR_VIRTUALIZATION + if (g->is_virtual) + vgpu_vm_remove(vm); +#endif return err; } @@ -503,7 +522,7 @@ void __nvgpu_vm_remove(struct vm_gk20a *vm) #ifdef CONFIG_TEGRA_GR_VIRTUALIZATION if (g->is_virtual) - nvgpu_vm_remove_vgpu(vm); + vgpu_vm_remove(vm); #endif nvgpu_mutex_release(&vm->update_gmmu_lock); -- cgit v1.2.2