r600_cs.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. /*
  2. * Copyright 2008 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 "r600d.h"
  31. #include "r600_reg_safe.h"
  32. static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser *p,
  33. struct radeon_cs_reloc **cs_reloc);
  34. static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser *p,
  35. struct radeon_cs_reloc **cs_reloc);
  36. typedef int (*next_reloc_t)(struct radeon_cs_parser*, struct radeon_cs_reloc**);
  37. static next_reloc_t r600_cs_packet_next_reloc = &r600_cs_packet_next_reloc_mm;
  38. extern void r600_cs_legacy_get_tiling_conf(struct drm_device *dev, u32 *npipes, u32 *nbanks, u32 *group_size);
  39. struct r600_cs_track {
  40. /* configuration we miror so that we use same code btw kms/ums */
  41. u32 group_size;
  42. u32 nbanks;
  43. u32 npipes;
  44. /* value we track */
  45. u32 sq_config;
  46. u32 nsamples;
  47. u32 cb_color_base_last[8];
  48. struct radeon_bo *cb_color_bo[8];
  49. u32 cb_color_bo_offset[8];
  50. struct radeon_bo *cb_color_frag_bo[8];
  51. struct radeon_bo *cb_color_tile_bo[8];
  52. u32 cb_color_info[8];
  53. u32 cb_color_size_idx[8];
  54. u32 cb_target_mask;
  55. u32 cb_shader_mask;
  56. u32 cb_color_size[8];
  57. u32 vgt_strmout_en;
  58. u32 vgt_strmout_buffer_en;
  59. u32 db_depth_control;
  60. u32 db_depth_info;
  61. u32 db_depth_size_idx;
  62. u32 db_depth_view;
  63. u32 db_depth_size;
  64. u32 db_offset;
  65. struct radeon_bo *db_bo;
  66. };
  67. static inline int r600_bpe_from_format(u32 *bpe, u32 format)
  68. {
  69. switch (format) {
  70. case V_038004_COLOR_8:
  71. case V_038004_COLOR_4_4:
  72. case V_038004_COLOR_3_3_2:
  73. case V_038004_FMT_1:
  74. *bpe = 1;
  75. break;
  76. case V_038004_COLOR_16:
  77. case V_038004_COLOR_16_FLOAT:
  78. case V_038004_COLOR_8_8:
  79. case V_038004_COLOR_5_6_5:
  80. case V_038004_COLOR_6_5_5:
  81. case V_038004_COLOR_1_5_5_5:
  82. case V_038004_COLOR_4_4_4_4:
  83. case V_038004_COLOR_5_5_5_1:
  84. *bpe = 2;
  85. break;
  86. case V_038004_FMT_8_8_8:
  87. *bpe = 3;
  88. break;
  89. case V_038004_COLOR_32:
  90. case V_038004_COLOR_32_FLOAT:
  91. case V_038004_COLOR_16_16:
  92. case V_038004_COLOR_16_16_FLOAT:
  93. case V_038004_COLOR_8_24:
  94. case V_038004_COLOR_8_24_FLOAT:
  95. case V_038004_COLOR_24_8:
  96. case V_038004_COLOR_24_8_FLOAT:
  97. case V_038004_COLOR_10_11_11:
  98. case V_038004_COLOR_10_11_11_FLOAT:
  99. case V_038004_COLOR_11_11_10:
  100. case V_038004_COLOR_11_11_10_FLOAT:
  101. case V_038004_COLOR_2_10_10_10:
  102. case V_038004_COLOR_8_8_8_8:
  103. case V_038004_COLOR_10_10_10_2:
  104. case V_038004_FMT_5_9_9_9_SHAREDEXP:
  105. case V_038004_FMT_32_AS_8:
  106. case V_038004_FMT_32_AS_8_8:
  107. *bpe = 4;
  108. break;
  109. case V_038004_COLOR_X24_8_32_FLOAT:
  110. case V_038004_COLOR_32_32:
  111. case V_038004_COLOR_32_32_FLOAT:
  112. case V_038004_COLOR_16_16_16_16:
  113. case V_038004_COLOR_16_16_16_16_FLOAT:
  114. *bpe = 8;
  115. break;
  116. case V_038004_FMT_16_16_16:
  117. case V_038004_FMT_16_16_16_FLOAT:
  118. *bpe = 6;
  119. break;
  120. case V_038004_FMT_32_32_32:
  121. case V_038004_FMT_32_32_32_FLOAT:
  122. *bpe = 12;
  123. break;
  124. case V_038004_COLOR_32_32_32_32:
  125. case V_038004_COLOR_32_32_32_32_FLOAT:
  126. *bpe = 16;
  127. break;
  128. case V_038004_FMT_GB_GR:
  129. case V_038004_FMT_BG_RG:
  130. case V_038004_COLOR_INVALID:
  131. *bpe = 16;
  132. return -EINVAL;
  133. }
  134. return 0;
  135. }
  136. static void r600_cs_track_init(struct r600_cs_track *track)
  137. {
  138. int i;
  139. /* assume DX9 mode */
  140. track->sq_config = DX9_CONSTS;
  141. for (i = 0; i < 8; i++) {
  142. track->cb_color_base_last[i] = 0;
  143. track->cb_color_size[i] = 0;
  144. track->cb_color_size_idx[i] = 0;
  145. track->cb_color_info[i] = 0;
  146. track->cb_color_bo[i] = NULL;
  147. track->cb_color_bo_offset[i] = 0xFFFFFFFF;
  148. }
  149. track->cb_target_mask = 0xFFFFFFFF;
  150. track->cb_shader_mask = 0xFFFFFFFF;
  151. track->db_bo = NULL;
  152. /* assume the biggest format and that htile is enabled */
  153. track->db_depth_info = 7 | (1 << 25);
  154. track->db_depth_view = 0xFFFFC000;
  155. track->db_depth_size = 0xFFFFFFFF;
  156. track->db_depth_size_idx = 0;
  157. track->db_depth_control = 0xFFFFFFFF;
  158. }
  159. static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
  160. {
  161. struct r600_cs_track *track = p->track;
  162. u32 bpe = 0, pitch, slice_tile_max, size, tmp, height;
  163. volatile u32 *ib = p->ib->ptr;
  164. if (G_0280A0_TILE_MODE(track->cb_color_info[i])) {
  165. dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n");
  166. return -EINVAL;
  167. }
  168. size = radeon_bo_size(track->cb_color_bo[i]);
  169. if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) {
  170. dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n",
  171. __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]),
  172. i, track->cb_color_info[i]);
  173. return -EINVAL;
  174. }
  175. pitch = (G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1) << 3;
  176. slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1;
  177. if (!pitch) {
  178. dev_warn(p->dev, "%s:%d cb pitch (%d) for %d invalid (0x%08X)\n",
  179. __func__, __LINE__, pitch, i, track->cb_color_size[i]);
  180. return -EINVAL;
  181. }
  182. height = size / (pitch * bpe);
  183. if (height > 8192)
  184. height = 8192;
  185. switch (G_0280A0_ARRAY_MODE(track->cb_color_info[i])) {
  186. case V_0280A0_ARRAY_LINEAR_GENERAL:
  187. case V_0280A0_ARRAY_LINEAR_ALIGNED:
  188. if (pitch & 0x3f) {
  189. dev_warn(p->dev, "%s:%d cb pitch (%d x %d = %d) invalid\n",
  190. __func__, __LINE__, pitch, bpe, pitch * bpe);
  191. return -EINVAL;
  192. }
  193. if ((pitch * bpe) & (track->group_size - 1)) {
  194. dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
  195. __func__, __LINE__, pitch);
  196. return -EINVAL;
  197. }
  198. break;
  199. case V_0280A0_ARRAY_1D_TILED_THIN1:
  200. if ((pitch * 8 * bpe * track->nsamples) & (track->group_size - 1)) {
  201. dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
  202. __func__, __LINE__, pitch);
  203. return -EINVAL;
  204. }
  205. height &= ~0x7;
  206. if (!height)
  207. height = 8;
  208. break;
  209. case V_0280A0_ARRAY_2D_TILED_THIN1:
  210. if (pitch & ((8 * track->nbanks) - 1)) {
  211. dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
  212. __func__, __LINE__, pitch);
  213. return -EINVAL;
  214. }
  215. tmp = pitch * 8 * bpe * track->nsamples;
  216. tmp = tmp / track->nbanks;
  217. if (tmp & (track->group_size - 1)) {
  218. dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n",
  219. __func__, __LINE__, pitch);
  220. return -EINVAL;
  221. }
  222. height &= ~((16 * track->npipes) - 1);
  223. if (!height)
  224. height = 16 * track->npipes;
  225. break;
  226. default:
  227. dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__,
  228. G_0280A0_ARRAY_MODE(track->cb_color_info[i]), i,
  229. track->cb_color_info[i]);
  230. return -EINVAL;
  231. }
  232. /* check offset */
  233. tmp = height * pitch;
  234. if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) {
  235. dev_warn(p->dev, "%s offset[%d] %d to big\n", __func__, i, track->cb_color_bo_offset[i]);
  236. return -EINVAL;
  237. }
  238. /* limit max tile */
  239. tmp = (height * pitch) >> 6;
  240. if (tmp < slice_tile_max)
  241. slice_tile_max = tmp;
  242. tmp = S_028060_PITCH_TILE_MAX((pitch >> 3) - 1) |
  243. S_028060_SLICE_TILE_MAX(slice_tile_max - 1);
  244. ib[track->cb_color_size_idx[i]] = tmp;
  245. return 0;
  246. }
  247. static int r600_cs_track_check(struct radeon_cs_parser *p)
  248. {
  249. struct r600_cs_track *track = p->track;
  250. u32 tmp;
  251. int r, i;
  252. volatile u32 *ib = p->ib->ptr;
  253. /* on legacy kernel we don't perform advanced check */
  254. if (p->rdev == NULL)
  255. return 0;
  256. /* we don't support out buffer yet */
  257. if (track->vgt_strmout_en || track->vgt_strmout_buffer_en) {
  258. dev_warn(p->dev, "this kernel doesn't support SMX output buffer\n");
  259. return -EINVAL;
  260. }
  261. /* check that we have a cb for each enabled target, we don't check
  262. * shader_mask because it seems mesa isn't always setting it :(
  263. */
  264. tmp = track->cb_target_mask;
  265. for (i = 0; i < 8; i++) {
  266. if ((tmp >> (i * 4)) & 0xF) {
  267. /* at least one component is enabled */
  268. if (track->cb_color_bo[i] == NULL) {
  269. dev_warn(p->dev, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
  270. __func__, __LINE__, track->cb_target_mask, track->cb_shader_mask, i);
  271. return -EINVAL;
  272. }
  273. /* perform rewrite of CB_COLOR[0-7]_SIZE */
  274. r = r600_cs_track_validate_cb(p, i);
  275. if (r)
  276. return r;
  277. }
  278. }
  279. /* Check depth buffer */
  280. if (G_028800_STENCIL_ENABLE(track->db_depth_control) ||
  281. G_028800_Z_ENABLE(track->db_depth_control)) {
  282. u32 nviews, bpe, ntiles;
  283. if (track->db_bo == NULL) {
  284. dev_warn(p->dev, "z/stencil with no depth buffer\n");
  285. return -EINVAL;
  286. }
  287. if (G_028010_TILE_SURFACE_ENABLE(track->db_depth_info)) {
  288. dev_warn(p->dev, "this kernel doesn't support z/stencil htile\n");
  289. return -EINVAL;
  290. }
  291. switch (G_028010_FORMAT(track->db_depth_info)) {
  292. case V_028010_DEPTH_16:
  293. bpe = 2;
  294. break;
  295. case V_028010_DEPTH_X8_24:
  296. case V_028010_DEPTH_8_24:
  297. case V_028010_DEPTH_X8_24_FLOAT:
  298. case V_028010_DEPTH_8_24_FLOAT:
  299. case V_028010_DEPTH_32_FLOAT:
  300. bpe = 4;
  301. break;
  302. case V_028010_DEPTH_X24_8_32_FLOAT:
  303. bpe = 8;
  304. break;
  305. default:
  306. dev_warn(p->dev, "z/stencil with invalid format %d\n", G_028010_FORMAT(track->db_depth_info));
  307. return -EINVAL;
  308. }
  309. if ((track->db_depth_size & 0xFFFFFC00) == 0xFFFFFC00) {
  310. if (!track->db_depth_size_idx) {
  311. dev_warn(p->dev, "z/stencil buffer size not set\n");
  312. return -EINVAL;
  313. }
  314. printk_once(KERN_WARNING "You have old & broken userspace please consider updating mesa\n");
  315. tmp = radeon_bo_size(track->db_bo) - track->db_offset;
  316. tmp = (tmp / bpe) >> 6;
  317. if (!tmp) {
  318. dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %ld)\n",
  319. track->db_depth_size, bpe, track->db_offset,
  320. radeon_bo_size(track->db_bo));
  321. return -EINVAL;
  322. }
  323. ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF);
  324. } else {
  325. ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1;
  326. nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1;
  327. tmp = ntiles * bpe * 64 * nviews;
  328. if ((tmp + track->db_offset) > radeon_bo_size(track->db_bo)) {
  329. dev_warn(p->dev, "z/stencil buffer too small (0x%08X %d %d %d -> %d have %ld)\n",
  330. track->db_depth_size, ntiles, nviews, bpe, tmp + track->db_offset,
  331. radeon_bo_size(track->db_bo));
  332. return -EINVAL;
  333. }
  334. }
  335. }
  336. return 0;
  337. }
  338. /**
  339. * r600_cs_packet_parse() - parse cp packet and point ib index to next packet
  340. * @parser: parser structure holding parsing context.
  341. * @pkt: where to store packet informations
  342. *
  343. * Assume that chunk_ib_index is properly set. Will return -EINVAL
  344. * if packet is bigger than remaining ib size. or if packets is unknown.
  345. **/
  346. int r600_cs_packet_parse(struct radeon_cs_parser *p,
  347. struct radeon_cs_packet *pkt,
  348. unsigned idx)
  349. {
  350. struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
  351. uint32_t header;
  352. if (idx >= ib_chunk->length_dw) {
  353. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  354. idx, ib_chunk->length_dw);
  355. return -EINVAL;
  356. }
  357. header = radeon_get_ib_value(p, idx);
  358. pkt->idx = idx;
  359. pkt->type = CP_PACKET_GET_TYPE(header);
  360. pkt->count = CP_PACKET_GET_COUNT(header);
  361. pkt->one_reg_wr = 0;
  362. switch (pkt->type) {
  363. case PACKET_TYPE0:
  364. pkt->reg = CP_PACKET0_GET_REG(header);
  365. break;
  366. case PACKET_TYPE3:
  367. pkt->opcode = CP_PACKET3_GET_OPCODE(header);
  368. break;
  369. case PACKET_TYPE2:
  370. pkt->count = -1;
  371. break;
  372. default:
  373. DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
  374. return -EINVAL;
  375. }
  376. if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
  377. DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
  378. pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
  379. return -EINVAL;
  380. }
  381. return 0;
  382. }
  383. /**
  384. * r600_cs_packet_next_reloc_mm() - parse next packet which should be reloc packet3
  385. * @parser: parser structure holding parsing context.
  386. * @data: pointer to relocation data
  387. * @offset_start: starting offset
  388. * @offset_mask: offset mask (to align start offset on)
  389. * @reloc: reloc informations
  390. *
  391. * Check next packet is relocation packet3, do bo validation and compute
  392. * GPU offset using the provided start.
  393. **/
  394. static int r600_cs_packet_next_reloc_mm(struct radeon_cs_parser *p,
  395. struct radeon_cs_reloc **cs_reloc)
  396. {
  397. struct radeon_cs_chunk *relocs_chunk;
  398. struct radeon_cs_packet p3reloc;
  399. unsigned idx;
  400. int r;
  401. if (p->chunk_relocs_idx == -1) {
  402. DRM_ERROR("No relocation chunk !\n");
  403. return -EINVAL;
  404. }
  405. *cs_reloc = NULL;
  406. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  407. r = r600_cs_packet_parse(p, &p3reloc, p->idx);
  408. if (r) {
  409. return r;
  410. }
  411. p->idx += p3reloc.count + 2;
  412. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  413. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  414. p3reloc.idx);
  415. return -EINVAL;
  416. }
  417. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  418. if (idx >= relocs_chunk->length_dw) {
  419. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  420. idx, relocs_chunk->length_dw);
  421. return -EINVAL;
  422. }
  423. /* FIXME: we assume reloc size is 4 dwords */
  424. *cs_reloc = p->relocs_ptr[(idx / 4)];
  425. return 0;
  426. }
  427. /**
  428. * r600_cs_packet_next_reloc_nomm() - parse next packet which should be reloc packet3
  429. * @parser: parser structure holding parsing context.
  430. * @data: pointer to relocation data
  431. * @offset_start: starting offset
  432. * @offset_mask: offset mask (to align start offset on)
  433. * @reloc: reloc informations
  434. *
  435. * Check next packet is relocation packet3, do bo validation and compute
  436. * GPU offset using the provided start.
  437. **/
  438. static int r600_cs_packet_next_reloc_nomm(struct radeon_cs_parser *p,
  439. struct radeon_cs_reloc **cs_reloc)
  440. {
  441. struct radeon_cs_chunk *relocs_chunk;
  442. struct radeon_cs_packet p3reloc;
  443. unsigned idx;
  444. int r;
  445. if (p->chunk_relocs_idx == -1) {
  446. DRM_ERROR("No relocation chunk !\n");
  447. return -EINVAL;
  448. }
  449. *cs_reloc = NULL;
  450. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  451. r = r600_cs_packet_parse(p, &p3reloc, p->idx);
  452. if (r) {
  453. return r;
  454. }
  455. p->idx += p3reloc.count + 2;
  456. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  457. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  458. p3reloc.idx);
  459. return -EINVAL;
  460. }
  461. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  462. if (idx >= relocs_chunk->length_dw) {
  463. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  464. idx, relocs_chunk->length_dw);
  465. return -EINVAL;
  466. }
  467. *cs_reloc = p->relocs;
  468. (*cs_reloc)->lobj.gpu_offset = (u64)relocs_chunk->kdata[idx + 3] << 32;
  469. (*cs_reloc)->lobj.gpu_offset |= relocs_chunk->kdata[idx + 0];
  470. return 0;
  471. }
  472. /**
  473. * r600_cs_packet_next_is_pkt3_nop() - test if next packet is packet3 nop for reloc
  474. * @parser: parser structure holding parsing context.
  475. *
  476. * Check next packet is relocation packet3, do bo validation and compute
  477. * GPU offset using the provided start.
  478. **/
  479. static inline int r600_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p)
  480. {
  481. struct radeon_cs_packet p3reloc;
  482. int r;
  483. r = r600_cs_packet_parse(p, &p3reloc, p->idx);
  484. if (r) {
  485. return 0;
  486. }
  487. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  488. return 0;
  489. }
  490. return 1;
  491. }
  492. /**
  493. * r600_cs_packet_next_vline() - parse userspace VLINE packet
  494. * @parser: parser structure holding parsing context.
  495. *
  496. * Userspace sends a special sequence for VLINE waits.
  497. * PACKET0 - VLINE_START_END + value
  498. * PACKET3 - WAIT_REG_MEM poll vline status reg
  499. * RELOC (P3) - crtc_id in reloc.
  500. *
  501. * This function parses this and relocates the VLINE START END
  502. * and WAIT_REG_MEM packets to the correct crtc.
  503. * It also detects a switched off crtc and nulls out the
  504. * wait in that case.
  505. */
  506. static int r600_cs_packet_parse_vline(struct radeon_cs_parser *p)
  507. {
  508. struct drm_mode_object *obj;
  509. struct drm_crtc *crtc;
  510. struct radeon_crtc *radeon_crtc;
  511. struct radeon_cs_packet p3reloc, wait_reg_mem;
  512. int crtc_id;
  513. int r;
  514. uint32_t header, h_idx, reg, wait_reg_mem_info;
  515. volatile uint32_t *ib;
  516. ib = p->ib->ptr;
  517. /* parse the WAIT_REG_MEM */
  518. r = r600_cs_packet_parse(p, &wait_reg_mem, p->idx);
  519. if (r)
  520. return r;
  521. /* check its a WAIT_REG_MEM */
  522. if (wait_reg_mem.type != PACKET_TYPE3 ||
  523. wait_reg_mem.opcode != PACKET3_WAIT_REG_MEM) {
  524. DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
  525. r = -EINVAL;
  526. return r;
  527. }
  528. wait_reg_mem_info = radeon_get_ib_value(p, wait_reg_mem.idx + 1);
  529. /* bit 4 is reg (0) or mem (1) */
  530. if (wait_reg_mem_info & 0x10) {
  531. DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
  532. r = -EINVAL;
  533. return r;
  534. }
  535. /* waiting for value to be equal */
  536. if ((wait_reg_mem_info & 0x7) != 0x3) {
  537. DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
  538. r = -EINVAL;
  539. return r;
  540. }
  541. if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != AVIVO_D1MODE_VLINE_STATUS) {
  542. DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
  543. r = -EINVAL;
  544. return r;
  545. }
  546. if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != AVIVO_D1MODE_VLINE_STAT) {
  547. DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
  548. r = -EINVAL;
  549. return r;
  550. }
  551. /* jump over the NOP */
  552. r = r600_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
  553. if (r)
  554. return r;
  555. h_idx = p->idx - 2;
  556. p->idx += wait_reg_mem.count + 2;
  557. p->idx += p3reloc.count + 2;
  558. header = radeon_get_ib_value(p, h_idx);
  559. crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
  560. reg = CP_PACKET0_GET_REG(header);
  561. mutex_lock(&p->rdev->ddev->mode_config.mutex);
  562. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  563. if (!obj) {
  564. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  565. r = -EINVAL;
  566. goto out;
  567. }
  568. crtc = obj_to_crtc(obj);
  569. radeon_crtc = to_radeon_crtc(crtc);
  570. crtc_id = radeon_crtc->crtc_id;
  571. if (!crtc->enabled) {
  572. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  573. ib[h_idx + 2] = PACKET2(0);
  574. ib[h_idx + 3] = PACKET2(0);
  575. ib[h_idx + 4] = PACKET2(0);
  576. ib[h_idx + 5] = PACKET2(0);
  577. ib[h_idx + 6] = PACKET2(0);
  578. ib[h_idx + 7] = PACKET2(0);
  579. ib[h_idx + 8] = PACKET2(0);
  580. } else if (crtc_id == 1) {
  581. switch (reg) {
  582. case AVIVO_D1MODE_VLINE_START_END:
  583. header &= ~R600_CP_PACKET0_REG_MASK;
  584. header |= AVIVO_D2MODE_VLINE_START_END >> 2;
  585. break;
  586. default:
  587. DRM_ERROR("unknown crtc reloc\n");
  588. r = -EINVAL;
  589. goto out;
  590. }
  591. ib[h_idx] = header;
  592. ib[h_idx + 4] = AVIVO_D2MODE_VLINE_STATUS >> 2;
  593. }
  594. out:
  595. mutex_unlock(&p->rdev->ddev->mode_config.mutex);
  596. return r;
  597. }
  598. static int r600_packet0_check(struct radeon_cs_parser *p,
  599. struct radeon_cs_packet *pkt,
  600. unsigned idx, unsigned reg)
  601. {
  602. int r;
  603. switch (reg) {
  604. case AVIVO_D1MODE_VLINE_START_END:
  605. r = r600_cs_packet_parse_vline(p);
  606. if (r) {
  607. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  608. idx, reg);
  609. return r;
  610. }
  611. break;
  612. default:
  613. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  614. reg, idx);
  615. return -EINVAL;
  616. }
  617. return 0;
  618. }
  619. static int r600_cs_parse_packet0(struct radeon_cs_parser *p,
  620. struct radeon_cs_packet *pkt)
  621. {
  622. unsigned reg, i;
  623. unsigned idx;
  624. int r;
  625. idx = pkt->idx + 1;
  626. reg = pkt->reg;
  627. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  628. r = r600_packet0_check(p, pkt, idx, reg);
  629. if (r) {
  630. return r;
  631. }
  632. }
  633. return 0;
  634. }
  635. /**
  636. * r600_cs_check_reg() - check if register is authorized or not
  637. * @parser: parser structure holding parsing context
  638. * @reg: register we are testing
  639. * @idx: index into the cs buffer
  640. *
  641. * This function will test against r600_reg_safe_bm and return 0
  642. * if register is safe. If register is not flag as safe this function
  643. * will test it against a list of register needind special handling.
  644. */
  645. static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  646. {
  647. struct r600_cs_track *track = (struct r600_cs_track *)p->track;
  648. struct radeon_cs_reloc *reloc;
  649. u32 last_reg = ARRAY_SIZE(r600_reg_safe_bm);
  650. u32 m, i, tmp, *ib;
  651. int r;
  652. i = (reg >> 7);
  653. if (i > last_reg) {
  654. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  655. return -EINVAL;
  656. }
  657. m = 1 << ((reg >> 2) & 31);
  658. if (!(r600_reg_safe_bm[i] & m))
  659. return 0;
  660. ib = p->ib->ptr;
  661. switch (reg) {
  662. /* force following reg to 0 in an attemp to disable out buffer
  663. * which will need us to better understand how it works to perform
  664. * security check on it (Jerome)
  665. */
  666. case R_0288A8_SQ_ESGS_RING_ITEMSIZE:
  667. case R_008C44_SQ_ESGS_RING_SIZE:
  668. case R_0288B0_SQ_ESTMP_RING_ITEMSIZE:
  669. case R_008C54_SQ_ESTMP_RING_SIZE:
  670. case R_0288C0_SQ_FBUF_RING_ITEMSIZE:
  671. case R_008C74_SQ_FBUF_RING_SIZE:
  672. case R_0288B4_SQ_GSTMP_RING_ITEMSIZE:
  673. case R_008C5C_SQ_GSTMP_RING_SIZE:
  674. case R_0288AC_SQ_GSVS_RING_ITEMSIZE:
  675. case R_008C4C_SQ_GSVS_RING_SIZE:
  676. case R_0288BC_SQ_PSTMP_RING_ITEMSIZE:
  677. case R_008C6C_SQ_PSTMP_RING_SIZE:
  678. case R_0288C4_SQ_REDUC_RING_ITEMSIZE:
  679. case R_008C7C_SQ_REDUC_RING_SIZE:
  680. case R_0288B8_SQ_VSTMP_RING_ITEMSIZE:
  681. case R_008C64_SQ_VSTMP_RING_SIZE:
  682. case R_0288C8_SQ_GS_VERT_ITEMSIZE:
  683. /* get value to populate the IB don't remove */
  684. tmp =radeon_get_ib_value(p, idx);
  685. ib[idx] = 0;
  686. break;
  687. case SQ_CONFIG:
  688. track->sq_config = radeon_get_ib_value(p, idx);
  689. break;
  690. case R_028800_DB_DEPTH_CONTROL:
  691. track->db_depth_control = radeon_get_ib_value(p, idx);
  692. break;
  693. case R_028010_DB_DEPTH_INFO:
  694. track->db_depth_info = radeon_get_ib_value(p, idx);
  695. break;
  696. case R_028004_DB_DEPTH_VIEW:
  697. track->db_depth_view = radeon_get_ib_value(p, idx);
  698. break;
  699. case R_028000_DB_DEPTH_SIZE:
  700. track->db_depth_size = radeon_get_ib_value(p, idx);
  701. track->db_depth_size_idx = idx;
  702. break;
  703. case R_028AB0_VGT_STRMOUT_EN:
  704. track->vgt_strmout_en = radeon_get_ib_value(p, idx);
  705. break;
  706. case R_028B20_VGT_STRMOUT_BUFFER_EN:
  707. track->vgt_strmout_buffer_en = radeon_get_ib_value(p, idx);
  708. break;
  709. case R_028238_CB_TARGET_MASK:
  710. track->cb_target_mask = radeon_get_ib_value(p, idx);
  711. break;
  712. case R_02823C_CB_SHADER_MASK:
  713. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  714. break;
  715. case R_028C04_PA_SC_AA_CONFIG:
  716. tmp = G_028C04_MSAA_NUM_SAMPLES(radeon_get_ib_value(p, idx));
  717. track->nsamples = 1 << tmp;
  718. break;
  719. case R_0280A0_CB_COLOR0_INFO:
  720. case R_0280A4_CB_COLOR1_INFO:
  721. case R_0280A8_CB_COLOR2_INFO:
  722. case R_0280AC_CB_COLOR3_INFO:
  723. case R_0280B0_CB_COLOR4_INFO:
  724. case R_0280B4_CB_COLOR5_INFO:
  725. case R_0280B8_CB_COLOR6_INFO:
  726. case R_0280BC_CB_COLOR7_INFO:
  727. tmp = (reg - R_0280A0_CB_COLOR0_INFO) / 4;
  728. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  729. break;
  730. case R_028060_CB_COLOR0_SIZE:
  731. case R_028064_CB_COLOR1_SIZE:
  732. case R_028068_CB_COLOR2_SIZE:
  733. case R_02806C_CB_COLOR3_SIZE:
  734. case R_028070_CB_COLOR4_SIZE:
  735. case R_028074_CB_COLOR5_SIZE:
  736. case R_028078_CB_COLOR6_SIZE:
  737. case R_02807C_CB_COLOR7_SIZE:
  738. tmp = (reg - R_028060_CB_COLOR0_SIZE) / 4;
  739. track->cb_color_size[tmp] = radeon_get_ib_value(p, idx);
  740. track->cb_color_size_idx[tmp] = idx;
  741. break;
  742. /* This register were added late, there is userspace
  743. * which does provide relocation for those but set
  744. * 0 offset. In order to avoid breaking old userspace
  745. * we detect this and set address to point to last
  746. * CB_COLOR0_BASE, note that if userspace doesn't set
  747. * CB_COLOR0_BASE before this register we will report
  748. * error. Old userspace always set CB_COLOR0_BASE
  749. * before any of this.
  750. */
  751. case R_0280E0_CB_COLOR0_FRAG:
  752. case R_0280E4_CB_COLOR1_FRAG:
  753. case R_0280E8_CB_COLOR2_FRAG:
  754. case R_0280EC_CB_COLOR3_FRAG:
  755. case R_0280F0_CB_COLOR4_FRAG:
  756. case R_0280F4_CB_COLOR5_FRAG:
  757. case R_0280F8_CB_COLOR6_FRAG:
  758. case R_0280FC_CB_COLOR7_FRAG:
  759. tmp = (reg - R_0280E0_CB_COLOR0_FRAG) / 4;
  760. if (!r600_cs_packet_next_is_pkt3_nop(p)) {
  761. if (!track->cb_color_base_last[tmp]) {
  762. dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
  763. return -EINVAL;
  764. }
  765. ib[idx] = track->cb_color_base_last[tmp];
  766. printk_once(KERN_WARNING "You have old & broken userspace "
  767. "please consider updating mesa & xf86-video-ati\n");
  768. track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp];
  769. } else {
  770. r = r600_cs_packet_next_reloc(p, &reloc);
  771. if (r) {
  772. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  773. return -EINVAL;
  774. }
  775. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  776. track->cb_color_frag_bo[tmp] = reloc->robj;
  777. }
  778. break;
  779. case R_0280C0_CB_COLOR0_TILE:
  780. case R_0280C4_CB_COLOR1_TILE:
  781. case R_0280C8_CB_COLOR2_TILE:
  782. case R_0280CC_CB_COLOR3_TILE:
  783. case R_0280D0_CB_COLOR4_TILE:
  784. case R_0280D4_CB_COLOR5_TILE:
  785. case R_0280D8_CB_COLOR6_TILE:
  786. case R_0280DC_CB_COLOR7_TILE:
  787. tmp = (reg - R_0280C0_CB_COLOR0_TILE) / 4;
  788. if (!r600_cs_packet_next_is_pkt3_nop(p)) {
  789. if (!track->cb_color_base_last[tmp]) {
  790. dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
  791. return -EINVAL;
  792. }
  793. ib[idx] = track->cb_color_base_last[tmp];
  794. printk_once(KERN_WARNING "You have old & broken userspace "
  795. "please consider updating mesa & xf86-video-ati\n");
  796. track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp];
  797. } else {
  798. r = r600_cs_packet_next_reloc(p, &reloc);
  799. if (r) {
  800. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  801. return -EINVAL;
  802. }
  803. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  804. track->cb_color_tile_bo[tmp] = reloc->robj;
  805. }
  806. break;
  807. case CB_COLOR0_BASE:
  808. case CB_COLOR1_BASE:
  809. case CB_COLOR2_BASE:
  810. case CB_COLOR3_BASE:
  811. case CB_COLOR4_BASE:
  812. case CB_COLOR5_BASE:
  813. case CB_COLOR6_BASE:
  814. case CB_COLOR7_BASE:
  815. r = r600_cs_packet_next_reloc(p, &reloc);
  816. if (r) {
  817. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  818. "0x%04X\n", reg);
  819. return -EINVAL;
  820. }
  821. tmp = (reg - CB_COLOR0_BASE) / 4;
  822. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  823. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  824. track->cb_color_base_last[tmp] = ib[idx];
  825. track->cb_color_bo[tmp] = reloc->robj;
  826. break;
  827. case DB_DEPTH_BASE:
  828. r = r600_cs_packet_next_reloc(p, &reloc);
  829. if (r) {
  830. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  831. "0x%04X\n", reg);
  832. return -EINVAL;
  833. }
  834. track->db_offset = radeon_get_ib_value(p, idx);
  835. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  836. track->db_bo = reloc->robj;
  837. break;
  838. case DB_HTILE_DATA_BASE:
  839. case SQ_PGM_START_FS:
  840. case SQ_PGM_START_ES:
  841. case SQ_PGM_START_VS:
  842. case SQ_PGM_START_GS:
  843. case SQ_PGM_START_PS:
  844. case SQ_ALU_CONST_CACHE_GS_0:
  845. case SQ_ALU_CONST_CACHE_GS_1:
  846. case SQ_ALU_CONST_CACHE_GS_2:
  847. case SQ_ALU_CONST_CACHE_GS_3:
  848. case SQ_ALU_CONST_CACHE_GS_4:
  849. case SQ_ALU_CONST_CACHE_GS_5:
  850. case SQ_ALU_CONST_CACHE_GS_6:
  851. case SQ_ALU_CONST_CACHE_GS_7:
  852. case SQ_ALU_CONST_CACHE_GS_8:
  853. case SQ_ALU_CONST_CACHE_GS_9:
  854. case SQ_ALU_CONST_CACHE_GS_10:
  855. case SQ_ALU_CONST_CACHE_GS_11:
  856. case SQ_ALU_CONST_CACHE_GS_12:
  857. case SQ_ALU_CONST_CACHE_GS_13:
  858. case SQ_ALU_CONST_CACHE_GS_14:
  859. case SQ_ALU_CONST_CACHE_GS_15:
  860. case SQ_ALU_CONST_CACHE_PS_0:
  861. case SQ_ALU_CONST_CACHE_PS_1:
  862. case SQ_ALU_CONST_CACHE_PS_2:
  863. case SQ_ALU_CONST_CACHE_PS_3:
  864. case SQ_ALU_CONST_CACHE_PS_4:
  865. case SQ_ALU_CONST_CACHE_PS_5:
  866. case SQ_ALU_CONST_CACHE_PS_6:
  867. case SQ_ALU_CONST_CACHE_PS_7:
  868. case SQ_ALU_CONST_CACHE_PS_8:
  869. case SQ_ALU_CONST_CACHE_PS_9:
  870. case SQ_ALU_CONST_CACHE_PS_10:
  871. case SQ_ALU_CONST_CACHE_PS_11:
  872. case SQ_ALU_CONST_CACHE_PS_12:
  873. case SQ_ALU_CONST_CACHE_PS_13:
  874. case SQ_ALU_CONST_CACHE_PS_14:
  875. case SQ_ALU_CONST_CACHE_PS_15:
  876. case SQ_ALU_CONST_CACHE_VS_0:
  877. case SQ_ALU_CONST_CACHE_VS_1:
  878. case SQ_ALU_CONST_CACHE_VS_2:
  879. case SQ_ALU_CONST_CACHE_VS_3:
  880. case SQ_ALU_CONST_CACHE_VS_4:
  881. case SQ_ALU_CONST_CACHE_VS_5:
  882. case SQ_ALU_CONST_CACHE_VS_6:
  883. case SQ_ALU_CONST_CACHE_VS_7:
  884. case SQ_ALU_CONST_CACHE_VS_8:
  885. case SQ_ALU_CONST_CACHE_VS_9:
  886. case SQ_ALU_CONST_CACHE_VS_10:
  887. case SQ_ALU_CONST_CACHE_VS_11:
  888. case SQ_ALU_CONST_CACHE_VS_12:
  889. case SQ_ALU_CONST_CACHE_VS_13:
  890. case SQ_ALU_CONST_CACHE_VS_14:
  891. case SQ_ALU_CONST_CACHE_VS_15:
  892. r = r600_cs_packet_next_reloc(p, &reloc);
  893. if (r) {
  894. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  895. "0x%04X\n", reg);
  896. return -EINVAL;
  897. }
  898. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  899. break;
  900. default:
  901. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  902. return -EINVAL;
  903. }
  904. return 0;
  905. }
  906. static inline unsigned minify(unsigned size, unsigned levels)
  907. {
  908. size = size >> levels;
  909. if (size < 1)
  910. size = 1;
  911. return size;
  912. }
  913. static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels,
  914. unsigned w0, unsigned h0, unsigned d0, unsigned bpe,
  915. unsigned *l0_size, unsigned *mipmap_size)
  916. {
  917. unsigned offset, i, level, face;
  918. unsigned width, height, depth, rowstride, size;
  919. w0 = minify(w0, 0);
  920. h0 = minify(h0, 0);
  921. d0 = minify(d0, 0);
  922. for(i = 0, offset = 0, level = blevel; i < nlevels; i++, level++) {
  923. width = minify(w0, i);
  924. height = minify(h0, i);
  925. depth = minify(d0, i);
  926. for(face = 0; face < nfaces; face++) {
  927. rowstride = ((width * bpe) + 255) & ~255;
  928. size = height * rowstride * depth;
  929. offset += size;
  930. offset = (offset + 0x1f) & ~0x1f;
  931. }
  932. }
  933. *l0_size = (((w0 * bpe) + 255) & ~255) * h0 * d0;
  934. *mipmap_size = offset;
  935. if (!blevel)
  936. *mipmap_size -= *l0_size;
  937. if (!nlevels)
  938. *mipmap_size = *l0_size;
  939. }
  940. /**
  941. * r600_check_texture_resource() - check if register is authorized or not
  942. * @p: parser structure holding parsing context
  943. * @idx: index into the cs buffer
  944. * @texture: texture's bo structure
  945. * @mipmap: mipmap's bo structure
  946. *
  947. * This function will check that the resource has valid field and that
  948. * the texture and mipmap bo object are big enough to cover this resource.
  949. */
  950. static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
  951. struct radeon_bo *texture,
  952. struct radeon_bo *mipmap)
  953. {
  954. u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0;
  955. u32 word0, word1, l0_size, mipmap_size;
  956. /* on legacy kernel we don't perform advanced check */
  957. if (p->rdev == NULL)
  958. return 0;
  959. word0 = radeon_get_ib_value(p, idx + 0);
  960. word1 = radeon_get_ib_value(p, idx + 1);
  961. w0 = G_038000_TEX_WIDTH(word0) + 1;
  962. h0 = G_038004_TEX_HEIGHT(word1) + 1;
  963. d0 = G_038004_TEX_DEPTH(word1);
  964. nfaces = 1;
  965. switch (G_038000_DIM(word0)) {
  966. case V_038000_SQ_TEX_DIM_1D:
  967. case V_038000_SQ_TEX_DIM_2D:
  968. case V_038000_SQ_TEX_DIM_3D:
  969. break;
  970. case V_038000_SQ_TEX_DIM_CUBEMAP:
  971. nfaces = 6;
  972. break;
  973. case V_038000_SQ_TEX_DIM_1D_ARRAY:
  974. case V_038000_SQ_TEX_DIM_2D_ARRAY:
  975. case V_038000_SQ_TEX_DIM_2D_MSAA:
  976. case V_038000_SQ_TEX_DIM_2D_ARRAY_MSAA:
  977. default:
  978. dev_warn(p->dev, "this kernel doesn't support %d texture dim\n", G_038000_DIM(word0));
  979. return -EINVAL;
  980. }
  981. if (r600_bpe_from_format(&bpe, G_038004_DATA_FORMAT(word1))) {
  982. dev_warn(p->dev, "%s:%d texture invalid format %d\n",
  983. __func__, __LINE__, G_038004_DATA_FORMAT(word1));
  984. return -EINVAL;
  985. }
  986. word0 = radeon_get_ib_value(p, idx + 4);
  987. word1 = radeon_get_ib_value(p, idx + 5);
  988. blevel = G_038010_BASE_LEVEL(word0);
  989. nlevels = G_038014_LAST_LEVEL(word1);
  990. r600_texture_size(nfaces, blevel, nlevels, w0, h0, d0, bpe, &l0_size, &mipmap_size);
  991. /* using get ib will give us the offset into the texture bo */
  992. word0 = radeon_get_ib_value(p, idx + 2);
  993. if ((l0_size + word0) > radeon_bo_size(texture)) {
  994. dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
  995. w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
  996. return -EINVAL;
  997. }
  998. /* using get ib will give us the offset into the mipmap bo */
  999. word0 = radeon_get_ib_value(p, idx + 3);
  1000. if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
  1001. dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
  1002. w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
  1003. return -EINVAL;
  1004. }
  1005. return 0;
  1006. }
  1007. static int r600_packet3_check(struct radeon_cs_parser *p,
  1008. struct radeon_cs_packet *pkt)
  1009. {
  1010. struct radeon_cs_reloc *reloc;
  1011. struct r600_cs_track *track;
  1012. volatile u32 *ib;
  1013. unsigned idx;
  1014. unsigned i;
  1015. unsigned start_reg, end_reg, reg;
  1016. int r;
  1017. u32 idx_value;
  1018. track = (struct r600_cs_track *)p->track;
  1019. ib = p->ib->ptr;
  1020. idx = pkt->idx + 1;
  1021. idx_value = radeon_get_ib_value(p, idx);
  1022. switch (pkt->opcode) {
  1023. case PACKET3_START_3D_CMDBUF:
  1024. if (p->family >= CHIP_RV770 || pkt->count) {
  1025. DRM_ERROR("bad START_3D\n");
  1026. return -EINVAL;
  1027. }
  1028. break;
  1029. case PACKET3_CONTEXT_CONTROL:
  1030. if (pkt->count != 1) {
  1031. DRM_ERROR("bad CONTEXT_CONTROL\n");
  1032. return -EINVAL;
  1033. }
  1034. break;
  1035. case PACKET3_INDEX_TYPE:
  1036. case PACKET3_NUM_INSTANCES:
  1037. if (pkt->count) {
  1038. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES\n");
  1039. return -EINVAL;
  1040. }
  1041. break;
  1042. case PACKET3_DRAW_INDEX:
  1043. if (pkt->count != 3) {
  1044. DRM_ERROR("bad DRAW_INDEX\n");
  1045. return -EINVAL;
  1046. }
  1047. r = r600_cs_packet_next_reloc(p, &reloc);
  1048. if (r) {
  1049. DRM_ERROR("bad DRAW_INDEX\n");
  1050. return -EINVAL;
  1051. }
  1052. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1053. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1054. r = r600_cs_track_check(p);
  1055. if (r) {
  1056. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1057. return r;
  1058. }
  1059. break;
  1060. case PACKET3_DRAW_INDEX_AUTO:
  1061. if (pkt->count != 1) {
  1062. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1063. return -EINVAL;
  1064. }
  1065. r = r600_cs_track_check(p);
  1066. if (r) {
  1067. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1068. return r;
  1069. }
  1070. break;
  1071. case PACKET3_DRAW_INDEX_IMMD_BE:
  1072. case PACKET3_DRAW_INDEX_IMMD:
  1073. if (pkt->count < 2) {
  1074. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1075. return -EINVAL;
  1076. }
  1077. r = r600_cs_track_check(p);
  1078. if (r) {
  1079. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1080. return r;
  1081. }
  1082. break;
  1083. case PACKET3_WAIT_REG_MEM:
  1084. if (pkt->count != 5) {
  1085. DRM_ERROR("bad WAIT_REG_MEM\n");
  1086. return -EINVAL;
  1087. }
  1088. /* bit 4 is reg (0) or mem (1) */
  1089. if (idx_value & 0x10) {
  1090. r = r600_cs_packet_next_reloc(p, &reloc);
  1091. if (r) {
  1092. DRM_ERROR("bad WAIT_REG_MEM\n");
  1093. return -EINVAL;
  1094. }
  1095. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1096. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1097. }
  1098. break;
  1099. case PACKET3_SURFACE_SYNC:
  1100. if (pkt->count != 3) {
  1101. DRM_ERROR("bad SURFACE_SYNC\n");
  1102. return -EINVAL;
  1103. }
  1104. /* 0xffffffff/0x0 is flush all cache flag */
  1105. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  1106. radeon_get_ib_value(p, idx + 2) != 0) {
  1107. r = r600_cs_packet_next_reloc(p, &reloc);
  1108. if (r) {
  1109. DRM_ERROR("bad SURFACE_SYNC\n");
  1110. return -EINVAL;
  1111. }
  1112. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1113. }
  1114. break;
  1115. case PACKET3_EVENT_WRITE:
  1116. if (pkt->count != 2 && pkt->count != 0) {
  1117. DRM_ERROR("bad EVENT_WRITE\n");
  1118. return -EINVAL;
  1119. }
  1120. if (pkt->count) {
  1121. r = r600_cs_packet_next_reloc(p, &reloc);
  1122. if (r) {
  1123. DRM_ERROR("bad EVENT_WRITE\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_EVENT_WRITE_EOP:
  1131. if (pkt->count != 4) {
  1132. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1133. return -EINVAL;
  1134. }
  1135. r = r600_cs_packet_next_reloc(p, &reloc);
  1136. if (r) {
  1137. DRM_ERROR("bad EVENT_WRITE\n");
  1138. return -EINVAL;
  1139. }
  1140. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1141. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1142. break;
  1143. case PACKET3_SET_CONFIG_REG:
  1144. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_OFFSET;
  1145. end_reg = 4 * pkt->count + start_reg - 4;
  1146. if ((start_reg < PACKET3_SET_CONFIG_REG_OFFSET) ||
  1147. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  1148. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  1149. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  1150. return -EINVAL;
  1151. }
  1152. for (i = 0; i < pkt->count; i++) {
  1153. reg = start_reg + (4 * i);
  1154. r = r600_cs_check_reg(p, reg, idx+1+i);
  1155. if (r)
  1156. return r;
  1157. }
  1158. break;
  1159. case PACKET3_SET_CONTEXT_REG:
  1160. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_OFFSET;
  1161. end_reg = 4 * pkt->count + start_reg - 4;
  1162. if ((start_reg < PACKET3_SET_CONTEXT_REG_OFFSET) ||
  1163. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  1164. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  1165. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  1166. return -EINVAL;
  1167. }
  1168. for (i = 0; i < pkt->count; i++) {
  1169. reg = start_reg + (4 * i);
  1170. r = r600_cs_check_reg(p, reg, idx+1+i);
  1171. if (r)
  1172. return r;
  1173. }
  1174. break;
  1175. case PACKET3_SET_RESOURCE:
  1176. if (pkt->count % 7) {
  1177. DRM_ERROR("bad SET_RESOURCE\n");
  1178. return -EINVAL;
  1179. }
  1180. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_OFFSET;
  1181. end_reg = 4 * pkt->count + start_reg - 4;
  1182. if ((start_reg < PACKET3_SET_RESOURCE_OFFSET) ||
  1183. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  1184. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  1185. DRM_ERROR("bad SET_RESOURCE\n");
  1186. return -EINVAL;
  1187. }
  1188. for (i = 0; i < (pkt->count / 7); i++) {
  1189. struct radeon_bo *texture, *mipmap;
  1190. u32 size, offset;
  1191. switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
  1192. case SQ_TEX_VTX_VALID_TEXTURE:
  1193. /* tex base */
  1194. r = r600_cs_packet_next_reloc(p, &reloc);
  1195. if (r) {
  1196. DRM_ERROR("bad SET_RESOURCE\n");
  1197. return -EINVAL;
  1198. }
  1199. ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1200. texture = reloc->robj;
  1201. /* tex mip base */
  1202. r = r600_cs_packet_next_reloc(p, &reloc);
  1203. if (r) {
  1204. DRM_ERROR("bad SET_RESOURCE\n");
  1205. return -EINVAL;
  1206. }
  1207. ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1208. mipmap = reloc->robj;
  1209. r = r600_check_texture_resource(p, idx+(i*7)+1,
  1210. texture, mipmap);
  1211. if (r)
  1212. return r;
  1213. break;
  1214. case SQ_TEX_VTX_VALID_BUFFER:
  1215. /* vtx base */
  1216. r = r600_cs_packet_next_reloc(p, &reloc);
  1217. if (r) {
  1218. DRM_ERROR("bad SET_RESOURCE\n");
  1219. return -EINVAL;
  1220. }
  1221. offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
  1222. size = radeon_get_ib_value(p, idx+1+(i*7)+1);
  1223. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  1224. /* force size to size of the buffer */
  1225. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  1226. ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
  1227. }
  1228. ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
  1229. ib[idx+1+(i*7)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1230. break;
  1231. case SQ_TEX_VTX_INVALID_TEXTURE:
  1232. case SQ_TEX_VTX_INVALID_BUFFER:
  1233. default:
  1234. DRM_ERROR("bad SET_RESOURCE\n");
  1235. return -EINVAL;
  1236. }
  1237. }
  1238. break;
  1239. case PACKET3_SET_ALU_CONST:
  1240. if (track->sq_config & DX9_CONSTS) {
  1241. start_reg = (idx_value << 2) + PACKET3_SET_ALU_CONST_OFFSET;
  1242. end_reg = 4 * pkt->count + start_reg - 4;
  1243. if ((start_reg < PACKET3_SET_ALU_CONST_OFFSET) ||
  1244. (start_reg >= PACKET3_SET_ALU_CONST_END) ||
  1245. (end_reg >= PACKET3_SET_ALU_CONST_END)) {
  1246. DRM_ERROR("bad SET_ALU_CONST\n");
  1247. return -EINVAL;
  1248. }
  1249. }
  1250. break;
  1251. case PACKET3_SET_BOOL_CONST:
  1252. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_OFFSET;
  1253. end_reg = 4 * pkt->count + start_reg - 4;
  1254. if ((start_reg < PACKET3_SET_BOOL_CONST_OFFSET) ||
  1255. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  1256. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  1257. DRM_ERROR("bad SET_BOOL_CONST\n");
  1258. return -EINVAL;
  1259. }
  1260. break;
  1261. case PACKET3_SET_LOOP_CONST:
  1262. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_OFFSET;
  1263. end_reg = 4 * pkt->count + start_reg - 4;
  1264. if ((start_reg < PACKET3_SET_LOOP_CONST_OFFSET) ||
  1265. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  1266. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  1267. DRM_ERROR("bad SET_LOOP_CONST\n");
  1268. return -EINVAL;
  1269. }
  1270. break;
  1271. case PACKET3_SET_CTL_CONST:
  1272. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_OFFSET;
  1273. end_reg = 4 * pkt->count + start_reg - 4;
  1274. if ((start_reg < PACKET3_SET_CTL_CONST_OFFSET) ||
  1275. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  1276. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  1277. DRM_ERROR("bad SET_CTL_CONST\n");
  1278. return -EINVAL;
  1279. }
  1280. break;
  1281. case PACKET3_SET_SAMPLER:
  1282. if (pkt->count % 3) {
  1283. DRM_ERROR("bad SET_SAMPLER\n");
  1284. return -EINVAL;
  1285. }
  1286. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_OFFSET;
  1287. end_reg = 4 * pkt->count + start_reg - 4;
  1288. if ((start_reg < PACKET3_SET_SAMPLER_OFFSET) ||
  1289. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  1290. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  1291. DRM_ERROR("bad SET_SAMPLER\n");
  1292. return -EINVAL;
  1293. }
  1294. break;
  1295. case PACKET3_SURFACE_BASE_UPDATE:
  1296. if (p->family >= CHIP_RV770 || p->family == CHIP_R600) {
  1297. DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
  1298. return -EINVAL;
  1299. }
  1300. if (pkt->count) {
  1301. DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
  1302. return -EINVAL;
  1303. }
  1304. break;
  1305. case PACKET3_NOP:
  1306. break;
  1307. default:
  1308. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1309. return -EINVAL;
  1310. }
  1311. return 0;
  1312. }
  1313. int r600_cs_parse(struct radeon_cs_parser *p)
  1314. {
  1315. struct radeon_cs_packet pkt;
  1316. struct r600_cs_track *track;
  1317. int r;
  1318. if (p->track == NULL) {
  1319. /* initialize tracker, we are in kms */
  1320. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1321. if (track == NULL)
  1322. return -ENOMEM;
  1323. r600_cs_track_init(track);
  1324. if (p->rdev->family < CHIP_RV770) {
  1325. track->npipes = p->rdev->config.r600.tiling_npipes;
  1326. track->nbanks = p->rdev->config.r600.tiling_nbanks;
  1327. track->group_size = p->rdev->config.r600.tiling_group_size;
  1328. } else if (p->rdev->family <= CHIP_RV740) {
  1329. track->npipes = p->rdev->config.rv770.tiling_npipes;
  1330. track->nbanks = p->rdev->config.rv770.tiling_nbanks;
  1331. track->group_size = p->rdev->config.rv770.tiling_group_size;
  1332. }
  1333. p->track = track;
  1334. }
  1335. do {
  1336. r = r600_cs_packet_parse(p, &pkt, p->idx);
  1337. if (r) {
  1338. kfree(p->track);
  1339. p->track = NULL;
  1340. return r;
  1341. }
  1342. p->idx += pkt.count + 2;
  1343. switch (pkt.type) {
  1344. case PACKET_TYPE0:
  1345. r = r600_cs_parse_packet0(p, &pkt);
  1346. break;
  1347. case PACKET_TYPE2:
  1348. break;
  1349. case PACKET_TYPE3:
  1350. r = r600_packet3_check(p, &pkt);
  1351. break;
  1352. default:
  1353. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1354. kfree(p->track);
  1355. p->track = NULL;
  1356. return -EINVAL;
  1357. }
  1358. if (r) {
  1359. kfree(p->track);
  1360. p->track = NULL;
  1361. return r;
  1362. }
  1363. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1364. #if 0
  1365. for (r = 0; r < p->ib->length_dw; r++) {
  1366. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  1367. mdelay(1);
  1368. }
  1369. #endif
  1370. kfree(p->track);
  1371. p->track = NULL;
  1372. return 0;
  1373. }
  1374. static int r600_cs_parser_relocs_legacy(struct radeon_cs_parser *p)
  1375. {
  1376. if (p->chunk_relocs_idx == -1) {
  1377. return 0;
  1378. }
  1379. p->relocs = kzalloc(sizeof(struct radeon_cs_reloc), GFP_KERNEL);
  1380. if (p->relocs == NULL) {
  1381. return -ENOMEM;
  1382. }
  1383. return 0;
  1384. }
  1385. /**
  1386. * cs_parser_fini() - clean parser states
  1387. * @parser: parser structure holding parsing context.
  1388. * @error: error number
  1389. *
  1390. * If error is set than unvalidate buffer, otherwise just free memory
  1391. * used by parsing context.
  1392. **/
  1393. static void r600_cs_parser_fini(struct radeon_cs_parser *parser, int error)
  1394. {
  1395. unsigned i;
  1396. kfree(parser->relocs);
  1397. for (i = 0; i < parser->nchunks; i++) {
  1398. kfree(parser->chunks[i].kdata);
  1399. kfree(parser->chunks[i].kpage[0]);
  1400. kfree(parser->chunks[i].kpage[1]);
  1401. }
  1402. kfree(parser->chunks);
  1403. kfree(parser->chunks_array);
  1404. }
  1405. int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
  1406. unsigned family, u32 *ib, int *l)
  1407. {
  1408. struct radeon_cs_parser parser;
  1409. struct radeon_cs_chunk *ib_chunk;
  1410. struct radeon_ib fake_ib;
  1411. struct r600_cs_track *track;
  1412. int r;
  1413. /* initialize tracker */
  1414. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1415. if (track == NULL)
  1416. return -ENOMEM;
  1417. r600_cs_track_init(track);
  1418. r600_cs_legacy_get_tiling_conf(dev, &track->npipes, &track->nbanks, &track->group_size);
  1419. /* initialize parser */
  1420. memset(&parser, 0, sizeof(struct radeon_cs_parser));
  1421. parser.filp = filp;
  1422. parser.dev = &dev->pdev->dev;
  1423. parser.rdev = NULL;
  1424. parser.family = family;
  1425. parser.ib = &fake_ib;
  1426. parser.track = track;
  1427. fake_ib.ptr = ib;
  1428. r = radeon_cs_parser_init(&parser, data);
  1429. if (r) {
  1430. DRM_ERROR("Failed to initialize parser !\n");
  1431. r600_cs_parser_fini(&parser, r);
  1432. return r;
  1433. }
  1434. r = r600_cs_parser_relocs_legacy(&parser);
  1435. if (r) {
  1436. DRM_ERROR("Failed to parse relocation !\n");
  1437. r600_cs_parser_fini(&parser, r);
  1438. return r;
  1439. }
  1440. /* Copy the packet into the IB, the parser will read from the
  1441. * input memory (cached) and write to the IB (which can be
  1442. * uncached). */
  1443. ib_chunk = &parser.chunks[parser.chunk_ib_idx];
  1444. parser.ib->length_dw = ib_chunk->length_dw;
  1445. *l = parser.ib->length_dw;
  1446. r = r600_cs_parse(&parser);
  1447. if (r) {
  1448. DRM_ERROR("Invalid command stream !\n");
  1449. r600_cs_parser_fini(&parser, r);
  1450. return r;
  1451. }
  1452. r = radeon_cs_finish_pages(&parser);
  1453. if (r) {
  1454. DRM_ERROR("Invalid command stream !\n");
  1455. r600_cs_parser_fini(&parser, r);
  1456. return r;
  1457. }
  1458. r600_cs_parser_fini(&parser, r);
  1459. return r;
  1460. }
  1461. void r600_cs_legacy_init(void)
  1462. {
  1463. r600_cs_packet_next_reloc = &r600_cs_packet_next_reloc_nomm;
  1464. }