summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/nvgpu_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/nvgpu_common.c')
-rw-r--r--drivers/gpu/nvgpu/nvgpu_common.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/nvgpu_common.c b/drivers/gpu/nvgpu/nvgpu_common.c
index a1f4832b..a2673b26 100644
--- a/drivers/gpu/nvgpu/nvgpu_common.c
+++ b/drivers/gpu/nvgpu/nvgpu_common.c
@@ -231,3 +231,42 @@ const struct firmware *nvgpu_request_firmware(struct gk20a *g,
231 231
232 return fw; 232 return fw;
233} 233}
234
235/**
236 * cyclic_delta - Returns delta of cyclic integers a and b.
237 *
238 * @a - First integer
239 * @b - Second integer
240 *
241 * Note: if a is ahead of b, delta is positive.
242 */
243static int cyclic_delta(int a, int b)
244{
245 return a - b;
246}
247
248/**
249 * nvgpu_wait_for_deferred_interrupts - Wait for interrupts to complete
250 *
251 * @g - The GPU to wait on.
252 *
253 * Waits until all interrupt handlers that have been scheduled to run have
254 * completed.
255 */
256void nvgpu_wait_for_deferred_interrupts(struct gk20a *g)
257{
258 int stall_irq_threshold = atomic_read(&g->hw_irq_stall_count);
259 int nonstall_irq_threshold = atomic_read(&g->hw_irq_nonstall_count);
260
261 /* wait until all stalling irqs are handled */
262 wait_event(g->sw_irq_stall_last_handled_wq,
263 cyclic_delta(stall_irq_threshold,
264 atomic_read(&g->sw_irq_stall_last_handled))
265 <= 0);
266
267 /* wait until all non-stalling irqs are handled */
268 wait_event(g->sw_irq_nonstall_last_handled_wq,
269 cyclic_delta(nonstall_irq_threshold,
270 atomic_read(&g->sw_irq_nonstall_last_handled))
271 <= 0);
272}