evergreen_cs.c 38 KB

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