evergreen_cs.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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 inline int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
  119. {
  120. /* XXX fill in */
  121. return 0;
  122. }
  123. static int evergreen_cs_track_check(struct radeon_cs_parser *p)
  124. {
  125. struct evergreen_cs_track *track = p->track;
  126. /* we don't support stream out buffer yet */
  127. if (track->vgt_strmout_config || track->vgt_strmout_buffer_config) {
  128. dev_warn(p->dev, "this kernel doesn't support SMX output buffer\n");
  129. return -EINVAL;
  130. }
  131. /* XXX fill in */
  132. return 0;
  133. }
  134. /**
  135. * evergreen_cs_packet_parse() - parse cp packet and point ib index to next packet
  136. * @parser: parser structure holding parsing context.
  137. * @pkt: where to store packet informations
  138. *
  139. * Assume that chunk_ib_index is properly set. Will return -EINVAL
  140. * if packet is bigger than remaining ib size. or if packets is unknown.
  141. **/
  142. int evergreen_cs_packet_parse(struct radeon_cs_parser *p,
  143. struct radeon_cs_packet *pkt,
  144. unsigned idx)
  145. {
  146. struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
  147. uint32_t header;
  148. if (idx >= ib_chunk->length_dw) {
  149. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  150. idx, ib_chunk->length_dw);
  151. return -EINVAL;
  152. }
  153. header = radeon_get_ib_value(p, idx);
  154. pkt->idx = idx;
  155. pkt->type = CP_PACKET_GET_TYPE(header);
  156. pkt->count = CP_PACKET_GET_COUNT(header);
  157. pkt->one_reg_wr = 0;
  158. switch (pkt->type) {
  159. case PACKET_TYPE0:
  160. pkt->reg = CP_PACKET0_GET_REG(header);
  161. break;
  162. case PACKET_TYPE3:
  163. pkt->opcode = CP_PACKET3_GET_OPCODE(header);
  164. break;
  165. case PACKET_TYPE2:
  166. pkt->count = -1;
  167. break;
  168. default:
  169. DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
  170. return -EINVAL;
  171. }
  172. if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
  173. DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
  174. pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
  175. return -EINVAL;
  176. }
  177. return 0;
  178. }
  179. /**
  180. * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3
  181. * @parser: parser structure holding parsing context.
  182. * @data: pointer to relocation data
  183. * @offset_start: starting offset
  184. * @offset_mask: offset mask (to align start offset on)
  185. * @reloc: reloc informations
  186. *
  187. * Check next packet is relocation packet3, do bo validation and compute
  188. * GPU offset using the provided start.
  189. **/
  190. static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
  191. struct radeon_cs_reloc **cs_reloc)
  192. {
  193. struct radeon_cs_chunk *relocs_chunk;
  194. struct radeon_cs_packet p3reloc;
  195. unsigned idx;
  196. int r;
  197. if (p->chunk_relocs_idx == -1) {
  198. DRM_ERROR("No relocation chunk !\n");
  199. return -EINVAL;
  200. }
  201. *cs_reloc = NULL;
  202. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  203. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx);
  204. if (r) {
  205. return r;
  206. }
  207. p->idx += p3reloc.count + 2;
  208. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  209. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  210. p3reloc.idx);
  211. return -EINVAL;
  212. }
  213. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  214. if (idx >= relocs_chunk->length_dw) {
  215. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  216. idx, relocs_chunk->length_dw);
  217. return -EINVAL;
  218. }
  219. /* FIXME: we assume reloc size is 4 dwords */
  220. *cs_reloc = p->relocs_ptr[(idx / 4)];
  221. return 0;
  222. }
  223. /**
  224. * evergreen_cs_packet_next_is_pkt3_nop() - test if next packet is packet3 nop for reloc
  225. * @parser: parser structure holding parsing context.
  226. *
  227. * Check next packet is relocation packet3, do bo validation and compute
  228. * GPU offset using the provided start.
  229. **/
  230. static inline int evergreen_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p)
  231. {
  232. struct radeon_cs_packet p3reloc;
  233. int r;
  234. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx);
  235. if (r) {
  236. return 0;
  237. }
  238. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  239. return 0;
  240. }
  241. return 1;
  242. }
  243. /**
  244. * evergreen_cs_packet_next_vline() - parse userspace VLINE packet
  245. * @parser: parser structure holding parsing context.
  246. *
  247. * Userspace sends a special sequence for VLINE waits.
  248. * PACKET0 - VLINE_START_END + value
  249. * PACKET3 - WAIT_REG_MEM poll vline status reg
  250. * RELOC (P3) - crtc_id in reloc.
  251. *
  252. * This function parses this and relocates the VLINE START END
  253. * and WAIT_REG_MEM packets to the correct crtc.
  254. * It also detects a switched off crtc and nulls out the
  255. * wait in that case.
  256. */
  257. static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
  258. {
  259. struct drm_mode_object *obj;
  260. struct drm_crtc *crtc;
  261. struct radeon_crtc *radeon_crtc;
  262. struct radeon_cs_packet p3reloc, wait_reg_mem;
  263. int crtc_id;
  264. int r;
  265. uint32_t header, h_idx, reg, wait_reg_mem_info;
  266. volatile uint32_t *ib;
  267. ib = p->ib->ptr;
  268. /* parse the WAIT_REG_MEM */
  269. r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx);
  270. if (r)
  271. return r;
  272. /* check its a WAIT_REG_MEM */
  273. if (wait_reg_mem.type != PACKET_TYPE3 ||
  274. wait_reg_mem.opcode != PACKET3_WAIT_REG_MEM) {
  275. DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
  276. r = -EINVAL;
  277. return r;
  278. }
  279. wait_reg_mem_info = radeon_get_ib_value(p, wait_reg_mem.idx + 1);
  280. /* bit 4 is reg (0) or mem (1) */
  281. if (wait_reg_mem_info & 0x10) {
  282. DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
  283. r = -EINVAL;
  284. return r;
  285. }
  286. /* waiting for value to be equal */
  287. if ((wait_reg_mem_info & 0x7) != 0x3) {
  288. DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
  289. r = -EINVAL;
  290. return r;
  291. }
  292. if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != EVERGREEN_VLINE_STATUS) {
  293. DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
  294. r = -EINVAL;
  295. return r;
  296. }
  297. if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != EVERGREEN_VLINE_STAT) {
  298. DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
  299. r = -EINVAL;
  300. return r;
  301. }
  302. /* jump over the NOP */
  303. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
  304. if (r)
  305. return r;
  306. h_idx = p->idx - 2;
  307. p->idx += wait_reg_mem.count + 2;
  308. p->idx += p3reloc.count + 2;
  309. header = radeon_get_ib_value(p, h_idx);
  310. crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
  311. reg = CP_PACKET0_GET_REG(header);
  312. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  313. if (!obj) {
  314. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  315. r = -EINVAL;
  316. goto out;
  317. }
  318. crtc = obj_to_crtc(obj);
  319. radeon_crtc = to_radeon_crtc(crtc);
  320. crtc_id = radeon_crtc->crtc_id;
  321. if (!crtc->enabled) {
  322. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  323. ib[h_idx + 2] = PACKET2(0);
  324. ib[h_idx + 3] = PACKET2(0);
  325. ib[h_idx + 4] = PACKET2(0);
  326. ib[h_idx + 5] = PACKET2(0);
  327. ib[h_idx + 6] = PACKET2(0);
  328. ib[h_idx + 7] = PACKET2(0);
  329. ib[h_idx + 8] = PACKET2(0);
  330. } else {
  331. switch (reg) {
  332. case EVERGREEN_VLINE_START_END:
  333. header &= ~R600_CP_PACKET0_REG_MASK;
  334. header |= (EVERGREEN_VLINE_START_END + radeon_crtc->crtc_offset) >> 2;
  335. ib[h_idx] = header;
  336. ib[h_idx + 4] = (EVERGREEN_VLINE_STATUS + radeon_crtc->crtc_offset) >> 2;
  337. break;
  338. default:
  339. DRM_ERROR("unknown crtc reloc\n");
  340. r = -EINVAL;
  341. goto out;
  342. }
  343. }
  344. out:
  345. return r;
  346. }
  347. static int evergreen_packet0_check(struct radeon_cs_parser *p,
  348. struct radeon_cs_packet *pkt,
  349. unsigned idx, unsigned reg)
  350. {
  351. int r;
  352. switch (reg) {
  353. case EVERGREEN_VLINE_START_END:
  354. r = evergreen_cs_packet_parse_vline(p);
  355. if (r) {
  356. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  357. idx, reg);
  358. return r;
  359. }
  360. break;
  361. default:
  362. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  363. reg, idx);
  364. return -EINVAL;
  365. }
  366. return 0;
  367. }
  368. static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
  369. struct radeon_cs_packet *pkt)
  370. {
  371. unsigned reg, i;
  372. unsigned idx;
  373. int r;
  374. idx = pkt->idx + 1;
  375. reg = pkt->reg;
  376. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  377. r = evergreen_packet0_check(p, pkt, idx, reg);
  378. if (r) {
  379. return r;
  380. }
  381. }
  382. return 0;
  383. }
  384. /**
  385. * evergreen_cs_check_reg() - check if register is authorized or not
  386. * @parser: parser structure holding parsing context
  387. * @reg: register we are testing
  388. * @idx: index into the cs buffer
  389. *
  390. * This function will test against evergreen_reg_safe_bm and return 0
  391. * if register is safe. If register is not flag as safe this function
  392. * will test it against a list of register needind special handling.
  393. */
  394. static inline int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  395. {
  396. struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
  397. struct radeon_cs_reloc *reloc;
  398. u32 last_reg;
  399. u32 m, i, tmp, *ib;
  400. int r;
  401. if (p->rdev->family >= CHIP_CAYMAN)
  402. last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
  403. else
  404. last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
  405. i = (reg >> 7);
  406. if (i > last_reg) {
  407. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  408. return -EINVAL;
  409. }
  410. m = 1 << ((reg >> 2) & 31);
  411. if (p->rdev->family >= CHIP_CAYMAN) {
  412. if (!(cayman_reg_safe_bm[i] & m))
  413. return 0;
  414. } else {
  415. if (!(evergreen_reg_safe_bm[i] & m))
  416. return 0;
  417. }
  418. ib = p->ib->ptr;
  419. switch (reg) {
  420. /* force following reg to 0 in an attemp to disable out buffer
  421. * which will need us to better understand how it works to perform
  422. * security check on it (Jerome)
  423. */
  424. case SQ_ESGS_RING_SIZE:
  425. case SQ_GSVS_RING_SIZE:
  426. case SQ_ESTMP_RING_SIZE:
  427. case SQ_GSTMP_RING_SIZE:
  428. case SQ_HSTMP_RING_SIZE:
  429. case SQ_LSTMP_RING_SIZE:
  430. case SQ_PSTMP_RING_SIZE:
  431. case SQ_VSTMP_RING_SIZE:
  432. case SQ_ESGS_RING_ITEMSIZE:
  433. case SQ_ESTMP_RING_ITEMSIZE:
  434. case SQ_GSTMP_RING_ITEMSIZE:
  435. case SQ_GSVS_RING_ITEMSIZE:
  436. case SQ_GS_VERT_ITEMSIZE:
  437. case SQ_GS_VERT_ITEMSIZE_1:
  438. case SQ_GS_VERT_ITEMSIZE_2:
  439. case SQ_GS_VERT_ITEMSIZE_3:
  440. case SQ_GSVS_RING_OFFSET_1:
  441. case SQ_GSVS_RING_OFFSET_2:
  442. case SQ_GSVS_RING_OFFSET_3:
  443. case SQ_HSTMP_RING_ITEMSIZE:
  444. case SQ_LSTMP_RING_ITEMSIZE:
  445. case SQ_PSTMP_RING_ITEMSIZE:
  446. case SQ_VSTMP_RING_ITEMSIZE:
  447. case VGT_TF_RING_SIZE:
  448. /* get value to populate the IB don't remove */
  449. /*tmp =radeon_get_ib_value(p, idx);
  450. ib[idx] = 0;*/
  451. break;
  452. case SQ_ESGS_RING_BASE:
  453. case SQ_GSVS_RING_BASE:
  454. case SQ_ESTMP_RING_BASE:
  455. case SQ_GSTMP_RING_BASE:
  456. case SQ_HSTMP_RING_BASE:
  457. case SQ_LSTMP_RING_BASE:
  458. case SQ_PSTMP_RING_BASE:
  459. case SQ_VSTMP_RING_BASE:
  460. r = evergreen_cs_packet_next_reloc(p, &reloc);
  461. if (r) {
  462. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  463. "0x%04X\n", reg);
  464. return -EINVAL;
  465. }
  466. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  467. break;
  468. case DB_DEPTH_CONTROL:
  469. track->db_depth_control = radeon_get_ib_value(p, idx);
  470. break;
  471. case CAYMAN_DB_EQAA:
  472. if (p->rdev->family < CHIP_CAYMAN) {
  473. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  474. "0x%04X\n", reg);
  475. return -EINVAL;
  476. }
  477. break;
  478. case CAYMAN_DB_DEPTH_INFO:
  479. if (p->rdev->family < CHIP_CAYMAN) {
  480. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  481. "0x%04X\n", reg);
  482. return -EINVAL;
  483. }
  484. break;
  485. case DB_Z_INFO:
  486. r = evergreen_cs_packet_next_reloc(p, &reloc);
  487. if (r) {
  488. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  489. "0x%04X\n", reg);
  490. return -EINVAL;
  491. }
  492. track->db_z_info = radeon_get_ib_value(p, idx);
  493. ib[idx] &= ~Z_ARRAY_MODE(0xf);
  494. track->db_z_info &= ~Z_ARRAY_MODE(0xf);
  495. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  496. ib[idx] |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  497. track->db_z_info |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  498. } else {
  499. ib[idx] |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  500. track->db_z_info |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  501. }
  502. break;
  503. case DB_STENCIL_INFO:
  504. track->db_s_info = radeon_get_ib_value(p, idx);
  505. break;
  506. case DB_DEPTH_VIEW:
  507. track->db_depth_view = radeon_get_ib_value(p, idx);
  508. break;
  509. case DB_DEPTH_SIZE:
  510. track->db_depth_size = radeon_get_ib_value(p, idx);
  511. track->db_depth_size_idx = idx;
  512. break;
  513. case DB_Z_READ_BASE:
  514. r = evergreen_cs_packet_next_reloc(p, &reloc);
  515. if (r) {
  516. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  517. "0x%04X\n", reg);
  518. return -EINVAL;
  519. }
  520. track->db_z_read_offset = radeon_get_ib_value(p, idx);
  521. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  522. track->db_z_read_bo = reloc->robj;
  523. break;
  524. case DB_Z_WRITE_BASE:
  525. r = evergreen_cs_packet_next_reloc(p, &reloc);
  526. if (r) {
  527. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  528. "0x%04X\n", reg);
  529. return -EINVAL;
  530. }
  531. track->db_z_write_offset = radeon_get_ib_value(p, idx);
  532. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  533. track->db_z_write_bo = reloc->robj;
  534. break;
  535. case DB_STENCIL_READ_BASE:
  536. r = evergreen_cs_packet_next_reloc(p, &reloc);
  537. if (r) {
  538. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  539. "0x%04X\n", reg);
  540. return -EINVAL;
  541. }
  542. track->db_s_read_offset = radeon_get_ib_value(p, idx);
  543. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  544. track->db_s_read_bo = reloc->robj;
  545. break;
  546. case DB_STENCIL_WRITE_BASE:
  547. r = evergreen_cs_packet_next_reloc(p, &reloc);
  548. if (r) {
  549. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  550. "0x%04X\n", reg);
  551. return -EINVAL;
  552. }
  553. track->db_s_write_offset = radeon_get_ib_value(p, idx);
  554. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  555. track->db_s_write_bo = reloc->robj;
  556. break;
  557. case VGT_STRMOUT_CONFIG:
  558. track->vgt_strmout_config = radeon_get_ib_value(p, idx);
  559. break;
  560. case VGT_STRMOUT_BUFFER_CONFIG:
  561. track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
  562. break;
  563. case CB_TARGET_MASK:
  564. track->cb_target_mask = radeon_get_ib_value(p, idx);
  565. break;
  566. case CB_SHADER_MASK:
  567. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  568. break;
  569. case PA_SC_AA_CONFIG:
  570. if (p->rdev->family >= CHIP_CAYMAN) {
  571. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  572. "0x%04X\n", reg);
  573. return -EINVAL;
  574. }
  575. tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
  576. track->nsamples = 1 << tmp;
  577. break;
  578. case CAYMAN_PA_SC_AA_CONFIG:
  579. if (p->rdev->family < CHIP_CAYMAN) {
  580. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  581. "0x%04X\n", reg);
  582. return -EINVAL;
  583. }
  584. tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
  585. track->nsamples = 1 << tmp;
  586. break;
  587. case CB_COLOR0_VIEW:
  588. case CB_COLOR1_VIEW:
  589. case CB_COLOR2_VIEW:
  590. case CB_COLOR3_VIEW:
  591. case CB_COLOR4_VIEW:
  592. case CB_COLOR5_VIEW:
  593. case CB_COLOR6_VIEW:
  594. case CB_COLOR7_VIEW:
  595. tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
  596. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  597. break;
  598. case CB_COLOR8_VIEW:
  599. case CB_COLOR9_VIEW:
  600. case CB_COLOR10_VIEW:
  601. case CB_COLOR11_VIEW:
  602. tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
  603. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  604. break;
  605. case CB_COLOR0_INFO:
  606. case CB_COLOR1_INFO:
  607. case CB_COLOR2_INFO:
  608. case CB_COLOR3_INFO:
  609. case CB_COLOR4_INFO:
  610. case CB_COLOR5_INFO:
  611. case CB_COLOR6_INFO:
  612. case CB_COLOR7_INFO:
  613. r = evergreen_cs_packet_next_reloc(p, &reloc);
  614. if (r) {
  615. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  616. "0x%04X\n", reg);
  617. return -EINVAL;
  618. }
  619. tmp = (reg - CB_COLOR0_INFO) / 0x3c;
  620. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  621. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  622. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  623. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  624. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  625. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  626. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  627. }
  628. break;
  629. case CB_COLOR8_INFO:
  630. case CB_COLOR9_INFO:
  631. case CB_COLOR10_INFO:
  632. case CB_COLOR11_INFO:
  633. r = evergreen_cs_packet_next_reloc(p, &reloc);
  634. if (r) {
  635. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  636. "0x%04X\n", reg);
  637. return -EINVAL;
  638. }
  639. tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
  640. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  641. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  642. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  643. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  644. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  645. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  646. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  647. }
  648. break;
  649. case CB_COLOR0_PITCH:
  650. case CB_COLOR1_PITCH:
  651. case CB_COLOR2_PITCH:
  652. case CB_COLOR3_PITCH:
  653. case CB_COLOR4_PITCH:
  654. case CB_COLOR5_PITCH:
  655. case CB_COLOR6_PITCH:
  656. case CB_COLOR7_PITCH:
  657. tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
  658. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  659. track->cb_color_pitch_idx[tmp] = idx;
  660. break;
  661. case CB_COLOR8_PITCH:
  662. case CB_COLOR9_PITCH:
  663. case CB_COLOR10_PITCH:
  664. case CB_COLOR11_PITCH:
  665. tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
  666. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  667. track->cb_color_pitch_idx[tmp] = idx;
  668. break;
  669. case CB_COLOR0_SLICE:
  670. case CB_COLOR1_SLICE:
  671. case CB_COLOR2_SLICE:
  672. case CB_COLOR3_SLICE:
  673. case CB_COLOR4_SLICE:
  674. case CB_COLOR5_SLICE:
  675. case CB_COLOR6_SLICE:
  676. case CB_COLOR7_SLICE:
  677. tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
  678. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  679. track->cb_color_slice_idx[tmp] = idx;
  680. break;
  681. case CB_COLOR8_SLICE:
  682. case CB_COLOR9_SLICE:
  683. case CB_COLOR10_SLICE:
  684. case CB_COLOR11_SLICE:
  685. tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
  686. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  687. track->cb_color_slice_idx[tmp] = idx;
  688. break;
  689. case CB_COLOR0_ATTRIB:
  690. case CB_COLOR1_ATTRIB:
  691. case CB_COLOR2_ATTRIB:
  692. case CB_COLOR3_ATTRIB:
  693. case CB_COLOR4_ATTRIB:
  694. case CB_COLOR5_ATTRIB:
  695. case CB_COLOR6_ATTRIB:
  696. case CB_COLOR7_ATTRIB:
  697. case CB_COLOR8_ATTRIB:
  698. case CB_COLOR9_ATTRIB:
  699. case CB_COLOR10_ATTRIB:
  700. case CB_COLOR11_ATTRIB:
  701. break;
  702. case CB_COLOR0_DIM:
  703. case CB_COLOR1_DIM:
  704. case CB_COLOR2_DIM:
  705. case CB_COLOR3_DIM:
  706. case CB_COLOR4_DIM:
  707. case CB_COLOR5_DIM:
  708. case CB_COLOR6_DIM:
  709. case CB_COLOR7_DIM:
  710. tmp = (reg - CB_COLOR0_DIM) / 0x3c;
  711. track->cb_color_dim[tmp] = radeon_get_ib_value(p, idx);
  712. track->cb_color_dim_idx[tmp] = idx;
  713. break;
  714. case CB_COLOR8_DIM:
  715. case CB_COLOR9_DIM:
  716. case CB_COLOR10_DIM:
  717. case CB_COLOR11_DIM:
  718. tmp = ((reg - CB_COLOR8_DIM) / 0x1c) + 8;
  719. track->cb_color_dim[tmp] = radeon_get_ib_value(p, idx);
  720. track->cb_color_dim_idx[tmp] = idx;
  721. break;
  722. case CB_COLOR0_FMASK:
  723. case CB_COLOR1_FMASK:
  724. case CB_COLOR2_FMASK:
  725. case CB_COLOR3_FMASK:
  726. case CB_COLOR4_FMASK:
  727. case CB_COLOR5_FMASK:
  728. case CB_COLOR6_FMASK:
  729. case CB_COLOR7_FMASK:
  730. tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
  731. r = evergreen_cs_packet_next_reloc(p, &reloc);
  732. if (r) {
  733. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  734. return -EINVAL;
  735. }
  736. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  737. track->cb_color_fmask_bo[tmp] = reloc->robj;
  738. break;
  739. case CB_COLOR0_CMASK:
  740. case CB_COLOR1_CMASK:
  741. case CB_COLOR2_CMASK:
  742. case CB_COLOR3_CMASK:
  743. case CB_COLOR4_CMASK:
  744. case CB_COLOR5_CMASK:
  745. case CB_COLOR6_CMASK:
  746. case CB_COLOR7_CMASK:
  747. tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
  748. r = evergreen_cs_packet_next_reloc(p, &reloc);
  749. if (r) {
  750. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  751. return -EINVAL;
  752. }
  753. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  754. track->cb_color_cmask_bo[tmp] = reloc->robj;
  755. break;
  756. case CB_COLOR0_FMASK_SLICE:
  757. case CB_COLOR1_FMASK_SLICE:
  758. case CB_COLOR2_FMASK_SLICE:
  759. case CB_COLOR3_FMASK_SLICE:
  760. case CB_COLOR4_FMASK_SLICE:
  761. case CB_COLOR5_FMASK_SLICE:
  762. case CB_COLOR6_FMASK_SLICE:
  763. case CB_COLOR7_FMASK_SLICE:
  764. tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
  765. track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
  766. break;
  767. case CB_COLOR0_CMASK_SLICE:
  768. case CB_COLOR1_CMASK_SLICE:
  769. case CB_COLOR2_CMASK_SLICE:
  770. case CB_COLOR3_CMASK_SLICE:
  771. case CB_COLOR4_CMASK_SLICE:
  772. case CB_COLOR5_CMASK_SLICE:
  773. case CB_COLOR6_CMASK_SLICE:
  774. case CB_COLOR7_CMASK_SLICE:
  775. tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
  776. track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
  777. break;
  778. case CB_COLOR0_BASE:
  779. case CB_COLOR1_BASE:
  780. case CB_COLOR2_BASE:
  781. case CB_COLOR3_BASE:
  782. case CB_COLOR4_BASE:
  783. case CB_COLOR5_BASE:
  784. case CB_COLOR6_BASE:
  785. case CB_COLOR7_BASE:
  786. r = evergreen_cs_packet_next_reloc(p, &reloc);
  787. if (r) {
  788. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  789. "0x%04X\n", reg);
  790. return -EINVAL;
  791. }
  792. tmp = (reg - CB_COLOR0_BASE) / 0x3c;
  793. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  794. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  795. track->cb_color_base_last[tmp] = ib[idx];
  796. track->cb_color_bo[tmp] = reloc->robj;
  797. break;
  798. case CB_COLOR8_BASE:
  799. case CB_COLOR9_BASE:
  800. case CB_COLOR10_BASE:
  801. case CB_COLOR11_BASE:
  802. r = evergreen_cs_packet_next_reloc(p, &reloc);
  803. if (r) {
  804. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  805. "0x%04X\n", reg);
  806. return -EINVAL;
  807. }
  808. tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
  809. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  810. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  811. track->cb_color_base_last[tmp] = ib[idx];
  812. track->cb_color_bo[tmp] = reloc->robj;
  813. break;
  814. case CB_IMMED0_BASE:
  815. case CB_IMMED1_BASE:
  816. case CB_IMMED2_BASE:
  817. case CB_IMMED3_BASE:
  818. case CB_IMMED4_BASE:
  819. case CB_IMMED5_BASE:
  820. case CB_IMMED6_BASE:
  821. case CB_IMMED7_BASE:
  822. case CB_IMMED8_BASE:
  823. case CB_IMMED9_BASE:
  824. case CB_IMMED10_BASE:
  825. case CB_IMMED11_BASE:
  826. case DB_HTILE_DATA_BASE:
  827. case SQ_PGM_START_FS:
  828. case SQ_PGM_START_ES:
  829. case SQ_PGM_START_VS:
  830. case SQ_PGM_START_GS:
  831. case SQ_PGM_START_PS:
  832. case SQ_PGM_START_HS:
  833. case SQ_PGM_START_LS:
  834. case GDS_ADDR_BASE:
  835. case SQ_CONST_MEM_BASE:
  836. case SQ_ALU_CONST_CACHE_GS_0:
  837. case SQ_ALU_CONST_CACHE_GS_1:
  838. case SQ_ALU_CONST_CACHE_GS_2:
  839. case SQ_ALU_CONST_CACHE_GS_3:
  840. case SQ_ALU_CONST_CACHE_GS_4:
  841. case SQ_ALU_CONST_CACHE_GS_5:
  842. case SQ_ALU_CONST_CACHE_GS_6:
  843. case SQ_ALU_CONST_CACHE_GS_7:
  844. case SQ_ALU_CONST_CACHE_GS_8:
  845. case SQ_ALU_CONST_CACHE_GS_9:
  846. case SQ_ALU_CONST_CACHE_GS_10:
  847. case SQ_ALU_CONST_CACHE_GS_11:
  848. case SQ_ALU_CONST_CACHE_GS_12:
  849. case SQ_ALU_CONST_CACHE_GS_13:
  850. case SQ_ALU_CONST_CACHE_GS_14:
  851. case SQ_ALU_CONST_CACHE_GS_15:
  852. case SQ_ALU_CONST_CACHE_PS_0:
  853. case SQ_ALU_CONST_CACHE_PS_1:
  854. case SQ_ALU_CONST_CACHE_PS_2:
  855. case SQ_ALU_CONST_CACHE_PS_3:
  856. case SQ_ALU_CONST_CACHE_PS_4:
  857. case SQ_ALU_CONST_CACHE_PS_5:
  858. case SQ_ALU_CONST_CACHE_PS_6:
  859. case SQ_ALU_CONST_CACHE_PS_7:
  860. case SQ_ALU_CONST_CACHE_PS_8:
  861. case SQ_ALU_CONST_CACHE_PS_9:
  862. case SQ_ALU_CONST_CACHE_PS_10:
  863. case SQ_ALU_CONST_CACHE_PS_11:
  864. case SQ_ALU_CONST_CACHE_PS_12:
  865. case SQ_ALU_CONST_CACHE_PS_13:
  866. case SQ_ALU_CONST_CACHE_PS_14:
  867. case SQ_ALU_CONST_CACHE_PS_15:
  868. case SQ_ALU_CONST_CACHE_VS_0:
  869. case SQ_ALU_CONST_CACHE_VS_1:
  870. case SQ_ALU_CONST_CACHE_VS_2:
  871. case SQ_ALU_CONST_CACHE_VS_3:
  872. case SQ_ALU_CONST_CACHE_VS_4:
  873. case SQ_ALU_CONST_CACHE_VS_5:
  874. case SQ_ALU_CONST_CACHE_VS_6:
  875. case SQ_ALU_CONST_CACHE_VS_7:
  876. case SQ_ALU_CONST_CACHE_VS_8:
  877. case SQ_ALU_CONST_CACHE_VS_9:
  878. case SQ_ALU_CONST_CACHE_VS_10:
  879. case SQ_ALU_CONST_CACHE_VS_11:
  880. case SQ_ALU_CONST_CACHE_VS_12:
  881. case SQ_ALU_CONST_CACHE_VS_13:
  882. case SQ_ALU_CONST_CACHE_VS_14:
  883. case SQ_ALU_CONST_CACHE_VS_15:
  884. case SQ_ALU_CONST_CACHE_HS_0:
  885. case SQ_ALU_CONST_CACHE_HS_1:
  886. case SQ_ALU_CONST_CACHE_HS_2:
  887. case SQ_ALU_CONST_CACHE_HS_3:
  888. case SQ_ALU_CONST_CACHE_HS_4:
  889. case SQ_ALU_CONST_CACHE_HS_5:
  890. case SQ_ALU_CONST_CACHE_HS_6:
  891. case SQ_ALU_CONST_CACHE_HS_7:
  892. case SQ_ALU_CONST_CACHE_HS_8:
  893. case SQ_ALU_CONST_CACHE_HS_9:
  894. case SQ_ALU_CONST_CACHE_HS_10:
  895. case SQ_ALU_CONST_CACHE_HS_11:
  896. case SQ_ALU_CONST_CACHE_HS_12:
  897. case SQ_ALU_CONST_CACHE_HS_13:
  898. case SQ_ALU_CONST_CACHE_HS_14:
  899. case SQ_ALU_CONST_CACHE_HS_15:
  900. case SQ_ALU_CONST_CACHE_LS_0:
  901. case SQ_ALU_CONST_CACHE_LS_1:
  902. case SQ_ALU_CONST_CACHE_LS_2:
  903. case SQ_ALU_CONST_CACHE_LS_3:
  904. case SQ_ALU_CONST_CACHE_LS_4:
  905. case SQ_ALU_CONST_CACHE_LS_5:
  906. case SQ_ALU_CONST_CACHE_LS_6:
  907. case SQ_ALU_CONST_CACHE_LS_7:
  908. case SQ_ALU_CONST_CACHE_LS_8:
  909. case SQ_ALU_CONST_CACHE_LS_9:
  910. case SQ_ALU_CONST_CACHE_LS_10:
  911. case SQ_ALU_CONST_CACHE_LS_11:
  912. case SQ_ALU_CONST_CACHE_LS_12:
  913. case SQ_ALU_CONST_CACHE_LS_13:
  914. case SQ_ALU_CONST_CACHE_LS_14:
  915. case SQ_ALU_CONST_CACHE_LS_15:
  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 inline 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_WAIT_REG_MEM:
  1123. if (pkt->count != 5) {
  1124. DRM_ERROR("bad WAIT_REG_MEM\n");
  1125. return -EINVAL;
  1126. }
  1127. /* bit 4 is reg (0) or mem (1) */
  1128. if (idx_value & 0x10) {
  1129. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1130. if (r) {
  1131. DRM_ERROR("bad WAIT_REG_MEM\n");
  1132. return -EINVAL;
  1133. }
  1134. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1135. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1136. }
  1137. break;
  1138. case PACKET3_SURFACE_SYNC:
  1139. if (pkt->count != 3) {
  1140. DRM_ERROR("bad SURFACE_SYNC\n");
  1141. return -EINVAL;
  1142. }
  1143. /* 0xffffffff/0x0 is flush all cache flag */
  1144. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  1145. radeon_get_ib_value(p, idx + 2) != 0) {
  1146. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1147. if (r) {
  1148. DRM_ERROR("bad SURFACE_SYNC\n");
  1149. return -EINVAL;
  1150. }
  1151. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1152. }
  1153. break;
  1154. case PACKET3_EVENT_WRITE:
  1155. if (pkt->count != 2 && pkt->count != 0) {
  1156. DRM_ERROR("bad EVENT_WRITE\n");
  1157. return -EINVAL;
  1158. }
  1159. if (pkt->count) {
  1160. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1161. if (r) {
  1162. DRM_ERROR("bad EVENT_WRITE\n");
  1163. return -EINVAL;
  1164. }
  1165. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1166. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1167. }
  1168. break;
  1169. case PACKET3_EVENT_WRITE_EOP:
  1170. if (pkt->count != 4) {
  1171. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1172. return -EINVAL;
  1173. }
  1174. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1175. if (r) {
  1176. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1177. return -EINVAL;
  1178. }
  1179. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1180. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1181. break;
  1182. case PACKET3_EVENT_WRITE_EOS:
  1183. if (pkt->count != 3) {
  1184. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1185. return -EINVAL;
  1186. }
  1187. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1188. if (r) {
  1189. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1190. return -EINVAL;
  1191. }
  1192. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1193. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1194. break;
  1195. case PACKET3_SET_CONFIG_REG:
  1196. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  1197. end_reg = 4 * pkt->count + start_reg - 4;
  1198. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  1199. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  1200. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  1201. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  1202. return -EINVAL;
  1203. }
  1204. for (i = 0; i < pkt->count; i++) {
  1205. reg = start_reg + (4 * i);
  1206. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1207. if (r)
  1208. return r;
  1209. }
  1210. break;
  1211. case PACKET3_SET_CONTEXT_REG:
  1212. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
  1213. end_reg = 4 * pkt->count + start_reg - 4;
  1214. if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
  1215. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  1216. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  1217. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  1218. return -EINVAL;
  1219. }
  1220. for (i = 0; i < pkt->count; i++) {
  1221. reg = start_reg + (4 * i);
  1222. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1223. if (r)
  1224. return r;
  1225. }
  1226. break;
  1227. case PACKET3_SET_RESOURCE:
  1228. if (pkt->count % 8) {
  1229. DRM_ERROR("bad SET_RESOURCE\n");
  1230. return -EINVAL;
  1231. }
  1232. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
  1233. end_reg = 4 * pkt->count + start_reg - 4;
  1234. if ((start_reg < PACKET3_SET_RESOURCE_START) ||
  1235. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  1236. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  1237. DRM_ERROR("bad SET_RESOURCE\n");
  1238. return -EINVAL;
  1239. }
  1240. for (i = 0; i < (pkt->count / 8); i++) {
  1241. struct radeon_bo *texture, *mipmap;
  1242. u32 size, offset;
  1243. switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
  1244. case SQ_TEX_VTX_VALID_TEXTURE:
  1245. /* tex base */
  1246. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1247. if (r) {
  1248. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1249. return -EINVAL;
  1250. }
  1251. ib[idx+1+(i*8)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1252. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
  1253. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  1254. else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
  1255. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  1256. texture = reloc->robj;
  1257. /* tex mip base */
  1258. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1259. if (r) {
  1260. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1261. return -EINVAL;
  1262. }
  1263. ib[idx+1+(i*8)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1264. mipmap = reloc->robj;
  1265. r = evergreen_check_texture_resource(p, idx+1+(i*8),
  1266. texture, mipmap);
  1267. if (r)
  1268. return r;
  1269. break;
  1270. case SQ_TEX_VTX_VALID_BUFFER:
  1271. /* vtx base */
  1272. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1273. if (r) {
  1274. DRM_ERROR("bad SET_RESOURCE (vtx)\n");
  1275. return -EINVAL;
  1276. }
  1277. offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
  1278. size = radeon_get_ib_value(p, idx+1+(i*8)+1);
  1279. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  1280. /* force size to size of the buffer */
  1281. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  1282. ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj);
  1283. }
  1284. ib[idx+1+(i*8)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
  1285. ib[idx+1+(i*8)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1286. break;
  1287. case SQ_TEX_VTX_INVALID_TEXTURE:
  1288. case SQ_TEX_VTX_INVALID_BUFFER:
  1289. default:
  1290. DRM_ERROR("bad SET_RESOURCE\n");
  1291. return -EINVAL;
  1292. }
  1293. }
  1294. break;
  1295. case PACKET3_SET_ALU_CONST:
  1296. /* XXX fix me ALU const buffers only */
  1297. break;
  1298. case PACKET3_SET_BOOL_CONST:
  1299. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
  1300. end_reg = 4 * pkt->count + start_reg - 4;
  1301. if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
  1302. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  1303. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  1304. DRM_ERROR("bad SET_BOOL_CONST\n");
  1305. return -EINVAL;
  1306. }
  1307. break;
  1308. case PACKET3_SET_LOOP_CONST:
  1309. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
  1310. end_reg = 4 * pkt->count + start_reg - 4;
  1311. if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
  1312. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  1313. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  1314. DRM_ERROR("bad SET_LOOP_CONST\n");
  1315. return -EINVAL;
  1316. }
  1317. break;
  1318. case PACKET3_SET_CTL_CONST:
  1319. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
  1320. end_reg = 4 * pkt->count + start_reg - 4;
  1321. if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
  1322. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  1323. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  1324. DRM_ERROR("bad SET_CTL_CONST\n");
  1325. return -EINVAL;
  1326. }
  1327. break;
  1328. case PACKET3_SET_SAMPLER:
  1329. if (pkt->count % 3) {
  1330. DRM_ERROR("bad SET_SAMPLER\n");
  1331. return -EINVAL;
  1332. }
  1333. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
  1334. end_reg = 4 * pkt->count + start_reg - 4;
  1335. if ((start_reg < PACKET3_SET_SAMPLER_START) ||
  1336. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  1337. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  1338. DRM_ERROR("bad SET_SAMPLER\n");
  1339. return -EINVAL;
  1340. }
  1341. break;
  1342. case PACKET3_NOP:
  1343. break;
  1344. default:
  1345. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1346. return -EINVAL;
  1347. }
  1348. return 0;
  1349. }
  1350. int evergreen_cs_parse(struct radeon_cs_parser *p)
  1351. {
  1352. struct radeon_cs_packet pkt;
  1353. struct evergreen_cs_track *track;
  1354. int r;
  1355. if (p->track == NULL) {
  1356. /* initialize tracker, we are in kms */
  1357. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1358. if (track == NULL)
  1359. return -ENOMEM;
  1360. evergreen_cs_track_init(track);
  1361. track->npipes = p->rdev->config.evergreen.tiling_npipes;
  1362. track->nbanks = p->rdev->config.evergreen.tiling_nbanks;
  1363. track->group_size = p->rdev->config.evergreen.tiling_group_size;
  1364. p->track = track;
  1365. }
  1366. do {
  1367. r = evergreen_cs_packet_parse(p, &pkt, p->idx);
  1368. if (r) {
  1369. kfree(p->track);
  1370. p->track = NULL;
  1371. return r;
  1372. }
  1373. p->idx += pkt.count + 2;
  1374. switch (pkt.type) {
  1375. case PACKET_TYPE0:
  1376. r = evergreen_cs_parse_packet0(p, &pkt);
  1377. break;
  1378. case PACKET_TYPE2:
  1379. break;
  1380. case PACKET_TYPE3:
  1381. r = evergreen_packet3_check(p, &pkt);
  1382. break;
  1383. default:
  1384. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1385. kfree(p->track);
  1386. p->track = NULL;
  1387. return -EINVAL;
  1388. }
  1389. if (r) {
  1390. kfree(p->track);
  1391. p->track = NULL;
  1392. return r;
  1393. }
  1394. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1395. #if 0
  1396. for (r = 0; r < p->ib->length_dw; r++) {
  1397. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  1398. mdelay(1);
  1399. }
  1400. #endif
  1401. kfree(p->track);
  1402. p->track = NULL;
  1403. return 0;
  1404. }