blob: ca368490b3ee2e47efcb129b5225d6d340abd983 [file] [log] [blame]
Rob Clark7198e6b2013-07-19 12:59:32 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "msm_gpu.h"
19#include "msm_gem.h"
Rob Clark871d8122013-11-16 12:56:06 -050020#include "msm_mmu.h"
Rob Clarkfde5de62016-03-15 15:35:08 -040021#include "msm_fence.h"
Rob Clark7198e6b2013-07-19 12:59:32 -040022
Jordan Crousec0fec7f2018-07-24 10:33:27 -060023#include <generated/utsrelease.h>
Rob Clark18bb8a62017-09-13 10:17:18 -040024#include <linux/string_helpers.h>
Jordan Crousef91c14a2018-01-10 10:41:54 -070025#include <linux/pm_opp.h>
26#include <linux/devfreq.h>
Jordan Crousec0fec7f2018-07-24 10:33:27 -060027#include <linux/devcoredump.h>
Rob Clark7198e6b2013-07-19 12:59:32 -040028
29/*
30 * Power Management:
31 */
32
Jordan Crousef91c14a2018-01-10 10:41:54 -070033static int msm_devfreq_target(struct device *dev, unsigned long *freq,
34 u32 flags)
35{
36 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev));
37 struct dev_pm_opp *opp;
38
39 opp = devfreq_recommended_opp(dev, freq, flags);
40
41 if (IS_ERR(opp))
42 return PTR_ERR(opp);
43
44 clk_set_rate(gpu->core_clk, *freq);
45 dev_pm_opp_put(opp);
46
47 return 0;
48}
49
50static int msm_devfreq_get_dev_status(struct device *dev,
51 struct devfreq_dev_status *status)
52{
53 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev));
54 u64 cycles;
55 u32 freq = ((u32) status->current_frequency) / 1000000;
56 ktime_t time;
57
58 status->current_frequency = (unsigned long) clk_get_rate(gpu->core_clk);
59 gpu->funcs->gpu_busy(gpu, &cycles);
60
61 status->busy_time = ((u32) (cycles - gpu->devfreq.busy_cycles)) / freq;
62
63 gpu->devfreq.busy_cycles = cycles;
64
65 time = ktime_get();
66 status->total_time = ktime_us_delta(time, gpu->devfreq.time);
67 gpu->devfreq.time = time;
68
69 return 0;
70}
71
72static int msm_devfreq_get_cur_freq(struct device *dev, unsigned long *freq)
73{
74 struct msm_gpu *gpu = platform_get_drvdata(to_platform_device(dev));
75
76 *freq = (unsigned long) clk_get_rate(gpu->core_clk);
77
78 return 0;
79}
80
81static struct devfreq_dev_profile msm_devfreq_profile = {
82 .polling_ms = 10,
83 .target = msm_devfreq_target,
84 .get_dev_status = msm_devfreq_get_dev_status,
85 .get_cur_freq = msm_devfreq_get_cur_freq,
86};
87
88static void msm_devfreq_init(struct msm_gpu *gpu)
89{
90 /* We need target support to do devfreq */
91 if (!gpu->funcs->gpu_busy)
92 return;
93
94 msm_devfreq_profile.initial_freq = gpu->fast_rate;
95
96 /*
97 * Don't set the freq_table or max_state and let devfreq build the table
98 * from OPP
99 */
100
101 gpu->devfreq.devfreq = devm_devfreq_add_device(&gpu->pdev->dev,
102 &msm_devfreq_profile, "simple_ondemand", NULL);
103
104 if (IS_ERR(gpu->devfreq.devfreq)) {
105 dev_err(&gpu->pdev->dev, "Couldn't initialize GPU devfreq\n");
106 gpu->devfreq.devfreq = NULL;
107 }
108}
109
Rob Clark7198e6b2013-07-19 12:59:32 -0400110static int enable_pwrrail(struct msm_gpu *gpu)
111{
112 struct drm_device *dev = gpu->dev;
113 int ret = 0;
114
115 if (gpu->gpu_reg) {
116 ret = regulator_enable(gpu->gpu_reg);
117 if (ret) {
118 dev_err(dev->dev, "failed to enable 'gpu_reg': %d\n", ret);
119 return ret;
120 }
121 }
122
123 if (gpu->gpu_cx) {
124 ret = regulator_enable(gpu->gpu_cx);
125 if (ret) {
126 dev_err(dev->dev, "failed to enable 'gpu_cx': %d\n", ret);
127 return ret;
128 }
129 }
130
131 return 0;
132}
133
134static int disable_pwrrail(struct msm_gpu *gpu)
135{
136 if (gpu->gpu_cx)
137 regulator_disable(gpu->gpu_cx);
138 if (gpu->gpu_reg)
139 regulator_disable(gpu->gpu_reg);
140 return 0;
141}
142
143static int enable_clk(struct msm_gpu *gpu)
144{
Jordan Crouse98db8032017-03-07 10:02:56 -0700145 if (gpu->core_clk && gpu->fast_rate)
146 clk_set_rate(gpu->core_clk, gpu->fast_rate);
Jordan Crouse89d777a2016-11-28 12:28:31 -0700147
Jordan Crouseb5f103a2016-11-28 12:28:33 -0700148 /* Set the RBBM timer rate to 19.2Mhz */
Jordan Crouse98db8032017-03-07 10:02:56 -0700149 if (gpu->rbbmtimer_clk)
150 clk_set_rate(gpu->rbbmtimer_clk, 19200000);
Jordan Crouseb5f103a2016-11-28 12:28:33 -0700151
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600152 return clk_bulk_prepare_enable(gpu->nr_clocks, gpu->grp_clks);
Rob Clark7198e6b2013-07-19 12:59:32 -0400153}
154
155static int disable_clk(struct msm_gpu *gpu)
156{
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600157 clk_bulk_disable_unprepare(gpu->nr_clocks, gpu->grp_clks);
Rob Clark7198e6b2013-07-19 12:59:32 -0400158
Jordan Crousebf5af4a2017-03-07 10:02:54 -0700159 /*
160 * Set the clock to a deliberately low rate. On older targets the clock
161 * speed had to be non zero to avoid problems. On newer targets this
162 * will be rounded down to zero anyway so it all works out.
163 */
Jordan Crouse98db8032017-03-07 10:02:56 -0700164 if (gpu->core_clk)
165 clk_set_rate(gpu->core_clk, 27000000);
Jordan Crouse89d777a2016-11-28 12:28:31 -0700166
Jordan Crouse98db8032017-03-07 10:02:56 -0700167 if (gpu->rbbmtimer_clk)
168 clk_set_rate(gpu->rbbmtimer_clk, 0);
Jordan Crouseb5f103a2016-11-28 12:28:33 -0700169
Rob Clark7198e6b2013-07-19 12:59:32 -0400170 return 0;
171}
172
173static int enable_axi(struct msm_gpu *gpu)
174{
175 if (gpu->ebi1_clk)
176 clk_prepare_enable(gpu->ebi1_clk);
Rob Clark7198e6b2013-07-19 12:59:32 -0400177 return 0;
178}
179
180static int disable_axi(struct msm_gpu *gpu)
181{
182 if (gpu->ebi1_clk)
183 clk_disable_unprepare(gpu->ebi1_clk);
Rob Clark7198e6b2013-07-19 12:59:32 -0400184 return 0;
185}
186
187int msm_gpu_pm_resume(struct msm_gpu *gpu)
188{
189 int ret;
190
Rob Clarkeeb75472017-02-10 15:36:33 -0500191 DBG("%s", gpu->name);
Rob Clark7198e6b2013-07-19 12:59:32 -0400192
193 ret = enable_pwrrail(gpu);
194 if (ret)
195 return ret;
196
197 ret = enable_clk(gpu);
198 if (ret)
199 return ret;
200
201 ret = enable_axi(gpu);
202 if (ret)
203 return ret;
204
Jordan Crousef91c14a2018-01-10 10:41:54 -0700205 if (gpu->devfreq.devfreq) {
206 gpu->devfreq.busy_cycles = 0;
207 gpu->devfreq.time = ktime_get();
208
209 devfreq_resume_device(gpu->devfreq.devfreq);
210 }
211
Rob Clarkeeb75472017-02-10 15:36:33 -0500212 gpu->needs_hw_init = true;
213
Rob Clark7198e6b2013-07-19 12:59:32 -0400214 return 0;
215}
216
217int msm_gpu_pm_suspend(struct msm_gpu *gpu)
218{
219 int ret;
220
Rob Clarkeeb75472017-02-10 15:36:33 -0500221 DBG("%s", gpu->name);
Rob Clark7198e6b2013-07-19 12:59:32 -0400222
Jordan Crousef91c14a2018-01-10 10:41:54 -0700223 if (gpu->devfreq.devfreq)
224 devfreq_suspend_device(gpu->devfreq.devfreq);
225
Rob Clark7198e6b2013-07-19 12:59:32 -0400226 ret = disable_axi(gpu);
227 if (ret)
228 return ret;
229
230 ret = disable_clk(gpu);
231 if (ret)
232 return ret;
233
234 ret = disable_pwrrail(gpu);
235 if (ret)
236 return ret;
237
238 return 0;
239}
240
Rob Clarkeeb75472017-02-10 15:36:33 -0500241int msm_gpu_hw_init(struct msm_gpu *gpu)
Rob Clark37d77c32014-01-11 16:25:08 -0500242{
Rob Clarkeeb75472017-02-10 15:36:33 -0500243 int ret;
Rob Clark37d77c32014-01-11 16:25:08 -0500244
Rob Clarkcb1e3812017-06-13 09:15:36 -0400245 WARN_ON(!mutex_is_locked(&gpu->dev->struct_mutex));
246
Rob Clarkeeb75472017-02-10 15:36:33 -0500247 if (!gpu->needs_hw_init)
248 return 0;
Rob Clark37d77c32014-01-11 16:25:08 -0500249
Rob Clarkeeb75472017-02-10 15:36:33 -0500250 disable_irq(gpu->irq);
251 ret = gpu->funcs->hw_init(gpu);
252 if (!ret)
253 gpu->needs_hw_init = false;
254 enable_irq(gpu->irq);
Rob Clark37d77c32014-01-11 16:25:08 -0500255
Rob Clarkeeb75472017-02-10 15:36:33 -0500256 return ret;
Rob Clark37d77c32014-01-11 16:25:08 -0500257}
258
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600259#ifdef CONFIG_DEV_COREDUMP
260static ssize_t msm_gpu_devcoredump_read(char *buffer, loff_t offset,
261 size_t count, void *data, size_t datalen)
262{
263 struct msm_gpu *gpu = data;
264 struct drm_print_iterator iter;
265 struct drm_printer p;
266 struct msm_gpu_state *state;
267
268 state = msm_gpu_crashstate_get(gpu);
269 if (!state)
270 return 0;
271
272 iter.data = buffer;
273 iter.offset = 0;
274 iter.start = offset;
275 iter.remain = count;
276
277 p = drm_coredump_printer(&iter);
278
279 drm_printf(&p, "---\n");
280 drm_printf(&p, "kernel: " UTS_RELEASE "\n");
281 drm_printf(&p, "module: " KBUILD_MODNAME "\n");
Arnd Bergmann3530a172018-07-26 14:39:25 +0200282 drm_printf(&p, "time: %lld.%09ld\n",
283 state->time.tv_sec, state->time.tv_nsec);
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600284 if (state->comm)
285 drm_printf(&p, "comm: %s\n", state->comm);
286 if (state->cmd)
287 drm_printf(&p, "cmdline: %s\n", state->cmd);
288
289 gpu->funcs->show(gpu, state, &p);
290
291 msm_gpu_crashstate_put(gpu);
292
293 return count - iter.remain;
294}
295
296static void msm_gpu_devcoredump_free(void *data)
297{
298 struct msm_gpu *gpu = data;
299
300 msm_gpu_crashstate_put(gpu);
301}
302
Jordan Crousecdb95932018-07-24 10:33:31 -0600303static void msm_gpu_crashstate_get_bo(struct msm_gpu_state *state,
304 struct msm_gem_object *obj, u64 iova, u32 flags)
305{
306 struct msm_gpu_state_bo *state_bo = &state->bos[state->nr_bos];
307
308 /* Don't record write only objects */
309
310 state_bo->size = obj->base.size;
311 state_bo->iova = iova;
312
313 /* Only store the data for buffer objects marked for read */
314 if ((flags & MSM_SUBMIT_BO_READ)) {
315 void *ptr;
316
317 state_bo->data = kvmalloc(obj->base.size, GFP_KERNEL);
318 if (!state_bo->data)
319 return;
320
321 ptr = msm_gem_get_vaddr_active(&obj->base);
322 if (IS_ERR(ptr)) {
323 kvfree(state_bo->data);
324 return;
325 }
326
327 memcpy(state_bo->data, ptr, obj->base.size);
328 msm_gem_put_vaddr(&obj->base);
329 }
330
331 state->nr_bos++;
332}
333
334static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,
335 struct msm_gem_submit *submit, char *comm, char *cmd)
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600336{
337 struct msm_gpu_state *state;
338
339 /* Only save one crash state at a time */
340 if (gpu->crashstate)
341 return;
342
343 state = gpu->funcs->gpu_state_get(gpu);
344 if (IS_ERR_OR_NULL(state))
345 return;
346
347 /* Fill in the additional crash state information */
348 state->comm = kstrdup(comm, GFP_KERNEL);
349 state->cmd = kstrdup(cmd, GFP_KERNEL);
350
Jordan Crousecdb95932018-07-24 10:33:31 -0600351 if (submit) {
352 int i;
353
354 state->bos = kcalloc(submit->nr_bos,
355 sizeof(struct msm_gpu_state_bo), GFP_KERNEL);
356
357 for (i = 0; state->bos && i < submit->nr_bos; i++)
358 msm_gpu_crashstate_get_bo(state, submit->bos[i].obj,
359 submit->bos[i].iova, submit->bos[i].flags);
360 }
361
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600362 /* Set the active crash state to be dumped on failure */
363 gpu->crashstate = state;
364
365 /* FIXME: Release the crashstate if this errors out? */
366 dev_coredumpm(gpu->dev->dev, THIS_MODULE, gpu, 0, GFP_KERNEL,
367 msm_gpu_devcoredump_read, msm_gpu_devcoredump_free);
368}
369#else
370static void msm_gpu_crashstate_capture(struct msm_gpu *gpu, char *comm,
371 char *cmd)
372{
373}
374#endif
375
Rob Clark37d77c32014-01-11 16:25:08 -0500376/*
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400377 * Hangcheck detection for locked gpu:
378 */
379
Jordan Crousef97deca2017-10-20 11:06:57 -0600380static void update_fences(struct msm_gpu *gpu, struct msm_ringbuffer *ring,
381 uint32_t fence)
382{
383 struct msm_gem_submit *submit;
384
385 list_for_each_entry(submit, &ring->submits, node) {
386 if (submit->seqno > fence)
387 break;
388
389 msm_update_fence(submit->ring->fctx,
390 submit->fence->seqno);
391 }
392}
393
Rob Clark18bb8a62017-09-13 10:17:18 -0400394static struct msm_gem_submit *
395find_submit(struct msm_ringbuffer *ring, uint32_t fence)
396{
397 struct msm_gem_submit *submit;
398
399 WARN_ON(!mutex_is_locked(&ring->gpu->dev->struct_mutex));
400
401 list_for_each_entry(submit, &ring->submits, node)
402 if (submit->seqno == fence)
403 return submit;
404
405 return NULL;
406}
407
Rob Clarkb6295f92016-03-15 18:26:28 -0400408static void retire_submits(struct msm_gpu *gpu);
Rob Clark1a370be2015-06-07 13:46:04 -0400409
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400410static void recover_worker(struct work_struct *work)
411{
412 struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work);
413 struct drm_device *dev = gpu->dev;
Rob Clark96169f42017-09-15 11:04:44 -0400414 struct msm_drm_private *priv = dev->dev_private;
Rob Clark4816b622016-05-03 10:10:15 -0400415 struct msm_gem_submit *submit;
Jordan Crousef97deca2017-10-20 11:06:57 -0600416 struct msm_ringbuffer *cur_ring = gpu->funcs->active_ring(gpu);
Jordan Crouse65a3c272018-07-24 10:33:26 -0600417 char *comm = NULL, *cmd = NULL;
Jordan Crousef97deca2017-10-20 11:06:57 -0600418 int i;
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400419
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400420 mutex_lock(&dev->struct_mutex);
Rob Clark1a370be2015-06-07 13:46:04 -0400421
Rob Clark4816b622016-05-03 10:10:15 -0400422 dev_err(dev->dev, "%s: hangcheck recover!\n", gpu->name);
Jordan Crousef97deca2017-10-20 11:06:57 -0600423
Rob Clark96169f42017-09-15 11:04:44 -0400424 submit = find_submit(cur_ring, cur_ring->memptrs->fence + 1);
Rob Clark18bb8a62017-09-13 10:17:18 -0400425 if (submit) {
426 struct task_struct *task;
Rob Clark4816b622016-05-03 10:10:15 -0400427
Rob Clark18bb8a62017-09-13 10:17:18 -0400428 rcu_read_lock();
429 task = pid_task(submit->pid, PIDTYPE_PID);
430 if (task) {
Jordan Crouse65a3c272018-07-24 10:33:26 -0600431 comm = kstrdup(task->comm, GFP_ATOMIC);
Rob Clark18bb8a62017-09-13 10:17:18 -0400432
433 /*
434 * So slightly annoying, in other paths like
435 * mmap'ing gem buffers, mmap_sem is acquired
436 * before struct_mutex, which means we can't
437 * hold struct_mutex across the call to
438 * get_cmdline(). But submits are retired
439 * from the same in-order workqueue, so we can
440 * safely drop the lock here without worrying
441 * about the submit going away.
442 */
443 mutex_unlock(&dev->struct_mutex);
Jordan Crouse65a3c272018-07-24 10:33:26 -0600444 cmd = kstrdup_quotable_cmdline(task, GFP_ATOMIC);
Rob Clark18bb8a62017-09-13 10:17:18 -0400445 mutex_lock(&dev->struct_mutex);
Rob Clark4816b622016-05-03 10:10:15 -0400446 }
Rob Clark18bb8a62017-09-13 10:17:18 -0400447 rcu_read_unlock();
Jordan Crouse65a3c272018-07-24 10:33:26 -0600448
449 if (comm && cmd) {
450 dev_err(dev->dev, "%s: offending task: %s (%s)\n",
451 gpu->name, comm, cmd);
452
453 msm_rd_dump_submit(priv->hangrd, submit,
454 "offending task: %s (%s)", comm, cmd);
455 } else
456 msm_rd_dump_submit(priv->hangrd, submit, NULL);
Rob Clark96169f42017-09-15 11:04:44 -0400457 }
Rob Clark18bb8a62017-09-13 10:17:18 -0400458
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600459 /* Record the crash state */
460 pm_runtime_get_sync(&gpu->pdev->dev);
Jordan Crousecdb95932018-07-24 10:33:31 -0600461 msm_gpu_crashstate_capture(gpu, submit, comm, cmd);
Jordan Crousec0fec7f2018-07-24 10:33:27 -0600462 pm_runtime_put_sync(&gpu->pdev->dev);
463
Jordan Crouse65a3c272018-07-24 10:33:26 -0600464 kfree(cmd);
465 kfree(comm);
Rob Clark96169f42017-09-15 11:04:44 -0400466
467 /*
468 * Update all the rings with the latest and greatest fence.. this
469 * needs to happen after msm_rd_dump_submit() to ensure that the
470 * bo's referenced by the offending submit are still around.
471 */
Jordan Crouse7ddae822017-12-13 13:45:44 -0700472 for (i = 0; i < gpu->nr_rings; i++) {
Rob Clark96169f42017-09-15 11:04:44 -0400473 struct msm_ringbuffer *ring = gpu->rb[i];
474
475 uint32_t fence = ring->memptrs->fence;
476
477 /*
478 * For the current (faulting?) ring/submit advance the fence by
479 * one more to clear the faulting submit
480 */
481 if (ring == cur_ring)
482 fence++;
483
484 update_fences(gpu, ring, fence);
Rob Clark4816b622016-05-03 10:10:15 -0400485 }
486
487 if (msm_gpu_active(gpu)) {
Rob Clark1a370be2015-06-07 13:46:04 -0400488 /* retire completed submits, plus the one that hung: */
Rob Clarkb6295f92016-03-15 18:26:28 -0400489 retire_submits(gpu);
Rob Clark1a370be2015-06-07 13:46:04 -0400490
Rob Clarkeeb75472017-02-10 15:36:33 -0500491 pm_runtime_get_sync(&gpu->pdev->dev);
Rob Clark37d77c32014-01-11 16:25:08 -0500492 gpu->funcs->recover(gpu);
Rob Clarkeeb75472017-02-10 15:36:33 -0500493 pm_runtime_put_sync(&gpu->pdev->dev);
Rob Clark1a370be2015-06-07 13:46:04 -0400494
Jordan Crousef97deca2017-10-20 11:06:57 -0600495 /*
496 * Replay all remaining submits starting with highest priority
497 * ring
498 */
Jordan Crouseb1fc2832017-10-20 11:07:01 -0600499 for (i = 0; i < gpu->nr_rings; i++) {
Jordan Crousef97deca2017-10-20 11:06:57 -0600500 struct msm_ringbuffer *ring = gpu->rb[i];
501
502 list_for_each_entry(submit, &ring->submits, node)
503 gpu->funcs->submit(gpu, submit, NULL);
Rob Clark1a370be2015-06-07 13:46:04 -0400504 }
Rob Clark37d77c32014-01-11 16:25:08 -0500505 }
Rob Clark4816b622016-05-03 10:10:15 -0400506
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400507 mutex_unlock(&dev->struct_mutex);
508
509 msm_gpu_retire(gpu);
510}
511
512static void hangcheck_timer_reset(struct msm_gpu *gpu)
513{
514 DBG("%s", gpu->name);
515 mod_timer(&gpu->hangcheck_timer,
516 round_jiffies_up(jiffies + DRM_MSM_HANGCHECK_JIFFIES));
517}
518
Kees Cooke99e88a2017-10-16 14:43:17 -0700519static void hangcheck_handler(struct timer_list *t)
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400520{
Kees Cooke99e88a2017-10-16 14:43:17 -0700521 struct msm_gpu *gpu = from_timer(gpu, t, hangcheck_timer);
Rob Clark6b8819c2013-09-11 17:14:30 -0400522 struct drm_device *dev = gpu->dev;
523 struct msm_drm_private *priv = dev->dev_private;
Jordan Crousef97deca2017-10-20 11:06:57 -0600524 struct msm_ringbuffer *ring = gpu->funcs->active_ring(gpu);
525 uint32_t fence = ring->memptrs->fence;
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400526
Jordan Crousef97deca2017-10-20 11:06:57 -0600527 if (fence != ring->hangcheck_fence) {
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400528 /* some progress has been made.. ya! */
Jordan Crousef97deca2017-10-20 11:06:57 -0600529 ring->hangcheck_fence = fence;
530 } else if (fence < ring->seqno) {
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400531 /* no progress and not done.. hung! */
Jordan Crousef97deca2017-10-20 11:06:57 -0600532 ring->hangcheck_fence = fence;
533 dev_err(dev->dev, "%s: hangcheck detected gpu lockup rb %d!\n",
534 gpu->name, ring->id);
Rob Clark26791c42013-09-03 07:12:03 -0400535 dev_err(dev->dev, "%s: completed fence: %u\n",
536 gpu->name, fence);
537 dev_err(dev->dev, "%s: submitted fence: %u\n",
Jordan Crousef97deca2017-10-20 11:06:57 -0600538 gpu->name, ring->seqno);
539
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400540 queue_work(priv->wq, &gpu->recover_work);
541 }
542
543 /* if still more pending work, reset the hangcheck timer: */
Jordan Crousef97deca2017-10-20 11:06:57 -0600544 if (ring->seqno > ring->hangcheck_fence)
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400545 hangcheck_timer_reset(gpu);
Rob Clark6b8819c2013-09-11 17:14:30 -0400546
547 /* workaround for missing irq: */
548 queue_work(priv->wq, &gpu->retire_work);
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400549}
550
551/*
Rob Clark70c70f02014-05-30 14:49:43 -0400552 * Performance Counters:
553 */
554
555/* called under perf_lock */
556static int update_hw_cntrs(struct msm_gpu *gpu, uint32_t ncntrs, uint32_t *cntrs)
557{
558 uint32_t current_cntrs[ARRAY_SIZE(gpu->last_cntrs)];
559 int i, n = min(ncntrs, gpu->num_perfcntrs);
560
561 /* read current values: */
562 for (i = 0; i < gpu->num_perfcntrs; i++)
563 current_cntrs[i] = gpu_read(gpu, gpu->perfcntrs[i].sample_reg);
564
565 /* update cntrs: */
566 for (i = 0; i < n; i++)
567 cntrs[i] = current_cntrs[i] - gpu->last_cntrs[i];
568
569 /* save current values: */
570 for (i = 0; i < gpu->num_perfcntrs; i++)
571 gpu->last_cntrs[i] = current_cntrs[i];
572
573 return n;
574}
575
576static void update_sw_cntrs(struct msm_gpu *gpu)
577{
578 ktime_t time;
579 uint32_t elapsed;
580 unsigned long flags;
581
582 spin_lock_irqsave(&gpu->perf_lock, flags);
583 if (!gpu->perfcntr_active)
584 goto out;
585
586 time = ktime_get();
587 elapsed = ktime_to_us(ktime_sub(time, gpu->last_sample.time));
588
589 gpu->totaltime += elapsed;
590 if (gpu->last_sample.active)
591 gpu->activetime += elapsed;
592
593 gpu->last_sample.active = msm_gpu_active(gpu);
594 gpu->last_sample.time = time;
595
596out:
597 spin_unlock_irqrestore(&gpu->perf_lock, flags);
598}
599
600void msm_gpu_perfcntr_start(struct msm_gpu *gpu)
601{
602 unsigned long flags;
603
Rob Clarkeeb75472017-02-10 15:36:33 -0500604 pm_runtime_get_sync(&gpu->pdev->dev);
605
Rob Clark70c70f02014-05-30 14:49:43 -0400606 spin_lock_irqsave(&gpu->perf_lock, flags);
607 /* we could dynamically enable/disable perfcntr registers too.. */
608 gpu->last_sample.active = msm_gpu_active(gpu);
609 gpu->last_sample.time = ktime_get();
610 gpu->activetime = gpu->totaltime = 0;
611 gpu->perfcntr_active = true;
612 update_hw_cntrs(gpu, 0, NULL);
613 spin_unlock_irqrestore(&gpu->perf_lock, flags);
614}
615
616void msm_gpu_perfcntr_stop(struct msm_gpu *gpu)
617{
618 gpu->perfcntr_active = false;
Rob Clarkeeb75472017-02-10 15:36:33 -0500619 pm_runtime_put_sync(&gpu->pdev->dev);
Rob Clark70c70f02014-05-30 14:49:43 -0400620}
621
622/* returns -errno or # of cntrs sampled */
623int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
624 uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs)
625{
626 unsigned long flags;
627 int ret;
628
629 spin_lock_irqsave(&gpu->perf_lock, flags);
630
631 if (!gpu->perfcntr_active) {
632 ret = -EINVAL;
633 goto out;
634 }
635
636 *activetime = gpu->activetime;
637 *totaltime = gpu->totaltime;
638
639 gpu->activetime = gpu->totaltime = 0;
640
641 ret = update_hw_cntrs(gpu, ncntrs, cntrs);
642
643out:
644 spin_unlock_irqrestore(&gpu->perf_lock, flags);
645
646 return ret;
647}
648
649/*
Rob Clark7198e6b2013-07-19 12:59:32 -0400650 * Cmdstream submission/retirement:
651 */
652
Rob Clark7d12a272016-03-16 16:07:38 -0400653static void retire_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
654{
655 int i;
656
657 for (i = 0; i < submit->nr_bos; i++) {
658 struct msm_gem_object *msm_obj = submit->bos[i].obj;
659 /* move to inactive: */
660 msm_gem_move_to_inactive(&msm_obj->base);
Rob Clark8bdcd942017-06-13 11:07:08 -0400661 msm_gem_put_iova(&msm_obj->base, gpu->aspace);
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100662 drm_gem_object_put(&msm_obj->base);
Rob Clark7d12a272016-03-16 16:07:38 -0400663 }
664
Rob Clarkeeb75472017-02-10 15:36:33 -0500665 pm_runtime_mark_last_busy(&gpu->pdev->dev);
666 pm_runtime_put_autosuspend(&gpu->pdev->dev);
Rob Clark40e68152016-05-03 09:50:26 -0400667 msm_gem_submit_free(submit);
Rob Clark7d12a272016-03-16 16:07:38 -0400668}
669
Rob Clarkb6295f92016-03-15 18:26:28 -0400670static void retire_submits(struct msm_gpu *gpu)
Rob Clark1a370be2015-06-07 13:46:04 -0400671{
672 struct drm_device *dev = gpu->dev;
Jordan Crousef97deca2017-10-20 11:06:57 -0600673 struct msm_gem_submit *submit, *tmp;
674 int i;
Rob Clark1a370be2015-06-07 13:46:04 -0400675
676 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
677
Jordan Crousef97deca2017-10-20 11:06:57 -0600678 /* Retire the commits starting with highest priority */
Jordan Crouseb1fc2832017-10-20 11:07:01 -0600679 for (i = 0; i < gpu->nr_rings; i++) {
Jordan Crousef97deca2017-10-20 11:06:57 -0600680 struct msm_ringbuffer *ring = gpu->rb[i];
Rob Clark1a370be2015-06-07 13:46:04 -0400681
Jordan Crousef97deca2017-10-20 11:06:57 -0600682 list_for_each_entry_safe(submit, tmp, &ring->submits, node) {
683 if (dma_fence_is_signaled(submit->fence))
684 retire_submit(gpu, submit);
Rob Clark1a370be2015-06-07 13:46:04 -0400685 }
686 }
687}
688
Rob Clark7198e6b2013-07-19 12:59:32 -0400689static void retire_worker(struct work_struct *work)
690{
691 struct msm_gpu *gpu = container_of(work, struct msm_gpu, retire_work);
692 struct drm_device *dev = gpu->dev;
Jordan Crousef97deca2017-10-20 11:06:57 -0600693 int i;
Rob Clark7198e6b2013-07-19 12:59:32 -0400694
Jordan Crousef97deca2017-10-20 11:06:57 -0600695 for (i = 0; i < gpu->nr_rings; i++)
696 update_fences(gpu, gpu->rb[i], gpu->rb[i]->memptrs->fence);
Rob Clarkedd4fc62013-09-14 14:01:55 -0400697
Rob Clark7198e6b2013-07-19 12:59:32 -0400698 mutex_lock(&dev->struct_mutex);
Rob Clarkb6295f92016-03-15 18:26:28 -0400699 retire_submits(gpu);
Rob Clark7198e6b2013-07-19 12:59:32 -0400700 mutex_unlock(&dev->struct_mutex);
701}
702
703/* call from irq handler to schedule work to retire bo's */
704void msm_gpu_retire(struct msm_gpu *gpu)
705{
706 struct msm_drm_private *priv = gpu->dev->dev_private;
707 queue_work(priv->wq, &gpu->retire_work);
Rob Clark70c70f02014-05-30 14:49:43 -0400708 update_sw_cntrs(gpu);
Rob Clark7198e6b2013-07-19 12:59:32 -0400709}
710
711/* add bo's to gpu's ring, and kick gpu: */
Rob Clarkf44d32c2016-06-16 16:37:38 -0400712void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
Rob Clark7198e6b2013-07-19 12:59:32 -0400713 struct msm_file_private *ctx)
714{
715 struct drm_device *dev = gpu->dev;
716 struct msm_drm_private *priv = dev->dev_private;
Jordan Crousef97deca2017-10-20 11:06:57 -0600717 struct msm_ringbuffer *ring = submit->ring;
Rob Clarkf44d32c2016-06-16 16:37:38 -0400718 int i;
Rob Clark7198e6b2013-07-19 12:59:32 -0400719
Rob Clark1a370be2015-06-07 13:46:04 -0400720 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
721
Rob Clarkeeb75472017-02-10 15:36:33 -0500722 pm_runtime_get_sync(&gpu->pdev->dev);
723
724 msm_gpu_hw_init(gpu);
Rob Clark37d77c32014-01-11 16:25:08 -0500725
Jordan Crousef97deca2017-10-20 11:06:57 -0600726 submit->seqno = ++ring->seqno;
727
728 list_add_tail(&submit->node, &ring->submits);
Rob Clark1a370be2015-06-07 13:46:04 -0400729
Rob Clark998b9a52017-09-15 10:46:45 -0400730 msm_rd_dump_submit(priv->rd, submit, NULL);
Rob Clarka7d3c952014-05-30 14:47:38 -0400731
Rob Clark70c70f02014-05-30 14:49:43 -0400732 update_sw_cntrs(gpu);
733
Rob Clark7198e6b2013-07-19 12:59:32 -0400734 for (i = 0; i < submit->nr_bos; i++) {
735 struct msm_gem_object *msm_obj = submit->bos[i].obj;
Rob Clark78babc12016-11-11 12:06:46 -0500736 uint64_t iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400737
738 /* can't happen yet.. but when we add 2d support we'll have
739 * to deal w/ cross-ring synchronization:
740 */
741 WARN_ON(is_active(msm_obj) && (msm_obj->gpu != gpu));
742
Rob Clark7d12a272016-03-16 16:07:38 -0400743 /* submit takes a reference to the bo and iova until retired: */
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100744 drm_gem_object_get(&msm_obj->base);
Sushmita Susheelendra0e082702017-06-13 16:52:54 -0600745 msm_gem_get_iova(&msm_obj->base,
Rob Clark8bdcd942017-06-13 11:07:08 -0400746 submit->gpu->aspace, &iova);
Rob Clark7198e6b2013-07-19 12:59:32 -0400747
Rob Clarkbf6811f2013-09-01 13:25:09 -0400748 if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)
749 msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence);
Rob Clarkb6295f92016-03-15 18:26:28 -0400750 else if (submit->bos[i].flags & MSM_SUBMIT_BO_READ)
751 msm_gem_move_to_active(&msm_obj->base, gpu, false, submit->fence);
Rob Clark7198e6b2013-07-19 12:59:32 -0400752 }
Rob Clark1a370be2015-06-07 13:46:04 -0400753
Rob Clark1193c3b2016-05-03 09:46:49 -0400754 gpu->funcs->submit(gpu, submit, ctx);
Rob Clark1a370be2015-06-07 13:46:04 -0400755 priv->lastctx = ctx;
756
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400757 hangcheck_timer_reset(gpu);
Rob Clark7198e6b2013-07-19 12:59:32 -0400758}
759
760/*
761 * Init/Cleanup:
762 */
763
764static irqreturn_t irq_handler(int irq, void *data)
765{
766 struct msm_gpu *gpu = data;
767 return gpu->funcs->irq(gpu);
768}
769
Jordan Crouse98db8032017-03-07 10:02:56 -0700770static int get_clocks(struct platform_device *pdev, struct msm_gpu *gpu)
771{
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600772 int ret = msm_clk_bulk_get(&pdev->dev, &gpu->grp_clks);
Jordan Crouse98db8032017-03-07 10:02:56 -0700773
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600774 if (ret < 1) {
Jordan Crouse98db8032017-03-07 10:02:56 -0700775 gpu->nr_clocks = 0;
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600776 return ret;
Jordan Crouse98db8032017-03-07 10:02:56 -0700777 }
778
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600779 gpu->nr_clocks = ret;
Jordan Crouse98db8032017-03-07 10:02:56 -0700780
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600781 gpu->core_clk = msm_clk_bulk_get_clock(gpu->grp_clks,
782 gpu->nr_clocks, "core");
Jordan Crouse98db8032017-03-07 10:02:56 -0700783
Jordan Crouse8e54eea2018-08-06 11:33:21 -0600784 gpu->rbbmtimer_clk = msm_clk_bulk_get_clock(gpu->grp_clks,
785 gpu->nr_clocks, "rbbmtimer");
Jordan Crouse98db8032017-03-07 10:02:56 -0700786
787 return 0;
788}
Rob Clark7198e6b2013-07-19 12:59:32 -0400789
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600790static struct msm_gem_address_space *
791msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
792 uint64_t va_start, uint64_t va_end)
793{
794 struct iommu_domain *iommu;
795 struct msm_gem_address_space *aspace;
796 int ret;
797
798 /*
799 * Setup IOMMU.. eventually we will (I think) do this once per context
800 * and have separate page tables per context. For now, to keep things
801 * simple and to get something working, just use a single address space:
802 */
803 iommu = iommu_domain_alloc(&platform_bus_type);
804 if (!iommu)
805 return NULL;
806
807 iommu->geometry.aperture_start = va_start;
808 iommu->geometry.aperture_end = va_end;
809
810 dev_info(gpu->dev->dev, "%s: using IOMMU\n", gpu->name);
811
812 aspace = msm_gem_address_space_create(&pdev->dev, iommu, "gpu");
813 if (IS_ERR(aspace)) {
814 dev_err(gpu->dev->dev, "failed to init iommu: %ld\n",
815 PTR_ERR(aspace));
816 iommu_domain_free(iommu);
817 return ERR_CAST(aspace);
818 }
819
820 ret = aspace->mmu->funcs->attach(aspace->mmu, NULL, 0);
821 if (ret) {
822 msm_gem_address_space_put(aspace);
823 return ERR_PTR(ret);
824 }
825
826 return aspace;
827}
828
Rob Clark7198e6b2013-07-19 12:59:32 -0400829int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
830 struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
Jordan Crouse5770fc72017-05-08 14:35:03 -0600831 const char *name, struct msm_gpu_config *config)
Rob Clark7198e6b2013-07-19 12:59:32 -0400832{
Jordan Crousef97deca2017-10-20 11:06:57 -0600833 int i, ret, nr_rings = config->nr_rings;
834 void *memptrs;
835 uint64_t memptrs_iova;
Rob Clark7198e6b2013-07-19 12:59:32 -0400836
Rob Clark70c70f02014-05-30 14:49:43 -0400837 if (WARN_ON(gpu->num_perfcntrs > ARRAY_SIZE(gpu->last_cntrs)))
838 gpu->num_perfcntrs = ARRAY_SIZE(gpu->last_cntrs);
839
Rob Clark7198e6b2013-07-19 12:59:32 -0400840 gpu->dev = drm;
841 gpu->funcs = funcs;
842 gpu->name = name;
843
844 INIT_LIST_HEAD(&gpu->active_list);
845 INIT_WORK(&gpu->retire_work, retire_worker);
Rob Clarkbd6f82d2013-08-24 14:20:38 -0400846 INIT_WORK(&gpu->recover_work, recover_worker);
847
Rob Clark1a370be2015-06-07 13:46:04 -0400848
Kees Cooke99e88a2017-10-16 14:43:17 -0700849 timer_setup(&gpu->hangcheck_timer, hangcheck_handler, 0);
Rob Clark7198e6b2013-07-19 12:59:32 -0400850
Rob Clark70c70f02014-05-30 14:49:43 -0400851 spin_lock_init(&gpu->perf_lock);
852
Rob Clark7198e6b2013-07-19 12:59:32 -0400853
854 /* Map registers: */
Jordan Crouse5770fc72017-05-08 14:35:03 -0600855 gpu->mmio = msm_ioremap(pdev, config->ioname, name);
Rob Clark7198e6b2013-07-19 12:59:32 -0400856 if (IS_ERR(gpu->mmio)) {
857 ret = PTR_ERR(gpu->mmio);
858 goto fail;
859 }
860
861 /* Get Interrupt: */
Jordan Crouse5770fc72017-05-08 14:35:03 -0600862 gpu->irq = platform_get_irq_byname(pdev, config->irqname);
Rob Clark7198e6b2013-07-19 12:59:32 -0400863 if (gpu->irq < 0) {
864 ret = gpu->irq;
865 dev_err(drm->dev, "failed to get irq: %d\n", ret);
866 goto fail;
867 }
868
869 ret = devm_request_irq(&pdev->dev, gpu->irq, irq_handler,
870 IRQF_TRIGGER_HIGH, gpu->name, gpu);
871 if (ret) {
872 dev_err(drm->dev, "failed to request IRQ%u: %d\n", gpu->irq, ret);
873 goto fail;
874 }
875
Jordan Crouse98db8032017-03-07 10:02:56 -0700876 ret = get_clocks(pdev, gpu);
877 if (ret)
878 goto fail;
Rob Clark7198e6b2013-07-19 12:59:32 -0400879
Rob Clark720c3bb2017-01-30 11:30:58 -0500880 gpu->ebi1_clk = msm_clk_get(pdev, "bus");
Rob Clark7198e6b2013-07-19 12:59:32 -0400881 DBG("ebi1_clk: %p", gpu->ebi1_clk);
882 if (IS_ERR(gpu->ebi1_clk))
883 gpu->ebi1_clk = NULL;
884
885 /* Acquire regulators: */
886 gpu->gpu_reg = devm_regulator_get(&pdev->dev, "vdd");
887 DBG("gpu_reg: %p", gpu->gpu_reg);
888 if (IS_ERR(gpu->gpu_reg))
889 gpu->gpu_reg = NULL;
890
891 gpu->gpu_cx = devm_regulator_get(&pdev->dev, "vddcx");
892 DBG("gpu_cx: %p", gpu->gpu_cx);
893 if (IS_ERR(gpu->gpu_cx))
894 gpu->gpu_cx = NULL;
895
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600896 gpu->pdev = pdev;
897 platform_set_drvdata(pdev, gpu);
Rob Clark667ce332016-09-28 19:58:32 -0400898
Jordan Crousef91c14a2018-01-10 10:41:54 -0700899 msm_devfreq_init(gpu);
900
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600901 gpu->aspace = msm_gpu_create_address_space(gpu, pdev,
902 config->va_start, config->va_end);
903
904 if (gpu->aspace == NULL)
Rob Clark871d8122013-11-16 12:56:06 -0500905 dev_info(drm->dev, "%s: no IOMMU, fallback to VRAM carveout!\n", name);
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600906 else if (IS_ERR(gpu->aspace)) {
907 ret = PTR_ERR(gpu->aspace);
908 goto fail;
Rob Clark7198e6b2013-07-19 12:59:32 -0400909 }
Rob Clarka1ad3522014-07-11 11:59:22 -0400910
Jordan Crousef97deca2017-10-20 11:06:57 -0600911 memptrs = msm_gem_kernel_new(drm, sizeof(*gpu->memptrs_bo),
Jordan Crousecd414f32017-10-20 11:06:56 -0600912 MSM_BO_UNCACHED, gpu->aspace, &gpu->memptrs_bo,
Jordan Crousef97deca2017-10-20 11:06:57 -0600913 &memptrs_iova);
Jordan Crousecd414f32017-10-20 11:06:56 -0600914
Jordan Crousef97deca2017-10-20 11:06:57 -0600915 if (IS_ERR(memptrs)) {
916 ret = PTR_ERR(memptrs);
Jordan Crousecd414f32017-10-20 11:06:56 -0600917 dev_err(drm->dev, "could not allocate memptrs: %d\n", ret);
918 goto fail;
919 }
920
Jordan Crousef97deca2017-10-20 11:06:57 -0600921 if (nr_rings > ARRAY_SIZE(gpu->rb)) {
Arnd Bergmann39ae0d32017-08-03 13:50:48 +0200922 DRM_DEV_INFO_ONCE(drm->dev, "Only creating %zu ringbuffers\n",
Jordan Crousef97deca2017-10-20 11:06:57 -0600923 ARRAY_SIZE(gpu->rb));
924 nr_rings = ARRAY_SIZE(gpu->rb);
Rob Clark7198e6b2013-07-19 12:59:32 -0400925 }
926
Jordan Crousef97deca2017-10-20 11:06:57 -0600927 /* Create ringbuffer(s): */
928 for (i = 0; i < nr_rings; i++) {
929 gpu->rb[i] = msm_ringbuffer_new(gpu, i, memptrs, memptrs_iova);
930
931 if (IS_ERR(gpu->rb[i])) {
932 ret = PTR_ERR(gpu->rb[i]);
933 dev_err(drm->dev,
934 "could not create ringbuffer %d: %d\n", i, ret);
935 goto fail;
936 }
937
938 memptrs += sizeof(struct msm_rbmemptrs);
939 memptrs_iova += sizeof(struct msm_rbmemptrs);
940 }
941
942 gpu->nr_rings = nr_rings;
943
Rob Clark7198e6b2013-07-19 12:59:32 -0400944 return 0;
945
946fail:
Jordan Crousef97deca2017-10-20 11:06:57 -0600947 for (i = 0; i < ARRAY_SIZE(gpu->rb); i++) {
948 msm_ringbuffer_destroy(gpu->rb[i]);
949 gpu->rb[i] = NULL;
950 }
951
Jordan Crousecd414f32017-10-20 11:06:56 -0600952 if (gpu->memptrs_bo) {
953 msm_gem_put_vaddr(gpu->memptrs_bo);
954 msm_gem_put_iova(gpu->memptrs_bo, gpu->aspace);
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100955 drm_gem_object_put_unlocked(gpu->memptrs_bo);
Jordan Crousecd414f32017-10-20 11:06:56 -0600956 }
957
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600958 platform_set_drvdata(pdev, NULL);
Rob Clark7198e6b2013-07-19 12:59:32 -0400959 return ret;
960}
961
962void msm_gpu_cleanup(struct msm_gpu *gpu)
963{
Jordan Crousef97deca2017-10-20 11:06:57 -0600964 int i;
965
Rob Clark7198e6b2013-07-19 12:59:32 -0400966 DBG("%s", gpu->name);
967
968 WARN_ON(!list_empty(&gpu->active_list));
969
Jordan Crousef97deca2017-10-20 11:06:57 -0600970 for (i = 0; i < ARRAY_SIZE(gpu->rb); i++) {
971 msm_ringbuffer_destroy(gpu->rb[i]);
972 gpu->rb[i] = NULL;
Rob Clark7198e6b2013-07-19 12:59:32 -0400973 }
Jordan Crousecd414f32017-10-20 11:06:56 -0600974
975 if (gpu->memptrs_bo) {
976 msm_gem_put_vaddr(gpu->memptrs_bo);
977 msm_gem_put_iova(gpu->memptrs_bo, gpu->aspace);
Steve Kowalikdc9a9b32018-01-26 14:55:54 +1100978 drm_gem_object_put_unlocked(gpu->memptrs_bo);
Jordan Crousecd414f32017-10-20 11:06:56 -0600979 }
980
981 if (!IS_ERR_OR_NULL(gpu->aspace)) {
Jordan Crouse1267a4d2017-07-27 10:42:39 -0600982 gpu->aspace->mmu->funcs->detach(gpu->aspace->mmu,
983 NULL, 0);
984 msm_gem_address_space_put(gpu->aspace);
985 }
Rob Clark7198e6b2013-07-19 12:59:32 -0400986}