evergreen_cs.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include "drmP.h"
  29. #include "radeon.h"
  30. #include "evergreend.h"
  31. #include "evergreen_reg_safe.h"
  32. #include "cayman_reg_safe.h"
  33. static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
  34. struct radeon_cs_reloc **cs_reloc);
  35. struct evergreen_cs_track {
  36. u32 group_size;
  37. u32 nbanks;
  38. u32 npipes;
  39. /* value we track */
  40. u32 nsamples;
  41. u32 cb_color_base_last[12];
  42. struct radeon_bo *cb_color_bo[12];
  43. u32 cb_color_bo_offset[12];
  44. struct radeon_bo *cb_color_fmask_bo[8];
  45. struct radeon_bo *cb_color_cmask_bo[8];
  46. u32 cb_color_info[12];
  47. u32 cb_color_view[12];
  48. u32 cb_color_pitch_idx[12];
  49. u32 cb_color_slice_idx[12];
  50. u32 cb_color_dim_idx[12];
  51. u32 cb_color_dim[12];
  52. u32 cb_color_pitch[12];
  53. u32 cb_color_slice[12];
  54. u32 cb_color_cmask_slice[8];
  55. u32 cb_color_fmask_slice[8];
  56. u32 cb_target_mask;
  57. u32 cb_shader_mask;
  58. u32 vgt_strmout_config;
  59. u32 vgt_strmout_buffer_config;
  60. u32 db_depth_control;
  61. u32 db_depth_view;
  62. u32 db_depth_size;
  63. u32 db_depth_size_idx;
  64. u32 db_z_info;
  65. u32 db_z_idx;
  66. u32 db_z_read_offset;
  67. u32 db_z_write_offset;
  68. struct radeon_bo *db_z_read_bo;
  69. struct radeon_bo *db_z_write_bo;
  70. u32 db_s_info;
  71. u32 db_s_idx;
  72. u32 db_s_read_offset;
  73. u32 db_s_write_offset;
  74. struct radeon_bo *db_s_read_bo;
  75. struct radeon_bo *db_s_write_bo;
  76. };
  77. static void evergreen_cs_track_init(struct evergreen_cs_track *track)
  78. {
  79. int i;
  80. for (i = 0; i < 8; i++) {
  81. track->cb_color_fmask_bo[i] = NULL;
  82. track->cb_color_cmask_bo[i] = NULL;
  83. track->cb_color_cmask_slice[i] = 0;
  84. track->cb_color_fmask_slice[i] = 0;
  85. }
  86. for (i = 0; i < 12; i++) {
  87. track->cb_color_base_last[i] = 0;
  88. track->cb_color_bo[i] = NULL;
  89. track->cb_color_bo_offset[i] = 0xFFFFFFFF;
  90. track->cb_color_info[i] = 0;
  91. track->cb_color_view[i] = 0;
  92. track->cb_color_pitch_idx[i] = 0;
  93. track->cb_color_slice_idx[i] = 0;
  94. track->cb_color_dim[i] = 0;
  95. track->cb_color_pitch[i] = 0;
  96. track->cb_color_slice[i] = 0;
  97. track->cb_color_dim[i] = 0;
  98. }
  99. track->cb_target_mask = 0xFFFFFFFF;
  100. track->cb_shader_mask = 0xFFFFFFFF;
  101. track->db_depth_view = 0xFFFFC000;
  102. track->db_depth_size = 0xFFFFFFFF;
  103. track->db_depth_size_idx = 0;
  104. track->db_depth_control = 0xFFFFFFFF;
  105. track->db_z_info = 0xFFFFFFFF;
  106. track->db_z_idx = 0xFFFFFFFF;
  107. track->db_z_read_offset = 0xFFFFFFFF;
  108. track->db_z_write_offset = 0xFFFFFFFF;
  109. track->db_z_read_bo = NULL;
  110. track->db_z_write_bo = NULL;
  111. track->db_s_info = 0xFFFFFFFF;
  112. track->db_s_idx = 0xFFFFFFFF;
  113. track->db_s_read_offset = 0xFFFFFFFF;
  114. track->db_s_write_offset = 0xFFFFFFFF;
  115. track->db_s_read_bo = NULL;
  116. track->db_s_write_bo = NULL;
  117. }
  118. static int evergreen_cs_track_check(struct radeon_cs_parser *p)
  119. {
  120. struct evergreen_cs_track *track = p->track;
  121. /* we don't support stream out buffer yet */
  122. if (track->vgt_strmout_config || track->vgt_strmout_buffer_config) {
  123. dev_warn(p->dev, "this kernel doesn't support SMX output buffer\n");
  124. return -EINVAL;
  125. }
  126. /* XXX fill in */
  127. return 0;
  128. }
  129. /**
  130. * evergreen_cs_packet_parse() - parse cp packet and point ib index to next packet
  131. * @parser: parser structure holding parsing context.
  132. * @pkt: where to store packet informations
  133. *
  134. * Assume that chunk_ib_index is properly set. Will return -EINVAL
  135. * if packet is bigger than remaining ib size. or if packets is unknown.
  136. **/
  137. int evergreen_cs_packet_parse(struct radeon_cs_parser *p,
  138. struct radeon_cs_packet *pkt,
  139. unsigned idx)
  140. {
  141. struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
  142. uint32_t header;
  143. if (idx >= ib_chunk->length_dw) {
  144. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  145. idx, ib_chunk->length_dw);
  146. return -EINVAL;
  147. }
  148. header = radeon_get_ib_value(p, idx);
  149. pkt->idx = idx;
  150. pkt->type = CP_PACKET_GET_TYPE(header);
  151. pkt->count = CP_PACKET_GET_COUNT(header);
  152. pkt->one_reg_wr = 0;
  153. switch (pkt->type) {
  154. case PACKET_TYPE0:
  155. pkt->reg = CP_PACKET0_GET_REG(header);
  156. break;
  157. case PACKET_TYPE3:
  158. pkt->opcode = CP_PACKET3_GET_OPCODE(header);
  159. break;
  160. case PACKET_TYPE2:
  161. pkt->count = -1;
  162. break;
  163. default:
  164. DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
  165. return -EINVAL;
  166. }
  167. if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
  168. DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
  169. pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
  170. return -EINVAL;
  171. }
  172. return 0;
  173. }
  174. /**
  175. * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3
  176. * @parser: parser structure holding parsing context.
  177. * @data: pointer to relocation data
  178. * @offset_start: starting offset
  179. * @offset_mask: offset mask (to align start offset on)
  180. * @reloc: reloc informations
  181. *
  182. * Check next packet is relocation packet3, do bo validation and compute
  183. * GPU offset using the provided start.
  184. **/
  185. static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
  186. struct radeon_cs_reloc **cs_reloc)
  187. {
  188. struct radeon_cs_chunk *relocs_chunk;
  189. struct radeon_cs_packet p3reloc;
  190. unsigned idx;
  191. int r;
  192. if (p->chunk_relocs_idx == -1) {
  193. DRM_ERROR("No relocation chunk !\n");
  194. return -EINVAL;
  195. }
  196. *cs_reloc = NULL;
  197. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  198. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx);
  199. if (r) {
  200. return r;
  201. }
  202. p->idx += p3reloc.count + 2;
  203. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  204. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  205. p3reloc.idx);
  206. return -EINVAL;
  207. }
  208. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  209. if (idx >= relocs_chunk->length_dw) {
  210. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  211. idx, relocs_chunk->length_dw);
  212. return -EINVAL;
  213. }
  214. /* FIXME: we assume reloc size is 4 dwords */
  215. *cs_reloc = p->relocs_ptr[(idx / 4)];
  216. return 0;
  217. }
  218. /**
  219. * evergreen_cs_packet_next_vline() - parse userspace VLINE packet
  220. * @parser: parser structure holding parsing context.
  221. *
  222. * Userspace sends a special sequence for VLINE waits.
  223. * PACKET0 - VLINE_START_END + value
  224. * PACKET3 - WAIT_REG_MEM poll vline status reg
  225. * RELOC (P3) - crtc_id in reloc.
  226. *
  227. * This function parses this and relocates the VLINE START END
  228. * and WAIT_REG_MEM packets to the correct crtc.
  229. * It also detects a switched off crtc and nulls out the
  230. * wait in that case.
  231. */
  232. static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
  233. {
  234. struct drm_mode_object *obj;
  235. struct drm_crtc *crtc;
  236. struct radeon_crtc *radeon_crtc;
  237. struct radeon_cs_packet p3reloc, wait_reg_mem;
  238. int crtc_id;
  239. int r;
  240. uint32_t header, h_idx, reg, wait_reg_mem_info;
  241. volatile uint32_t *ib;
  242. ib = p->ib->ptr;
  243. /* parse the WAIT_REG_MEM */
  244. r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx);
  245. if (r)
  246. return r;
  247. /* check its a WAIT_REG_MEM */
  248. if (wait_reg_mem.type != PACKET_TYPE3 ||
  249. wait_reg_mem.opcode != PACKET3_WAIT_REG_MEM) {
  250. DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
  251. return -EINVAL;
  252. }
  253. wait_reg_mem_info = radeon_get_ib_value(p, wait_reg_mem.idx + 1);
  254. /* bit 4 is reg (0) or mem (1) */
  255. if (wait_reg_mem_info & 0x10) {
  256. DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
  257. return -EINVAL;
  258. }
  259. /* waiting for value to be equal */
  260. if ((wait_reg_mem_info & 0x7) != 0x3) {
  261. DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
  262. return -EINVAL;
  263. }
  264. if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != EVERGREEN_VLINE_STATUS) {
  265. DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
  266. return -EINVAL;
  267. }
  268. if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != EVERGREEN_VLINE_STAT) {
  269. DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
  270. return -EINVAL;
  271. }
  272. /* jump over the NOP */
  273. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
  274. if (r)
  275. return r;
  276. h_idx = p->idx - 2;
  277. p->idx += wait_reg_mem.count + 2;
  278. p->idx += p3reloc.count + 2;
  279. header = radeon_get_ib_value(p, h_idx);
  280. crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
  281. reg = CP_PACKET0_GET_REG(header);
  282. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  283. if (!obj) {
  284. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  285. return -EINVAL;
  286. }
  287. crtc = obj_to_crtc(obj);
  288. radeon_crtc = to_radeon_crtc(crtc);
  289. crtc_id = radeon_crtc->crtc_id;
  290. if (!crtc->enabled) {
  291. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  292. ib[h_idx + 2] = PACKET2(0);
  293. ib[h_idx + 3] = PACKET2(0);
  294. ib[h_idx + 4] = PACKET2(0);
  295. ib[h_idx + 5] = PACKET2(0);
  296. ib[h_idx + 6] = PACKET2(0);
  297. ib[h_idx + 7] = PACKET2(0);
  298. ib[h_idx + 8] = PACKET2(0);
  299. } else {
  300. switch (reg) {
  301. case EVERGREEN_VLINE_START_END:
  302. header &= ~R600_CP_PACKET0_REG_MASK;
  303. header |= (EVERGREEN_VLINE_START_END + radeon_crtc->crtc_offset) >> 2;
  304. ib[h_idx] = header;
  305. ib[h_idx + 4] = (EVERGREEN_VLINE_STATUS + radeon_crtc->crtc_offset) >> 2;
  306. break;
  307. default:
  308. DRM_ERROR("unknown crtc reloc\n");
  309. return -EINVAL;
  310. }
  311. }
  312. return 0;
  313. }
  314. static int evergreen_packet0_check(struct radeon_cs_parser *p,
  315. struct radeon_cs_packet *pkt,
  316. unsigned idx, unsigned reg)
  317. {
  318. int r;
  319. switch (reg) {
  320. case EVERGREEN_VLINE_START_END:
  321. r = evergreen_cs_packet_parse_vline(p);
  322. if (r) {
  323. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  324. idx, reg);
  325. return r;
  326. }
  327. break;
  328. default:
  329. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  330. reg, idx);
  331. return -EINVAL;
  332. }
  333. return 0;
  334. }
  335. static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
  336. struct radeon_cs_packet *pkt)
  337. {
  338. unsigned reg, i;
  339. unsigned idx;
  340. int r;
  341. idx = pkt->idx + 1;
  342. reg = pkt->reg;
  343. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  344. r = evergreen_packet0_check(p, pkt, idx, reg);
  345. if (r) {
  346. return r;
  347. }
  348. }
  349. return 0;
  350. }
  351. /**
  352. * evergreen_cs_check_reg() - check if register is authorized or not
  353. * @parser: parser structure holding parsing context
  354. * @reg: register we are testing
  355. * @idx: index into the cs buffer
  356. *
  357. * This function will test against evergreen_reg_safe_bm and return 0
  358. * if register is safe. If register is not flag as safe this function
  359. * will test it against a list of register needind special handling.
  360. */
  361. static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  362. {
  363. struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
  364. struct radeon_cs_reloc *reloc;
  365. u32 last_reg;
  366. u32 m, i, tmp, *ib;
  367. int r;
  368. if (p->rdev->family >= CHIP_CAYMAN)
  369. last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
  370. else
  371. last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
  372. i = (reg >> 7);
  373. if (i >= last_reg) {
  374. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  375. return -EINVAL;
  376. }
  377. m = 1 << ((reg >> 2) & 31);
  378. if (p->rdev->family >= CHIP_CAYMAN) {
  379. if (!(cayman_reg_safe_bm[i] & m))
  380. return 0;
  381. } else {
  382. if (!(evergreen_reg_safe_bm[i] & m))
  383. return 0;
  384. }
  385. ib = p->ib->ptr;
  386. switch (reg) {
  387. /* force following reg to 0 in an attempt to disable out buffer
  388. * which will need us to better understand how it works to perform
  389. * security check on it (Jerome)
  390. */
  391. case SQ_ESGS_RING_SIZE:
  392. case SQ_GSVS_RING_SIZE:
  393. case SQ_ESTMP_RING_SIZE:
  394. case SQ_GSTMP_RING_SIZE:
  395. case SQ_HSTMP_RING_SIZE:
  396. case SQ_LSTMP_RING_SIZE:
  397. case SQ_PSTMP_RING_SIZE:
  398. case SQ_VSTMP_RING_SIZE:
  399. case SQ_ESGS_RING_ITEMSIZE:
  400. case SQ_ESTMP_RING_ITEMSIZE:
  401. case SQ_GSTMP_RING_ITEMSIZE:
  402. case SQ_GSVS_RING_ITEMSIZE:
  403. case SQ_GS_VERT_ITEMSIZE:
  404. case SQ_GS_VERT_ITEMSIZE_1:
  405. case SQ_GS_VERT_ITEMSIZE_2:
  406. case SQ_GS_VERT_ITEMSIZE_3:
  407. case SQ_GSVS_RING_OFFSET_1:
  408. case SQ_GSVS_RING_OFFSET_2:
  409. case SQ_GSVS_RING_OFFSET_3:
  410. case SQ_HSTMP_RING_ITEMSIZE:
  411. case SQ_LSTMP_RING_ITEMSIZE:
  412. case SQ_PSTMP_RING_ITEMSIZE:
  413. case SQ_VSTMP_RING_ITEMSIZE:
  414. case VGT_TF_RING_SIZE:
  415. /* get value to populate the IB don't remove */
  416. /*tmp =radeon_get_ib_value(p, idx);
  417. ib[idx] = 0;*/
  418. break;
  419. case SQ_ESGS_RING_BASE:
  420. case SQ_GSVS_RING_BASE:
  421. case SQ_ESTMP_RING_BASE:
  422. case SQ_GSTMP_RING_BASE:
  423. case SQ_HSTMP_RING_BASE:
  424. case SQ_LSTMP_RING_BASE:
  425. case SQ_PSTMP_RING_BASE:
  426. case SQ_VSTMP_RING_BASE:
  427. r = evergreen_cs_packet_next_reloc(p, &reloc);
  428. if (r) {
  429. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  430. "0x%04X\n", reg);
  431. return -EINVAL;
  432. }
  433. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  434. break;
  435. case DB_DEPTH_CONTROL:
  436. track->db_depth_control = radeon_get_ib_value(p, idx);
  437. break;
  438. case CAYMAN_DB_EQAA:
  439. if (p->rdev->family < CHIP_CAYMAN) {
  440. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  441. "0x%04X\n", reg);
  442. return -EINVAL;
  443. }
  444. break;
  445. case CAYMAN_DB_DEPTH_INFO:
  446. if (p->rdev->family < CHIP_CAYMAN) {
  447. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  448. "0x%04X\n", reg);
  449. return -EINVAL;
  450. }
  451. break;
  452. case DB_Z_INFO:
  453. track->db_z_info = radeon_get_ib_value(p, idx);
  454. if (!p->keep_tiling_flags) {
  455. r = evergreen_cs_packet_next_reloc(p, &reloc);
  456. if (r) {
  457. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  458. "0x%04X\n", reg);
  459. return -EINVAL;
  460. }
  461. ib[idx] &= ~Z_ARRAY_MODE(0xf);
  462. track->db_z_info &= ~Z_ARRAY_MODE(0xf);
  463. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  464. ib[idx] |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  465. track->db_z_info |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  466. } else {
  467. ib[idx] |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  468. track->db_z_info |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  469. }
  470. }
  471. break;
  472. case DB_STENCIL_INFO:
  473. track->db_s_info = radeon_get_ib_value(p, idx);
  474. break;
  475. case DB_DEPTH_VIEW:
  476. track->db_depth_view = radeon_get_ib_value(p, idx);
  477. break;
  478. case DB_DEPTH_SIZE:
  479. track->db_depth_size = radeon_get_ib_value(p, idx);
  480. track->db_depth_size_idx = idx;
  481. break;
  482. case DB_Z_READ_BASE:
  483. r = evergreen_cs_packet_next_reloc(p, &reloc);
  484. if (r) {
  485. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  486. "0x%04X\n", reg);
  487. return -EINVAL;
  488. }
  489. track->db_z_read_offset = radeon_get_ib_value(p, idx);
  490. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  491. track->db_z_read_bo = reloc->robj;
  492. break;
  493. case DB_Z_WRITE_BASE:
  494. r = evergreen_cs_packet_next_reloc(p, &reloc);
  495. if (r) {
  496. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  497. "0x%04X\n", reg);
  498. return -EINVAL;
  499. }
  500. track->db_z_write_offset = radeon_get_ib_value(p, idx);
  501. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  502. track->db_z_write_bo = reloc->robj;
  503. break;
  504. case DB_STENCIL_READ_BASE:
  505. r = evergreen_cs_packet_next_reloc(p, &reloc);
  506. if (r) {
  507. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  508. "0x%04X\n", reg);
  509. return -EINVAL;
  510. }
  511. track->db_s_read_offset = radeon_get_ib_value(p, idx);
  512. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  513. track->db_s_read_bo = reloc->robj;
  514. break;
  515. case DB_STENCIL_WRITE_BASE:
  516. r = evergreen_cs_packet_next_reloc(p, &reloc);
  517. if (r) {
  518. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  519. "0x%04X\n", reg);
  520. return -EINVAL;
  521. }
  522. track->db_s_write_offset = radeon_get_ib_value(p, idx);
  523. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  524. track->db_s_write_bo = reloc->robj;
  525. break;
  526. case VGT_STRMOUT_CONFIG:
  527. track->vgt_strmout_config = radeon_get_ib_value(p, idx);
  528. break;
  529. case VGT_STRMOUT_BUFFER_CONFIG:
  530. track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
  531. break;
  532. case CB_TARGET_MASK:
  533. track->cb_target_mask = radeon_get_ib_value(p, idx);
  534. break;
  535. case CB_SHADER_MASK:
  536. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  537. break;
  538. case PA_SC_AA_CONFIG:
  539. if (p->rdev->family >= CHIP_CAYMAN) {
  540. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  541. "0x%04X\n", reg);
  542. return -EINVAL;
  543. }
  544. tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
  545. track->nsamples = 1 << tmp;
  546. break;
  547. case CAYMAN_PA_SC_AA_CONFIG:
  548. if (p->rdev->family < CHIP_CAYMAN) {
  549. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  550. "0x%04X\n", reg);
  551. return -EINVAL;
  552. }
  553. tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
  554. track->nsamples = 1 << tmp;
  555. break;
  556. case CB_COLOR0_VIEW:
  557. case CB_COLOR1_VIEW:
  558. case CB_COLOR2_VIEW:
  559. case CB_COLOR3_VIEW:
  560. case CB_COLOR4_VIEW:
  561. case CB_COLOR5_VIEW:
  562. case CB_COLOR6_VIEW:
  563. case CB_COLOR7_VIEW:
  564. tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
  565. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  566. break;
  567. case CB_COLOR8_VIEW:
  568. case CB_COLOR9_VIEW:
  569. case CB_COLOR10_VIEW:
  570. case CB_COLOR11_VIEW:
  571. tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
  572. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  573. break;
  574. case CB_COLOR0_INFO:
  575. case CB_COLOR1_INFO:
  576. case CB_COLOR2_INFO:
  577. case CB_COLOR3_INFO:
  578. case CB_COLOR4_INFO:
  579. case CB_COLOR5_INFO:
  580. case CB_COLOR6_INFO:
  581. case CB_COLOR7_INFO:
  582. tmp = (reg - CB_COLOR0_INFO) / 0x3c;
  583. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  584. if (!p->keep_tiling_flags) {
  585. r = evergreen_cs_packet_next_reloc(p, &reloc);
  586. if (r) {
  587. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  588. "0x%04X\n", reg);
  589. return -EINVAL;
  590. }
  591. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  592. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  593. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  594. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  595. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  596. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  597. }
  598. }
  599. break;
  600. case CB_COLOR8_INFO:
  601. case CB_COLOR9_INFO:
  602. case CB_COLOR10_INFO:
  603. case CB_COLOR11_INFO:
  604. tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
  605. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  606. if (!p->keep_tiling_flags) {
  607. r = evergreen_cs_packet_next_reloc(p, &reloc);
  608. if (r) {
  609. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  610. "0x%04X\n", reg);
  611. return -EINVAL;
  612. }
  613. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  614. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  615. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  616. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  617. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  618. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  619. }
  620. }
  621. break;
  622. case CB_COLOR0_PITCH:
  623. case CB_COLOR1_PITCH:
  624. case CB_COLOR2_PITCH:
  625. case CB_COLOR3_PITCH:
  626. case CB_COLOR4_PITCH:
  627. case CB_COLOR5_PITCH:
  628. case CB_COLOR6_PITCH:
  629. case CB_COLOR7_PITCH:
  630. tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
  631. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  632. track->cb_color_pitch_idx[tmp] = idx;
  633. break;
  634. case CB_COLOR8_PITCH:
  635. case CB_COLOR9_PITCH:
  636. case CB_COLOR10_PITCH:
  637. case CB_COLOR11_PITCH:
  638. tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
  639. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  640. track->cb_color_pitch_idx[tmp] = idx;
  641. break;
  642. case CB_COLOR0_SLICE:
  643. case CB_COLOR1_SLICE:
  644. case CB_COLOR2_SLICE:
  645. case CB_COLOR3_SLICE:
  646. case CB_COLOR4_SLICE:
  647. case CB_COLOR5_SLICE:
  648. case CB_COLOR6_SLICE:
  649. case CB_COLOR7_SLICE:
  650. tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
  651. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  652. track->cb_color_slice_idx[tmp] = idx;
  653. break;
  654. case CB_COLOR8_SLICE:
  655. case CB_COLOR9_SLICE:
  656. case CB_COLOR10_SLICE:
  657. case CB_COLOR11_SLICE:
  658. tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
  659. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  660. track->cb_color_slice_idx[tmp] = idx;
  661. break;
  662. case CB_COLOR0_ATTRIB:
  663. case CB_COLOR1_ATTRIB:
  664. case CB_COLOR2_ATTRIB:
  665. case CB_COLOR3_ATTRIB:
  666. case CB_COLOR4_ATTRIB:
  667. case CB_COLOR5_ATTRIB:
  668. case CB_COLOR6_ATTRIB:
  669. case CB_COLOR7_ATTRIB:
  670. case CB_COLOR8_ATTRIB:
  671. case CB_COLOR9_ATTRIB:
  672. case CB_COLOR10_ATTRIB:
  673. case CB_COLOR11_ATTRIB:
  674. break;
  675. case CB_COLOR0_DIM:
  676. case CB_COLOR1_DIM:
  677. case CB_COLOR2_DIM:
  678. case CB_COLOR3_DIM:
  679. case CB_COLOR4_DIM:
  680. case CB_COLOR5_DIM:
  681. case CB_COLOR6_DIM:
  682. case CB_COLOR7_DIM:
  683. tmp = (reg - CB_COLOR0_DIM) / 0x3c;
  684. track->cb_color_dim[tmp] = radeon_get_ib_value(p, idx);
  685. track->cb_color_dim_idx[tmp] = idx;
  686. break;
  687. case CB_COLOR8_DIM:
  688. case CB_COLOR9_DIM:
  689. case CB_COLOR10_DIM:
  690. case CB_COLOR11_DIM:
  691. tmp = ((reg - CB_COLOR8_DIM) / 0x1c) + 8;
  692. track->cb_color_dim[tmp] = radeon_get_ib_value(p, idx);
  693. track->cb_color_dim_idx[tmp] = idx;
  694. break;
  695. case CB_COLOR0_FMASK:
  696. case CB_COLOR1_FMASK:
  697. case CB_COLOR2_FMASK:
  698. case CB_COLOR3_FMASK:
  699. case CB_COLOR4_FMASK:
  700. case CB_COLOR5_FMASK:
  701. case CB_COLOR6_FMASK:
  702. case CB_COLOR7_FMASK:
  703. tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
  704. r = evergreen_cs_packet_next_reloc(p, &reloc);
  705. if (r) {
  706. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  707. return -EINVAL;
  708. }
  709. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  710. track->cb_color_fmask_bo[tmp] = reloc->robj;
  711. break;
  712. case CB_COLOR0_CMASK:
  713. case CB_COLOR1_CMASK:
  714. case CB_COLOR2_CMASK:
  715. case CB_COLOR3_CMASK:
  716. case CB_COLOR4_CMASK:
  717. case CB_COLOR5_CMASK:
  718. case CB_COLOR6_CMASK:
  719. case CB_COLOR7_CMASK:
  720. tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
  721. r = evergreen_cs_packet_next_reloc(p, &reloc);
  722. if (r) {
  723. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  724. return -EINVAL;
  725. }
  726. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  727. track->cb_color_cmask_bo[tmp] = reloc->robj;
  728. break;
  729. case CB_COLOR0_FMASK_SLICE:
  730. case CB_COLOR1_FMASK_SLICE:
  731. case CB_COLOR2_FMASK_SLICE:
  732. case CB_COLOR3_FMASK_SLICE:
  733. case CB_COLOR4_FMASK_SLICE:
  734. case CB_COLOR5_FMASK_SLICE:
  735. case CB_COLOR6_FMASK_SLICE:
  736. case CB_COLOR7_FMASK_SLICE:
  737. tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
  738. track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
  739. break;
  740. case CB_COLOR0_CMASK_SLICE:
  741. case CB_COLOR1_CMASK_SLICE:
  742. case CB_COLOR2_CMASK_SLICE:
  743. case CB_COLOR3_CMASK_SLICE:
  744. case CB_COLOR4_CMASK_SLICE:
  745. case CB_COLOR5_CMASK_SLICE:
  746. case CB_COLOR6_CMASK_SLICE:
  747. case CB_COLOR7_CMASK_SLICE:
  748. tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
  749. track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
  750. break;
  751. case CB_COLOR0_BASE:
  752. case CB_COLOR1_BASE:
  753. case CB_COLOR2_BASE:
  754. case CB_COLOR3_BASE:
  755. case CB_COLOR4_BASE:
  756. case CB_COLOR5_BASE:
  757. case CB_COLOR6_BASE:
  758. case CB_COLOR7_BASE:
  759. r = evergreen_cs_packet_next_reloc(p, &reloc);
  760. if (r) {
  761. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  762. "0x%04X\n", reg);
  763. return -EINVAL;
  764. }
  765. tmp = (reg - CB_COLOR0_BASE) / 0x3c;
  766. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  767. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  768. track->cb_color_base_last[tmp] = ib[idx];
  769. track->cb_color_bo[tmp] = reloc->robj;
  770. break;
  771. case CB_COLOR8_BASE:
  772. case CB_COLOR9_BASE:
  773. case CB_COLOR10_BASE:
  774. case CB_COLOR11_BASE:
  775. r = evergreen_cs_packet_next_reloc(p, &reloc);
  776. if (r) {
  777. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  778. "0x%04X\n", reg);
  779. return -EINVAL;
  780. }
  781. tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
  782. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  783. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  784. track->cb_color_base_last[tmp] = ib[idx];
  785. track->cb_color_bo[tmp] = reloc->robj;
  786. break;
  787. case CB_IMMED0_BASE:
  788. case CB_IMMED1_BASE:
  789. case CB_IMMED2_BASE:
  790. case CB_IMMED3_BASE:
  791. case CB_IMMED4_BASE:
  792. case CB_IMMED5_BASE:
  793. case CB_IMMED6_BASE:
  794. case CB_IMMED7_BASE:
  795. case CB_IMMED8_BASE:
  796. case CB_IMMED9_BASE:
  797. case CB_IMMED10_BASE:
  798. case CB_IMMED11_BASE:
  799. case DB_HTILE_DATA_BASE:
  800. case SQ_PGM_START_FS:
  801. case SQ_PGM_START_ES:
  802. case SQ_PGM_START_VS:
  803. case SQ_PGM_START_GS:
  804. case SQ_PGM_START_PS:
  805. case SQ_PGM_START_HS:
  806. case SQ_PGM_START_LS:
  807. case SQ_CONST_MEM_BASE:
  808. case SQ_ALU_CONST_CACHE_GS_0:
  809. case SQ_ALU_CONST_CACHE_GS_1:
  810. case SQ_ALU_CONST_CACHE_GS_2:
  811. case SQ_ALU_CONST_CACHE_GS_3:
  812. case SQ_ALU_CONST_CACHE_GS_4:
  813. case SQ_ALU_CONST_CACHE_GS_5:
  814. case SQ_ALU_CONST_CACHE_GS_6:
  815. case SQ_ALU_CONST_CACHE_GS_7:
  816. case SQ_ALU_CONST_CACHE_GS_8:
  817. case SQ_ALU_CONST_CACHE_GS_9:
  818. case SQ_ALU_CONST_CACHE_GS_10:
  819. case SQ_ALU_CONST_CACHE_GS_11:
  820. case SQ_ALU_CONST_CACHE_GS_12:
  821. case SQ_ALU_CONST_CACHE_GS_13:
  822. case SQ_ALU_CONST_CACHE_GS_14:
  823. case SQ_ALU_CONST_CACHE_GS_15:
  824. case SQ_ALU_CONST_CACHE_PS_0:
  825. case SQ_ALU_CONST_CACHE_PS_1:
  826. case SQ_ALU_CONST_CACHE_PS_2:
  827. case SQ_ALU_CONST_CACHE_PS_3:
  828. case SQ_ALU_CONST_CACHE_PS_4:
  829. case SQ_ALU_CONST_CACHE_PS_5:
  830. case SQ_ALU_CONST_CACHE_PS_6:
  831. case SQ_ALU_CONST_CACHE_PS_7:
  832. case SQ_ALU_CONST_CACHE_PS_8:
  833. case SQ_ALU_CONST_CACHE_PS_9:
  834. case SQ_ALU_CONST_CACHE_PS_10:
  835. case SQ_ALU_CONST_CACHE_PS_11:
  836. case SQ_ALU_CONST_CACHE_PS_12:
  837. case SQ_ALU_CONST_CACHE_PS_13:
  838. case SQ_ALU_CONST_CACHE_PS_14:
  839. case SQ_ALU_CONST_CACHE_PS_15:
  840. case SQ_ALU_CONST_CACHE_VS_0:
  841. case SQ_ALU_CONST_CACHE_VS_1:
  842. case SQ_ALU_CONST_CACHE_VS_2:
  843. case SQ_ALU_CONST_CACHE_VS_3:
  844. case SQ_ALU_CONST_CACHE_VS_4:
  845. case SQ_ALU_CONST_CACHE_VS_5:
  846. case SQ_ALU_CONST_CACHE_VS_6:
  847. case SQ_ALU_CONST_CACHE_VS_7:
  848. case SQ_ALU_CONST_CACHE_VS_8:
  849. case SQ_ALU_CONST_CACHE_VS_9:
  850. case SQ_ALU_CONST_CACHE_VS_10:
  851. case SQ_ALU_CONST_CACHE_VS_11:
  852. case SQ_ALU_CONST_CACHE_VS_12:
  853. case SQ_ALU_CONST_CACHE_VS_13:
  854. case SQ_ALU_CONST_CACHE_VS_14:
  855. case SQ_ALU_CONST_CACHE_VS_15:
  856. case SQ_ALU_CONST_CACHE_HS_0:
  857. case SQ_ALU_CONST_CACHE_HS_1:
  858. case SQ_ALU_CONST_CACHE_HS_2:
  859. case SQ_ALU_CONST_CACHE_HS_3:
  860. case SQ_ALU_CONST_CACHE_HS_4:
  861. case SQ_ALU_CONST_CACHE_HS_5:
  862. case SQ_ALU_CONST_CACHE_HS_6:
  863. case SQ_ALU_CONST_CACHE_HS_7:
  864. case SQ_ALU_CONST_CACHE_HS_8:
  865. case SQ_ALU_CONST_CACHE_HS_9:
  866. case SQ_ALU_CONST_CACHE_HS_10:
  867. case SQ_ALU_CONST_CACHE_HS_11:
  868. case SQ_ALU_CONST_CACHE_HS_12:
  869. case SQ_ALU_CONST_CACHE_HS_13:
  870. case SQ_ALU_CONST_CACHE_HS_14:
  871. case SQ_ALU_CONST_CACHE_HS_15:
  872. case SQ_ALU_CONST_CACHE_LS_0:
  873. case SQ_ALU_CONST_CACHE_LS_1:
  874. case SQ_ALU_CONST_CACHE_LS_2:
  875. case SQ_ALU_CONST_CACHE_LS_3:
  876. case SQ_ALU_CONST_CACHE_LS_4:
  877. case SQ_ALU_CONST_CACHE_LS_5:
  878. case SQ_ALU_CONST_CACHE_LS_6:
  879. case SQ_ALU_CONST_CACHE_LS_7:
  880. case SQ_ALU_CONST_CACHE_LS_8:
  881. case SQ_ALU_CONST_CACHE_LS_9:
  882. case SQ_ALU_CONST_CACHE_LS_10:
  883. case SQ_ALU_CONST_CACHE_LS_11:
  884. case SQ_ALU_CONST_CACHE_LS_12:
  885. case SQ_ALU_CONST_CACHE_LS_13:
  886. case SQ_ALU_CONST_CACHE_LS_14:
  887. case SQ_ALU_CONST_CACHE_LS_15:
  888. r = evergreen_cs_packet_next_reloc(p, &reloc);
  889. if (r) {
  890. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  891. "0x%04X\n", reg);
  892. return -EINVAL;
  893. }
  894. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  895. break;
  896. case SX_MEMORY_EXPORT_BASE:
  897. if (p->rdev->family >= CHIP_CAYMAN) {
  898. dev_warn(p->dev, "bad SET_CONFIG_REG "
  899. "0x%04X\n", reg);
  900. return -EINVAL;
  901. }
  902. r = evergreen_cs_packet_next_reloc(p, &reloc);
  903. if (r) {
  904. dev_warn(p->dev, "bad SET_CONFIG_REG "
  905. "0x%04X\n", reg);
  906. return -EINVAL;
  907. }
  908. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  909. break;
  910. case CAYMAN_SX_SCATTER_EXPORT_BASE:
  911. if (p->rdev->family < CHIP_CAYMAN) {
  912. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  913. "0x%04X\n", reg);
  914. return -EINVAL;
  915. }
  916. r = evergreen_cs_packet_next_reloc(p, &reloc);
  917. if (r) {
  918. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  919. "0x%04X\n", reg);
  920. return -EINVAL;
  921. }
  922. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  923. break;
  924. default:
  925. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  926. return -EINVAL;
  927. }
  928. return 0;
  929. }
  930. /**
  931. * evergreen_check_texture_resource() - check if register is authorized or not
  932. * @p: parser structure holding parsing context
  933. * @idx: index into the cs buffer
  934. * @texture: texture's bo structure
  935. * @mipmap: mipmap's bo structure
  936. *
  937. * This function will check that the resource has valid field and that
  938. * the texture and mipmap bo object are big enough to cover this resource.
  939. */
  940. static int evergreen_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
  941. struct radeon_bo *texture,
  942. struct radeon_bo *mipmap)
  943. {
  944. /* XXX fill in */
  945. return 0;
  946. }
  947. static int evergreen_packet3_check(struct radeon_cs_parser *p,
  948. struct radeon_cs_packet *pkt)
  949. {
  950. struct radeon_cs_reloc *reloc;
  951. struct evergreen_cs_track *track;
  952. volatile u32 *ib;
  953. unsigned idx;
  954. unsigned i;
  955. unsigned start_reg, end_reg, reg;
  956. int r;
  957. u32 idx_value;
  958. track = (struct evergreen_cs_track *)p->track;
  959. ib = p->ib->ptr;
  960. idx = pkt->idx + 1;
  961. idx_value = radeon_get_ib_value(p, idx);
  962. switch (pkt->opcode) {
  963. case PACKET3_SET_PREDICATION:
  964. {
  965. int pred_op;
  966. int tmp;
  967. if (pkt->count != 1) {
  968. DRM_ERROR("bad SET PREDICATION\n");
  969. return -EINVAL;
  970. }
  971. tmp = radeon_get_ib_value(p, idx + 1);
  972. pred_op = (tmp >> 16) & 0x7;
  973. /* for the clear predicate operation */
  974. if (pred_op == 0)
  975. return 0;
  976. if (pred_op > 2) {
  977. DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op);
  978. return -EINVAL;
  979. }
  980. r = evergreen_cs_packet_next_reloc(p, &reloc);
  981. if (r) {
  982. DRM_ERROR("bad SET PREDICATION\n");
  983. return -EINVAL;
  984. }
  985. ib[idx + 0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  986. ib[idx + 1] = tmp + (upper_32_bits(reloc->lobj.gpu_offset) & 0xff);
  987. }
  988. break;
  989. case PACKET3_CONTEXT_CONTROL:
  990. if (pkt->count != 1) {
  991. DRM_ERROR("bad CONTEXT_CONTROL\n");
  992. return -EINVAL;
  993. }
  994. break;
  995. case PACKET3_INDEX_TYPE:
  996. case PACKET3_NUM_INSTANCES:
  997. case PACKET3_CLEAR_STATE:
  998. if (pkt->count) {
  999. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1000. return -EINVAL;
  1001. }
  1002. break;
  1003. case CAYMAN_PACKET3_DEALLOC_STATE:
  1004. if (p->rdev->family < CHIP_CAYMAN) {
  1005. DRM_ERROR("bad PACKET3_DEALLOC_STATE\n");
  1006. return -EINVAL;
  1007. }
  1008. if (pkt->count) {
  1009. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1010. return -EINVAL;
  1011. }
  1012. break;
  1013. case PACKET3_INDEX_BASE:
  1014. if (pkt->count != 1) {
  1015. DRM_ERROR("bad INDEX_BASE\n");
  1016. return -EINVAL;
  1017. }
  1018. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1019. if (r) {
  1020. DRM_ERROR("bad INDEX_BASE\n");
  1021. return -EINVAL;
  1022. }
  1023. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1024. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1025. r = evergreen_cs_track_check(p);
  1026. if (r) {
  1027. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1028. return r;
  1029. }
  1030. break;
  1031. case PACKET3_DRAW_INDEX:
  1032. if (pkt->count != 3) {
  1033. DRM_ERROR("bad DRAW_INDEX\n");
  1034. return -EINVAL;
  1035. }
  1036. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1037. if (r) {
  1038. DRM_ERROR("bad DRAW_INDEX\n");
  1039. return -EINVAL;
  1040. }
  1041. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1042. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1043. r = evergreen_cs_track_check(p);
  1044. if (r) {
  1045. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1046. return r;
  1047. }
  1048. break;
  1049. case PACKET3_DRAW_INDEX_2:
  1050. if (pkt->count != 4) {
  1051. DRM_ERROR("bad DRAW_INDEX_2\n");
  1052. return -EINVAL;
  1053. }
  1054. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1055. if (r) {
  1056. DRM_ERROR("bad DRAW_INDEX_2\n");
  1057. return -EINVAL;
  1058. }
  1059. ib[idx+1] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1060. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1061. r = evergreen_cs_track_check(p);
  1062. if (r) {
  1063. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1064. return r;
  1065. }
  1066. break;
  1067. case PACKET3_DRAW_INDEX_AUTO:
  1068. if (pkt->count != 1) {
  1069. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1070. return -EINVAL;
  1071. }
  1072. r = evergreen_cs_track_check(p);
  1073. if (r) {
  1074. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1075. return r;
  1076. }
  1077. break;
  1078. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  1079. if (pkt->count != 2) {
  1080. DRM_ERROR("bad DRAW_INDEX_MULTI_AUTO\n");
  1081. return -EINVAL;
  1082. }
  1083. r = evergreen_cs_track_check(p);
  1084. if (r) {
  1085. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1086. return r;
  1087. }
  1088. break;
  1089. case PACKET3_DRAW_INDEX_IMMD:
  1090. if (pkt->count < 2) {
  1091. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1092. return -EINVAL;
  1093. }
  1094. r = evergreen_cs_track_check(p);
  1095. if (r) {
  1096. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1097. return r;
  1098. }
  1099. break;
  1100. case PACKET3_DRAW_INDEX_OFFSET:
  1101. if (pkt->count != 2) {
  1102. DRM_ERROR("bad DRAW_INDEX_OFFSET\n");
  1103. return -EINVAL;
  1104. }
  1105. r = evergreen_cs_track_check(p);
  1106. if (r) {
  1107. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1108. return r;
  1109. }
  1110. break;
  1111. case PACKET3_DRAW_INDEX_OFFSET_2:
  1112. if (pkt->count != 3) {
  1113. DRM_ERROR("bad DRAW_INDEX_OFFSET_2\n");
  1114. return -EINVAL;
  1115. }
  1116. r = evergreen_cs_track_check(p);
  1117. if (r) {
  1118. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1119. return r;
  1120. }
  1121. break;
  1122. case PACKET3_DISPATCH_DIRECT:
  1123. if (pkt->count != 3) {
  1124. DRM_ERROR("bad DISPATCH_DIRECT\n");
  1125. return -EINVAL;
  1126. }
  1127. r = evergreen_cs_track_check(p);
  1128. if (r) {
  1129. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1130. return r;
  1131. }
  1132. break;
  1133. case PACKET3_DISPATCH_INDIRECT:
  1134. if (pkt->count != 1) {
  1135. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  1136. return -EINVAL;
  1137. }
  1138. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1139. if (r) {
  1140. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  1141. return -EINVAL;
  1142. }
  1143. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1144. r = evergreen_cs_track_check(p);
  1145. if (r) {
  1146. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1147. return r;
  1148. }
  1149. break;
  1150. case PACKET3_WAIT_REG_MEM:
  1151. if (pkt->count != 5) {
  1152. DRM_ERROR("bad WAIT_REG_MEM\n");
  1153. return -EINVAL;
  1154. }
  1155. /* bit 4 is reg (0) or mem (1) */
  1156. if (idx_value & 0x10) {
  1157. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1158. if (r) {
  1159. DRM_ERROR("bad WAIT_REG_MEM\n");
  1160. return -EINVAL;
  1161. }
  1162. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1163. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1164. }
  1165. break;
  1166. case PACKET3_SURFACE_SYNC:
  1167. if (pkt->count != 3) {
  1168. DRM_ERROR("bad SURFACE_SYNC\n");
  1169. return -EINVAL;
  1170. }
  1171. /* 0xffffffff/0x0 is flush all cache flag */
  1172. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  1173. radeon_get_ib_value(p, idx + 2) != 0) {
  1174. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1175. if (r) {
  1176. DRM_ERROR("bad SURFACE_SYNC\n");
  1177. return -EINVAL;
  1178. }
  1179. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1180. }
  1181. break;
  1182. case PACKET3_EVENT_WRITE:
  1183. if (pkt->count != 2 && pkt->count != 0) {
  1184. DRM_ERROR("bad EVENT_WRITE\n");
  1185. return -EINVAL;
  1186. }
  1187. if (pkt->count) {
  1188. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1189. if (r) {
  1190. DRM_ERROR("bad EVENT_WRITE\n");
  1191. return -EINVAL;
  1192. }
  1193. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1194. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1195. }
  1196. break;
  1197. case PACKET3_EVENT_WRITE_EOP:
  1198. if (pkt->count != 4) {
  1199. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1200. return -EINVAL;
  1201. }
  1202. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1203. if (r) {
  1204. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1205. return -EINVAL;
  1206. }
  1207. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1208. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1209. break;
  1210. case PACKET3_EVENT_WRITE_EOS:
  1211. if (pkt->count != 3) {
  1212. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1213. return -EINVAL;
  1214. }
  1215. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1216. if (r) {
  1217. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1218. return -EINVAL;
  1219. }
  1220. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1221. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1222. break;
  1223. case PACKET3_SET_CONFIG_REG:
  1224. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  1225. end_reg = 4 * pkt->count + start_reg - 4;
  1226. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  1227. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  1228. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  1229. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  1230. return -EINVAL;
  1231. }
  1232. for (i = 0; i < pkt->count; i++) {
  1233. reg = start_reg + (4 * i);
  1234. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1235. if (r)
  1236. return r;
  1237. }
  1238. break;
  1239. case PACKET3_SET_CONTEXT_REG:
  1240. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
  1241. end_reg = 4 * pkt->count + start_reg - 4;
  1242. if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
  1243. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  1244. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  1245. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  1246. return -EINVAL;
  1247. }
  1248. for (i = 0; i < pkt->count; i++) {
  1249. reg = start_reg + (4 * i);
  1250. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1251. if (r)
  1252. return r;
  1253. }
  1254. break;
  1255. case PACKET3_SET_RESOURCE:
  1256. if (pkt->count % 8) {
  1257. DRM_ERROR("bad SET_RESOURCE\n");
  1258. return -EINVAL;
  1259. }
  1260. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
  1261. end_reg = 4 * pkt->count + start_reg - 4;
  1262. if ((start_reg < PACKET3_SET_RESOURCE_START) ||
  1263. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  1264. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  1265. DRM_ERROR("bad SET_RESOURCE\n");
  1266. return -EINVAL;
  1267. }
  1268. for (i = 0; i < (pkt->count / 8); i++) {
  1269. struct radeon_bo *texture, *mipmap;
  1270. u32 size, offset;
  1271. switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
  1272. case SQ_TEX_VTX_VALID_TEXTURE:
  1273. /* tex base */
  1274. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1275. if (r) {
  1276. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1277. return -EINVAL;
  1278. }
  1279. ib[idx+1+(i*8)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1280. if (!p->keep_tiling_flags) {
  1281. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
  1282. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  1283. else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
  1284. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  1285. }
  1286. texture = reloc->robj;
  1287. /* tex mip base */
  1288. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1289. if (r) {
  1290. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1291. return -EINVAL;
  1292. }
  1293. ib[idx+1+(i*8)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1294. mipmap = reloc->robj;
  1295. r = evergreen_check_texture_resource(p, idx+1+(i*8),
  1296. texture, mipmap);
  1297. if (r)
  1298. return r;
  1299. break;
  1300. case SQ_TEX_VTX_VALID_BUFFER:
  1301. /* vtx base */
  1302. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1303. if (r) {
  1304. DRM_ERROR("bad SET_RESOURCE (vtx)\n");
  1305. return -EINVAL;
  1306. }
  1307. offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
  1308. size = radeon_get_ib_value(p, idx+1+(i*8)+1);
  1309. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  1310. /* force size to size of the buffer */
  1311. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  1312. ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj);
  1313. }
  1314. ib[idx+1+(i*8)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
  1315. ib[idx+1+(i*8)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1316. break;
  1317. case SQ_TEX_VTX_INVALID_TEXTURE:
  1318. case SQ_TEX_VTX_INVALID_BUFFER:
  1319. default:
  1320. DRM_ERROR("bad SET_RESOURCE\n");
  1321. return -EINVAL;
  1322. }
  1323. }
  1324. break;
  1325. case PACKET3_SET_ALU_CONST:
  1326. /* XXX fix me ALU const buffers only */
  1327. break;
  1328. case PACKET3_SET_BOOL_CONST:
  1329. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
  1330. end_reg = 4 * pkt->count + start_reg - 4;
  1331. if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
  1332. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  1333. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  1334. DRM_ERROR("bad SET_BOOL_CONST\n");
  1335. return -EINVAL;
  1336. }
  1337. break;
  1338. case PACKET3_SET_LOOP_CONST:
  1339. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
  1340. end_reg = 4 * pkt->count + start_reg - 4;
  1341. if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
  1342. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  1343. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  1344. DRM_ERROR("bad SET_LOOP_CONST\n");
  1345. return -EINVAL;
  1346. }
  1347. break;
  1348. case PACKET3_SET_CTL_CONST:
  1349. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
  1350. end_reg = 4 * pkt->count + start_reg - 4;
  1351. if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
  1352. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  1353. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  1354. DRM_ERROR("bad SET_CTL_CONST\n");
  1355. return -EINVAL;
  1356. }
  1357. break;
  1358. case PACKET3_SET_SAMPLER:
  1359. if (pkt->count % 3) {
  1360. DRM_ERROR("bad SET_SAMPLER\n");
  1361. return -EINVAL;
  1362. }
  1363. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
  1364. end_reg = 4 * pkt->count + start_reg - 4;
  1365. if ((start_reg < PACKET3_SET_SAMPLER_START) ||
  1366. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  1367. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  1368. DRM_ERROR("bad SET_SAMPLER\n");
  1369. return -EINVAL;
  1370. }
  1371. break;
  1372. case PACKET3_NOP:
  1373. break;
  1374. default:
  1375. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1376. return -EINVAL;
  1377. }
  1378. return 0;
  1379. }
  1380. int evergreen_cs_parse(struct radeon_cs_parser *p)
  1381. {
  1382. struct radeon_cs_packet pkt;
  1383. struct evergreen_cs_track *track;
  1384. int r;
  1385. if (p->track == NULL) {
  1386. /* initialize tracker, we are in kms */
  1387. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1388. if (track == NULL)
  1389. return -ENOMEM;
  1390. evergreen_cs_track_init(track);
  1391. track->npipes = p->rdev->config.evergreen.tiling_npipes;
  1392. track->nbanks = p->rdev->config.evergreen.tiling_nbanks;
  1393. track->group_size = p->rdev->config.evergreen.tiling_group_size;
  1394. p->track = track;
  1395. }
  1396. do {
  1397. r = evergreen_cs_packet_parse(p, &pkt, p->idx);
  1398. if (r) {
  1399. kfree(p->track);
  1400. p->track = NULL;
  1401. return r;
  1402. }
  1403. p->idx += pkt.count + 2;
  1404. switch (pkt.type) {
  1405. case PACKET_TYPE0:
  1406. r = evergreen_cs_parse_packet0(p, &pkt);
  1407. break;
  1408. case PACKET_TYPE2:
  1409. break;
  1410. case PACKET_TYPE3:
  1411. r = evergreen_packet3_check(p, &pkt);
  1412. break;
  1413. default:
  1414. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1415. kfree(p->track);
  1416. p->track = NULL;
  1417. return -EINVAL;
  1418. }
  1419. if (r) {
  1420. kfree(p->track);
  1421. p->track = NULL;
  1422. return r;
  1423. }
  1424. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1425. #if 0
  1426. for (r = 0; r < p->ib->length_dw; r++) {
  1427. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  1428. mdelay(1);
  1429. }
  1430. #endif
  1431. kfree(p->track);
  1432. p->track = NULL;
  1433. return 0;
  1434. }