summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gp106/sec2_gp106.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gp106/sec2_gp106.c')
-rw-r--r--drivers/gpu/nvgpu/gp106/sec2_gp106.c230
1 files changed, 230 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gp106/sec2_gp106.c b/drivers/gpu/nvgpu/gp106/sec2_gp106.c
new file mode 100644
index 00000000..26ded39e
--- /dev/null
+++ b/drivers/gpu/nvgpu/gp106/sec2_gp106.c
@@ -0,0 +1,230 @@
1/*
2 * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/pmu.h>
24#include <nvgpu/falcon.h>
25#include <nvgpu/mm.h>
26
27#include "gk20a/gk20a.h"
28#include "sec2_gp106.h"
29
30#include <nvgpu/hw/gp106/hw_pwr_gp106.h>
31#include <nvgpu/hw/gp106/hw_psec_gp106.h>
32
33/*Defines*/
34#define gm20b_dbg_pmu(fmt, arg...) \
35 gk20a_dbg(gpu_dbg_pmu, fmt, ##arg)
36
37int sec2_clear_halt_interrupt_status(struct gk20a *g, unsigned int timeout)
38{
39 int status = 0;
40
41 if (nvgpu_flcn_clear_halt_intr_status(&g->sec2_flcn, timeout))
42 status = -EBUSY;
43
44 return status;
45}
46
47int sec2_wait_for_halt(struct gk20a *g, unsigned int timeout)
48{
49 u32 data = 0;
50 int completion = 0;
51
52 completion = nvgpu_flcn_wait_for_halt(&g->sec2_flcn, timeout);
53 if (completion) {
54 nvgpu_err(g, "ACR boot timed out");
55 return completion;
56 }
57
58 g->acr.capabilities = gk20a_readl(g, psec_falcon_mailbox1_r());
59 gm20b_dbg_pmu("ACR capabilities %x\n", g->acr.capabilities);
60 data = gk20a_readl(g, psec_falcon_mailbox0_r());
61 if (data) {
62
63 nvgpu_err(g, "ACR boot failed, err %x", data);
64 completion = -EAGAIN;
65 }
66
67 init_pmu_setup_hw1(g);
68
69 return completion;
70}
71
72int bl_bootstrap_sec2(struct nvgpu_pmu *pmu,
73 void *desc, u32 bl_sz)
74{
75 struct gk20a *g = gk20a_from_pmu(pmu);
76 struct acr_desc *acr = &g->acr;
77 struct mm_gk20a *mm = &g->mm;
78 u32 virt_addr = 0;
79 struct hsflcn_bl_desc *pmu_bl_gm10x_desc = g->acr.pmu_hsbl_desc;
80 u32 data = 0;
81 u32 dst;
82
83 gk20a_dbg_fn("");
84
85 /* SEC2 Config */
86 gk20a_writel(g, psec_falcon_itfen_r(),
87 gk20a_readl(g, psec_falcon_itfen_r()) |
88 psec_falcon_itfen_ctxen_enable_f());
89
90 gk20a_writel(g, psec_falcon_nxtctx_r(),
91 pwr_pmu_new_instblk_ptr_f(
92 nvgpu_inst_block_addr(g, &mm->pmu.inst_block) >> 12) |
93 pwr_pmu_new_instblk_valid_f(1) |
94 nvgpu_aperture_mask(g, &mm->pmu.inst_block,
95 pwr_pmu_new_instblk_target_sys_coh_f(),
96 pwr_pmu_new_instblk_target_fb_f()));
97
98 data = gk20a_readl(g, psec_falcon_debug1_r());
99 data |= psec_falcon_debug1_ctxsw_mode_m();
100 gk20a_writel(g, psec_falcon_debug1_r(), data);
101
102 data = gk20a_readl(g, psec_falcon_engctl_r());
103 data |= (1 << 3);
104 gk20a_writel(g, psec_falcon_engctl_r(), data);
105
106 /*copy bootloader interface structure to dmem*/
107 nvgpu_flcn_copy_to_dmem(&g->sec2_flcn, 0, (u8 *)desc,
108 sizeof(struct flcn_bl_dmem_desc), 0);
109
110 /* copy bootloader to TOP of IMEM */
111 dst = (psec_falcon_hwcfg_imem_size_v(
112 gk20a_readl(g, psec_falcon_hwcfg_r())) << 8) - bl_sz;
113
114 nvgpu_flcn_copy_to_imem(&g->sec2_flcn, dst,
115 (u8 *)(acr->hsbl_ucode.cpu_va), bl_sz, 0, 0,
116 pmu_bl_gm10x_desc->bl_start_tag);
117
118 gm20b_dbg_pmu("Before starting falcon with BL\n");
119
120 gk20a_writel(g, psec_falcon_mailbox0_r(), 0xDEADA5A5);
121
122 virt_addr = pmu_bl_gm10x_desc->bl_start_tag << 8;
123
124 nvgpu_flcn_bootstrap(&g->sec2_flcn, virt_addr);
125
126 return 0;
127}
128
129void init_pmu_setup_hw1(struct gk20a *g)
130{
131 struct mm_gk20a *mm = &g->mm;
132 struct nvgpu_pmu *pmu = &g->pmu;
133
134 /* PMU TRANSCFG */
135 /* setup apertures - virtual */
136 gk20a_writel(g, pwr_fbif_transcfg_r(GK20A_PMU_DMAIDX_UCODE),
137 pwr_fbif_transcfg_mem_type_physical_f() |
138 pwr_fbif_transcfg_target_local_fb_f());
139 gk20a_writel(g, pwr_fbif_transcfg_r(GK20A_PMU_DMAIDX_VIRT),
140 pwr_fbif_transcfg_mem_type_virtual_f());
141 /* setup apertures - physical */
142 gk20a_writel(g, pwr_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_VID),
143 pwr_fbif_transcfg_mem_type_physical_f() |
144 pwr_fbif_transcfg_target_local_fb_f());
145 gk20a_writel(g, pwr_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_SYS_COH),
146 pwr_fbif_transcfg_mem_type_physical_f() |
147 pwr_fbif_transcfg_target_coherent_sysmem_f());
148 gk20a_writel(g, pwr_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_SYS_NCOH),
149 pwr_fbif_transcfg_mem_type_physical_f() |
150 pwr_fbif_transcfg_target_noncoherent_sysmem_f());
151
152 /* PMU Config */
153 gk20a_writel(g, pwr_falcon_itfen_r(),
154 gk20a_readl(g, pwr_falcon_itfen_r()) |
155 pwr_falcon_itfen_ctxen_enable_f());
156 gk20a_writel(g, pwr_pmu_new_instblk_r(),
157 pwr_pmu_new_instblk_ptr_f(
158 nvgpu_inst_block_addr(g, &mm->pmu.inst_block) >> 12) |
159 pwr_pmu_new_instblk_valid_f(1) |
160 nvgpu_aperture_mask(g, &mm->pmu.inst_block,
161 pwr_pmu_new_instblk_target_sys_coh_f(),
162 pwr_pmu_new_instblk_target_fb_f()));
163
164 /*Copying pmu cmdline args*/
165 g->ops.pmu_ver.set_pmu_cmdline_args_cpu_freq(pmu, 0);
166 g->ops.pmu_ver.set_pmu_cmdline_args_secure_mode(pmu, 1);
167 g->ops.pmu_ver.set_pmu_cmdline_args_trace_size(
168 pmu, GK20A_PMU_TRACE_BUFSIZE);
169 g->ops.pmu_ver.set_pmu_cmdline_args_trace_dma_base(pmu);
170 g->ops.pmu_ver.set_pmu_cmdline_args_trace_dma_idx(
171 pmu, GK20A_PMU_DMAIDX_VIRT);
172
173 nvgpu_flcn_copy_to_dmem(pmu->flcn, g->acr.pmu_args,
174 (u8 *)(g->ops.pmu_ver.get_pmu_cmdline_args_ptr(pmu)),
175 g->ops.pmu_ver.get_pmu_cmdline_args_size(pmu), 0);
176
177}
178
179int gp106_sec2_reset(struct gk20a *g)
180{
181 nvgpu_log_fn(g, " ");
182
183 gk20a_writel(g, psec_falcon_engine_r(),
184 pwr_falcon_engine_reset_true_f());
185 nvgpu_udelay(10);
186 gk20a_writel(g, psec_falcon_engine_r(),
187 pwr_falcon_engine_reset_false_f());
188
189 nvgpu_log_fn(g, "done");
190 return 0;
191}
192
193int init_sec2_setup_hw1(struct gk20a *g,
194 void *desc, u32 bl_sz)
195{
196 struct nvgpu_pmu *pmu = &g->pmu;
197 int err;
198 u32 data = 0;
199
200 nvgpu_log_fn(g, " ");
201
202 nvgpu_flcn_reset(&g->sec2_flcn);
203
204 data = gk20a_readl(g, psec_fbif_ctl_r());
205 data |= psec_fbif_ctl_allow_phys_no_ctx_allow_f();
206 gk20a_writel(g, psec_fbif_ctl_r(), data);
207
208 /* setup apertures - virtual */
209 gk20a_writel(g, psec_fbif_transcfg_r(GK20A_PMU_DMAIDX_UCODE),
210 psec_fbif_transcfg_mem_type_physical_f() |
211 psec_fbif_transcfg_target_local_fb_f());
212 gk20a_writel(g, psec_fbif_transcfg_r(GK20A_PMU_DMAIDX_VIRT),
213 psec_fbif_transcfg_mem_type_virtual_f());
214 /* setup apertures - physical */
215 gk20a_writel(g, psec_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_VID),
216 psec_fbif_transcfg_mem_type_physical_f() |
217 psec_fbif_transcfg_target_local_fb_f());
218 gk20a_writel(g, psec_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_SYS_COH),
219 psec_fbif_transcfg_mem_type_physical_f() |
220 psec_fbif_transcfg_target_coherent_sysmem_f());
221 gk20a_writel(g, psec_fbif_transcfg_r(GK20A_PMU_DMAIDX_PHYS_SYS_NCOH),
222 psec_fbif_transcfg_mem_type_physical_f() |
223 psec_fbif_transcfg_target_noncoherent_sysmem_f());
224
225 err = bl_bootstrap_sec2(pmu, desc, bl_sz);
226 if (err)
227 return err;
228
229 return 0;
230}