msm_gpu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. WARN_ON(!mutex_is_locked(&gpu->dev->struct_mutex));
  167. if (!gpu->needs_hw_init)
  168. return 0;
  169. disable_irq(gpu->irq);
  170. ret = gpu->funcs->hw_init(gpu);
  171. if (!ret)
  172. gpu->needs_hw_init = false;
  173. enable_irq(gpu->irq);
  174. return ret;
  175. }
  176. /*
  177. * Hangcheck detection for locked gpu:
  178. */
  179. static void retire_submits(struct msm_gpu *gpu);
  180. static void recover_worker(struct work_struct *work)
  181. {
  182. struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work);
  183. struct drm_device *dev = gpu->dev;
  184. struct msm_gem_submit *submit;
  185. uint32_t fence = gpu->funcs->last_fence(gpu);
  186. msm_update_fence(gpu->fctx, fence + 1);
  187. mutex_lock(&dev->struct_mutex);
  188. dev_err(dev->dev, "%s: hangcheck recover!\n", gpu->name);
  189. list_for_each_entry(submit, &gpu->submit_list, node) {
  190. if (submit->fence->seqno == (fence + 1)) {
  191. struct task_struct *task;
  192. rcu_read_lock();
  193. task = pid_task(submit->pid, PIDTYPE_PID);
  194. if (task) {
  195. dev_err(dev->dev, "%s: offending task: %s\n",
  196. gpu->name, task->comm);
  197. }
  198. rcu_read_unlock();
  199. break;
  200. }
  201. }
  202. if (msm_gpu_active(gpu)) {
  203. /* retire completed submits, plus the one that hung: */
  204. retire_submits(gpu);
  205. pm_runtime_get_sync(&gpu->pdev->dev);
  206. gpu->funcs->recover(gpu);
  207. pm_runtime_put_sync(&gpu->pdev->dev);
  208. /* replay the remaining submits after the one that hung: */
  209. list_for_each_entry(submit, &gpu->submit_list, node) {
  210. gpu->funcs->submit(gpu, submit, NULL);
  211. }
  212. }
  213. mutex_unlock(&dev->struct_mutex);
  214. msm_gpu_retire(gpu);
  215. }
  216. static void hangcheck_timer_reset(struct msm_gpu *gpu)
  217. {
  218. DBG("%s", gpu->name);
  219. mod_timer(&gpu->hangcheck_timer,
  220. round_jiffies_up(jiffies + DRM_MSM_HANGCHECK_JIFFIES));
  221. }
  222. static void hangcheck_handler(unsigned long data)
  223. {
  224. struct msm_gpu *gpu = (struct msm_gpu *)data;
  225. struct drm_device *dev = gpu->dev;
  226. struct msm_drm_private *priv = dev->dev_private;
  227. uint32_t fence = gpu->funcs->last_fence(gpu);
  228. if (fence != gpu->hangcheck_fence) {
  229. /* some progress has been made.. ya! */
  230. gpu->hangcheck_fence = fence;
  231. } else if (fence < gpu->fctx->last_fence) {
  232. /* no progress and not done.. hung! */
  233. gpu->hangcheck_fence = fence;
  234. dev_err(dev->dev, "%s: hangcheck detected gpu lockup!\n",
  235. gpu->name);
  236. dev_err(dev->dev, "%s: completed fence: %u\n",
  237. gpu->name, fence);
  238. dev_err(dev->dev, "%s: submitted fence: %u\n",
  239. gpu->name, gpu->fctx->last_fence);
  240. queue_work(priv->wq, &gpu->recover_work);
  241. }
  242. /* if still more pending work, reset the hangcheck timer: */
  243. if (gpu->fctx->last_fence > gpu->hangcheck_fence)
  244. hangcheck_timer_reset(gpu);
  245. /* workaround for missing irq: */
  246. queue_work(priv->wq, &gpu->retire_work);
  247. }
  248. /*
  249. * Performance Counters:
  250. */
  251. /* called under perf_lock */
  252. static int update_hw_cntrs(struct msm_gpu *gpu, uint32_t ncntrs, uint32_t *cntrs)
  253. {
  254. uint32_t current_cntrs[ARRAY_SIZE(gpu->last_cntrs)];
  255. int i, n = min(ncntrs, gpu->num_perfcntrs);
  256. /* read current values: */
  257. for (i = 0; i < gpu->num_perfcntrs; i++)
  258. current_cntrs[i] = gpu_read(gpu, gpu->perfcntrs[i].sample_reg);
  259. /* update cntrs: */
  260. for (i = 0; i < n; i++)
  261. cntrs[i] = current_cntrs[i] - gpu->last_cntrs[i];
  262. /* save current values: */
  263. for (i = 0; i < gpu->num_perfcntrs; i++)
  264. gpu->last_cntrs[i] = current_cntrs[i];
  265. return n;
  266. }
  267. static void update_sw_cntrs(struct msm_gpu *gpu)
  268. {
  269. ktime_t time;
  270. uint32_t elapsed;
  271. unsigned long flags;
  272. spin_lock_irqsave(&gpu->perf_lock, flags);
  273. if (!gpu->perfcntr_active)
  274. goto out;
  275. time = ktime_get();
  276. elapsed = ktime_to_us(ktime_sub(time, gpu->last_sample.time));
  277. gpu->totaltime += elapsed;
  278. if (gpu->last_sample.active)
  279. gpu->activetime += elapsed;
  280. gpu->last_sample.active = msm_gpu_active(gpu);
  281. gpu->last_sample.time = time;
  282. out:
  283. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  284. }
  285. void msm_gpu_perfcntr_start(struct msm_gpu *gpu)
  286. {
  287. unsigned long flags;
  288. pm_runtime_get_sync(&gpu->pdev->dev);
  289. spin_lock_irqsave(&gpu->perf_lock, flags);
  290. /* we could dynamically enable/disable perfcntr registers too.. */
  291. gpu->last_sample.active = msm_gpu_active(gpu);
  292. gpu->last_sample.time = ktime_get();
  293. gpu->activetime = gpu->totaltime = 0;
  294. gpu->perfcntr_active = true;
  295. update_hw_cntrs(gpu, 0, NULL);
  296. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  297. }
  298. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu)
  299. {
  300. gpu->perfcntr_active = false;
  301. pm_runtime_put_sync(&gpu->pdev->dev);
  302. }
  303. /* returns -errno or # of cntrs sampled */
  304. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  305. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs)
  306. {
  307. unsigned long flags;
  308. int ret;
  309. spin_lock_irqsave(&gpu->perf_lock, flags);
  310. if (!gpu->perfcntr_active) {
  311. ret = -EINVAL;
  312. goto out;
  313. }
  314. *activetime = gpu->activetime;
  315. *totaltime = gpu->totaltime;
  316. gpu->activetime = gpu->totaltime = 0;
  317. ret = update_hw_cntrs(gpu, ncntrs, cntrs);
  318. out:
  319. spin_unlock_irqrestore(&gpu->perf_lock, flags);
  320. return ret;
  321. }
  322. /*
  323. * Cmdstream submission/retirement:
  324. */
  325. static void retire_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
  326. {
  327. int i;
  328. for (i = 0; i < submit->nr_bos; i++) {
  329. struct msm_gem_object *msm_obj = submit->bos[i].obj;
  330. /* move to inactive: */
  331. msm_gem_move_to_inactive(&msm_obj->base);
  332. msm_gem_put_iova(&msm_obj->base, gpu->aspace);
  333. drm_gem_object_unreference(&msm_obj->base);
  334. }
  335. pm_runtime_mark_last_busy(&gpu->pdev->dev);
  336. pm_runtime_put_autosuspend(&gpu->pdev->dev);
  337. msm_gem_submit_free(submit);
  338. }
  339. static void retire_submits(struct msm_gpu *gpu)
  340. {
  341. struct drm_device *dev = gpu->dev;
  342. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  343. while (!list_empty(&gpu->submit_list)) {
  344. struct msm_gem_submit *submit;
  345. submit = list_first_entry(&gpu->submit_list,
  346. struct msm_gem_submit, node);
  347. if (dma_fence_is_signaled(submit->fence)) {
  348. retire_submit(gpu, submit);
  349. } else {
  350. break;
  351. }
  352. }
  353. }
  354. static void retire_worker(struct work_struct *work)
  355. {
  356. struct msm_gpu *gpu = container_of(work, struct msm_gpu, retire_work);
  357. struct drm_device *dev = gpu->dev;
  358. uint32_t fence = gpu->funcs->last_fence(gpu);
  359. msm_update_fence(gpu->fctx, fence);
  360. mutex_lock(&dev->struct_mutex);
  361. retire_submits(gpu);
  362. mutex_unlock(&dev->struct_mutex);
  363. }
  364. /* call from irq handler to schedule work to retire bo's */
  365. void msm_gpu_retire(struct msm_gpu *gpu)
  366. {
  367. struct msm_drm_private *priv = gpu->dev->dev_private;
  368. queue_work(priv->wq, &gpu->retire_work);
  369. update_sw_cntrs(gpu);
  370. }
  371. /* add bo's to gpu's ring, and kick gpu: */
  372. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  373. struct msm_file_private *ctx)
  374. {
  375. struct drm_device *dev = gpu->dev;
  376. struct msm_drm_private *priv = dev->dev_private;
  377. int i;
  378. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  379. pm_runtime_get_sync(&gpu->pdev->dev);
  380. msm_gpu_hw_init(gpu);
  381. list_add_tail(&submit->node, &gpu->submit_list);
  382. msm_rd_dump_submit(submit);
  383. update_sw_cntrs(gpu);
  384. for (i = 0; i < submit->nr_bos; i++) {
  385. struct msm_gem_object *msm_obj = submit->bos[i].obj;
  386. uint64_t iova;
  387. /* can't happen yet.. but when we add 2d support we'll have
  388. * to deal w/ cross-ring synchronization:
  389. */
  390. WARN_ON(is_active(msm_obj) && (msm_obj->gpu != gpu));
  391. /* submit takes a reference to the bo and iova until retired: */
  392. drm_gem_object_reference(&msm_obj->base);
  393. msm_gem_get_iova(&msm_obj->base,
  394. submit->gpu->aspace, &iova);
  395. if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)
  396. msm_gem_move_to_active(&msm_obj->base, gpu, true, submit->fence);
  397. else if (submit->bos[i].flags & MSM_SUBMIT_BO_READ)
  398. msm_gem_move_to_active(&msm_obj->base, gpu, false, submit->fence);
  399. }
  400. gpu->funcs->submit(gpu, submit, ctx);
  401. priv->lastctx = ctx;
  402. hangcheck_timer_reset(gpu);
  403. }
  404. /*
  405. * Init/Cleanup:
  406. */
  407. static irqreturn_t irq_handler(int irq, void *data)
  408. {
  409. struct msm_gpu *gpu = data;
  410. return gpu->funcs->irq(gpu);
  411. }
  412. static struct clk *get_clock(struct device *dev, const char *name)
  413. {
  414. struct clk *clk = devm_clk_get(dev, name);
  415. return IS_ERR(clk) ? NULL : clk;
  416. }
  417. static int get_clocks(struct platform_device *pdev, struct msm_gpu *gpu)
  418. {
  419. struct device *dev = &pdev->dev;
  420. struct property *prop;
  421. const char *name;
  422. int i = 0;
  423. gpu->nr_clocks = of_property_count_strings(dev->of_node, "clock-names");
  424. if (gpu->nr_clocks < 1) {
  425. gpu->nr_clocks = 0;
  426. return 0;
  427. }
  428. gpu->grp_clks = devm_kcalloc(dev, sizeof(struct clk *), gpu->nr_clocks,
  429. GFP_KERNEL);
  430. if (!gpu->grp_clks)
  431. return -ENOMEM;
  432. of_property_for_each_string(dev->of_node, "clock-names", prop, name) {
  433. gpu->grp_clks[i] = get_clock(dev, name);
  434. /* Remember the key clocks that we need to control later */
  435. if (!strcmp(name, "core") || !strcmp(name, "core_clk"))
  436. gpu->core_clk = gpu->grp_clks[i];
  437. else if (!strcmp(name, "rbbmtimer") || !strcmp(name, "rbbmtimer_clk"))
  438. gpu->rbbmtimer_clk = gpu->grp_clks[i];
  439. ++i;
  440. }
  441. return 0;
  442. }
  443. static struct msm_gem_address_space *
  444. msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
  445. uint64_t va_start, uint64_t va_end)
  446. {
  447. struct iommu_domain *iommu;
  448. struct msm_gem_address_space *aspace;
  449. int ret;
  450. /*
  451. * Setup IOMMU.. eventually we will (I think) do this once per context
  452. * and have separate page tables per context. For now, to keep things
  453. * simple and to get something working, just use a single address space:
  454. */
  455. iommu = iommu_domain_alloc(&platform_bus_type);
  456. if (!iommu)
  457. return NULL;
  458. iommu->geometry.aperture_start = va_start;
  459. iommu->geometry.aperture_end = va_end;
  460. dev_info(gpu->dev->dev, "%s: using IOMMU\n", gpu->name);
  461. aspace = msm_gem_address_space_create(&pdev->dev, iommu, "gpu");
  462. if (IS_ERR(aspace)) {
  463. dev_err(gpu->dev->dev, "failed to init iommu: %ld\n",
  464. PTR_ERR(aspace));
  465. iommu_domain_free(iommu);
  466. return ERR_CAST(aspace);
  467. }
  468. ret = aspace->mmu->funcs->attach(aspace->mmu, NULL, 0);
  469. if (ret) {
  470. msm_gem_address_space_put(aspace);
  471. return ERR_PTR(ret);
  472. }
  473. return aspace;
  474. }
  475. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  476. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  477. const char *name, struct msm_gpu_config *config)
  478. {
  479. int ret;
  480. if (WARN_ON(gpu->num_perfcntrs > ARRAY_SIZE(gpu->last_cntrs)))
  481. gpu->num_perfcntrs = ARRAY_SIZE(gpu->last_cntrs);
  482. gpu->dev = drm;
  483. gpu->funcs = funcs;
  484. gpu->name = name;
  485. gpu->fctx = msm_fence_context_alloc(drm, name);
  486. if (IS_ERR(gpu->fctx)) {
  487. ret = PTR_ERR(gpu->fctx);
  488. gpu->fctx = NULL;
  489. goto fail;
  490. }
  491. INIT_LIST_HEAD(&gpu->active_list);
  492. INIT_WORK(&gpu->retire_work, retire_worker);
  493. INIT_WORK(&gpu->recover_work, recover_worker);
  494. INIT_LIST_HEAD(&gpu->submit_list);
  495. setup_timer(&gpu->hangcheck_timer, hangcheck_handler,
  496. (unsigned long)gpu);
  497. spin_lock_init(&gpu->perf_lock);
  498. /* Map registers: */
  499. gpu->mmio = msm_ioremap(pdev, config->ioname, name);
  500. if (IS_ERR(gpu->mmio)) {
  501. ret = PTR_ERR(gpu->mmio);
  502. goto fail;
  503. }
  504. /* Get Interrupt: */
  505. gpu->irq = platform_get_irq_byname(pdev, config->irqname);
  506. if (gpu->irq < 0) {
  507. ret = gpu->irq;
  508. dev_err(drm->dev, "failed to get irq: %d\n", ret);
  509. goto fail;
  510. }
  511. ret = devm_request_irq(&pdev->dev, gpu->irq, irq_handler,
  512. IRQF_TRIGGER_HIGH, gpu->name, gpu);
  513. if (ret) {
  514. dev_err(drm->dev, "failed to request IRQ%u: %d\n", gpu->irq, ret);
  515. goto fail;
  516. }
  517. ret = get_clocks(pdev, gpu);
  518. if (ret)
  519. goto fail;
  520. gpu->ebi1_clk = msm_clk_get(pdev, "bus");
  521. DBG("ebi1_clk: %p", gpu->ebi1_clk);
  522. if (IS_ERR(gpu->ebi1_clk))
  523. gpu->ebi1_clk = NULL;
  524. /* Acquire regulators: */
  525. gpu->gpu_reg = devm_regulator_get(&pdev->dev, "vdd");
  526. DBG("gpu_reg: %p", gpu->gpu_reg);
  527. if (IS_ERR(gpu->gpu_reg))
  528. gpu->gpu_reg = NULL;
  529. gpu->gpu_cx = devm_regulator_get(&pdev->dev, "vddcx");
  530. DBG("gpu_cx: %p", gpu->gpu_cx);
  531. if (IS_ERR(gpu->gpu_cx))
  532. gpu->gpu_cx = NULL;
  533. gpu->pdev = pdev;
  534. platform_set_drvdata(pdev, gpu);
  535. bs_init(gpu);
  536. gpu->aspace = msm_gpu_create_address_space(gpu, pdev,
  537. config->va_start, config->va_end);
  538. if (gpu->aspace == NULL)
  539. dev_info(drm->dev, "%s: no IOMMU, fallback to VRAM carveout!\n", name);
  540. else if (IS_ERR(gpu->aspace)) {
  541. ret = PTR_ERR(gpu->aspace);
  542. goto fail;
  543. }
  544. /* Create ringbuffer: */
  545. gpu->rb = msm_ringbuffer_new(gpu, config->ringsz);
  546. if (IS_ERR(gpu->rb)) {
  547. ret = PTR_ERR(gpu->rb);
  548. gpu->rb = NULL;
  549. dev_err(drm->dev, "could not create ringbuffer: %d\n", ret);
  550. goto fail;
  551. }
  552. return 0;
  553. fail:
  554. platform_set_drvdata(pdev, NULL);
  555. return ret;
  556. }
  557. void msm_gpu_cleanup(struct msm_gpu *gpu)
  558. {
  559. DBG("%s", gpu->name);
  560. WARN_ON(!list_empty(&gpu->active_list));
  561. bs_fini(gpu);
  562. if (gpu->rb) {
  563. if (gpu->rb_iova)
  564. msm_gem_put_iova(gpu->rb->bo, gpu->aspace);
  565. msm_ringbuffer_destroy(gpu->rb);
  566. }
  567. if (gpu->aspace) {
  568. gpu->aspace->mmu->funcs->detach(gpu->aspace->mmu,
  569. NULL, 0);
  570. msm_gem_address_space_put(gpu->aspace);
  571. }
  572. }