diff options
Diffstat (limited to 'include/os/linux/module.c')
| -rw-r--r-- | include/os/linux/module.c | 1547 |
1 files changed, 0 insertions, 1547 deletions
diff --git a/include/os/linux/module.c b/include/os/linux/module.c deleted file mode 100644 index fdbab46..0000000 --- a/include/os/linux/module.c +++ /dev/null | |||
| @@ -1,1547 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * GK20A Graphics | ||
| 3 | * | ||
| 4 | * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms and conditions of the GNU General Public License, | ||
| 8 | * version 2, as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 13 | * more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <linux/module.h> | ||
| 20 | #include <linux/of.h> | ||
| 21 | #include <linux/of_device.h> | ||
| 22 | #include <linux/of_platform.h> | ||
| 23 | #include <linux/of_address.h> | ||
| 24 | #include <linux/interrupt.h> | ||
| 25 | #include <linux/pm_runtime.h> | ||
| 26 | #include <linux/reset.h> | ||
| 27 | #include <linux/reboot.h> | ||
| 28 | #include <linux/notifier.h> | ||
| 29 | #include <linux/platform/tegra/common.h> | ||
| 30 | #include <linux/pci.h> | ||
| 31 | |||
| 32 | #include <uapi/linux/nvgpu.h> | ||
| 33 | #include <dt-bindings/soc/gm20b-fuse.h> | ||
| 34 | #include <dt-bindings/soc/gp10b-fuse.h> | ||
| 35 | #include <dt-bindings/soc/gv11b-fuse.h> | ||
| 36 | |||
| 37 | #include <soc/tegra/fuse.h> | ||
| 38 | |||
| 39 | #include <nvgpu/hal_init.h> | ||
| 40 | #include <nvgpu/dma.h> | ||
| 41 | #include <nvgpu/kmem.h> | ||
| 42 | #include <nvgpu/nvgpu_common.h> | ||
| 43 | #include <nvgpu/soc.h> | ||
| 44 | #include <nvgpu/enabled.h> | ||
| 45 | #include <nvgpu/debug.h> | ||
| 46 | #include <nvgpu/ctxsw_trace.h> | ||
| 47 | #include <nvgpu/vidmem.h> | ||
| 48 | #include <nvgpu/sim.h> | ||
| 49 | #include <nvgpu/clk_arb.h> | ||
| 50 | #include <nvgpu/timers.h> | ||
| 51 | #include <nvgpu/channel.h> | ||
| 52 | #include <nvgpu/nvgpu_err.h> | ||
| 53 | |||
| 54 | #include "platform_gk20a.h" | ||
| 55 | #include "sysfs.h" | ||
| 56 | #include "vgpu/vgpu_linux.h" | ||
| 57 | #include "scale.h" | ||
| 58 | #include "pci.h" | ||
| 59 | #include "module.h" | ||
| 60 | #include "module_usermode.h" | ||
| 61 | #include "intr.h" | ||
| 62 | #include "ioctl.h" | ||
| 63 | #include "ioctl_ctrl.h" | ||
| 64 | |||
| 65 | #include "os_linux.h" | ||
| 66 | #include "os_ops.h" | ||
| 67 | #include "ctxsw_trace.h" | ||
| 68 | #include "driver_common.h" | ||
| 69 | #include "channel.h" | ||
| 70 | #include "debug_pmgr.h" | ||
| 71 | |||
| 72 | #ifdef CONFIG_NVGPU_SUPPORT_CDE | ||
| 73 | #include "cde.h" | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #define CLASS_NAME "nvidia-gpu" | ||
| 77 | /* TODO: Change to e.g. "nvidia-gpu%s" once we have symlinks in place. */ | ||
| 78 | |||
| 79 | #define GK20A_WAIT_FOR_IDLE_MS 2000 | ||
| 80 | |||
| 81 | #define CREATE_TRACE_POINTS | ||
| 82 | #include <trace/events/gk20a.h> | ||
| 83 | |||
| 84 | static int nvgpu_kernel_shutdown_notification(struct notifier_block *nb, | ||
| 85 | unsigned long event, void *unused) | ||
| 86 | { | ||
| 87 | struct gk20a *g = container_of(nb, struct gk20a, nvgpu_reboot_nb); | ||
| 88 | |||
| 89 | __nvgpu_set_enabled(g, NVGPU_KERNEL_IS_DYING, true); | ||
| 90 | return NOTIFY_DONE; | ||
| 91 | } | ||
| 92 | |||
| 93 | struct device_node *nvgpu_get_node(struct gk20a *g) | ||
| 94 | { | ||
| 95 | struct device *dev = dev_from_gk20a(g); | ||
| 96 | |||
| 97 | if (dev_is_pci(dev)) { | ||
| 98 | struct pci_bus *bus = to_pci_dev(dev)->bus; | ||
| 99 | |||
| 100 | while (!pci_is_root_bus(bus)) | ||
| 101 | bus = bus->parent; | ||
| 102 | |||
| 103 | return bus->bridge->parent->of_node; | ||
| 104 | } | ||
| 105 | |||
| 106 | return dev->of_node; | ||
| 107 | } | ||
| 108 | |||
| 109 | void gk20a_busy_noresume(struct gk20a *g) | ||
| 110 | { | ||
| 111 | pm_runtime_get_noresume(dev_from_gk20a(g)); | ||
| 112 | } | ||
| 113 | |||
| 114 | /* | ||
| 115 | * Check if the device can go busy. | ||
| 116 | */ | ||
| 117 | static int nvgpu_can_busy(struct gk20a *g) | ||
| 118 | { | ||
| 119 | /* Can't do anything if the system is rebooting/shutting down. */ | ||
| 120 | if (nvgpu_is_enabled(g, NVGPU_KERNEL_IS_DYING)) | ||
| 121 | return 0; | ||
| 122 | |||
| 123 | /* Can't do anything if the driver is restarting. */ | ||
| 124 | if (nvgpu_is_enabled(g, NVGPU_DRIVER_IS_DYING)) | ||
| 125 | return 0; | ||
| 126 | |||
| 127 | return 1; | ||
| 128 | } | ||
| 129 | |||
| 130 | int gk20a_busy(struct gk20a *g) | ||
| 131 | { | ||
| 132 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 133 | int ret = 0; | ||
| 134 | struct device *dev; | ||
| 135 | |||
| 136 | if (!g) | ||
| 137 | return -ENODEV; | ||
| 138 | |||
| 139 | atomic_inc(&g->usage_count.atomic_var); | ||
| 140 | |||
| 141 | down_read(&l->busy_lock); | ||
| 142 | |||
| 143 | if (!nvgpu_can_busy(g)) { | ||
| 144 | ret = -ENODEV; | ||
| 145 | atomic_dec(&g->usage_count.atomic_var); | ||
| 146 | goto fail; | ||
| 147 | } | ||
| 148 | |||
| 149 | dev = dev_from_gk20a(g); | ||
| 150 | |||
| 151 | if (pm_runtime_enabled(dev)) { | ||
| 152 | /* Increment usage count and attempt to resume device */ | ||
| 153 | ret = pm_runtime_get_sync(dev); | ||
| 154 | if (ret < 0) { | ||
| 155 | /* Mark suspended so runtime pm will retry later */ | ||
| 156 | pm_runtime_set_suspended(dev); | ||
| 157 | pm_runtime_put_noidle(dev); | ||
| 158 | atomic_dec(&g->usage_count.atomic_var); | ||
| 159 | goto fail; | ||
| 160 | } | ||
| 161 | } else { | ||
| 162 | ret = gk20a_gpu_is_virtual(dev) ? | ||
| 163 | vgpu_pm_finalize_poweron(dev) : | ||
| 164 | gk20a_pm_finalize_poweron(dev); | ||
| 165 | if (ret) { | ||
| 166 | atomic_dec(&g->usage_count.atomic_var); | ||
| 167 | goto fail; | ||
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | fail: | ||
| 172 | up_read(&l->busy_lock); | ||
| 173 | |||
| 174 | return ret < 0 ? ret : 0; | ||
| 175 | } | ||
| 176 | |||
| 177 | void gk20a_idle_nosuspend(struct gk20a *g) | ||
| 178 | { | ||
| 179 | pm_runtime_put_noidle(dev_from_gk20a(g)); | ||
| 180 | } | ||
| 181 | |||
| 182 | void gk20a_idle(struct gk20a *g) | ||
| 183 | { | ||
| 184 | struct device *dev; | ||
| 185 | |||
| 186 | atomic_dec(&g->usage_count.atomic_var); | ||
| 187 | |||
| 188 | dev = dev_from_gk20a(g); | ||
| 189 | |||
| 190 | if (!(dev && nvgpu_can_busy(g))) | ||
| 191 | return; | ||
| 192 | |||
| 193 | if (pm_runtime_enabled(dev)) { | ||
| 194 | pm_runtime_mark_last_busy(dev); | ||
| 195 | pm_runtime_put_sync_autosuspend(dev); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | /* | ||
| 200 | * Undoes gk20a_lockout_registers(). | ||
| 201 | */ | ||
| 202 | static int gk20a_restore_registers(struct gk20a *g) | ||
| 203 | { | ||
| 204 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 205 | |||
| 206 | l->regs = l->regs_saved; | ||
| 207 | l->bar1 = l->bar1_saved; | ||
| 208 | |||
| 209 | nvgpu_restore_usermode_registers(g); | ||
| 210 | |||
| 211 | return 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | int nvgpu_finalize_poweron_linux(struct nvgpu_os_linux *l) | ||
| 215 | { | ||
| 216 | struct gk20a *g = &l->g; | ||
| 217 | int err; | ||
| 218 | |||
| 219 | if (l->init_done) | ||
| 220 | return 0; | ||
| 221 | |||
| 222 | err = nvgpu_init_channel_support_linux(l); | ||
| 223 | if (err) { | ||
| 224 | nvgpu_err(g, "failed to init linux channel support"); | ||
| 225 | return err; | ||
| 226 | } | ||
| 227 | |||
| 228 | if (l->ops.clk.init_debugfs) { | ||
| 229 | err = l->ops.clk.init_debugfs(g); | ||
| 230 | if (err) { | ||
