From b0092ea95c6e1f695912cdb0b13767f3881cb22f Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Wed, 27 Sep 2017 15:05:50 -0700 Subject: gpu: nvgpu: gv11b: Abstract IO aperture accessors Implement T19x specific usermode aperture initialization functions. Move usermode_regs field to nvgpu_os_linux_t19x, because it is Linux specific. JIRA NVGPU-259 Change-Id: I9d6ce243a692ab48209d468288ed85f89fb26770 Signed-off-by: Terje Bergstrom Reviewed-on: https://git-master.nvidia.com/r/1569699 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/Makefile | 2 + drivers/gpu/nvgpu/common/linux/io_t19x.c | 29 ++++++++++ drivers/gpu/nvgpu/common/linux/module_t19x.c | 62 ++++++++++++++++++++++ drivers/gpu/nvgpu/fifo_t19x.h | 1 - drivers/gpu/nvgpu/gv11b/fifo_gv11b.c | 10 ---- drivers/gpu/nvgpu/include/nvgpu/io_t19x.h | 29 ++++++++++ drivers/gpu/nvgpu/include/nvgpu/linux/io_t19x.h | 26 +++++++++ .../gpu/nvgpu/include/nvgpu/linux/module_t19x.h | 27 ++++++++++ .../gpu/nvgpu/include/nvgpu/linux/os_linux_t19x.h | 26 +++++++++ .../nvgpu/vgpu/gv11b/platform_gv11b_vgpu_tegra.c | 7 +-- 10 files changed, 205 insertions(+), 14 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/linux/io_t19x.c create mode 100644 drivers/gpu/nvgpu/common/linux/module_t19x.c create mode 100644 drivers/gpu/nvgpu/include/nvgpu/io_t19x.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/linux/io_t19x.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/linux/module_t19x.h create mode 100644 drivers/gpu/nvgpu/include/nvgpu/linux/os_linux_t19x.h (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 1ca21fb5..cc304df6 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -3,6 +3,8 @@ nvgpu-t19x := ../../../../nvgpu-t19x/drivers/gpu/nvgpu nvgpu-y += \ $(nvgpu-t19x)/common/mm/gmmu_t19x.o \ $(nvgpu-t19x)/common/linux/ioctl_tsg_t19x.o \ + $(nvgpu-t19x)/common/linux/io_t19x.o \ + $(nvgpu-t19x)/common/linux/module_t19x.o \ $(nvgpu-t19x)/gv11b/gv11b.o \ $(nvgpu-t19x)/gv11b/mc_gv11b.o \ $(nvgpu-t19x)/gv11b/ltc_gv11b.o \ diff --git a/drivers/gpu/nvgpu/common/linux/io_t19x.c b/drivers/gpu/nvgpu/common/linux/io_t19x.c new file mode 100644 index 00000000..5c6b76ba --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/io_t19x.c @@ -0,0 +1,29 @@ +/* + * 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. + */ + +#include +#include + +#include "common/linux/os_linux.h" +#include "gk20a/gk20a.h" + +#include + +void gv11b_usermode_writel(struct gk20a *g, u32 r, u32 v) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + void __iomem *reg = l->t19x.usermode_regs + (r - usermode_cfg0_r()); + + writel_relaxed(v, reg); + gk20a_dbg(gpu_dbg_reg, "usermode r=0x%x v=0x%x", r, v); +} diff --git a/drivers/gpu/nvgpu/common/linux/module_t19x.c b/drivers/gpu/nvgpu/common/linux/module_t19x.c new file mode 100644 index 00000000..f0e3d438 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/module_t19x.c @@ -0,0 +1,62 @@ +/* + * 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 . + */ + +#include + +#include + +#include "common/linux/os_linux.h" + +/* + * Locks out the driver from accessing GPU registers. This prevents access to + * thse registers after the GPU has been clock or power gated. This should help + * find annoying bugs where register reads and writes are silently dropped + * after the GPU has been turned off. On older chips these reads and writes can + * also lock the entire CPU up. + */ +void t19x_lockout_registers(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + + l->t19x.usermode_regs = NULL; +} + +/* + * Undoes t19x_lockout_registers(). + */ +void t19x_restore_registers(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + + l->t19x.usermode_regs = l->t19x.usermode_regs_saved; +} + +void t19x_remove_support(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + + if (l->t19x.usermode_regs) { + l->t19x.usermode_regs = NULL; + } +} + +void t19x_init_support(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + + l->t19x.usermode_regs = l->regs + usermode_cfg0_r(); + l->t19x.usermode_regs_saved = l->t19x.usermode_regs; +} diff --git a/drivers/gpu/nvgpu/fifo_t19x.h b/drivers/gpu/nvgpu/fifo_t19x.h index 6d508304..7274d1fe 100644 --- a/drivers/gpu/nvgpu/fifo_t19x.h +++ b/drivers/gpu/nvgpu/fifo_t19x.h @@ -24,7 +24,6 @@ #define _FIFO_T19X_H_ struct fifo_t19x { - void __iomem *usermode_regs; u32 max_subctx_count; }; diff --git a/drivers/gpu/nvgpu/gv11b/fifo_gv11b.c b/drivers/gpu/nvgpu/gv11b/fifo_gv11b.c index b8798033..e9830c0e 100644 --- a/drivers/gpu/nvgpu/gv11b/fifo_gv11b.c +++ b/drivers/gpu/nvgpu/gv11b/fifo_gv11b.c @@ -61,15 +61,6 @@ static void gv11b_fifo_init_ramfc_eng_method_buffer(struct gk20a *g, struct channel_gk20a *ch, struct nvgpu_mem *mem); -static inline void gv11b_usermode_writel(struct gk20a *g, u32 r, u32 v) -{ - struct fifo_gk20a *f = &g->fifo; - void __iomem *reg = f->t19x.usermode_regs + (r - usermode_cfg0_r()); - - writel_relaxed(v, reg); - gk20a_dbg(gpu_dbg_reg, "usermode r=0x%x v=0x%x", r, v); -} - void gv11b_get_tsg_runlist_entry(struct tsg_gk20a *tsg, u32 *runlist) { @@ -1787,7 +1778,6 @@ int gv11b_init_fifo_setup_hw(struct gk20a *g) { struct fifo_gk20a *f = &g->fifo; - f->t19x.usermode_regs = g->regs + usermode_cfg0_r(); f->t19x.max_subctx_count = gr_pri_fe_chip_def_info_max_veid_count_init_v(); return 0; diff --git a/drivers/gpu/nvgpu/include/nvgpu/io_t19x.h b/drivers/gpu/nvgpu/include/nvgpu/io_t19x.h new file mode 100644 index 00000000..f8c7dbbd --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/io_t19x.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017, 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_IO_T19X_H__ +#define __NVGPU_IO_T19X_H__ + +#ifdef __KERNEL__ +#include "linux/io_t19x.h" +#endif + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/io_t19x.h b/drivers/gpu/nvgpu/include/nvgpu/linux/io_t19x.h new file mode 100644 index 00000000..f71a6ecf --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/io_t19x.h @@ -0,0 +1,26 @@ +/* + * 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_IO_T19X_LINUX_H__ +#define __NVGPU_IO_T19X_LINUX_H__ + +#include + +struct gk20a; + +void gv11b_usermode_writel(struct gk20a *g, u32 r, u32 v); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/module_t19x.h b/drivers/gpu/nvgpu/include/nvgpu/linux/module_t19x.h new file mode 100644 index 00000000..a105c6dc --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/module_t19x.h @@ -0,0 +1,27 @@ +/* + * 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_MODULE_T19X_H__ +#define __NVGPU_MODULE_T19X_H__ + +struct gk20a; + +void t19x_init_support(struct gk20a *g); +void t19x_remove_support(struct gk20a *g); +void t19x_lockout_registers(struct gk20a *g); +void t19x_restore_registers(struct gk20a *g); + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/os_linux_t19x.h b/drivers/gpu/nvgpu/include/nvgpu/linux/os_linux_t19x.h new file mode 100644 index 00000000..a306bfb8 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/os_linux_t19x.h @@ -0,0 +1,26 @@ +/* + * 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_OS_LINUX_T19X_H +#define NVGPU_OS_LINUX_T19X_H + +#include + +struct nvgpu_os_linux_t19x { + void __iomem *usermode_regs; + void __iomem *usermode_regs_saved; +}; + +#endif diff --git a/drivers/gpu/nvgpu/vgpu/gv11b/platform_gv11b_vgpu_tegra.c b/drivers/gpu/nvgpu/vgpu/gv11b/platform_gv11b_vgpu_tegra.c index 396359c3..6adbd46b 100644 --- a/drivers/gpu/nvgpu/vgpu/gv11b/platform_gv11b_vgpu_tegra.c +++ b/drivers/gpu/nvgpu/vgpu/gv11b/platform_gv11b_vgpu_tegra.c @@ -23,6 +23,7 @@ #include "gk20a/gk20a.h" #include "gk20a/platform_gk20a.h" #include "vgpu/clk_vgpu.h" +#include "common/linux/os_linux.h" #include #include @@ -33,7 +34,7 @@ static int gv11b_vgpu_probe(struct device *dev) struct gk20a_platform *platform = dev_get_drvdata(dev); struct resource *r; void __iomem *regs; - struct fifo_gk20a *f = &platform->g->fifo; + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(platform->g); int ret; r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usermode"); @@ -46,12 +47,12 @@ static int gv11b_vgpu_probe(struct device *dev) dev_err(dev, "failed to map usermode regs\n"); return PTR_ERR(regs); } - f->t19x.usermode_regs = regs; + l->t19x.usermode_regs = regs; #ifdef CONFIG_TEGRA_GK20A_NVHOST ret = nvgpu_get_nvhost_dev(platform->g); if (ret) { - f->t19x.usermode_regs = NULL; + l->t19x.usermode_regs = NULL; return ret; } #endif -- cgit v1.2.2