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 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/nvgpu/common/as.c') 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. -- cgit v1.2.2