msm_gpu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  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. #include "msm_gpu.h"
  18. #include "msm_gem.h"
  19. #include "msm_mmu.h"
  20. #include "msm_fence.h"
  21. /*
  22. * Power Management:
  23. */
  24. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  25. #include <mach/board.h>
  26. static void bs_init(struct msm_gpu *gpu)
  27. {
  28. if (gpu->bus_scale_table) {
  29. gpu->bsc = msm_bus_scale_register_client(gpu->bus_scale_table);
  30. DBG("bus scale client: %08x", gpu->bsc);
  31. }
  32. }
  33. static void bs_fini(struct msm_gpu *gpu)
  34. {
  35. if (gpu->bsc) {
  36. msm_bus_scale_unregister_client(gpu->bsc);
  37. gpu->bsc = 0;
  38. }
  39. }
  40. static void bs_set(struct msm_gpu *gpu, int idx)
  41. {
  42. if (gpu->bsc) {
  43. DBG("set bus scaling: %d", idx);
  44. msm_bus_scale_client_update_request(gpu->bsc, idx);
  45. }
  46. }
  47. #else
  48. static void bs_init(struct msm_gpu *gpu) {}
  49. static void bs_fini(struct msm_gpu *gpu) {}
  50. static void bs_set(struct msm_gpu *gpu, int idx) {}
  51. #endif
  52. static int enable_pwrrail(struct msm_gpu *gpu)
  53. {
  54. struct drm_device *dev = gpu->dev;
  55. int ret = 0;
  56. if (gpu->gpu_reg) {
  57. ret = regulator_enable(gpu->gpu_reg);
  58. if (ret) {
  59. dev_err(dev->dev, "failed to enable 'gpu_reg': %d\n", ret);
  60. return ret;
  61. }
  62. }
  63. if (gpu->gpu_cx) {
  64. ret = regulator_enable(gpu->gpu_cx);
  65. if (ret) {
  66. dev_err(dev->dev, "failed to enable 'gpu_cx': %d\n", ret);
  67. return ret;
  68. }
  69. }
  70. return 0;
  71. }
  72. static int disable_pwrrail(struct msm_gpu *gpu)
  73. {
  74. if (gpu->gpu_cx)
  75. regulator_disable(gpu->gpu_cx);
  76. if (gpu->gpu_reg)
  77. regulator_disable(gpu->gpu_reg);
  78. return 0;
  79. }
  80. static int enable_clk(struct msm_gpu *gpu)
  81. {
  82. int i;
  83. if (gpu->core_clk && gpu->fast_rate)
  84. clk_set_rate(gpu->core_clk, gpu->fast_rate);
  85. /* Set the RBBM timer rate to 19.2Mhz */
  86. if (gpu->rbbmtimer_clk)
  87. clk_set_rate(gpu->rbbmtimer_clk, 19200000);
  88. for (i = gpu->nr_clocks - 1; i >= 0; i--)
  89. if (gpu->grp_clks[i])
  90. clk_prepare(gpu->grp_clks[i]);
  91. for (i = gpu->nr_clocks - 1; i >= 0; i--)
  92. if (gpu->grp_clks[i])
  93. clk_enable(gpu->grp_clks[i]);
  94. return 0;
  95. }
  96. static int disable_clk(struct msm_gpu *gpu)
  97. {
  98. int i;
  99. for (i = gpu->nr_clocks - 1; i >= 0; i--)
  100. if (gpu->grp_clks[i])
  101. clk_disable(gpu->grp_clks[i]);
  102. for (i = gpu->nr_clocks - 1; i >= 0; i--)
  103. if (gpu->grp_clks[i])
  104. clk_unprepare(gpu->grp_clks[i]);
  105. /*
  106. * Set the clock to a deliberately low rate. On older targets the clock
  107. * speed had to be non zero to avoid problems. On newer targets this
  108. * will be rounded down to zero anyway so it all works out.
  109. */
  110. if (gpu->core_clk)
  111. clk_set_rate(gpu->core_clk, 27000000);
  112. if (gpu->rbbmtimer_clk)
  113. clk_set_rate(gpu->rbbmtimer_clk, 0);
  114. return 0;
  115. }
  116. static int enable_axi(struct msm_gpu *gpu)
  117. {
  118. if (gpu->ebi1_clk)
  119. clk_prepare_enable(gpu->ebi1_clk);
  120. if (gpu->bus_freq)
  121. bs_set(gpu, gpu->bus_freq);
  122. return 0;
  123. }
  124. static int disable_axi(struct msm_gpu *gpu)
  125. {
  126. if (gpu->ebi1_clk)
  127. clk_disable_unprepare(gpu->ebi1_clk);
  128. if (gpu->bus_freq)
  129. bs_set(gpu, 0);
  130. return 0;
  131. }
  132. int msm_gpu_pm_resume(struct msm_gpu *gpu)
  133. {
  134. int ret;
  135. DBG("%s", gpu->name);
  136. ret = enable_pwrrail(gpu);
  137. if (ret)
  138. return ret;
  139. ret = enable_clk(gpu);
  140. if (ret)
  141. return ret;
  142. ret = enable_axi(gpu);
  143. if (ret)
  144. return ret;
  145. gpu->needs_hw_init = true;
  146. return 0;
  147. }
  148. int msm_gpu_pm_suspend(struct msm_gpu *gpu)
  149. {
  150. int ret;
  151. DBG("%s", gpu->name);
  152. ret = disable_axi(gpu);
  153. if (ret)
  154. return ret;
  155. ret = disable_clk(gpu);
  156. if (ret)
  157. return ret;
  158. ret = disable_pwrrail(gpu);
  159. if (ret)
  160. return ret;
  161. return 0;
  162. }
  163. int msm_gpu_hw_init(struct msm_gpu *gpu)
  164. {
  165. int ret;
  166. if (!gpu->needs_hw_init)
  167. return 0;
  168. disable_irq(gpu->irq);
  169. ret = gpu->funcs->hw_init(gpu);
  170. if (!ret)
  171. gpu->needs_hw_init = false;
  172. enable_irq(gpu->irq);
  173. return ret;
  174. }
  175. /*
  176. * Hangcheck detection for locked gpu:
  177. */
  178. static void retire_submits(struct msm_gpu *gpu);
  179. static void recover_worker(struct work_struct *work)
  180. {
  181. struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work);
  182. struct drm_device *dev = gpu->dev;
  183. struct msm_gem_submit *submit;
  184. uint32_t fence = gpu->funcs->last_fence(gpu);
  185. msm_update_fence(gpu->fctx, fence + 1);
  186. mutex_lock(&dev->struct_mutex);
  187. dev_err(dev->dev, "%s: hangcheck recover!\n", gpu->name);
  188. list_for_each_entry(submit, &gpu->submit_list, node) {
  189. if (submit->fence->seqno == (fence + 1)) {
  190. struct task_struct *task;
  191. rcu_read_lock();
  192. task = pid_task(submit->pid, PIDTYPE_PID);
  193. if (task) {
  194. dev_err(dev->dev, "%s: offending task: %s\n",
  195. gpu->name, task->comm);
  196. }
  197. rcu_read_unlock();
  198. break;
  199. }
  200. }
  201. if (msm_gpu_active(gpu)) {
  202. /* retire completed submits, plus the one that hung: */
  203. retire_submits(gpu);
  204. pm_runtime_get_sync(&gpu->pdev->dev);
  205. gpu->funcs->recover(gpu);
  206. pm_runtime_put_sync(&gpu->pdev->dev);
  207. /* replay the remaining submits after the one that hung: */
  208. list_for_each_entry(submit, &gpu->submit_list, node) {
  209. gpu->funcs->submit(gpu, submit, NULL);
  210. }
  211. }
  212. mutex_unlock(&dev->struct_mutex);
  213. msm_gpu_retire(gpu);
  214. }
  215. static void hangcheck_timer_reset(struct msm_gpu *gpu)
  216. {
  217. DBG("%s", gpu->name);
  218. mod_timer(&gpu->hangcheck_timer,
  219. round_jiffies_up(jiffies + DRM_MSM_HANGCHECK_JIFFIES));
  220. }
  221. static void hangcheck_handler(unsigned long data)
  222. {
  223. struct msm_gpu *gpu = (struct msm_gpu *)data;
  224. struct drm_device *dev = gpu->dev;
  225. struct msm_drm_private *priv = dev->dev_private;
  226. uint32_t fence = gpu->funcs->last_fence(gpu);
  227. if (fence != gpu->hangcheck_fence) {
  228. /* some progress has been made.. ya! */
  229. gpu->hangcheck_fence = fence;
  230. } else if (fence < gpu->fctx->last_fence) {
  231. /* no progress and not done.. hung! */
  232. gpu->hangcheck_fence = fence;
  233. dev_err(dev->dev, "%s: hangcheck detected gpu lockup!\n",
  234. gpu->name);
  235. dev_err(dev->dev, "%s: completed fence: %u\n",
  236. gpu->name, fence);
  237. dev_err(dev->dev, "%s: submitted fence: %u\n",
  238. gpu->name, gpu->fctx->last_fence);
  239. queue_work(priv->wq, &gpu->recover_work);
  240. }
  241. /* if still more pending work, reset the hangcheck timer: */
  242. if (gpu->fctx->last_fence > gpu->hangcheck_fence)
  243. hangcheck_timer_reset(gpu);
  244. /* workaround for missing irq: */
  245. queue_work(priv->wq, &gpu->retire_work);
  246. }
  247. /*
  248. * Performance Counters:
  249. */
  250. /* called under perf_lock */
  251. static int update_hw_cntrs(struct msm_gpu *gpu, uint32_t ncntrs, uint32_t *cntrs)
  252. {
  253. uint32_t current_cntrs[ARRAY_SIZE(gpu->last_cntrs)];
  254. int i, n = min(ncntrs, gpu->num_perfcntrs);
  255. /* read current values: */
  256. for (i = 0; i < gpu->num_perfcntrs; i++)
  257. current_cntrs[i] = gpu_read(gpu, gpu->perfcntrs[i].sample_reg);
  258. /* update cntrs: */
  259. for (i = 0; i < n; i++)
  260. cntrs[i] = current_cntrs[i] - gpu->last_cntrs[i];
  261. /* save current values: */
  262. for (i = 0; i < gpu->num_perfcntrs; i++)
  263. gpu->last_cntrs[i] = current_cntrs[i];
  264. return n;
  265. }
  266. static void update_sw_cntrs(struct msm_gpu *gpu)
  267. {
  268. ktime_t time;
  269. uint32_t elapsed;
  270. unsigned long flags;
  271. spin_lock_irqsave(&gpu->perf_lock, flags);
  272. if (!gpu->perfcntr_active)
  273. goto out;
  274. time = ktime_get();
  275. elapsed = ktime_to_us(ktime_sub(time, gpu->last_sample.time));
  276. gpu->totaltime += elapsed;
  277. if (gpu->last_sample.active)
  278. gpu->activetime += elapsed;
  279. gpu->last_sample.active = msm_gpu_active(gpu);
  280. gpu->last_sample.time = time;
  281. out:
  282. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  283. }
  284. void msm_gpu_perfcntr_start(struct msm_gpu *gpu)
  285. {
  286. unsigned long flags;
  287. pm_runtime_get_sync(&gpu->pdev->dev);
  288. spin_lock_irqsave(&gpu->perf_lock, flags);
  289. /* we could dynamically enable/disable perfcntr registers too.. */
  290. gpu->last_sample.active = msm_gpu_active(gpu);
  291. gpu->last_sample.time = ktime_get();
  292. gpu->activetime = gpu->totaltime = 0;
  293. gpu->perfcntr_active = true;
  294. update_hw_cntrs(gpu, 0, NULL);
  295. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  296. }
  297. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu)
  298. {
  299. gpu->perfcntr_active = false;
  300. pm_runtime_put_sync(&gpu->pdev->dev);
  301. }
  302. /* returns -errno or # of cntrs sampled */
  303. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  304. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs)
  305. {
  306. unsigned long flags;
  307. int ret;
  308. spin_lock_irqsave(&gpu->perf_lock, flags);
  309. if (!gpu->perfcntr_active) {
  310. ret = -EINVAL;
  311. goto out;
  312. }
  313. *activetime = gpu->activetime;
  314. *totaltime = gpu->totaltime;
  315. gpu->activetime = gpu->totaltime = 0;
  316. ret = update_hw_cntrs(gpu, ncntrs, cntrs);
  317. out:
  318. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  319. return ret;
  320. }
  321. /*
  322. * Cmdstream submission/retirement:
  323. */
  324. static void retire_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
  325. {
  326. int i;
  327. for (i = 0; i < submit->nr_bos; i++) {
  328. struct msm_gem_object *msm_obj = submit->bos[i].obj;
  329. /* move to inactive: */
  330. msm_gem_move_to_inactive(&msm_obj->base);
  331. msm_gem_put_iova(&msm_obj->base, gpu->id);
  332. drm_gem_object_unreference(&msm_obj->base);
  333. }
  334. pm_runtime_mark_last_busy(&gpu->pdev->dev);
  335. pm_runtime_put_autosuspend(&gpu->pdev->dev);
  336. msm_gem_submit_free(submit);
  337. }
  338. static void retire_submits(struct msm_gpu *gpu)
  339. {
  340. struct drm_device *dev = gpu->dev;
  341. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  342. while (!list_empty(&gpu->submit_list)) {
  343. struct msm_gem_submit *submit;
  344. submit = list_first_entry(&gpu->submit_list,
  345. struct msm_gem_submit, node);
  346. if (dma_fence_is_signaled(submit->fence)) {
  347. retire_submit(gpu, submit);
  348. } else {
  349. break;
  350. }
  351. }
  352. }
  353. static void retire_worker(struct work_struct *work)
  354. {
  355. struct msm_gpu *gpu = container_of(work, struct msm_gpu, retire_work);
  356. struct drm_device *dev = gpu->dev;
  357. uint32_t fence = gpu->funcs->last_fence(gpu);
  358. msm_update_fence(gpu->fctx, fence);
  359. mutex_lock(&dev->struct_mutex);
  360. retire_submits(gpu);
  361. mutex_unlock(&dev->struct_mutex);
  362. }
  363. /* call from irq handler to schedule work to retire bo's */
  364. void msm_gpu_retire(struct msm_gpu *gpu)
  365. {
  366. struct msm_drm_private *priv = gpu->dev->dev_private;
  367. queue_work(priv->wq, &gpu->retire_work);
  368. update_sw_cntrs(gpu);
  369. }
  370. /* add bo's to gpu's ring, and kick gpu: */
  371. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  372. struct msm_file_private *ctx)
  373. {
  374. struct drm_device *dev = gpu->dev;
  375. struct msm_drm_private *priv = dev->dev_private;
  376. int i;
  377. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  378. pm_runtime_get_sync(&gpu->pdev->dev);
  379. msm_gpu_hw_init(gpu);
  380. list_add_tail(&submit->node, &gpu->submit_list);
  381. msm_rd_dump_submit(submit);
  382. update_sw_cntrs(gpu);
  383. for (i = 0; i < submit->nr_bos; i++) {
  384. struct msm_gem_object *msm_obj = submit->bos[i].obj;
  385. uint64_t iova;
  386. /* can't happen yet.. but when we add 2d support we'll have
  387. * to deal w/ cross-ring synchronization:
  388. */
  389. WARN_ON(is_active(msm_obj) && (msm_obj->gpu != gpu));
  390. /* submit takes a reference to the bo and iova until retired: */
  391. drm_gem_object_reference(&msm_obj->base);
  392. msm_gem_get_iova_locked(&msm_obj->base,
  393. submit->gpu->id, &iova);
  394. if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)
  395. msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence);
  396. else if (submit->bos[i].flags & MSM_SUBMIT_BO_READ)
  397. msm_gem_move_to_active(&msm_obj->base, gpu, false, submit->fence);
  398. }
  399. gpu->funcs->submit(gpu, submit, ctx);
  400. priv->lastctx = ctx;
  401. hangcheck_timer_reset(gpu);
  402. }
  403. /*
  404. * Init/Cleanup:
  405. */
  406. static irqreturn_t irq_handler(int irq, void *data)
  407. {
  408. struct msm_gpu *gpu = data;
  409. return gpu->funcs->irq(gpu);
  410. }
  411. static struct clk *get_clock(struct device *dev, const char *name)
  412. {
  413. struct clk *clk = devm_clk_get(dev, name);
  414. return IS_ERR(clk) ? NULL : clk;
  415. }
  416. static int get_clocks(struct platform_device *pdev, struct msm_gpu *gpu)
  417. {
  418. struct device *dev = &pdev->dev;
  419. struct property *prop;
  420. const char *name;
  421. int i = 0;
  422. gpu->nr_clocks = of_property_count_strings(dev->of_node, "clock-names");
  423. if (gpu->nr_clocks < 1) {
  424. gpu->nr_clocks = 0;
  425. return 0;
  426. }
  427. gpu->grp_clks = devm_kcalloc(dev, sizeof(struct clk *), gpu->nr_clocks,
  428. GFP_KERNEL);
  429. if (!gpu->grp_clks)
  430. return -ENOMEM;
  431. of_property_for_each_string(dev->of_node, "clock-names", prop, name) {
  432. gpu->grp_clks[i] = get_clock(dev, name);
  433. /* Remember the key clocks that we need to control later */
  434. if (!strcmp(name, "core") || !strcmp(name, "core_clk"))
  435. gpu->core_clk = gpu->grp_clks[i];
  436. else if (!strcmp(name, "rbbmtimer") || !strcmp(name, "rbbmtimer_clk"))
  437. gpu->rbbmtimer_clk = gpu->grp_clks[i];
  438. ++i;
  439. }
  440. return 0;
  441. }
  442. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  443. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  444. const char *name, const char *ioname, const char *irqname, int ringsz)
  445. {
  446. struct iommu_domain *iommu;
  447. int ret;
  448. if (WARN_ON(gpu->num_perfcntrs > ARRAY_SIZE(gpu->last_cntrs)))
  449. gpu->num_perfcntrs = ARRAY_SIZE(gpu->last_cntrs);
  450. gpu->dev = drm;
  451. gpu->funcs = funcs;
  452. gpu->name = name;
  453. gpu->fctx = msm_fence_context_alloc(drm, name);
  454. if (IS_ERR(gpu->fctx)) {
  455. ret = PTR_ERR(gpu->fctx);
  456. gpu->fctx = NULL;
  457. goto fail;
  458. }
  459. INIT_LIST_HEAD(&gpu->active_list);
  460. INIT_WORK(&gpu->retire_work, retire_worker);
  461. INIT_WORK(&gpu->recover_work, recover_worker);
  462. INIT_LIST_HEAD(&gpu->submit_list);
  463. setup_timer(&gpu->hangcheck_timer, hangcheck_handler,
  464. (unsigned long)gpu);
  465. spin_lock_init(&gpu->perf_lock);
  466. /* Map registers: */
  467. gpu->mmio = msm_ioremap(pdev, ioname, name);
  468. if (IS_ERR(gpu->mmio)) {
  469. ret = PTR_ERR(gpu->mmio);
  470. goto fail;
  471. }
  472. /* Get Interrupt: */
  473. gpu->irq = platform_get_irq_byname(pdev, irqname);
  474. if (gpu->irq < 0) {
  475. ret = gpu->irq;
  476. dev_err(drm->dev, "failed to get irq: %d\n", ret);
  477. goto fail;
  478. }
  479. ret = devm_request_irq(&pdev->dev, gpu->irq, irq_handler,
  480. IRQF_TRIGGER_HIGH, gpu->name, gpu);
  481. if (ret) {
  482. dev_err(drm->dev, "failed to request IRQ%u: %d\n", gpu->irq, ret);
  483. goto fail;
  484. }
  485. ret = get_clocks(pdev, gpu);
  486. if (ret)
  487. goto fail;
  488. gpu->ebi1_clk = msm_clk_get(pdev, "bus");
  489. DBG("ebi1_clk: %p", gpu->ebi1_clk);
  490. if (IS_ERR(gpu->ebi1_clk))
  491. gpu->ebi1_clk = NULL;
  492. /* Acquire regulators: */
  493. gpu->gpu_reg = devm_regulator_get(&pdev->dev, "vdd");
  494. DBG("gpu_reg: %p", gpu->gpu_reg);
  495. if (IS_ERR(gpu->gpu_reg))
  496. gpu->gpu_reg = NULL;
  497. gpu->gpu_cx = devm_regulator_get(&pdev->dev, "vddcx");
  498. DBG("gpu_cx: %p", gpu->gpu_cx);
  499. if (IS_ERR(gpu->gpu_cx))
  500. gpu->gpu_cx = NULL;
  501. /* Setup IOMMU.. eventually we will (I think) do this once per context
  502. * and have separate page tables per context. For now, to keep things
  503. * simple and to get something working, just use a single address space:
  504. */
  505. iommu = iommu_domain_alloc(&platform_bus_type);
  506. if (iommu) {
  507. /* TODO 32b vs 64b address space.. */
  508. iommu->geometry.aperture_start = SZ_16M;
  509. iommu->geometry.aperture_end = 0xffffffff;
  510. dev_info(drm->dev, "%s: using IOMMU\n", name);
  511. gpu->aspace = msm_gem_address_space_create(&pdev->dev,
  512. iommu, "gpu");
  513. if (IS_ERR(gpu->aspace)) {
  514. ret = PTR_ERR(gpu->aspace);
  515. dev_err(drm->dev, "failed to init iommu: %d\n", ret);
  516. gpu->aspace = NULL;
  517. iommu_domain_free(iommu);
  518. goto fail;
  519. }
  520. } else {
  521. dev_info(drm->dev, "%s: no IOMMU, fallback to VRAM carveout!\n", name);
  522. }
  523. gpu->id = msm_register_address_space(drm, gpu->aspace);
  524. /* Create ringbuffer: */
  525. mutex_lock(&drm->struct_mutex);
  526. gpu->rb = msm_ringbuffer_new(gpu, ringsz);
  527. mutex_unlock(&drm->struct_mutex);
  528. if (IS_ERR(gpu->rb)) {
  529. ret = PTR_ERR(gpu->rb);
  530. gpu->rb = NULL;
  531. dev_err(drm->dev, "could not create ringbuffer: %d\n", ret);
  532. goto fail;
  533. }
  534. gpu->pdev = pdev;
  535. platform_set_drvdata(pdev, gpu);
  536. bs_init(gpu);
  537. return 0;
  538. fail:
  539. return ret;
  540. }
  541. void msm_gpu_cleanup(struct msm_gpu *gpu)
  542. {
  543. DBG("%s", gpu->name);
  544. WARN_ON(!list_empty(&gpu->active_list));
  545. bs_fini(gpu);
  546. if (gpu->rb) {
  547. if (gpu->rb_iova)
  548. msm_gem_put_iova(gpu->rb->bo, gpu->id);
  549. msm_ringbuffer_destroy(gpu->rb);
  550. }
  551. if (gpu->fctx)
  552. msm_fence_context_free(gpu->fctx);
  553. }