r600_cs.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  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. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  562. if (!obj) {
  563. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  564. r = -EINVAL;
  565. goto out;
  566. }
  567. crtc = obj_to_crtc(obj);
  568. radeon_crtc = to_radeon_crtc(crtc);
  569. crtc_id = radeon_crtc->crtc_id;
  570. if (!crtc->enabled) {
  571. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  572. ib[h_idx + 2] = PACKET2(0);
  573. ib[h_idx + 3] = PACKET2(0);
  574. ib[h_idx + 4] = PACKET2(0);
  575. ib[h_idx + 5] = PACKET2(0);
  576. ib[h_idx + 6] = PACKET2(0);
  577. ib[h_idx + 7] = PACKET2(0);
  578. ib[h_idx + 8] = PACKET2(0);
  579. } else if (crtc_id == 1) {
  580. switch (reg) {
  581. case AVIVO_D1MODE_VLINE_START_END:
  582. header &= ~R600_CP_PACKET0_REG_MASK;
  583. header |= AVIVO_D2MODE_VLINE_START_END >> 2;
  584. break;
  585. default:
  586. DRM_ERROR("unknown crtc reloc\n");
  587. r = -EINVAL;
  588. goto out;
  589. }
  590. ib[h_idx] = header;
  591. ib[h_idx + 4] = AVIVO_D2MODE_VLINE_STATUS >> 2;
  592. }
  593. out:
  594. return r;
  595. }
  596. static int r600_packet0_check(struct radeon_cs_parser *p,
  597. struct radeon_cs_packet *pkt,
  598. unsigned idx, unsigned reg)
  599. {
  600. int r;
  601. switch (reg) {
  602. case AVIVO_D1MODE_VLINE_START_END:
  603. r = r600_cs_packet_parse_vline(p);
  604. if (r) {
  605. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  606. idx, reg);
  607. return r;
  608. }
  609. break;
  610. default:
  611. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  612. reg, idx);
  613. return -EINVAL;
  614. }
  615. return 0;
  616. }
  617. static int r600_cs_parse_packet0(struct radeon_cs_parser *p,
  618. struct radeon_cs_packet *pkt)
  619. {
  620. unsigned reg, i;
  621. unsigned idx;
  622. int r;
  623. idx = pkt->idx + 1;
  624. reg = pkt->reg;
  625. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  626. r = r600_packet0_check(p, pkt, idx, reg);
  627. if (r) {
  628. return r;
  629. }
  630. }
  631. return 0;
  632. }
  633. /**
  634. * r600_cs_check_reg() - check if register is authorized or not
  635. * @parser: parser structure holding parsing context
  636. * @reg: register we are testing
  637. * @idx: index into the cs buffer
  638. *
  639. * This function will test against r600_reg_safe_bm and return 0
  640. * if register is safe. If register is not flag as safe this function
  641. * will test it against a list of register needind special handling.
  642. */
  643. static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  644. {
  645. struct r600_cs_track *track = (struct r600_cs_track *)p->track;
  646. struct radeon_cs_reloc *reloc;
  647. u32 last_reg = ARRAY_SIZE(r600_reg_safe_bm);
  648. u32 m, i, tmp, *ib;
  649. int r;
  650. i = (reg >> 7);
  651. if (i > last_reg) {
  652. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  653. return -EINVAL;
  654. }
  655. m = 1 << ((reg >> 2) & 31);
  656. if (!(r600_reg_safe_bm[i] & m))
  657. return 0;
  658. ib = p->ib->ptr;
  659. switch (reg) {
  660. /* force following reg to 0 in an attemp to disable out buffer
  661. * which will need us to better understand how it works to perform
  662. * security check on it (Jerome)
  663. */
  664. case R_0288A8_SQ_ESGS_RING_ITEMSIZE:
  665. case R_008C44_SQ_ESGS_RING_SIZE:
  666. case R_0288B0_SQ_ESTMP_RING_ITEMSIZE:
  667. case R_008C54_SQ_ESTMP_RING_SIZE:
  668. case R_0288C0_SQ_FBUF_RING_ITEMSIZE:
  669. case R_008C74_SQ_FBUF_RING_SIZE:
  670. case R_0288B4_SQ_GSTMP_RING_ITEMSIZE:
  671. case R_008C5C_SQ_GSTMP_RING_SIZE:
  672. case R_0288AC_SQ_GSVS_RING_ITEMSIZE:
  673. case R_008C4C_SQ_GSVS_RING_SIZE:
  674. case R_0288BC_SQ_PSTMP_RING_ITEMSIZE:
  675. case R_008C6C_SQ_PSTMP_RING_SIZE:
  676. case R_0288C4_SQ_REDUC_RING_ITEMSIZE:
  677. case R_008C7C_SQ_REDUC_RING_SIZE:
  678. case R_0288B8_SQ_VSTMP_RING_ITEMSIZE:
  679. case R_008C64_SQ_VSTMP_RING_SIZE:
  680. case R_0288C8_SQ_GS_VERT_ITEMSIZE:
  681. /* get value to populate the IB don't remove */
  682. tmp =radeon_get_ib_value(p, idx);
  683. ib[idx] = 0;
  684. break;
  685. case SQ_CONFIG:
  686. track->sq_config = radeon_get_ib_value(p, idx);
  687. break;
  688. case R_028800_DB_DEPTH_CONTROL:
  689. track->db_depth_control = radeon_get_ib_value(p, idx);
  690. break;
  691. case R_028010_DB_DEPTH_INFO:
  692. track->db_depth_info = radeon_get_ib_value(p, idx);
  693. break;
  694. case R_028004_DB_DEPTH_VIEW:
  695. track->db_depth_view = radeon_get_ib_value(p, idx);
  696. break;
  697. case R_028000_DB_DEPTH_SIZE:
  698. track->db_depth_size = radeon_get_ib_value(p, idx);
  699. track->db_depth_size_idx = idx;
  700. break;
  701. case R_028AB0_VGT_STRMOUT_EN:
  702. track->vgt_strmout_en = radeon_get_ib_value(p, idx);
  703. break;
  704. case R_028B20_VGT_STRMOUT_BUFFER_EN:
  705. track->vgt_strmout_buffer_en = radeon_get_ib_value(p, idx);
  706. break;
  707. case R_028238_CB_TARGET_MASK:
  708. track->cb_target_mask = radeon_get_ib_value(p, idx);
  709. break;
  710. case R_02823C_CB_SHADER_MASK:
  711. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  712. break;
  713. case R_028C04_PA_SC_AA_CONFIG:
  714. tmp = G_028C04_MSAA_NUM_SAMPLES(radeon_get_ib_value(p, idx));
  715. track->nsamples = 1 << tmp;
  716. break;
  717. case R_0280A0_CB_COLOR0_INFO:
  718. case R_0280A4_CB_COLOR1_INFO:
  719. case R_0280A8_CB_COLOR2_INFO:
  720. case R_0280AC_CB_COLOR3_INFO:
  721. case R_0280B0_CB_COLOR4_INFO:
  722. case R_0280B4_CB_COLOR5_INFO:
  723. case R_0280B8_CB_COLOR6_INFO:
  724. case R_0280BC_CB_COLOR7_INFO:
  725. tmp = (reg - R_0280A0_CB_COLOR0_INFO) / 4;
  726. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  727. break;
  728. case R_028060_CB_COLOR0_SIZE:
  729. case R_028064_CB_COLOR1_SIZE:
  730. case R_028068_CB_COLOR2_SIZE:
  731. case R_02806C_CB_COLOR3_SIZE:
  732. case R_028070_CB_COLOR4_SIZE:
  733. case R_028074_CB_COLOR5_SIZE:
  734. case R_028078_CB_COLOR6_SIZE:
  735. case R_02807C_CB_COLOR7_SIZE:
  736. tmp = (reg - R_028060_CB_COLOR0_SIZE) / 4;
  737. track->cb_color_size[tmp] = radeon_get_ib_value(p, idx);
  738. track->cb_color_size_idx[tmp] = idx;
  739. break;
  740. /* This register were added late, there is userspace
  741. * which does provide relocation for those but set
  742. * 0 offset. In order to avoid breaking old userspace
  743. * we detect this and set address to point to last
  744. * CB_COLOR0_BASE, note that if userspace doesn't set
  745. * CB_COLOR0_BASE before this register we will report
  746. * error. Old userspace always set CB_COLOR0_BASE
  747. * before any of this.
  748. */
  749. case R_0280E0_CB_COLOR0_FRAG:
  750. case R_0280E4_CB_COLOR1_FRAG:
  751. case R_0280E8_CB_COLOR2_FRAG:
  752. case R_0280EC_CB_COLOR3_FRAG:
  753. case R_0280F0_CB_COLOR4_FRAG:
  754. case R_0280F4_CB_COLOR5_FRAG:
  755. case R_0280F8_CB_COLOR6_FRAG:
  756. case R_0280FC_CB_COLOR7_FRAG:
  757. tmp = (reg - R_0280E0_CB_COLOR0_FRAG) / 4;
  758. if (!r600_cs_packet_next_is_pkt3_nop(p)) {
  759. if (!track->cb_color_base_last[tmp]) {
  760. dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
  761. return -EINVAL;
  762. }
  763. ib[idx] = track->cb_color_base_last[tmp];
  764. printk_once(KERN_WARNING "You have old & broken userspace "
  765. "please consider updating mesa & xf86-video-ati\n");
  766. track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp];
  767. } else {
  768. r = r600_cs_packet_next_reloc(p, &reloc);
  769. if (r) {
  770. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  771. return -EINVAL;
  772. }
  773. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  774. track->cb_color_frag_bo[tmp] = reloc->robj;
  775. }
  776. break;
  777. case R_0280C0_CB_COLOR0_TILE:
  778. case R_0280C4_CB_COLOR1_TILE:
  779. case R_0280C8_CB_COLOR2_TILE:
  780. case R_0280CC_CB_COLOR3_TILE:
  781. case R_0280D0_CB_COLOR4_TILE:
  782. case R_0280D4_CB_COLOR5_TILE:
  783. case R_0280D8_CB_COLOR6_TILE:
  784. case R_0280DC_CB_COLOR7_TILE:
  785. tmp = (reg - R_0280C0_CB_COLOR0_TILE) / 4;
  786. if (!r600_cs_packet_next_is_pkt3_nop(p)) {
  787. if (!track->cb_color_base_last[tmp]) {
  788. dev_err(p->dev, "Broken old userspace ? no cb_color0_base supplied before trying to write 0x%08X\n", reg);
  789. return -EINVAL;
  790. }
  791. ib[idx] = track->cb_color_base_last[tmp];
  792. printk_once(KERN_WARNING "You have old & broken userspace "
  793. "please consider updating mesa & xf86-video-ati\n");
  794. track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp];
  795. } else {
  796. r = r600_cs_packet_next_reloc(p, &reloc);
  797. if (r) {
  798. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  799. return -EINVAL;
  800. }
  801. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  802. track->cb_color_tile_bo[tmp] = reloc->robj;
  803. }
  804. break;
  805. case CB_COLOR0_BASE:
  806. case CB_COLOR1_BASE:
  807. case CB_COLOR2_BASE:
  808. case CB_COLOR3_BASE:
  809. case CB_COLOR4_BASE:
  810. case CB_COLOR5_BASE:
  811. case CB_COLOR6_BASE:
  812. case CB_COLOR7_BASE:
  813. r = r600_cs_packet_next_reloc(p, &reloc);
  814. if (r) {
  815. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  816. "0x%04X\n", reg);
  817. return -EINVAL;
  818. }
  819. tmp = (reg - CB_COLOR0_BASE) / 4;
  820. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  821. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  822. track->cb_color_base_last[tmp] = ib[idx];
  823. track->cb_color_bo[tmp] = reloc->robj;
  824. break;
  825. case DB_DEPTH_BASE:
  826. r = r600_cs_packet_next_reloc(p, &reloc);
  827. if (r) {
  828. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  829. "0x%04X\n", reg);
  830. return -EINVAL;
  831. }
  832. track->db_offset = radeon_get_ib_value(p, idx);
  833. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  834. track->db_bo = reloc->robj;
  835. break;
  836. case DB_HTILE_DATA_BASE:
  837. case SQ_PGM_START_FS:
  838. case SQ_PGM_START_ES:
  839. case SQ_PGM_START_VS:
  840. case SQ_PGM_START_GS:
  841. case SQ_PGM_START_PS:
  842. case SQ_ALU_CONST_CACHE_GS_0:
  843. case SQ_ALU_CONST_CACHE_GS_1:
  844. case SQ_ALU_CONST_CACHE_GS_2:
  845. case SQ_ALU_CONST_CACHE_GS_3:
  846. case SQ_ALU_CONST_CACHE_GS_4:
  847. case SQ_ALU_CONST_CACHE_GS_5:
  848. case SQ_ALU_CONST_CACHE_GS_6:
  849. case SQ_ALU_CONST_CACHE_GS_7:
  850. case SQ_ALU_CONST_CACHE_GS_8:
  851. case SQ_ALU_CONST_CACHE_GS_9:
  852. case SQ_ALU_CONST_CACHE_GS_10:
  853. case SQ_ALU_CONST_CACHE_GS_11:
  854. case SQ_ALU_CONST_CACHE_GS_12:
  855. case SQ_ALU_CONST_CACHE_GS_13:
  856. case SQ_ALU_CONST_CACHE_GS_14:
  857. case SQ_ALU_CONST_CACHE_GS_15:
  858. case SQ_ALU_CONST_CACHE_PS_0:
  859. case SQ_ALU_CONST_CACHE_PS_1:
  860. case SQ_ALU_CONST_CACHE_PS_2:
  861. case SQ_ALU_CONST_CACHE_PS_3:
  862. case SQ_ALU_CONST_CACHE_PS_4:
  863. case SQ_ALU_CONST_CACHE_PS_5:
  864. case SQ_ALU_CONST_CACHE_PS_6:
  865. case SQ_ALU_CONST_CACHE_PS_7:
  866. case SQ_ALU_CONST_CACHE_PS_8:
  867. case SQ_ALU_CONST_CACHE_PS_9:
  868. case SQ_ALU_CONST_CACHE_PS_10:
  869. case SQ_ALU_CONST_CACHE_PS_11:
  870. case SQ_ALU_CONST_CACHE_PS_12:
  871. case SQ_ALU_CONST_CACHE_PS_13:
  872. case SQ_ALU_CONST_CACHE_PS_14:
  873. case SQ_ALU_CONST_CACHE_PS_15:
  874. case SQ_ALU_CONST_CACHE_VS_0:
  875. case SQ_ALU_CONST_CACHE_VS_1:
  876. case SQ_ALU_CONST_CACHE_VS_2:
  877. case SQ_ALU_CONST_CACHE_VS_3:
  878. case SQ_ALU_CONST_CACHE_VS_4:
  879. case SQ_ALU_CONST_CACHE_VS_5:
  880. case SQ_ALU_CONST_CACHE_VS_6:
  881. case SQ_ALU_CONST_CACHE_VS_7:
  882. case SQ_ALU_CONST_CACHE_VS_8:
  883. case SQ_ALU_CONST_CACHE_VS_9:
  884. case SQ_ALU_CONST_CACHE_VS_10:
  885. case SQ_ALU_CONST_CACHE_VS_11:
  886. case SQ_ALU_CONST_CACHE_VS_12:
  887. case SQ_ALU_CONST_CACHE_VS_13:
  888. case SQ_ALU_CONST_CACHE_VS_14:
  889. case SQ_ALU_CONST_CACHE_VS_15:
  890. r = r600_cs_packet_next_reloc(p, &reloc);
  891. if (r) {
  892. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  893. "0x%04X\n", reg);
  894. return -EINVAL;
  895. }
  896. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  897. break;
  898. default:
  899. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  900. return -EINVAL;
  901. }
  902. return 0;
  903. }
  904. static inline unsigned minify(unsigned size, unsigned levels)
  905. {
  906. size = size >> levels;
  907. if (size < 1)
  908. size = 1;
  909. return size;
  910. }
  911. static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels,
  912. unsigned w0, unsigned h0, unsigned d0, unsigned bpe,
  913. unsigned *l0_size, unsigned *mipmap_size)
  914. {
  915. unsigned offset, i, level, face;
  916. unsigned width, height, depth, rowstride, size;
  917. w0 = minify(w0, 0);
  918. h0 = minify(h0, 0);
  919. d0 = minify(d0, 0);
  920. for(i = 0, offset = 0, level = blevel; i < nlevels; i++, level++) {
  921. width = minify(w0, i);
  922. height = minify(h0, i);
  923. depth = minify(d0, i);
  924. for(face = 0; face < nfaces; face++) {
  925. rowstride = ((width * bpe) + 255) & ~255;
  926. size = height * rowstride * depth;
  927. offset += size;
  928. offset = (offset + 0x1f) & ~0x1f;
  929. }
  930. }
  931. *l0_size = (((w0 * bpe) + 255) & ~255) * h0 * d0;
  932. *mipmap_size = offset;
  933. if (!blevel)
  934. *mipmap_size -= *l0_size;
  935. if (!nlevels)
  936. *mipmap_size = *l0_size;
  937. }
  938. /**
  939. * r600_check_texture_resource() - check if register is authorized or not
  940. * @p: parser structure holding parsing context
  941. * @idx: index into the cs buffer
  942. * @texture: texture's bo structure
  943. * @mipmap: mipmap's bo structure
  944. *
  945. * This function will check that the resource has valid field and that
  946. * the texture and mipmap bo object are big enough to cover this resource.
  947. */
  948. static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
  949. struct radeon_bo *texture,
  950. struct radeon_bo *mipmap)
  951. {
  952. u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0;
  953. u32 word0, word1, l0_size, mipmap_size;
  954. /* on legacy kernel we don't perform advanced check */
  955. if (p->rdev == NULL)
  956. return 0;
  957. word0 = radeon_get_ib_value(p, idx + 0);
  958. word1 = radeon_get_ib_value(p, idx + 1);
  959. w0 = G_038000_TEX_WIDTH(word0) + 1;
  960. h0 = G_038004_TEX_HEIGHT(word1) + 1;
  961. d0 = G_038004_TEX_DEPTH(word1);
  962. nfaces = 1;
  963. switch (G_038000_DIM(word0)) {
  964. case V_038000_SQ_TEX_DIM_1D:
  965. case V_038000_SQ_TEX_DIM_2D:
  966. case V_038000_SQ_TEX_DIM_3D:
  967. break;
  968. case V_038000_SQ_TEX_DIM_CUBEMAP:
  969. nfaces = 6;
  970. break;
  971. case V_038000_SQ_TEX_DIM_1D_ARRAY:
  972. case V_038000_SQ_TEX_DIM_2D_ARRAY:
  973. case V_038000_SQ_TEX_DIM_2D_MSAA:
  974. case V_038000_SQ_TEX_DIM_2D_ARRAY_MSAA:
  975. default:
  976. dev_warn(p->dev, "this kernel doesn't support %d texture dim\n", G_038000_DIM(word0));
  977. return -EINVAL;
  978. }
  979. if (r600_bpe_from_format(&bpe, G_038004_DATA_FORMAT(word1))) {
  980. dev_warn(p->dev, "%s:%d texture invalid format %d\n",
  981. __func__, __LINE__, G_038004_DATA_FORMAT(word1));
  982. return -EINVAL;
  983. }
  984. word0 = radeon_get_ib_value(p, idx + 4);
  985. word1 = radeon_get_ib_value(p, idx + 5);
  986. blevel = G_038010_BASE_LEVEL(word0);
  987. nlevels = G_038014_LAST_LEVEL(word1);
  988. r600_texture_size(nfaces, blevel, nlevels, w0, h0, d0, bpe, &l0_size, &mipmap_size);
  989. /* using get ib will give us the offset into the texture bo */
  990. word0 = radeon_get_ib_value(p, idx + 2);
  991. if ((l0_size + word0) > radeon_bo_size(texture)) {
  992. dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
  993. w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
  994. return -EINVAL;
  995. }
  996. /* using get ib will give us the offset into the mipmap bo */
  997. word0 = radeon_get_ib_value(p, idx + 3);
  998. if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
  999. dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
  1000. w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
  1001. return -EINVAL;
  1002. }
  1003. return 0;
  1004. }
  1005. static int r600_packet3_check(struct radeon_cs_parser *p,
  1006. struct radeon_cs_packet *pkt)
  1007. {
  1008. struct radeon_cs_reloc *reloc;
  1009. struct r600_cs_track *track;
  1010. volatile u32 *ib;
  1011. unsigned idx;
  1012. unsigned i;
  1013. unsigned start_reg, end_reg, reg;
  1014. int r;
  1015. u32 idx_value;
  1016. track = (struct r600_cs_track *)p->track;
  1017. ib = p->ib->ptr;
  1018. idx = pkt->idx + 1;
  1019. idx_value = radeon_get_ib_value(p, idx);
  1020. switch (pkt->opcode) {
  1021. case PACKET3_START_3D_CMDBUF:
  1022. if (p->family >= CHIP_RV770 || pkt->count) {
  1023. DRM_ERROR("bad START_3D\n");
  1024. return -EINVAL;
  1025. }
  1026. break;
  1027. case PACKET3_CONTEXT_CONTROL:
  1028. if (pkt->count != 1) {
  1029. DRM_ERROR("bad CONTEXT_CONTROL\n");
  1030. return -EINVAL;
  1031. }
  1032. break;
  1033. case PACKET3_INDEX_TYPE:
  1034. case PACKET3_NUM_INSTANCES:
  1035. if (pkt->count) {
  1036. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES\n");
  1037. return -EINVAL;
  1038. }
  1039. break;
  1040. case PACKET3_DRAW_INDEX:
  1041. if (pkt->count != 3) {
  1042. DRM_ERROR("bad DRAW_INDEX\n");
  1043. return -EINVAL;
  1044. }
  1045. r = r600_cs_packet_next_reloc(p, &reloc);
  1046. if (r) {
  1047. DRM_ERROR("bad DRAW_INDEX\n");
  1048. return -EINVAL;
  1049. }
  1050. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1051. ib[idx+1] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1052. r = r600_cs_track_check(p);
  1053. if (r) {
  1054. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1055. return r;
  1056. }
  1057. break;
  1058. case PACKET3_DRAW_INDEX_AUTO:
  1059. if (pkt->count != 1) {
  1060. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1061. return -EINVAL;
  1062. }
  1063. r = r600_cs_track_check(p);
  1064. if (r) {
  1065. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1066. return r;
  1067. }
  1068. break;
  1069. case PACKET3_DRAW_INDEX_IMMD_BE:
  1070. case PACKET3_DRAW_INDEX_IMMD:
  1071. if (pkt->count < 2) {
  1072. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1073. return -EINVAL;
  1074. }
  1075. r = r600_cs_track_check(p);
  1076. if (r) {
  1077. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1078. return r;
  1079. }
  1080. break;
  1081. case PACKET3_WAIT_REG_MEM:
  1082. if (pkt->count != 5) {
  1083. DRM_ERROR("bad WAIT_REG_MEM\n");
  1084. return -EINVAL;
  1085. }
  1086. /* bit 4 is reg (0) or mem (1) */
  1087. if (idx_value & 0x10) {
  1088. r = r600_cs_packet_next_reloc(p, &reloc);
  1089. if (r) {
  1090. DRM_ERROR("bad WAIT_REG_MEM\n");
  1091. return -EINVAL;
  1092. }
  1093. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1094. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1095. }
  1096. break;
  1097. case PACKET3_SURFACE_SYNC:
  1098. if (pkt->count != 3) {
  1099. DRM_ERROR("bad SURFACE_SYNC\n");
  1100. return -EINVAL;
  1101. }
  1102. /* 0xffffffff/0x0 is flush all cache flag */
  1103. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  1104. radeon_get_ib_value(p, idx + 2) != 0) {
  1105. r = r600_cs_packet_next_reloc(p, &reloc);
  1106. if (r) {
  1107. DRM_ERROR("bad SURFACE_SYNC\n");
  1108. return -EINVAL;
  1109. }
  1110. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1111. }
  1112. break;
  1113. case PACKET3_EVENT_WRITE:
  1114. if (pkt->count != 2 && pkt->count != 0) {
  1115. DRM_ERROR("bad EVENT_WRITE\n");
  1116. return -EINVAL;
  1117. }
  1118. if (pkt->count) {
  1119. r = r600_cs_packet_next_reloc(p, &reloc);
  1120. if (r) {
  1121. DRM_ERROR("bad EVENT_WRITE\n");
  1122. return -EINVAL;
  1123. }
  1124. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1125. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1126. }
  1127. break;
  1128. case PACKET3_EVENT_WRITE_EOP:
  1129. if (pkt->count != 4) {
  1130. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  1131. return -EINVAL;
  1132. }
  1133. r = r600_cs_packet_next_reloc(p, &reloc);
  1134. if (r) {
  1135. DRM_ERROR("bad EVENT_WRITE\n");
  1136. return -EINVAL;
  1137. }
  1138. ib[idx+1] += (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  1139. ib[idx+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1140. break;
  1141. case PACKET3_SET_CONFIG_REG:
  1142. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_OFFSET;
  1143. end_reg = 4 * pkt->count + start_reg - 4;
  1144. if ((start_reg < PACKET3_SET_CONFIG_REG_OFFSET) ||
  1145. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  1146. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  1147. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  1148. return -EINVAL;
  1149. }
  1150. for (i = 0; i < pkt->count; i++) {
  1151. reg = start_reg + (4 * i);
  1152. r = r600_cs_check_reg(p, reg, idx+1+i);
  1153. if (r)
  1154. return r;
  1155. }
  1156. break;
  1157. case PACKET3_SET_CONTEXT_REG:
  1158. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_OFFSET;
  1159. end_reg = 4 * pkt->count + start_reg - 4;
  1160. if ((start_reg < PACKET3_SET_CONTEXT_REG_OFFSET) ||
  1161. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  1162. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  1163. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  1164. return -EINVAL;
  1165. }
  1166. for (i = 0; i < pkt->count; i++) {
  1167. reg = start_reg + (4 * i);
  1168. r = r600_cs_check_reg(p, reg, idx+1+i);
  1169. if (r)
  1170. return r;
  1171. }
  1172. break;
  1173. case PACKET3_SET_RESOURCE:
  1174. if (pkt->count % 7) {
  1175. DRM_ERROR("bad SET_RESOURCE\n");
  1176. return -EINVAL;
  1177. }
  1178. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_OFFSET;
  1179. end_reg = 4 * pkt->count + start_reg - 4;
  1180. if ((start_reg < PACKET3_SET_RESOURCE_OFFSET) ||
  1181. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  1182. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  1183. DRM_ERROR("bad SET_RESOURCE\n");
  1184. return -EINVAL;
  1185. }
  1186. for (i = 0; i < (pkt->count / 7); i++) {
  1187. struct radeon_bo *texture, *mipmap;
  1188. u32 size, offset;
  1189. switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
  1190. case SQ_TEX_VTX_VALID_TEXTURE:
  1191. /* tex base */
  1192. r = r600_cs_packet_next_reloc(p, &reloc);
  1193. if (r) {
  1194. DRM_ERROR("bad SET_RESOURCE\n");
  1195. return -EINVAL;
  1196. }
  1197. ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1198. texture = reloc->robj;
  1199. /* tex mip base */
  1200. r = r600_cs_packet_next_reloc(p, &reloc);
  1201. if (r) {
  1202. DRM_ERROR("bad SET_RESOURCE\n");
  1203. return -EINVAL;
  1204. }
  1205. ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1206. mipmap = reloc->robj;
  1207. r = r600_check_texture_resource(p, idx+(i*7)+1,
  1208. texture, mipmap);
  1209. if (r)
  1210. return r;
  1211. break;
  1212. case SQ_TEX_VTX_VALID_BUFFER:
  1213. /* vtx base */
  1214. r = r600_cs_packet_next_reloc(p, &reloc);
  1215. if (r) {
  1216. DRM_ERROR("bad SET_RESOURCE\n");
  1217. return -EINVAL;
  1218. }
  1219. offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
  1220. size = radeon_get_ib_value(p, idx+1+(i*7)+1);
  1221. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  1222. /* force size to size of the buffer */
  1223. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  1224. ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
  1225. }
  1226. ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
  1227. ib[idx+1+(i*7)+2] += upper_32_bits(reloc->lobj.gpu_offset) & 0xff;
  1228. break;
  1229. case SQ_TEX_VTX_INVALID_TEXTURE:
  1230. case SQ_TEX_VTX_INVALID_BUFFER:
  1231. default:
  1232. DRM_ERROR("bad SET_RESOURCE\n");
  1233. return -EINVAL;
  1234. }
  1235. }
  1236. break;
  1237. case PACKET3_SET_ALU_CONST:
  1238. if (track->sq_config & DX9_CONSTS) {
  1239. start_reg = (idx_value << 2) + PACKET3_SET_ALU_CONST_OFFSET;
  1240. end_reg = 4 * pkt->count + start_reg - 4;
  1241. if ((start_reg < PACKET3_SET_ALU_CONST_OFFSET) ||
  1242. (start_reg >= PACKET3_SET_ALU_CONST_END) ||
  1243. (end_reg >= PACKET3_SET_ALU_CONST_END)) {
  1244. DRM_ERROR("bad SET_ALU_CONST\n");
  1245. return -EINVAL;
  1246. }
  1247. }
  1248. break;
  1249. case PACKET3_SET_BOOL_CONST:
  1250. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_OFFSET;
  1251. end_reg = 4 * pkt->count + start_reg - 4;
  1252. if ((start_reg < PACKET3_SET_BOOL_CONST_OFFSET) ||
  1253. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  1254. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  1255. DRM_ERROR("bad SET_BOOL_CONST\n");
  1256. return -EINVAL;
  1257. }
  1258. break;
  1259. case PACKET3_SET_LOOP_CONST:
  1260. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_OFFSET;
  1261. end_reg = 4 * pkt->count + start_reg - 4;
  1262. if ((start_reg < PACKET3_SET_LOOP_CONST_OFFSET) ||
  1263. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  1264. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  1265. DRM_ERROR("bad SET_LOOP_CONST\n");
  1266. return -EINVAL;
  1267. }
  1268. break;
  1269. case PACKET3_SET_CTL_CONST:
  1270. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_OFFSET;
  1271. end_reg = 4 * pkt->count + start_reg - 4;
  1272. if ((start_reg < PACKET3_SET_CTL_CONST_OFFSET) ||
  1273. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  1274. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  1275. DRM_ERROR("bad SET_CTL_CONST\n");
  1276. return -EINVAL;
  1277. }
  1278. break;
  1279. case PACKET3_SET_SAMPLER:
  1280. if (pkt->count % 3) {
  1281. DRM_ERROR("bad SET_SAMPLER\n");
  1282. return -EINVAL;
  1283. }
  1284. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_OFFSET;
  1285. end_reg = 4 * pkt->count + start_reg - 4;
  1286. if ((start_reg < PACKET3_SET_SAMPLER_OFFSET) ||
  1287. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  1288. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  1289. DRM_ERROR("bad SET_SAMPLER\n");
  1290. return -EINVAL;
  1291. }
  1292. break;
  1293. case PACKET3_SURFACE_BASE_UPDATE:
  1294. if (p->family >= CHIP_RV770 || p->family == CHIP_R600) {
  1295. DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
  1296. return -EINVAL;
  1297. }
  1298. if (pkt->count) {
  1299. DRM_ERROR("bad SURFACE_BASE_UPDATE\n");
  1300. return -EINVAL;
  1301. }
  1302. break;
  1303. case PACKET3_NOP:
  1304. break;
  1305. default:
  1306. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1307. return -EINVAL;
  1308. }
  1309. return 0;
  1310. }
  1311. int r600_cs_parse(struct radeon_cs_parser *p)
  1312. {
  1313. struct radeon_cs_packet pkt;
  1314. struct r600_cs_track *track;
  1315. int r;
  1316. if (p->track == NULL) {
  1317. /* initialize tracker, we are in kms */
  1318. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1319. if (track == NULL)
  1320. return -ENOMEM;
  1321. r600_cs_track_init(track);
  1322. if (p->rdev->family < CHIP_RV770) {
  1323. track->npipes = p->rdev->config.r600.tiling_npipes;
  1324. track->nbanks = p->rdev->config.r600.tiling_nbanks;
  1325. track->group_size = p->rdev->config.r600.tiling_group_size;
  1326. } else if (p->rdev->family <= CHIP_RV740) {
  1327. track->npipes = p->rdev->config.rv770.tiling_npipes;
  1328. track->nbanks = p->rdev->config.rv770.tiling_nbanks;
  1329. track->group_size = p->rdev->config.rv770.tiling_group_size;
  1330. }
  1331. p->track = track;
  1332. }
  1333. do {
  1334. r = r600_cs_packet_parse(p, &pkt, p->idx);
  1335. if (r) {
  1336. kfree(p->track);
  1337. p->track = NULL;
  1338. return r;
  1339. }
  1340. p->idx += pkt.count + 2;
  1341. switch (pkt.type) {
  1342. case PACKET_TYPE0:
  1343. r = r600_cs_parse_packet0(p, &pkt);
  1344. break;
  1345. case PACKET_TYPE2:
  1346. break;
  1347. case PACKET_TYPE3:
  1348. r = r600_packet3_check(p, &pkt);
  1349. break;
  1350. default:
  1351. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1352. kfree(p->track);
  1353. p->track = NULL;
  1354. return -EINVAL;
  1355. }
  1356. if (r) {
  1357. kfree(p->track);
  1358. p->track = NULL;
  1359. return r;
  1360. }
  1361. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1362. #if 0
  1363. for (r = 0; r < p->ib->length_dw; r++) {
  1364. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  1365. mdelay(1);
  1366. }
  1367. #endif
  1368. kfree(p->track);
  1369. p->track = NULL;
  1370. return 0;
  1371. }
  1372. static int r600_cs_parser_relocs_legacy(struct radeon_cs_parser *p)
  1373. {
  1374. if (p->chunk_relocs_idx == -1) {
  1375. return 0;
  1376. }
  1377. p->relocs = kzalloc(sizeof(struct radeon_cs_reloc), GFP_KERNEL);
  1378. if (p->relocs == NULL) {
  1379. return -ENOMEM;
  1380. }
  1381. return 0;
  1382. }
  1383. /**
  1384. * cs_parser_fini() - clean parser states
  1385. * @parser: parser structure holding parsing context.
  1386. * @error: error number
  1387. *
  1388. * If error is set than unvalidate buffer, otherwise just free memory
  1389. * used by parsing context.
  1390. **/
  1391. static void r600_cs_parser_fini(struct radeon_cs_parser *parser, int error)
  1392. {
  1393. unsigned i;
  1394. kfree(parser->relocs);
  1395. for (i = 0; i < parser->nchunks; i++) {
  1396. kfree(parser->chunks[i].kdata);
  1397. kfree(parser->chunks[i].kpage[0]);
  1398. kfree(parser->chunks[i].kpage[1]);
  1399. }
  1400. kfree(parser->chunks);
  1401. kfree(parser->chunks_array);
  1402. }
  1403. int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
  1404. unsigned family, u32 *ib, int *l)
  1405. {
  1406. struct radeon_cs_parser parser;
  1407. struct radeon_cs_chunk *ib_chunk;
  1408. struct radeon_ib fake_ib;
  1409. struct r600_cs_track *track;
  1410. int r;
  1411. /* initialize tracker */
  1412. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1413. if (track == NULL)
  1414. return -ENOMEM;
  1415. r600_cs_track_init(track);
  1416. r600_cs_legacy_get_tiling_conf(dev, &track->npipes, &track->nbanks, &track->group_size);
  1417. /* initialize parser */
  1418. memset(&parser, 0, sizeof(struct radeon_cs_parser));
  1419. parser.filp = filp;
  1420. parser.dev = &dev->pdev->dev;
  1421. parser.rdev = NULL;
  1422. parser.family = family;
  1423. parser.ib = &fake_ib;
  1424. parser.track = track;
  1425. fake_ib.ptr = ib;
  1426. r = radeon_cs_parser_init(&parser, data);
  1427. if (r) {
  1428. DRM_ERROR("Failed to initialize parser !\n");
  1429. r600_cs_parser_fini(&parser, r);
  1430. return r;
  1431. }
  1432. r = r600_cs_parser_relocs_legacy(&parser);
  1433. if (r) {
  1434. DRM_ERROR("Failed to parse relocation !\n");
  1435. r600_cs_parser_fini(&parser, r);
  1436. return r;
  1437. }
  1438. /* Copy the packet into the IB, the parser will read from the
  1439. * input memory (cached) and write to the IB (which can be
  1440. * uncached). */
  1441. ib_chunk = &parser.chunks[parser.chunk_ib_idx];
  1442. parser.ib->length_dw = ib_chunk->length_dw;
  1443. *l = parser.ib->length_dw;
  1444. r = r600_cs_parse(&parser);
  1445. if (r) {
  1446. DRM_ERROR("Invalid command stream !\n");
  1447. r600_cs_parser_fini(&parser, r);
  1448. return r;
  1449. }
  1450. r = radeon_cs_finish_pages(&parser);
  1451. if (r) {
  1452. DRM_ERROR("Invalid command stream !\n");
  1453. r600_cs_parser_fini(&parser, r);
  1454. return r;
  1455. }
  1456. r600_cs_parser_fini(&parser, r);
  1457. return r;
  1458. }
  1459. void r600_cs_legacy_init(void)
  1460. {
  1461. r600_cs_packet_next_reloc = &r600_cs_packet_next_reloc_nomm;
  1462. }