From a7d358f773f0a2006b3d153327d9c20d23504513 Mon Sep 17 00:00:00 2001 From: Richard Zhao Date: Tue, 17 Jan 2023 13:22:50 -0800 Subject: [PATCH] gpu: nvgpu: vf: init gmmu related structure vf driver implements gmmu map/unmap on client side. - adds helper function to check whether nvgpu device is vf or legacy vgpu. - inits pd_cache struct for vf - inits platform->phys_addr for ipa2pa Jira GVSCI-15733 Change-Id: I46c84f0acdd167b9c4bdcec2f1c25f3acd6a0f71 Signed-off-by: Richard Zhao Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2863430 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: Prathap Kumar Valsan GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/mm/vm.c | 8 +++--- .../gpu/nvgpu/common/vgpu/init/init_vgpu.c | 10 +++++++- .../gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c | 4 +-- .../gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c | 4 +-- drivers/gpu/nvgpu/include/nvgpu/gk20a.h | 25 +++++++++++++++++++ drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c | 8 +++++- 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 6d1a76581..710e296aa 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2023, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -763,7 +763,7 @@ static int nvgpu_vm_init_attributes(struct mm_gk20a *mm, g->ops.mm.gmmu.get_mmu_levels(g, vm->big_page_size); #ifdef CONFIG_NVGPU_GR_VIRTUALIZATION - if (g->is_virtual && userspace_managed) { + if (nvgpu_is_legacy_vgpu(g) && userspace_managed) { nvgpu_err(g, "vGPU: no userspace managed addr space support"); return -ENOSYS; } @@ -807,7 +807,7 @@ int nvgpu_vm_do_init(struct mm_gk20a *mm, /* Initialize the page table data structures. */ (void) strncpy(vm->name, name, min(strlen(name), (size_t)(sizeof(vm->name)-1ULL))); - if (!g->is_virtual) { + if (!nvgpu_is_legacy_vgpu(g)) { err = nvgpu_gmmu_init_page_table(vm); if (err != 0) { goto clean_up_gpu_vm; @@ -985,7 +985,7 @@ static void nvgpu_vm_remove(struct vm_gk20a *vm) nvgpu_alloc_destroy(&vm->user_lp); } - if (!g->is_virtual) { + if (!nvgpu_is_legacy_vgpu(g)) { nvgpu_vm_free_entries(vm, &vm->pdb); } diff --git a/drivers/gpu/nvgpu/common/vgpu/init/init_vgpu.c b/drivers/gpu/nvgpu/common/vgpu/init/init_vgpu.c index 32fc3f58d..7ba846bc9 100644 --- a/drivers/gpu/nvgpu/common/vgpu/init/init_vgpu.c +++ b/drivers/gpu/nvgpu/common/vgpu/init/init_vgpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -226,6 +226,14 @@ int vgpu_finalize_poweron_common(struct gk20a *g) return err; } + if (g->ops.mm.pd_cache_init != NULL) { + err = g->ops.mm.pd_cache_init(g); + if (err != 0) { + nvgpu_err(g, "failed to init pd_cache"); + return err; + } + } + err = nvgpu_fifo_init_support(g); if (err != 0) { nvgpu_err(g, "failed to init gk20a fifo"); diff --git a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c index a490e95e0..1e520bbc3 100644 --- a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c +++ b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -812,7 +812,7 @@ static const struct gops_mm_gmmu vgpu_ga10b_ops_mm_gmmu = { static const struct gops_mm vgpu_ga10b_ops_mm = { .init_mm_support = nvgpu_init_mm_support, - .pd_cache_init = nvgpu_pd_cache_init, + .pd_cache_init = NULL, .mm_suspend = nvgpu_mm_suspend, .vm_bind_channel = vgpu_vm_bind_channel, .setup_hw = NULL, diff --git a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c index 4697b48aa..183d60bd7 100644 --- a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c +++ b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2023, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -780,7 +780,7 @@ static const struct gops_mm_gmmu vgpu_gv11b_ops_mm_gmmu = { static const struct gops_mm vgpu_gv11b_ops_mm = { .init_mm_support = nvgpu_init_mm_support, - .pd_cache_init = nvgpu_pd_cache_init, + .pd_cache_init = NULL, .mm_suspend = nvgpu_mm_suspend, .vm_bind_channel = vgpu_vm_bind_channel, .setup_hw = NULL, diff --git a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h index 1bf8c04c8..c34c37b94 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h @@ -944,6 +944,31 @@ struct gk20a { bool is_pci_igpu; }; +/** + * @brief Check whether nvgpu device is virtual function (VF) + * + * @param g [in] The GPU superstructure. + * @return true nvgpu device is VF + * @return false nvgpu device is not VF + */ +static inline bool nvgpu_is_vf(struct gk20a *g) +{ + return g->is_virtual && g->func_regs != 0U; +} + +/** + * @brief Check whether nvgpu device is legacy vgpu which does not rely on VF. + * + * @param g [in] The GPU superstructure. + * @return true nvgpu device is legacy vgpu device, for which gpu context is + * managed on gpu server + * @return false nvgpu device is not legacy vgpu device + */ +static inline bool nvgpu_is_legacy_vgpu(struct gk20a *g) +{ + return g->is_virtual && g->func_regs == 0U; +} + /** * @brief Check if watchdog and context switch timeouts are enabled. * diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c index 54fa438e1..083332b0f 100644 --- a/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c +++ b/drivers/gpu/nvgpu/os/linux/vgpu/vgpu_linux.c @@ -1,7 +1,7 @@ /* * Virtualized GPU for Linux * - * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2023, 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, @@ -95,6 +95,7 @@ static void vgpu_init_vars(struct gk20a *g, struct gk20a_platform *platform) nvgpu_mutex_init(&g->clk_arb_enable_lock); nvgpu_mutex_init(&g->cg_pg_lock); nvgpu_rwsem_init(&g->deterministic_busy); + nvgpu_rwsem_init(&(g->ipa_pa_cache.ipa_pa_rw_lock)); nvgpu_mutex_init(&priv->vgpu_clk_get_freq_lock); @@ -117,6 +118,11 @@ static void vgpu_init_vars(struct gk20a *g, struct gk20a_platform *platform) platform->unified_memory); nvgpu_set_enabled(g, NVGPU_MM_UNIFY_ADDRESS_SPACES, platform->unify_address_spaces); + + if (nvgpu_is_vf(g)) { + /* only VF needs IPA2PA */ + nvgpu_init_soc_vars(g); + } } static int vgpu_init_support(struct platform_device *pdev)