From c616fba1eb357684e3796603a226f4df7d88be73 Mon Sep 17 00:00:00 2001 From: ddutta Date: Mon, 17 Sep 2018 13:09:18 +0530 Subject: gpu: nvgpu: remove circular dependency between hal.c and gk20a/ gk20a/hal.c depends on HAL init functions in all chips. But all chips also depend on gk20a. That creates a circular dependency. In order to solve the above, move gpu_init_hal and gk20a_detect_chip to common/init/hal_init.c. These methods are declared in include/nvgpu/hal_init.h. Also, the above methods are renamed to nvgpu_init_hal and nvgpu_detect_chip respectively. Jira NVGPU-613 Change-Id: Ib0df90287d4491571e4751475739b75fabd1041b Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/1827576 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/Makefile | 2 +- drivers/gpu/nvgpu/Makefile.sources | 2 +- drivers/gpu/nvgpu/common/init/hal_init.c | 122 +++++++++++++++++++++++++++++ drivers/gpu/nvgpu/gk20a/gk20a.c | 28 ------- drivers/gpu/nvgpu/gk20a/hal.c | 84 -------------------- drivers/gpu/nvgpu/gk20a/hal.h | 32 -------- drivers/gpu/nvgpu/include/nvgpu/gk20a.h | 1 - drivers/gpu/nvgpu/include/nvgpu/hal_init.h | 33 ++++++++ drivers/gpu/nvgpu/os/linux/module.c | 3 +- 9 files changed, 159 insertions(+), 148 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/init/hal_init.c delete mode 100644 drivers/gpu/nvgpu/gk20a/hal.c delete mode 100644 drivers/gpu/nvgpu/gk20a/hal.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/hal_init.h (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 1b7dbd26..bf02affe 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -203,6 +203,7 @@ nvgpu-y += \ common/vbios/bios.o \ common/falcon/falcon.o \ common/falcon/falcon_queue.o \ + common/init/hal_init.o \ common/pmu/pmu.o \ common/pmu/pmu_ipc.o \ common/pmu/pmu_fw.o \ @@ -237,7 +238,6 @@ nvgpu-y += \ gk20a/fence_gk20a.o \ gk20a/gr_ctx_gk20a_sim.o \ gk20a/gr_ctx_gk20a.o \ - gk20a/hal.o \ gk20a/tsg_gk20a.o \ gk20a/fecs_trace_gk20a.o \ gm20b/hal_gm20b.o \ diff --git a/drivers/gpu/nvgpu/Makefile.sources b/drivers/gpu/nvgpu/Makefile.sources index 5c15ebd0..4e67434d 100644 --- a/drivers/gpu/nvgpu/Makefile.sources +++ b/drivers/gpu/nvgpu/Makefile.sources @@ -68,6 +68,7 @@ srcs := os/posix/nvgpu.c \ common/fb/fb_gp106.c \ common/fb/fb_gv100.c \ common/fb/fb_gv11b.c \ + common/init/hal_init.c \ common/xve/xve_gp106.c \ common/therm/therm.c \ common/therm/therm_gm20b.c \ @@ -157,7 +158,6 @@ srcs := os/posix/nvgpu.c \ gk20a/fence_gk20a.c \ gk20a/gr_ctx_gk20a_sim.c \ gk20a/gr_ctx_gk20a.c \ - gk20a/hal.c \ gk20a/tsg_gk20a.c \ gm20b/hal_gm20b.c \ gm20b/gr_gm20b.c \ diff --git a/drivers/gpu/nvgpu/common/init/hal_init.c b/drivers/gpu/nvgpu/common/init/hal_init.c new file mode 100644 index 00000000..598790b6 --- /dev/null +++ b/drivers/gpu/nvgpu/common/init/hal_init.c @@ -0,0 +1,122 @@ +/* + * NVIDIA GPU HAL interface. + * + * Copyright (c) 2014-2018, 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "gm20b/hal_gm20b.h" +#include "gp10b/hal_gp10b.h" +#include "gp106/hal_gp106.h" +#include "gv100/hal_gv100.h" +#include "gv11b/hal_gv11b.h" +#if defined(CONFIG_TEGRA_GPU_NEXT) +#include "nvgpu_gpuid_next.h" +#endif + +int nvgpu_init_hal(struct gk20a *g) +{ + int err = 0; + u32 ver = g->params.gpu_arch + g->params.gpu_impl; + + switch (ver) { + case GK20A_GPUID_GM20B: + nvgpu_log_info(g, "gm20b detected"); + if (gm20b_init_hal(g) != 0) { + return -ENODEV; + } + break; + case GK20A_GPUID_GM20B_B: + nvgpu_log_info(g, "gm20b detected"); + if (gm20b_init_hal(g) != 0) { + return -ENODEV; + } + break; + case NVGPU_GPUID_GP10B: + if (gp10b_init_hal(g) != 0) { + return -ENODEV; + } + break; + case NVGPU_GPUID_GP104: + if (gp106_init_hal(g) != 0) { + return -ENODEV; + } + break; + case NVGPU_GPUID_GP106: + if (gp106_init_hal(g) != 0) { + return -ENODEV; + } + break; + case NVGPU_GPUID_GV11B: + if (gv11b_init_hal(g) != 0) { + return -ENODEV; + } + break; + case NVGPU_GPUID_GV100: + if (gv100_init_hal(g) != 0) { + return -ENODEV; + } + break; +#if defined(CONFIG_TEGRA_GPU_NEXT) + case NVGPU_GPUID_NEXT: + if (NVGPU_NEXT_INIT_HAL(g) != 0) { + return -ENODEV; + } + break; +#endif + default: + nvgpu_err(g, "no support for %x", ver); + err = -ENODEV; + break; + } + + return err; +} + + +int nvgpu_detect_chip(struct gk20a *g) +{ + struct nvgpu_gpu_params *p = &g->params; + + if (p->gpu_arch != 0U) { + return 0; + } + + nvgpu_mc_boot_0(g, &p->gpu_arch, &p->gpu_impl, &p->gpu_rev); + + if ((p->gpu_arch + p->gpu_impl) == (u32)NVGPU_GPUID_GV11B) { + /* overwrite gpu revison for A02 */ + if (!nvgpu_is_soc_t194_a01(g)) { + p->gpu_rev = 0xa2; + } + } + nvgpu_log_info(g, "arch: %x, impl: %x, rev: %x\n", + g->params.gpu_arch, + g->params.gpu_impl, + g->params.gpu_rev); + + return nvgpu_init_hal(g); +} diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 1caa1dcf..223c7727 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -45,7 +45,6 @@ #include "gk20a.h" #include "dbg_gpu_gk20a.h" -#include "hal.h" #include "pstate/pstate.h" void __nvgpu_check_gpu_state(struct gk20a *g) @@ -65,33 +64,6 @@ void __gk20a_warn_on_no_regs(void) WARN_ONCE(1, "Attempted access to GPU regs after unmapping!"); } -int gk20a_detect_chip(struct gk20a *g) -{ - struct nvgpu_gpu_params *p = &g->params; - - if (p->gpu_arch) { - return 0; - } - - nvgpu_mc_boot_0(g, &p->gpu_arch, &p->gpu_impl, &p->gpu_rev); - - if ((p->gpu_arch + p->gpu_impl) == NVGPU_GPUID_GV11B) { - - /* overwrite gpu revison for A02 */ - if (!nvgpu_is_soc_t194_a01(g)) { - p->gpu_rev = 0xa2; - } - - } - - nvgpu_log_info(g, "arch: %x, impl: %x, rev: %x\n", - g->params.gpu_arch, - g->params.gpu_impl, - g->params.gpu_rev); - - return gpu_init_hal(g); -} - static void gk20a_mask_interrupts(struct gk20a *g) { if (g->ops.mc.intr_mask != NULL) { diff --git a/drivers/gpu/nvgpu/gk20a/hal.c b/drivers/gpu/nvgpu/gk20a/hal.c deleted file mode 100644 index f2f55d43..00000000 --- a/drivers/gpu/nvgpu/gk20a/hal.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * NVIDIA GPU HAL interface. - * - * Copyright (c) 2014-2018, 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "gk20a.h" -#include "hal.h" -#include "gm20b/hal_gm20b.h" -#include "gp10b/hal_gp10b.h" -#include "gp106/hal_gp106.h" -#include "gv100/hal_gv100.h" -#include "gv11b/hal_gv11b.h" -#if defined(CONFIG_TEGRA_GPU_NEXT) -#include "nvgpu_gpuid_next.h" -#endif - -#include - -int gpu_init_hal(struct gk20a *g) -{ - u32 ver = g->params.gpu_arch + g->params.gpu_impl; - switch (ver) { - case GK20A_GPUID_GM20B: - case GK20A_GPUID_GM20B_B: - nvgpu_log_info(g, "gm20b detected"); - if (gm20b_init_hal(g)) { - return -ENODEV; - } - break; - case NVGPU_GPUID_GP10B: - if (gp10b_init_hal(g)) { - return -ENODEV; - } - break; - case NVGPU_GPUID_GP104: - case NVGPU_GPUID_GP106: - if (gp106_init_hal(g)) { - return -ENODEV; - } - break; - case NVGPU_GPUID_GV11B: - if (gv11b_init_hal(g)) { - return -ENODEV; - } - break; - case NVGPU_GPUID_GV100: - if (gv100_init_hal(g)) { - return -ENODEV; - } - break; -#if defined(CONFIG_TEGRA_GPU_NEXT) - case NVGPU_GPUID_NEXT: - if (NVGPU_NEXT_INIT_HAL(g)) { - return -ENODEV; - } - break; -#endif - - default: - nvgpu_err(g, "no support for %x", ver); - return -ENODEV; - } - - return 0; -} diff --git a/drivers/gpu/nvgpu/gk20a/hal.h b/drivers/gpu/nvgpu/gk20a/hal.h deleted file mode 100644 index 0a6e7094..00000000 --- a/drivers/gpu/nvgpu/gk20a/hal.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * NVIDIA GPU Hardware Abstraction Layer functions definitions. - * - * Copyright (c) 2014-2018, 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"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef NVGPU_GK20A_HAL_H -#define NVGPU_GK20A_HAL_H - -struct gk20a; - -int gpu_init_hal(struct gk20a *g); - -#endif /* NVGPU_GK20A_HAL_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h index a653109a..244b6ed2 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h @@ -1761,5 +1761,4 @@ static inline bool gk20a_platform_has_syncpoints(struct gk20a *g) #endif } -int gk20a_detect_chip(struct gk20a *g); #endif /* GK20A_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/hal_init.h b/drivers/gpu/nvgpu/include/nvgpu/hal_init.h new file mode 100644 index 00000000..06e58e70 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/hal_init.h @@ -0,0 +1,33 @@ +/* + * NVIDIA GPU Hardware Abstraction Layer functions definitions. + * + * Copyright (c) 2014-2018, 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef NVGPU_HAL_INIT_H +#define NVGPU_HAL_INIT_H + +struct gk20a; + +int nvgpu_init_hal(struct gk20a *g); +int nvgpu_detect_chip(struct gk20a *g); + +#endif /* NVGPU_HAL_INIT_H */ diff --git a/drivers/gpu/nvgpu/os/linux/module.c b/drivers/gpu/nvgpu/os/linux/module.c index 9d84cc2f..dbc97f95 100644 --- a/drivers/gpu/nvgpu/os/linux/module.c +++ b/drivers/gpu/nvgpu/os/linux/module.c @@ -33,6 +33,7 @@ #include +#include #include #include #include @@ -266,7 +267,7 @@ int gk20a_pm_finalize_poweron(struct device *dev) INIT_WORK(&l->nonstall_fn_work, nvgpu_intr_nonstall_cb); } - err = gk20a_detect_chip(g); + err = nvgpu_detect_chip(g); if (err) goto done; -- cgit v1.2.2