radeon_uvd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. radeon_set_uvd_clocks(rdev, 53300, 40000);
  162. return 0;
  163. }
  164. void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo)
  165. {
  166. rbo->placement.fpfn = 0 >> PAGE_SHIFT;
  167. rbo->placement.lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
  168. }
  169. void radeon_uvd_free_handles(struct radeon_device *rdev, struct drm_file *filp)
  170. {
  171. int i, r;
  172. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  173. if (rdev->uvd.filp[i] == filp) {
  174. uint32_t handle = atomic_read(&rdev->uvd.handles[i]);
  175. struct radeon_fence *fence;
  176. r = radeon_uvd_get_destroy_msg(rdev,
  177. R600_RING_TYPE_UVD_INDEX, handle, &fence);
  178. if (r) {
  179. DRM_ERROR("Error destroying UVD (%d)!\n", r);
  180. continue;
  181. }
  182. radeon_fence_wait(fence, false);
  183. radeon_fence_unref(&fence);
  184. rdev->uvd.filp[i] = NULL;
  185. atomic_set(&rdev->uvd.handles[i], 0);
  186. }
  187. }
  188. }
  189. static int radeon_uvd_cs_msg_decode(uint32_t *msg, unsigned buf_sizes[])
  190. {
  191. unsigned stream_type = msg[4];
  192. unsigned width = msg[6];
  193. unsigned height = msg[7];
  194. unsigned dpb_size = msg[9];
  195. unsigned pitch = msg[28];
  196. unsigned width_in_mb = width / 16;
  197. unsigned height_in_mb = ALIGN(height / 16, 2);
  198. unsigned image_size, tmp, min_dpb_size;
  199. image_size = width * height;
  200. image_size += image_size / 2;
  201. image_size = ALIGN(image_size, 1024);
  202. switch (stream_type) {
  203. case 0: /* H264 */
  204. /* reference picture buffer */
  205. min_dpb_size = image_size * 17;
  206. /* macroblock context buffer */
  207. min_dpb_size += width_in_mb * height_in_mb * 17 * 192;
  208. /* IT surface buffer */
  209. min_dpb_size += width_in_mb * height_in_mb * 32;
  210. break;
  211. case 1: /* VC1 */
  212. /* reference picture buffer */
  213. min_dpb_size = image_size * 3;
  214. /* CONTEXT_BUFFER */
  215. min_dpb_size += width_in_mb * height_in_mb * 128;
  216. /* IT surface buffer */
  217. min_dpb_size += width_in_mb * 64;
  218. /* DB surface buffer */
  219. min_dpb_size += width_in_mb * 128;
  220. /* BP */
  221. tmp = max(width_in_mb, height_in_mb);
  222. min_dpb_size += ALIGN(tmp * 7 * 16, 64);
  223. break;
  224. case 3: /* MPEG2 */
  225. /* reference picture buffer */
  226. min_dpb_size = image_size * 3;
  227. break;
  228. case 4: /* MPEG4 */
  229. /* reference picture buffer */
  230. min_dpb_size = image_size * 3;
  231. /* CM */
  232. min_dpb_size += width_in_mb * height_in_mb * 64;
  233. /* IT surface buffer */
  234. min_dpb_size += ALIGN(width_in_mb * height_in_mb * 32, 64);
  235. break;
  236. default:
  237. DRM_ERROR("UVD codec not handled %d!\n", stream_type);
  238. return -EINVAL;
  239. }
  240. if (width > pitch) {
  241. DRM_ERROR("Invalid UVD decoding target pitch!\n");
  242. return -EINVAL;
  243. }
  244. if (dpb_size < min_dpb_size) {
  245. DRM_ERROR("Invalid dpb_size in UVD message (%d / %d)!\n",
  246. dpb_size, min_dpb_size);
  247. return -EINVAL;
  248. }
  249. buf_sizes[0x1] = dpb_size;
  250. buf_sizes[0x2] = image_size;
  251. return 0;
  252. }
  253. static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,
  254. unsigned offset, unsigned buf_sizes[])
  255. {
  256. int32_t *msg, msg_type, handle;
  257. void *ptr;
  258. int i, r;
  259. if (offset & 0x3F) {
  260. DRM_ERROR("UVD messages must be 64 byte aligned!\n");
  261. return -EINVAL;
  262. }
  263. r = radeon_bo_kmap(bo, &ptr);
  264. if (r)
  265. return r;
  266. msg = ptr + offset;
  267. msg_type = msg[1];
  268. handle = msg[2];
  269. if (handle == 0) {
  270. DRM_ERROR("Invalid UVD handle!\n");
  271. return -EINVAL;
  272. }
  273. if (msg_type == 1) {
  274. /* it's a decode msg, calc buffer sizes */
  275. r = radeon_uvd_cs_msg_decode(msg, buf_sizes);
  276. radeon_bo_kunmap(bo);
  277. if (r)
  278. return r;
  279. } else if (msg_type == 2) {
  280. /* it's a destroy msg, free the handle */
  281. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i)
  282. atomic_cmpxchg(&p->rdev->uvd.handles[i], handle, 0);
  283. radeon_bo_kunmap(bo);
  284. return 0;
  285. } else {
  286. /* it's a create msg, no special handling needed */
  287. radeon_bo_kunmap(bo);
  288. }
  289. /* create or decode, validate the handle */
  290. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  291. if (atomic_read(&p->rdev->uvd.handles[i]) == handle)
  292. return 0;
  293. }
  294. /* handle not found try to alloc a new one */
  295. for (i = 0; i < RADEON_MAX_UVD_HANDLES; ++i) {
  296. if (!atomic_cmpxchg(&p->rdev->uvd.handles[i], 0, handle)) {
  297. p->rdev->uvd.filp[i] = p->filp;
  298. return 0;
  299. }
  300. }
  301. DRM_ERROR("No more free UVD handles!\n");
  302. return -EINVAL;
  303. }
  304. static int radeon_uvd_cs_reloc(struct radeon_cs_parser *p,
  305. int data0, int data1,
  306. unsigned buf_sizes[])
  307. {
  308. struct radeon_cs_chunk *relocs_chunk;
  309. struct radeon_cs_reloc *reloc;
  310. unsigned idx, cmd, offset;
  311. uint64_t start, end;
  312. int r;
  313. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  314. offset = radeon_get_ib_value(p, data0);
  315. idx = radeon_get_ib_value(p, data1);
  316. if (idx >= relocs_chunk->length_dw) {
  317. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  318. idx, relocs_chunk->length_dw);
  319. return -EINVAL;
  320. }
  321. reloc = p->relocs_ptr[(idx / 4)];
  322. start = reloc->lobj.gpu_offset;
  323. end = start + radeon_bo_size(reloc->robj);
  324. start += offset;
  325. p->ib.ptr[data0] = start & 0xFFFFFFFF;
  326. p->ib.ptr[data1] = start >> 32;
  327. cmd = radeon_get_ib_value(p, p->idx) >> 1;
  328. if (cmd < 0x4) {
  329. if ((end - start) < buf_sizes[cmd]) {
  330. DRM_ERROR("buffer to small (%d / %d)!\n",
  331. (unsigned)(end - start), buf_sizes[cmd]);
  332. return -EINVAL;
  333. }
  334. } else if (cmd != 0x100) {
  335. DRM_ERROR("invalid UVD command %X!\n", cmd);
  336. return -EINVAL;
  337. }
  338. if (cmd == 0) {
  339. if (end & 0xFFFFFFFFF0000000) {
  340. DRM_ERROR("msg buffer %LX-%LX out of 256MB segment!\n",
  341. start, end);
  342. return -EINVAL;
  343. }
  344. r = radeon_uvd_cs_msg(p, reloc->robj, offset, buf_sizes);
  345. if (r)
  346. return r;
  347. }
  348. if ((start & 0xFFFFFFFFF0000000) != (end & 0xFFFFFFFFF0000000)) {
  349. DRM_ERROR("reloc %LX-%LX crossing 256MB boundary!\n",
  350. start, end);
  351. return -EINVAL;
  352. }
  353. return 0;
  354. }
  355. static int radeon_uvd_cs_reg(struct radeon_cs_parser *p,
  356. struct radeon_cs_packet *pkt,
  357. int *data0, int *data1,
  358. unsigned buf_sizes[])
  359. {
  360. int i, r;
  361. p->idx++;
  362. for (i = 0; i <= pkt->count; ++i) {
  363. switch (pkt->reg + i*4) {
  364. case UVD_GPCOM_VCPU_DATA0:
  365. *data0 = p->idx;
  366. break;
  367. case UVD_GPCOM_VCPU_DATA1:
  368. *data1 = p->idx;
  369. break;
  370. case UVD_GPCOM_VCPU_CMD:
  371. r = radeon_uvd_cs_reloc(p, *data0, *data1, buf_sizes);
  372. if (r)
  373. return r;
  374. break;
  375. case UVD_ENGINE_CNTL:
  376. break;
  377. default:
  378. DRM_ERROR("Invalid reg 0x%X!\n",
  379. pkt->reg + i*4);
  380. return -EINVAL;
  381. }
  382. p->idx++;
  383. }
  384. return 0;
  385. }
  386. int radeon_uvd_cs_parse(struct radeon_cs_parser *p)
  387. {
  388. struct radeon_cs_packet pkt;
  389. int r, data0 = 0, data1 = 0;
  390. /* minimum buffer sizes */
  391. unsigned buf_sizes[] = {
  392. [0x00000000] = 2048,
  393. [0x00000001] = 32 * 1024 * 1024,
  394. [0x00000002] = 2048 * 1152 * 3,
  395. [0x00000003] = 2048,
  396. };
  397. if (p->chunks[p->chunk_ib_idx].length_dw % 16) {
  398. DRM_ERROR("UVD IB length (%d) not 16 dwords aligned!\n",
  399. p->chunks[p->chunk_ib_idx].length_dw);
  400. return -EINVAL;
  401. }
  402. if (p->chunk_relocs_idx == -1) {
  403. DRM_ERROR("No relocation chunk !\n");
  404. return -EINVAL;
  405. }
  406. do {
  407. r = radeon_cs_packet_parse(p, &pkt, p->idx);
  408. if (r)
  409. return r;
  410. switch (pkt.type) {
  411. case RADEON_PACKET_TYPE0:
  412. r = radeon_uvd_cs_reg(p, &pkt, &data0,
  413. &data1, buf_sizes);
  414. if (r)
  415. return r;
  416. break;
  417. case RADEON_PACKET_TYPE2:
  418. p->idx += pkt.count + 2;
  419. break;
  420. default:
  421. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  422. return -EINVAL;
  423. }
  424. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  425. return 0;
  426. }
  427. static int radeon_uvd_send_msg(struct radeon_device *rdev,
  428. int ring, struct radeon_bo *bo,
  429. struct radeon_fence **fence)
  430. {
  431. struct ttm_validate_buffer tv;
  432. struct list_head head;
  433. struct radeon_ib ib;
  434. uint64_t addr;
  435. int i, r;
  436. memset(&tv, 0, sizeof(tv));
  437. tv.bo = &bo->tbo;
  438. INIT_LIST_HEAD(&head);
  439. list_add(&tv.head, &head);
  440. r = ttm_eu_reserve_buffers(&head);
  441. if (r)
  442. return r;
  443. radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_VRAM);
  444. radeon_uvd_force_into_uvd_segment(bo);
  445. r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
  446. if (r) {
  447. ttm_eu_backoff_reservation(&head);
  448. return r;
  449. }
  450. r = radeon_ib_get(rdev, ring, &ib, NULL, 16);
  451. if (r) {
  452. ttm_eu_backoff_reservation(&head);
  453. return r;
  454. }
  455. addr = radeon_bo_gpu_offset(bo);
  456. ib.ptr[0] = PACKET0(UVD_GPCOM_VCPU_DATA0, 0);
  457. ib.ptr[1] = addr;
  458. ib.ptr[2] = PACKET0(UVD_GPCOM_VCPU_DATA1, 0);
  459. ib.ptr[3] = addr >> 32;
  460. ib.ptr[4] = PACKET0(UVD_GPCOM_VCPU_CMD, 0);
  461. ib.ptr[5] = 0;
  462. for (i = 6; i < 16; ++i)
  463. ib.ptr[i] = PACKET2(0);
  464. ib.length_dw = 16;
  465. r = radeon_ib_schedule(rdev, &ib, NULL);
  466. if (r) {
  467. ttm_eu_backoff_reservation(&head);
  468. return r;
  469. }
  470. ttm_eu_fence_buffer_objects(&head, ib.fence);
  471. if (fence)
  472. *fence = radeon_fence_ref(ib.fence);
  473. radeon_ib_free(rdev, &ib);
  474. radeon_bo_unref(&bo);
  475. return 0;
  476. }
  477. /* multiple fence commands without any stream commands in between can
  478. crash the vcpu so just try to emmit a dummy create/destroy msg to
  479. avoid this */
  480. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  481. uint32_t handle, struct radeon_fence **fence)
  482. {
  483. struct radeon_bo *bo;
  484. uint32_t *msg;
  485. int r, i;
  486. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  487. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  488. if (r)
  489. return r;
  490. r = radeon_bo_reserve(bo, false);
  491. if (r) {
  492. radeon_bo_unref(&bo);
  493. return r;
  494. }
  495. r = radeon_bo_kmap(bo, (void **)&msg);
  496. if (r) {
  497. radeon_bo_unreserve(bo);
  498. radeon_bo_unref(&bo);
  499. return r;
  500. }
  501. /* stitch together an UVD create msg */
  502. msg[0] = 0x00000de4;
  503. msg[1] = 0x00000000;
  504. msg[2] = handle;
  505. msg[3] = 0x00000000;
  506. msg[4] = 0x00000000;
  507. msg[5] = 0x00000000;
  508. msg[6] = 0x00000000;
  509. msg[7] = 0x00000780;
  510. msg[8] = 0x00000440;
  511. msg[9] = 0x00000000;
  512. msg[10] = 0x01b37000;
  513. for (i = 11; i < 1024; ++i)
  514. msg[i] = 0x0;
  515. radeon_bo_kunmap(bo);
  516. radeon_bo_unreserve(bo);
  517. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  518. }
  519. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  520. uint32_t handle, struct radeon_fence **fence)
  521. {
  522. struct radeon_bo *bo;
  523. uint32_t *msg;
  524. int r, i;
  525. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  526. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  527. if (r)
  528. return r;
  529. r = radeon_bo_reserve(bo, false);
  530. if (r) {
  531. radeon_bo_unref(&bo);
  532. return r;
  533. }
  534. r = radeon_bo_kmap(bo, (void **)&msg);
  535. if (r) {
  536. radeon_bo_unreserve(bo);
  537. radeon_bo_unref(&bo);
  538. return r;
  539. }
  540. /* stitch together an UVD destroy msg */
  541. msg[0] = 0x00000de4;
  542. msg[1] = 0x00000002;
  543. msg[2] = handle;
  544. msg[3] = 0x00000000;
  545. for (i = 4; i < 1024; ++i)
  546. msg[i] = 0x0;
  547. radeon_bo_kunmap(bo);
  548. radeon_bo_unreserve(bo);
  549. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  550. }