aboutsummaryrefslogtreecommitdiffstats
path: root/include/gk20a/gr_gk20a.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/gk20a/gr_gk20a.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/gk20a/gr_gk20a.c')
-rw-r--r--include/gk20a/gr_gk20a.c8998
1 files changed, 8998 insertions, 0 deletions
diff --git a/include/gk20a/gr_gk20a.c b/include/gk20a/gr_gk20a.c
new file mode 100644
index 0000000..7bcf528
--- /dev/null
+++ b/include/gk20a/gr_gk20a.c
@@ -0,0 +1,8998 @@
1/*
2 * GK20A Graphics
3 *
4 * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <nvgpu/dma.h>
26#include <nvgpu/kmem.h>
27#include <nvgpu/gmmu.h>
28#include <nvgpu/timers.h>
29#include <nvgpu/nvgpu_common.h>
30#include <nvgpu/log.h>
31#include <nvgpu/bsearch.h>
32#include <nvgpu/sort.h>
33#include <nvgpu/bug.h>
34#include <nvgpu/firmware.h>
35#include <nvgpu/enabled.h>
36#include <nvgpu/debug.h>
37#include <nvgpu/barrier.h>
38#include <nvgpu/mm.h>
39#include <nvgpu/ctxsw_trace.h>
40#include <nvgpu/error_notifier.h>
41#include <nvgpu/ecc.h>
42#include <nvgpu/io.h>
43#include <nvgpu/utils.h>
44#include <nvgpu/channel.h>
45#include <nvgpu/unit.h>
46#include <nvgpu/power_features/pg.h>
47#include <nvgpu/power_features/cg.h>
48
49#include "gk20a.h"
50#include "gr_gk20a.h"
51#include "gk20a/fecs_trace_gk20a.h"
52#include "gr_ctx_gk20a.h"
53#include "gr_pri_gk20a.h"
54#include "regops_gk20a.h"
55#include "dbg_gpu_gk20a.h"
56
57#include <nvgpu/hw/gk20a/hw_ccsr_gk20a.h>
58#include <nvgpu/hw/gk20a/hw_ctxsw_prog_gk20a.h>
59#include <nvgpu/hw/gk20a/hw_fifo_gk20a.h>
60#include <nvgpu/hw/gk20a/hw_gr_gk20a.h>
61#include <nvgpu/hw/gk20a/hw_gmmu_gk20a.h>
62#include <nvgpu/hw/gk20a/hw_mc_gk20a.h>
63#include <nvgpu/hw/gk20a/hw_ram_gk20a.h>
64#include <nvgpu/hw/gk20a/hw_pri_ringmaster_gk20a.h>
65#include <nvgpu/hw/gk20a/hw_top_gk20a.h>
66#include <nvgpu/hw/gk20a/hw_pbdma_gk20a.h>
67
68#define BLK_SIZE (256)
69#define NV_PERF_PMM_FBP_ROUTER_STRIDE 0x0200
70#define NV_PERF_PMMGPCROUTER_STRIDE 0x0200
71#define NV_PCFG_BASE 0x00088000
72#define NV_XBAR_MXBAR_PRI_GPC_GNIC_STRIDE 0x0020
73#define FE_PWR_MODE_TIMEOUT_MAX 2000
74#define FE_PWR_MODE_TIMEOUT_DEFAULT 10
75#define CTXSW_MEM_SCRUBBING_TIMEOUT_MAX 1000
76#define CTXSW_MEM_SCRUBBING_TIMEOUT_DEFAULT 10
77#define FECS_ARB_CMD_TIMEOUT_MAX 40
78#define FECS_ARB_CMD_TIMEOUT_DEFAULT 2
79
80static int gk20a_init_gr_bind_fecs_elpg(struct gk20a *g);
81
82static void gr_gk20a_free_channel_pm_ctx(struct gk20a *g,
83 struct vm_gk20a *vm,
84 struct nvgpu_gr_ctx *gr_ctx);
85
86/* channel patch ctx buffer */
87static int gr_gk20a_alloc_channel_patch_ctx(struct gk20a *g,
88 struct channel_gk20a *c);
89static void gr_gk20a_free_channel_patch_ctx(struct gk20a *g,
90 struct vm_gk20a *vm,
91 struct nvgpu_gr_ctx *gr_ctx);
92
93/* golden ctx image */
94static int gr_gk20a_init_golden_ctx_image(struct gk20a *g,
95 struct channel_gk20a *c);
96
97int gr_gk20a_get_ctx_id(struct gk20a *g,
98 struct channel_gk20a *c,
99 u32 *ctx_id)
100{
101 struct tsg_gk20a *tsg;
102 struct nvgpu_gr_ctx *gr_ctx = NULL;
103 struct nvgpu_mem *mem = NULL;
104
105 tsg = tsg_gk20a_from_ch(c);
106 if (tsg == NULL) {
107 return -EINVAL;
108 }
109
110 gr_ctx = &tsg->gr_ctx;
111 mem = &gr_ctx->mem;
112
113 /* Channel gr_ctx buffer is gpu cacheable.
114 Flush and invalidate before cpu update. */
115 g->ops.mm.l2_flush(g, true);
116
117 *ctx_id = nvgpu_mem_rd(g, mem,
118 ctxsw_prog_main_image_context_id_o());
119 nvgpu_log(g, gpu_dbg_fn | gpu_dbg_intr, "ctx_id: 0x%x", *ctx_id);
120
121 return 0;
122}
123
124void gk20a_fecs_dump_falcon_stats(struct gk20a *g)
125{
126 unsigned int i;
127
128 nvgpu_err(g, "gr_fecs_os_r : %d",
129 gk20a_readl(g, gr_fecs_os_r()));
130 nvgpu_err(g, "gr_fecs_cpuctl_r : 0x%x",
131 gk20a_readl(g, gr_fecs_cpuctl_r()));
132 nvgpu_err(g, "gr_fecs_idlestate_r : 0x%x",
133 gk20a_readl(g, gr_fecs_idlestate_r()));
134 nvgpu_err(g, "gr_fecs_mailbox0_r : 0x%x",
135 gk20a_readl(g, gr_fecs_mailbox0_r()));
136 nvgpu_err(g, "gr_fecs_mailbox1_r : 0x%x",
137 gk20a_readl(g, gr_fecs_mailbox1_r()));
138 nvgpu_err(g, "gr_fecs_irqstat_r : 0x%x",
139 gk20a_readl(g, gr_fecs_irqstat_r()));
140 nvgpu_err(g, "gr_fecs_irqmode_r : 0x%x",
141 gk20a_readl(g, gr_fecs_irqmode_r()));
142 nvgpu_err(g, "gr_fecs_irqmask_r : 0x%x",
143 gk20a_readl(g, gr_fecs_irqmask_r()));
144 nvgpu_err(g, "gr_fecs_irqdest_r : 0x%x",
145 gk20a_readl(g, gr_fecs_irqdest_r()));
146 nvgpu_err(g, "gr_fecs_debug1_r : 0x%x",
147 gk20a_readl(g, gr_fecs_debug1_r()));
148 nvgpu_err(g, "gr_fecs_debuginfo_r : 0x%x",
149 gk20a_readl(g, gr_fecs_debuginfo_r()));
150 nvgpu_err(g, "gr_fecs_ctxsw_status_1_r : 0x%x",
151 gk20a_readl(g, gr_fecs_ctxsw_status_1_r()));
152
153 for (i = 0; i < g->ops.gr.fecs_ctxsw_mailbox_size(); i++) {
154 nvgpu_err(g, "gr_fecs_ctxsw_mailbox_r(%d) : 0x%x",
155 i, gk20a_readl(g, gr_fecs_ctxsw_mailbox_r(i)));
156 }
157
158 nvgpu_err(g, "gr_fecs_engctl_r : 0x%x",
159 gk20a_readl(g, gr_fecs_engctl_r()));
160 nvgpu_err(g, "gr_fecs_curctx_r : 0x%x",
161 gk20a_readl(g, gr_fecs_curctx_r()));
162 nvgpu_err(g, "gr_fecs_nxtctx_r : 0x%x",
163 gk20a_readl(g, gr_fecs_nxtctx_r()));
164
165 gk20a_writel(g, gr_fecs_icd_cmd_r(),
166 gr_fecs_icd_cmd_opc_rreg_f() |
167 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_IMB));
168 nvgpu_err(g, "FECS_FALCON_REG_IMB : 0x%x",
169 gk20a_readl(g, gr_fecs_icd_rdata_r()));
170
171 gk20a_writel(g, gr_fecs_icd_cmd_r(),
172 gr_fecs_icd_cmd_opc_rreg_f() |
173 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_DMB));
174 nvgpu_err(g, "FECS_FALCON_REG_DMB : 0x%x",
175 gk20a_readl(g, gr_fecs_icd_rdata_r()));
176
177 gk20a_writel(g, gr_fecs_icd_cmd_r(),
178 gr_fecs_icd_cmd_opc_rreg_f() |
179 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_CSW));
180 nvgpu_err(g, "FECS_FALCON_REG_CSW : 0x%x",
181 gk20a_readl(g, gr_fecs_icd_rdata_r()));
182
183 gk20a_writel(g, gr_fecs_icd_cmd_r(),
184 gr_fecs_icd_cmd_opc_rreg_f() |
185 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_CTX));
186 nvgpu_err(g, "FECS_FALCON_REG_CTX : 0x%x",
187 gk20a_readl(g, gr_fecs_icd_rdata_r()));
188
189 gk20a_writel(g, gr_fecs_icd_cmd_r(),
190 gr_fecs_icd_cmd_opc_rreg_f() |
191 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_EXCI));
192 nvgpu_err(g, "FECS_FALCON_REG_EXCI : 0x%x",
193 gk20a_readl(g, gr_fecs_icd_rdata_r()));
194
195 for (i = 0; i < 4; i++) {
196 gk20a_writel(g, gr_fecs_icd_cmd_r(),
197 gr_fecs_icd_cmd_opc_rreg_f() |
198 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_PC));
199 nvgpu_err(g, "FECS_FALCON_REG_PC : 0x%x",
200 gk20a_readl(g, gr_fecs_icd_rdata_r()));
201
202 gk20a_writel(g, gr_fecs_icd_cmd_r(),
203 gr_fecs_icd_cmd_opc_rreg_f() |
204 gr_fecs_icd_cmd_idx_f(PMU_FALCON_REG_SP));
205 nvgpu_err(g, "FECS_FALCON_REG_SP : 0x%x",
206 gk20a_readl(g, gr_fecs_icd_rdata_r()));
207 }
208}
209
210static void gr_gk20a_load_falcon_dmem(struct gk20a *g)
211{
212 u32 i, ucode_u32_size;
213 const u32 *ucode_u32_data;
214 u32 checksum;
215</