summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gm20b/pmu_gm20b.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gm20b/pmu_gm20b.c')
-rw-r--r--drivers/gpu/nvgpu/gm20b/pmu_gm20b.c283
1 files changed, 283 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gm20b/pmu_gm20b.c b/drivers/gpu/nvgpu/gm20b/pmu_gm20b.c
new file mode 100644
index 00000000..664134f9
--- /dev/null
+++ b/drivers/gpu/nvgpu/gm20b/pmu_gm20b.c
@@ -0,0 +1,283 @@
1/*
2 * GM20B PMU
3 *
4 * Copyright (c) 2015-2017, 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/timers.h>
26#include <nvgpu/pmu.h>
27#include <nvgpu/fuse.h>
28#include <nvgpu/enabled.h>
29
30#include "gk20a/gk20a.h"
31#include "gk20a/pmu_gk20a.h"
32
33#include "acr_gm20b.h"
34#include "pmu_gm20b.h"
35
36#include <nvgpu/hw/gm20b/hw_gr_gm20b.h>
37#include <nvgpu/hw/gm20b/hw_pwr_gm20b.h>
38#include <nvgpu/hw/gm20b/hw_fuse_gm20b.h>
39
40/*!
41 * Structure/object which single register write need to be done during PG init
42 * sequence to set PROD values.
43 */
44struct pg_init_sequence_list {
45 u32 regaddr;
46 u32 writeval;
47};
48
49#define gm20b_dbg_pmu(fmt, arg...) \
50 gk20a_dbg(gpu_dbg_pmu, fmt, ##arg)
51
52
53/* PROD settings for ELPG sequencing registers*/
54static struct pg_init_sequence_list _pginitseq_gm20b[] = {
55 { 0x0010ab10, 0x8180},
56 { 0x0010e118, 0x83828180},
57 { 0x0010e068, 0},
58 { 0x0010e06c, 0x00000080},
59 { 0x0010e06c, 0x00000081},
60 { 0x0010e06c, 0x00000082},
61 { 0x0010e06c, 0x00000083},
62 { 0x0010e06c, 0x00000084},
63 { 0x0010e06c, 0x00000085},
64 { 0x0010e06c, 0x00000086},
65 { 0x0010e06c, 0x00000087},
66 { 0x0010e06c, 0x00000088},
67 { 0x0010e06c, 0x00000089},
68 { 0x0010e06c, 0x0000008a},
69 { 0x0010e06c, 0x0000008b},
70 { 0x0010e06c, 0x0000008c},
71 { 0x0010e06c, 0x0000008d},
72 { 0x0010e06c, 0x0000008e},
73 { 0x0010e06c, 0x0000008f},
74 { 0x0010e06c, 0x00000090},
75 { 0x0010e06c, 0x00000091},
76 { 0x0010e06c, 0x00000092},
77 { 0x0010e06c, 0x00000093},
78 { 0x0010e06c, 0x00000094},
79 { 0x0010e06c, 0x00000095},
80 { 0x0010e06c, 0x00000096},
81 { 0x0010e06c, 0x00000097},
82 { 0x0010e06c, 0x00000098},
83 { 0x0010e06c, 0x00000099},
84 { 0x0010e06c, 0x0000009a},
85 { 0x0010e06c, 0x0000009b},
86 { 0x0010ab14, 0x00000000},
87 { 0x0010ab18, 0x00000000},
88 { 0x0010e024, 0x00000000},
89 { 0x0010e028, 0x00000000},
90 { 0x0010e11c, 0x00000000},
91 { 0x0010e120, 0x00000000},
92 { 0x0010ab1c, 0x02010155},
93 { 0x0010e020, 0x001b1b55},
94 { 0x0010e124, 0x01030355},
95 { 0x0010ab20, 0x89abcdef},
96 { 0x0010ab24, 0x00000000},
97 { 0x0010e02c, 0x89abcdef},
98 { 0x0010e030, 0x00000000},
99 { 0x0010e128, 0x89abcdef},
100 { 0x0010e12c, 0x00000000},
101 { 0x0010ab28, 0x74444444},
102 { 0x0010ab2c, 0x70000000},
103 { 0x0010e034, 0x74444444},
104 { 0x0010e038, 0x70000000},
105 { 0x0010e130, 0x74444444},
106 { 0x0010e134, 0x70000000},
107 { 0x0010ab30, 0x00000000},
108 { 0x0010ab34, 0x00000001},
109 { 0x00020004, 0x00000000},
110 { 0x0010e138, 0x00000000},
111 { 0x0010e040, 0x00000000},
112};
113
114int gm20b_pmu_setup_elpg(struct gk20a *g)
115{
116 int ret = 0;
117 u32 reg_writes;
118 u32 index;
119
120 gk20a_dbg_fn("");
121
122 if (g->elpg_enabled) {
123 reg_writes = ((sizeof(_pginitseq_gm20b) /
124 sizeof((_pginitseq_gm20b)[0])));
125 /* Initialize registers with production values*/
126 for (index = 0; index < reg_writes; index++) {
127 gk20a_writel(g, _pginitseq_gm20b[index].regaddr,
128 _pginitseq_gm20b[index].writeval);
129 }
130 }
131
132 gk20a_dbg_fn("done");
133 return ret;
134}
135
136static void pmu_handle_acr_init_wpr_msg(struct gk20a *g, struct pmu_msg *msg,
137 void *param, u32 handle, u32 status)
138{
139 gk20a_dbg_fn("");
140
141 gm20b_dbg_pmu("reply PMU_ACR_CMD_ID_INIT_WPR_REGION");
142
143 if (msg->msg.acr.acrmsg.errorcode == PMU_ACR_SUCCESS)
144 g->pmu_lsf_pmu_wpr_init_done = 1;
145 gk20a_dbg_fn("done");
146}
147
148
149int gm20b_pmu_init_acr(struct gk20a *g)
150{
151 struct nvgpu_pmu *pmu = &g->pmu;
152 struct pmu_cmd cmd;
153 u32 seq;
154
155 gk20a_dbg_fn("");
156
157 /* init ACR */
158 memset(&cmd, 0, sizeof(struct pmu_cmd));
159 cmd.hdr.unit_id = PMU_UNIT_ACR;
160 cmd.hdr.size = PMU_CMD_HDR_SIZE +
161 sizeof(struct pmu_acr_cmd_init_wpr_details);
162 cmd.cmd.acr.init_wpr.cmd_type = PMU_ACR_CMD_ID_INIT_WPR_REGION;
163 cmd.cmd.acr.init_wpr.regionid = 0x01;
164 cmd.cmd.acr.init_wpr.wproffset = 0x00;
165 gm20b_dbg_pmu("cmd post PMU_ACR_CMD_ID_INIT_WPR_REGION");
166 nvgpu_pmu_cmd_post(g, &cmd, NULL, NULL, PMU_COMMAND_QUEUE_HPQ,
167 pmu_handle_acr_init_wpr_msg, pmu, &seq, ~0);
168
169 gk20a_dbg_fn("done");
170 return 0;
171}
172
173void pmu_handle_fecs_boot_acr_msg(struct gk20a *g, struct pmu_msg *msg,
174 void *param, u32 handle, u32 status)
175{
176
177 gk20a_dbg_fn("");
178
179
180 gm20b_dbg_pmu("reply PMU_ACR_CMD_ID_BOOTSTRAP_FALCON");
181
182 gm20b_dbg_pmu("response code = %x\n", msg->msg.acr.acrmsg.falconid);
183 g->pmu_lsf_loaded_falcon_id = msg->msg.acr.acrmsg.falconid;
184 gk20a_dbg_fn("done");
185}
186
187static int pmu_gm20b_ctx_wait_lsf_ready(struct gk20a *g, u32 timeout_ms,
188 u32 val)
189{
190 unsigned long delay = GR_FECS_POLL_INTERVAL;
191 u32 reg;
192 struct nvgpu_timeout timeout;
193
194 gk20a_dbg_fn("");
195 reg = gk20a_readl(g, gr_fecs_ctxsw_mailbox_r(0));
196
197 nvgpu_timeout_init(g, &timeout, timeout_ms, NVGPU_TIMER_CPU_TIMER);
198
199 do {
200 reg = gk20a_readl(g, gr_fecs_ctxsw_mailbox_r(0));
201 if (reg == val)
202 return 0;
203 nvgpu_udelay(delay);
204 } while (!nvgpu_timeout_expired(&timeout));
205
206 return -ETIMEDOUT;
207}
208
209void gm20b_pmu_load_lsf(struct gk20a *g, u32 falcon_id, u32 flags)
210{
211 struct nvgpu_pmu *pmu = &g->pmu;
212 struct pmu_cmd cmd;
213 u32 seq;
214
215 gk20a_dbg_fn("");
216
217 gm20b_dbg_pmu("wprinit status = %x\n", g->pmu_lsf_pmu_wpr_init_done);
218 if (g->pmu_lsf_pmu_wpr_init_done) {
219 /* send message to load FECS falcon */
220 memset(&cmd, 0, sizeof(struct pmu_cmd));
221 cmd.hdr.unit_id = PMU_UNIT_ACR;
222 cmd.hdr.size = PMU_CMD_HDR_SIZE +
223 sizeof(struct pmu_acr_cmd_bootstrap_falcon);
224 cmd.cmd.acr.bootstrap_falcon.cmd_type =
225 PMU_ACR_CMD_ID_BOOTSTRAP_FALCON;
226 cmd.cmd.acr.bootstrap_falcon.flags = flags;
227 cmd.cmd.acr.bootstrap_falcon.falconid = falcon_id;
228 gm20b_dbg_pmu("cmd post PMU_ACR_CMD_ID_BOOTSTRAP_FALCON: %x\n",
229 falcon_id);
230 nvgpu_pmu_cmd_post(g, &cmd, NULL, NULL, PMU_COMMAND_QUEUE_HPQ,
231 pmu_handle_fecs_boot_acr_msg, pmu, &seq, ~0);
232 }
233
234 gk20a_dbg_fn("done");
235 return;
236}
237
238int gm20b_load_falcon_ucode(struct gk20a *g, u32 falconidmask)
239{
240 u32 err = 0;
241 u32 flags = PMU_ACR_CMD_BOOTSTRAP_FALCON_FLAGS_RESET_YES;
242 unsigned long timeout = gk20a_get_gr_idle_timeout(g);
243
244 /* GM20B PMU supports loading FECS only */
245 if (!(falconidmask == (1 << LSF_FALCON_ID_FECS)))
246 return -EINVAL;
247 /* check whether pmu is ready to bootstrap lsf if not wait for it */
248 if (!g->pmu_lsf_pmu_wpr_init_done) {
249 pmu_wait_message_cond(&g->pmu,
250 gk20a_get_gr_idle_timeout(g),
251 &g->pmu_lsf_pmu_wpr_init_done, 1);
252 /* check again if it still not ready indicate an error */
253 if (!g->pmu_lsf_pmu_wpr_init_done) {
254 nvgpu_err(g, "PMU not ready to load LSF");
255 return -ETIMEDOUT;
256 }
257 }
258 /* load FECS */
259 gk20a_writel(g,
260 gr_fecs_ctxsw_mailbox_clear_r(0), ~0x0);
261 gm20b_pmu_load_lsf(g, LSF_FALCON_ID_FECS, flags);
262 err = pmu_gm20b_ctx_wait_lsf_ready(g, timeout,
263 0x55AA55AA);
264 return err;
265}
266
267void gm20b_write_dmatrfbase(struct gk20a *g, u32 addr)
268{
269 gk20a_writel(g, pwr_falcon_dmatrfbase_r(), addr);
270}
271
272/*Dump Security related fuses*/
273void pmu_dump_security_fuses_gm20b(struct gk20a *g)
274{
275 u32 val;
276
277 nvgpu_err(g, "FUSE_OPT_SEC_DEBUG_EN_0: 0x%x",
278 gk20a_readl(g, fuse_opt_sec_debug_en_r()));
279 nvgpu_err(g, "FUSE_OPT_PRIV_SEC_EN_0: 0x%x",
280 gk20a_readl(g, fuse_opt_priv_sec_en_r()));
281 nvgpu_tegra_fuse_read_gcplex_config_fuse(g, &val);
282 nvgpu_err(g, "FUSE_GCPLEX_CONFIG_FUSE_0: 0x%x", val);
283}