vc4_gem.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /*
  2. * Copyright © 2014 Broadcom
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/device.h>
  27. #include <linux/io.h>
  28. #include <linux/sched/signal.h>
  29. #include "uapi/drm/vc4_drm.h"
  30. #include "vc4_drv.h"
  31. #include "vc4_regs.h"
  32. #include "vc4_trace.h"
  33. static void
  34. vc4_queue_hangcheck(struct drm_device *dev)
  35. {
  36. struct vc4_dev *vc4 = to_vc4_dev(dev);
  37. mod_timer(&vc4->hangcheck.timer,
  38. round_jiffies_up(jiffies + msecs_to_jiffies(100)));
  39. }
  40. struct vc4_hang_state {
  41. struct drm_vc4_get_hang_state user_state;
  42. u32 bo_count;
  43. struct drm_gem_object **bo;
  44. };
  45. static void
  46. vc4_free_hang_state(struct drm_device *dev, struct vc4_hang_state *state)
  47. {
  48. unsigned int i;
  49. for (i = 0; i < state->user_state.bo_count; i++)
  50. drm_gem_object_put_unlocked(state->bo[i]);
  51. kfree(state);
  52. }
  53. int
  54. vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
  55. struct drm_file *file_priv)
  56. {
  57. struct drm_vc4_get_hang_state *get_state = data;
  58. struct drm_vc4_get_hang_state_bo *bo_state;
  59. struct vc4_hang_state *kernel_state;
  60. struct drm_vc4_get_hang_state *state;
  61. struct vc4_dev *vc4 = to_vc4_dev(dev);
  62. unsigned long irqflags;
  63. u32 i;
  64. int ret = 0;
  65. spin_lock_irqsave(&vc4->job_lock, irqflags);
  66. kernel_state = vc4->hang_state;
  67. if (!kernel_state) {
  68. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  69. return -ENOENT;
  70. }
  71. state = &kernel_state->user_state;
  72. /* If the user's array isn't big enough, just return the
  73. * required array size.
  74. */
  75. if (get_state->bo_count < state->bo_count) {
  76. get_state->bo_count = state->bo_count;
  77. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  78. return 0;
  79. }
  80. vc4->hang_state = NULL;
  81. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  82. /* Save the user's BO pointer, so we don't stomp it with the memcpy. */
  83. state->bo = get_state->bo;
  84. memcpy(get_state, state, sizeof(*state));
  85. bo_state = kcalloc(state->bo_count, sizeof(*bo_state), GFP_KERNEL);
  86. if (!bo_state) {
  87. ret = -ENOMEM;
  88. goto err_free;
  89. }
  90. for (i = 0; i < state->bo_count; i++) {
  91. struct vc4_bo *vc4_bo = to_vc4_bo(kernel_state->bo[i]);
  92. u32 handle;
  93. ret = drm_gem_handle_create(file_priv, kernel_state->bo[i],
  94. &handle);
  95. if (ret) {
  96. state->bo_count = i;
  97. goto err_delete_handle;
  98. }
  99. bo_state[i].handle = handle;
  100. bo_state[i].paddr = vc4_bo->base.paddr;
  101. bo_state[i].size = vc4_bo->base.base.size;
  102. }
  103. if (copy_to_user(u64_to_user_ptr(get_state->bo),
  104. bo_state,
  105. state->bo_count * sizeof(*bo_state)))
  106. ret = -EFAULT;
  107. err_delete_handle:
  108. if (ret) {
  109. for (i = 0; i < state->bo_count; i++)
  110. drm_gem_handle_delete(file_priv, bo_state[i].handle);
  111. }
  112. err_free:
  113. vc4_free_hang_state(dev, kernel_state);
  114. kfree(bo_state);
  115. return ret;
  116. }
  117. static void
  118. vc4_save_hang_state(struct drm_device *dev)
  119. {
  120. struct vc4_dev *vc4 = to_vc4_dev(dev);
  121. struct drm_vc4_get_hang_state *state;
  122. struct vc4_hang_state *kernel_state;
  123. struct vc4_exec_info *exec[2];
  124. struct vc4_bo *bo;
  125. unsigned long irqflags;
  126. unsigned int i, j, unref_list_count, prev_idx;
  127. kernel_state = kcalloc(1, sizeof(*kernel_state), GFP_KERNEL);
  128. if (!kernel_state)
  129. return;
  130. state = &kernel_state->user_state;
  131. spin_lock_irqsave(&vc4->job_lock, irqflags);
  132. exec[0] = vc4_first_bin_job(vc4);
  133. exec[1] = vc4_first_render_job(vc4);
  134. if (!exec[0] && !exec[1]) {
  135. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  136. return;
  137. }
  138. /* Get the bos from both binner and renderer into hang state. */
  139. state->bo_count = 0;
  140. for (i = 0; i < 2; i++) {
  141. if (!exec[i])
  142. continue;
  143. unref_list_count = 0;
  144. list_for_each_entry(bo, &exec[i]->unref_list, unref_head)
  145. unref_list_count++;
  146. state->bo_count += exec[i]->bo_count + unref_list_count;
  147. }
  148. kernel_state->bo = kcalloc(state->bo_count,
  149. sizeof(*kernel_state->bo), GFP_ATOMIC);
  150. if (!kernel_state->bo) {
  151. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  152. return;
  153. }
  154. prev_idx = 0;
  155. for (i = 0; i < 2; i++) {
  156. if (!exec[i])
  157. continue;
  158. for (j = 0; j < exec[i]->bo_count; j++) {
  159. bo = to_vc4_bo(&exec[i]->bo[j]->base);
  160. /* Retain BOs just in case they were marked purgeable.
  161. * This prevents the BO from being purged before
  162. * someone had a chance to dump the hang state.
  163. */
  164. WARN_ON(!refcount_read(&bo->usecnt));
  165. refcount_inc(&bo->usecnt);
  166. drm_gem_object_get(&exec[i]->bo[j]->base);
  167. kernel_state->bo[j + prev_idx] = &exec[i]->bo[j]->base;
  168. }
  169. list_for_each_entry(bo, &exec[i]->unref_list, unref_head) {
  170. /* No need to retain BOs coming from the ->unref_list
  171. * because they are naturally unpurgeable.
  172. */
  173. drm_gem_object_get(&bo->base.base);
  174. kernel_state->bo[j + prev_idx] = &bo->base.base;
  175. j++;
  176. }
  177. prev_idx = j + 1;
  178. }
  179. if (exec[0])
  180. state->start_bin = exec[0]->ct0ca;
  181. if (exec[1])
  182. state->start_render = exec[1]->ct1ca;
  183. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  184. state->ct0ca = V3D_READ(V3D_CTNCA(0));
  185. state->ct0ea = V3D_READ(V3D_CTNEA(0));
  186. state->ct1ca = V3D_READ(V3D_CTNCA(1));
  187. state->ct1ea = V3D_READ(V3D_CTNEA(1));
  188. state->ct0cs = V3D_READ(V3D_CTNCS(0));
  189. state->ct1cs = V3D_READ(V3D_CTNCS(1));
  190. state->ct0ra0 = V3D_READ(V3D_CT00RA0);
  191. state->ct1ra0 = V3D_READ(V3D_CT01RA0);
  192. state->bpca = V3D_READ(V3D_BPCA);
  193. state->bpcs = V3D_READ(V3D_BPCS);
  194. state->bpoa = V3D_READ(V3D_BPOA);
  195. state->bpos = V3D_READ(V3D_BPOS);
  196. state->vpmbase = V3D_READ(V3D_VPMBASE);
  197. state->dbge = V3D_READ(V3D_DBGE);
  198. state->fdbgo = V3D_READ(V3D_FDBGO);
  199. state->fdbgb = V3D_READ(V3D_FDBGB);
  200. state->fdbgr = V3D_READ(V3D_FDBGR);
  201. state->fdbgs = V3D_READ(V3D_FDBGS);
  202. state->errstat = V3D_READ(V3D_ERRSTAT);
  203. /* We need to turn purgeable BOs into unpurgeable ones so that
  204. * userspace has a chance to dump the hang state before the kernel
  205. * decides to purge those BOs.
  206. * Note that BO consistency at dump time cannot be guaranteed. For
  207. * example, if the owner of these BOs decides to re-use them or mark
  208. * them purgeable again there's nothing we can do to prevent it.
  209. */
  210. for (i = 0; i < kernel_state->user_state.bo_count; i++) {
  211. struct vc4_bo *bo = to_vc4_bo(kernel_state->bo[i]);
  212. if (bo->madv == __VC4_MADV_NOTSUPP)
  213. continue;
  214. mutex_lock(&bo->madv_lock);
  215. if (!WARN_ON(bo->madv == __VC4_MADV_PURGED))
  216. bo->madv = VC4_MADV_WILLNEED;
  217. refcount_dec(&bo->usecnt);
  218. mutex_unlock(&bo->madv_lock);
  219. }
  220. spin_lock_irqsave(&vc4->job_lock, irqflags);
  221. if (vc4->hang_state) {
  222. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  223. vc4_free_hang_state(dev, kernel_state);
  224. } else {
  225. vc4->hang_state = kernel_state;
  226. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  227. }
  228. }
  229. static void
  230. vc4_reset(struct drm_device *dev)
  231. {
  232. struct vc4_dev *vc4 = to_vc4_dev(dev);
  233. DRM_INFO("Resetting GPU.\n");
  234. mutex_lock(&vc4->power_lock);
  235. if (vc4->power_refcount) {
  236. /* Power the device off and back on the by dropping the
  237. * reference on runtime PM.
  238. */
  239. pm_runtime_put_sync_suspend(&vc4->v3d->pdev->dev);
  240. pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  241. }
  242. mutex_unlock(&vc4->power_lock);
  243. vc4_irq_reset(dev);
  244. /* Rearm the hangcheck -- another job might have been waiting
  245. * for our hung one to get kicked off, and vc4_irq_reset()
  246. * would have started it.
  247. */
  248. vc4_queue_hangcheck(dev);
  249. }
  250. static void
  251. vc4_reset_work(struct work_struct *work)
  252. {
  253. struct vc4_dev *vc4 =
  254. container_of(work, struct vc4_dev, hangcheck.reset_work);
  255. vc4_save_hang_state(vc4->dev);
  256. vc4_reset(vc4->dev);
  257. }
  258. static void
  259. vc4_hangcheck_elapsed(struct timer_list *t)
  260. {
  261. struct vc4_dev *vc4 = from_timer(vc4, t, hangcheck.timer);
  262. struct drm_device *dev = vc4->dev;
  263. uint32_t ct0ca, ct1ca;
  264. unsigned long irqflags;
  265. struct vc4_exec_info *bin_exec, *render_exec;
  266. spin_lock_irqsave(&vc4->job_lock, irqflags);
  267. bin_exec = vc4_first_bin_job(vc4);
  268. render_exec = vc4_first_render_job(vc4);
  269. /* If idle, we can stop watching for hangs. */
  270. if (!bin_exec && !render_exec) {
  271. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  272. return;
  273. }
  274. ct0ca = V3D_READ(V3D_CTNCA(0));
  275. ct1ca = V3D_READ(V3D_CTNCA(1));
  276. /* If we've made any progress in execution, rearm the timer
  277. * and wait.
  278. */
  279. if ((bin_exec && ct0ca != bin_exec->last_ct0ca) ||
  280. (render_exec && ct1ca != render_exec->last_ct1ca)) {
  281. if (bin_exec)
  282. bin_exec->last_ct0ca = ct0ca;
  283. if (render_exec)
  284. render_exec->last_ct1ca = ct1ca;
  285. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  286. vc4_queue_hangcheck(dev);
  287. return;
  288. }
  289. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  290. /* We've gone too long with no progress, reset. This has to
  291. * be done from a work struct, since resetting can sleep and
  292. * this timer hook isn't allowed to.
  293. */
  294. schedule_work(&vc4->hangcheck.reset_work);
  295. }
  296. static void
  297. submit_cl(struct drm_device *dev, uint32_t thread, uint32_t start, uint32_t end)
  298. {
  299. struct vc4_dev *vc4 = to_vc4_dev(dev);
  300. /* Set the current and end address of the control list.
  301. * Writing the end register is what starts the job.
  302. */
  303. V3D_WRITE(V3D_CTNCA(thread), start);
  304. V3D_WRITE(V3D_CTNEA(thread), end);
  305. }
  306. int
  307. vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, uint64_t timeout_ns,
  308. bool interruptible)
  309. {
  310. struct vc4_dev *vc4 = to_vc4_dev(dev);
  311. int ret = 0;
  312. unsigned long timeout_expire;
  313. DEFINE_WAIT(wait);
  314. if (vc4->finished_seqno >= seqno)
  315. return 0;
  316. if (timeout_ns == 0)
  317. return -ETIME;
  318. timeout_expire = jiffies + nsecs_to_jiffies(timeout_ns);
  319. trace_vc4_wait_for_seqno_begin(dev, seqno, timeout_ns);
  320. for (;;) {
  321. prepare_to_wait(&vc4->job_wait_queue, &wait,
  322. interruptible ? TASK_INTERRUPTIBLE :
  323. TASK_UNINTERRUPTIBLE);
  324. if (interruptible && signal_pending(current)) {
  325. ret = -ERESTARTSYS;
  326. break;
  327. }
  328. if (vc4->finished_seqno >= seqno)
  329. break;
  330. if (timeout_ns != ~0ull) {
  331. if (time_after_eq(jiffies, timeout_expire)) {
  332. ret = -ETIME;
  333. break;
  334. }
  335. schedule_timeout(timeout_expire - jiffies);
  336. } else {
  337. schedule();
  338. }
  339. }
  340. finish_wait(&vc4->job_wait_queue, &wait);
  341. trace_vc4_wait_for_seqno_end(dev, seqno);
  342. return ret;
  343. }
  344. static void
  345. vc4_flush_caches(struct drm_device *dev)
  346. {
  347. struct vc4_dev *vc4 = to_vc4_dev(dev);
  348. /* Flush the GPU L2 caches. These caches sit on top of system
  349. * L3 (the 128kb or so shared with the CPU), and are
  350. * non-allocating in the L3.
  351. */
  352. V3D_WRITE(V3D_L2CACTL,
  353. V3D_L2CACTL_L2CCLR);
  354. V3D_WRITE(V3D_SLCACTL,
  355. VC4_SET_FIELD(0xf, V3D_SLCACTL_T1CC) |
  356. VC4_SET_FIELD(0xf, V3D_SLCACTL_T0CC) |
  357. VC4_SET_FIELD(0xf, V3D_SLCACTL_UCC) |
  358. VC4_SET_FIELD(0xf, V3D_SLCACTL_ICC));
  359. }
  360. /* Sets the registers for the next job to be actually be executed in
  361. * the hardware.
  362. *
  363. * The job_lock should be held during this.
  364. */
  365. void
  366. vc4_submit_next_bin_job(struct drm_device *dev)
  367. {
  368. struct vc4_dev *vc4 = to_vc4_dev(dev);
  369. struct vc4_exec_info *exec;
  370. again:
  371. exec = vc4_first_bin_job(vc4);
  372. if (!exec)
  373. return;
  374. vc4_flush_caches(dev);
  375. /* Either put the job in the binner if it uses the binner, or
  376. * immediately move it to the to-be-rendered queue.
  377. */
  378. if (exec->ct0ca != exec->ct0ea) {
  379. submit_cl(dev, 0, exec->ct0ca, exec->ct0ea);
  380. } else {
  381. vc4_move_job_to_render(dev, exec);
  382. goto again;
  383. }
  384. }
  385. void
  386. vc4_submit_next_render_job(struct drm_device *dev)
  387. {
  388. struct vc4_dev *vc4 = to_vc4_dev(dev);
  389. struct vc4_exec_info *exec = vc4_first_render_job(vc4);
  390. if (!exec)
  391. return;
  392. submit_cl(dev, 1, exec->ct1ca, exec->ct1ea);
  393. }
  394. void
  395. vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec)
  396. {
  397. struct vc4_dev *vc4 = to_vc4_dev(dev);
  398. bool was_empty = list_empty(&vc4->render_job_list);
  399. list_move_tail(&exec->head, &vc4->render_job_list);
  400. if (was_empty)
  401. vc4_submit_next_render_job(dev);
  402. }
  403. static void
  404. vc4_update_bo_seqnos(struct vc4_exec_info *exec, uint64_t seqno)
  405. {
  406. struct vc4_bo *bo;
  407. unsigned i;
  408. for (i = 0; i < exec->bo_count; i++) {
  409. bo = to_vc4_bo(&exec->bo[i]->base);
  410. bo->seqno = seqno;
  411. reservation_object_add_shared_fence(bo->resv, exec->fence);
  412. }
  413. list_for_each_entry(bo, &exec->unref_list, unref_head) {
  414. bo->seqno = seqno;
  415. }
  416. for (i = 0; i < exec->rcl_write_bo_count; i++) {
  417. bo = to_vc4_bo(&exec->rcl_write_bo[i]->base);
  418. bo->write_seqno = seqno;
  419. reservation_object_add_excl_fence(bo->resv, exec->fence);
  420. }
  421. }
  422. static void
  423. vc4_unlock_bo_reservations(struct drm_device *dev,
  424. struct vc4_exec_info *exec,
  425. struct ww_acquire_ctx *acquire_ctx)
  426. {
  427. int i;
  428. for (i = 0; i < exec->bo_count; i++) {
  429. struct vc4_bo *bo = to_vc4_bo(&exec->bo[i]->base);
  430. ww_mutex_unlock(&bo->resv->lock);
  431. }
  432. ww_acquire_fini(acquire_ctx);
  433. }
  434. /* Takes the reservation lock on all the BOs being referenced, so that
  435. * at queue submit time we can update the reservations.
  436. *
  437. * We don't lock the RCL the tile alloc/state BOs, or overflow memory
  438. * (all of which are on exec->unref_list). They're entirely private
  439. * to vc4, so we don't attach dma-buf fences to them.
  440. */
  441. static int
  442. vc4_lock_bo_reservations(struct drm_device *dev,
  443. struct vc4_exec_info *exec,
  444. struct ww_acquire_ctx *acquire_ctx)
  445. {
  446. int contended_lock = -1;
  447. int i, ret;
  448. struct vc4_bo *bo;
  449. ww_acquire_init(acquire_ctx, &reservation_ww_class);
  450. retry:
  451. if (contended_lock != -1) {
  452. bo = to_vc4_bo(&exec->bo[contended_lock]->base);
  453. ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
  454. acquire_ctx);
  455. if (ret) {
  456. ww_acquire_done(acquire_ctx);
  457. return ret;
  458. }
  459. }
  460. for (i = 0; i < exec->bo_count; i++) {
  461. if (i == contended_lock)
  462. continue;
  463. bo = to_vc4_bo(&exec->bo[i]->base);
  464. ret = ww_mutex_lock_interruptible(&bo->resv->lock, acquire_ctx);
  465. if (ret) {
  466. int j;
  467. for (j = 0; j < i; j++) {
  468. bo = to_vc4_bo(&exec->bo[j]->base);
  469. ww_mutex_unlock(&bo->resv->lock);
  470. }
  471. if (contended_lock != -1 && contended_lock >= i) {
  472. bo = to_vc4_bo(&exec->bo[contended_lock]->base);
  473. ww_mutex_unlock(&bo->resv->lock);
  474. }
  475. if (ret == -EDEADLK) {
  476. contended_lock = i;
  477. goto retry;
  478. }
  479. ww_acquire_done(acquire_ctx);
  480. return ret;
  481. }
  482. }
  483. ww_acquire_done(acquire_ctx);
  484. /* Reserve space for our shared (read-only) fence references,
  485. * before we commit the CL to the hardware.
  486. */
  487. for (i = 0; i < exec->bo_count; i++) {
  488. bo = to_vc4_bo(&exec->bo[i]->base);
  489. ret = reservation_object_reserve_shared(bo->resv);
  490. if (ret) {
  491. vc4_unlock_bo_reservations(dev, exec, acquire_ctx);
  492. return ret;
  493. }
  494. }
  495. return 0;
  496. }
  497. /* Queues a struct vc4_exec_info for execution. If no job is
  498. * currently executing, then submits it.
  499. *
  500. * Unlike most GPUs, our hardware only handles one command list at a
  501. * time. To queue multiple jobs at once, we'd need to edit the
  502. * previous command list to have a jump to the new one at the end, and
  503. * then bump the end address. That's a change for a later date,
  504. * though.
  505. */
  506. static int
  507. vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,
  508. struct ww_acquire_ctx *acquire_ctx)
  509. {
  510. struct vc4_dev *vc4 = to_vc4_dev(dev);
  511. uint64_t seqno;
  512. unsigned long irqflags;
  513. struct vc4_fence *fence;
  514. fence = kzalloc(sizeof(*fence), GFP_KERNEL);
  515. if (!fence)
  516. return -ENOMEM;
  517. fence->dev = dev;
  518. spin_lock_irqsave(&vc4->job_lock, irqflags);
  519. seqno = ++vc4->emit_seqno;
  520. exec->seqno = seqno;
  521. dma_fence_init(&fence->base, &vc4_fence_ops, &vc4->job_lock,
  522. vc4->dma_fence_context, exec->seqno);
  523. fence->seqno = exec->seqno;
  524. exec->fence = &fence->base;
  525. vc4_update_bo_seqnos(exec, seqno);
  526. vc4_unlock_bo_reservations(dev, exec, acquire_ctx);
  527. list_add_tail(&exec->head, &vc4->bin_job_list);
  528. /* If no job was executing, kick ours off. Otherwise, it'll
  529. * get started when the previous job's flush done interrupt
  530. * occurs.
  531. */
  532. if (vc4_first_bin_job(vc4) == exec) {
  533. vc4_submit_next_bin_job(dev);
  534. vc4_queue_hangcheck(dev);
  535. }
  536. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  537. return 0;
  538. }
  539. /**
  540. * vc4_cl_lookup_bos() - Sets up exec->bo[] with the GEM objects
  541. * referenced by the job.
  542. * @dev: DRM device
  543. * @file_priv: DRM file for this fd
  544. * @exec: V3D job being set up
  545. *
  546. * The command validator needs to reference BOs by their index within
  547. * the submitted job's BO list. This does the validation of the job's
  548. * BO list and reference counting for the lifetime of the job.
  549. */
  550. static int
  551. vc4_cl_lookup_bos(struct drm_device *dev,
  552. struct drm_file *file_priv,
  553. struct vc4_exec_info *exec)
  554. {
  555. struct drm_vc4_submit_cl *args = exec->args;
  556. uint32_t *handles;
  557. int ret = 0;
  558. int i;
  559. exec->bo_count = args->bo_handle_count;
  560. if (!exec->bo_count) {
  561. /* See comment on bo_index for why we have to check
  562. * this.
  563. */
  564. DRM_DEBUG("Rendering requires BOs to validate\n");
  565. return -EINVAL;
  566. }
  567. exec->bo = kvmalloc_array(exec->bo_count,
  568. sizeof(struct drm_gem_cma_object *),
  569. GFP_KERNEL | __GFP_ZERO);
  570. if (!exec->bo) {
  571. DRM_ERROR("Failed to allocate validated BO pointers\n");
  572. return -ENOMEM;
  573. }
  574. handles = kvmalloc_array(exec->bo_count, sizeof(uint32_t), GFP_KERNEL);
  575. if (!handles) {
  576. ret = -ENOMEM;
  577. DRM_ERROR("Failed to allocate incoming GEM handles\n");
  578. goto fail;
  579. }
  580. if (copy_from_user(handles, u64_to_user_ptr(args->bo_handles),
  581. exec->bo_count * sizeof(uint32_t))) {
  582. ret = -EFAULT;
  583. DRM_ERROR("Failed to copy in GEM handles\n");
  584. goto fail;
  585. }
  586. spin_lock(&file_priv->table_lock);
  587. for (i = 0; i < exec->bo_count; i++) {
  588. struct drm_gem_object *bo = idr_find(&file_priv->object_idr,
  589. handles[i]);
  590. if (!bo) {
  591. DRM_DEBUG("Failed to look up GEM BO %d: %d\n",
  592. i, handles[i]);
  593. ret = -EINVAL;
  594. break;
  595. }
  596. drm_gem_object_get(bo);
  597. exec->bo[i] = (struct drm_gem_cma_object *)bo;
  598. }
  599. spin_unlock(&file_priv->table_lock);
  600. if (ret)
  601. goto fail_put_bo;
  602. for (i = 0; i < exec->bo_count; i++) {
  603. ret = vc4_bo_inc_usecnt(to_vc4_bo(&exec->bo[i]->base));
  604. if (ret)
  605. goto fail_dec_usecnt;
  606. }
  607. kvfree(handles);
  608. return 0;
  609. fail_dec_usecnt:
  610. /* Decrease usecnt on acquired objects.
  611. * We cannot rely on vc4_complete_exec() to release resources here,
  612. * because vc4_complete_exec() has no information about which BO has
  613. * had its ->usecnt incremented.
  614. * To make things easier we just free everything explicitly and set
  615. * exec->bo to NULL so that vc4_complete_exec() skips the 'BO release'
  616. * step.
  617. */
  618. for (i-- ; i >= 0; i--)
  619. vc4_bo_dec_usecnt(to_vc4_bo(&exec->bo[i]->base));
  620. fail_put_bo:
  621. /* Release any reference to acquired objects. */
  622. for (i = 0; i < exec->bo_count && exec->bo[i]; i++)
  623. drm_gem_object_put_unlocked(&exec->bo[i]->base);
  624. fail:
  625. kvfree(handles);
  626. kvfree(exec->bo);
  627. exec->bo = NULL;
  628. return ret;
  629. }
  630. static int
  631. vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
  632. {
  633. struct drm_vc4_submit_cl *args = exec->args;
  634. void *temp = NULL;
  635. void *bin;
  636. int ret = 0;
  637. uint32_t bin_offset = 0;
  638. uint32_t shader_rec_offset = roundup(bin_offset + args->bin_cl_size,
  639. 16);
  640. uint32_t uniforms_offset = shader_rec_offset + args->shader_rec_size;
  641. uint32_t exec_size = uniforms_offset + args->uniforms_size;
  642. uint32_t temp_size = exec_size + (sizeof(struct vc4_shader_state) *
  643. args->shader_rec_count);
  644. struct vc4_bo *bo;
  645. if (shader_rec_offset < args->bin_cl_size ||
  646. uniforms_offset < shader_rec_offset ||
  647. exec_size < uniforms_offset ||
  648. args->shader_rec_count >= (UINT_MAX /
  649. sizeof(struct vc4_shader_state)) ||
  650. temp_size < exec_size) {
  651. DRM_DEBUG("overflow in exec arguments\n");
  652. ret = -EINVAL;
  653. goto fail;
  654. }
  655. /* Allocate space where we'll store the copied in user command lists
  656. * and shader records.
  657. *
  658. * We don't just copy directly into the BOs because we need to
  659. * read the contents back for validation, and I think the
  660. * bo->vaddr is uncached access.
  661. */
  662. temp = kvmalloc_array(temp_size, 1, GFP_KERNEL);
  663. if (!temp) {
  664. DRM_ERROR("Failed to allocate storage for copying "
  665. "in bin/render CLs.\n");
  666. ret = -ENOMEM;
  667. goto fail;
  668. }
  669. bin = temp + bin_offset;
  670. exec->shader_rec_u = temp + shader_rec_offset;
  671. exec->uniforms_u = temp + uniforms_offset;
  672. exec->shader_state = temp + exec_size;
  673. exec->shader_state_size = args->shader_rec_count;
  674. if (copy_from_user(bin,
  675. u64_to_user_ptr(args->bin_cl),
  676. args->bin_cl_size)) {
  677. ret = -EFAULT;
  678. goto fail;
  679. }
  680. if (copy_from_user(exec->shader_rec_u,
  681. u64_to_user_ptr(args->shader_rec),
  682. args->shader_rec_size)) {
  683. ret = -EFAULT;
  684. goto fail;
  685. }
  686. if (copy_from_user(exec->uniforms_u,
  687. u64_to_user_ptr(args->uniforms),
  688. args->uniforms_size)) {
  689. ret = -EFAULT;
  690. goto fail;
  691. }
  692. bo = vc4_bo_create(dev, exec_size, true, VC4_BO_TYPE_BCL);
  693. if (IS_ERR(bo)) {
  694. DRM_ERROR("Couldn't allocate BO for binning\n");
  695. ret = PTR_ERR(bo);
  696. goto fail;
  697. }
  698. exec->exec_bo = &bo->base;
  699. list_add_tail(&to_vc4_bo(&exec->exec_bo->base)->unref_head,
  700. &exec->unref_list);
  701. exec->ct0ca = exec->exec_bo->paddr + bin_offset;
  702. exec->bin_u = bin;
  703. exec->shader_rec_v = exec->exec_bo->vaddr + shader_rec_offset;
  704. exec->shader_rec_p = exec->exec_bo->paddr + shader_rec_offset;
  705. exec->shader_rec_size = args->shader_rec_size;
  706. exec->uniforms_v = exec->exec_bo->vaddr + uniforms_offset;
  707. exec->uniforms_p = exec->exec_bo->paddr + uniforms_offset;
  708. exec->uniforms_size = args->uniforms_size;
  709. ret = vc4_validate_bin_cl(dev,
  710. exec->exec_bo->vaddr + bin_offset,
  711. bin,
  712. exec);
  713. if (ret)
  714. goto fail;
  715. ret = vc4_validate_shader_recs(dev, exec);
  716. if (ret)
  717. goto fail;
  718. /* Block waiting on any previous rendering into the CS's VBO,
  719. * IB, or textures, so that pixels are actually written by the
  720. * time we try to read them.
  721. */
  722. ret = vc4_wait_for_seqno(dev, exec->bin_dep_seqno, ~0ull, true);
  723. fail:
  724. kvfree(temp);
  725. return ret;
  726. }
  727. static void
  728. vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
  729. {
  730. struct vc4_dev *vc4 = to_vc4_dev(dev);
  731. unsigned long irqflags;
  732. unsigned i;
  733. /* If we got force-completed because of GPU reset rather than
  734. * through our IRQ handler, signal the fence now.
  735. */
  736. if (exec->fence)
  737. dma_fence_signal(exec->fence);
  738. if (exec->bo) {
  739. for (i = 0; i < exec->bo_count; i++) {
  740. struct vc4_bo *bo = to_vc4_bo(&exec->bo[i]->base);
  741. vc4_bo_dec_usecnt(bo);
  742. drm_gem_object_put_unlocked(&exec->bo[i]->base);
  743. }
  744. kvfree(exec->bo);
  745. }
  746. while (!list_empty(&exec->unref_list)) {
  747. struct vc4_bo *bo = list_first_entry(&exec->unref_list,
  748. struct vc4_bo, unref_head);
  749. list_del(&bo->unref_head);
  750. drm_gem_object_put_unlocked(&bo->base.base);
  751. }
  752. /* Free up the allocation of any bin slots we used. */
  753. spin_lock_irqsave(&vc4->job_lock, irqflags);
  754. vc4->bin_alloc_used &= ~exec->bin_slots;
  755. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  756. mutex_lock(&vc4->power_lock);
  757. if (--vc4->power_refcount == 0) {
  758. pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
  759. pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
  760. }
  761. mutex_unlock(&vc4->power_lock);
  762. kfree(exec);
  763. }
  764. void
  765. vc4_job_handle_completed(struct vc4_dev *vc4)
  766. {
  767. unsigned long irqflags;
  768. struct vc4_seqno_cb *cb, *cb_temp;
  769. spin_lock_irqsave(&vc4->job_lock, irqflags);
  770. while (!list_empty(&vc4->job_done_list)) {
  771. struct vc4_exec_info *exec =
  772. list_first_entry(&vc4->job_done_list,
  773. struct vc4_exec_info, head);
  774. list_del(&exec->head);
  775. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  776. vc4_complete_exec(vc4->dev, exec);
  777. spin_lock_irqsave(&vc4->job_lock, irqflags);
  778. }
  779. list_for_each_entry_safe(cb, cb_temp, &vc4->seqno_cb_list, work.entry) {
  780. if (cb->seqno <= vc4->finished_seqno) {
  781. list_del_init(&cb->work.entry);
  782. schedule_work(&cb->work);
  783. }
  784. }
  785. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  786. }
  787. static void vc4_seqno_cb_work(struct work_struct *work)
  788. {
  789. struct vc4_seqno_cb *cb = container_of(work, struct vc4_seqno_cb, work);
  790. cb->func(cb);
  791. }
  792. int vc4_queue_seqno_cb(struct drm_device *dev,
  793. struct vc4_seqno_cb *cb, uint64_t seqno,
  794. void (*func)(struct vc4_seqno_cb *cb))
  795. {
  796. struct vc4_dev *vc4 = to_vc4_dev(dev);
  797. int ret = 0;
  798. unsigned long irqflags;
  799. cb->func = func;
  800. INIT_WORK(&cb->work, vc4_seqno_cb_work);
  801. spin_lock_irqsave(&vc4->job_lock, irqflags);
  802. if (seqno > vc4->finished_seqno) {
  803. cb->seqno = seqno;
  804. list_add_tail(&cb->work.entry, &vc4->seqno_cb_list);
  805. } else {
  806. schedule_work(&cb->work);
  807. }
  808. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  809. return ret;
  810. }
  811. /* Scheduled when any job has been completed, this walks the list of
  812. * jobs that had completed and unrefs their BOs and frees their exec
  813. * structs.
  814. */
  815. static void
  816. vc4_job_done_work(struct work_struct *work)
  817. {
  818. struct vc4_dev *vc4 =
  819. container_of(work, struct vc4_dev, job_done_work);
  820. vc4_job_handle_completed(vc4);
  821. }
  822. static int
  823. vc4_wait_for_seqno_ioctl_helper(struct drm_device *dev,
  824. uint64_t seqno,
  825. uint64_t *timeout_ns)
  826. {
  827. unsigned long start = jiffies;
  828. int ret = vc4_wait_for_seqno(dev, seqno, *timeout_ns, true);
  829. if ((ret == -EINTR || ret == -ERESTARTSYS) && *timeout_ns != ~0ull) {
  830. uint64_t delta = jiffies_to_nsecs(jiffies - start);
  831. if (*timeout_ns >= delta)
  832. *timeout_ns -= delta;
  833. }
  834. return ret;
  835. }
  836. int
  837. vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
  838. struct drm_file *file_priv)
  839. {
  840. struct drm_vc4_wait_seqno *args = data;
  841. return vc4_wait_for_seqno_ioctl_helper(dev, args->seqno,
  842. &args->timeout_ns);
  843. }
  844. int
  845. vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
  846. struct drm_file *file_priv)
  847. {
  848. int ret;
  849. struct drm_vc4_wait_bo *args = data;
  850. struct drm_gem_object *gem_obj;
  851. struct vc4_bo *bo;
  852. if (args->pad != 0)
  853. return -EINVAL;
  854. gem_obj = drm_gem_object_lookup(file_priv, args->handle);
  855. if (!gem_obj) {
  856. DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
  857. return -EINVAL;
  858. }
  859. bo = to_vc4_bo(gem_obj);
  860. ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno,
  861. &args->timeout_ns);
  862. drm_gem_object_put_unlocked(gem_obj);
  863. return ret;
  864. }
  865. /**
  866. * vc4_submit_cl_ioctl() - Submits a job (frame) to the VC4.
  867. * @dev: DRM device
  868. * @data: ioctl argument
  869. * @file_priv: DRM file for this fd
  870. *
  871. * This is the main entrypoint for userspace to submit a 3D frame to
  872. * the GPU. Userspace provides the binner command list (if
  873. * applicable), and the kernel sets up the render command list to draw
  874. * to the framebuffer described in the ioctl, using the command lists
  875. * that the 3D engine's binner will produce.
  876. */
  877. int
  878. vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
  879. struct drm_file *file_priv)
  880. {
  881. struct vc4_dev *vc4 = to_vc4_dev(dev);
  882. struct drm_vc4_submit_cl *args = data;
  883. struct vc4_exec_info *exec;
  884. struct ww_acquire_ctx acquire_ctx;
  885. int ret = 0;
  886. if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
  887. VC4_SUBMIT_CL_FIXED_RCL_ORDER |
  888. VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
  889. VC4_SUBMIT_CL_RCL_ORDER_INCREASING_Y)) != 0) {
  890. DRM_DEBUG("Unknown flags: 0x%02x\n", args->flags);
  891. return -EINVAL;
  892. }
  893. exec = kcalloc(1, sizeof(*exec), GFP_KERNEL);
  894. if (!exec) {
  895. DRM_ERROR("malloc failure on exec struct\n");
  896. return -ENOMEM;
  897. }
  898. mutex_lock(&vc4->power_lock);
  899. if (vc4->power_refcount++ == 0) {
  900. ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  901. if (ret < 0) {
  902. mutex_unlock(&vc4->power_lock);
  903. vc4->power_refcount--;
  904. kfree(exec);
  905. return ret;
  906. }
  907. }
  908. mutex_unlock(&vc4->power_lock);
  909. exec->args = args;
  910. INIT_LIST_HEAD(&exec->unref_list);
  911. ret = vc4_cl_lookup_bos(dev, file_priv, exec);
  912. if (ret)
  913. goto fail;
  914. if (exec->args->bin_cl_size != 0) {
  915. ret = vc4_get_bcl(dev, exec);
  916. if (ret)
  917. goto fail;
  918. } else {
  919. exec->ct0ca = 0;
  920. exec->ct0ea = 0;
  921. }
  922. ret = vc4_get_rcl(dev, exec);
  923. if (ret)
  924. goto fail;
  925. ret = vc4_lock_bo_reservations(dev, exec, &acquire_ctx);
  926. if (ret)
  927. goto fail;
  928. /* Clear this out of the struct we'll be putting in the queue,
  929. * since it's part of our stack.
  930. */
  931. exec->args = NULL;
  932. ret = vc4_queue_submit(dev, exec, &acquire_ctx);
  933. if (ret)
  934. goto fail;
  935. /* Return the seqno for our job. */
  936. args->seqno = vc4->emit_seqno;
  937. return 0;
  938. fail:
  939. vc4_complete_exec(vc4->dev, exec);
  940. return ret;
  941. }
  942. void
  943. vc4_gem_init(struct drm_device *dev)
  944. {
  945. struct vc4_dev *vc4 = to_vc4_dev(dev);
  946. vc4->dma_fence_context = dma_fence_context_alloc(1);
  947. INIT_LIST_HEAD(&vc4->bin_job_list);
  948. INIT_LIST_HEAD(&vc4->render_job_list);
  949. INIT_LIST_HEAD(&vc4->job_done_list);
  950. INIT_LIST_HEAD(&vc4->seqno_cb_list);
  951. spin_lock_init(&vc4->job_lock);
  952. INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
  953. timer_setup(&vc4->hangcheck.timer, vc4_hangcheck_elapsed, 0);
  954. INIT_WORK(&vc4->job_done_work, vc4_job_done_work);
  955. mutex_init(&vc4->power_lock);
  956. INIT_LIST_HEAD(&vc4->purgeable.list);
  957. mutex_init(&vc4->purgeable.lock);
  958. }
  959. void
  960. vc4_gem_destroy(struct drm_device *dev)
  961. {
  962. struct vc4_dev *vc4 = to_vc4_dev(dev);
  963. /* Waiting for exec to finish would need to be done before
  964. * unregistering V3D.
  965. */
  966. WARN_ON(vc4->emit_seqno != vc4->finished_seqno);
  967. /* V3D should already have disabled its interrupt and cleared
  968. * the overflow allocation registers. Now free the object.
  969. */
  970. if (vc4->bin_bo) {
  971. drm_gem_object_put_unlocked(&vc4->bin_bo->base.base);
  972. vc4->bin_bo = NULL;
  973. }
  974. if (vc4->hang_state)
  975. vc4_free_hang_state(dev, vc4->hang_state);
  976. }
  977. int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
  978. struct drm_file *file_priv)
  979. {
  980. struct drm_vc4_gem_madvise *args = data;
  981. struct drm_gem_object *gem_obj;
  982. struct vc4_bo *bo;
  983. int ret;
  984. switch (args->madv) {
  985. case VC4_MADV_DONTNEED:
  986. case VC4_MADV_WILLNEED:
  987. break;
  988. default:
  989. return -EINVAL;
  990. }
  991. if (args->pad != 0)
  992. return -EINVAL;
  993. gem_obj = drm_gem_object_lookup(file_priv, args->handle);
  994. if (!gem_obj) {
  995. DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
  996. return -ENOENT;
  997. }
  998. bo = to_vc4_bo(gem_obj);
  999. /* Only BOs exposed to userspace can be purged. */
  1000. if (bo->madv == __VC4_MADV_NOTSUPP) {
  1001. DRM_DEBUG("madvise not supported on this BO\n");
  1002. ret = -EINVAL;
  1003. goto out_put_gem;
  1004. }
  1005. /* Not sure it's safe to purge imported BOs. Let's just assume it's
  1006. * not until proven otherwise.
  1007. */
  1008. if (gem_obj->import_attach) {
  1009. DRM_DEBUG("madvise not supported on imported BOs\n");
  1010. ret = -EINVAL;
  1011. goto out_put_gem;
  1012. }
  1013. mutex_lock(&bo->madv_lock);
  1014. if (args->madv == VC4_MADV_DONTNEED && bo->madv == VC4_MADV_WILLNEED &&
  1015. !refcount_read(&bo->usecnt)) {
  1016. /* If the BO is about to be marked as purgeable, is not used
  1017. * and is not already purgeable or purged, add it to the
  1018. * purgeable list.
  1019. */
  1020. vc4_bo_add_to_purgeable_pool(bo);
  1021. } else if (args->madv == VC4_MADV_WILLNEED &&
  1022. bo->madv == VC4_MADV_DONTNEED &&
  1023. !refcount_read(&bo->usecnt)) {
  1024. /* The BO has not been purged yet, just remove it from
  1025. * the purgeable list.
  1026. */
  1027. vc4_bo_remove_from_purgeable_pool(bo);
  1028. }
  1029. /* Save the purged state. */
  1030. args->retained = bo->madv != __VC4_MADV_PURGED;
  1031. /* Update internal madv state only if the bo was not purged. */
  1032. if (bo->madv != __VC4_MADV_PURGED)
  1033. bo->madv = args->madv;
  1034. mutex_unlock(&bo->madv_lock);
  1035. ret = 0;
  1036. out_put_gem:
  1037. drm_gem_object_put_unlocked(gem_obj);
  1038. return ret;
  1039. }