2 * GK20A Graphics FIFO (gr host)
4 * Copyright (c) 2011-2015, NVIDIA CORPORATION. All rights reserved.
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.
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
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/scatterlist.h>
22 #include <trace/events/gk20a.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/nvhost.h>
27 #include "debug_gk20a.h"
28 #include "semaphore_gk20a.h"
29 #include "hw_fifo_gk20a.h"
30 #include "hw_pbdma_gk20a.h"
31 #include "hw_ccsr_gk20a.h"
32 #include "hw_ram_gk20a.h"
33 #include "hw_proj_gk20a.h"
34 #include "hw_top_gk20a.h"
35 #include "hw_mc_gk20a.h"
36 #include "hw_gr_gk20a.h"
37 #define FECS_METHOD_WFI_RESTORE 0x80000
39 static int gk20a_fifo_update_runlist_locked(struct gk20a *g, u32 runlist_id,
40 u32 hw_chid, bool add,
41 bool wait_for_finish);
44 * Link engine IDs to MMU IDs and vice versa.
47 static inline u32 gk20a_engine_id_to_mmu_id(u32 engine_id)
52 case ENGINE_CE2_GK20A:
59 static inline u32 gk20a_mmu_id_to_engine_id(u32 engine_id)
63 return ENGINE_GR_GK20A;
65 return ENGINE_CE2_GK20A;
72 static int init_engine_info(struct fifo_gk20a *f)
74 struct gk20a *g = f->g;
75 struct device *d = dev_from_gk20a(g);
77 u32 max_info_entries = top_device_info__size_1_v();
81 /* all we really care about finding is the graphics entry */
82 /* especially early on in sim it probably thinks it has more */
85 for (i = 0; i < max_info_entries; i++) {
86 struct fifo_engine_info_gk20a *info = NULL;
87 u32 table_entry = gk20a_readl(f->g, top_device_info_r(i));
88 u32 entry = top_device_info_entry_v(table_entry);
93 if (entry != top_device_info_entry_enum_v())
96 /* we only care about GR engine here */
97 engine_enum = top_device_info_engine_enum_v(table_entry);
98 if (engine_enum >= ENGINE_INVAL_GK20A)
101 gk20a_dbg_info("info: engine_id %d",
102 top_device_info_engine_enum_v(table_entry));
103 info = &g->fifo.engine_info[engine_enum];
106 top_device_info_runlist_enum_v(table_entry);
107 gk20a_dbg_info("gr info: runlist_id %d", info->runlist_id);
110 top_device_info_engine_enum_v(table_entry);
111 gk20a_dbg_info("gr info: engine_id %d", info->engine_id);
113 runlist_bit = 1 << info->runlist_id;
115 for (pbdma_id = 0; pbdma_id < f->num_pbdma; pbdma_id++) {
116 gk20a_dbg_info("gr info: pbdma_map[%d]=%d",
117 pbdma_id, f->pbdma_map[pbdma_id]);
118 if (f->pbdma_map[pbdma_id] & runlist_bit)
122 if (pbdma_id == f->num_pbdma) {
123 gk20a_err(d, "busted pbmda map");
126 info->pbdma_id = pbdma_id;
129 top_device_info_intr_enum_v(table_entry);
130 gk20a_dbg_info("gr info: intr_id %d", info->intr_id);
133 top_device_info_reset_enum_v(table_entry);
134 gk20a_dbg_info("gr info: reset_id %d",
142 u32 gk20a_fifo_engine_interrupt_mask(struct gk20a *g)
144 u32 eng_intr_mask = 0;
147 for (i = 0; i < g->fifo.max_engines; i++) {
148 u32 intr_id = g->fifo.engine_info[i].intr_id;
149 if (i == ENGINE_CE2_GK20A &&
150 (!g->ops.ce2.isr_stall || !g->ops.ce2.isr_nonstall))
154 eng_intr_mask |= BIT(intr_id);
157 return eng_intr_mask;
160 static void gk20a_remove_fifo_support(struct fifo_gk20a *f)
162 struct gk20a *g = f->g;
163 struct fifo_engine_info_gk20a *engine_info;
164 struct fifo_runlist_info_gk20a *runlist;
172 for (c = 0; c < f->num_channels; c++) {
173 if (f->channel[c].remove_support)
174 f->channel[c].remove_support(f->channel+c);
178 gk20a_gmmu_unmap_free(&g->mm.bar1.vm, &f->userd);
180 engine_info = f->engine_info + ENGINE_GR_GK20A;
181 runlist_id = engine_info->runlist_id;
182 runlist = &f->runlist_info[runlist_id];
184 for (i = 0; i < MAX_RUNLIST_BUFFERS; i++)
185 gk20a_gmmu_free(g, &runlist->mem[i]);
187 kfree(runlist->active_channels);
188 kfree(runlist->active_tsgs);
190 kfree(f->runlist_info);
192 kfree(f->engine_info);
195 /* reads info from hardware and fills in pbmda exception info record */
196 static inline void get_exception_pbdma_info(
198 struct fifo_engine_info_gk20a *eng_info)
200 struct fifo_pbdma_exception_info_gk20a *e =
201 &eng_info->pbdma_exception_info;
203 u32 pbdma_status_r = e->status_r = gk20a_readl(g,
204 fifo_pbdma_status_r(eng_info->pbdma_id));
205 e->id = fifo_pbdma_status_id_v(pbdma_status_r); /* vs. id_hw_v()? */
206 e->id_is_chid = fifo_pbdma_status_id_type_v(pbdma_status_r) ==
207 fifo_pbdma_status_id_type_chid_v();
208 e->chan_status_v = fifo_pbdma_status_chan_status_v(pbdma_status_r);
210 fifo_pbdma_status_next_id_type_v(pbdma_status_r) ==
211 fifo_pbdma_status_next_id_type_chid_v();
212 e->next_id = fifo_pbdma_status_next_id_v(pbdma_status_r);
213 e->chsw_in_progress =
214 fifo_pbdma_status_chsw_v(pbdma_status_r) ==
215 fifo_pbdma_status_chsw_in_progress_v();
218 static void fifo_pbdma_exception_status(struct gk20a *g,
219 struct fifo_engine_info_gk20a *eng_info)
221 struct fifo_pbdma_exception_info_gk20a *e;
222 get_exception_pbdma_info(g, eng_info);
223 e = &eng_info->pbdma_exception_info;
225 gk20a_dbg_fn("pbdma_id %d, "
226 "id_type %s, id %d, chan_status %d, "
227 "next_id_type %s, next_id %d, "
228 "chsw_in_progress %d",
230 e->id_is_chid ? "chid" : "tsgid", e->id, e->chan_status_v,
231 e->next_id_is_chid ? "chid" : "tsgid", e->next_id,
232 e->chsw_in_progress);
235 /* reads info from hardware and fills in pbmda exception info record */
236 static inline void get_exception_engine_info(
238 struct fifo_engine_info_gk20a *eng_info)
240 struct fifo_engine_exception_info_gk20a *e =
241 &eng_info->engine_exception_info;
242 u32 engine_status_r = e->status_r =
243 gk20a_readl(g, fifo_engine_status_r(eng_info->engine_id));
244 e->id = fifo_engine_status_id_v(engine_status_r); /* vs. id_hw_v()? */
245 e->id_is_chid = fifo_engine_status_id_type_v(engine_status_r) ==
246 fifo_engine_status_id_type_chid_v();
247 e->ctx_status_v = fifo_engine_status_ctx_status_v(engine_status_r);
249 fifo_engine_status_faulted_v(engine_status_r) ==
250 fifo_engine_status_faulted_true_v();
252 fifo_engine_status_engine_v(engine_status_r) ==
253 fifo_engine_status_engine_idle_v();
254 e->ctxsw_in_progress =
255 fifo_engine_status_ctxsw_v(engine_status_r) ==
256 fifo_engine_status_ctxsw_in_progress_v();
259 static void fifo_engine_exception_status(struct gk20a *g,
260 struct fifo_engine_info_gk20a *eng_info)
262 struct fifo_engine_exception_info_gk20a *e;
263 get_exception_engine_info(g, eng_info);
264 e = &eng_info->engine_exception_info;
266 gk20a_dbg_fn("engine_id %d, id_type %s, id %d, ctx_status %d, "
267 "faulted %d, idle %d, ctxsw_in_progress %d, ",
268 eng_info->engine_id, e->id_is_chid ? "chid" : "tsgid",
269 e->id, e->ctx_status_v,
270 e->faulted, e->idle, e->ctxsw_in_progress);
273 static int init_runlist(struct gk20a *g, struct fifo_gk20a *f)
275 struct fifo_engine_info_gk20a *engine_info;
276 struct fifo_runlist_info_gk20a *runlist;
277 struct device *d = dev_from_gk20a(g);
284 f->max_runlists = fifo_eng_runlist_base__size_1_v();
285 f->runlist_info = kzalloc(sizeof(struct fifo_runlist_info_gk20a) *
286 f->max_runlists, GFP_KERNEL);
287 if (!f->runlist_info)
290 engine_info = f->engine_info + ENGINE_GR_GK20A;
291 runlist_id = engine_info->runlist_id;
292 runlist = &f->runlist_info[runlist_id];
294 runlist->active_channels =
295 kzalloc(DIV_ROUND_UP(f->num_channels, BITS_PER_BYTE),
297 if (!runlist->active_channels)
298 goto clean_up_runlist_info;
300 runlist->active_tsgs =
301 kzalloc(DIV_ROUND_UP(f->num_channels, BITS_PER_BYTE),
303 if (!runlist->active_tsgs)
304 goto clean_up_runlist_info;
306 runlist_size = ram_rl_entry_size_v() * f->num_channels;
307 for (i = 0; i < MAX_RUNLIST_BUFFERS; i++) {
308 int err = gk20a_gmmu_alloc(g, runlist_size, &runlist->mem[i]);
310 dev_err(d, "memory allocation failed\n");
311 goto clean_up_runlist;
314 mutex_init(&runlist->mutex);
316 /* None of buffers is pinned if this value doesn't change.
317 Otherwise, one of them (cur_buffer) must have been pinned. */
318 runlist->cur_buffer = MAX_RUNLIST_BUFFERS;
320 gk20a_dbg_fn("done");
324 for (i = 0; i < MAX_RUNLIST_BUFFERS; i++)
325 gk20a_gmmu_free(g, &runlist->mem[i]);
327 kfree(runlist->active_channels);
328 runlist->active_channels = NULL;
330 clean_up_runlist_info:
331 kfree(f->runlist_info);
332 f->runlist_info = NULL;
335 gk20a_dbg_fn("fail");
339 #define GRFIFO_TIMEOUT_CHECK_PERIOD_US 100000
341 int gk20a_init_fifo_reset_enable_hw(struct gk20a *g)
349 /* enable pmc pfifo */
350 gk20a_reset(g, mc_enable_pfifo_enabled_f()
351 | mc_enable_ce2_enabled_f());
353 if (g->ops.clock_gating.slcg_ce2_load_gating_prod)
354 g->ops.clock_gating.slcg_ce2_load_gating_prod(g,
356 if (g->ops.clock_gating.slcg_fifo_load_gating_prod)
357 g->ops.clock_gating.slcg_fifo_load_gating_prod(g,
359 if (g->ops.clock_gating.blcg_fifo_load_gating_prod)
360 g->ops.clock_gating.blcg_fifo_load_gating_prod(g,
365 for (i = 0; i < proj_host_num_pbdma_v(); ++i)
366 mask |= mc_enable_pb_sel_f(mc_enable_pb_0_enabled_v(), i);
367 gk20a_writel(g, mc_enable_pb_r(), mask);
369 /* enable pfifo interrupt */
370 gk20a_writel(g, fifo_intr_0_r(), 0xFFFFFFFF);
371 gk20a_writel(g, fifo_intr_en_0_r(), 0x7FFFFFFF);
372 gk20a_writel(g, fifo_intr_en_1_r(), 0x80000000);
374 /* enable pbdma interrupt */
376 for (i = 0; i < proj_host_num_pbdma_v(); i++) {
377 intr_stall = gk20a_readl(g, pbdma_intr_stall_r(i));
378 intr_stall &= ~pbdma_intr_stall_lbreq_enabled_f();
379 gk20a_writel(g, pbdma_intr_stall_r(i), intr_stall);
380 gk20a_writel(g, pbdma_intr_0_r(i), 0xFFFFFFFF);
381 gk20a_writel(g, pbdma_intr_en_0_r(i),
382 ~pbdma_intr_en_0_lbreq_enabled_f());
383 gk20a_writel(g, pbdma_intr_1_r(i), 0xFFFFFFFF);
384 gk20a_writel(g, pbdma_intr_en_1_r(i),
385 ~pbdma_intr_en_0_lbreq_enabled_f());
388 /* TBD: apply overrides */
392 /* reset runlist interrupts */
393 gk20a_writel(g, fifo_intr_runlist_r(), ~0);
395 /* TBD: do we need those? */
396 timeout = gk20a_readl(g, fifo_fb_timeout_r());
397 timeout = set_field(timeout, fifo_fb_timeout_period_m(),
398 fifo_fb_timeout_period_max_f());
399 gk20a_writel(g, fifo_fb_timeout_r(), timeout);
401 for (i = 0; i < pbdma_timeout__size_1_v(); i++) {
402 timeout = gk20a_readl(g, pbdma_timeout_r(i));
403 timeout = set_field(timeout, pbdma_timeout_period_m(),
404 pbdma_timeout_period_max_f());
405 gk20a_writel(g, pbdma_timeout_r(i), timeout);
408 if (g->ops.fifo.apply_pb_timeout)
409 g->ops.fifo.apply_pb_timeout(g);
411 timeout = GRFIFO_TIMEOUT_CHECK_PERIOD_US |
412 fifo_eng_timeout_detection_enabled_f();
413 gk20a_writel(g, fifo_eng_timeout_r(), timeout);
415 gk20a_dbg_fn("done");
420 static void gk20a_init_fifo_pbdma_intr_descs(struct fifo_gk20a *f)
422 /* These are all errors which indicate something really wrong
423 * going on in the device. */
424 f->intr.pbdma.device_fatal_0 =
425 pbdma_intr_0_memreq_pending_f() |
426 pbdma_intr_0_memack_timeout_pending_f() |
427 pbdma_intr_0_memack_extra_pending_f() |
428 pbdma_intr_0_memdat_timeout_pending_f() |
429 pbdma_intr_0_memdat_extra_pending_f() |
430 pbdma_intr_0_memflush_pending_f() |
431 pbdma_intr_0_memop_pending_f() |
432 pbdma_intr_0_lbconnect_pending_f() |
433 pbdma_intr_0_lback_timeout_pending_f() |
434 pbdma_intr_0_lback_extra_pending_f() |
435 pbdma_intr_0_lbdat_timeout_pending_f() |
436 pbdma_intr_0_lbdat_extra_pending_f() |
437 pbdma_intr_0_xbarconnect_pending_f() |
438 pbdma_intr_0_pri_pending_f();
440 /* These are data parsing, framing errors or others which can be
441 * recovered from with intervention... or just resetting the
443 f->intr.pbdma.channel_fatal_0 =
444 pbdma_intr_0_gpfifo_pending_f() |
445 pbdma_intr_0_gpptr_pending_f() |
446 pbdma_intr_0_gpentry_pending_f() |
447 pbdma_intr_0_gpcrc_pending_f() |
448 pbdma_intr_0_pbptr_pending_f() |
449 pbdma_intr_0_pbentry_pending_f() |
450 pbdma_intr_0_pbcrc_pending_f() |
451 pbdma_intr_0_method_pending_f() |
452 pbdma_intr_0_methodcrc_pending_f() |
453 pbdma_intr_0_pbseg_pending_f() |
454 pbdma_intr_0_signature_pending_f();
456 /* Can be used for sw-methods, or represents
457 * a recoverable timeout. */
458 f->intr.pbdma.restartable_0 =
459 pbdma_intr_0_device_pending_f() |
460 pbdma_intr_0_acquire_pending_f();
463 static int gk20a_init_fifo_setup_sw(struct gk20a *g)
465 struct fifo_gk20a *f = &g->fifo;
466 struct device *d = dev_from_gk20a(g);
467 int chid, i, err = 0;
472 gk20a_dbg_fn("skip init");
478 mutex_init(&f->intr.isr.mutex);
479 mutex_init(&f->gr_reset_mutex);
480 gk20a_init_fifo_pbdma_intr_descs(f); /* just filling in data/tables */
482 f->num_channels = g->ops.fifo.get_num_fifos(g);
483 f->num_pbdma = proj_host_num_pbdma_v();
484 f->max_engines = ENGINE_INVAL_GK20A;
486 f->userd_entry_size = 1 << ram_userd_base_shift_v();
488 err = gk20a_gmmu_alloc_map(&g->mm.bar1.vm,
489 f->userd_entry_size * f->num_channels,
492 dev_err(d, "memory allocation failed\n");
496 gk20a_dbg(gpu_dbg_map, "userd bar1 va = 0x%llx", f->userd.gpu_va);
498 f->channel = kzalloc(f->num_channels * sizeof(*f->channel),
500 f->tsg = kzalloc(f->num_channels * sizeof(*f->tsg),
502 f->pbdma_map = kzalloc(f->num_pbdma * sizeof(*f->pbdma_map),
504 f->engine_info = kzalloc(f->max_engines * sizeof(*f->engine_info),
507 if (!(f->channel && f->pbdma_map && f->engine_info)) {
512 /* pbdma map needs to be in place before calling engine info init */
513 for (i = 0; i < f->num_pbdma; ++i)
514 f->pbdma_map[i] = gk20a_readl(g, fifo_pbdma_map_r(i));
520 INIT_LIST_HEAD(&f->free_chs);
521 mutex_init(&f->free_chs_mutex);
523 for (chid = 0; chid < f->num_channels; chid++) {
524 f->channel[chid].userd_cpu_va =
525 f->userd.cpu_va + chid * f->userd_entry_size;
526 f->channel[chid].userd_iova =
527 g->ops.mm.get_iova_addr(g, f->userd.sgt->sgl, 0)
528 + chid * f->userd_entry_size;
529 f->channel[chid].userd_gpu_va =
530 f->userd.gpu_va + chid * f->userd_entry_size;
532 gk20a_init_channel_support(g, chid);
533 gk20a_init_tsg_support(g, chid);
535 mutex_init(&f->tsg_inuse_mutex);
537 f->remove_support = gk20a_remove_fifo_support;
539 f->deferred_reset_pending = false;
540 mutex_init(&f->deferred_reset_mutex);
544 gk20a_dbg_fn("done");
548 gk20a_dbg_fn("fail");
549 gk20a_gmmu_unmap_free(&g->mm.bar1.vm, &f->userd);
555 kfree(f->engine_info);
556 f->engine_info = NULL;
561 static void gk20a_fifo_handle_runlist_event(struct gk20a *g)
563 u32 runlist_event = gk20a_readl(g, fifo_intr_runlist_r());
565 gk20a_dbg(gpu_dbg_intr, "runlist event %08x\n",
568 gk20a_writel(g, fifo_intr_runlist_r(), runlist_event);
571 static int gk20a_init_fifo_setup_hw(struct gk20a *g)
573 struct fifo_gk20a *f = &g->fifo;
577 /* test write, read through bar1 @ userd region before
578 * turning on the snooping */
580 struct fifo_gk20a *f = &g->fifo;
581 u32 v, v1 = 0x33, v2 = 0x55;
583 u32 bar1_vaddr = f->userd.gpu_va;
584 volatile u32 *cpu_vaddr = f->userd.cpu_va;
586 gk20a_dbg_info("test bar1 @ vaddr 0x%x",
589 v = gk20a_bar1_readl(g, bar1_vaddr);
594 if (v1 != gk20a_bar1_readl(g, bar1_vaddr)) {
595 gk20a_err(dev_from_gk20a(g), "bar1 broken @ gk20a: CPU wrote 0x%x, \
596 GPU read 0x%x", *cpu_vaddr, gk20a_bar1_readl(g, bar1_vaddr));
600 gk20a_bar1_writel(g, bar1_vaddr, v2);
602 if (v2 != gk20a_bar1_readl(g, bar1_vaddr)) {
603 gk20a_err(dev_from_gk20a(g), "bar1 broken @ gk20a: GPU wrote 0x%x, \
604 CPU read 0x%x", gk20a_bar1_readl(g, bar1_vaddr), *cpu_vaddr);
608 /* is it visible to the cpu? */
609 if (*cpu_vaddr != v2) {
610 gk20a_err(dev_from_gk20a(g),
611 "cpu didn't see bar1 write @ %p!",
616 gk20a_bar1_writel(g, bar1_vaddr, v);
619 /*XXX all manner of flushes and caching worries, etc */
621 /* set the base for the userd region now */
622 gk20a_writel(g, fifo_bar1_base_r(),
623 fifo_bar1_base_ptr_f(f->userd.gpu_va >> 12) |
624 fifo_bar1_base_valid_true_f());
626 gk20a_dbg_fn("done");
631 int gk20a_init_fifo_support(struct gk20a *g)
635 err = gk20a_init_fifo_setup_sw(g);
639 err = gk20a_init_fifo_setup_hw(g);
646 /* return with a reference to the channel, caller must put it back */
647 static struct channel_gk20a *
648 channel_from_inst_ptr(struct fifo_gk20a *f, u64 inst_ptr)
651 if (unlikely(!f->channel))
653 for (ci = 0; ci < f->num_channels; ci++) {
654 struct channel_gk20a *ch = gk20a_channel_get(&f->channel[ci]);
655 /* only alive channels are searched */
659 if (ch->inst_block.cpu_va &&
660 (inst_ptr == gk20a_mem_phys(&ch->inst_block)))
663 gk20a_channel_put(ch);
668 /* fault info/descriptions.
671 static const char * const fault_type_descs[] = {
672 "pde", /*fifo_intr_mmu_fault_info_type_pde_v() == 0 */
683 "compression failure",
689 /* engine descriptions */
690 static const char * const engine_subid_descs[] = {
695 static const char * const hub_client_descs[] = {
696 "vip", "ce0", "ce1", "dniso", "fe", "fecs", "host", "host cpu",
697 "host cpu nb", "iso", "mmu", "mspdec", "msppp", "msvld",
698 "niso", "p2p", "pd", "perf", "pmu", "raster twod", "scc",
699 "scc nb", "sec", "ssync", "gr copy", "ce2", "xv", "mmu nb",
700 "msenc", "d falcon", "sked", "a falcon", "n/a",
703 static const char * const gpc_client_descs[] = {
704 "l1 0", "t1 0", "pe 0",
705 "l1 1", "t1 1", "pe 1",
706 "l1 2", "t1 2", "pe 2",
707 "l1 3", "t1 3", "pe 3",
708 "rast", "gcc", "gpccs",
709 "prop 0", "prop 1", "prop 2", "prop 3",
710 "l1 4", "t1 4", "pe 4",
711 "l1 5", "t1 5", "pe 5",
712 "l1 6", "t1 6", "pe 6",
713 "l1 7", "t1 7", "pe 7",
715 "ltp utlb 0", "ltp utlb 1", "ltp utlb 2", "ltp utlb 3",
719 /* reads info from hardware and fills in mmu fault info record */
720 static inline void get_exception_mmu_fault_info(
721 struct gk20a *g, u32 engine_id,
722 struct fifo_mmu_fault_info_gk20a *f)
726 gk20a_dbg_fn("engine_id %d", engine_id);
728 memset(f, 0, sizeof(*f));
730 f->fault_info_v = fault_info_v = gk20a_readl(g,
731 fifo_intr_mmu_fault_info_r(engine_id));
733 fifo_intr_mmu_fault_info_type_v(fault_info_v);
735 fifo_intr_mmu_fault_info_engine_subid_v(fault_info_v);
736 f->client_v = fifo_intr_mmu_fault_info_client_v(fault_info_v);
738 BUG_ON(f->fault_type_v >= ARRAY_SIZE(fault_type_descs));
739 f->fault_type_desc = fault_type_descs[f->fault_type_v];
741 BUG_ON(f->engine_subid_v >= ARRAY_SIZE(engine_subid_descs));
742 f->engine_subid_desc = engine_subid_descs[f->engine_subid_v];
744 if (f->engine_subid_v ==
745 fifo_intr_mmu_fault_info_engine_subid_hub_v()) {
747 BUG_ON(f->client_v >= ARRAY_SIZE(hub_client_descs));
748 f->client_desc = hub_client_descs[f->client_v];
749 } else if (f->engine_subid_v ==
750 fifo_intr_mmu_fault_info_engine_subid_gpc_v()) {
751 BUG_ON(f->client_v >= ARRAY_SIZE(gpc_client_descs));
752 f->client_desc = gpc_client_descs[f->client_v];
757 f->fault_hi_v = gk20a_readl(g, fifo_intr_mmu_fault_hi_r(engine_id));
758 f->fault_lo_v = gk20a_readl(g, fifo_intr_mmu_fault_lo_r(engine_id));
759 /* note:ignoring aperture on gk20a... */
760 f->inst_ptr = fifo_intr_mmu_fault_inst_ptr_v(
761 gk20a_readl(g, fifo_intr_mmu_fault_inst_r(engine_id)));
762 /* note: inst_ptr is a 40b phys addr. */
763 f->inst_ptr <<= fifo_intr_mmu_fault_inst_ptr_align_shift_v();
766 void gk20a_fifo_reset_engine(struct gk20a *g, u32 engine_id)
770 if (engine_id == top_device_info_type_enum_graphics_v()) {
771 if (support_gk20a_pmu(g->dev) && g->elpg_enabled)
772 gk20a_pmu_disable_elpg(g);
773 /*HALT_PIPELINE method, halt GR engine*/
774 if (gr_gk20a_halt_pipe(g))
775 gk20a_err(dev_from_gk20a(g),
776 "failed to HALT gr pipe");
777 /* resetting engine using mc_enable_r() is not
778 enough, we do full init sequence */
780 gk20a_pmu_enable_elpg(g);
782 if (engine_id == top_device_info_type_enum_copy0_v())
783 gk20a_reset(g, mc_enable_ce2_m());
786 static void gk20a_fifo_handle_chsw_fault(struct gk20a *g)
790 intr = gk20a_readl(g, fifo_intr_chsw_error_r());
791 gk20a_err(dev_from_gk20a(g), "chsw: %08x\n", intr);
792 gk20a_fecs_dump_falcon_stats(g);
793 gk20a_writel(g, fifo_intr_chsw_error_r(), intr);
796 static void gk20a_fifo_handle_dropped_mmu_fault(struct gk20a *g)
798 struct device *dev = dev_from_gk20a(g);
799 u32 fault_id = gk20a_readl(g, fifo_intr_mmu_fault_id_r());
800 gk20a_err(dev, "dropped mmu fault (0x%08x)", fault_id);
803 static bool gk20a_fifo_should_defer_engine_reset(struct gk20a *g, u32 engine_id,
804 struct fifo_mmu_fault_info_gk20a *f, bool fake_fault)
806 /* channel recovery is only deferred if an sm debugger
807 is attached and has MMU debug mode is enabled */
808 if (!gk20a_gr_sm_debugger_attached(g) ||
809 !g->ops.mm.is_debug_mode_enabled(g))
812 /* if this fault is fake (due to RC recovery), don't defer recovery */
816 if (engine_id != ENGINE_GR_GK20A ||
817 f->engine_subid_v != fifo_intr_mmu_fault_info_engine_subid_gpc_v())
823 /* caller must hold a channel reference */
824 static bool gk20a_fifo_set_ctx_mmu_error(struct gk20a *g,
825 struct channel_gk20a *ch)
831 if (ch->error_notifier) {
832 u32 err = ch->error_notifier->info32;
833 if (ch->error_notifier->status == 0xffff) {
834 /* If error code is already set, this mmu fault
835 * was triggered as part of recovery from other
837 * Don't overwrite error flag. */
838 /* Fifo timeout debug spew is controlled by user */
839 if (err == NVGPU_CHANNEL_FIFO_ERROR_IDLE_TIMEOUT)
840 verbose = ch->timeout_debug_dump;
842 gk20a_set_error_notifier(ch,
843 NVGPU_CHANNEL_FIFO_ERROR_MMU_ERR_FLT);
846 /* mark channel as faulted */
847 ch->has_timedout = true;
849 /* unblock pending waits */
850 wake_up(&ch->semaphore_wq);
851 wake_up(&ch->notifier_wq);
852 wake_up(&ch->submit_wq);
856 static bool gk20a_fifo_set_ctx_mmu_error_ch(struct gk20a *g,
857 struct channel_gk20a *ch)
859 gk20a_err(dev_from_gk20a(g),
860 "channel %d generated a mmu fault", ch->hw_chid);
862 return gk20a_fifo_set_ctx_mmu_error(g, ch);
865 static bool gk20a_fifo_set_ctx_mmu_error_tsg(struct gk20a *g,
866 struct tsg_gk20a *tsg)
869 struct channel_gk20a *ch = NULL;
871 gk20a_err(dev_from_gk20a(g),
872 "TSG %d generated a mmu fault", tsg->tsgid);
874 mutex_lock(&tsg->ch_list_lock);
875 list_for_each_entry(ch, &tsg->ch_list, ch_entry) {
876 if (gk20a_channel_get(ch)) {
877 if (!gk20a_fifo_set_ctx_mmu_error(g, ch))
879 gk20a_channel_put(ch);
882 mutex_unlock(&tsg->ch_list_lock);
887 static void gk20a_fifo_abort_tsg(struct gk20a *g, u32 tsgid)
889 struct tsg_gk20a *tsg = &g->fifo.tsg[tsgid];
890 struct channel_gk20a *ch;
892 mutex_lock(&tsg->ch_list_lock);
893 list_for_each_entry(ch, &tsg->ch_list, ch_entry) {
894 if (gk20a_channel_get(ch)) {
895 gk20a_channel_abort(ch, false);
896 gk20a_channel_put(ch);
899 mutex_unlock(&tsg->ch_list_lock);
902 static bool gk20a_fifo_handle_mmu_fault(
904 u32 mmu_fault_engines, /* queried from HW if 0 */
905 u32 hw_id, /* queried from HW if ~(u32)0 OR mmu_fault_engines == 0*/
909 unsigned long fault_id;
910 unsigned long engine_mmu_id;
916 g->fifo.deferred_reset_pending = false;
918 /* Disable power management */
919 if (support_gk20a_pmu(g->dev) && g->elpg_enabled)
920 gk20a_pmu_disable_elpg(g);
921 g->ops.clock_gating.slcg_gr_load_gating_prod(g,
923 g->ops.clock_gating.slcg_perf_load_gating_prod(g,
925 g->ops.clock_gating.slcg_ltc_load_gating_prod(g,
927 gr_gk20a_init_elcg_mode(g, ELCG_RUN, ENGINE_GR_GK20A);
928 gr_gk20a_init_elcg_mode(g, ELCG_RUN, ENGINE_CE2_GK20A);
930 /* Disable fifo access */
931 grfifo_ctl = gk20a_readl(g, gr_gpfifo_ctl_r());
932 grfifo_ctl &= ~gr_gpfifo_ctl_semaphore_access_f(1);
933 grfifo_ctl &= ~gr_gpfifo_ctl_access_f(1);
935 gk20a_writel(g, gr_gpfifo_ctl_r(),
936 grfifo_ctl | gr_gpfifo_ctl_access_f(0) |
937 gr_gpfifo_ctl_semaphore_access_f(0));
939 if (mmu_fault_engines) {
940 fault_id = mmu_fault_engines;
943 fault_id = gk20a_readl(g, fifo_intr_mmu_fault_id_r());
945 gk20a_debug_dump(g->dev);
949 /* go through all faulted engines */
950 for_each_set_bit(engine_mmu_id, &fault_id, 32) {
951 /* bits in fifo_intr_mmu_fault_id_r do not correspond 1:1 to
952 * engines. Convert engine_mmu_id to engine_id */
953 u32 engine_id = gk20a_mmu_id_to_engine_id(engine_mmu_id);
954 struct fifo_mmu_fault_info_gk20a f;
955 struct channel_gk20a *ch = NULL;
956 struct tsg_gk20a *tsg = NULL;
957 struct channel_gk20a *referenced_channel = NULL;
959 /* read and parse engine status */
960 u32 status = gk20a_readl(g, fifo_engine_status_r(engine_id));
961 u32 ctx_status = fifo_engine_status_ctx_status_v(status);
962 bool ctxsw = (ctx_status ==
963 fifo_engine_status_ctx_status_ctxsw_switch_v()
965 fifo_engine_status_ctx_status_ctxsw_save_v()
967 fifo_engine_status_ctx_status_ctxsw_load_v());
969 get_exception_mmu_fault_info(g, engine_mmu_id, &f);
970 trace_gk20a_mmu_fault(f.fault_hi_v,
978 gk20a_err(dev_from_gk20a(g), "mmu fault on engine %d, "
979 "engine subid %d (%s), client %d (%s), "
980 "addr 0x%08x:0x%08x, type %d (%s), info 0x%08x,"
983 f.engine_subid_v, f.engine_subid_desc,
984 f.client_v, f.client_desc,
985 f.fault_hi_v, f.fault_lo_v,
986 f.fault_type_v, f.fault_type_desc,
987 f.fault_info_v, f.inst_ptr);
990 gk20a_fecs_dump_falcon_stats(g);
991 gk20a_err(dev_from_gk20a(g), "gr_status_r : 0x%x",
992 gk20a_readl(g, gr_status_r()));
995 /* get the channel/TSG */
997 /* use next_id if context load is failing */
1000 if (hw_id == ~(u32)0) {
1002 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1003 fifo_engine_status_next_id_v(status) :
1004 fifo_engine_status_id_v(status);
1005 type = (ctx_status ==
1006 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1007 fifo_engine_status_next_id_type_v(status) :
1008 fifo_engine_status_id_type_v(status);
1012 fifo_engine_status_id_type_tsgid_v() :
1013 fifo_engine_status_id_type_chid_v();
1016 if (type == fifo_engine_status_id_type_tsgid_v())
1017 tsg = &g->fifo.tsg[id];
1018 else if (type == fifo_engine_status_id_type_chid_v()) {
1019 ch = &g->fifo.channel[id];
1020 referenced_channel = gk20a_channel_get(ch);
1023 /* read channel based on instruction pointer */
1024 ch = channel_from_inst_ptr(&g->fifo, f.inst_ptr);
1025 referenced_channel = ch;
1028 if (ch && gk20a_is_channel_marked_as_tsg(ch))
1029 tsg = &g->fifo.tsg[ch->tsgid];
1031 /* check if engine reset should be deferred */
1032 if ((ch || tsg) && gk20a_fifo_should_defer_engine_reset(g,
1033 engine_id, &f, fake_fault)) {
1034 g->fifo.deferred_fault_engines = fault_id;
1036 /* handled during channel free */
1037 g->fifo.deferred_reset_pending = true;
1038 } else if (engine_id != ~0) {
1039 was_reset = mutex_is_locked(&g->fifo.gr_reset_mutex);
1040 mutex_lock(&g->fifo.gr_reset_mutex);
1041 /* if lock is already taken, a reset is taking place
1042 so no need to repeat */
1044 gk20a_fifo_reset_engine(g, engine_id);
1045 mutex_unlock(&g->fifo.gr_reset_mutex);
1047 /* disable the channel/TSG from hw and increment
1051 if (!g->fifo.deferred_reset_pending)
1053 gk20a_fifo_set_ctx_mmu_error_tsg(g, tsg);
1055 gk20a_fifo_abort_tsg(g, tsg->tsgid);
1057 /* put back the ref taken early above */
1058 if (referenced_channel)
1059 gk20a_channel_put(ch);
1061 if (referenced_channel) {
1062 if (!g->fifo.deferred_reset_pending)
1063 verbose = gk20a_fifo_set_ctx_mmu_error_ch(g, ch);
1064 gk20a_channel_abort(ch, false);
1065 gk20a_channel_put(ch);
1067 gk20a_err(dev_from_gk20a(g),
1068 "mmu error in freed channel %d",
1071 } else if (f.inst_ptr ==
1072 gk20a_mem_phys(&g->mm.bar1.inst_block)) {
1073 gk20a_err(dev_from_gk20a(g), "mmu fault from bar1");
1074 } else if (f.inst_ptr ==
1075 gk20a_mem_phys(&g->mm.pmu.inst_block)) {
1076 gk20a_err(dev_from_gk20a(g), "mmu fault from pmu");
1078 gk20a_err(dev_from_gk20a(g), "couldn't locate channel for mmu fault");
1081 if (g->fifo.deferred_reset_pending) {
1082 gk20a_dbg(gpu_dbg_intr | gpu_dbg_gpu_dbg, "sm debugger attached,"
1083 " deferring channel recovery to channel free");
1084 /* clear interrupt */
1085 gk20a_writel(g, fifo_intr_mmu_fault_id_r(), fault_id);
1089 /* clear interrupt */
1090 gk20a_writel(g, fifo_intr_mmu_fault_id_r(), fault_id);
1092 /* resume scheduler */
1093 gk20a_writel(g, fifo_error_sched_disable_r(),
1094 gk20a_readl(g, fifo_error_sched_disable_r()));
1096 /* Re-enable fifo access */
1097 gk20a_writel(g, gr_gpfifo_ctl_r(),
1098 gr_gpfifo_ctl_access_enabled_f() |
1099 gr_gpfifo_ctl_semaphore_access_enabled_f());
1102 /* It is safe to enable ELPG again. */
1103 if (support_gk20a_pmu(g->dev) && g->elpg_enabled)
1104 gk20a_pmu_enable_elpg(g);
1108 static void gk20a_fifo_get_faulty_id_type(struct gk20a *g, int engine_id,
1111 u32 status = gk20a_readl(g, fifo_engine_status_r(engine_id));
1112 u32 ctx_status = fifo_engine_status_ctx_status_v(status);
1114 /* use next_id if context load is failing */
1115 *id = (ctx_status ==
1116 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1117 fifo_engine_status_next_id_v(status) :
1118 fifo_engine_status_id_v(status);
1120 *type = (ctx_status ==
1121 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1122 fifo_engine_status_next_id_type_v(status) :
1123 fifo_engine_status_id_type_v(status);
1126 static void gk20a_fifo_trigger_mmu_fault(struct gk20a *g,
1127 unsigned long engine_ids)
1129 unsigned long end_jiffies = jiffies +
1130 msecs_to_jiffies(gk20a_get_gr_idle_timeout(g));
1131 unsigned long delay = GR_IDLE_CHECK_DEFAULT;
1132 unsigned long engine_id;
1135 /* trigger faults for all bad engines */
1136 for_each_set_bit(engine_id, &engine_ids, 32) {
1137 if (engine_id > g->fifo.max_engines) {
1142 gk20a_writel(g, fifo_trigger_mmu_fault_r(engine_id),
1143 fifo_trigger_mmu_fault_id_f(
1144 gk20a_engine_id_to_mmu_id(engine_id)) |
1145 fifo_trigger_mmu_fault_enable_f(1));
1148 /* Wait for MMU fault to trigger */
1151 if (gk20a_readl(g, fifo_intr_0_r()) &
1152 fifo_intr_0_mmu_fault_pending_f()) {
1157 usleep_range(delay, delay * 2);
1158 delay = min_t(u32, delay << 1, GR_IDLE_CHECK_MAX);
1159 } while (time_before(jiffies, end_jiffies) ||
1160 !tegra_platform_is_silicon());
1163 gk20a_err(dev_from_gk20a(g), "mmu fault timeout");
1165 /* release mmu fault trigger */
1166 for_each_set_bit(engine_id, &engine_ids, 32)
1167 gk20a_writel(g, fifo_trigger_mmu_fault_r(engine_id), 0);
1170 static u32 gk20a_fifo_engines_on_id(struct gk20a *g, u32 id, bool is_tsg)
1175 for (i = 0; i < g->fifo.max_engines; i++) {
1176 u32 status = gk20a_readl(g, fifo_engine_status_r(i));
1178 fifo_engine_status_ctx_status_v(status);
1179 u32 ctx_id = (ctx_status ==
1180 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1181 fifo_engine_status_next_id_v(status) :
1182 fifo_engine_status_id_v(status);
1183 u32 type = (ctx_status ==
1184 fifo_engine_status_ctx_status_ctxsw_load_v()) ?
1185 fifo_engine_status_next_id_type_v(status) :
1186 fifo_engine_status_id_type_v(status);
1187 bool busy = fifo_engine_status_engine_v(status) ==
1188 fifo_engine_status_engine_busy_v();
1189 if (busy && ctx_id == id) {
1190 if ((is_tsg && type ==
1191 fifo_engine_status_id_type_tsgid_v()) ||
1193 fifo_engine_status_id_type_chid_v()))
1201 void gk20a_fifo_recover_ch(struct gk20a *g, u32 hw_chid, bool verbose)
1205 /* stop context switching to prevent engine assignments from
1206 changing until channel is recovered */
1207 mutex_lock(&g->dbg_sessions_lock);
1208 gr_gk20a_disable_ctxsw(g);
1210 engines = gk20a_fifo_engines_on_id(g, hw_chid, false);
1213 gk20a_fifo_recover(g, engines, hw_chid, false, true, verbose);
1215 struct channel_gk20a *ch = &g->fifo.channel[hw_chid];
1217 if (gk20a_channel_get(ch)) {
1218 gk20a_channel_abort(ch, false);
1220 if (gk20a_fifo_set_ctx_mmu_error_ch(g, ch))
1221 gk20a_debug_dump(g->dev);
1223 gk20a_channel_put(ch);
1227 gr_gk20a_enable_ctxsw(g);
1228 mutex_unlock(&g->dbg_sessions_lock);
1231 void gk20a_fifo_recover_tsg(struct gk20a *g, u32 tsgid, bool verbose)
1235 /* stop context switching to prevent engine assignments from
1236 changing until TSG is recovered */
1237 mutex_lock(&g->dbg_sessions_lock);
1238 gr_gk20a_disable_ctxsw(g);
1240 engines = gk20a_fifo_engines_on_id(g, tsgid, true);
1243 gk20a_fifo_recover(g, engines, tsgid, true, true, verbose);
1245 struct tsg_gk20a *tsg = &g->fifo.tsg[tsgid];
1247 if (gk20a_fifo_set_ctx_mmu_error_tsg(g, tsg))
1248 gk20a_debug_dump(g->dev);
1250 gk20a_fifo_abort_tsg(g, tsgid);
1253 gr_gk20a_enable_ctxsw(g);
1254 mutex_unlock(&g->dbg_sessions_lock);
1257 void gk20a_fifo_recover(struct gk20a *g, u32 __engine_ids,
1258 u32 hw_id, bool id_is_tsg,
1259 bool id_is_known, bool verbose)
1261 unsigned long engine_id, i;
1262 unsigned long _engine_ids = __engine_ids;
1263 unsigned long engine_ids = 0;
1265 u32 mmu_fault_engines = 0;
1268 u32 ref_id_is_tsg = false;
1271 gk20a_debug_dump(g->dev);
1273 if (g->ops.ltc.flush)
1274 g->ops.ltc.flush(g);
1277 engine_ids = gk20a_fifo_engines_on_id(g, hw_id, id_is_tsg);
1279 ref_type = id_is_tsg ?
1280 fifo_engine_status_id_type_tsgid_v() :
1281 fifo_engine_status_id_type_chid_v();
1282 ref_id_is_tsg = id_is_tsg;
1283 /* atleast one engine will get passed during sched err*/
1284 engine_ids |= __engine_ids;
1285 for_each_set_bit(engine_id, &engine_ids, 32) {
1286 mmu_fault_engines |=
1287 BIT(gk20a_engine_id_to_mmu_id(engine_id));
1290 /* store faulted engines in advance */
1291 for_each_set_bit(engine_id, &_engine_ids, 32) {
1292 gk20a_fifo_get_faulty_id_type(g, engine_id, &ref_id,
1294 if (ref_type == fifo_engine_status_id_type_tsgid_v())
1295 ref_id_is_tsg = true;
1297 ref_id_is_tsg = false;
1298 /* Reset *all* engines that use the
1299 * same channel as faulty engine */
1300 for (i = 0; i < g->fifo.max_engines; i++) {
1303 gk20a_fifo_get_faulty_id_type(g, i, &id, &type);
1304 if (ref_type == type && ref_id == id) {
1305 engine_ids |= BIT(i);
1306 mmu_fault_engines |=
1307 BIT(gk20a_engine_id_to_mmu_id(i));
1313 if (mmu_fault_engines) {
1315 * sched error prevents recovery, and ctxsw error will retrigger
1316 * every 100ms. Disable the sched error to allow recovery.
1318 val = gk20a_readl(g, fifo_intr_en_0_r());
1319 val &= ~(fifo_intr_en_0_sched_error_m() |
1320 fifo_intr_en_0_mmu_fault_m());
1321 gk20a_writel(g, fifo_intr_en_0_r(), val);
1322 gk20a_writel(g, fifo_intr_0_r(),
1323 fifo_intr_0_sched_error_reset_f());
1325 g->ops.fifo.trigger_mmu_fault(g, engine_ids);
1326 gk20a_fifo_handle_mmu_fault(g, mmu_fault_engines, ref_id,
1329 val = gk20a_readl(g, fifo_intr_en_0_r());
1330 val |= fifo_intr_en_0_mmu_fault_f(1)
1331 | fifo_intr_en_0_sched_error_f(1);
1332 gk20a_writel(g, fifo_intr_en_0_r(), val);
1336 /* force reset channel and tsg (if it's part of one) */
1337 int gk20a_fifo_force_reset_ch(struct channel_gk20a *ch, bool verbose)
1339 struct tsg_gk20a *tsg = NULL;
1340 struct channel_gk20a *ch_tsg = NULL;
1341 struct gk20a *g = ch->g;
1343 if (gk20a_is_channel_marked_as_tsg(ch)) {
1344 tsg = &g->fifo.tsg[ch->hw_chid];
1346 mutex_lock(&tsg->ch_list_lock);
1348 list_for_each_entry(ch_tsg, &tsg->ch_list, ch_entry) {
1349 if (gk20a_channel_get(ch_tsg)) {
1350 gk20a_set_error_notifier(ch_tsg,
1351 NVGPU_CHANNEL_RESETCHANNEL_VERIF_ERROR);
1352 gk20a_channel_put(ch_tsg);
1356 mutex_unlock(&tsg->ch_list_lock);
1357 gk20a_fifo_recover_tsg(g, ch->tsgid, verbose);
1359 gk20a_set_error_notifier(ch,
1360 NVGPU_CHANNEL_RESETCHANNEL_VERIF_ERROR);
1361 gk20a_fifo_recover_ch(g, ch->hw_chid, verbose);
1367 static bool gk20a_fifo_handle_sched_error(struct gk20a *g)
1372 bool non_chid = false;
1375 /* read the scheduler error register */
1376 sched_error = gk20a_readl(g, fifo_intr_sched_error_r());
1378 for (engine_id = 0; engine_id < g->fifo.max_engines; engine_id++) {
1379 u32 status = gk20a_readl(g, fifo_engine_status_r(engine_id));
1380 u32 ctx_status = fifo_engine_status_ctx_status_v(status);
1381 bool failing_engine;
1383 /* we are interested in busy engines */
1384 failing_engine = fifo_engine_status_engine_v(status) ==
1385 fifo_engine_status_engine_busy_v();
1387 /* ..that are doing context switch */
1388 failing_engine = failing_engine &&
1390 fifo_engine_status_ctx_status_ctxsw_switch_v()
1392 fifo_engine_status_ctx_status_ctxsw_save_v()
1394 fifo_engine_status_ctx_status_ctxsw_load_v());
1396 if (!failing_engine)
1399 fifo_engine_status_ctx_status_ctxsw_load_v()) {
1400 id = fifo_engine_status_next_id_v(status);
1401 non_chid = fifo_pbdma_status_id_type_v(status)
1402 != fifo_pbdma_status_id_type_chid_v();
1403 } else if (ctx_status ==
1404 fifo_engine_status_ctx_status_ctxsw_switch_v()) {
1405 mailbox2 = gk20a_readl(g, gr_fecs_ctxsw_mailbox_r(2));
1406 if (mailbox2 & FECS_METHOD_WFI_RESTORE)
1407 id = fifo_engine_status_next_id_v(status);
1409 id = fifo_engine_status_id_v(status);
1411 id = fifo_engine_status_id_v(status);
1416 /* could not find the engine - should never happen */
1417 if (unlikely(engine_id >= g->fifo.max_engines)) {
1418 gk20a_err(dev_from_gk20a(g), "fifo sched error : 0x%08x, failed to find engine\n",
1424 if (fifo_intr_sched_error_code_f(sched_error) ==
1425 fifo_intr_sched_error_code_ctxsw_timeout_v()) {
1426 struct fifo_gk20a *f = &g->fifo;
1427 struct channel_gk20a *ch = &f->channel[id];
1430 gk20a_fifo_recover(g, BIT(engine_id), id, true,
1436 if (!gk20a_channel_get(ch))
1439 if (gk20a_channel_update_and_check_timeout(ch,
1440 GRFIFO_TIMEOUT_CHECK_PERIOD_US / 1000)) {
1441 gk20a_set_error_notifier(ch,
1442 NVGPU_CHANNEL_FIFO_ERROR_IDLE_TIMEOUT);
1443 gk20a_err(dev_from_gk20a(g),
1444 "fifo sched ctxsw timeout error:"
1445 "engine = %u, ch = %d", engine_id, id);
1446 gk20a_gr_debug_dump(g->dev);
1447 gk20a_fifo_recover(g, BIT(engine_id), id, false,
1448 true, ch->timeout_debug_dump);
1452 "fifo is waiting for ctx switch for %d ms,"
1454 ch->timeout_accumulated_ms,
1458 gk20a_channel_put(ch);
1462 gk20a_err(dev_from_gk20a(g), "fifo sched error : 0x%08x, engine=%u, %s=%d",
1463 sched_error, engine_id, non_chid ? "non-ch" : "ch", id);
1469 static u32 fifo_error_isr(struct gk20a *g, u32 fifo_intr)
1471 bool print_channel_reset_log = false;
1472 struct device *dev = dev_from_gk20a(g);
1477 if (fifo_intr & fifo_intr_0_pio_error_pending_f()) {
1478 /* pio mode is unused. this shouldn't happen, ever. */
1479 /* should we clear it or just leave it pending? */
1480 gk20a_err(dev, "fifo pio error!\n");
1484 if (fifo_intr & fifo_intr_0_bind_error_pending_f()) {
1485 u32 bind_error = gk20a_readl(g, fifo_intr_bind_error_r());
1486 gk20a_err(dev, "fifo bind error: 0x%08x", bind_error);
1487 print_channel_reset_log = true;
1488 handled |= fifo_intr_0_bind_error_pending_f();
1491 if (fifo_intr & fifo_intr_0_sched_error_pending_f()) {
1492 print_channel_reset_log = gk20a_fifo_handle_sched_error(g);
1493 handled |= fifo_intr_0_sched_error_pending_f();
1496 if (fifo_intr & fifo_intr_0_chsw_error_pending_f()) {
1497 gk20a_fifo_handle_chsw_fault(g);
1498 handled |= fifo_intr_0_chsw_error_pending_f();
1501 if (fifo_intr & fifo_intr_0_mmu_fault_pending_f()) {
1502 print_channel_reset_log =
1503 gk20a_fifo_handle_mmu_fault(g, 0, ~(u32)0, false);
1504 handled |= fifo_intr_0_mmu_fault_pending_f();
1507 if (fifo_intr & fifo_intr_0_dropped_mmu_fault_pending_f()) {
1508 gk20a_fifo_handle_dropped_mmu_fault(g);
1509 handled |= fifo_intr_0_dropped_mmu_fault_pending_f();
1512 print_channel_reset_log = !g->fifo.deferred_reset_pending
1513 && print_channel_reset_log;
1515 if (print_channel_reset_log) {
1517 gk20a_err(dev_from_gk20a(g),
1518 "channel reset initiated from %s; intr=0x%08x",
1519 __func__, fifo_intr);
1521 engine_id < g->fifo.max_engines;
1523 gk20a_dbg_fn("enum:%d -> engine_id:%d", engine_id,
1524 g->fifo.engine_info[engine_id].engine_id);
1525 fifo_pbdma_exception_status(g,
1526 &g->fifo.engine_info[engine_id]);
1527 fifo_engine_exception_status(g,
1528 &g->fifo.engine_info[engine_id]);
1535 static inline void gk20a_fifo_reset_pbdma_header(struct gk20a *g, int pbdma_id)
1537 gk20a_writel(g, pbdma_pb_header_r(pbdma_id),
1538 pbdma_pb_header_first_true_f() |
1539 pbdma_pb_header_type_non_inc_f());
1542 static inline void gk20a_fifo_reset_pbdma_method(struct gk20a *g, int pbdma_id,
1543 int pbdma_method_index)
1545 u32 pbdma_method_stride;
1546 u32 pbdma_method_reg;
1548 pbdma_method_stride = pbdma_method1_r(pbdma_id) -
1549 pbdma_method0_r(pbdma_id);
1551 pbdma_method_reg = pbdma_method0_r(pbdma_id) +
1552 (pbdma_method_index * pbdma_method_stride);
1554 gk20a_writel(g, pbdma_method_reg,
1555 pbdma_method0_valid_true_f() |
1556 pbdma_method0_first_true_f() |
1557 pbdma_method0_addr_f(
1558 pbdma_udma_nop_r() >> 2));
1561 static bool gk20a_fifo_is_sw_method_subch(struct gk20a *g, int pbdma_id,
1562 int pbdma_method_index)
1564 u32 pbdma_method_stride;
1565 u32 pbdma_method_reg, pbdma_method_subch;
1567 pbdma_method_stride = pbdma_method1_r(pbdma_id) -
1568 pbdma_method0_r(pbdma_id);
1570 pbdma_method_reg = pbdma_method0_r(pbdma_id) +
1571 (pbdma_method_index * pbdma_method_stride);
1573 pbdma_method_subch = pbdma_method0_subch_v(
1574 gk20a_readl(g, pbdma_method_reg));
1576 if (pbdma_method_subch == 5 || pbdma_method_subch == 6 ||
1577 pbdma_method_subch == 7)
1583 static u32 gk20a_fifo_handle_pbdma_intr(struct device *dev,
1585 struct fifo_gk20a *f,
1588 u32 pbdma_intr_0 = gk20a_readl(g, pbdma_intr_0_r(pbdma_id));
1589 u32 pbdma_intr_1 = gk20a_readl(g, pbdma_intr_1_r(pbdma_id));
1596 gk20a_dbg(gpu_dbg_intr, "pbdma id intr pending %d %08x %08x", pbdma_id,
1597 pbdma_intr_0, pbdma_intr_1);
1599 if ((f->intr.pbdma.device_fatal_0 |
1600 f->intr.pbdma.channel_fatal_0 |
1601 f->intr.pbdma.restartable_0) & pbdma_intr_0) {
1602 gk20a_err(dev_from_gk20a(g),
1603 "pbdma_intr_0(%d):0x%08x PBH: %08x SHADOW: %08x M0: %08x %08x %08x %08x",
1604 pbdma_id, pbdma_intr_0,
1605 gk20a_readl(g, pbdma_pb_header_r(pbdma_id)),
1606 gk20a_readl(g, pbdma_hdr_shadow_r(pbdma_id)),
1607 gk20a_readl(g, pbdma_method0_r(pbdma_id)),
1608 gk20a_readl(g, pbdma_method1_r(pbdma_id)),
1609 gk20a_readl(g, pbdma_method2_r(pbdma_id)),
1610 gk20a_readl(g, pbdma_method3_r(pbdma_id))
1613 handled |= ((f->intr.pbdma.device_fatal_0 |
1614 f->intr.pbdma.channel_fatal_0 |
1615 f->intr.pbdma.restartable_0) &
1619 if (pbdma_intr_0 & pbdma_intr_0_pbentry_pending_f()) {
1620 gk20a_fifo_reset_pbdma_header(g, pbdma_id);
1621 gk20a_fifo_reset_pbdma_method(g, pbdma_id, 0);
1625 if (pbdma_intr_0 & pbdma_intr_0_method_pending_f()) {
1626 gk20a_fifo_reset_pbdma_method(g, pbdma_id, 0);
1630 if (pbdma_intr_0 & pbdma_intr_0_device_pending_f()) {
1631 gk20a_fifo_reset_pbdma_header(g, pbdma_id);
1633 for (i = 0; i < 4; i++) {
1634 if (gk20a_fifo_is_sw_method_subch(g,
1636 gk20a_fifo_reset_pbdma_method(g,
1642 gk20a_writel(g, pbdma_intr_0_r(pbdma_id), pbdma_intr_0);
1645 /* all intrs in _intr_1 are "host copy engine" related,
1646 * which gk20a doesn't have. for now just make them channel fatal. */
1648 dev_err(dev, "channel hce error: pbdma_intr_1(%d): 0x%08x",
1649 pbdma_id, pbdma_intr_1);
1651 gk20a_writel(g, pbdma_intr_1_r(pbdma_id), pbdma_intr_1);
1655 /* Remove the channel from runlist */
1656 u32 status = gk20a_readl(g, fifo_pbdma_status_r(pbdma_id));
1657 u32 id = fifo_pbdma_status_id_v(status);
1658 if (fifo_pbdma_status_id_type_v(status)
1659 == fifo_pbdma_status_id_type_chid_v()) {
1660 struct channel_gk20a *ch = &f->channel[id];
1662 if (gk20a_channel_get(ch)) {
1663 gk20a_set_error_notifier(ch,
1664 NVGPU_CHANNEL_PBDMA_ERROR);
1665 gk20a_fifo_recover_ch(g, id, true);
1666 gk20a_channel_put(ch);
1668 } else if (fifo_pbdma_status_id_type_v(status)
1669 == fifo_pbdma_status_id_type_tsgid_v()) {
1670 struct tsg_gk20a *tsg = &f->tsg[id];
1671 struct channel_gk20a *ch = NULL;
1673 mutex_lock(&tsg->ch_list_lock);
1674 list_for_each_entry(ch, &tsg->ch_list, ch_entry) {
1675 if (gk20a_channel_get(ch)) {
1676 gk20a_set_error_notifier(ch,
1677 NVGPU_CHANNEL_PBDMA_ERROR);
1678 gk20a_channel_put(ch);
1681 mutex_unlock(&tsg->ch_list_lock);
1682 gk20a_fifo_recover_tsg(g, id, true);
1689 static u32 fifo_channel_isr(struct gk20a *g, u32 fifo_intr)
1691 gk20a_channel_semaphore_wakeup(g);
1692 return fifo_intr_0_channel_intr_pending_f();
1696 static u32 fifo_pbdma_isr(struct gk20a *g, u32 fifo_intr)
1698 struct device *dev = dev_from_gk20a(g);
1699 struct fifo_gk20a *f = &g->fifo;
1700 u32 clear_intr = 0, i;
1701 u32 pbdma_pending = gk20a_readl(g, fifo_intr_pbdma_id_r());
1703 for (i = 0; i < fifo_intr_pbdma_id_status__size_1_v(); i++) {
1704 if (fifo_intr_pbdma_id_status_f(pbdma_pending, i)) {
1705 gk20a_dbg(gpu_dbg_intr, "pbdma id %d intr pending", i);
1707 gk20a_fifo_handle_pbdma_intr(dev, g, f, i);
1710 return fifo_intr_0_pbdma_intr_pending_f();
1713 void gk20a_fifo_isr(struct gk20a *g)
1715 u32 error_intr_mask =
1716 fifo_intr_0_bind_error_pending_f() |
1717 fifo_intr_0_sched_error_pending_f() |
1718 fifo_intr_0_chsw_error_pending_f() |
1719 fifo_intr_0_fb_flush_timeout_pending_f() |
1720 fifo_intr_0_dropped_mmu_fault_pending_f() |
1721 fifo_intr_0_mmu_fault_pending_f() |
1722 fifo_intr_0_lb_error_pending_f() |
1723 fifo_intr_0_pio_error_pending_f();
1725 u32 fifo_intr = gk20a_readl(g, fifo_intr_0_r());
1728 if (g->fifo.sw_ready) {
1729 /* note we're not actually in an "isr", but rather
1730 * in a threaded interrupt context... */
1731 mutex_lock(&g->fifo.intr.isr.mutex);
1733 gk20a_dbg(gpu_dbg_intr, "fifo isr %08x\n", fifo_intr);
1735 /* handle runlist update */
1736 if (fifo_intr & fifo_intr_0_runlist_event_pending_f()) {
1737 gk20a_fifo_handle_runlist_event(g);
1738 clear_intr |= fifo_intr_0_runlist_event_pending_f();
1740 if (fifo_intr & fifo_intr_0_pbdma_intr_pending_f())
1741 clear_intr |= fifo_pbdma_isr(g, fifo_intr);
1743 if (unlikely(fifo_intr & error_intr_mask))
1744 clear_intr = fifo_error_isr(g, fifo_intr);
1746 mutex_unlock(&g->fifo.intr.isr.mutex);
1748 gk20a_writel(g, fifo_intr_0_r(), clear_intr);
1753 void gk20a_fifo_nonstall_isr(struct gk20a *g)
1755 u32 fifo_intr = gk20a_readl(g, fifo_intr_0_r());
1758 gk20a_dbg(gpu_dbg_intr, "fifo nonstall isr %08x\n", fifo_intr);
1760 if (fifo_intr & fifo_intr_0_channel_intr_pending_f())
1761 clear_intr |= fifo_channel_isr(g, fifo_intr);
1763 gk20a_writel(g, fifo_intr_0_r(), clear_intr);
1768 static int __locked_fifo_preempt(struct gk20a *g, u32 id, bool is_tsg)
1770 u32 delay = GR_IDLE_CHECK_DEFAULT;
1771 unsigned long end_jiffies = jiffies
1772 + msecs_to_jiffies(gk20a_get_gr_idle_timeout(g));
1775 gk20a_dbg_fn("%d", id);
1779 gk20a_writel(g, fifo_preempt_r(),
1780 fifo_preempt_id_f(id) |
1781 fifo_preempt_type_tsg_f());
1783 gk20a_writel(g, fifo_preempt_r(),
1784 fifo_preempt_chid_f(id) |
1785 fifo_preempt_type_channel_f());
1787 gk20a_dbg_fn("%d", id);
1788 /* wait for preempt */
1791 if (!(gk20a_readl(g, fifo_preempt_r()) &
1792 fifo_preempt_pending_true_f())) {
1797 usleep_range(delay, delay * 2);
1798 delay = min_t(u32, delay << 1, GR_IDLE_CHECK_MAX);
1799 } while (time_before(jiffies, end_jiffies) ||
1800 !tegra_platform_is_silicon());
1802 gk20a_dbg_fn("%d", id);
1805 struct tsg_gk20a *tsg = &g->fifo.tsg[id];
1806 struct channel_gk20a *ch = NULL;
1808 gk20a_err(dev_from_gk20a(g),
1809 "preempt TSG %d timeout\n", id);
1811 mutex_lock(&tsg->ch_list_lock);
1812 list_for_each_entry(ch, &tsg->ch_list, ch_entry) {
1813 if (!gk20a_channel_get(ch))
1815 gk20a_set_error_notifier(ch,
1816 NVGPU_CHANNEL_FIFO_ERROR_IDLE_TIMEOUT);
1817 gk20a_channel_put(ch);
1819 mutex_unlock(&tsg->ch_list_lock);
1820 gk20a_fifo_recover_tsg(g, id, true);
1822 struct channel_gk20a *ch = &g->fifo.channel[id];
1824 gk20a_err(dev_from_gk20a(g),
1825 "preempt channel %d timeout\n", id);
1827 if (gk20a_channel_get(ch)) {
1828 gk20a_set_error_notifier(ch,
1829 NVGPU_CHANNEL_FIFO_ERROR_IDLE_TIMEOUT);
1830 gk20a_fifo_recover_ch(g, id, true);
1831 gk20a_channel_put(ch);
1839 int gk20a_fifo_preempt_channel(struct gk20a *g, u32 hw_chid)
1841 struct fifo_gk20a *f = &g->fifo;
1843 u32 token = PMU_INVALID_MUTEX_OWNER_ID;
1847 gk20a_dbg_fn("%d", hw_chid);
1849 /* we have no idea which runlist we are using. lock all */
1850 for (i = 0; i < g->fifo.max_runlists; i++)
1851 mutex_lock(&f->runlist_info[i].mutex);
1853 mutex_ret = pmu_mutex_acquire(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1855 ret = __locked_fifo_preempt(g, hw_chid, false);
1858 pmu_mutex_release(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1860 for (i = 0; i < g->fifo.max_runlists; i++)
1861 mutex_unlock(&f->runlist_info[i].mutex);
1866 int gk20a_fifo_preempt_tsg(struct gk20a *g, u32 tsgid)
1868 struct fifo_gk20a *f = &g->fifo;
1870 u32 token = PMU_INVALID_MUTEX_OWNER_ID;
1874 gk20a_dbg_fn("%d", tsgid);
1876 /* we have no idea which runlist we are using. lock all */
1877 for (i = 0; i < g->fifo.max_runlists; i++)
1878 mutex_lock(&f->runlist_info[i].mutex);
1880 mutex_ret = pmu_mutex_acquire(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1882 ret = __locked_fifo_preempt(g, tsgid, true);
1885 pmu_mutex_release(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1887 for (i = 0; i < g->fifo.max_runlists; i++)
1888 mutex_unlock(&f->runlist_info[i].mutex);
1893 int gk20a_fifo_preempt(struct gk20a *g, struct channel_gk20a *ch)
1897 if (gk20a_is_channel_marked_as_tsg(ch))
1898 err = gk20a_fifo_preempt_tsg(ch->g, ch->tsgid);
1900 err = gk20a_fifo_preempt_channel(ch->g, ch->hw_chid);
1905 int gk20a_fifo_enable_engine_activity(struct gk20a *g,
1906 struct fifo_engine_info_gk20a *eng_info)
1908 u32 token = PMU_INVALID_MUTEX_OWNER_ID;
1914 mutex_ret = pmu_mutex_acquire(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1916 enable = gk20a_readl(g, fifo_sched_disable_r());
1917 enable &= ~(fifo_sched_disable_true_v() >> eng_info->runlist_id);
1918 gk20a_writel(g, fifo_sched_disable_r(), enable);
1921 pmu_mutex_release(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1923 gk20a_dbg_fn("done");
1927 int gk20a_fifo_disable_engine_activity(struct gk20a *g,
1928 struct fifo_engine_info_gk20a *eng_info,
1931 u32 gr_stat, pbdma_stat, chan_stat, eng_stat, ctx_stat;
1932 u32 pbdma_chid = ~0, engine_chid = ~0, disable;
1933 u32 token = PMU_INVALID_MUTEX_OWNER_ID;
1940 gk20a_readl(g, fifo_engine_status_r(eng_info->engine_id));
1941 if (fifo_engine_status_engine_v(gr_stat) ==
1942 fifo_engine_status_engine_busy_v() && !wait_for_idle)
1945 mutex_ret = pmu_mutex_acquire(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1947 disable = gk20a_readl(g, fifo_sched_disable_r());
1948 disable = set_field(disable,
1949 fifo_sched_disable_runlist_m(eng_info->runlist_id),
1950 fifo_sched_disable_runlist_f(fifo_sched_disable_true_v(),
1951 eng_info->runlist_id));
1952 gk20a_writel(g, fifo_sched_disable_r(), disable);
1954 /* chid from pbdma status */
1955 pbdma_stat = gk20a_readl(g, fifo_pbdma_status_r(eng_info->pbdma_id));
1956 chan_stat = fifo_pbdma_status_chan_status_v(pbdma_stat);
1957 if (chan_stat == fifo_pbdma_status_chan_status_valid_v() ||
1958 chan_stat == fifo_pbdma_status_chan_status_chsw_save_v())
1959 pbdma_chid = fifo_pbdma_status_id_v(pbdma_stat);
1960 else if (chan_stat == fifo_pbdma_status_chan_status_chsw_load_v() ||
1961 chan_stat == fifo_pbdma_status_chan_status_chsw_switch_v())
1962 pbdma_chid = fifo_pbdma_status_next_id_v(pbdma_stat);
1964 if (pbdma_chid != ~0) {
1965 err = g->ops.fifo.preempt_channel(g, pbdma_chid);
1970 /* chid from engine status */
1971 eng_stat = gk20a_readl(g, fifo_engine_status_r(eng_info->engine_id));
1972 ctx_stat = fifo_engine_status_ctx_status_v(eng_stat);
1973 if (ctx_stat == fifo_engine_status_ctx_status_valid_v() ||
1974 ctx_stat == fifo_engine_status_ctx_status_ctxsw_save_v())
1975 engine_chid = fifo_engine_status_id_v(eng_stat);
1976 else if (ctx_stat == fifo_engine_status_ctx_status_ctxsw_load_v() ||
1977 ctx_stat == fifo_engine_status_ctx_status_ctxsw_switch_v())
1978 engine_chid = fifo_engine_status_next_id_v(eng_stat);
1980 if (engine_chid != ~0 && engine_chid != pbdma_chid) {
1981 err = g->ops.fifo.preempt_channel(g, engine_chid);
1988 pmu_mutex_release(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
1991 gk20a_dbg_fn("failed");
1992 if (gk20a_fifo_enable_engine_activity(g, eng_info))
1993 gk20a_err(dev_from_gk20a(g),
1994 "failed to enable gr engine activity\n");
1996 gk20a_dbg_fn("done");
2001 static void gk20a_fifo_runlist_reset_engines(struct gk20a *g, u32 runlist_id)
2003 struct fifo_gk20a *f = &g->fifo;
2007 for (i = 0; i < f->max_engines; i++) {
2008 u32 status = gk20a_readl(g, fifo_engine_status_r(i));
2009 bool engine_busy = fifo_engine_status_engine_v(status) ==
2010 fifo_engine_status_engine_busy_v();
2013 (f->engine_info[i].runlist_id == runlist_id))
2018 gk20a_fifo_recover(g, engines, ~(u32)0, false, false, true);
2021 static int gk20a_fifo_runlist_wait_pending(struct gk20a *g, u32 runlist_id)
2023 struct fifo_runlist_info_gk20a *runlist;
2024 unsigned long end_jiffies = jiffies +
2025 msecs_to_jiffies(gk20a_get_gr_idle_timeout(g));
2026 unsigned long delay = GR_IDLE_CHECK_DEFAULT;
2027 int ret = -ETIMEDOUT;
2029 runlist = &g->fifo.runlist_info[runlist_id];
2031 if ((gk20a_readl(g, fifo_eng_runlist_r(runlist_id)) &
2032 fifo_eng_runlist_pending_true_f()) == 0) {
2037 usleep_range(delay, delay * 2);
2038 delay = min_t(u32, delay << 1, GR_IDLE_CHECK_MAX);
2039 } while (time_before(jiffies, end_jiffies) ||
2040 !tegra_platform_is_silicon());
2045 static int gk20a_fifo_update_runlist_locked(struct gk20a *g, u32 runlist_id,
2046 u32 hw_chid, bool add,
2047 bool wait_for_finish)
2050 struct fifo_gk20a *f = &g->fifo;
2051 struct fifo_runlist_info_gk20a *runlist = NULL;
2052 u32 *runlist_entry_base = NULL;
2053 u32 *runlist_entry = NULL;
2054 phys_addr_t runlist_pa;
2055 u32 old_buf, new_buf;
2057 struct channel_gk20a *ch = NULL;
2058 struct tsg_gk20a *tsg = NULL;
2060 u32 count_channels_in_tsg;
2061 runlist = &f->runlist_info[runlist_id];
2063 /* valid channel, add/remove it from active list.
2064 Otherwise, keep active list untouched for suspend/resume. */
2065 if (hw_chid != ~0) {
2066 ch = &f->channel[hw_chid];
2067 if (gk20a_is_channel_marked_as_tsg(ch))
2068 tsg = &f->tsg[ch->tsgid];
2071 if (test_and_set_bit(hw_chid,
2072 runlist->active_channels) == 1)
2074 if (tsg && ++tsg->num_active_channels)
2075 set_bit(f->channel[hw_chid].tsgid,
2076 runlist->active_tsgs);
2078 if (test_and_clear_bit(hw_chid,
2079 runlist->active_channels) == 0)
2081 if (tsg && --tsg->num_active_channels == 0)
2082 clear_bit(f->channel[hw_chid].tsgid,
2083 runlist->active_tsgs);
2087 old_buf = runlist->cur_buffer;
2088 new_buf = !runlist->cur_buffer;
2090 gk20a_dbg_info("runlist_id : %d, switch to new buffer 0x%16llx",
2091 runlist_id, (u64)gk20a_mem_phys(&runlist->mem[new_buf]));
2093 runlist_pa = gk20a_mem_phys(&runlist->mem[new_buf]);
2099 runlist_entry_base = runlist->mem[new_buf].cpu_va;
2100 if (!runlist_entry_base) {
2105 if (hw_chid != ~0 || /* add/remove a valid channel */
2106 add /* resume to add all channels back */) {
2107 runlist_entry = runlist_entry_base;
2109 /* add non-TSG channels first */
2110 for_each_set_bit(chid,
2111 runlist->active_channels, f->num_channels) {
2112 ch = &f->channel[chid];
2114 if (!gk20a_is_channel_marked_as_tsg(ch)) {
2115 gk20a_dbg_info("add channel %d to runlist",
2117 runlist_entry[0] = ram_rl_entry_chid_f(chid);
2118 runlist_entry[1] = 0;
2124 /* now add TSG entries and channels bound to TSG */
2125 mutex_lock(&f->tsg_inuse_mutex);
2126 for_each_set_bit(tsgid,
2127 runlist->active_tsgs, f->num_channels) {
2128 tsg = &f->tsg[tsgid];
2130 gk20a_dbg_info("add TSG %d to runlist", tsg->tsgid);
2131 runlist_entry[0] = ram_rl_entry_id_f(tsg->tsgid) |
2132 ram_rl_entry_type_tsg_f() |
2133 ram_rl_entry_timeslice_scale_3_f() |
2134 ram_rl_entry_timeslice_timeout_128_f() |
2135 ram_rl_entry_tsg_length_f(
2136 tsg->num_active_channels);
2137 runlist_entry[1] = 0;
2141 /* add runnable channels bound to this TSG */
2142 count_channels_in_tsg = 0;
2143 mutex_lock(&tsg->ch_list_lock);
2144 list_for_each_entry(ch, &tsg->ch_list, ch_entry) {
2145 if (!test_bit(ch->hw_chid,
2146 runlist->active_channels))
2148 gk20a_dbg_info("add channel %d to runlist",
2151 ram_rl_entry_chid_f(ch->hw_chid);
2152 runlist_entry[1] = 0;
2155 count_channels_in_tsg++;
2157 mutex_unlock(&tsg->ch_list_lock);
2159 WARN_ON(tsg->num_active_channels !=
2160 count_channels_in_tsg);
2162 mutex_unlock(&f->tsg_inuse_mutex);
2163 } else /* suspend to remove all channels */
2167 gk20a_writel(g, fifo_runlist_base_r(),
2168 fifo_runlist_base_ptr_f(u64_lo32(runlist_pa >> 12)) |
2169 fifo_runlist_base_target_vid_mem_f());
2172 gk20a_writel(g, fifo_runlist_r(),
2173 fifo_runlist_engine_f(runlist_id) |
2174 fifo_eng_runlist_length_f(count));
2176 if (wait_for_finish) {
2177 ret = gk20a_fifo_runlist_wait_pending(g, runlist_id);
2179 if (ret == -ETIMEDOUT) {
2180 gk20a_err(dev_from_gk20a(g),
2181 "runlist update timeout");
2183 gk20a_fifo_runlist_reset_engines(g, runlist_id);
2185 /* engine reset needs the lock. drop it */
2186 /* wait until the runlist is active again */
2187 ret = gk20a_fifo_runlist_wait_pending(g, runlist_id);
2188 /* get the lock back. at this point everything should
2192 gk20a_err(dev_from_gk20a(g),
2193 "runlist update failed: %d", ret);
2194 } else if (ret == -EINTR)
2195 gk20a_err(dev_from_gk20a(g),
2196 "runlist update interrupted");
2199 runlist->cur_buffer = new_buf;
2205 /* add/remove a channel from runlist
2206 special cases below: runlist->active_channels will NOT be changed.
2207 (hw_chid == ~0 && !add) means remove all active channels from runlist.
2208 (hw_chid == ~0 && add) means restore all active channels on runlist. */
2209 int gk20a_fifo_update_runlist(struct gk20a *g, u32 runlist_id, u32 hw_chid,
2210 bool add, bool wait_for_finish)
2212 struct fifo_runlist_info_gk20a *runlist = NULL;
2213 struct fifo_gk20a *f = &g->fifo;
2214 u32 token = PMU_INVALID_MUTEX_OWNER_ID;
2220 runlist = &f->runlist_info[runlist_id];
2222 mutex_lock(&runlist->mutex);
2224 mutex_ret = pmu_mutex_acquire(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
2226 ret = gk20a_fifo_update_runlist_locked(g, runlist_id, hw_chid, add,
2230 pmu_mutex_release(&g->pmu, PMU_MUTEX_ID_FIFO, &token);
2232 mutex_unlock(&runlist->mutex);
2236 int gk20a_fifo_suspend(struct gk20a *g)
2240 /* stop bar1 snooping */
2241 gk20a_writel(g, fifo_bar1_base_r(),
2242 fifo_bar1_base_valid_false_f());
2244 /* disable fifo intr */
2245 gk20a_writel(g, fifo_intr_en_0_r(), 0);
2246 gk20a_writel(g, fifo_intr_en_1_r(), 0);
2248 gk20a_dbg_fn("done");
2252 bool gk20a_fifo_mmu_fault_pending(struct gk20a *g)
2254 if (gk20a_readl(g, fifo_intr_0_r()) &
2255 fifo_intr_0_mmu_fault_pending_f())
2261 int gk20a_fifo_wait_engine_idle(struct gk20a *g)
2263 unsigned long end_jiffies = jiffies +
2264 msecs_to_jiffies(gk20a_get_gr_idle_timeout(g));
2265 unsigned long delay = GR_IDLE_CHECK_DEFAULT;
2266 int ret = -ETIMEDOUT;
2268 struct device *d = dev_from_gk20a(g);
2272 for (i = 0; i < fifo_engine_status__size_1_v(); i++) {
2274 u32 status = gk20a_readl(g, fifo_engine_status_r(i));
2275 if (!fifo_engine_status_engine_v(status)) {
2280 usleep_range(delay, delay * 2);
2281 delay = min_t(unsigned long,
2282 delay << 1, GR_IDLE_CHECK_MAX);
2283 } while (time_before(jiffies, end_jiffies) ||
2284 !tegra_platform_is_silicon());
2286 gk20a_err(d, "cannot idle engine %u\n", i);
2291 gk20a_dbg_fn("done");
2296 static void gk20a_fifo_apply_pb_timeout(struct gk20a *g)
2300 if (tegra_platform_is_silicon()) {
2301 timeout = gk20a_readl(g, fifo_pb_timeout_r());
2302 timeout &= ~fifo_pb_timeout_detection_enabled_f();
2303 gk20a_writel(g, fifo_pb_timeout_r(), timeout);
2307 static u32 gk20a_fifo_get_num_fifos(struct gk20a *g)
2309 return ccsr_channel__size_1_v();
2312 u32 gk20a_fifo_get_pbdma_signature(struct gk20a *g)
2314 return pbdma_signature_hw_valid_f() | pbdma_signature_sw_zero_f();
2317 void gk20a_init_fifo(struct gpu_ops *gops)
2319 gk20a_init_channel(gops);
2320 gops->fifo.preempt_channel = gk20a_fifo_preempt_channel;
2321 gops->fifo.update_runlist = gk20a_fifo_update_runlist;
2322 gops->fifo.trigger_mmu_fault = gk20a_fifo_trigger_mmu_fault;
2323 gops->fifo.apply_pb_timeout = gk20a_fifo_apply_pb_timeout;
2324 gops->fifo.wait_engine_idle = gk20a_fifo_wait_engine_idle;
2325 gops->fifo.get_num_fifos = gk20a_fifo_get_num_fifos;
2326 gops->fifo.get_pbdma_signature = gk20a_fifo_get_pbdma_signature;