radeon_uvd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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 + 8) +
  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 ((start >> 28) != (end >> 28)) {
  339. DRM_ERROR("reloc %LX-%LX crossing 256MB boundary!\n",
  340. start, end);
  341. return -EINVAL;
  342. }
  343. /* TODO: is this still necessary on NI+ ? */
  344. if ((cmd == 0 || cmd == 0x3) &&
  345. (start >> 28) != (p->rdev->uvd.gpu_addr >> 28)) {
  346. DRM_ERROR("msg/fb buffer %LX-%LX out of 256MB segment!\n",
  347. start, end);
  348. return -EINVAL;
  349. }
  350. if (cmd == 0) {
  351. r = radeon_uvd_cs_msg(p, reloc->robj, offset, buf_sizes);
  352. if (r)
  353. return r;
  354. }
  355. return 0;
  356. }
  357. static int radeon_uvd_cs_reg(struct radeon_cs_parser *p,
  358. struct radeon_cs_packet *pkt,
  359. int *data0, int *data1,
  360. unsigned buf_sizes[])
  361. {
  362. int i, r;
  363. p->idx++;
  364. for (i = 0; i <= pkt->count; ++i) {
  365. switch (pkt->reg + i*4) {
  366. case UVD_GPCOM_VCPU_DATA0:
  367. *data0 = p->idx;
  368. break;
  369. case UVD_GPCOM_VCPU_DATA1:
  370. *data1 = p->idx;
  371. break;
  372. case UVD_GPCOM_VCPU_CMD:
  373. r = radeon_uvd_cs_reloc(p, *data0, *data1, buf_sizes);
  374. if (r)
  375. return r;
  376. break;
  377. case UVD_ENGINE_CNTL:
  378. break;
  379. default:
  380. DRM_ERROR("Invalid reg 0x%X!\n",
  381. pkt->reg + i*4);
  382. return -EINVAL;
  383. }
  384. p->idx++;
  385. }
  386. return 0;
  387. }
  388. int radeon_uvd_cs_parse(struct radeon_cs_parser *p)
  389. {
  390. struct radeon_cs_packet pkt;
  391. int r, data0 = 0, data1 = 0;
  392. /* minimum buffer sizes */
  393. unsigned buf_sizes[] = {
  394. [0x00000000] = 2048,
  395. [0x00000001] = 32 * 1024 * 1024,
  396. [0x00000002] = 2048 * 1152 * 3,
  397. [0x00000003] = 2048,
  398. };
  399. if (p->chunks[p->chunk_ib_idx].length_dw % 16) {
  400. DRM_ERROR("UVD IB length (%d) not 16 dwords aligned!\n",
  401. p->chunks[p->chunk_ib_idx].length_dw);
  402. return -EINVAL;
  403. }
  404. if (p->chunk_relocs_idx == -1) {
  405. DRM_ERROR("No relocation chunk !\n");
  406. return -EINVAL;
  407. }
  408. do {
  409. r = radeon_cs_packet_parse(p, &pkt, p->idx);
  410. if (r)
  411. return r;
  412. switch (pkt.type) {
  413. case RADEON_PACKET_TYPE0:
  414. r = radeon_uvd_cs_reg(p, &pkt, &data0,
  415. &data1, buf_sizes);
  416. if (r)
  417. return r;
  418. break;
  419. case RADEON_PACKET_TYPE2:
  420. p->idx += pkt.count + 2;
  421. break;
  422. default:
  423. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  424. return -EINVAL;
  425. }
  426. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  427. return 0;
  428. }
  429. static int radeon_uvd_send_msg(struct radeon_device *rdev,
  430. int ring, struct radeon_bo *bo,
  431. struct radeon_fence **fence)
  432. {
  433. struct ttm_validate_buffer tv;
  434. struct list_head head;
  435. struct radeon_ib ib;
  436. uint64_t addr;
  437. int i, r;
  438. memset(&tv, 0, sizeof(tv));
  439. tv.bo = &bo->tbo;
  440. INIT_LIST_HEAD(&head);
  441. list_add(&tv.head, &head);
  442. r = ttm_eu_reserve_buffers(&head);
  443. if (r)
  444. return r;
  445. radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_VRAM);
  446. radeon_uvd_force_into_uvd_segment(bo);
  447. r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
  448. if (r) {
  449. ttm_eu_backoff_reservation(&head);
  450. return r;
  451. }
  452. r = radeon_ib_get(rdev, ring, &ib, NULL, 16);
  453. if (r) {
  454. ttm_eu_backoff_reservation(&head);
  455. return r;
  456. }
  457. addr = radeon_bo_gpu_offset(bo);
  458. ib.ptr[0] = PACKET0(UVD_GPCOM_VCPU_DATA0, 0);
  459. ib.ptr[1] = addr;
  460. ib.ptr[2] = PACKET0(UVD_GPCOM_VCPU_DATA1, 0);
  461. ib.ptr[3] = addr >> 32;
  462. ib.ptr[4] = PACKET0(UVD_GPCOM_VCPU_CMD, 0);
  463. ib.ptr[5] = 0;
  464. for (i = 6; i < 16; ++i)
  465. ib.ptr[i] = PACKET2(0);
  466. ib.length_dw = 16;
  467. r = radeon_ib_schedule(rdev, &ib, NULL);
  468. if (r) {
  469. ttm_eu_backoff_reservation(&head);
  470. return r;
  471. }
  472. ttm_eu_fence_buffer_objects(&head, ib.fence);
  473. if (fence)
  474. *fence = radeon_fence_ref(ib.fence);
  475. radeon_ib_free(rdev, &ib);
  476. radeon_bo_unref(&bo);
  477. return 0;
  478. }
  479. /* multiple fence commands without any stream commands in between can
  480. crash the vcpu so just try to emmit a dummy create/destroy msg to
  481. avoid this */
  482. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  483. uint32_t handle, struct radeon_fence **fence)
  484. {
  485. struct radeon_bo *bo;
  486. uint32_t *msg;
  487. int r, i;
  488. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  489. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  490. if (r)
  491. return r;
  492. r = radeon_bo_reserve(bo, false);
  493. if (r) {
  494. radeon_bo_unref(&bo);
  495. return r;
  496. }
  497. r = radeon_bo_kmap(bo, (void **)&msg);
  498. if (r) {
  499. radeon_bo_unreserve(bo);
  500. radeon_bo_unref(&bo);
  501. return r;
  502. }
  503. /* stitch together an UVD create msg */
  504. msg[0] = 0x00000de4;
  505. msg[1] = 0x00000000;
  506. msg[2] = handle;
  507. msg[3] = 0x00000000;
  508. msg[4] = 0x00000000;
  509. msg[5] = 0x00000000;
  510. msg[6] = 0x00000000;
  511. msg[7] = 0x00000780;
  512. msg[8] = 0x00000440;
  513. msg[9] = 0x00000000;
  514. msg[10] = 0x01b37000;
  515. for (i = 11; i < 1024; ++i)
  516. msg[i] = 0x0;
  517. radeon_bo_kunmap(bo);
  518. radeon_bo_unreserve(bo);
  519. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  520. }
  521. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  522. uint32_t handle, struct radeon_fence **fence)
  523. {
  524. struct radeon_bo *bo;
  525. uint32_t *msg;
  526. int r, i;
  527. r = radeon_bo_create(rdev, 1024, PAGE_SIZE, true,
  528. RADEON_GEM_DOMAIN_VRAM, NULL, &bo);
  529. if (r)
  530. return r;
  531. r = radeon_bo_reserve(bo, false);
  532. if (r) {
  533. radeon_bo_unref(&bo);
  534. return r;
  535. }
  536. r = radeon_bo_kmap(bo, (void **)&msg);
  537. if (r) {
  538. radeon_bo_unreserve(bo);
  539. radeon_bo_unref(&bo);
  540. return r;
  541. }
  542. /* stitch together an UVD destroy msg */
  543. msg[0] = 0x00000de4;
  544. msg[1] = 0x00000002;
  545. msg[2] = handle;
  546. msg[3] = 0x00000000;
  547. for (i = 4; i < 1024; ++i)
  548. msg[i] = 0x0;
  549. radeon_bo_kunmap(bo);
  550. radeon_bo_unreserve(bo);
  551. return radeon_uvd_send_msg(rdev, ring, bo, fence);
  552. }