radeon_uvd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Copyright 2011 Advanced Micro Devices, Inc.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  16. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  17. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  18. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. *
  21. * The above copyright notice and this permission notice (including the
  22. * next paragraph) shall be included in all copies or substantial portions
  23. * of the Software.
  24. *
  25. */
  26. /*
  27. * Authors:
  28. * Christian König <deathsimple@vodafone.de>
  29. */
  30. #include <linux/firmware.h>
  31. #include <linux/module.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm.h>
  34. #include "radeon.h"
  35. #include "r600d.h"
  36. /* Firmware Names */
  37. #define FIRMWARE_RV710 "radeon/RV710_uvd.bin"
  38. #define FIRMWARE_CYPRESS "radeon/CYPRESS_uvd.bin"
  39. #define FIRMWARE_SUMO "radeon/SUMO_uvd.bin"
  40. #define FIRMWARE_TAHITI "radeon/TAHITI_uvd.bin"
  41. MODULE_FIRMWARE(FIRMWARE_RV710);
  42. MODULE_FIRMWARE(FIRMWARE_CYPRESS);
  43. MODULE_FIRMWARE(FIRMWARE_SUMO);
  44. MODULE_FIRMWARE(FIRMWARE_TAHITI);
  45. int radeon_uvd_init(struct radeon_device *rdev)
  46. {
  47. struct platform_device *pdev;
  48. unsigned long bo_size;
  49. const char *fw_name;
  50. int i, r;
  51. pdev = platform_device_register_simple("radeon_uvd", 0, NULL, 0);
  52. r = IS_ERR(pdev);
  53. if (r) {
  54. dev_err(rdev->dev, "radeon_uvd: Failed to register firmware\n");
  55. return -EINVAL;
  56. }
  57. switch (rdev->family) {
  58. case CHIP_RV710:
  59. case CHIP_RV730:
  60. case CHIP_RV740:
  61. fw_name = FIRMWARE_RV710;
  62. break;
  63. case CHIP_CYPRESS:
  64. case CHIP_HEMLOCK:
  65. case CHIP_JUNIPER:
  66. case CHIP_REDWOOD:
  67. case CHIP_CEDAR:
  68. fw_name = FIRMWARE_CYPRESS;
  69. break;
  70. case CHIP_SUMO:
  71. case CHIP_SUMO2:
  72. case CHIP_PALM:
  73. case CHIP_CAYMAN:
  74. case CHIP_BARTS:
  75. case CHIP_TURKS:
  76. case CHIP_CAICOS:
  77. fw_name = FIRMWARE_SUMO;
  78. break;
  79. case CHIP_TAHITI:
  80. case CHIP_VERDE:
  81. case CHIP_PITCAIRN:
  82. case CHIP_ARUBA:
  83. fw_name = FIRMWARE_TAHITI;
  84. break;
  85. default:
  86. return -EINVAL;
  87. }
  88. r = request_firmware(&rdev->uvd_fw, fw_name, &pdev->dev);
  89. if (r) {
  90. dev_err(rdev->dev, "radeon_uvd: Can't load firmware \"%s\"\n",
  91. fw_name);
  92. platform_device_unregister(pdev);
  93. return r;
  94. }
  95. platform_device_unregister(pdev);
  96. bo_size = RADEON_GPU_PAGE_ALIGN(rdev->uvd_fw->size + 4) +
  97. RADEON_UVD_STACK_SIZE + RADEON_UVD_HEAP_SIZE;
  98. r = radeon_bo_create(rdev, bo_size, PAGE_SIZE, true,
  99. RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->uvd.vcpu_bo);
  100. if (r) {
  101. dev_err(rdev->dev, "(%d) failed to allocate UVD bo\n", r);
  102. return r;
  103. }
  104. r = radeon_uvd_resume(rdev);
  105. if (r)
  106. return r;
  107. memset(rdev->uvd.cpu_addr, 0, bo_size);
  108. memcpy(rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size);
  109. r = radeon_uvd_suspend(rdev);
  110. if (r)
  111. return r;
  112. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  113. atomic_set(&rdev->uvd.handles[i], 0);
  114. rdev->uvd.filp[i] = NULL;
  115. }
  116. return 0;
  117. }
  118. void radeon_uvd_fini(struct radeon_device *rdev)
  119. {
  120. radeon_uvd_suspend(rdev);
  121. radeon_bo_unref(&rdev->uvd.vcpu_bo);
  122. }
  123. int radeon_uvd_suspend(struct radeon_device *rdev)
  124. {
  125. int r;
  126. if (rdev->uvd.vcpu_bo == NULL)
  127. return 0;
  128. r = radeon_bo_reserve(rdev->uvd.vcpu_bo, false);
  129. if (!r) {
  130. radeon_bo_kunmap(rdev->uvd.vcpu_bo);
  131. radeon_bo_unpin(rdev->uvd.vcpu_bo);
  132. radeon_bo_unreserve(rdev->uvd.vcpu_bo);
  133. }
  134. return r;
  135. }
  136. int radeon_uvd_resume(struct radeon_device *rdev)
  137. {
  138. int r;
  139. if (rdev->uvd.vcpu_bo == NULL)
  140. return -EINVAL;
  141. r = radeon_bo_reserve(rdev->uvd.vcpu_bo, false);
  142. if (r) {
  143. radeon_bo_unref(&rdev->uvd.vcpu_bo);
  144. dev_err(rdev->dev, "(%d) failed to reserve UVD bo\n", r);
  145. return r;
  146. }
  147. r = radeon_bo_pin(rdev->uvd.vcpu_bo, RADEON_GEM_DOMAIN_VRAM,
  148. &rdev->uvd.gpu_addr);
  149. if (r) {
  150. radeon_bo_unreserve(rdev->uvd.vcpu_bo);
  151. radeon_bo_unref(&rdev->uvd.vcpu_bo);
  152. dev_err(rdev->dev, "(%d) UVD bo pin failed\n", r);
  153. return r;
  154. }
  155. r = radeon_bo_kmap(rdev->uvd.vcpu_bo, &rdev->uvd.cpu_addr);
  156. if (r) {
  157. dev_err(rdev->dev, "(%d) UVD map failed\n", r);
  158. return r;
  159. }
  160. radeon_bo_unreserve(rdev->uvd.vcpu_bo);
  161. return 0;
  162. }
  163. void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo)
  164. {
  165. rbo->placement.fpfn = 0 >> PAGE_SHIFT;
  166. rbo->placement.lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
  167. }
  168. void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
  169. {
  170. int i, r;
  171. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  172. if (rdev->uvd.filp[i] == filp) {
  173. uint32_t handle = atomic_read(&rdev->uvd.handles[i]);
  174. struct radeon_fence *fence;
  175. r = radeon_uvd_get_destroy_msg(rdev,
  176. R600_RING_TYPE_UVD_INDEX, handle, &fence);
  177. if (r) {
  178. DRM_ERROR("Error destroying UVD (%d)!\n", r);
  179. continue;
  180. }
  181. radeon_fence_wait(fence, false);
  182. radeon_fence_unref(&fence);
  183. rdev->uvd.filp[i] = NULL;
  184. atomic_set(&rdev->uvd.handles[i], 0);
  185. }
  186. }
  187. }
  188. static int radeon_uvd_cs_msg_decode(uint32_t *msg, unsigned buf_sizes[])
  189. {
  190. unsigned stream_type = msg[4];
  191. unsigned width = msg[6];
  192. unsigned height = msg[7];
  193. unsigned dpb_size = msg[9];
  194. unsigned pitch = msg[28];
  195. unsigned width_in_mb = width / 16;
  196. unsigned height_in_mb = ALIGN(height / 16, 2);
  197. unsigned image_size, tmp, min_dpb_size;
  198. image_size = width * height;
  199. image_size += image_size / 2;
  200. image_size = ALIGN(image_size, 1024);
  201. switch (stream_type) {
  202. case 0: /* H264 */
  203. /* reference picture buffer */
  204. min_dpb_size = image_size * 17;
  205. /* macroblock context buffer */
  206. min_dpb_size += width_in_mb * height_in_mb * 17 * 192;
  207. /* IT surface buffer */
  208. min_dpb_size += width_in_mb * height_in_mb * 32;
  209. break;
  210. case 1: /* VC1 */
  211. /* reference picture buffer */
  212. min_dpb_size = image_size * 3;
  213. /* CONTEXT_BUFFER */
  214. min_dpb_size += width_in_mb * height_in_mb * 128;
  215. /* IT surface buffer */
  216. min_dpb_size += width_in_mb * 64;
  217. /* DB surface buffer */
  218. min_dpb_size += width_in_mb * 128;
  219. /* BP */
  220. tmp = max(width_in_mb, height_in_mb);
  221. min_dpb_size += ALIGN(tmp * 7 * 16, 64);
  222. break;
  223. case 3: /* MPEG2 */
  224. /* reference picture buffer */
  225. min_dpb_size = image_size * 3;
  226. break;
  227. case 4: /* MPEG4 */
  228. /* reference picture buffer */
  229. min_dpb_size = image_size * 3;
  230. /* CM */
  231. min_dpb_size += width_in_mb * height_in_mb * 64;
  232. /* IT surface buffer */
  233. min_dpb_size += ALIGN(width_in_mb * height_in_mb * 32, 64);
  234. break;
  235. default:
  236. DRM_ERROR("UVD codec not handled %d!\n", stream_type);
  237. return -EINVAL;
  238. }
  239. if (width > pitch) {
  240. DRM_ERROR("Invalid UVD decoding target pitch!\n");
  241. return -EINVAL;
  242. }
  243. if (dpb_size < min_dpb_size) {
  244. DRM_ERROR("Invalid dpb_size in UVD message (%d / %d)!\n",
  245. dpb_size, min_dpb_size);
  246. return -EINVAL;
  247. }
  248. buf_sizes[0x1] = dpb_size;
  249. buf_sizes[0x2] = image_size;
  250. return 0;
  251. }
  252. static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,
  253. unsigned offset, unsigned buf_sizes[])
  254. {
  255. int32_t *msg, msg_type, handle;
  256. void *ptr;
  257. int i, r;
  258. if (offset & 0x3F) {
  259. DRM_ERROR("UVD messages must be 64 byte aligned!\n");
  260. return -EINVAL;
  261. }
  262. r = radeon_bo_kmap(bo, &ptr);
  263. if (r)
  264. return r;
  265. msg = ptr + offset;
  266. msg_type = msg[1];
  267. handle = msg[2];
  268. if (handle == 0) {
  269. DRM_ERROR("Invalid UVD handle!\n");
  270. return -EINVAL;
  271. }
  272. if (msg_type == 1) {
  273. /* it's a decode msg, calc buffer sizes */
  274. r = radeon_uvd_cs_msg_decode(msg, buf_sizes);
  275. radeon_bo_kunmap(bo);
  276. if (r)
  277. return r;
  278. } else if (msg_type == 2) {
  279. /* it's a destroy msg, free the handle */
  280. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i)
  281. atomic_cmpxchg(&p->rdev->uvd.handles[i], handle, 0);
  282. radeon_bo_kunmap(bo);
  283. return 0;
  284. } else {
  285. /* it's a create msg, no special handling needed */
  286. radeon_bo_kunmap(bo);
  287. }
  288. /* create or decode, validate the handle */
  289. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  290. if (atomic_read(&p->rdev->uvd.handles[i]) == handle)
  291. return 0;
  292. }
  293. /* handle not found try to alloc a new one */
  294. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  295. if (!atomic_cmpxchg(&p->rdev->uvd.handles[i], 0, handle)) {
  296. p->rdev->uvd.filp[i] = p->filp;
  297. return 0;
  298. }
  299. }
  300. DRM_ERROR("No more free UVD handles!\n");
  301. return -EINVAL;
  302. }
  303. static int radeon_uvd_cs_reloc(struct radeon_cs_parser *p,
  304. int data0, int data1,
  305. unsigned buf_sizes[])
  306. {
  307. struct radeon_cs_chunk *relocs_chunk;
  308. struct radeon_cs_reloc *reloc;
  309. unsigned idx, cmd, offset;
  310. uint64_t start, end;
  311. int r;
  312. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  313. offset = radeon_get_ib_value(p, data0);
  314. idx = radeon_get_ib_value(p, data1);
  315. if (idx >= relocs_chunk->length_dw) {
  316. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  317. idx, relocs_chunk->length_dw);
  318. return -EINVAL;
  319. }
  320. reloc = p->relocs_ptr[(idx / 4)];
  321. start = reloc->lobj.gpu_offset;
  322. end = start + radeon_bo_size(reloc->robj);
  323. start += offset;
  324. p->ib.ptr[data0] = start & 0xFFFFFFFF;
  325. p->ib.ptr[data1] = start >> 32;
  326. cmd = radeon_get_ib_value(p, p->idx) >> 1;
  327. if (cmd < 0x4) {
  328. if ((end - start) < buf_sizes[cmd]) {
  329. DRM_ERROR("buffer to small (%d / %d)!\n",
  330. (unsigned)(end - start), buf_sizes[cmd]);
  331. return -EINVAL;
  332. }
  333. } else if (cmd != 0x100) {
  334. DRM_ERROR("invalid UVD command %X!\n", cmd);
  335. return -EINVAL;
  336. }
  337. if (cmd == 0) {
  338. if (end & 0xFFFFFFFFF0000000) {
  339. DRM_ERROR("msg buffer %LX-%LX out of 256MB segment!\n",
  340. start, end);
  341. return -EINVAL;
  342. }
  343. r = radeon_uvd_cs_msg(p, reloc->robj, offset, buf_sizes);
  344. if (r)
  345. return r;
  346. }
  347. if ((start & 0xFFFFFFFFF0000000) != (end & 0xFFFFFFFFF0000000)) {
  348. DRM_ERROR("reloc %LX-%LX crossing 256MB boundary!\n",
  349. start, end);
  350. return -EINVAL;
  351. }
  352. return 0;
  353. }
  354. static int radeon_uvd_cs_reg(struct radeon_cs_parser *p,
  355. struct radeon_cs_packet *pkt,
  356. int *data0, int *data1,
  357. unsigned buf_sizes[])
  358. {
  359. int i, r;
  360. p->idx++;
  361. for (i = 0; i <= pkt->count; ++i) {
  362. switch (pkt->reg + i*4) {
  363. case UVD_GPCOM_VCPU_DATA0:
  364. *data0 = p->idx;
  365. break;
  366. case UVD_GPCOM_VCPU_DATA1:
  367. *data1 = p->idx;
  368. break;
  369. case UVD_GPCOM_VCPU_CMD:
  370. r = radeon_uvd_cs_reloc(p, *data0, *data1, buf_sizes);
  371. if (r)
  372. return r;
  373. break;
  374. case UVD_ENGINE_CNTL:
  375. break;
  376. default:
  377. DRM_ERROR("Invalid reg 0x%X!\n",
  378. pkt->reg + i*4);
  379. return -EINVAL;
  380. }
  381. p->idx++;
  382. }
  383. return 0;
  384. }
  385. int radeon_uvd_cs_parse(struct radeon_cs_parser *p)
  386. {
  387. struct radeon_cs_packet pkt;
  388. int r, data0 = 0, data1 = 0;
  389. /* minimum buffer sizes */
  390. unsigned buf_sizes[] = {
  391. [0x00000000] = 2048,
  392. [0x00000001] = 32 * 1024 * 1024,
  393. [0x00000002] = 2048 * 1152 * 3,
  394. [0x00000003] = 2048,
  395. };
  396. if (p->chunks[p->chunk_ib_idx].length_dw % 16) {
  397. DRM_ERROR("UVD IB length (%d) not 16 dwords aligned!\n",
  398. p->chunks[p->chunk_ib_idx].length_dw);
  399. return -EINVAL;
  400. }
  401. if (p->chunk_relocs_idx == -1) {
  402. DRM_ERROR("No relocation chunk !\n");
  403. return -EINVAL;
  404. }
  405. do {
  406. r = radeon_cs_packet_parse(p, &pkt, p->idx);
  407. if (r)
  408. return r;
  409. switch (pkt.type) {
  410. case RADEON_PACKET_TYPE0:
  411. r = radeon_uvd_cs_reg(p, &pkt, &data0,
  412. &data1, buf_sizes);
  413. if (r)
  414. return r;
  415. break;
  416. case RADEON_PACKET_TYPE2:
  417. p->idx += pkt.count + 2;
  418. break;
  419. default:
  420. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  421. return -EINVAL;
  422. }
  423. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  424. return 0;
  425. }
  426. static int radeon_uvd_send_msg(struct radeon_device *rdev,
  427. int ring, struct radeon_bo *bo,
  428. struct radeon_fence **fence)
  429. {
  430. struct ttm_validate_buffer tv;
  431. struct list_head head;
  432. struct radeon_ib ib;
  433. uint64_t addr;
  434. int i, r;
  435. memset(&tv, 0, sizeof(tv));
  436. tv.bo = &bo->tbo;
  437. INIT_LIST_HEAD(&head);
  438. list_add(&tv.head, &head);
  439. r = ttm_eu_reserve_buffers(&head);
  440. if (r)
  441. return r;
  442. radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_VRAM);
  443. radeon_uvd_force_into_uvd_segment(bo);
  444. r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
  445. if (r) {
  446. ttm_eu_backoff_reservation(&head);
  447. return r;
  448. }
  449. r = radeon_ib_get(rdev, ring, &ib, NULL, 16);
  450. if (r) {
  451. ttm_eu_backoff_reservation(&head);
  452. return r;
  453. }
  454. addr = radeon_bo_gpu_offset(bo);
  455. ib.ptr[0] = PACKET0(UVD_GPCOM_VCPU_DATA0, 0);
  456. ib.ptr[1] = addr;
  457. ib.ptr[2] = PACKET0(UVD_GPCOM_VCPU_DATA1, 0);
  458. ib.ptr[3] = addr >> 32;
  459. ib.ptr[4] = PACKET0(UVD_GPCOM_VCPU_CMD, 0);
  460. ib.ptr[5] = 0;
  461. for (i = 6; i < 16; ++i)
  462. ib.ptr[i] = PACKET2(0);
  463. ib.length_dw = 16;
  464. r = radeon_ib_schedule(rdev, &ib, NULL);
  465. if (r) {
  466. ttm_eu_backoff_reservation(&head);
  467. return r;
  468. }
  469. ttm_eu_fence_buffer_objects(&head, ib.fence);
  470. if (fence)
  471. *fence = radeon_fence_ref(ib.fence);
  472. radeon_ib_free(rdev, &ib);
  473. radeon_bo_unref(&bo);
  474. return 0;
  475. }
  476. /* multiple fence commands without any stream commands in between can
  477. crash the vcpu so just try to emmit a dummy create/destroy msg to
  478. avoid this */
  479. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  480. uint32_t handle, struct radeon_fence **fence)
  481. {
  482. struct radeon_bo *bo;
  483. uint32_t *msg;
  484. int r, i;
  485. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  486. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  487. if (r)
  488. return r;
  489. r = radeon_bo_reserve(bo, false);
  490. if (r) {
  491. radeon_bo_unref(&bo);
  492. return r;
  493. }
  494. r = radeon_bo_kmap(bo, (void **)&msg);
  495. if (r) {
  496. radeon_bo_unreserve(bo);
  497. radeon_bo_unref(&bo);
  498. return r;
  499. }
  500. /* stitch together an UVD create msg */
  501. msg[0] = 0x00000de4;
  502. msg[1] = 0x00000000;
  503. msg[2] = handle;
  504. msg[3] = 0x00000000;
  505. msg[4] = 0x00000000;
  506. msg[5] = 0x00000000;
  507. msg[6] = 0x00000000;
  508. msg[7] = 0x00000780;
  509. msg[8] = 0x00000440;
  510. msg[9] = 0x00000000;
  511. msg[10] = 0x01b37000;
  512. for (i = 11; i < 1024; ++i)
  513. msg[i] = 0x0;
  514. radeon_bo_kunmap(bo);
  515. radeon_bo_unreserve(bo);
  516. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  517. }
  518. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  519. uint32_t handle, struct radeon_fence **fence)
  520. {
  521. struct radeon_bo *bo;
  522. uint32_t *msg;
  523. int r, i;
  524. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  525. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  526. if (r)
  527. return r;
  528. r = radeon_bo_reserve(bo, false);
  529. if (r) {
  530. radeon_bo_unref(&bo);
  531. return r;
  532. }
  533. r = radeon_bo_kmap(bo, (void **)&msg);
  534. if (r) {
  535. radeon_bo_unreserve(bo);
  536. radeon_bo_unref(&bo);
  537. return r;
  538. }
  539. /* stitch together an UVD destroy msg */
  540. msg[0] = 0x00000de4;
  541. msg[1] = 0x00000002;
  542. msg[2] = handle;
  543. msg[3] = 0x00000000;
  544. for (i = 4; i < 1024; ++i)
  545. msg[i] = 0x0;
  546. radeon_bo_kunmap(bo);
  547. radeon_bo_unreserve(bo);
  548. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  549. }