summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/mc_gk20a.c
diff options
context:
space:
mode:
authorKonsta Holtta <kholtta@nvidia.com>2015-03-06 09:33:43 -0500
committerTerje Bergstrom <tbergstrom@nvidia.com>2015-06-09 14:13:43 -0400
commit6085c90f499c642bc41a646b0efbdfe60e096c74 (patch)
tree0eaab99b228ce162ec3a44d0f8138b441f5a64f4 /drivers/gpu/nvgpu/gk20a/mc_gk20a.c
parenta41e5c41cadaa3d030a1f75b09328b8b1a440b69 (diff)
gpu: nvgpu: add per-channel refcounting
Add reference counting for channels, and wait for reference count to get to 0 in gk20a_channel_free() before actually freeing the channel. Also, change free channel tracking a bit by employing a list of free channels, which simplifies the procedure of finding available channels with reference counting. Each use of a channel must have a reference taken before use or held by the caller. Taking a reference of a wild channel pointer may fail, if the channel is either not opened or in a process of being closed. Also, add safeguards for protecting accidental use of closed channels, specifically, by setting ch->g = NULL in channel free. This will make it obvious if freed channel is attempted to be used. The last user of a channel might be the deferred interrupt handler, so wait for deferred interrupts to be processed twice in the channel free procedure: once for providing last notifications to the channel and once to make sure there are no stale pointers left after referencing to the channel has been denied. Finally, fix some races in channel and TSG force reset IOCTL path, by pausing the channel scheduler in gk20a_fifo_recover_ch() and gk20a_fifo_recover_tsg(), while the affected engines have been identified, the appropriate MMU faults triggered, and the MMU faults handled. In this case, make sure that the MMU fault does not attempt to query the hardware about the failing channel or TSG ids. This should make channel recovery more safe also in the regular (i.e., not in the interrupt handler) context. Bug 1530226 Bug 1597493 Bug 1625901 Bug 200076344 Bug 200071810 Change-Id: Ib274876908e18219c64ea41e50ca443df81d957b Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Signed-off-by: Konsta Holtta <kholtta@nvidia.com> Signed-off-by: Sami Kiminki <skiminki@nvidia.com> Reviewed-on: http://git-master/r/448463 (cherry picked from commit 3f03aeae64ef2af4829e06f5f63062e8ebd21353) Reviewed-on: http://git-master/r/755147 Reviewed-by: Automatic_Commit_Validation_User
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/mc_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/mc_gk20a.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/mc_gk20a.c b/drivers/gpu/nvgpu/gk20a/mc_gk20a.c
index 06b00a25..0a773d10 100644
--- a/drivers/gpu/nvgpu/gk20a/mc_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/mc_gk20a.c
@@ -40,6 +40,8 @@ irqreturn_t mc_gk20a_isr_stall(struct gk20a *g)
40 /* flush previous write */ 40 /* flush previous write */
41 gk20a_readl(g, mc_intr_en_0_r()); 41 gk20a_readl(g, mc_intr_en_0_r());
42 42
43 atomic_inc(&g->hw_irq_stall_count);
44
43 trace_mc_gk20a_intr_stall_done(g->dev->name); 45 trace_mc_gk20a_intr_stall_done(g->dev->name);
44 46
45 return IRQ_WAKE_THREAD; 47 return IRQ_WAKE_THREAD;
@@ -63,18 +65,22 @@ irqreturn_t mc_gk20a_isr_nonstall(struct gk20a *g)
63 /* flush previous write */ 65 /* flush previous write */
64 gk20a_readl(g, mc_intr_en_1_r()); 66 gk20a_readl(g, mc_intr_en_1_r());
65 67
68 atomic_inc(&g->hw_irq_nonstall_count);
69
66 return IRQ_WAKE_THREAD; 70 return IRQ_WAKE_THREAD;
67} 71}
68 72
69irqreturn_t mc_gk20a_intr_thread_stall(struct gk20a *g) 73irqreturn_t mc_gk20a_intr_thread_stall(struct gk20a *g)
70{ 74{
71 u32 mc_intr_0; 75 u32 mc_intr_0;
76 int hw_irq_count;
72 77
73 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched"); 78 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched");
74 79
75 trace_mc_gk20a_intr_thread_stall(g->dev->name); 80 trace_mc_gk20a_intr_thread_stall(g->dev->name);
76 81
77 mc_intr_0 = gk20a_readl(g, mc_intr_0_r()); 82 mc_intr_0 = gk20a_readl(g, mc_intr_0_r());
83 hw_irq_count = atomic_read(&g->hw_irq_stall_count);
78 84
79 gk20a_dbg(gpu_dbg_intr, "stall intr %08x\n", mc_intr_0); 85 gk20a_dbg(gpu_dbg_intr, "stall intr %08x\n", mc_intr_0);
80 86
@@ -94,12 +100,17 @@ irqreturn_t mc_gk20a_intr_thread_stall(struct gk20a *g)
94 if (mc_intr_0 & mc_intr_0_pbus_pending_f()) 100 if (mc_intr_0 & mc_intr_0_pbus_pending_f())
95 gk20a_pbus_isr(g); 101 gk20a_pbus_isr(g);
96 102
103 /* sync handled irq counter before re-enabling interrupts */
104 atomic_set(&g->sw_irq_stall_last_handled, hw_irq_count);
105
97 gk20a_writel(g, mc_intr_en_0_r(), 106 gk20a_writel(g, mc_intr_en_0_r(),
98 mc_intr_en_0_inta_hardware_f()); 107 mc_intr_en_0_inta_hardware_f());
99 108
100 /* flush previous write */ 109 /* flush previous write */
101 gk20a_readl(g, mc_intr_en_0_r()); 110 gk20a_readl(g, mc_intr_en_0_r());
102 111
112 wake_up_all(&g->sw_irq_stall_last_handled_wq);
113
103 trace_mc_gk20a_intr_thread_stall_done(g->dev->name); 114 trace_mc_gk20a_intr_thread_stall_done(g->dev->name);
104 115
105 return IRQ_HANDLED; 116 return IRQ_HANDLED;
@@ -108,10 +119,12 @@ irqreturn_t mc_gk20a_intr_thread_stall(struct gk20a *g)
108irqreturn_t mc_gk20a_intr_thread_nonstall(struct gk20a *g) 119irqreturn_t mc_gk20a_intr_thread_nonstall(struct gk20a *g)
109{ 120{
110 u32 mc_intr_1; 121 u32 mc_intr_1;
122 int hw_irq_count;
111 123
112 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched"); 124 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched");
113 125
114 mc_intr_1 = gk20a_readl(g, mc_intr_1_r()); 126 mc_intr_1 = gk20a_readl(g, mc_intr_1_r());
127 hw_irq_count = atomic_read(&g->hw_irq_nonstall_count);
115 128
116 gk20a_dbg(gpu_dbg_intr, "non-stall intr %08x\n", mc_intr_1); 129 gk20a_dbg(gpu_dbg_intr, "non-stall intr %08x\n", mc_intr_1);
117 130
@@ -125,12 +138,17 @@ irqreturn_t mc_gk20a_intr_thread_nonstall(struct gk20a *g)
125 && g->ops.ce2.isr_nonstall) 138 && g->ops.ce2.isr_nonstall)
126 g->ops.ce2.isr_nonstall(g); 139 g->ops.ce2.isr_nonstall(g);
127 140
141 /* sync handled irq counter before re-enabling interrupts */
142 atomic_set(&g->sw_irq_nonstall_last_handled, hw_irq_count);
143
128 gk20a_writel(g, mc_intr_en_1_r(), 144 gk20a_writel(g, mc_intr_en_1_r(),
129 mc_intr_en_1_inta_hardware_f()); 145 mc_intr_en_1_inta_hardware_f());
130 146
131 /* flush previous write */ 147 /* flush previous write */
132 gk20a_readl(g, mc_intr_en_1_r()); 148 gk20a_readl(g, mc_intr_en_1_r());
133 149
150 wake_up_all(&g->sw_irq_stall_last_handled_wq);
151
134 return IRQ_HANDLED; 152 return IRQ_HANDLED;
135} 153}
136 154