aboutsummaryrefslogtreecommitdiffstats
path: root/include/os/linux/driver_common.c
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
commit01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch)
tree4ef34501728a087be24f4ba0af90f91486bf780b /include/os/linux/driver_common.c
parent306a03d18b305e4e573be3b2931978fa10679eb9 (diff)
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time being. Only a couple structs are required, so it should be fairly easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/os/linux/driver_common.c')
-rw-r--r--include/os/linux/driver_common.c351
1 files changed, 351 insertions, 0 deletions
diff --git a/include/os/linux/driver_common.c b/include/os/linux/driver_common.c
new file mode 100644
index 0000000..c76dabe
--- /dev/null
+++ b/include/os/linux/driver_common.c
@@ -0,0 +1,351 @@
1/*
2 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/reboot.h>
18#include <linux/dma-mapping.h>
19#include <linux/mm.h>
20#include <linux/slab.h>
21#include <uapi/linux/nvgpu.h>
22
23#include <nvgpu/defaults.h>
24#include <nvgpu/kmem.h>
25#include <nvgpu/nvgpu_common.h>
26#include <nvgpu/soc.h>
27#include <nvgpu/bug.h>
28#include <nvgpu/enabled.h>
29#include <nvgpu/debug.h>
30#include <nvgpu/sizes.h>
31#include <nvgpu/gk20a.h>
32
33#include "platform_gk20a.h"
34#include "module.h"
35#include "os_linux.h"
36#include "sysfs.h"
37#include "ioctl.h"
38#include "gk20a/regops_gk20a.h"
39
40#define EMC3D_DEFAULT_RATIO 750
41
42void nvgpu_kernel_restart(void *cmd)
43{
44 kernel_restart(cmd);
45}
46
47static void nvgpu_init_vars(struct gk20a *g)
48{
49 struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g);
50 struct device *dev = dev_from_gk20a(g);
51 struct gk20a_platform *platform = dev_get_drvdata(dev);
52
53 nvgpu_cond_init(&l->sw_irq_stall_last_handled_wq);
54 nvgpu_cond_init(&l->sw_irq_nonstall_last_handled_wq);
55
56 init_rwsem(&l->busy_lock);
57 nvgpu_rwsem_init(&g->deterministic_busy);
58
59 nvgpu_spinlock_init(&g->mc_enable_lock);
60
61 nvgpu_mutex_init(&platform->railgate_lock);
62 nvgpu_mutex_init(&g->dbg_sessions_lock);
63 nvgpu_mutex_init(&g->client_lock);
64 nvgpu_mutex_init(&g->power_lock);
65 nvgpu_mutex_init(&g->ctxsw_disable_lock);
66 nvgpu_mutex_init(&g->tpc_pg_lock);
67 nvgpu_mutex_init(&g->clk_arb_enable_lock);
68 nvgpu_mutex_init(&g->cg_pg_lock);
69
70 /* Init the clock req count to 0 */
71 nvgpu_atomic_set(&g->clk_arb_global_nr, 0);
72
73 nvgpu_mutex_init(&l->ctrl.privs_lock);
74 nvgpu_init_list_node(&l->ctrl.privs);
75
76 l->regs_saved = l->regs;
77 l->bar1_saved = l->bar1;
78
79 g->emc3d_ratio = EMC3D_DEFAULT_RATIO;
80
81 /* Set DMA parameters to allow larger sgt lists */
82 dev->dma_parms = &l->dma_parms;
83 dma_set_max_seg_size(dev, UINT_MAX);
84
85 /*
86 * A default of 16GB is the largest supported DMA size that is
87 * acceptable to all currently supported Tegra SoCs.
88 */
89 if (!platform->dma_mask)
90 platform->dma_mask = DMA_BIT_MASK(34);
91
92 dma_set_mask(dev, platform->dma_mask);
93 dma_set_coherent_mask(dev, platform->dma_mask);
94
95 nvgpu_init_list_node(&g->profiler_objects);
96
97 nvgpu_init_list_node(&g->boardobj_head);
98 nvgpu_init_list_node(&g->boardobjgrp_head);
99
100 __nvgpu_set_enabled(g, NVGPU_HAS_SYNCPOINTS, platform->has_syncpoints);
101}
102
103static void nvgpu_init_gr_vars(struct gk20a *g)
104{
105 gk20a_init_gr(g);
106
107 nvgpu_log_info(g, "total ram pages : %lu", totalram_pages);
108 g->gr.max_comptag_mem = totalram_size_in_mb;
109}
110
111static void nvgpu_init_timeout(struct gk20a *g)
112{
113 struct gk20a_platform *platform = dev_get_drvdata(dev_from_gk20a(g));
114
115 g->timeouts_disabled_by_user = false;
116 nvgpu_atomic_set(&g->timeouts_disabled_refcount, 0);
117
118 if (nvgpu_platform_is_silicon(g)) {
119 g->gr_idle_timeout_default = NVGPU_DEFAULT_GR_IDLE_TIMEOUT;
120 } else if (nvgpu_platform_is_fpga(g)) {
121 g->gr_idle_timeout_default = GK20A_TIMEOUT_FPGA;
122 } else {
123 g->gr_idle_timeout_default = (u32)ULONG_MAX;
124 }
125 g->ch_wdt_timeout_ms = platform->ch_wdt_timeout_ms;
126 g->fifo_eng_timeout_us = GRFIFO_TIMEOUT_CHECK_PERIOD_US;
127}
128
129static void nvgpu_init_timeslice(struct gk20a *g)
130{
131 g->runlist_interleave = true;
132
133 g->timeslice_low_priority_us = 1300;
134 g->timeslice_medium_priority_us = 2600;
135 g->timeslice_high_priority_us = 5200;
136
137 g->min_timeslice_us = 1000;
138 g->max_timeslice_us = 50000;
139}
140
141static void nvgpu_init_pm_vars(struct gk20a *g)
142{
143 struct gk20a_platform *platform = dev_get_drvdata(dev_from_gk20a(g));
144 u32 i = 0;
145
146 /*
147 * Set up initial power settings. For non-slicon platforms, disable
148 * power features and for silicon platforms, read from platform data
149 */
150 g->slcg_enabled =
151 nvgpu_platform_is_silicon(g) ? platform->enable_slcg : false;
152 g->blcg_enabled =
153 nvgpu_platform_is_silicon(g) ? platform->enable_blcg : false;
154 g->elcg_enabled =
155 nvgpu_platform_is_silicon(g) ? platform->enable_elcg : false;
156 g->elpg_enabled =
157 nvgpu_platform_is_silicon(g) ? platform->enable_elpg : false;
158 g->aelpg_enabled =
159 nvgpu_platform_is_silicon(g) ? platform->enable_aelpg : false;
160 g->mscg_enabled =
161 nvgpu_platform_is_silicon(g) ? platform->enable_mscg : false;
162 g->can_elpg =
163 nvgpu_platform_is_silicon(g) ? platform->can_elpg_init : false;
164
165 __nvgpu_set_enabled(g, NVGPU_GPU_CAN_ELCG,
166 nvgpu_platform_is_silicon(g) ? platform->can_elcg : false);
167 __nvgpu_set_enabled(g, NVGPU_GPU_CAN_SLCG,
168 nvgpu_platform_is_silicon(g) ? platform->can_slcg : false);
169 __nvgpu_set_enabled(g, NVGPU_GPU_CAN_BLCG,
170 nvgpu_platform_is_silicon(g) ? platform->can_blcg : false);
171
172 g->aggressive_sync_destroy = platform->aggressive_sync_destroy;
173 g->aggressive_sync_destroy_thresh = platform->aggressive_sync_destroy_thresh;
174#ifdef CONFIG_NVGPU_SUPPORT_CDE
175 g->has_cde = platform->has_cde;
176#endif
177 g->ptimer_src_freq = platform->ptimer_src_freq;
178 g->support_pmu = support_gk20a_pmu(dev_from_gk20a(g));
179 __nvgpu_set_enabled(g, NVGPU_CAN_RAILGATE, platform->can_railgate_init);
180 g->can_tpc_powergate = platform->can_tpc_powergate;
181
182 for (i = 0; i < MAX_TPC_PG_CONFIGS; i++)
183 g->valid_tpc_mask[i] = platform->valid_tpc_mask[i];
184
185 g->ldiv_slowdown_factor = platform->ldiv_slowdown_factor_init;
186 /* if default delay is not set, set default delay to 500msec */
187 if (platform->railgate_delay_init)
188 g->railgate_delay = platform->railgate_delay_init;
189 else
190 g->railgate_delay = NVGPU_DEFAULT_RAILGATE_IDLE_TIMEOUT;
191 __nvgpu_set_enabled(g, NVGPU_PMU_PERFMON, platform->enable_perfmon);
192
193 /* set default values to aelpg parameters */
194 g->pmu.aelpg_param[0] = APCTRL_SAMPLING_PERIOD_PG_DEFAULT_US;
195 g->pmu.aelpg_param[1] = APCTRL_MINIMUM_IDLE_FILTER_DEFAULT_US;
196 g->pmu.aelpg_param[2] = APCTRL_MINIMUM_TARGET_SAVING_DEFAULT_US;
197 g->pmu.aelpg_param[3] = APCTRL_POWER_BREAKEVEN_DEFAULT_US;
198 g->pmu.aelpg_param[4] = APCTRL_CYCLES_PER_SAMPLE_MAX_DEFAULT;
199
200 __nvgpu_set_enabled(g, NVGPU_SUPPORT_ASPM, !platform->disable_aspm);
201}
202
203static void nvgpu_init_vbios_vars(struct gk20a *g)
204{
205 struct gk20a_platform *platform = dev_get_drvdata(dev_from_gk20a(g));
206
207 __nvgpu_set_enabled(g, NVGPU_PMU_RUN_PREOS, platform->run_preos);
208 g->vbios_min_version = platform->vbios_min_version;