evergreen_cs.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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. return -EINVAL;
  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. return -EINVAL;
  283. }
  284. /* waiting for value to be equal */
  285. if ((wait_reg_mem_info & 0x7) != 0x3) {
  286. DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
  287. return -EINVAL;
  288. }
  289. if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != EVERGREEN_VLINE_STATUS) {
  290. DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
  291. return -EINVAL;
  292. }
  293. if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != EVERGREEN_VLINE_STAT) {
  294. DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
  295. return -EINVAL;
  296. }
  297. /* jump over the NOP */
  298. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
  299. if (r)
  300. return r;
  301. h_idx = p->idx - 2;
  302. p->idx += wait_reg_mem.count + 2;
  303. p->idx += p3reloc.count + 2;
  304. header = radeon_get_ib_value(p, h_idx);
  305. crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
  306. reg = CP_PACKET0_GET_REG(header);
  307. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  308. if (!obj) {
  309. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  310. return -EINVAL;
  311. }
  312. crtc = obj_to_crtc(obj);
  313. radeon_crtc = to_radeon_crtc(crtc);
  314. crtc_id = radeon_crtc->crtc_id;
  315. if (!crtc->enabled) {
  316. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  317. ib[h_idx + 2] = PACKET2(0);
  318. ib[h_idx + 3] = PACKET2(0);
  319. ib[h_idx + 4] = PACKET2(0);
  320. ib[h_idx + 5] = PACKET2(0);
  321. ib[h_idx + 6] = PACKET2(0);
  322. ib[h_idx + 7] = PACKET2(0);
  323. ib[h_idx + 8] = PACKET2(0);
  324. } else {
  325. switch (reg) {
  326. case EVERGREEN_VLINE_START_END:
  327. header &= ~R600_CP_PACKET0_REG_MASK;
  328. header |= (EVERGREEN_VLINE_START_END + radeon_crtc->crtc_offset) >> 2;
  329. ib[h_idx] = header;
  330. ib[h_idx + 4] = (EVERGREEN_VLINE_STATUS + radeon_crtc->crtc_offset) >> 2;
  331. break;
  332. default:
  333. DRM_ERROR("unknown crtc reloc\n");
  334. return -EINVAL;
  335. }
  336. }
  337. return 0;
  338. }
  339. static int evergreen_packet0_check(struct radeon_cs_parser *p,
  340. struct radeon_cs_packet *pkt,
  341. unsigned idx, unsigned reg)
  342. {
  343. int r;
  344. switch (reg) {
  345. case EVERGREEN_VLINE_START_END:
  346. r = evergreen_cs_packet_parse_vline(p);
  347. if (r) {
  348. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  349. idx, reg);
  350. return r;
  351. }
  352. break;
  353. default:
  354. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  355. reg, idx);
  356. return -EINVAL;
  357. }
  358. return 0;
  359. }
  360. static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
  361. struct radeon_cs_packet *pkt)
  362. {
  363. unsigned reg, i;
  364. unsigned idx;
  365. int r;
  366. idx = pkt->idx + 1;
  367. reg = pkt->reg;
  368. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  369. r = evergreen_packet0_check(p, pkt, idx, reg);
  370. if (r) {
  371. return r;
  372. }
  373. }
  374. return 0;
  375. }
  376. /**
  377. * evergreen_cs_check_reg() - check if register is authorized or not
  378. * @parser: parser structure holding parsing context
  379. * @reg: register we are testing
  380. * @idx: index into the cs buffer
  381. *
  382. * This function will test against evergreen_reg_safe_bm and return 0
  383. * if register is safe. If register is not flag as safe this function
  384. * will test it against a list of register needind special handling.
  385. */
  386. static inline int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  387. {
  388. struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
  389. struct radeon_cs_reloc *reloc;
  390. u32 last_reg;
  391. u32 m, i, tmp, *ib;
  392. int r;
  393. if (p->rdev->family >= CHIP_CAYMAN)
  394. last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
  395. else
  396. last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
  397. i = (reg >> 7);
  398. if (i > last_reg) {
  399. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  400. return -EINVAL;
  401. }
  402. m = 1 << ((reg >> 2) & 31);
  403. if (p->rdev->family >= CHIP_CAYMAN) {
  404. if (!(cayman_reg_safe_bm[i] & m))
  405. return 0;
  406. } else {
  407. if (!(evergreen_reg_safe_bm[i] & m))
  408. return 0;
  409. }
  410. ib = p->ib->ptr;
  411. switch (reg) {
  412. /* force following reg to 0 in an attempt to disable out buffer
  413. * which will need us to better understand how it works to perform
  414. * security check on it (Jerome)
  415. */
  416. case SQ_ESGS_RING_SIZE:
  417. case SQ_GSVS_RING_SIZE:
  418. case SQ_ESTMP_RING_SIZE:
  419. case SQ_GSTMP_RING_SIZE:
  420. case SQ_HSTMP_RING_SIZE:
  421. case SQ_LSTMP_RING_SIZE:
  422. case SQ_PSTMP_RING_SIZE:
  423. case SQ_VSTMP_RING_SIZE:
  424. case SQ_ESGS_RING_ITEMSIZE:
  425. case SQ_ESTMP_RING_ITEMSIZE:
  426. case SQ_GSTMP_RING_ITEMSIZE:
  427. case SQ_GSVS_RING_ITEMSIZE:
  428. case SQ_GS_VERT_ITEMSIZE:
  429. case SQ_GS_VERT_ITEMSIZE_1:
  430. case SQ_GS_VERT_ITEMSIZE_2:
  431. case SQ_GS_VERT_ITEMSIZE_3:
  432. case SQ_GSVS_RING_OFFSET_1:
  433. case SQ_GSVS_RING_OFFSET_2:
  434. case SQ_GSVS_RING_OFFSET_3:
  435. case SQ_HSTMP_RING_ITEMSIZE:
  436. case SQ_LSTMP_RING_ITEMSIZE:
  437. case SQ_PSTMP_RING_ITEMSIZE:
  438. case SQ_VSTMP_RING_ITEMSIZE:
  439. case VGT_TF_RING_SIZE:
  440. /* get value to populate the IB don't remove */
  441. /*tmp =radeon_get_ib_value(p, idx);
  442. ib[idx] = 0;*/
  443. break;
  444. case SQ_ESGS_RING_BASE:
  445. case SQ_GSVS_RING_BASE:
  446. case SQ_ESTMP_RING_BASE:
  447. case SQ_GSTMP_RING_BASE:
  448. case SQ_HSTMP_RING_BASE:
  449. case SQ_LSTMP_RING_BASE:
  450. case SQ_PSTMP_RING_BASE:
  451. case SQ_VSTMP_RING_BASE:
  452. r = evergreen_cs_packet_next_reloc(p, &reloc);
  453. if (r) {
  454. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  455. "0x%04X\n", reg);
  456. return -EINVAL;
  457. }
  458. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  459. break;
  460. case DB_DEPTH_CONTROL:
  461. track->db_depth_control = radeon_get_ib_value(p, idx);
  462. break;
  463. case CAYMAN_DB_EQAA:
  464. if (p->rdev->family < CHIP_CAYMAN) {
  465. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  466. "0x%04X\n", reg);
  467. return -EINVAL;
  468. }
  469. break;
  470. case CAYMAN_DB_DEPTH_INFO:
  471. if (p->rdev->family < CHIP_CAYMAN) {
  472. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  473. "0x%04X\n", reg);
  474. return -EINVAL;
  475. }
  476. break;
  477. case DB_Z_INFO:
  478. r = evergreen_cs_packet_next_reloc(p, &reloc);
  479. if (r) {
  480. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  481. "0x%04X\n", reg);
  482. return -EINVAL;
  483. }
  484. track->db_z_info = radeon_get_ib_value(p, idx);
  485. ib[idx] &= ~Z_ARRAY_MODE(0xf);
  486. track->db_z_info &= ~Z_ARRAY_MODE(0xf);
  487. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  488. ib[idx] |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  489. track->db_z_info |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  490. } else {
  491. ib[idx] |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  492. track->db_z_info |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  493. }
  494. break;
  495. case DB_STENCIL_INFO:
  496. track->db_s_info = radeon_get_ib_value(p, idx);
  497. break;
  498. case DB_DEPTH_VIEW:
  499. track->db_depth_view = radeon_get_ib_value(p, idx);
  500. break;
  501. case DB_DEPTH_SIZE:
  502. track->db_depth_size = radeon_get_ib_value(p, idx);
  503. track->db_depth_size_idx = idx;
  504. break;
  505. case DB_Z_READ_BASE:
  506. r = evergreen_cs_packet_next_reloc(p, &reloc);
  507. if (r) {
  508. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  509. "0x%04X\n", reg);
  510. return -EINVAL;
  511. }
  512. track->db_z_read_offset = radeon_get_ib_value(p, idx);
  513. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  514. track->db_z_read_bo = reloc->robj;
  515. break;
  516. case DB_Z_WRITE_BASE:
  517. r = evergreen_cs_packet_next_reloc(p, &reloc);
  518. if (r) {
  519. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  520. "0x%04X\n", reg);
  521. return -EINVAL;
  522. }
  523. track->db_z_write_offset = radeon_get_ib_value(p, idx);
  524. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  525. track->db_z_write_bo = reloc->robj;
  526. break;
  527. case DB_STENCIL_READ_BASE:
  528. r = evergreen_cs_packet_next_reloc(p, &reloc);
  529. if (r) {
  530. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  531. "0x%04X\n", reg);
  532. return -EINVAL;
  533. }
  534. track->db_s_read_offset = radeon_get_ib_value(p, idx);
  535. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  536. track->db_s_read_bo = reloc->robj;
  537. break;
  538. case DB_STENCIL_WRITE_BASE:
  539. r = evergreen_cs_packet_next_reloc(p, &reloc);
  540. if (r) {
  541. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  542. "0x%04X\n", reg);
  543. return -EINVAL;
  544. }
  545. track->db_s_write_offset = radeon_get_ib_value(p, idx);
  546. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  547. track->db_s_write_bo = reloc->robj;
  548. break;
  549. case VGT_STRMOUT_CONFIG:
  550. track->vgt_strmout_config = radeon_get_ib_value(p, idx);
  551. break;
  552. case VGT_STRMOUT_BUFFER_CONFIG:
  553. track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
  554. break;
  555. case CB_TARGET_MASK:
  556. track->cb_target_mask = radeon_get_ib_value(p, idx);
  557. break;
  558. case CB_SHADER_MASK:
  559. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  560. break;
  561. case PA_SC_AA_CONFIG:
  562. if (p->rdev->family >= CHIP_CAYMAN) {
  563. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  564. "0x%04X\n", reg);
  565. return -EINVAL;
  566. }
  567. tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
  568. track->nsamples = 1 << tmp;
  569. break;
  570. case CAYMAN_PA_SC_AA_CONFIG:
  571. if (p->rdev->family < CHIP_CAYMAN) {
  572. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  573. "0x%04X\n", reg);
  574. return -EINVAL;
  575. }
  576. tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
  577. track->nsamples = 1 << tmp;
  578. break;
  579. case CB_COLOR0_VIEW:
  580. case CB_COLOR1_VIEW:
  581. case CB_COLOR2_VIEW:
  582. case CB_COLOR3_VIEW:
  583. case CB_COLOR4_VIEW:
  584. case CB_COLOR5_VIEW:
  585. case CB_COLOR6_VIEW:
  586. case CB_COLOR7_VIEW:
  587. tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
  588. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  589. break;
  590. case CB_COLOR8_VIEW:
  591. case CB_COLOR9_VIEW:
  592. case CB_COLOR10_VIEW:
  593. case CB_COLOR11_VIEW:
  594. tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
  595. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  596. break;
  597. case CB_COLOR0_INFO:
  598. case CB_COLOR1_INFO:
  599. case CB_COLOR2_INFO:
  600. case CB_COLOR3_INFO:
  601. case CB_COLOR4_INFO:
  602. case CB_COLOR5_INFO:
  603. case CB_COLOR6_INFO:
  604. case CB_COLOR7_INFO:
  605. r = evergreen_cs_packet_next_reloc(p, &reloc);
  606. if (r) {
  607. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  608. "0x%04X\n", reg);
  609. return -EINVAL;
  610. }
  611. tmp = (reg - CB_COLOR0_INFO) / 0x3c;
  612. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  613. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  614. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  615. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  616. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  617. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  618. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  619. }
  620. break;
  621. case CB_COLOR8_INFO:
  622. case CB_COLOR9_INFO:
  623. case CB_COLOR10_INFO:
  624. case CB_COLOR11_INFO:
  625. r = evergreen_cs_packet_next_reloc(p, &reloc);
  626. if (r) {
  627. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  628. "0x%04X\n", reg);
  629. return -EINVAL;
  630. }
  631. tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
  632. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  633. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  634. ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  635. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  636. } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) {
  637. ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  638. track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  639. }
  640. break;
  641. case CB_COLOR0_PITCH:
  642. case CB_COLOR1_PITCH:
  643. case CB_COLOR2_PITCH:
  644. case CB_COLOR3_PITCH:
  645. case CB_COLOR4_PITCH:
  646. case CB_COLOR5_PITCH:
  647. case CB_COLOR6_PITCH:
  648. case CB_COLOR7_PITCH:
  649. tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
  650. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  651. track->cb_color_pitch_idx[tmp] = idx;
  652. break;
  653. case CB_COLOR8_PITCH:
  654. case CB_COLOR9_PITCH:
  655. case CB_COLOR10_PITCH:
  656. case CB_COLOR11_PITCH:
  657. tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
  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_COLOR0_SLICE:
  662. case CB_COLOR1_SLICE:
  663. case CB_COLOR2_SLICE:
  664. case CB_COLOR3_SLICE:
  665. case CB_COLOR4_SLICE:
  666. case CB_COLOR5_SLICE:
  667. case CB_COLOR6_SLICE:
  668. case CB_COLOR7_SLICE:
  669. tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
  670. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  671. track->cb_color_slice_idx[tmp] = idx;
  672. break;
  673. case CB_COLOR8_SLICE:
  674. case CB_COLOR9_SLICE:
  675. case CB_COLOR10_SLICE:
  676. case CB_COLOR11_SLICE:
  677. tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
  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_COLOR0_ATTRIB:
  682. case CB_COLOR1_ATTRIB:
  683. case CB_COLOR2_ATTRIB:
  684. case CB_COLOR3_ATTRIB:
  685. case CB_COLOR4_ATTRIB:
  686. case CB_COLOR5_ATTRIB:
  687. case CB_COLOR6_ATTRIB:
  688. case CB_COLOR7_ATTRIB:
  689. case CB_COLOR8_ATTRIB:
  690. case CB_COLOR9_ATTRIB:
  691. case CB_COLOR10_ATTRIB:
  692. case CB_COLOR11_ATTRIB:
  693. break;
  694. case CB_COLOR0_DIM:
  695. case CB_COLOR1_DIM:
  696. case CB_COLOR2_DIM:
  697. case CB_COLOR3_DIM:
  698. case CB_COLOR4_DIM:
  699. case CB_COLOR5_DIM:
  700. case CB_COLOR6_DIM:
  701. case CB_COLOR7_DIM:
  702. tmp = (reg - CB_COLOR0_DIM) / 0x3c;
  703. track->cb_color_dim[tmp] = radeon_get_ib_value(p, idx);
  704. track->cb_color_dim_idx[tmp] = idx;
  705. break;
  706. case CB_COLOR8_DIM:
  707. case CB_COLOR9_DIM:
  708. case CB_COLOR10_DIM:
  709. case CB_COLOR11_DIM:
  710. tmp = ((reg - CB_COLOR8_DIM) / 0x1c) + 8;
  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_COLOR0_FMASK:
  715. case CB_COLOR1_FMASK:
  716. case CB_COLOR2_FMASK:
  717. case CB_COLOR3_FMASK:
  718. case CB_COLOR4_FMASK:
  719. case CB_COLOR5_FMASK:
  720. case CB_COLOR6_FMASK:
  721. case CB_COLOR7_FMASK:
  722. tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
  723. r = evergreen_cs_packet_next_reloc(p, &reloc);
  724. if (r) {
  725. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  726. return -EINVAL;
  727. }
  728. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  729. track->cb_color_fmask_bo[tmp] = reloc->robj;
  730. break;
  731. case CB_COLOR0_CMASK:
  732. case CB_COLOR1_CMASK:
  733. case CB_COLOR2_CMASK:
  734. case CB_COLOR3_CMASK:
  735. case CB_COLOR4_CMASK:
  736. case CB_COLOR5_CMASK:
  737. case CB_COLOR6_CMASK:
  738. case CB_COLOR7_CMASK:
  739. tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
  740. r = evergreen_cs_packet_next_reloc(p, &reloc);
  741. if (r) {
  742. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  743. return -EINVAL;
  744. }
  745. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  746. track->cb_color_cmask_bo[tmp] = reloc->robj;
  747. break;
  748. case CB_COLOR0_FMASK_SLICE:
  749. case CB_COLOR1_FMASK_SLICE:
  750. case CB_COLOR2_FMASK_SLICE:
  751. case CB_COLOR3_FMASK_SLICE:
  752. case CB_COLOR4_FMASK_SLICE:
  753. case CB_COLOR5_FMASK_SLICE:
  754. case CB_COLOR6_FMASK_SLICE:
  755. case CB_COLOR7_FMASK_SLICE:
  756. tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
  757. track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
  758. break;
  759. case CB_COLOR0_CMASK_SLICE:
  760. case CB_COLOR1_CMASK_SLICE:
  761. case CB_COLOR2_CMASK_SLICE:
  762. case CB_COLOR3_CMASK_SLICE:
  763. case CB_COLOR4_CMASK_SLICE:
  764. case CB_COLOR5_CMASK_SLICE:
  765. case CB_COLOR6_CMASK_SLICE:
  766. case CB_COLOR7_CMASK_SLICE:
  767. tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
  768. track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
  769. break;
  770. case CB_COLOR0_BASE:
  771. case CB_COLOR1_BASE:
  772. case CB_COLOR2_BASE:
  773. case CB_COLOR3_BASE:
  774. case CB_COLOR4_BASE:
  775. case CB_COLOR5_BASE:
  776. case CB_COLOR6_BASE:
  777. case CB_COLOR7_BASE:
  778. r = evergreen_cs_packet_next_reloc(p, &reloc);
  779. if (r) {
  780. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  781. "0x%04X\n", reg);
  782. return -EINVAL;
  783. }
  784. tmp = (reg - CB_COLOR0_BASE) / 0x3c;
  785. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  786. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  787. track->cb_color_base_last[tmp] = ib[idx];
  788. track->cb_color_bo[tmp] = reloc->robj;
  789. break;
  790. case CB_COLOR8_BASE:
  791. case CB_COLOR9_BASE:
  792. case CB_COLOR10_BASE:
  793. case CB_COLOR11_BASE:
  794. r = evergreen_cs_packet_next_reloc(p, &reloc);
  795. if (r) {
  796. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  797. "0x%04X\n", reg);
  798. return -EINVAL;
  799. }
  800. tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
  801. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  802. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  803. track->cb_color_base_last[tmp] = ib[idx];
  804. track->cb_color_bo[tmp] = reloc->robj;
  805. break;
  806. case CB_IMMED0_BASE:
  807. case CB_IMMED1_BASE:
  808. case CB_IMMED2_BASE:
  809. case CB_IMMED3_BASE:
  810. case CB_IMMED4_BASE:
  811. case CB_IMMED5_BASE:
  812. case CB_IMMED6_BASE:
  813. case CB_IMMED7_BASE:
  814. case CB_IMMED8_BASE:
  815. case CB_IMMED9_BASE:
  816. case CB_IMMED10_BASE:
  817. case CB_IMMED11_BASE:
  818. case DB_HTILE_DATA_BASE:
  819. case SQ_PGM_START_FS:
  820. case SQ_PGM_START_ES:
  821. case SQ_PGM_START_VS:
  822. case SQ_PGM_START_GS:
  823. case SQ_PGM_START_PS:
  824. case SQ_PGM_START_HS:
  825. case SQ_PGM_START_LS:
  826. case GDS_ADDR_BASE:
  827. case SQ_CONST_MEM_BASE:
  828. case SQ_ALU_CONST_CACHE_GS_0:
  829. case SQ_ALU_CONST_CACHE_GS_1:
  830. case SQ_ALU_CONST_CACHE_GS_2:
  831. case SQ_ALU_CONST_CACHE_GS_3:
  832. case SQ_ALU_CONST_CACHE_GS_4:
  833. case SQ_ALU_CONST_CACHE_GS_5:
  834. case SQ_ALU_CONST_CACHE_GS_6:
  835. case SQ_ALU_CONST_CACHE_GS_7:
  836. case SQ_ALU_CONST_CACHE_GS_8:
  837. case SQ_ALU_CONST_CACHE_GS_9:
  838. case SQ_ALU_CONST_CACHE_GS_10:
  839. case SQ_ALU_CONST_CACHE_GS_11:
  840. case SQ_ALU_CONST_CACHE_GS_12:
  841. case SQ_ALU_CONST_CACHE_GS_13:
  842. case SQ_ALU_CONST_CACHE_GS_14:
  843. case SQ_ALU_CONST_CACHE_GS_15:
  844. case SQ_ALU_CONST_CACHE_PS_0:
  845. case SQ_ALU_CONST_CACHE_PS_1:
  846. case SQ_ALU_CONST_CACHE_PS_2:
  847. case SQ_ALU_CONST_CACHE_PS_3:
  848. case SQ_ALU_CONST_CACHE_PS_4:
  849. case SQ_ALU_CONST_CACHE_PS_5:
  850. case SQ_ALU_CONST_CACHE_PS_6:
  851. case SQ_ALU_CONST_CACHE_PS_7:
  852. case SQ_ALU_CONST_CACHE_PS_8:
  853. case SQ_ALU_CONST_CACHE_PS_9:
  854. case SQ_ALU_CONST_CACHE_PS_10:
  855. case SQ_ALU_CONST_CACHE_PS_11:
  856. case SQ_ALU_CONST_CACHE_PS_12:
  857. case SQ_ALU_CONST_CACHE_PS_13:
  858. case SQ_ALU_CONST_CACHE_PS_14:
  859. case SQ_ALU_CONST_CACHE_PS_15:
  860. case SQ_ALU_CONST_CACHE_VS_0:
  861. case SQ_ALU_CONST_CACHE_VS_1:
  862. case SQ_ALU_CONST_CACHE_VS_2:
  863. case SQ_ALU_CONST_CACHE_VS_3:
  864. case SQ_ALU_CONST_CACHE_VS_4:
  865. case SQ_ALU_CONST_CACHE_VS_5:
  866. case SQ_ALU_CONST_CACHE_VS_6:
  867. case SQ_ALU_CONST_CACHE_VS_7:
  868. case SQ_ALU_CONST_CACHE_VS_8:
  869. case SQ_ALU_CONST_CACHE_VS_9:
  870. case SQ_ALU_CONST_CACHE_VS_10:
  871. case SQ_ALU_CONST_CACHE_VS_11:
  872. case SQ_ALU_CONST_CACHE_VS_12:
  873. case SQ_ALU_CONST_CACHE_VS_13:
  874. case SQ_ALU_CONST_CACHE_VS_14:
  875. case SQ_ALU_CONST_CACHE_VS_15:
  876. case SQ_ALU_CONST_CACHE_HS_0:
  877. case SQ_ALU_CONST_CACHE_HS_1:
  878. case SQ_ALU_CONST_CACHE_HS_2:
  879. case SQ_ALU_CONST_CACHE_HS_3:
  880. case SQ_ALU_CONST_CACHE_HS_4:
  881. case SQ_ALU_CONST_CACHE_HS_5:
  882. case SQ_ALU_CONST_CACHE_HS_6:
  883. case SQ_ALU_CONST_CACHE_HS_7:
  884. case SQ_ALU_CONST_CACHE_HS_8:
  885. case SQ_ALU_CONST_CACHE_HS_9:
  886. case SQ_ALU_CONST_CACHE_HS_10:
  887. case SQ_ALU_CONST_CACHE_HS_11:
  888. case SQ_ALU_CONST_CACHE_HS_12:
  889. case SQ_ALU_CONST_CACHE_HS_13:
  890. case SQ_ALU_CONST_CACHE_HS_14:
  891. case SQ_ALU_CONST_CACHE_HS_15:
  892. case SQ_ALU_CONST_CACHE_LS_0:
  893. case SQ_ALU_CONST_CACHE_LS_1:
  894. case SQ_ALU_CONST_CACHE_LS_2:
  895. case SQ_ALU_CONST_CACHE_LS_3:
  896. case SQ_ALU_CONST_CACHE_LS_4:
  897. case SQ_ALU_CONST_CACHE_LS_5:
  898. case SQ_ALU_CONST_CACHE_LS_6:
  899. case SQ_ALU_CONST_CACHE_LS_7:
  900. case SQ_ALU_CONST_CACHE_LS_8:
  901. case SQ_ALU_CONST_CACHE_LS_9:
  902. case SQ_ALU_CONST_CACHE_LS_10:
  903. case SQ_ALU_CONST_CACHE_LS_11:
  904. case SQ_ALU_CONST_CACHE_LS_12:
  905. case SQ_ALU_CONST_CACHE_LS_13:
  906. case SQ_ALU_CONST_CACHE_LS_14:
  907. case SQ_ALU_CONST_CACHE_LS_15:
  908. r = evergreen_cs_packet_next_reloc(p, &reloc);
  909. if (r) {
  910. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  911. "0x%04X\n", reg);
  912. return -EINVAL;
  913. }
  914. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  915. break;
  916. default:
  917. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  918. return -EINVAL;
  919. }
  920. return 0;
  921. }
  922. /**
  923. * evergreen_check_texture_resource() - check if register is authorized or not
  924. * @p: parser structure holding parsing context
  925. * @idx: index into the cs buffer
  926. * @texture: texture's bo structure
  927. * @mipmap: mipmap's bo structure
  928. *
  929. * This function will check that the resource has valid field and that
  930. * the texture and mipmap bo object are big enough to cover this resource.
  931. */
  932. static inline int evergreen_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
  933. struct radeon_bo *texture,
  934. struct radeon_bo *mipmap)
  935. {
  936. /* XXX fill in */
  937. return 0;
  938. }
  939. static int evergreen_packet3_check(struct radeon_cs_parser *p,
  940. struct radeon_cs_packet *pkt)
  941. {
  942. struct radeon_cs_reloc *reloc;
  943. struct evergreen_cs_track *track;
  944. volatile u32 *ib;
  945. unsigned idx;
  946. unsigned i;
  947. unsigned start_reg, end_reg, reg;
  948. int r;
  949. u32 idx_value;
  950. track = (struct evergreen_cs_track *)p->track;
  951. ib = p->ib->ptr;
  952. idx = pkt->idx + 1;
  953. idx_value = radeon_get_ib_value(p, idx);
  954. switch (pkt->opcode) {
  955. case PACKET3_SET_PREDICATION:
  956. {
  957. int pred_op;
  958. int tmp;
  959. if (pkt->count != 1) {
  960. DRM_ERROR("bad SET PREDICATION\n");
  961. return -EINVAL;
  962. }
  963. tmp = radeon_get_ib_value(p, idx + 1);
  964. pred_op = (tmp >> 16) & 0x7;
  965. /* for the clear predicate operation */
  966. if (pred_op == 0)
  967. return 0;
  968. if (pred_op > 2) {
  969. DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op);
  970. return -EINVAL;
  971. }
  972. r = evergreen_cs_packet_next_reloc(p, &reloc);
  973. if (r) {
  974. DRM_ERROR("bad SET PREDICATION\n");
  975. return -EINVAL;
  976. }
  977. ib[idx + 0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  978. ib[idx + 1] = tmp + (upper_32_bits(reloc->lobj.gpu_offset) & 0xff);
  979. }
  980. break;
  981. case PACKET3_CONTEXT_CONTROL:
  982. if (pkt->count != 1) {
  983. DRM_ERROR("bad CONTEXT_CONTROL\n");
  984. return -EINVAL;
  985. }
  986. break;
  987. case PACKET3_INDEX_TYPE:
  988. case PACKET3_NUM_INSTANCES:
  989. case PACKET3_CLEAR_STATE:
  990. if (pkt->count) {
  991. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  992. return -EINVAL;
  993. }
  994. break;
  995. case CAYMAN_PACKET3_DEALLOC_STATE:
  996. if (p->rdev->family < CHIP_CAYMAN) {
  997. DRM_ERROR("bad PACKET3_DEALLOC_STATE\n");
  998. return -EINVAL;
  999. }
  1000. if (pkt->count) {
  1001. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1002. return -EINVAL;
  1003. }
  1004. break;
  1005. case PACKET3_INDEX_BASE:
  1006. if (pkt->count != 1) {
  1007. DRM_ERROR("bad INDEX_BASE\n");
  1008. return -EINVAL;
  1009. }
  1010. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1011. if (r) {
  1012. DRM_ERROR("bad INDEX_BASE\n");
  1013. return -EINVAL;
  1014. }
  1015. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1016. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1017. r = evergreen_cs_track_check(p);
  1018. if (r) {
  1019. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1020. return r;
  1021. }
  1022. break;
  1023. case PACKET3_DRAW_INDEX:
  1024. if (pkt->count != 3) {
  1025. DRM_ERROR("bad DRAW_INDEX\n");
  1026. return -EINVAL;
  1027. }
  1028. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1029. if (r) {
  1030. DRM_ERROR("bad DRAW_INDEX\n");
  1031. return -EINVAL;
  1032. }
  1033. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1034. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1035. r = evergreen_cs_track_check(p);
  1036. if (r) {
  1037. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1038. return r;
  1039. }
  1040. break;
  1041. case PACKET3_DRAW_INDEX_2:
  1042. if (pkt->count != 4) {
  1043. DRM_ERROR("bad DRAW_INDEX_2\n");
  1044. return -EINVAL;
  1045. }
  1046. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1047. if (r) {
  1048. DRM_ERROR("bad DRAW_INDEX_2\n");
  1049. return -EINVAL;
  1050. }
  1051. ib[idx+1] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1052. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1053. r = evergreen_cs_track_check(p);
  1054. if (r) {
  1055. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1056. return r;
  1057. }
  1058. break;
  1059. case PACKET3_DRAW_INDEX_AUTO:
  1060. if (pkt->count != 1) {
  1061. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1062. return -EINVAL;
  1063. }
  1064. r = evergreen_cs_track_check(p);
  1065. if (r) {
  1066. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1067. return r;
  1068. }
  1069. break;
  1070. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  1071. if (pkt->count != 2) {
  1072. DRM_ERROR("bad DRAW_INDEX_MULTI_AUTO\n");
  1073. return -EINVAL;
  1074. }
  1075. r = evergreen_cs_track_check(p);
  1076. if (r) {
  1077. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1078. return r;
  1079. }
  1080. break;
  1081. case PACKET3_DRAW_INDEX_IMMD:
  1082. if (pkt->count < 2) {
  1083. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1084. return -EINVAL;
  1085. }
  1086. r = evergreen_cs_track_check(p);
  1087. if (r) {
  1088. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1089. return r;
  1090. }
  1091. break;
  1092. case PACKET3_DRAW_INDEX_OFFSET:
  1093. if (pkt->count != 2) {
  1094. DRM_ERROR("bad DRAW_INDEX_OFFSET\n");
  1095. return -EINVAL;
  1096. }
  1097. r = evergreen_cs_track_check(p);
  1098. if (r) {
  1099. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1100. return r;
  1101. }
  1102. break;
  1103. case PACKET3_DRAW_INDEX_OFFSET_2:
  1104. if (pkt->count != 3) {
  1105. DRM_ERROR("bad DRAW_INDEX_OFFSET_2\n");
  1106. return -EINVAL;
  1107. }
  1108. r = evergreen_cs_track_check(p);
  1109. if (r) {
  1110. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1111. return r;
  1112. }
  1113. break;
  1114. case PACKET3_WAIT_REG_MEM:
  1115. if (pkt->count != 5) {
  1116. DRM_ERROR("bad WAIT_REG_MEM\n");
  1117. return -EINVAL;
  1118. }
  1119. /* bit 4 is reg (0) or mem (1) */
  1120. if (idx_value & 0x10) {
  1121. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1122. if (r) {
  1123. DRM_ERROR("bad WAIT_REG_MEM\n");
  1124. return -EINVAL;
  1125. }
  1126. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1127. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1128. }
  1129. break;
  1130. case PACKET3_SURFACE_SYNC:
  1131. if (pkt->count != 3) {
  1132. DRM_ERROR("bad SURFACE_SYNC\n");
  1133. return -EINVAL;
  1134. }
  1135. /* 0xffffffff/0x0 is flush all cache flag */
  1136. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  1137. radeon_get_ib_value(p, idx + 2) != 0) {
  1138. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1139. if (r) {
  1140. DRM_ERROR("bad SURFACE_SYNC\n");
  1141. return -EINVAL;
  1142. }
  1143. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1144. }
  1145. break;
  1146. case PACKET3_EVENT_WRITE:
  1147. if (pkt->count != 2 && pkt->count != 0) {
  1148. DRM_ERROR("bad EVENT_WRITE\n");
  1149. return -EINVAL;
  1150. }
  1151. if (pkt->count) {
  1152. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1153. if (r) {
  1154. DRM_ERROR("bad EVENT_WRITE\n");
  1155. return -EINVAL;
  1156. }
  1157. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1158. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1159. }
  1160. break;
  1161. case PACKET3_EVENT_WRITE_EOP:
  1162. if (pkt->count != 4) {
  1163. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1164. return -EINVAL;
  1165. }
  1166. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1167. if (r) {
  1168. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1169. return -EINVAL;
  1170. }
  1171. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1172. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1173. break;
  1174. case PACKET3_EVENT_WRITE_EOS:
  1175. if (pkt->count != 3) {
  1176. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1177. return -EINVAL;
  1178. }
  1179. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1180. if (r) {
  1181. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  1182. return -EINVAL;
  1183. }
  1184. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1185. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1186. break;
  1187. case PACKET3_SET_CONFIG_REG:
  1188. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  1189. end_reg = 4 * pkt->count + start_reg - 4;
  1190. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  1191. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  1192. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  1193. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  1194. return -EINVAL;
  1195. }
  1196. for (i = 0; i < pkt->count; i++) {
  1197. reg = start_reg + (4 * i);
  1198. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1199. if (r)
  1200. return r;
  1201. }
  1202. break;
  1203. case PACKET3_SET_CONTEXT_REG:
  1204. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
  1205. end_reg = 4 * pkt->count + start_reg - 4;
  1206. if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
  1207. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  1208. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  1209. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  1210. return -EINVAL;
  1211. }
  1212. for (i = 0; i < pkt->count; i++) {
  1213. reg = start_reg + (4 * i);
  1214. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  1215. if (r)
  1216. return r;
  1217. }
  1218. break;
  1219. case PACKET3_SET_RESOURCE:
  1220. if (pkt->count % 8) {
  1221. DRM_ERROR("bad SET_RESOURCE\n");
  1222. return -EINVAL;
  1223. }
  1224. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
  1225. end_reg = 4 * pkt->count + start_reg - 4;
  1226. if ((start_reg < PACKET3_SET_RESOURCE_START) ||
  1227. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  1228. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  1229. DRM_ERROR("bad SET_RESOURCE\n");
  1230. return -EINVAL;
  1231. }
  1232. for (i = 0; i < (pkt->count / 8); i++) {
  1233. struct radeon_bo *texture, *mipmap;
  1234. u32 size, offset;
  1235. switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
  1236. case SQ_TEX_VTX_VALID_TEXTURE:
  1237. /* tex base */
  1238. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1239. if (r) {
  1240. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1241. return -EINVAL;
  1242. }
  1243. ib[idx+1+(i*8)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1244. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
  1245. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_2D_TILED_THIN1);
  1246. else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
  1247. ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1);
  1248. texture = reloc->robj;
  1249. /* tex mip base */
  1250. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1251. if (r) {
  1252. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  1253. return -EINVAL;
  1254. }
  1255. ib[idx+1+(i*8)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1256. mipmap = reloc->robj;
  1257. r = evergreen_check_texture_resource(p, idx+1+(i*8),
  1258. texture, mipmap);
  1259. if (r)
  1260. return r;
  1261. break;
  1262. case SQ_TEX_VTX_VALID_BUFFER:
  1263. /* vtx base */
  1264. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1265. if (r) {
  1266. DRM_ERROR("bad SET_RESOURCE (vtx)\n");
  1267. return -EINVAL;
  1268. }
  1269. offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
  1270. size = radeon_get_ib_value(p, idx+1+(i*8)+1);
  1271. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  1272. /* force size to size of the buffer */
  1273. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  1274. ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj);
  1275. }
  1276. ib[idx+1+(i*8)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
  1277. ib[idx+1+(i*8)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1278. break;
  1279. case SQ_TEX_VTX_INVALID_TEXTURE:
  1280. case SQ_TEX_VTX_INVALID_BUFFER:
  1281. default:
  1282. DRM_ERROR("bad SET_RESOURCE\n");
  1283. return -EINVAL;
  1284. }
  1285. }
  1286. break;
  1287. case PACKET3_SET_ALU_CONST:
  1288. /* XXX fix me ALU const buffers only */
  1289. break;
  1290. case PACKET3_SET_BOOL_CONST:
  1291. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
  1292. end_reg = 4 * pkt->count + start_reg - 4;
  1293. if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
  1294. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  1295. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  1296. DRM_ERROR("bad SET_BOOL_CONST\n");
  1297. return -EINVAL;
  1298. }
  1299. break;
  1300. case PACKET3_SET_LOOP_CONST:
  1301. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
  1302. end_reg = 4 * pkt->count + start_reg - 4;
  1303. if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
  1304. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  1305. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  1306. DRM_ERROR("bad SET_LOOP_CONST\n");
  1307. return -EINVAL;
  1308. }
  1309. break;
  1310. case PACKET3_SET_CTL_CONST:
  1311. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
  1312. end_reg = 4 * pkt->count + start_reg - 4;
  1313. if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
  1314. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  1315. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  1316. DRM_ERROR("bad SET_CTL_CONST\n");
  1317. return -EINVAL;
  1318. }
  1319. break;
  1320. case PACKET3_SET_SAMPLER:
  1321. if (pkt->count % 3) {
  1322. DRM_ERROR("bad SET_SAMPLER\n");
  1323. return -EINVAL;
  1324. }
  1325. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
  1326. end_reg = 4 * pkt->count + start_reg - 4;
  1327. if ((start_reg < PACKET3_SET_SAMPLER_START) ||
  1328. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  1329. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  1330. DRM_ERROR("bad SET_SAMPLER\n");
  1331. return -EINVAL;
  1332. }
  1333. break;
  1334. case PACKET3_NOP:
  1335. break;
  1336. default:
  1337. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1338. return -EINVAL;
  1339. }
  1340. return 0;
  1341. }
  1342. int evergreen_cs_parse(struct radeon_cs_parser *p)
  1343. {
  1344. struct radeon_cs_packet pkt;
  1345. struct evergreen_cs_track *track;
  1346. int r;
  1347. if (p->track == NULL) {
  1348. /* initialize tracker, we are in kms */
  1349. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1350. if (track == NULL)
  1351. return -ENOMEM;
  1352. evergreen_cs_track_init(track);
  1353. track->npipes = p->rdev->config.evergreen.tiling_npipes;
  1354. track->nbanks = p->rdev->config.evergreen.tiling_nbanks;
  1355. track->group_size = p->rdev->config.evergreen.tiling_group_size;
  1356. p->track = track;
  1357. }
  1358. do {
  1359. r = evergreen_cs_packet_parse(p, &pkt, p->idx);
  1360. if (r) {
  1361. kfree(p->track);
  1362. p->track = NULL;
  1363. return r;
  1364. }
  1365. p->idx += pkt.count + 2;
  1366. switch (pkt.type) {
  1367. case PACKET_TYPE0:
  1368. r = evergreen_cs_parse_packet0(p, &pkt);
  1369. break;
  1370. case PACKET_TYPE2:
  1371. break;
  1372. case PACKET_TYPE3:
  1373. r = evergreen_packet3_check(p, &pkt);
  1374. break;
  1375. default:
  1376. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1377. kfree(p->track);
  1378. p->track = NULL;
  1379. return -EINVAL;
  1380. }
  1381. if (r) {
  1382. kfree(p->track);
  1383. p->track = NULL;
  1384. return r;
  1385. }
  1386. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1387. #if 0
  1388. for (r = 0; r < p->ib->length_dw; r++) {
  1389. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  1390. mdelay(1);
  1391. }
  1392. #endif
  1393. kfree(p->track);
  1394. p->track = NULL;
  1395. return 0;
  1396. }