amdgpu_uvd.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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 "amdgpu.h"
  35. #include "amdgpu_pm.h"
  36. #include "amdgpu_uvd.h"
  37. #include "cikd.h"
  38. #include "uvd/uvd_4_2_d.h"
  39. /* 1 second timeout */
  40. #define UVD_IDLE_TIMEOUT msecs_to_jiffies(1000)
  41. /* Firmware versions for VI */
  42. #define FW_1_65_10 ((1 << 24) | (65 << 16) | (10 << 8))
  43. #define FW_1_87_11 ((1 << 24) | (87 << 16) | (11 << 8))
  44. #define FW_1_87_12 ((1 << 24) | (87 << 16) | (12 << 8))
  45. #define FW_1_37_15 ((1 << 24) | (37 << 16) | (15 << 8))
  46. /* Polaris10/11 firmware version */
  47. #define FW_1_66_16 ((1 << 24) | (66 << 16) | (16 << 8))
  48. /* Firmware Names */
  49. #ifdef CONFIG_DRM_AMDGPU_CIK
  50. #define FIRMWARE_BONAIRE "radeon/bonaire_uvd.bin"
  51. #define FIRMWARE_KABINI "radeon/kabini_uvd.bin"
  52. #define FIRMWARE_KAVERI "radeon/kaveri_uvd.bin"
  53. #define FIRMWARE_HAWAII "radeon/hawaii_uvd.bin"
  54. #define FIRMWARE_MULLINS "radeon/mullins_uvd.bin"
  55. #endif
  56. #define FIRMWARE_TONGA "amdgpu/tonga_uvd.bin"
  57. #define FIRMWARE_CARRIZO "amdgpu/carrizo_uvd.bin"
  58. #define FIRMWARE_FIJI "amdgpu/fiji_uvd.bin"
  59. #define FIRMWARE_STONEY "amdgpu/stoney_uvd.bin"
  60. #define FIRMWARE_POLARIS10 "amdgpu/polaris10_uvd.bin"
  61. #define FIRMWARE_POLARIS11 "amdgpu/polaris11_uvd.bin"
  62. /**
  63. * amdgpu_uvd_cs_ctx - Command submission parser context
  64. *
  65. * Used for emulating virtual memory support on UVD 4.2.
  66. */
  67. struct amdgpu_uvd_cs_ctx {
  68. struct amdgpu_cs_parser *parser;
  69. unsigned reg, count;
  70. unsigned data0, data1;
  71. unsigned idx;
  72. unsigned ib_idx;
  73. /* does the IB has a msg command */
  74. bool has_msg_cmd;
  75. /* minimum buffer sizes */
  76. unsigned *buf_sizes;
  77. };
  78. #ifdef CONFIG_DRM_AMDGPU_CIK
  79. MODULE_FIRMWARE(FIRMWARE_BONAIRE);
  80. MODULE_FIRMWARE(FIRMWARE_KABINI);
  81. MODULE_FIRMWARE(FIRMWARE_KAVERI);
  82. MODULE_FIRMWARE(FIRMWARE_HAWAII);
  83. MODULE_FIRMWARE(FIRMWARE_MULLINS);
  84. #endif
  85. MODULE_FIRMWARE(FIRMWARE_TONGA);
  86. MODULE_FIRMWARE(FIRMWARE_CARRIZO);
  87. MODULE_FIRMWARE(FIRMWARE_FIJI);
  88. MODULE_FIRMWARE(FIRMWARE_STONEY);
  89. MODULE_FIRMWARE(FIRMWARE_POLARIS10);
  90. MODULE_FIRMWARE(FIRMWARE_POLARIS11);
  91. static void amdgpu_uvd_idle_work_handler(struct work_struct *work);
  92. int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
  93. {
  94. struct amdgpu_ring *ring;
  95. struct amd_sched_rq *rq;
  96. unsigned long bo_size;
  97. const char *fw_name;
  98. const struct common_firmware_header *hdr;
  99. unsigned version_major, version_minor, family_id;
  100. int i, r;
  101. INIT_DELAYED_WORK(&adev->uvd.idle_work, amdgpu_uvd_idle_work_handler);
  102. switch (adev->asic_type) {
  103. #ifdef CONFIG_DRM_AMDGPU_CIK
  104. case CHIP_BONAIRE:
  105. fw_name = FIRMWARE_BONAIRE;
  106. break;
  107. case CHIP_KABINI:
  108. fw_name = FIRMWARE_KABINI;
  109. break;
  110. case CHIP_KAVERI:
  111. fw_name = FIRMWARE_KAVERI;
  112. break;
  113. case CHIP_HAWAII:
  114. fw_name = FIRMWARE_HAWAII;
  115. break;
  116. case CHIP_MULLINS:
  117. fw_name = FIRMWARE_MULLINS;
  118. break;
  119. #endif
  120. case CHIP_TONGA:
  121. fw_name = FIRMWARE_TONGA;
  122. break;
  123. case CHIP_FIJI:
  124. fw_name = FIRMWARE_FIJI;
  125. break;
  126. case CHIP_CARRIZO:
  127. fw_name = FIRMWARE_CARRIZO;
  128. break;
  129. case CHIP_STONEY:
  130. fw_name = FIRMWARE_STONEY;
  131. break;
  132. case CHIP_POLARIS10:
  133. fw_name = FIRMWARE_POLARIS10;
  134. break;
  135. case CHIP_POLARIS11:
  136. fw_name = FIRMWARE_POLARIS11;
  137. break;
  138. default:
  139. return -EINVAL;
  140. }
  141. r = request_firmware(&adev->uvd.fw, fw_name, adev->dev);
  142. if (r) {
  143. dev_err(adev->dev, "amdgpu_uvd: Can't load firmware \"%s\"\n",
  144. fw_name);
  145. return r;
  146. }
  147. r = amdgpu_ucode_validate(adev->uvd.fw);
  148. if (r) {
  149. dev_err(adev->dev, "amdgpu_uvd: Can't validate firmware \"%s\"\n",
  150. fw_name);
  151. release_firmware(adev->uvd.fw);
  152. adev->uvd.fw = NULL;
  153. return r;
  154. }
  155. /* Set the default UVD handles that the firmware can handle */
  156. adev->uvd.max_handles = AMDGPU_DEFAULT_UVD_HANDLES;
  157. hdr = (const struct common_firmware_header *)adev->uvd.fw->data;
  158. family_id = le32_to_cpu(hdr->ucode_version) & 0xff;
  159. version_major = (le32_to_cpu(hdr->ucode_version) >> 24) & 0xff;
  160. version_minor = (le32_to_cpu(hdr->ucode_version) >> 8) & 0xff;
  161. DRM_INFO("Found UVD firmware Version: %hu.%hu Family ID: %hu\n",
  162. version_major, version_minor, family_id);
  163. /*
  164. * Limit the number of UVD handles depending on microcode major
  165. * and minor versions. The firmware version which has 40 UVD
  166. * instances support is 1.80. So all subsequent versions should
  167. * also have the same support.
  168. */
  169. if ((version_major > 0x01) ||
  170. ((version_major == 0x01) && (version_minor >= 0x50)))
  171. adev->uvd.max_handles = AMDGPU_MAX_UVD_HANDLES;
  172. adev->uvd.fw_version = ((version_major << 24) | (version_minor << 16) |
  173. (family_id << 8));
  174. if ((adev->asic_type == CHIP_POLARIS10 ||
  175. adev->asic_type == CHIP_POLARIS11) &&
  176. (adev->uvd.fw_version < FW_1_66_16))
  177. DRM_ERROR("POLARIS10/11 UVD firmware version %hu.%hu is too old.\n",
  178. version_major, version_minor);
  179. bo_size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8)
  180. + AMDGPU_UVD_STACK_SIZE + AMDGPU_UVD_HEAP_SIZE
  181. + AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles;
  182. r = amdgpu_bo_create(adev, bo_size, PAGE_SIZE, true,
  183. AMDGPU_GEM_DOMAIN_VRAM,
  184. AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
  185. NULL, NULL, &adev->uvd.vcpu_bo);
  186. if (r) {
  187. dev_err(adev->dev, "(%d) failed to allocate UVD bo\n", r);
  188. return r;
  189. }
  190. r = amdgpu_bo_reserve(adev->uvd.vcpu_bo, false);
  191. if (r) {
  192. amdgpu_bo_unref(&adev->uvd.vcpu_bo);
  193. dev_err(adev->dev, "(%d) failed to reserve UVD bo\n", r);
  194. return r;
  195. }
  196. r = amdgpu_bo_pin(adev->uvd.vcpu_bo, AMDGPU_GEM_DOMAIN_VRAM,
  197. &adev->uvd.gpu_addr);
  198. if (r) {
  199. amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
  200. amdgpu_bo_unref(&adev->uvd.vcpu_bo);
  201. dev_err(adev->dev, "(%d) UVD bo pin failed\n", r);
  202. return r;
  203. }
  204. r = amdgpu_bo_kmap(adev->uvd.vcpu_bo, &adev->uvd.cpu_addr);
  205. if (r) {
  206. dev_err(adev->dev, "(%d) UVD map failed\n", r);
  207. return r;
  208. }
  209. amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
  210. ring = &adev->uvd.ring;
  211. rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
  212. r = amd_sched_entity_init(&ring->sched, &adev->uvd.entity,
  213. rq, amdgpu_sched_jobs);
  214. if (r != 0) {
  215. DRM_ERROR("Failed setting up UVD run queue.\n");
  216. return r;
  217. }
  218. for (i = 0; i < adev->uvd.max_handles; ++i) {
  219. atomic_set(&adev->uvd.handles[i], 0);
  220. adev->uvd.filp[i] = NULL;
  221. }
  222. /* from uvd v5.0 HW addressing capacity increased to 64 bits */
  223. if (!amdgpu_ip_block_version_cmp(adev, AMD_IP_BLOCK_TYPE_UVD, 5, 0))
  224. adev->uvd.address_64_bit = true;
  225. switch (adev->asic_type) {
  226. case CHIP_TONGA:
  227. adev->uvd.use_ctx_buf = adev->uvd.fw_version >= FW_1_65_10;
  228. break;
  229. case CHIP_CARRIZO:
  230. adev->uvd.use_ctx_buf = adev->uvd.fw_version >= FW_1_87_11;
  231. break;
  232. case CHIP_FIJI:
  233. adev->uvd.use_ctx_buf = adev->uvd.fw_version >= FW_1_87_12;
  234. break;
  235. case CHIP_STONEY:
  236. adev->uvd.use_ctx_buf = adev->uvd.fw_version >= FW_1_37_15;
  237. break;
  238. default:
  239. adev->uvd.use_ctx_buf = adev->asic_type >= CHIP_POLARIS10;
  240. }
  241. return 0;
  242. }
  243. int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
  244. {
  245. int r;
  246. kfree(adev->uvd.saved_bo);
  247. amd_sched_entity_fini(&adev->uvd.ring.sched, &adev->uvd.entity);
  248. if (adev->uvd.vcpu_bo) {
  249. r = amdgpu_bo_reserve(adev->uvd.vcpu_bo, false);
  250. if (!r) {
  251. amdgpu_bo_kunmap(adev->uvd.vcpu_bo);
  252. amdgpu_bo_unpin(adev->uvd.vcpu_bo);
  253. amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
  254. }
  255. amdgpu_bo_unref(&adev->uvd.vcpu_bo);
  256. }
  257. amdgpu_ring_fini(&adev->uvd.ring);
  258. release_firmware(adev->uvd.fw);
  259. return 0;
  260. }
  261. int amdgpu_uvd_suspend(struct amdgpu_device *adev)
  262. {
  263. unsigned size;
  264. void *ptr;
  265. int i;
  266. if (adev->uvd.vcpu_bo == NULL)
  267. return 0;
  268. for (i = 0; i < adev->uvd.max_handles; ++i)
  269. if (atomic_read(&adev->uvd.handles[i]))
  270. break;
  271. if (i == AMDGPU_MAX_UVD_HANDLES)
  272. return 0;
  273. cancel_delayed_work_sync(&adev->uvd.idle_work);
  274. size = amdgpu_bo_size(adev->uvd.vcpu_bo);
  275. ptr = adev->uvd.cpu_addr;
  276. adev->uvd.saved_bo = kmalloc(size, GFP_KERNEL);
  277. if (!adev->uvd.saved_bo)
  278. return -ENOMEM;
  279. memcpy(adev->uvd.saved_bo, ptr, size);
  280. return 0;
  281. }
  282. int amdgpu_uvd_resume(struct amdgpu_device *adev)
  283. {
  284. unsigned size;
  285. void *ptr;
  286. if (adev->uvd.vcpu_bo == NULL)
  287. return -EINVAL;
  288. size = amdgpu_bo_size(adev->uvd.vcpu_bo);
  289. ptr = adev->uvd.cpu_addr;
  290. if (adev->uvd.saved_bo != NULL) {
  291. memcpy(ptr, adev->uvd.saved_bo, size);
  292. kfree(adev->uvd.saved_bo);
  293. adev->uvd.saved_bo = NULL;
  294. } else {
  295. const struct common_firmware_header *hdr;
  296. unsigned offset;
  297. hdr = (const struct common_firmware_header *)adev->uvd.fw->data;
  298. offset = le32_to_cpu(hdr->ucode_array_offset_bytes);
  299. memcpy(adev->uvd.cpu_addr, (adev->uvd.fw->data) + offset,
  300. (adev->uvd.fw->size) - offset);
  301. size -= le32_to_cpu(hdr->ucode_size_bytes);
  302. ptr += le32_to_cpu(hdr->ucode_size_bytes);
  303. memset(ptr, 0, size);
  304. }
  305. return 0;
  306. }
  307. void amdgpu_uvd_free_handles(struct amdgpu_device *adev, struct drm_file *filp)
  308. {
  309. struct amdgpu_ring *ring = &adev->uvd.ring;
  310. int i, r;
  311. for (i = 0; i < adev->uvd.max_handles; ++i) {
  312. uint32_t handle = atomic_read(&adev->uvd.handles[i]);
  313. if (handle != 0 && adev->uvd.filp[i] == filp) {
  314. struct fence *fence;
  315. r = amdgpu_uvd_get_destroy_msg(ring, handle,
  316. false, &fence);
  317. if (r) {
  318. DRM_ERROR("Error destroying UVD (%d)!\n", r);
  319. continue;
  320. }
  321. fence_wait(fence, false);
  322. fence_put(fence);
  323. adev->uvd.filp[i] = NULL;
  324. atomic_set(&adev->uvd.handles[i], 0);
  325. }
  326. }
  327. }
  328. static void amdgpu_uvd_force_into_uvd_segment(struct amdgpu_bo *rbo)
  329. {
  330. int i;
  331. for (i = 0; i < rbo->placement.num_placement; ++i) {
  332. rbo->placements[i].fpfn = 0 >> PAGE_SHIFT;
  333. rbo->placements[i].lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
  334. }
  335. }
  336. /**
  337. * amdgpu_uvd_cs_pass1 - first parsing round
  338. *
  339. * @ctx: UVD parser context
  340. *
  341. * Make sure UVD message and feedback buffers are in VRAM and
  342. * nobody is violating an 256MB boundary.
  343. */
  344. static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
  345. {
  346. struct amdgpu_bo_va_mapping *mapping;
  347. struct amdgpu_bo *bo;
  348. uint32_t cmd, lo, hi;
  349. uint64_t addr;
  350. int r = 0;
  351. lo = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->data0);
  352. hi = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->data1);
  353. addr = ((uint64_t)lo) | (((uint64_t)hi) << 32);
  354. mapping = amdgpu_cs_find_mapping(ctx->parser, addr, &bo);
  355. if (mapping == NULL) {
  356. DRM_ERROR("Can't find BO for addr 0x%08Lx\n", addr);
  357. return -EINVAL;
  358. }
  359. if (!ctx->parser->adev->uvd.address_64_bit) {
  360. /* check if it's a message or feedback command */
  361. cmd = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->idx) >> 1;
  362. if (cmd == 0x0 || cmd == 0x3) {
  363. /* yes, force it into VRAM */
  364. uint32_t domain = AMDGPU_GEM_DOMAIN_VRAM;
  365. amdgpu_ttm_placement_from_domain(bo, domain);
  366. }
  367. amdgpu_uvd_force_into_uvd_segment(bo);
  368. r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
  369. }
  370. return r;
  371. }
  372. /**
  373. * amdgpu_uvd_cs_msg_decode - handle UVD decode message
  374. *
  375. * @msg: pointer to message structure
  376. * @buf_sizes: returned buffer sizes
  377. *
  378. * Peek into the decode message and calculate the necessary buffer sizes.
  379. */
  380. static int amdgpu_uvd_cs_msg_decode(struct amdgpu_device *adev, uint32_t *msg,
  381. unsigned buf_sizes[])
  382. {
  383. unsigned stream_type = msg[4];
  384. unsigned width = msg[6];
  385. unsigned height = msg[7];
  386. unsigned dpb_size = msg[9];
  387. unsigned pitch = msg[28];
  388. unsigned level = msg[57];
  389. unsigned width_in_mb = width / 16;
  390. unsigned height_in_mb = ALIGN(height / 16, 2);
  391. unsigned fs_in_mb = width_in_mb * height_in_mb;
  392. unsigned image_size, tmp, min_dpb_size, num_dpb_buffer;
  393. unsigned min_ctx_size = ~0;
  394. image_size = width * height;
  395. image_size += image_size / 2;
  396. image_size = ALIGN(image_size, 1024);
  397. switch (stream_type) {
  398. case 0: /* H264 */
  399. switch(level) {
  400. case 30:
  401. num_dpb_buffer = 8100 / fs_in_mb;
  402. break;
  403. case 31:
  404. num_dpb_buffer = 18000 / fs_in_mb;
  405. break;
  406. case 32:
  407. num_dpb_buffer = 20480 / fs_in_mb;
  408. break;
  409. case 41:
  410. num_dpb_buffer = 32768 / fs_in_mb;
  411. break;
  412. case 42:
  413. num_dpb_buffer = 34816 / fs_in_mb;
  414. break;
  415. case 50:
  416. num_dpb_buffer = 110400 / fs_in_mb;
  417. break;
  418. case 51:
  419. num_dpb_buffer = 184320 / fs_in_mb;
  420. break;
  421. default:
  422. num_dpb_buffer = 184320 / fs_in_mb;
  423. break;
  424. }
  425. num_dpb_buffer++;
  426. if (num_dpb_buffer > 17)
  427. num_dpb_buffer = 17;
  428. /* reference picture buffer */
  429. min_dpb_size = image_size * num_dpb_buffer;
  430. /* macroblock context buffer */
  431. min_dpb_size += width_in_mb * height_in_mb * num_dpb_buffer * 192;
  432. /* IT surface buffer */
  433. min_dpb_size += width_in_mb * height_in_mb * 32;
  434. break;
  435. case 1: /* VC1 */
  436. /* reference picture buffer */
  437. min_dpb_size = image_size * 3;
  438. /* CONTEXT_BUFFER */
  439. min_dpb_size += width_in_mb * height_in_mb * 128;
  440. /* IT surface buffer */
  441. min_dpb_size += width_in_mb * 64;
  442. /* DB surface buffer */
  443. min_dpb_size += width_in_mb * 128;
  444. /* BP */
  445. tmp = max(width_in_mb, height_in_mb);
  446. min_dpb_size += ALIGN(tmp * 7 * 16, 64);
  447. break;
  448. case 3: /* MPEG2 */
  449. /* reference picture buffer */
  450. min_dpb_size = image_size * 3;
  451. break;
  452. case 4: /* MPEG4 */
  453. /* reference picture buffer */
  454. min_dpb_size = image_size * 3;
  455. /* CM */
  456. min_dpb_size += width_in_mb * height_in_mb * 64;
  457. /* IT surface buffer */
  458. min_dpb_size += ALIGN(width_in_mb * height_in_mb * 32, 64);
  459. break;
  460. case 7: /* H264 Perf */
  461. switch(level) {
  462. case 30:
  463. num_dpb_buffer = 8100 / fs_in_mb;
  464. break;
  465. case 31:
  466. num_dpb_buffer = 18000 / fs_in_mb;
  467. break;
  468. case 32:
  469. num_dpb_buffer = 20480 / fs_in_mb;
  470. break;
  471. case 41:
  472. num_dpb_buffer = 32768 / fs_in_mb;
  473. break;
  474. case 42:
  475. num_dpb_buffer = 34816 / fs_in_mb;
  476. break;
  477. case 50:
  478. num_dpb_buffer = 110400 / fs_in_mb;
  479. break;
  480. case 51:
  481. num_dpb_buffer = 184320 / fs_in_mb;
  482. break;
  483. default:
  484. num_dpb_buffer = 184320 / fs_in_mb;
  485. break;
  486. }
  487. num_dpb_buffer++;
  488. if (num_dpb_buffer > 17)
  489. num_dpb_buffer = 17;
  490. /* reference picture buffer */
  491. min_dpb_size = image_size * num_dpb_buffer;
  492. if (!adev->uvd.use_ctx_buf){
  493. /* macroblock context buffer */
  494. min_dpb_size +=
  495. width_in_mb * height_in_mb * num_dpb_buffer * 192;
  496. /* IT surface buffer */
  497. min_dpb_size += width_in_mb * height_in_mb * 32;
  498. } else {
  499. /* macroblock context buffer */
  500. min_ctx_size =
  501. width_in_mb * height_in_mb * num_dpb_buffer * 192;
  502. }
  503. break;
  504. case 16: /* H265 */
  505. image_size = (ALIGN(width, 16) * ALIGN(height, 16) * 3) / 2;
  506. image_size = ALIGN(image_size, 256);
  507. num_dpb_buffer = (le32_to_cpu(msg[59]) & 0xff) + 2;
  508. min_dpb_size = image_size * num_dpb_buffer;
  509. min_ctx_size = ((width + 255) / 16) * ((height + 255) / 16)
  510. * 16 * num_dpb_buffer + 52 * 1024;
  511. break;
  512. default:
  513. DRM_ERROR("UVD codec not handled %d!\n", stream_type);
  514. return -EINVAL;
  515. }
  516. if (width > pitch) {
  517. DRM_ERROR("Invalid UVD decoding target pitch!\n");
  518. return -EINVAL;
  519. }
  520. if (dpb_size < min_dpb_size) {
  521. DRM_ERROR("Invalid dpb_size in UVD message (%d / %d)!\n",
  522. dpb_size, min_dpb_size);
  523. return -EINVAL;
  524. }
  525. buf_sizes[0x1] = dpb_size;
  526. buf_sizes[0x2] = image_size;
  527. buf_sizes[0x4] = min_ctx_size;
  528. return 0;
  529. }
  530. /**
  531. * amdgpu_uvd_cs_msg - handle UVD message
  532. *
  533. * @ctx: UVD parser context
  534. * @bo: buffer object containing the message
  535. * @offset: offset into the buffer object
  536. *
  537. * Peek into the UVD message and extract the session id.
  538. * Make sure that we don't open up to many sessions.
  539. */
  540. static int amdgpu_uvd_cs_msg(struct amdgpu_uvd_cs_ctx *ctx,
  541. struct amdgpu_bo *bo, unsigned offset)
  542. {
  543. struct amdgpu_device *adev = ctx->parser->adev;
  544. int32_t *msg, msg_type, handle;
  545. void *ptr;
  546. long r;
  547. int i;
  548. if (offset & 0x3F) {
  549. DRM_ERROR("UVD messages must be 64 byte aligned!\n");
  550. return -EINVAL;
  551. }
  552. r = amdgpu_bo_kmap(bo, &ptr);
  553. if (r) {
  554. DRM_ERROR("Failed mapping the UVD message (%ld)!\n", r);
  555. return r;
  556. }
  557. msg = ptr + offset;
  558. msg_type = msg[1];
  559. handle = msg[2];
  560. if (handle == 0) {
  561. DRM_ERROR("Invalid UVD handle!\n");
  562. return -EINVAL;
  563. }
  564. switch (msg_type) {
  565. case 0:
  566. /* it's a create msg, calc image size (width * height) */
  567. amdgpu_bo_kunmap(bo);
  568. /* try to alloc a new handle */
  569. for (i = 0; i < adev->uvd.max_handles; ++i) {
  570. if (atomic_read(&adev->uvd.handles[i]) == handle) {
  571. DRM_ERROR("Handle 0x%x already in use!\n", handle);
  572. return -EINVAL;
  573. }
  574. if (!atomic_cmpxchg(&adev->uvd.handles[i], 0, handle)) {
  575. adev->uvd.filp[i] = ctx->parser->filp;
  576. return 0;
  577. }
  578. }
  579. DRM_ERROR("No more free UVD handles!\n");
  580. return -ENOSPC;
  581. case 1:
  582. /* it's a decode msg, calc buffer sizes */
  583. r = amdgpu_uvd_cs_msg_decode(adev, msg, ctx->buf_sizes);
  584. amdgpu_bo_kunmap(bo);
  585. if (r)
  586. return r;
  587. /* validate the handle */
  588. for (i = 0; i < adev->uvd.max_handles; ++i) {
  589. if (atomic_read(&adev->uvd.handles[i]) == handle) {
  590. if (adev->uvd.filp[i] != ctx->parser->filp) {
  591. DRM_ERROR("UVD handle collision detected!\n");
  592. return -EINVAL;
  593. }
  594. return 0;
  595. }
  596. }
  597. DRM_ERROR("Invalid UVD handle 0x%x!\n", handle);
  598. return -ENOENT;
  599. case 2:
  600. /* it's a destroy msg, free the handle */
  601. for (i = 0; i < adev->uvd.max_handles; ++i)
  602. atomic_cmpxchg(&adev->uvd.handles[i], handle, 0);
  603. amdgpu_bo_kunmap(bo);
  604. return 0;
  605. default:
  606. DRM_ERROR("Illegal UVD message type (%d)!\n", msg_type);
  607. return -EINVAL;
  608. }
  609. BUG();
  610. return -EINVAL;
  611. }
  612. /**
  613. * amdgpu_uvd_cs_pass2 - second parsing round
  614. *
  615. * @ctx: UVD parser context
  616. *
  617. * Patch buffer addresses, make sure buffer sizes are correct.
  618. */
  619. static int amdgpu_uvd_cs_pass2(struct amdgpu_uvd_cs_ctx *ctx)
  620. {
  621. struct amdgpu_bo_va_mapping *mapping;
  622. struct amdgpu_bo *bo;
  623. uint32_t cmd, lo, hi;
  624. uint64_t start, end;
  625. uint64_t addr;
  626. int r;
  627. lo = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->data0);
  628. hi = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->data1);
  629. addr = ((uint64_t)lo) | (((uint64_t)hi) << 32);
  630. mapping = amdgpu_cs_find_mapping(ctx->parser, addr, &bo);
  631. if (mapping == NULL)
  632. return -EINVAL;
  633. start = amdgpu_bo_gpu_offset(bo);
  634. end = (mapping->it.last + 1 - mapping->it.start);
  635. end = end * AMDGPU_GPU_PAGE_SIZE + start;
  636. addr -= ((uint64_t)mapping->it.start) * AMDGPU_GPU_PAGE_SIZE;
  637. start += addr;
  638. amdgpu_set_ib_value(ctx->parser, ctx->ib_idx, ctx->data0,
  639. lower_32_bits(start));
  640. amdgpu_set_ib_value(ctx->parser, ctx->ib_idx, ctx->data1,
  641. upper_32_bits(start));
  642. cmd = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->idx) >> 1;
  643. if (cmd < 0x4) {
  644. if ((end - start) < ctx->buf_sizes[cmd]) {
  645. DRM_ERROR("buffer (%d) to small (%d / %d)!\n", cmd,
  646. (unsigned)(end - start),
  647. ctx->buf_sizes[cmd]);
  648. return -EINVAL;
  649. }
  650. } else if (cmd == 0x206) {
  651. if ((end - start) < ctx->buf_sizes[4]) {
  652. DRM_ERROR("buffer (%d) to small (%d / %d)!\n", cmd,
  653. (unsigned)(end - start),
  654. ctx->buf_sizes[4]);
  655. return -EINVAL;
  656. }
  657. } else if ((cmd != 0x100) && (cmd != 0x204)) {
  658. DRM_ERROR("invalid UVD command %X!\n", cmd);
  659. return -EINVAL;
  660. }
  661. if (!ctx->parser->adev->uvd.address_64_bit) {
  662. if ((start >> 28) != ((end - 1) >> 28)) {
  663. DRM_ERROR("reloc %LX-%LX crossing 256MB boundary!\n",
  664. start, end);
  665. return -EINVAL;
  666. }
  667. if ((cmd == 0 || cmd == 0x3) &&
  668. (start >> 28) != (ctx->parser->adev->uvd.gpu_addr >> 28)) {
  669. DRM_ERROR("msg/fb buffer %LX-%LX out of 256MB segment!\n",
  670. start, end);
  671. return -EINVAL;
  672. }
  673. }
  674. if (cmd == 0) {
  675. ctx->has_msg_cmd = true;
  676. r = amdgpu_uvd_cs_msg(ctx, bo, addr);
  677. if (r)
  678. return r;
  679. } else if (!ctx->has_msg_cmd) {
  680. DRM_ERROR("Message needed before other commands are send!\n");
  681. return -EINVAL;
  682. }
  683. return 0;
  684. }
  685. /**
  686. * amdgpu_uvd_cs_reg - parse register writes
  687. *
  688. * @ctx: UVD parser context
  689. * @cb: callback function
  690. *
  691. * Parse the register writes, call cb on each complete command.
  692. */
  693. static int amdgpu_uvd_cs_reg(struct amdgpu_uvd_cs_ctx *ctx,
  694. int (*cb)(struct amdgpu_uvd_cs_ctx *ctx))
  695. {
  696. struct amdgpu_ib *ib = &ctx->parser->job->ibs[ctx->ib_idx];
  697. int i, r;
  698. ctx->idx++;
  699. for (i = 0; i <= ctx->count; ++i) {
  700. unsigned reg = ctx->reg + i;
  701. if (ctx->idx >= ib->length_dw) {
  702. DRM_ERROR("Register command after end of CS!\n");
  703. return -EINVAL;
  704. }
  705. switch (reg) {
  706. case mmUVD_GPCOM_VCPU_DATA0:
  707. ctx->data0 = ctx->idx;
  708. break;
  709. case mmUVD_GPCOM_VCPU_DATA1:
  710. ctx->data1 = ctx->idx;
  711. break;
  712. case mmUVD_GPCOM_VCPU_CMD:
  713. r = cb(ctx);
  714. if (r)
  715. return r;
  716. break;
  717. case mmUVD_ENGINE_CNTL:
  718. break;
  719. default:
  720. DRM_ERROR("Invalid reg 0x%X!\n", reg);
  721. return -EINVAL;
  722. }
  723. ctx->idx++;
  724. }
  725. return 0;
  726. }
  727. /**
  728. * amdgpu_uvd_cs_packets - parse UVD packets
  729. *
  730. * @ctx: UVD parser context
  731. * @cb: callback function
  732. *
  733. * Parse the command stream packets.
  734. */
  735. static int amdgpu_uvd_cs_packets(struct amdgpu_uvd_cs_ctx *ctx,
  736. int (*cb)(struct amdgpu_uvd_cs_ctx *ctx))
  737. {
  738. struct amdgpu_ib *ib = &ctx->parser->job->ibs[ctx->ib_idx];
  739. int r;
  740. for (ctx->idx = 0 ; ctx->idx < ib->length_dw; ) {
  741. uint32_t cmd = amdgpu_get_ib_value(ctx->parser, ctx->ib_idx, ctx->idx);
  742. unsigned type = CP_PACKET_GET_TYPE(cmd);
  743. switch (type) {
  744. case PACKET_TYPE0:
  745. ctx->reg = CP_PACKET0_GET_REG(cmd);
  746. ctx->count = CP_PACKET_GET_COUNT(cmd);
  747. r = amdgpu_uvd_cs_reg(ctx, cb);
  748. if (r)
  749. return r;
  750. break;
  751. case PACKET_TYPE2:
  752. ++ctx->idx;
  753. break;
  754. default:
  755. DRM_ERROR("Unknown packet type %d !\n", type);
  756. return -EINVAL;
  757. }
  758. }
  759. return 0;
  760. }
  761. /**
  762. * amdgpu_uvd_ring_parse_cs - UVD command submission parser
  763. *
  764. * @parser: Command submission parser context
  765. *
  766. * Parse the command stream, patch in addresses as necessary.
  767. */
  768. int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)
  769. {
  770. struct amdgpu_uvd_cs_ctx ctx = {};
  771. unsigned buf_sizes[] = {
  772. [0x00000000] = 2048,
  773. [0x00000001] = 0xFFFFFFFF,
  774. [0x00000002] = 0xFFFFFFFF,
  775. [0x00000003] = 2048,
  776. [0x00000004] = 0xFFFFFFFF,
  777. };
  778. struct amdgpu_ib *ib = &parser->job->ibs[ib_idx];
  779. int r;
  780. if (ib->length_dw % 16) {
  781. DRM_ERROR("UVD IB length (%d) not 16 dwords aligned!\n",
  782. ib->length_dw);
  783. return -EINVAL;
  784. }
  785. ctx.parser = parser;
  786. ctx.buf_sizes = buf_sizes;
  787. ctx.ib_idx = ib_idx;
  788. /* first round, make sure the buffers are actually in the UVD segment */
  789. r = amdgpu_uvd_cs_packets(&ctx, amdgpu_uvd_cs_pass1);
  790. if (r)
  791. return r;
  792. /* second round, patch buffer addresses into the command stream */
  793. r = amdgpu_uvd_cs_packets(&ctx, amdgpu_uvd_cs_pass2);
  794. if (r)
  795. return r;
  796. if (!ctx.has_msg_cmd) {
  797. DRM_ERROR("UVD-IBs need a msg command!\n");
  798. return -EINVAL;
  799. }
  800. return 0;
  801. }
  802. static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,
  803. bool direct, struct fence **fence)
  804. {
  805. struct ttm_validate_buffer tv;
  806. struct ww_acquire_ctx ticket;
  807. struct list_head head;
  808. struct amdgpu_job *job;
  809. struct amdgpu_ib *ib;
  810. struct fence *f = NULL;
  811. struct amdgpu_device *adev = ring->adev;
  812. uint64_t addr;
  813. int i, r;
  814. memset(&tv, 0, sizeof(tv));
  815. tv.bo = &bo->tbo;
  816. INIT_LIST_HEAD(&head);
  817. list_add(&tv.head, &head);
  818. r = ttm_eu_reserve_buffers(&ticket, &head, true, NULL);
  819. if (r)
  820. return r;
  821. if (!bo->adev->uvd.address_64_bit) {
  822. amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
  823. amdgpu_uvd_force_into_uvd_segment(bo);
  824. }
  825. r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
  826. if (r)
  827. goto err;
  828. r = amdgpu_job_alloc_with_ib(adev, 64, &job);
  829. if (r)
  830. goto err;
  831. ib = &job->ibs[0];
  832. addr = amdgpu_bo_gpu_offset(bo);
  833. ib->ptr[0] = PACKET0(mmUVD_GPCOM_VCPU_DATA0, 0);
  834. ib->ptr[1] = addr;
  835. ib->ptr[2] = PACKET0(mmUVD_GPCOM_VCPU_DATA1, 0);
  836. ib->ptr[3] = addr >> 32;
  837. ib->ptr[4] = PACKET0(mmUVD_GPCOM_VCPU_CMD, 0);
  838. ib->ptr[5] = 0;
  839. for (i = 6; i < 16; ++i)
  840. ib->ptr[i] = PACKET2(0);
  841. ib->length_dw = 16;
  842. if (direct) {
  843. r = amdgpu_ib_schedule(ring, 1, ib, NULL, NULL, &f);
  844. job->fence = fence_get(f);
  845. if (r)
  846. goto err_free;
  847. amdgpu_job_free(job);
  848. } else {
  849. r = amdgpu_job_submit(job, ring, &adev->uvd.entity,
  850. AMDGPU_FENCE_OWNER_UNDEFINED, &f);
  851. if (r)
  852. goto err_free;
  853. }
  854. ttm_eu_fence_buffer_objects(&ticket, &head, f);
  855. if (fence)
  856. *fence = fence_get(f);
  857. amdgpu_bo_unref(&bo);
  858. fence_put(f);
  859. return 0;
  860. err_free:
  861. amdgpu_job_free(job);
  862. err:
  863. ttm_eu_backoff_reservation(&ticket, &head);
  864. return r;
  865. }
  866. /* multiple fence commands without any stream commands in between can
  867. crash the vcpu so just try to emmit a dummy create/destroy msg to
  868. avoid this */
  869. int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
  870. struct fence **fence)
  871. {
  872. struct amdgpu_device *adev = ring->adev;
  873. struct amdgpu_bo *bo;
  874. uint32_t *msg;
  875. int r, i;
  876. r = amdgpu_bo_create(adev, 1024, PAGE_SIZE, true,
  877. AMDGPU_GEM_DOMAIN_VRAM,
  878. AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
  879. NULL, NULL, &bo);
  880. if (r)
  881. return r;
  882. r = amdgpu_bo_reserve(bo, false);
  883. if (r) {
  884. amdgpu_bo_unref(&bo);
  885. return r;
  886. }
  887. r = amdgpu_bo_kmap(bo, (void **)&msg);
  888. if (r) {
  889. amdgpu_bo_unreserve(bo);
  890. amdgpu_bo_unref(&bo);
  891. return r;
  892. }
  893. /* stitch together an UVD create msg */
  894. msg[0] = cpu_to_le32(0x00000de4);
  895. msg[1] = cpu_to_le32(0x00000000);
  896. msg[2] = cpu_to_le32(handle);
  897. msg[3] = cpu_to_le32(0x00000000);
  898. msg[4] = cpu_to_le32(0x00000000);
  899. msg[5] = cpu_to_le32(0x00000000);
  900. msg[6] = cpu_to_le32(0x00000000);
  901. msg[7] = cpu_to_le32(0x00000780);
  902. msg[8] = cpu_to_le32(0x00000440);
  903. msg[9] = cpu_to_le32(0x00000000);
  904. msg[10] = cpu_to_le32(0x01b37000);
  905. for (i = 11; i < 1024; ++i)
  906. msg[i] = cpu_to_le32(0x0);
  907. amdgpu_bo_kunmap(bo);
  908. amdgpu_bo_unreserve(bo);
  909. return amdgpu_uvd_send_msg(ring, bo, true, fence);
  910. }
  911. int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
  912. bool direct, struct fence **fence)
  913. {
  914. struct amdgpu_device *adev = ring->adev;
  915. struct amdgpu_bo *bo;
  916. uint32_t *msg;
  917. int r, i;
  918. r = amdgpu_bo_create(adev, 1024, PAGE_SIZE, true,
  919. AMDGPU_GEM_DOMAIN_VRAM,
  920. AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
  921. NULL, NULL, &bo);
  922. if (r)
  923. return r;
  924. r = amdgpu_bo_reserve(bo, false);
  925. if (r) {
  926. amdgpu_bo_unref(&bo);
  927. return r;
  928. }
  929. r = amdgpu_bo_kmap(bo, (void **)&msg);
  930. if (r) {
  931. amdgpu_bo_unreserve(bo);
  932. amdgpu_bo_unref(&bo);
  933. return r;
  934. }
  935. /* stitch together an UVD destroy msg */
  936. msg[0] = cpu_to_le32(0x00000de4);
  937. msg[1] = cpu_to_le32(0x00000002);
  938. msg[2] = cpu_to_le32(handle);
  939. msg[3] = cpu_to_le32(0x00000000);
  940. for (i = 4; i < 1024; ++i)
  941. msg[i] = cpu_to_le32(0x0);
  942. amdgpu_bo_kunmap(bo);
  943. amdgpu_bo_unreserve(bo);
  944. return amdgpu_uvd_send_msg(ring, bo, direct, fence);
  945. }
  946. static void amdgpu_uvd_idle_work_handler(struct work_struct *work)
  947. {
  948. struct amdgpu_device *adev =
  949. container_of(work, struct amdgpu_device, uvd.idle_work.work);
  950. unsigned i, fences, handles = 0;
  951. fences = amdgpu_fence_count_emitted(&adev->uvd.ring);
  952. for (i = 0; i < adev->uvd.max_handles; ++i)
  953. if (atomic_read(&adev->uvd.handles[i]))
  954. ++handles;
  955. if (fences == 0 && handles == 0) {
  956. if (adev->pm.dpm_enabled) {
  957. amdgpu_dpm_enable_uvd(adev, false);
  958. } else {
  959. amdgpu_asic_set_uvd_clocks(adev, 0, 0);
  960. }
  961. } else {
  962. schedule_delayed_work(&adev->uvd.idle_work, UVD_IDLE_TIMEOUT);
  963. }
  964. }
  965. void amdgpu_uvd_ring_begin_use(struct amdgpu_ring *ring)
  966. {
  967. struct amdgpu_device *adev = ring->adev;
  968. bool set_clocks = !cancel_delayed_work_sync(&adev->uvd.idle_work);
  969. if (set_clocks) {
  970. if (adev->pm.dpm_enabled) {
  971. amdgpu_dpm_enable_uvd(adev, true);
  972. } else {
  973. amdgpu_asic_set_uvd_clocks(adev, 53300, 40000);
  974. }
  975. }
  976. }
  977. void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring)
  978. {
  979. schedule_delayed_work(&ring->adev->uvd.idle_work, UVD_IDLE_TIMEOUT);
  980. }
  981. /**
  982. * amdgpu_uvd_ring_test_ib - test ib execution
  983. *
  984. * @ring: amdgpu_ring pointer
  985. *
  986. * Test if we can successfully execute an IB
  987. */
  988. int amdgpu_uvd_ring_test_ib(struct amdgpu_ring *ring, long timeout)
  989. {
  990. struct fence *fence;
  991. long r;
  992. r = amdgpu_uvd_get_create_msg(ring, 1, NULL);
  993. if (r) {
  994. DRM_ERROR("amdgpu: failed to get create msg (%ld).\n", r);
  995. goto error;
  996. }
  997. r = amdgpu_uvd_get_destroy_msg(ring, 1, true, &fence);
  998. if (r) {
  999. DRM_ERROR("amdgpu: failed to get destroy ib (%ld).\n", r);
  1000. goto error;
  1001. }
  1002. r = fence_wait_timeout(fence, false, timeout);
  1003. if (r == 0) {
  1004. DRM_ERROR("amdgpu: IB test timed out.\n");
  1005. r = -ETIMEDOUT;
  1006. } else if (r < 0) {
  1007. DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
  1008. } else {
  1009. DRM_INFO("ib test on ring %d succeeded\n", ring->idx);
  1010. r = 0;
  1011. }
  1012. fence_put(fence);
  1013. error:
  1014. return r;
  1015. }