evergreen_cs.c 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include "drmP.h"
  29. #include "radeon.h"
  30. #include "evergreend.h"
  31. #include "evergreen_reg_safe.h"
  32. #include "cayman_reg_safe.h"
  33. #define MAX(a,b) (((a)>(b))?(a):(b))
  34. #define MIN(a,b) (((a)<(b))?(a):(b))
  35. static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
  36. struct radeon_cs_reloc **cs_reloc);
  37. struct evergreen_cs_track {
  38. u32 group_size;
  39. u32 nbanks;
  40. u32 npipes;
  41. u32 row_size;
  42. /* value we track */
  43. u32 nsamples; /* unused */
  44. struct radeon_bo *cb_color_bo[12];
  45. u32 cb_color_bo_offset[12];
  46. struct radeon_bo *cb_color_fmask_bo[8]; /* unused */
  47. struct radeon_bo *cb_color_cmask_bo[8]; /* unused */
  48. u32 cb_color_info[12];
  49. u32 cb_color_view[12];
  50. u32 cb_color_pitch[12];
  51. u32 cb_color_slice[12];
  52. u32 cb_color_slice_idx[12];
  53. u32 cb_color_attrib[12];
  54. u32 cb_color_cmask_slice[8];/* unused */
  55. u32 cb_color_fmask_slice[8];/* unused */
  56. u32 cb_target_mask;
  57. u32 cb_shader_mask; /* unused */
  58. u32 vgt_strmout_config;
  59. u32 vgt_strmout_buffer_config;
  60. struct radeon_bo *vgt_strmout_bo[4];
  61. u32 vgt_strmout_bo_offset[4];
  62. u32 vgt_strmout_size[4];
  63. u32 db_depth_control;
  64. u32 db_depth_view;
  65. u32 db_depth_slice;
  66. u32 db_depth_size;
  67. u32 db_z_info;
  68. u32 db_z_read_offset;
  69. u32 db_z_write_offset;
  70. struct radeon_bo *db_z_read_bo;
  71. struct radeon_bo *db_z_write_bo;
  72. u32 db_s_info;
  73. u32 db_s_read_offset;
  74. u32 db_s_write_offset;
  75. struct radeon_bo *db_s_read_bo;
  76. struct radeon_bo *db_s_write_bo;
  77. bool sx_misc_kill_all_prims;
  78. bool cb_dirty;
  79. bool db_dirty;
  80. bool streamout_dirty;
  81. u32 htile_offset;
  82. u32 htile_surface;
  83. struct radeon_bo *htile_bo;
  84. };
  85. static u32 evergreen_cs_get_aray_mode(u32 tiling_flags)
  86. {
  87. if (tiling_flags & RADEON_TILING_MACRO)
  88. return ARRAY_2D_TILED_THIN1;
  89. else if (tiling_flags & RADEON_TILING_MICRO)
  90. return ARRAY_1D_TILED_THIN1;
  91. else
  92. return ARRAY_LINEAR_GENERAL;
  93. }
  94. static u32 evergreen_cs_get_num_banks(u32 nbanks)
  95. {
  96. switch (nbanks) {
  97. case 2:
  98. return ADDR_SURF_2_BANK;
  99. case 4:
  100. return ADDR_SURF_4_BANK;
  101. case 8:
  102. default:
  103. return ADDR_SURF_8_BANK;
  104. case 16:
  105. return ADDR_SURF_16_BANK;
  106. }
  107. }
  108. static void evergreen_cs_track_init(struct evergreen_cs_track *track)
  109. {
  110. int i;
  111. for (i = 0; i < 8; i++) {
  112. track->cb_color_fmask_bo[i] = NULL;
  113. track->cb_color_cmask_bo[i] = NULL;
  114. track->cb_color_cmask_slice[i] = 0;
  115. track->cb_color_fmask_slice[i] = 0;
  116. }
  117. for (i = 0; i < 12; i++) {
  118. track->cb_color_bo[i] = NULL;
  119. track->cb_color_bo_offset[i] = 0xFFFFFFFF;
  120. track->cb_color_info[i] = 0;
  121. track->cb_color_view[i] = 0xFFFFFFFF;
  122. track->cb_color_pitch[i] = 0;
  123. track->cb_color_slice[i] = 0xfffffff;
  124. track->cb_color_slice_idx[i] = 0;
  125. }
  126. track->cb_target_mask = 0xFFFFFFFF;
  127. track->cb_shader_mask = 0xFFFFFFFF;
  128. track->cb_dirty = true;
  129. track->db_depth_slice = 0xffffffff;
  130. track->db_depth_view = 0xFFFFC000;
  131. track->db_depth_size = 0xFFFFFFFF;
  132. track->db_depth_control = 0xFFFFFFFF;
  133. track->db_z_info = 0xFFFFFFFF;
  134. track->db_z_read_offset = 0xFFFFFFFF;
  135. track->db_z_write_offset = 0xFFFFFFFF;
  136. track->db_z_read_bo = NULL;
  137. track->db_z_write_bo = NULL;
  138. track->db_s_info = 0xFFFFFFFF;
  139. track->db_s_read_offset = 0xFFFFFFFF;
  140. track->db_s_write_offset = 0xFFFFFFFF;
  141. track->db_s_read_bo = NULL;
  142. track->db_s_write_bo = NULL;
  143. track->db_dirty = true;
  144. track->htile_bo = NULL;
  145. track->htile_offset = 0xFFFFFFFF;
  146. track->htile_surface = 0;
  147. for (i = 0; i < 4; i++) {
  148. track->vgt_strmout_size[i] = 0;
  149. track->vgt_strmout_bo[i] = NULL;
  150. track->vgt_strmout_bo_offset[i] = 0xFFFFFFFF;
  151. }
  152. track->streamout_dirty = true;
  153. track->sx_misc_kill_all_prims = false;
  154. }
  155. struct eg_surface {
  156. /* value gathered from cs */
  157. unsigned nbx;
  158. unsigned nby;
  159. unsigned format;
  160. unsigned mode;
  161. unsigned nbanks;
  162. unsigned bankw;
  163. unsigned bankh;
  164. unsigned tsplit;
  165. unsigned mtilea;
  166. unsigned nsamples;
  167. /* output value */
  168. unsigned bpe;
  169. unsigned layer_size;
  170. unsigned palign;
  171. unsigned halign;
  172. unsigned long base_align;
  173. };
  174. static int evergreen_surface_check_linear(struct radeon_cs_parser *p,
  175. struct eg_surface *surf,
  176. const char *prefix)
  177. {
  178. surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
  179. surf->base_align = surf->bpe;
  180. surf->palign = 1;
  181. surf->halign = 1;
  182. return 0;
  183. }
  184. static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
  185. struct eg_surface *surf,
  186. const char *prefix)
  187. {
  188. struct evergreen_cs_track *track = p->track;
  189. unsigned palign;
  190. palign = MAX(64, track->group_size / surf->bpe);
  191. surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
  192. surf->base_align = track->group_size;
  193. surf->palign = palign;
  194. surf->halign = 1;
  195. if (surf->nbx & (palign - 1)) {
  196. if (prefix) {
  197. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
  198. __func__, __LINE__, prefix, surf->nbx, palign);
  199. }
  200. return -EINVAL;
  201. }
  202. return 0;
  203. }
  204. static int evergreen_surface_check_1d(struct radeon_cs_parser *p,
  205. struct eg_surface *surf,
  206. const char *prefix)
  207. {
  208. struct evergreen_cs_track *track = p->track;
  209. unsigned palign;
  210. palign = track->group_size / (8 * surf->bpe * surf->nsamples);
  211. palign = MAX(8, palign);
  212. surf->layer_size = surf->nbx * surf->nby * surf->bpe;
  213. surf->base_align = track->group_size;
  214. surf->palign = palign;
  215. surf->halign = 8;
  216. if ((surf->nbx & (palign - 1))) {
  217. if (prefix) {
  218. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d (%d %d %d)\n",
  219. __func__, __LINE__, prefix, surf->nbx, palign,
  220. track->group_size, surf->bpe, surf->nsamples);
  221. }
  222. return -EINVAL;
  223. }
  224. if ((surf->nby & (8 - 1))) {
  225. if (prefix) {
  226. dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with 8\n",
  227. __func__, __LINE__, prefix, surf->nby);
  228. }
  229. return -EINVAL;
  230. }
  231. return 0;
  232. }
  233. static int evergreen_surface_check_2d(struct radeon_cs_parser *p,
  234. struct eg_surface *surf,
  235. const char *prefix)
  236. {
  237. struct evergreen_cs_track *track = p->track;
  238. unsigned palign, halign, tileb, slice_pt;
  239. unsigned mtile_pr, mtile_ps, mtileb;
  240. tileb = 64 * surf->bpe * surf->nsamples;
  241. slice_pt = 1;
  242. if (tileb > surf->tsplit) {
  243. slice_pt = tileb / surf->tsplit;
  244. }
  245. tileb = tileb / slice_pt;
  246. /* macro tile width & height */
  247. palign = (8 * surf->bankw * track->npipes) * surf->mtilea;
  248. halign = (8 * surf->bankh * surf->nbanks) / surf->mtilea;
  249. mtileb = (palign / 8) * (halign / 8) * tileb;;
  250. mtile_pr = surf->nbx / palign;
  251. mtile_ps = (mtile_pr * surf->nby) / halign;
  252. surf->layer_size = mtile_ps * mtileb * slice_pt;
  253. surf->base_align = (palign / 8) * (halign / 8) * tileb;
  254. surf->palign = palign;
  255. surf->halign = halign;
  256. if ((surf->nbx & (palign - 1))) {
  257. if (prefix) {
  258. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
  259. __func__, __LINE__, prefix, surf->nbx, palign);
  260. }
  261. return -EINVAL;
  262. }
  263. if ((surf->nby & (halign - 1))) {
  264. if (prefix) {
  265. dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with %d\n",
  266. __func__, __LINE__, prefix, surf->nby, halign);
  267. }
  268. return -EINVAL;
  269. }
  270. return 0;
  271. }
  272. static int evergreen_surface_check(struct radeon_cs_parser *p,
  273. struct eg_surface *surf,
  274. const char *prefix)
  275. {
  276. /* some common value computed here */
  277. surf->bpe = r600_fmt_get_blocksize(surf->format);
  278. switch (surf->mode) {
  279. case ARRAY_LINEAR_GENERAL:
  280. return evergreen_surface_check_linear(p, surf, prefix);
  281. case ARRAY_LINEAR_ALIGNED:
  282. return evergreen_surface_check_linear_aligned(p, surf, prefix);
  283. case ARRAY_1D_TILED_THIN1:
  284. return evergreen_surface_check_1d(p, surf, prefix);
  285. case ARRAY_2D_TILED_THIN1:
  286. return evergreen_surface_check_2d(p, surf, prefix);
  287. default:
  288. dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
  289. __func__, __LINE__, prefix, surf->mode);
  290. return -EINVAL;
  291. }
  292. return -EINVAL;
  293. }
  294. static int evergreen_surface_value_conv_check(struct radeon_cs_parser *p,
  295. struct eg_surface *surf,
  296. const char *prefix)
  297. {
  298. switch (surf->mode) {
  299. case ARRAY_2D_TILED_THIN1:
  300. break;
  301. case ARRAY_LINEAR_GENERAL:
  302. case ARRAY_LINEAR_ALIGNED:
  303. case ARRAY_1D_TILED_THIN1:
  304. return 0;
  305. default:
  306. dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
  307. __func__, __LINE__, prefix, surf->mode);
  308. return -EINVAL;
  309. }
  310. switch (surf->nbanks) {
  311. case 0: surf->nbanks = 2; break;
  312. case 1: surf->nbanks = 4; break;
  313. case 2: surf->nbanks = 8; break;
  314. case 3: surf->nbanks = 16; break;
  315. default:
  316. dev_warn(p->dev, "%s:%d %s invalid number of banks %d\n",
  317. __func__, __LINE__, prefix, surf->nbanks);
  318. return -EINVAL;
  319. }
  320. switch (surf->bankw) {
  321. case 0: surf->bankw = 1; break;
  322. case 1: surf->bankw = 2; break;
  323. case 2: surf->bankw = 4; break;
  324. case 3: surf->bankw = 8; break;
  325. default:
  326. dev_warn(p->dev, "%s:%d %s invalid bankw %d\n",
  327. __func__, __LINE__, prefix, surf->bankw);
  328. return -EINVAL;
  329. }
  330. switch (surf->bankh) {
  331. case 0: surf->bankh = 1; break;
  332. case 1: surf->bankh = 2; break;
  333. case 2: surf->bankh = 4; break;
  334. case 3: surf->bankh = 8; break;
  335. default:
  336. dev_warn(p->dev, "%s:%d %s invalid bankh %d\n",
  337. __func__, __LINE__, prefix, surf->bankh);
  338. return -EINVAL;
  339. }
  340. switch (surf->mtilea) {
  341. case 0: surf->mtilea = 1; break;
  342. case 1: surf->mtilea = 2; break;
  343. case 2: surf->mtilea = 4; break;
  344. case 3: surf->mtilea = 8; break;
  345. default:
  346. dev_warn(p->dev, "%s:%d %s invalid macro tile aspect %d\n",
  347. __func__, __LINE__, prefix, surf->mtilea);
  348. return -EINVAL;
  349. }
  350. switch (surf->tsplit) {
  351. case 0: surf->tsplit = 64; break;
  352. case 1: surf->tsplit = 128; break;
  353. case 2: surf->tsplit = 256; break;
  354. case 3: surf->tsplit = 512; break;
  355. case 4: surf->tsplit = 1024; break;
  356. case 5: surf->tsplit = 2048; break;
  357. case 6: surf->tsplit = 4096; break;
  358. default:
  359. dev_warn(p->dev, "%s:%d %s invalid tile split %d\n",
  360. __func__, __LINE__, prefix, surf->tsplit);
  361. return -EINVAL;
  362. }
  363. return 0;
  364. }
  365. static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned id)
  366. {
  367. struct evergreen_cs_track *track = p->track;
  368. struct eg_surface surf;
  369. unsigned pitch, slice, mslice;
  370. unsigned long offset;
  371. int r;
  372. mslice = G_028C6C_SLICE_MAX(track->cb_color_view[id]) + 1;
  373. pitch = track->cb_color_pitch[id];
  374. slice = track->cb_color_slice[id];
  375. surf.nbx = (pitch + 1) * 8;
  376. surf.nby = ((slice + 1) * 64) / surf.nbx;
  377. surf.mode = G_028C70_ARRAY_MODE(track->cb_color_info[id]);
  378. surf.format = G_028C70_FORMAT(track->cb_color_info[id]);
  379. surf.tsplit = G_028C74_TILE_SPLIT(track->cb_color_attrib[id]);
  380. surf.nbanks = G_028C74_NUM_BANKS(track->cb_color_attrib[id]);
  381. surf.bankw = G_028C74_BANK_WIDTH(track->cb_color_attrib[id]);
  382. surf.bankh = G_028C74_BANK_HEIGHT(track->cb_color_attrib[id]);
  383. surf.mtilea = G_028C74_MACRO_TILE_ASPECT(track->cb_color_attrib[id]);
  384. surf.nsamples = 1;
  385. if (!r600_fmt_is_valid_color(surf.format)) {
  386. dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08x)\n",
  387. __func__, __LINE__, surf.format,
  388. id, track->cb_color_info[id]);
  389. return -EINVAL;
  390. }
  391. r = evergreen_surface_value_conv_check(p, &surf, "cb");
  392. if (r) {
  393. return r;
  394. }
  395. r = evergreen_surface_check(p, &surf, "cb");
  396. if (r) {
  397. dev_warn(p->dev, "%s:%d cb[%d] invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  398. __func__, __LINE__, id, track->cb_color_pitch[id],
  399. track->cb_color_slice[id], track->cb_color_attrib[id],
  400. track->cb_color_info[id]);
  401. return r;
  402. }
  403. offset = track->cb_color_bo_offset[id] << 8;
  404. if (offset & (surf.base_align - 1)) {
  405. dev_warn(p->dev, "%s:%d cb[%d] bo base %ld not aligned with %ld\n",
  406. __func__, __LINE__, id, offset, surf.base_align);
  407. return -EINVAL;
  408. }
  409. offset += surf.layer_size * mslice;
  410. if (offset > radeon_bo_size(track->cb_color_bo[id])) {
  411. /* old ddx are broken they allocate bo with w*h*bpp but
  412. * program slice with ALIGN(h, 8), catch this and patch
  413. * command stream.
  414. */
  415. if (!surf.mode) {
  416. volatile u32 *ib = p->ib->ptr;
  417. unsigned long tmp, nby, bsize, size, min = 0;
  418. /* find the height the ddx wants */
  419. if (surf.nby > 8) {
  420. min = surf.nby - 8;
  421. }
  422. bsize = radeon_bo_size(track->cb_color_bo[id]);
  423. tmp = track->cb_color_bo_offset[id] << 8;
  424. for (nby = surf.nby; nby > min; nby--) {
  425. size = nby * surf.nbx * surf.bpe * surf.nsamples;
  426. if ((tmp + size * mslice) <= bsize) {
  427. break;
  428. }
  429. }
  430. if (nby > min) {
  431. surf.nby = nby;
  432. slice = ((nby * surf.nbx) / 64) - 1;
  433. if (!evergreen_surface_check(p, &surf, "cb")) {
  434. /* check if this one works */
  435. tmp += surf.layer_size * mslice;
  436. if (tmp <= bsize) {
  437. ib[track->cb_color_slice_idx[id]] = slice;
  438. goto old_ddx_ok;
  439. }
  440. }
  441. }
  442. }
  443. dev_warn(p->dev, "%s:%d cb[%d] bo too small (layer size %d, "
  444. "offset %d, max layer %d, bo size %ld, slice %d)\n",
  445. __func__, __LINE__, id, surf.layer_size,
  446. track->cb_color_bo_offset[id] << 8, mslice,
  447. radeon_bo_size(track->cb_color_bo[id]), slice);
  448. dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
  449. __func__, __LINE__, surf.nbx, surf.nby,
  450. surf.mode, surf.bpe, surf.nsamples,
  451. surf.bankw, surf.bankh,
  452. surf.tsplit, surf.mtilea);
  453. return -EINVAL;
  454. }
  455. old_ddx_ok:
  456. return 0;
  457. }
  458. static int evergreen_cs_track_validate_htile(struct radeon_cs_parser *p,
  459. unsigned nbx, unsigned nby)
  460. {
  461. struct evergreen_cs_track *track = p->track;
  462. unsigned long size;
  463. if (track->htile_bo == NULL) {
  464. dev_warn(p->dev, "%s:%d htile enabled without htile surface 0x%08x\n",
  465. __func__, __LINE__, track->db_z_info);
  466. return -EINVAL;
  467. }
  468. if (G_028ABC_LINEAR(track->htile_surface)) {
  469. /* pitch must be 16 htiles aligned == 16 * 8 pixel aligned */
  470. nbx = round_up(nbx, 16 * 8);
  471. /* height is npipes htiles aligned == npipes * 8 pixel aligned */
  472. nby = round_up(nby, track->npipes * 8);
  473. } else {
  474. switch (track->npipes) {
  475. case 8:
  476. nbx = round_up(nbx, 64 * 8);
  477. nby = round_up(nby, 64 * 8);
  478. break;
  479. case 4:
  480. nbx = round_up(nbx, 64 * 8);
  481. nby = round_up(nby, 32 * 8);
  482. break;
  483. case 2:
  484. nbx = round_up(nbx, 32 * 8);
  485. nby = round_up(nby, 32 * 8);
  486. break;
  487. case 1:
  488. nbx = round_up(nbx, 32 * 8);
  489. nby = round_up(nby, 16 * 8);
  490. break;
  491. default:
  492. dev_warn(p->dev, "%s:%d invalid num pipes %d\n",
  493. __func__, __LINE__, track->npipes);
  494. return -EINVAL;
  495. }
  496. }
  497. /* compute number of htile */
  498. nbx = nbx / 8;
  499. nby = nby / 8;
  500. size = nbx * nby * 4;
  501. size += track->htile_offset;
  502. if (size > radeon_bo_size(track->htile_bo)) {
  503. dev_warn(p->dev, "%s:%d htile surface too small %ld for %ld (%d %d)\n",
  504. __func__, __LINE__, radeon_bo_size(track->htile_bo),
  505. size, nbx, nby);
  506. return -EINVAL;
  507. }
  508. return 0;
  509. }
  510. static int evergreen_cs_track_validate_stencil(struct radeon_cs_parser *p)
  511. {
  512. struct evergreen_cs_track *track = p->track;
  513. struct eg_surface surf;
  514. unsigned pitch, slice, mslice;
  515. unsigned long offset;
  516. int r;
  517. mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
  518. pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
  519. slice = track->db_depth_slice;
  520. surf.nbx = (pitch + 1) * 8;
  521. surf.nby = ((slice + 1) * 64) / surf.nbx;
  522. surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
  523. surf.format = G_028044_FORMAT(track->db_s_info);
  524. surf.tsplit = G_028044_TILE_SPLIT(track->db_s_info);
  525. surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
  526. surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
  527. surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
  528. surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
  529. surf.nsamples = 1;
  530. if (surf.format != 1) {
  531. dev_warn(p->dev, "%s:%d stencil invalid format %d\n",
  532. __func__, __LINE__, surf.format);
  533. return -EINVAL;
  534. }
  535. /* replace by color format so we can use same code */
  536. surf.format = V_028C70_COLOR_8;
  537. r = evergreen_surface_value_conv_check(p, &surf, "stencil");
  538. if (r) {
  539. return r;
  540. }
  541. r = evergreen_surface_check(p, &surf, NULL);
  542. if (r) {
  543. /* old userspace doesn't compute proper depth/stencil alignment
  544. * check that alignment against a bigger byte per elements and
  545. * only report if that alignment is wrong too.
  546. */
  547. surf.format = V_028C70_COLOR_8_8_8_8;
  548. r = evergreen_surface_check(p, &surf, "stencil");
  549. if (r) {
  550. dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  551. __func__, __LINE__, track->db_depth_size,
  552. track->db_depth_slice, track->db_s_info, track->db_z_info);
  553. }
  554. return r;
  555. }
  556. offset = track->db_s_read_offset << 8;
  557. if (offset & (surf.base_align - 1)) {
  558. dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
  559. __func__, __LINE__, offset, surf.base_align);
  560. return -EINVAL;
  561. }
  562. offset += surf.layer_size * mslice;
  563. if (offset > radeon_bo_size(track->db_s_read_bo)) {
  564. dev_warn(p->dev, "%s:%d stencil read bo too small (layer size %d, "
  565. "offset %ld, max layer %d, bo size %ld)\n",
  566. __func__, __LINE__, surf.layer_size,
  567. (unsigned long)track->db_s_read_offset << 8, mslice,
  568. radeon_bo_size(track->db_s_read_bo));
  569. dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  570. __func__, __LINE__, track->db_depth_size,
  571. track->db_depth_slice, track->db_s_info, track->db_z_info);
  572. return -EINVAL;
  573. }
  574. offset = track->db_s_write_offset << 8;
  575. if (offset & (surf.base_align - 1)) {
  576. dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
  577. __func__, __LINE__, offset, surf.base_align);
  578. return -EINVAL;
  579. }
  580. offset += surf.layer_size * mslice;
  581. if (offset > radeon_bo_size(track->db_s_write_bo)) {
  582. dev_warn(p->dev, "%s:%d stencil write bo too small (layer size %d, "
  583. "offset %ld, max layer %d, bo size %ld)\n",
  584. __func__, __LINE__, surf.layer_size,
  585. (unsigned long)track->db_s_write_offset << 8, mslice,
  586. radeon_bo_size(track->db_s_write_bo));
  587. return -EINVAL;
  588. }
  589. /* hyperz */
  590. if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
  591. r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
  592. if (r) {
  593. return r;
  594. }
  595. }
  596. return 0;
  597. }
  598. static int evergreen_cs_track_validate_depth(struct radeon_cs_parser *p)
  599. {
  600. struct evergreen_cs_track *track = p->track;
  601. struct eg_surface surf;
  602. unsigned pitch, slice, mslice;
  603. unsigned long offset;
  604. int r;
  605. mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
  606. pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
  607. slice = track->db_depth_slice;
  608. surf.nbx = (pitch + 1) * 8;
  609. surf.nby = ((slice + 1) * 64) / surf.nbx;
  610. surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
  611. surf.format = G_028040_FORMAT(track->db_z_info);
  612. surf.tsplit = G_028040_TILE_SPLIT(track->db_z_info);
  613. surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
  614. surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
  615. surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
  616. surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
  617. surf.nsamples = 1;
  618. switch (surf.format) {
  619. case V_028040_Z_16:
  620. surf.format = V_028C70_COLOR_16;
  621. break;
  622. case V_028040_Z_24:
  623. case V_028040_Z_32_FLOAT:
  624. surf.format = V_028C70_COLOR_8_8_8_8;
  625. break;
  626. default:
  627. dev_warn(p->dev, "%s:%d depth invalid format %d\n",
  628. __func__, __LINE__, surf.format);
  629. return -EINVAL;
  630. }
  631. r = evergreen_surface_value_conv_check(p, &surf, "depth");
  632. if (r) {
  633. dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
  634. __func__, __LINE__, track->db_depth_size,
  635. track->db_depth_slice, track->db_z_info);
  636. return r;
  637. }
  638. r = evergreen_surface_check(p, &surf, "depth");
  639. if (r) {
  640. dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
  641. __func__, __LINE__, track->db_depth_size,
  642. track->db_depth_slice, track->db_z_info);
  643. return r;
  644. }
  645. offset = track->db_z_read_offset << 8;
  646. if (offset & (surf.base_align - 1)) {
  647. dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
  648. __func__, __LINE__, offset, surf.base_align);
  649. return -EINVAL;
  650. }
  651. offset += surf.layer_size * mslice;
  652. if (offset > radeon_bo_size(track->db_z_read_bo)) {
  653. dev_warn(p->dev, "%s:%d depth read bo too small (layer size %d, "
  654. "offset %ld, max layer %d, bo size %ld)\n",
  655. __func__, __LINE__, surf.layer_size,
  656. (unsigned long)track->db_z_read_offset << 8, mslice,
  657. radeon_bo_size(track->db_z_read_bo));
  658. return -EINVAL;
  659. }
  660. offset = track->db_z_write_offset << 8;
  661. if (offset & (surf.base_align - 1)) {
  662. dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
  663. __func__, __LINE__, offset, surf.base_align);
  664. return -EINVAL;
  665. }
  666. offset += surf.layer_size * mslice;
  667. if (offset > radeon_bo_size(track->db_z_write_bo)) {
  668. dev_warn(p->dev, "%s:%d depth write bo too small (layer size %d, "
  669. "offset %ld, max layer %d, bo size %ld)\n",
  670. __func__, __LINE__, surf.layer_size,
  671. (unsigned long)track->db_z_write_offset << 8, mslice,
  672. radeon_bo_size(track->db_z_write_bo));
  673. return -EINVAL;
  674. }
  675. /* hyperz */
  676. if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
  677. r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
  678. if (r) {
  679. return r;
  680. }
  681. }
  682. return 0;
  683. }
  684. static int evergreen_cs_track_validate_texture(struct radeon_cs_parser *p,
  685. struct radeon_bo *texture,
  686. struct radeon_bo *mipmap,
  687. unsigned idx)
  688. {
  689. struct eg_surface surf;
  690. unsigned long toffset, moffset;
  691. unsigned dim, llevel, mslice, width, height, depth, i;
  692. u32 texdw[8];
  693. int r;
  694. texdw[0] = radeon_get_ib_value(p, idx + 0);
  695. texdw[1] = radeon_get_ib_value(p, idx + 1);
  696. texdw[2] = radeon_get_ib_value(p, idx + 2);
  697. texdw[3] = radeon_get_ib_value(p, idx + 3);
  698. texdw[4] = radeon_get_ib_value(p, idx + 4);
  699. texdw[5] = radeon_get_ib_value(p, idx + 5);
  700. texdw[6] = radeon_get_ib_value(p, idx + 6);
  701. texdw[7] = radeon_get_ib_value(p, idx + 7);
  702. dim = G_030000_DIM(texdw[0]);
  703. llevel = G_030014_LAST_LEVEL(texdw[5]);
  704. mslice = G_030014_LAST_ARRAY(texdw[5]) + 1;
  705. width = G_030000_TEX_WIDTH(texdw[0]) + 1;
  706. height = G_030004_TEX_HEIGHT(texdw[1]) + 1;
  707. depth = G_030004_TEX_DEPTH(texdw[1]) + 1;
  708. surf.format = G_03001C_DATA_FORMAT(texdw[7]);
  709. surf.nbx = (G_030000_PITCH(texdw[0]) + 1) * 8;
  710. surf.nbx = r600_fmt_get_nblocksx(surf.format, surf.nbx);
  711. surf.nby = r600_fmt_get_nblocksy(surf.format, height);
  712. surf.mode = G_030004_ARRAY_MODE(texdw[1]);
  713. surf.tsplit = G_030018_TILE_SPLIT(texdw[6]);
  714. surf.nbanks = G_03001C_NUM_BANKS(texdw[7]);
  715. surf.bankw = G_03001C_BANK_WIDTH(texdw[7]);
  716. surf.bankh = G_03001C_BANK_HEIGHT(texdw[7]);
  717. surf.mtilea = G_03001C_MACRO_TILE_ASPECT(texdw[7]);
  718. surf.nsamples = 1;
  719. toffset = texdw[2] << 8;
  720. moffset = texdw[3] << 8;
  721. if (!r600_fmt_is_valid_texture(surf.format, p->family)) {
  722. dev_warn(p->dev, "%s:%d texture invalid format %d\n",
  723. __func__, __LINE__, surf.format);
  724. return -EINVAL;
  725. }
  726. switch (dim) {
  727. case V_030000_SQ_TEX_DIM_1D:
  728. case V_030000_SQ_TEX_DIM_2D:
  729. case V_030000_SQ_TEX_DIM_CUBEMAP:
  730. case V_030000_SQ_TEX_DIM_1D_ARRAY:
  731. case V_030000_SQ_TEX_DIM_2D_ARRAY:
  732. depth = 1;
  733. case V_030000_SQ_TEX_DIM_3D:
  734. break;
  735. default:
  736. dev_warn(p->dev, "%s:%d texture invalid dimension %d\n",
  737. __func__, __LINE__, dim);
  738. return -EINVAL;
  739. }
  740. r = evergreen_surface_value_conv_check(p, &surf, "texture");
  741. if (r) {
  742. return r;
  743. }
  744. /* align height */
  745. evergreen_surface_check(p, &surf, NULL);
  746. surf.nby = ALIGN(surf.nby, surf.halign);
  747. r = evergreen_surface_check(p, &surf, "texture");
  748. if (r) {
  749. dev_warn(p->dev, "%s:%d texture invalid 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  750. __func__, __LINE__, texdw[0], texdw[1], texdw[4],
  751. texdw[5], texdw[6], texdw[7]);
  752. return r;
  753. }
  754. /* check texture size */
  755. if (toffset & (surf.base_align - 1)) {
  756. dev_warn(p->dev, "%s:%d texture bo base %ld not aligned with %ld\n",
  757. __func__, __LINE__, toffset, surf.base_align);
  758. return -EINVAL;
  759. }
  760. if (moffset & (surf.base_align - 1)) {
  761. dev_warn(p->dev, "%s:%d mipmap bo base %ld not aligned with %ld\n",
  762. __func__, __LINE__, moffset, surf.base_align);
  763. return -EINVAL;
  764. }
  765. if (dim == SQ_TEX_DIM_3D) {
  766. toffset += surf.layer_size * depth;
  767. } else {
  768. toffset += surf.layer_size * mslice;
  769. }
  770. if (toffset > radeon_bo_size(texture)) {
  771. dev_warn(p->dev, "%s:%d texture bo too small (layer size %d, "
  772. "offset %ld, max layer %d, depth %d, bo size %ld) (%d %d)\n",
  773. __func__, __LINE__, surf.layer_size,
  774. (unsigned long)texdw[2] << 8, mslice,
  775. depth, radeon_bo_size(texture),
  776. surf.nbx, surf.nby);
  777. return -EINVAL;
  778. }
  779. /* check mipmap size */
  780. for (i = 1; i <= llevel; i++) {
  781. unsigned w, h, d;
  782. w = r600_mip_minify(width, i);
  783. h = r600_mip_minify(height, i);
  784. d = r600_mip_minify(depth, i);
  785. surf.nbx = r600_fmt_get_nblocksx(surf.format, w);
  786. surf.nby = r600_fmt_get_nblocksy(surf.format, h);
  787. switch (surf.mode) {
  788. case ARRAY_2D_TILED_THIN1:
  789. if (surf.nbx < surf.palign || surf.nby < surf.halign) {
  790. surf.mode = ARRAY_1D_TILED_THIN1;
  791. }
  792. /* recompute alignment */
  793. evergreen_surface_check(p, &surf, NULL);
  794. break;
  795. case ARRAY_LINEAR_GENERAL:
  796. case ARRAY_LINEAR_ALIGNED:
  797. case ARRAY_1D_TILED_THIN1:
  798. break;
  799. default:
  800. dev_warn(p->dev, "%s:%d invalid array mode %d\n",
  801. __func__, __LINE__, surf.mode);
  802. return -EINVAL;
  803. }
  804. surf.nbx = ALIGN(surf.nbx, surf.palign);
  805. surf.nby = ALIGN(surf.nby, surf.halign);
  806. r = evergreen_surface_check(p, &surf, "mipmap");
  807. if (r) {
  808. return r;
  809. }
  810. if (dim == SQ_TEX_DIM_3D) {
  811. moffset += surf.layer_size * d;
  812. } else {
  813. moffset += surf.layer_size * mslice;
  814. }
  815. if (moffset > radeon_bo_size(mipmap)) {
  816. dev_warn(p->dev, "%s:%d mipmap [%d] bo too small (layer size %d, "
  817. "offset %ld, coffset %ld, max layer %d, depth %d, "
  818. "bo size %ld) level0 (%d %d %d)\n",
  819. __func__, __LINE__, i, surf.layer_size,
  820. (unsigned long)texdw[3] << 8, moffset, mslice,
  821. d, radeon_bo_size(mipmap),
  822. width, height, depth);
  823. dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
  824. __func__, __LINE__, surf.nbx, surf.nby,
  825. surf.mode, surf.bpe, surf.nsamples,
  826. surf.bankw, surf.bankh,
  827. surf.tsplit, surf.mtilea);
  828. return -EINVAL;
  829. }
  830. }
  831. return 0;
  832. }
  833. static int evergreen_cs_track_check(struct radeon_cs_parser *p)
  834. {
  835. struct evergreen_cs_track *track = p->track;
  836. unsigned tmp, i;
  837. int r;
  838. unsigned buffer_mask = 0;
  839. /* check streamout */
  840. if (track->streamout_dirty && track->vgt_strmout_config) {
  841. for (i = 0; i < 4; i++) {
  842. if (track->vgt_strmout_config & (1 << i)) {
  843. buffer_mask |= (track->vgt_strmout_buffer_config >> (i * 4)) & 0xf;
  844. }
  845. }
  846. for (i = 0; i < 4; i++) {
  847. if (buffer_mask & (1 << i)) {
  848. if (track->vgt_strmout_bo[i]) {
  849. u64 offset = (u64)track->vgt_strmout_bo_offset[i] +
  850. (u64)track->vgt_strmout_size[i];
  851. if (offset > radeon_bo_size(track->vgt_strmout_bo[i])) {
  852. DRM_ERROR("streamout %d bo too small: 0x%llx, 0x%lx\n",
  853. i, offset,
  854. radeon_bo_size(track->vgt_strmout_bo[i]));
  855. return -EINVAL;
  856. }
  857. } else {
  858. dev_warn(p->dev, "No buffer for streamout %d\n", i);
  859. return -EINVAL;
  860. }
  861. }
  862. }
  863. track->streamout_dirty = false;
  864. }
  865. if (track->sx_misc_kill_all_prims)
  866. return 0;
  867. /* check that we have a cb for each enabled target
  868. */
  869. if (track->cb_dirty) {
  870. tmp = track->cb_target_mask;
  871. for (i = 0; i < 8; i++) {
  872. u32 format = G_028C70_FORMAT(track->cb_color_info[i]);
  873. if (format != V_028C70_COLOR_INVALID &&
  874. (tmp >> (i * 4)) & 0xF) {
  875. /* at least one component is enabled */
  876. if (track->cb_color_bo[i] == NULL) {
  877. dev_warn(p->dev, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
  878. __func__, __LINE__, track->cb_target_mask, track->cb_shader_mask, i);
  879. return -EINVAL;
  880. }
  881. /* check cb */
  882. r = evergreen_cs_track_validate_cb(p, i);
  883. if (r) {
  884. return r;
  885. }
  886. }
  887. }
  888. track->cb_dirty = false;
  889. }
  890. if (track->db_dirty) {
  891. /* Check stencil buffer */
  892. if (G_028800_STENCIL_ENABLE(track->db_depth_control)) {
  893. r = evergreen_cs_track_validate_stencil(p);
  894. if (r)
  895. return r;
  896. }
  897. /* Check depth buffer */
  898. if (G_028800_Z_ENABLE(track->db_depth_control)) {
  899. r = evergreen_cs_track_validate_depth(p);
  900. if (r)
  901. return r;
  902. }
  903. track->db_dirty = false;
  904. }
  905. return 0;
  906. }
  907. /**
  908. * evergreen_cs_packet_parse() - parse cp packet and point ib index to next packet
  909. * @parser: parser structure holding parsing context.
  910. * @pkt: where to store packet informations
  911. *
  912. * Assume that chunk_ib_index is properly set. Will return -EINVAL
  913. * if packet is bigger than remaining ib size. or if packets is unknown.
  914. **/
  915. int evergreen_cs_packet_parse(struct radeon_cs_parser *p,
  916. struct radeon_cs_packet *pkt,
  917. unsigned idx)
  918. {
  919. struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
  920. uint32_t header;
  921. if (idx >= ib_chunk->length_dw) {
  922. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  923. idx, ib_chunk->length_dw);
  924. return -EINVAL;
  925. }
  926. header = radeon_get_ib_value(p, idx);
  927. pkt->idx = idx;
  928. pkt->type = CP_PACKET_GET_TYPE(header);
  929. pkt->count = CP_PACKET_GET_COUNT(header);
  930. pkt->one_reg_wr = 0;
  931. switch (pkt->type) {
  932. case PACKET_TYPE0:
  933. pkt->reg = CP_PACKET0_GET_REG(header);
  934. break;
  935. case PACKET_TYPE3:
  936. pkt->opcode = CP_PACKET3_GET_OPCODE(header);
  937. break;
  938. case PACKET_TYPE2:
  939. pkt->count = -1;
  940. break;
  941. default:
  942. DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
  943. return -EINVAL;
  944. }
  945. if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
  946. DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
  947. pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
  948. return -EINVAL;
  949. }
  950. return 0;
  951. }
  952. /**
  953. * evergreen_cs_packet_next_reloc() - parse next packet which should be reloc packet3
  954. * @parser: parser structure holding parsing context.
  955. * @data: pointer to relocation data
  956. * @offset_start: starting offset
  957. * @offset_mask: offset mask (to align start offset on)
  958. * @reloc: reloc informations
  959. *
  960. * Check next packet is relocation packet3, do bo validation and compute
  961. * GPU offset using the provided start.
  962. **/
  963. static int evergreen_cs_packet_next_reloc(struct radeon_cs_parser *p,
  964. struct radeon_cs_reloc **cs_reloc)
  965. {
  966. struct radeon_cs_chunk *relocs_chunk;
  967. struct radeon_cs_packet p3reloc;
  968. unsigned idx;
  969. int r;
  970. if (p->chunk_relocs_idx == -1) {
  971. DRM_ERROR("No relocation chunk !\n");
  972. return -EINVAL;
  973. }
  974. *cs_reloc = NULL;
  975. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  976. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx);
  977. if (r) {
  978. return r;
  979. }
  980. p->idx += p3reloc.count + 2;
  981. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  982. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  983. p3reloc.idx);
  984. return -EINVAL;
  985. }
  986. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  987. if (idx >= relocs_chunk->length_dw) {
  988. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  989. idx, relocs_chunk->length_dw);
  990. return -EINVAL;
  991. }
  992. /* FIXME: we assume reloc size is 4 dwords */
  993. *cs_reloc = p->relocs_ptr[(idx / 4)];
  994. return 0;
  995. }
  996. /**
  997. * evergreen_cs_packet_next_vline() - parse userspace VLINE packet
  998. * @parser: parser structure holding parsing context.
  999. *
  1000. * Userspace sends a special sequence for VLINE waits.
  1001. * PACKET0 - VLINE_START_END + value
  1002. * PACKET3 - WAIT_REG_MEM poll vline status reg
  1003. * RELOC (P3) - crtc_id in reloc.
  1004. *
  1005. * This function parses this and relocates the VLINE START END
  1006. * and WAIT_REG_MEM packets to the correct crtc.
  1007. * It also detects a switched off crtc and nulls out the
  1008. * wait in that case.
  1009. */
  1010. static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
  1011. {
  1012. struct drm_mode_object *obj;
  1013. struct drm_crtc *crtc;
  1014. struct radeon_crtc *radeon_crtc;
  1015. struct radeon_cs_packet p3reloc, wait_reg_mem;
  1016. int crtc_id;
  1017. int r;
  1018. uint32_t header, h_idx, reg, wait_reg_mem_info;
  1019. volatile uint32_t *ib;
  1020. ib = p->ib->ptr;
  1021. /* parse the WAIT_REG_MEM */
  1022. r = evergreen_cs_packet_parse(p, &wait_reg_mem, p->idx);
  1023. if (r)
  1024. return r;
  1025. /* check its a WAIT_REG_MEM */
  1026. if (wait_reg_mem.type != PACKET_TYPE3 ||
  1027. wait_reg_mem.opcode != PACKET3_WAIT_REG_MEM) {
  1028. DRM_ERROR("vline wait missing WAIT_REG_MEM segment\n");
  1029. return -EINVAL;
  1030. }
  1031. wait_reg_mem_info = radeon_get_ib_value(p, wait_reg_mem.idx + 1);
  1032. /* bit 4 is reg (0) or mem (1) */
  1033. if (wait_reg_mem_info & 0x10) {
  1034. DRM_ERROR("vline WAIT_REG_MEM waiting on MEM rather than REG\n");
  1035. return -EINVAL;
  1036. }
  1037. /* waiting for value to be equal */
  1038. if ((wait_reg_mem_info & 0x7) != 0x3) {
  1039. DRM_ERROR("vline WAIT_REG_MEM function not equal\n");
  1040. return -EINVAL;
  1041. }
  1042. if ((radeon_get_ib_value(p, wait_reg_mem.idx + 2) << 2) != EVERGREEN_VLINE_STATUS) {
  1043. DRM_ERROR("vline WAIT_REG_MEM bad reg\n");
  1044. return -EINVAL;
  1045. }
  1046. if (radeon_get_ib_value(p, wait_reg_mem.idx + 5) != EVERGREEN_VLINE_STAT) {
  1047. DRM_ERROR("vline WAIT_REG_MEM bad bit mask\n");
  1048. return -EINVAL;
  1049. }
  1050. /* jump over the NOP */
  1051. r = evergreen_cs_packet_parse(p, &p3reloc, p->idx + wait_reg_mem.count + 2);
  1052. if (r)
  1053. return r;
  1054. h_idx = p->idx - 2;
  1055. p->idx += wait_reg_mem.count + 2;
  1056. p->idx += p3reloc.count + 2;
  1057. header = radeon_get_ib_value(p, h_idx);
  1058. crtc_id = radeon_get_ib_value(p, h_idx + 2 + 7 + 1);
  1059. reg = CP_PACKET0_GET_REG(header);
  1060. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  1061. if (!obj) {
  1062. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  1063. return -EINVAL;
  1064. }
  1065. crtc = obj_to_crtc(obj);
  1066. radeon_crtc = to_radeon_crtc(crtc);
  1067. crtc_id = radeon_crtc->crtc_id;
  1068. if (!crtc->enabled) {
  1069. /* if the CRTC isn't enabled - we need to nop out the WAIT_REG_MEM */
  1070. ib[h_idx + 2] = PACKET2(0);
  1071. ib[h_idx + 3] = PACKET2(0);
  1072. ib[h_idx + 4] = PACKET2(0);
  1073. ib[h_idx + 5] = PACKET2(0);
  1074. ib[h_idx + 6] = PACKET2(0);
  1075. ib[h_idx + 7] = PACKET2(0);
  1076. ib[h_idx + 8] = PACKET2(0);
  1077. } else {
  1078. switch (reg) {
  1079. case EVERGREEN_VLINE_START_END:
  1080. header &= ~R600_CP_PACKET0_REG_MASK;
  1081. header |= (EVERGREEN_VLINE_START_END + radeon_crtc->crtc_offset) >> 2;
  1082. ib[h_idx] = header;
  1083. ib[h_idx + 4] = (EVERGREEN_VLINE_STATUS + radeon_crtc->crtc_offset) >> 2;
  1084. break;
  1085. default:
  1086. DRM_ERROR("unknown crtc reloc\n");
  1087. return -EINVAL;
  1088. }
  1089. }
  1090. return 0;
  1091. }
  1092. static int evergreen_packet0_check(struct radeon_cs_parser *p,
  1093. struct radeon_cs_packet *pkt,
  1094. unsigned idx, unsigned reg)
  1095. {
  1096. int r;
  1097. switch (reg) {
  1098. case EVERGREEN_VLINE_START_END:
  1099. r = evergreen_cs_packet_parse_vline(p);
  1100. if (r) {
  1101. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1102. idx, reg);
  1103. return r;
  1104. }
  1105. break;
  1106. default:
  1107. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  1108. reg, idx);
  1109. return -EINVAL;
  1110. }
  1111. return 0;
  1112. }
  1113. static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
  1114. struct radeon_cs_packet *pkt)
  1115. {
  1116. unsigned reg, i;
  1117. unsigned idx;
  1118. int r;
  1119. idx = pkt->idx + 1;
  1120. reg = pkt->reg;
  1121. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  1122. r = evergreen_packet0_check(p, pkt, idx, reg);
  1123. if (r) {
  1124. return r;
  1125. }
  1126. }
  1127. return 0;
  1128. }
  1129. /**
  1130. * evergreen_cs_check_reg() - check if register is authorized or not
  1131. * @parser: parser structure holding parsing context
  1132. * @reg: register we are testing
  1133. * @idx: index into the cs buffer
  1134. *
  1135. * This function will test against evergreen_reg_safe_bm and return 0
  1136. * if register is safe. If register is not flag as safe this function
  1137. * will test it against a list of register needind special handling.
  1138. */
  1139. static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  1140. {
  1141. struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
  1142. struct radeon_cs_reloc *reloc;
  1143. u32 last_reg;
  1144. u32 m, i, tmp, *ib;
  1145. int r;
  1146. if (p->rdev->family >= CHIP_CAYMAN)
  1147. last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
  1148. else
  1149. last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
  1150. i = (reg >> 7);
  1151. if (i >= last_reg) {
  1152. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  1153. return -EINVAL;
  1154. }
  1155. m = 1 << ((reg >> 2) & 31);
  1156. if (p->rdev->family >= CHIP_CAYMAN) {
  1157. if (!(cayman_reg_safe_bm[i] & m))
  1158. return 0;
  1159. } else {
  1160. if (!(evergreen_reg_safe_bm[i] & m))
  1161. return 0;
  1162. }
  1163. ib = p->ib->ptr;
  1164. switch (reg) {
  1165. /* force following reg to 0 in an attempt to disable out buffer
  1166. * which will need us to better understand how it works to perform
  1167. * security check on it (Jerome)
  1168. */
  1169. case SQ_ESGS_RING_SIZE:
  1170. case SQ_GSVS_RING_SIZE:
  1171. case SQ_ESTMP_RING_SIZE:
  1172. case SQ_GSTMP_RING_SIZE:
  1173. case SQ_HSTMP_RING_SIZE:
  1174. case SQ_LSTMP_RING_SIZE:
  1175. case SQ_PSTMP_RING_SIZE:
  1176. case SQ_VSTMP_RING_SIZE:
  1177. case SQ_ESGS_RING_ITEMSIZE:
  1178. case SQ_ESTMP_RING_ITEMSIZE:
  1179. case SQ_GSTMP_RING_ITEMSIZE:
  1180. case SQ_GSVS_RING_ITEMSIZE:
  1181. case SQ_GS_VERT_ITEMSIZE:
  1182. case SQ_GS_VERT_ITEMSIZE_1:
  1183. case SQ_GS_VERT_ITEMSIZE_2:
  1184. case SQ_GS_VERT_ITEMSIZE_3:
  1185. case SQ_GSVS_RING_OFFSET_1:
  1186. case SQ_GSVS_RING_OFFSET_2:
  1187. case SQ_GSVS_RING_OFFSET_3:
  1188. case SQ_HSTMP_RING_ITEMSIZE:
  1189. case SQ_LSTMP_RING_ITEMSIZE:
  1190. case SQ_PSTMP_RING_ITEMSIZE:
  1191. case SQ_VSTMP_RING_ITEMSIZE:
  1192. case VGT_TF_RING_SIZE:
  1193. /* get value to populate the IB don't remove */
  1194. /*tmp =radeon_get_ib_value(p, idx);
  1195. ib[idx] = 0;*/
  1196. break;
  1197. case SQ_ESGS_RING_BASE:
  1198. case SQ_GSVS_RING_BASE:
  1199. case SQ_ESTMP_RING_BASE:
  1200. case SQ_GSTMP_RING_BASE:
  1201. case SQ_HSTMP_RING_BASE:
  1202. case SQ_LSTMP_RING_BASE:
  1203. case SQ_PSTMP_RING_BASE:
  1204. case SQ_VSTMP_RING_BASE:
  1205. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1206. if (r) {
  1207. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1208. "0x%04X\n", reg);
  1209. return -EINVAL;
  1210. }
  1211. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1212. break;
  1213. case DB_DEPTH_CONTROL:
  1214. track->db_depth_control = radeon_get_ib_value(p, idx);
  1215. track->db_dirty = true;
  1216. break;
  1217. case CAYMAN_DB_EQAA:
  1218. if (p->rdev->family < CHIP_CAYMAN) {
  1219. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1220. "0x%04X\n", reg);
  1221. return -EINVAL;
  1222. }
  1223. break;
  1224. case CAYMAN_DB_DEPTH_INFO:
  1225. if (p->rdev->family < CHIP_CAYMAN) {
  1226. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1227. "0x%04X\n", reg);
  1228. return -EINVAL;
  1229. }
  1230. break;
  1231. case DB_Z_INFO:
  1232. track->db_z_info = radeon_get_ib_value(p, idx);
  1233. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1234. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1235. if (r) {
  1236. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1237. "0x%04X\n", reg);
  1238. return -EINVAL;
  1239. }
  1240. ib[idx] &= ~Z_ARRAY_MODE(0xf);
  1241. track->db_z_info &= ~Z_ARRAY_MODE(0xf);
  1242. ib[idx] |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1243. track->db_z_info |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1244. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  1245. unsigned bankw, bankh, mtaspect, tile_split;
  1246. evergreen_tiling_fields(reloc->lobj.tiling_flags,
  1247. &bankw, &bankh, &mtaspect,
  1248. &tile_split);
  1249. ib[idx] |= DB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1250. ib[idx] |= DB_TILE_SPLIT(tile_split) |
  1251. DB_BANK_WIDTH(bankw) |
  1252. DB_BANK_HEIGHT(bankh) |
  1253. DB_MACRO_TILE_ASPECT(mtaspect);
  1254. }
  1255. }
  1256. track->db_dirty = true;
  1257. break;
  1258. case DB_STENCIL_INFO:
  1259. track->db_s_info = radeon_get_ib_value(p, idx);
  1260. track->db_dirty = true;
  1261. break;
  1262. case DB_DEPTH_VIEW:
  1263. track->db_depth_view = radeon_get_ib_value(p, idx);
  1264. track->db_dirty = true;
  1265. break;
  1266. case DB_DEPTH_SIZE:
  1267. track->db_depth_size = radeon_get_ib_value(p, idx);
  1268. track->db_dirty = true;
  1269. break;
  1270. case R_02805C_DB_DEPTH_SLICE:
  1271. track->db_depth_slice = radeon_get_ib_value(p, idx);
  1272. track->db_dirty = true;
  1273. break;
  1274. case DB_Z_READ_BASE:
  1275. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1276. if (r) {
  1277. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1278. "0x%04X\n", reg);
  1279. return -EINVAL;
  1280. }
  1281. track->db_z_read_offset = radeon_get_ib_value(p, idx);
  1282. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1283. track->db_z_read_bo = reloc->robj;
  1284. track->db_dirty = true;
  1285. break;
  1286. case DB_Z_WRITE_BASE:
  1287. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1288. if (r) {
  1289. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1290. "0x%04X\n", reg);
  1291. return -EINVAL;
  1292. }
  1293. track->db_z_write_offset = radeon_get_ib_value(p, idx);
  1294. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1295. track->db_z_write_bo = reloc->robj;
  1296. track->db_dirty = true;
  1297. break;
  1298. case DB_STENCIL_READ_BASE:
  1299. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1300. if (r) {
  1301. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1302. "0x%04X\n", reg);
  1303. return -EINVAL;
  1304. }
  1305. track->db_s_read_offset = radeon_get_ib_value(p, idx);
  1306. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1307. track->db_s_read_bo = reloc->robj;
  1308. track->db_dirty = true;
  1309. break;
  1310. case DB_STENCIL_WRITE_BASE:
  1311. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1312. if (r) {
  1313. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1314. "0x%04X\n", reg);
  1315. return -EINVAL;
  1316. }
  1317. track->db_s_write_offset = radeon_get_ib_value(p, idx);
  1318. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1319. track->db_s_write_bo = reloc->robj;
  1320. track->db_dirty = true;
  1321. break;
  1322. case VGT_STRMOUT_CONFIG:
  1323. track->vgt_strmout_config = radeon_get_ib_value(p, idx);
  1324. track->streamout_dirty = true;
  1325. break;
  1326. case VGT_STRMOUT_BUFFER_CONFIG:
  1327. track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
  1328. track->streamout_dirty = true;
  1329. break;
  1330. case VGT_STRMOUT_BUFFER_BASE_0:
  1331. case VGT_STRMOUT_BUFFER_BASE_1:
  1332. case VGT_STRMOUT_BUFFER_BASE_2:
  1333. case VGT_STRMOUT_BUFFER_BASE_3:
  1334. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1335. if (r) {
  1336. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1337. "0x%04X\n", reg);
  1338. return -EINVAL;
  1339. }
  1340. tmp = (reg - VGT_STRMOUT_BUFFER_BASE_0) / 16;
  1341. track->vgt_strmout_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
  1342. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1343. track->vgt_strmout_bo[tmp] = reloc->robj;
  1344. track->streamout_dirty = true;
  1345. break;
  1346. case VGT_STRMOUT_BUFFER_SIZE_0:
  1347. case VGT_STRMOUT_BUFFER_SIZE_1:
  1348. case VGT_STRMOUT_BUFFER_SIZE_2:
  1349. case VGT_STRMOUT_BUFFER_SIZE_3:
  1350. tmp = (reg - VGT_STRMOUT_BUFFER_SIZE_0) / 16;
  1351. /* size in register is DWs, convert to bytes */
  1352. track->vgt_strmout_size[tmp] = radeon_get_ib_value(p, idx) * 4;
  1353. track->streamout_dirty = true;
  1354. break;
  1355. case CP_COHER_BASE:
  1356. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1357. if (r) {
  1358. dev_warn(p->dev, "missing reloc for CP_COHER_BASE "
  1359. "0x%04X\n", reg);
  1360. return -EINVAL;
  1361. }
  1362. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1363. case CB_TARGET_MASK:
  1364. track->cb_target_mask = radeon_get_ib_value(p, idx);
  1365. track->cb_dirty = true;
  1366. break;
  1367. case CB_SHADER_MASK:
  1368. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  1369. track->cb_dirty = true;
  1370. break;
  1371. case PA_SC_AA_CONFIG:
  1372. if (p->rdev->family >= CHIP_CAYMAN) {
  1373. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1374. "0x%04X\n", reg);
  1375. return -EINVAL;
  1376. }
  1377. tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
  1378. track->nsamples = 1 << tmp;
  1379. break;
  1380. case CAYMAN_PA_SC_AA_CONFIG:
  1381. if (p->rdev->family < CHIP_CAYMAN) {
  1382. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1383. "0x%04X\n", reg);
  1384. return -EINVAL;
  1385. }
  1386. tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
  1387. track->nsamples = 1 << tmp;
  1388. break;
  1389. case CB_COLOR0_VIEW:
  1390. case CB_COLOR1_VIEW:
  1391. case CB_COLOR2_VIEW:
  1392. case CB_COLOR3_VIEW:
  1393. case CB_COLOR4_VIEW:
  1394. case CB_COLOR5_VIEW:
  1395. case CB_COLOR6_VIEW:
  1396. case CB_COLOR7_VIEW:
  1397. tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
  1398. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  1399. track->cb_dirty = true;
  1400. break;
  1401. case CB_COLOR8_VIEW:
  1402. case CB_COLOR9_VIEW:
  1403. case CB_COLOR10_VIEW:
  1404. case CB_COLOR11_VIEW:
  1405. tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
  1406. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  1407. track->cb_dirty = true;
  1408. break;
  1409. case CB_COLOR0_INFO:
  1410. case CB_COLOR1_INFO:
  1411. case CB_COLOR2_INFO:
  1412. case CB_COLOR3_INFO:
  1413. case CB_COLOR4_INFO:
  1414. case CB_COLOR5_INFO:
  1415. case CB_COLOR6_INFO:
  1416. case CB_COLOR7_INFO:
  1417. tmp = (reg - CB_COLOR0_INFO) / 0x3c;
  1418. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  1419. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1420. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1421. if (r) {
  1422. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1423. "0x%04X\n", reg);
  1424. return -EINVAL;
  1425. }
  1426. ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1427. track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1428. }
  1429. track->cb_dirty = true;
  1430. break;
  1431. case CB_COLOR8_INFO:
  1432. case CB_COLOR9_INFO:
  1433. case CB_COLOR10_INFO:
  1434. case CB_COLOR11_INFO:
  1435. tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
  1436. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  1437. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1438. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1439. if (r) {
  1440. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1441. "0x%04X\n", reg);
  1442. return -EINVAL;
  1443. }
  1444. ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1445. track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  1446. }
  1447. track->cb_dirty = true;
  1448. break;
  1449. case CB_COLOR0_PITCH:
  1450. case CB_COLOR1_PITCH:
  1451. case CB_COLOR2_PITCH:
  1452. case CB_COLOR3_PITCH:
  1453. case CB_COLOR4_PITCH:
  1454. case CB_COLOR5_PITCH:
  1455. case CB_COLOR6_PITCH:
  1456. case CB_COLOR7_PITCH:
  1457. tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
  1458. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  1459. track->cb_dirty = true;
  1460. break;
  1461. case CB_COLOR8_PITCH:
  1462. case CB_COLOR9_PITCH:
  1463. case CB_COLOR10_PITCH:
  1464. case CB_COLOR11_PITCH:
  1465. tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
  1466. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  1467. track->cb_dirty = true;
  1468. break;
  1469. case CB_COLOR0_SLICE:
  1470. case CB_COLOR1_SLICE:
  1471. case CB_COLOR2_SLICE:
  1472. case CB_COLOR3_SLICE:
  1473. case CB_COLOR4_SLICE:
  1474. case CB_COLOR5_SLICE:
  1475. case CB_COLOR6_SLICE:
  1476. case CB_COLOR7_SLICE:
  1477. tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
  1478. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  1479. track->cb_color_slice_idx[tmp] = idx;
  1480. track->cb_dirty = true;
  1481. break;
  1482. case CB_COLOR8_SLICE:
  1483. case CB_COLOR9_SLICE:
  1484. case CB_COLOR10_SLICE:
  1485. case CB_COLOR11_SLICE:
  1486. tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
  1487. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  1488. track->cb_color_slice_idx[tmp] = idx;
  1489. track->cb_dirty = true;
  1490. break;
  1491. case CB_COLOR0_ATTRIB:
  1492. case CB_COLOR1_ATTRIB:
  1493. case CB_COLOR2_ATTRIB:
  1494. case CB_COLOR3_ATTRIB:
  1495. case CB_COLOR4_ATTRIB:
  1496. case CB_COLOR5_ATTRIB:
  1497. case CB_COLOR6_ATTRIB:
  1498. case CB_COLOR7_ATTRIB:
  1499. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1500. if (r) {
  1501. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1502. "0x%04X\n", reg);
  1503. return -EINVAL;
  1504. }
  1505. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1506. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  1507. unsigned bankw, bankh, mtaspect, tile_split;
  1508. evergreen_tiling_fields(reloc->lobj.tiling_flags,
  1509. &bankw, &bankh, &mtaspect,
  1510. &tile_split);
  1511. ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1512. ib[idx] |= CB_TILE_SPLIT(tile_split) |
  1513. CB_BANK_WIDTH(bankw) |
  1514. CB_BANK_HEIGHT(bankh) |
  1515. CB_MACRO_TILE_ASPECT(mtaspect);
  1516. }
  1517. }
  1518. tmp = ((reg - CB_COLOR0_ATTRIB) / 0x3c);
  1519. track->cb_color_attrib[tmp] = ib[idx];
  1520. track->cb_dirty = true;
  1521. break;
  1522. case CB_COLOR8_ATTRIB:
  1523. case CB_COLOR9_ATTRIB:
  1524. case CB_COLOR10_ATTRIB:
  1525. case CB_COLOR11_ATTRIB:
  1526. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1527. if (r) {
  1528. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1529. "0x%04X\n", reg);
  1530. return -EINVAL;
  1531. }
  1532. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1533. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  1534. unsigned bankw, bankh, mtaspect, tile_split;
  1535. evergreen_tiling_fields(reloc->lobj.tiling_flags,
  1536. &bankw, &bankh, &mtaspect,
  1537. &tile_split);
  1538. ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1539. ib[idx] |= CB_TILE_SPLIT(tile_split) |
  1540. CB_BANK_WIDTH(bankw) |
  1541. CB_BANK_HEIGHT(bankh) |
  1542. CB_MACRO_TILE_ASPECT(mtaspect);
  1543. }
  1544. }
  1545. tmp = ((reg - CB_COLOR8_ATTRIB) / 0x1c) + 8;
  1546. track->cb_color_attrib[tmp] = ib[idx];
  1547. track->cb_dirty = true;
  1548. break;
  1549. case CB_COLOR0_FMASK:
  1550. case CB_COLOR1_FMASK:
  1551. case CB_COLOR2_FMASK:
  1552. case CB_COLOR3_FMASK:
  1553. case CB_COLOR4_FMASK:
  1554. case CB_COLOR5_FMASK:
  1555. case CB_COLOR6_FMASK:
  1556. case CB_COLOR7_FMASK:
  1557. tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
  1558. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1559. if (r) {
  1560. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  1561. return -EINVAL;
  1562. }
  1563. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1564. track->cb_color_fmask_bo[tmp] = reloc->robj;
  1565. break;
  1566. case CB_COLOR0_CMASK:
  1567. case CB_COLOR1_CMASK:
  1568. case CB_COLOR2_CMASK:
  1569. case CB_COLOR3_CMASK:
  1570. case CB_COLOR4_CMASK:
  1571. case CB_COLOR5_CMASK:
  1572. case CB_COLOR6_CMASK:
  1573. case CB_COLOR7_CMASK:
  1574. tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
  1575. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1576. if (r) {
  1577. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  1578. return -EINVAL;
  1579. }
  1580. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1581. track->cb_color_cmask_bo[tmp] = reloc->robj;
  1582. break;
  1583. case CB_COLOR0_FMASK_SLICE:
  1584. case CB_COLOR1_FMASK_SLICE:
  1585. case CB_COLOR2_FMASK_SLICE:
  1586. case CB_COLOR3_FMASK_SLICE:
  1587. case CB_COLOR4_FMASK_SLICE:
  1588. case CB_COLOR5_FMASK_SLICE:
  1589. case CB_COLOR6_FMASK_SLICE:
  1590. case CB_COLOR7_FMASK_SLICE:
  1591. tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
  1592. track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
  1593. break;
  1594. case CB_COLOR0_CMASK_SLICE:
  1595. case CB_COLOR1_CMASK_SLICE:
  1596. case CB_COLOR2_CMASK_SLICE:
  1597. case CB_COLOR3_CMASK_SLICE:
  1598. case CB_COLOR4_CMASK_SLICE:
  1599. case CB_COLOR5_CMASK_SLICE:
  1600. case CB_COLOR6_CMASK_SLICE:
  1601. case CB_COLOR7_CMASK_SLICE:
  1602. tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
  1603. track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
  1604. break;
  1605. case CB_COLOR0_BASE:
  1606. case CB_COLOR1_BASE:
  1607. case CB_COLOR2_BASE:
  1608. case CB_COLOR3_BASE:
  1609. case CB_COLOR4_BASE:
  1610. case CB_COLOR5_BASE:
  1611. case CB_COLOR6_BASE:
  1612. case CB_COLOR7_BASE:
  1613. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1614. if (r) {
  1615. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1616. "0x%04X\n", reg);
  1617. return -EINVAL;
  1618. }
  1619. tmp = (reg - CB_COLOR0_BASE) / 0x3c;
  1620. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  1621. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1622. track->cb_color_bo[tmp] = reloc->robj;
  1623. track->cb_dirty = true;
  1624. break;
  1625. case CB_COLOR8_BASE:
  1626. case CB_COLOR9_BASE:
  1627. case CB_COLOR10_BASE:
  1628. case CB_COLOR11_BASE:
  1629. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1630. if (r) {
  1631. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1632. "0x%04X\n", reg);
  1633. return -EINVAL;
  1634. }
  1635. tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
  1636. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  1637. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1638. track->cb_color_bo[tmp] = reloc->robj;
  1639. track->cb_dirty = true;
  1640. break;
  1641. case DB_HTILE_DATA_BASE:
  1642. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1643. if (r) {
  1644. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1645. "0x%04X\n", reg);
  1646. return -EINVAL;
  1647. }
  1648. track->htile_offset = radeon_get_ib_value(p, idx);
  1649. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1650. track->htile_bo = reloc->robj;
  1651. track->db_dirty = true;
  1652. break;
  1653. case DB_HTILE_SURFACE:
  1654. /* 8x8 only */
  1655. track->htile_surface = radeon_get_ib_value(p, idx);
  1656. track->db_dirty = true;
  1657. break;
  1658. case CB_IMMED0_BASE:
  1659. case CB_IMMED1_BASE:
  1660. case CB_IMMED2_BASE:
  1661. case CB_IMMED3_BASE:
  1662. case CB_IMMED4_BASE:
  1663. case CB_IMMED5_BASE:
  1664. case CB_IMMED6_BASE:
  1665. case CB_IMMED7_BASE:
  1666. case CB_IMMED8_BASE:
  1667. case CB_IMMED9_BASE:
  1668. case CB_IMMED10_BASE:
  1669. case CB_IMMED11_BASE:
  1670. case SQ_PGM_START_FS:
  1671. case SQ_PGM_START_ES:
  1672. case SQ_PGM_START_VS:
  1673. case SQ_PGM_START_GS:
  1674. case SQ_PGM_START_PS:
  1675. case SQ_PGM_START_HS:
  1676. case SQ_PGM_START_LS:
  1677. case SQ_CONST_MEM_BASE:
  1678. case SQ_ALU_CONST_CACHE_GS_0:
  1679. case SQ_ALU_CONST_CACHE_GS_1:
  1680. case SQ_ALU_CONST_CACHE_GS_2:
  1681. case SQ_ALU_CONST_CACHE_GS_3:
  1682. case SQ_ALU_CONST_CACHE_GS_4:
  1683. case SQ_ALU_CONST_CACHE_GS_5:
  1684. case SQ_ALU_CONST_CACHE_GS_6:
  1685. case SQ_ALU_CONST_CACHE_GS_7:
  1686. case SQ_ALU_CONST_CACHE_GS_8:
  1687. case SQ_ALU_CONST_CACHE_GS_9:
  1688. case SQ_ALU_CONST_CACHE_GS_10:
  1689. case SQ_ALU_CONST_CACHE_GS_11:
  1690. case SQ_ALU_CONST_CACHE_GS_12:
  1691. case SQ_ALU_CONST_CACHE_GS_13:
  1692. case SQ_ALU_CONST_CACHE_GS_14:
  1693. case SQ_ALU_CONST_CACHE_GS_15:
  1694. case SQ_ALU_CONST_CACHE_PS_0:
  1695. case SQ_ALU_CONST_CACHE_PS_1:
  1696. case SQ_ALU_CONST_CACHE_PS_2:
  1697. case SQ_ALU_CONST_CACHE_PS_3:
  1698. case SQ_ALU_CONST_CACHE_PS_4:
  1699. case SQ_ALU_CONST_CACHE_PS_5:
  1700. case SQ_ALU_CONST_CACHE_PS_6:
  1701. case SQ_ALU_CONST_CACHE_PS_7:
  1702. case SQ_ALU_CONST_CACHE_PS_8:
  1703. case SQ_ALU_CONST_CACHE_PS_9:
  1704. case SQ_ALU_CONST_CACHE_PS_10:
  1705. case SQ_ALU_CONST_CACHE_PS_11:
  1706. case SQ_ALU_CONST_CACHE_PS_12:
  1707. case SQ_ALU_CONST_CACHE_PS_13:
  1708. case SQ_ALU_CONST_CACHE_PS_14:
  1709. case SQ_ALU_CONST_CACHE_PS_15:
  1710. case SQ_ALU_CONST_CACHE_VS_0:
  1711. case SQ_ALU_CONST_CACHE_VS_1:
  1712. case SQ_ALU_CONST_CACHE_VS_2:
  1713. case SQ_ALU_CONST_CACHE_VS_3:
  1714. case SQ_ALU_CONST_CACHE_VS_4:
  1715. case SQ_ALU_CONST_CACHE_VS_5:
  1716. case SQ_ALU_CONST_CACHE_VS_6:
  1717. case SQ_ALU_CONST_CACHE_VS_7:
  1718. case SQ_ALU_CONST_CACHE_VS_8:
  1719. case SQ_ALU_CONST_CACHE_VS_9:
  1720. case SQ_ALU_CONST_CACHE_VS_10:
  1721. case SQ_ALU_CONST_CACHE_VS_11:
  1722. case SQ_ALU_CONST_CACHE_VS_12:
  1723. case SQ_ALU_CONST_CACHE_VS_13:
  1724. case SQ_ALU_CONST_CACHE_VS_14:
  1725. case SQ_ALU_CONST_CACHE_VS_15:
  1726. case SQ_ALU_CONST_CACHE_HS_0:
  1727. case SQ_ALU_CONST_CACHE_HS_1:
  1728. case SQ_ALU_CONST_CACHE_HS_2:
  1729. case SQ_ALU_CONST_CACHE_HS_3:
  1730. case SQ_ALU_CONST_CACHE_HS_4:
  1731. case SQ_ALU_CONST_CACHE_HS_5:
  1732. case SQ_ALU_CONST_CACHE_HS_6:
  1733. case SQ_ALU_CONST_CACHE_HS_7:
  1734. case SQ_ALU_CONST_CACHE_HS_8:
  1735. case SQ_ALU_CONST_CACHE_HS_9:
  1736. case SQ_ALU_CONST_CACHE_HS_10:
  1737. case SQ_ALU_CONST_CACHE_HS_11:
  1738. case SQ_ALU_CONST_CACHE_HS_12:
  1739. case SQ_ALU_CONST_CACHE_HS_13:
  1740. case SQ_ALU_CONST_CACHE_HS_14:
  1741. case SQ_ALU_CONST_CACHE_HS_15:
  1742. case SQ_ALU_CONST_CACHE_LS_0:
  1743. case SQ_ALU_CONST_CACHE_LS_1:
  1744. case SQ_ALU_CONST_CACHE_LS_2:
  1745. case SQ_ALU_CONST_CACHE_LS_3:
  1746. case SQ_ALU_CONST_CACHE_LS_4:
  1747. case SQ_ALU_CONST_CACHE_LS_5:
  1748. case SQ_ALU_CONST_CACHE_LS_6:
  1749. case SQ_ALU_CONST_CACHE_LS_7:
  1750. case SQ_ALU_CONST_CACHE_LS_8:
  1751. case SQ_ALU_CONST_CACHE_LS_9:
  1752. case SQ_ALU_CONST_CACHE_LS_10:
  1753. case SQ_ALU_CONST_CACHE_LS_11:
  1754. case SQ_ALU_CONST_CACHE_LS_12:
  1755. case SQ_ALU_CONST_CACHE_LS_13:
  1756. case SQ_ALU_CONST_CACHE_LS_14:
  1757. case SQ_ALU_CONST_CACHE_LS_15:
  1758. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1759. if (r) {
  1760. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1761. "0x%04X\n", reg);
  1762. return -EINVAL;
  1763. }
  1764. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1765. break;
  1766. case SX_MEMORY_EXPORT_BASE:
  1767. if (p->rdev->family >= CHIP_CAYMAN) {
  1768. dev_warn(p->dev, "bad SET_CONFIG_REG "
  1769. "0x%04X\n", reg);
  1770. return -EINVAL;
  1771. }
  1772. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1773. if (r) {
  1774. dev_warn(p->dev, "bad SET_CONFIG_REG "
  1775. "0x%04X\n", reg);
  1776. return -EINVAL;
  1777. }
  1778. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1779. break;
  1780. case CAYMAN_SX_SCATTER_EXPORT_BASE:
  1781. if (p->rdev->family < CHIP_CAYMAN) {
  1782. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1783. "0x%04X\n", reg);
  1784. return -EINVAL;
  1785. }
  1786. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1787. if (r) {
  1788. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1789. "0x%04X\n", reg);
  1790. return -EINVAL;
  1791. }
  1792. ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  1793. break;
  1794. case SX_MISC:
  1795. track->sx_misc_kill_all_prims = (radeon_get_ib_value(p, idx) & 0x1) != 0;
  1796. break;
  1797. default:
  1798. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  1799. return -EINVAL;
  1800. }
  1801. return 0;
  1802. }
  1803. static bool evergreen_is_safe_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  1804. {
  1805. u32 last_reg, m, i;
  1806. if (p->rdev->family >= CHIP_CAYMAN)
  1807. last_reg = ARRAY_SIZE(cayman_reg_safe_bm);
  1808. else
  1809. last_reg = ARRAY_SIZE(evergreen_reg_safe_bm);
  1810. i = (reg >> 7);
  1811. if (i >= last_reg) {
  1812. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  1813. return false;
  1814. }
  1815. m = 1 << ((reg >> 2) & 31);
  1816. if (p->rdev->family >= CHIP_CAYMAN) {
  1817. if (!(cayman_reg_safe_bm[i] & m))
  1818. return true;
  1819. } else {
  1820. if (!(evergreen_reg_safe_bm[i] & m))
  1821. return true;
  1822. }
  1823. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  1824. return false;
  1825. }
  1826. static int evergreen_packet3_check(struct radeon_cs_parser *p,
  1827. struct radeon_cs_packet *pkt)
  1828. {
  1829. struct radeon_cs_reloc *reloc;
  1830. struct evergreen_cs_track *track;
  1831. volatile u32 *ib;
  1832. unsigned idx;
  1833. unsigned i;
  1834. unsigned start_reg, end_reg, reg;
  1835. int r;
  1836. u32 idx_value;
  1837. track = (struct evergreen_cs_track *)p->track;
  1838. ib = p->ib->ptr;
  1839. idx = pkt->idx + 1;
  1840. idx_value = radeon_get_ib_value(p, idx);
  1841. switch (pkt->opcode) {
  1842. case PACKET3_SET_PREDICATION:
  1843. {
  1844. int pred_op;
  1845. int tmp;
  1846. uint64_t offset;
  1847. if (pkt->count != 1) {
  1848. DRM_ERROR("bad SET PREDICATION\n");
  1849. return -EINVAL;
  1850. }
  1851. tmp = radeon_get_ib_value(p, idx + 1);
  1852. pred_op = (tmp >> 16) & 0x7;
  1853. /* for the clear predicate operation */
  1854. if (pred_op == 0)
  1855. return 0;
  1856. if (pred_op > 2) {
  1857. DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op);
  1858. return -EINVAL;
  1859. }
  1860. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1861. if (r) {
  1862. DRM_ERROR("bad SET PREDICATION\n");
  1863. return -EINVAL;
  1864. }
  1865. offset = reloc->lobj.gpu_offset +
  1866. (idx_value & 0xfffffff0) +
  1867. ((u64)(tmp & 0xff) << 32);
  1868. ib[idx + 0] = offset;
  1869. ib[idx + 1] = (tmp & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  1870. }
  1871. break;
  1872. case PACKET3_CONTEXT_CONTROL:
  1873. if (pkt->count != 1) {
  1874. DRM_ERROR("bad CONTEXT_CONTROL\n");
  1875. return -EINVAL;
  1876. }
  1877. break;
  1878. case PACKET3_INDEX_TYPE:
  1879. case PACKET3_NUM_INSTANCES:
  1880. case PACKET3_CLEAR_STATE:
  1881. if (pkt->count) {
  1882. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1883. return -EINVAL;
  1884. }
  1885. break;
  1886. case CAYMAN_PACKET3_DEALLOC_STATE:
  1887. if (p->rdev->family < CHIP_CAYMAN) {
  1888. DRM_ERROR("bad PACKET3_DEALLOC_STATE\n");
  1889. return -EINVAL;
  1890. }
  1891. if (pkt->count) {
  1892. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1893. return -EINVAL;
  1894. }
  1895. break;
  1896. case PACKET3_INDEX_BASE:
  1897. {
  1898. uint64_t offset;
  1899. if (pkt->count != 1) {
  1900. DRM_ERROR("bad INDEX_BASE\n");
  1901. return -EINVAL;
  1902. }
  1903. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1904. if (r) {
  1905. DRM_ERROR("bad INDEX_BASE\n");
  1906. return -EINVAL;
  1907. }
  1908. offset = reloc->lobj.gpu_offset +
  1909. idx_value +
  1910. ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
  1911. ib[idx+0] = offset;
  1912. ib[idx+1] = upper_32_bits(offset) & 0xff;
  1913. r = evergreen_cs_track_check(p);
  1914. if (r) {
  1915. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1916. return r;
  1917. }
  1918. break;
  1919. }
  1920. case PACKET3_DRAW_INDEX:
  1921. {
  1922. uint64_t offset;
  1923. if (pkt->count != 3) {
  1924. DRM_ERROR("bad DRAW_INDEX\n");
  1925. return -EINVAL;
  1926. }
  1927. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1928. if (r) {
  1929. DRM_ERROR("bad DRAW_INDEX\n");
  1930. return -EINVAL;
  1931. }
  1932. offset = reloc->lobj.gpu_offset +
  1933. idx_value +
  1934. ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
  1935. ib[idx+0] = offset;
  1936. ib[idx+1] = upper_32_bits(offset) & 0xff;
  1937. r = evergreen_cs_track_check(p);
  1938. if (r) {
  1939. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1940. return r;
  1941. }
  1942. break;
  1943. }
  1944. case PACKET3_DRAW_INDEX_2:
  1945. {
  1946. uint64_t offset;
  1947. if (pkt->count != 4) {
  1948. DRM_ERROR("bad DRAW_INDEX_2\n");
  1949. return -EINVAL;
  1950. }
  1951. r = evergreen_cs_packet_next_reloc(p, &reloc);
  1952. if (r) {
  1953. DRM_ERROR("bad DRAW_INDEX_2\n");
  1954. return -EINVAL;
  1955. }
  1956. offset = reloc->lobj.gpu_offset +
  1957. radeon_get_ib_value(p, idx+1) +
  1958. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  1959. ib[idx+1] = offset;
  1960. ib[idx+2] = upper_32_bits(offset) & 0xff;
  1961. r = evergreen_cs_track_check(p);
  1962. if (r) {
  1963. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1964. return r;
  1965. }
  1966. break;
  1967. }
  1968. case PACKET3_DRAW_INDEX_AUTO:
  1969. if (pkt->count != 1) {
  1970. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1971. return -EINVAL;
  1972. }
  1973. r = evergreen_cs_track_check(p);
  1974. if (r) {
  1975. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1976. return r;
  1977. }
  1978. break;
  1979. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  1980. if (pkt->count != 2) {
  1981. DRM_ERROR("bad DRAW_INDEX_MULTI_AUTO\n");
  1982. return -EINVAL;
  1983. }
  1984. r = evergreen_cs_track_check(p);
  1985. if (r) {
  1986. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1987. return r;
  1988. }
  1989. break;
  1990. case PACKET3_DRAW_INDEX_IMMD:
  1991. if (pkt->count < 2) {
  1992. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1993. return -EINVAL;
  1994. }
  1995. r = evergreen_cs_track_check(p);
  1996. if (r) {
  1997. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1998. return r;
  1999. }
  2000. break;
  2001. case PACKET3_DRAW_INDEX_OFFSET:
  2002. if (pkt->count != 2) {
  2003. DRM_ERROR("bad DRAW_INDEX_OFFSET\n");
  2004. return -EINVAL;
  2005. }
  2006. r = evergreen_cs_track_check(p);
  2007. if (r) {
  2008. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  2009. return r;
  2010. }
  2011. break;
  2012. case PACKET3_DRAW_INDEX_OFFSET_2:
  2013. if (pkt->count != 3) {
  2014. DRM_ERROR("bad DRAW_INDEX_OFFSET_2\n");
  2015. return -EINVAL;
  2016. }
  2017. r = evergreen_cs_track_check(p);
  2018. if (r) {
  2019. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  2020. return r;
  2021. }
  2022. break;
  2023. case PACKET3_DISPATCH_DIRECT:
  2024. if (pkt->count != 3) {
  2025. DRM_ERROR("bad DISPATCH_DIRECT\n");
  2026. return -EINVAL;
  2027. }
  2028. r = evergreen_cs_track_check(p);
  2029. if (r) {
  2030. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  2031. return r;
  2032. }
  2033. break;
  2034. case PACKET3_DISPATCH_INDIRECT:
  2035. if (pkt->count != 1) {
  2036. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  2037. return -EINVAL;
  2038. }
  2039. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2040. if (r) {
  2041. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  2042. return -EINVAL;
  2043. }
  2044. ib[idx+0] = idx_value + (u32)(reloc->lobj.gpu_offset & 0xffffffff);
  2045. r = evergreen_cs_track_check(p);
  2046. if (r) {
  2047. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  2048. return r;
  2049. }
  2050. break;
  2051. case PACKET3_WAIT_REG_MEM:
  2052. if (pkt->count != 5) {
  2053. DRM_ERROR("bad WAIT_REG_MEM\n");
  2054. return -EINVAL;
  2055. }
  2056. /* bit 4 is reg (0) or mem (1) */
  2057. if (idx_value & 0x10) {
  2058. uint64_t offset;
  2059. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2060. if (r) {
  2061. DRM_ERROR("bad WAIT_REG_MEM\n");
  2062. return -EINVAL;
  2063. }
  2064. offset = reloc->lobj.gpu_offset +
  2065. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  2066. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2067. ib[idx+1] = (ib[idx+1] & 0x3) | (offset & 0xfffffffc);
  2068. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2069. }
  2070. break;
  2071. case PACKET3_SURFACE_SYNC:
  2072. if (pkt->count != 3) {
  2073. DRM_ERROR("bad SURFACE_SYNC\n");
  2074. return -EINVAL;
  2075. }
  2076. /* 0xffffffff/0x0 is flush all cache flag */
  2077. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  2078. radeon_get_ib_value(p, idx + 2) != 0) {
  2079. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2080. if (r) {
  2081. DRM_ERROR("bad SURFACE_SYNC\n");
  2082. return -EINVAL;
  2083. }
  2084. ib[idx+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  2085. }
  2086. break;
  2087. case PACKET3_EVENT_WRITE:
  2088. if (pkt->count != 2 && pkt->count != 0) {
  2089. DRM_ERROR("bad EVENT_WRITE\n");
  2090. return -EINVAL;
  2091. }
  2092. if (pkt->count) {
  2093. uint64_t offset;
  2094. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2095. if (r) {
  2096. DRM_ERROR("bad EVENT_WRITE\n");
  2097. return -EINVAL;
  2098. }
  2099. offset = reloc->lobj.gpu_offset +
  2100. (radeon_get_ib_value(p, idx+1) & 0xfffffff8) +
  2101. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2102. ib[idx+1] = offset & 0xfffffff8;
  2103. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2104. }
  2105. break;
  2106. case PACKET3_EVENT_WRITE_EOP:
  2107. {
  2108. uint64_t offset;
  2109. if (pkt->count != 4) {
  2110. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  2111. return -EINVAL;
  2112. }
  2113. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2114. if (r) {
  2115. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  2116. return -EINVAL;
  2117. }
  2118. offset = reloc->lobj.gpu_offset +
  2119. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  2120. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2121. ib[idx+1] = offset & 0xfffffffc;
  2122. ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  2123. break;
  2124. }
  2125. case PACKET3_EVENT_WRITE_EOS:
  2126. {
  2127. uint64_t offset;
  2128. if (pkt->count != 3) {
  2129. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  2130. return -EINVAL;
  2131. }
  2132. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2133. if (r) {
  2134. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  2135. return -EINVAL;
  2136. }
  2137. offset = reloc->lobj.gpu_offset +
  2138. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  2139. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2140. ib[idx+1] = offset & 0xfffffffc;
  2141. ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  2142. break;
  2143. }
  2144. case PACKET3_SET_CONFIG_REG:
  2145. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  2146. end_reg = 4 * pkt->count + start_reg - 4;
  2147. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  2148. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  2149. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  2150. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  2151. return -EINVAL;
  2152. }
  2153. for (i = 0; i < pkt->count; i++) {
  2154. reg = start_reg + (4 * i);
  2155. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  2156. if (r)
  2157. return r;
  2158. }
  2159. break;
  2160. case PACKET3_SET_CONTEXT_REG:
  2161. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
  2162. end_reg = 4 * pkt->count + start_reg - 4;
  2163. if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
  2164. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  2165. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  2166. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  2167. return -EINVAL;
  2168. }
  2169. for (i = 0; i < pkt->count; i++) {
  2170. reg = start_reg + (4 * i);
  2171. r = evergreen_cs_check_reg(p, reg, idx+1+i);
  2172. if (r)
  2173. return r;
  2174. }
  2175. break;
  2176. case PACKET3_SET_RESOURCE:
  2177. if (pkt->count % 8) {
  2178. DRM_ERROR("bad SET_RESOURCE\n");
  2179. return -EINVAL;
  2180. }
  2181. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
  2182. end_reg = 4 * pkt->count + start_reg - 4;
  2183. if ((start_reg < PACKET3_SET_RESOURCE_START) ||
  2184. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  2185. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  2186. DRM_ERROR("bad SET_RESOURCE\n");
  2187. return -EINVAL;
  2188. }
  2189. for (i = 0; i < (pkt->count / 8); i++) {
  2190. struct radeon_bo *texture, *mipmap;
  2191. u32 toffset, moffset;
  2192. u32 size, offset;
  2193. switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
  2194. case SQ_TEX_VTX_VALID_TEXTURE:
  2195. /* tex base */
  2196. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2197. if (r) {
  2198. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  2199. return -EINVAL;
  2200. }
  2201. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  2202. ib[idx+1+(i*8)+1] |=
  2203. TEX_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
  2204. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
  2205. unsigned bankw, bankh, mtaspect, tile_split;
  2206. evergreen_tiling_fields(reloc->lobj.tiling_flags,
  2207. &bankw, &bankh, &mtaspect,
  2208. &tile_split);
  2209. ib[idx+1+(i*8)+6] |= TEX_TILE_SPLIT(tile_split);
  2210. ib[idx+1+(i*8)+7] |=
  2211. TEX_BANK_WIDTH(bankw) |
  2212. TEX_BANK_HEIGHT(bankh) |
  2213. MACRO_TILE_ASPECT(mtaspect) |
  2214. TEX_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  2215. }
  2216. }
  2217. texture = reloc->robj;
  2218. toffset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  2219. /* tex mip base */
  2220. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2221. if (r) {
  2222. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  2223. return -EINVAL;
  2224. }
  2225. moffset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
  2226. mipmap = reloc->robj;
  2227. r = evergreen_cs_track_validate_texture(p, texture, mipmap, idx+1+(i*8));
  2228. if (r)
  2229. return r;
  2230. ib[idx+1+(i*8)+2] += toffset;
  2231. ib[idx+1+(i*8)+3] += moffset;
  2232. break;
  2233. case SQ_TEX_VTX_VALID_BUFFER:
  2234. {
  2235. uint64_t offset64;
  2236. /* vtx base */
  2237. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2238. if (r) {
  2239. DRM_ERROR("bad SET_RESOURCE (vtx)\n");
  2240. return -EINVAL;
  2241. }
  2242. offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
  2243. size = radeon_get_ib_value(p, idx+1+(i*8)+1);
  2244. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  2245. /* force size to size of the buffer */
  2246. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  2247. ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj) - offset;
  2248. }
  2249. offset64 = reloc->lobj.gpu_offset + offset;
  2250. ib[idx+1+(i*8)+0] = offset64;
  2251. ib[idx+1+(i*8)+2] = (ib[idx+1+(i*8)+2] & 0xffffff00) |
  2252. (upper_32_bits(offset64) & 0xff);
  2253. break;
  2254. }
  2255. case SQ_TEX_VTX_INVALID_TEXTURE:
  2256. case SQ_TEX_VTX_INVALID_BUFFER:
  2257. default:
  2258. DRM_ERROR("bad SET_RESOURCE\n");
  2259. return -EINVAL;
  2260. }
  2261. }
  2262. break;
  2263. case PACKET3_SET_ALU_CONST:
  2264. /* XXX fix me ALU const buffers only */
  2265. break;
  2266. case PACKET3_SET_BOOL_CONST:
  2267. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
  2268. end_reg = 4 * pkt->count + start_reg - 4;
  2269. if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
  2270. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  2271. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  2272. DRM_ERROR("bad SET_BOOL_CONST\n");
  2273. return -EINVAL;
  2274. }
  2275. break;
  2276. case PACKET3_SET_LOOP_CONST:
  2277. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
  2278. end_reg = 4 * pkt->count + start_reg - 4;
  2279. if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
  2280. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  2281. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  2282. DRM_ERROR("bad SET_LOOP_CONST\n");
  2283. return -EINVAL;
  2284. }
  2285. break;
  2286. case PACKET3_SET_CTL_CONST:
  2287. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
  2288. end_reg = 4 * pkt->count + start_reg - 4;
  2289. if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
  2290. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  2291. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  2292. DRM_ERROR("bad SET_CTL_CONST\n");
  2293. return -EINVAL;
  2294. }
  2295. break;
  2296. case PACKET3_SET_SAMPLER:
  2297. if (pkt->count % 3) {
  2298. DRM_ERROR("bad SET_SAMPLER\n");
  2299. return -EINVAL;
  2300. }
  2301. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
  2302. end_reg = 4 * pkt->count + start_reg - 4;
  2303. if ((start_reg < PACKET3_SET_SAMPLER_START) ||
  2304. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  2305. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  2306. DRM_ERROR("bad SET_SAMPLER\n");
  2307. return -EINVAL;
  2308. }
  2309. break;
  2310. case PACKET3_STRMOUT_BUFFER_UPDATE:
  2311. if (pkt->count != 4) {
  2312. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (invalid count)\n");
  2313. return -EINVAL;
  2314. }
  2315. /* Updating memory at DST_ADDRESS. */
  2316. if (idx_value & 0x1) {
  2317. u64 offset;
  2318. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2319. if (r) {
  2320. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing dst reloc)\n");
  2321. return -EINVAL;
  2322. }
  2323. offset = radeon_get_ib_value(p, idx+1);
  2324. offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
  2325. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2326. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE dst bo too small: 0x%llx, 0x%lx\n",
  2327. offset + 4, radeon_bo_size(reloc->robj));
  2328. return -EINVAL;
  2329. }
  2330. offset += reloc->lobj.gpu_offset;
  2331. ib[idx+1] = offset;
  2332. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2333. }
  2334. /* Reading data from SRC_ADDRESS. */
  2335. if (((idx_value >> 1) & 0x3) == 2) {
  2336. u64 offset;
  2337. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2338. if (r) {
  2339. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing src reloc)\n");
  2340. return -EINVAL;
  2341. }
  2342. offset = radeon_get_ib_value(p, idx+3);
  2343. offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2344. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2345. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE src bo too small: 0x%llx, 0x%lx\n",
  2346. offset + 4, radeon_bo_size(reloc->robj));
  2347. return -EINVAL;
  2348. }
  2349. offset += reloc->lobj.gpu_offset;
  2350. ib[idx+3] = offset;
  2351. ib[idx+4] = upper_32_bits(offset) & 0xff;
  2352. }
  2353. break;
  2354. case PACKET3_COPY_DW:
  2355. if (pkt->count != 4) {
  2356. DRM_ERROR("bad COPY_DW (invalid count)\n");
  2357. return -EINVAL;
  2358. }
  2359. if (idx_value & 0x1) {
  2360. u64 offset;
  2361. /* SRC is memory. */
  2362. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2363. if (r) {
  2364. DRM_ERROR("bad COPY_DW (missing src reloc)\n");
  2365. return -EINVAL;
  2366. }
  2367. offset = radeon_get_ib_value(p, idx+1);
  2368. offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
  2369. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2370. DRM_ERROR("bad COPY_DW src bo too small: 0x%llx, 0x%lx\n",
  2371. offset + 4, radeon_bo_size(reloc->robj));
  2372. return -EINVAL;
  2373. }
  2374. offset += reloc->lobj.gpu_offset;
  2375. ib[idx+1] = offset;
  2376. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2377. } else {
  2378. /* SRC is a reg. */
  2379. reg = radeon_get_ib_value(p, idx+1) << 2;
  2380. if (!evergreen_is_safe_reg(p, reg, idx+1))
  2381. return -EINVAL;
  2382. }
  2383. if (idx_value & 0x2) {
  2384. u64 offset;
  2385. /* DST is memory. */
  2386. r = evergreen_cs_packet_next_reloc(p, &reloc);
  2387. if (r) {
  2388. DRM_ERROR("bad COPY_DW (missing dst reloc)\n");
  2389. return -EINVAL;
  2390. }
  2391. offset = radeon_get_ib_value(p, idx+3);
  2392. offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2393. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2394. DRM_ERROR("bad COPY_DW dst bo too small: 0x%llx, 0x%lx\n",
  2395. offset + 4, radeon_bo_size(reloc->robj));
  2396. return -EINVAL;
  2397. }
  2398. offset += reloc->lobj.gpu_offset;
  2399. ib[idx+3] = offset;
  2400. ib[idx+4] = upper_32_bits(offset) & 0xff;
  2401. } else {
  2402. /* DST is a reg. */
  2403. reg = radeon_get_ib_value(p, idx+3) << 2;
  2404. if (!evergreen_is_safe_reg(p, reg, idx+3))
  2405. return -EINVAL;
  2406. }
  2407. break;
  2408. case PACKET3_NOP:
  2409. break;
  2410. default:
  2411. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  2412. return -EINVAL;
  2413. }
  2414. return 0;
  2415. }
  2416. int evergreen_cs_parse(struct radeon_cs_parser *p)
  2417. {
  2418. struct radeon_cs_packet pkt;
  2419. struct evergreen_cs_track *track;
  2420. u32 tmp;
  2421. int r;
  2422. if (p->track == NULL) {
  2423. /* initialize tracker, we are in kms */
  2424. track = kzalloc(sizeof(*track), GFP_KERNEL);
  2425. if (track == NULL)
  2426. return -ENOMEM;
  2427. evergreen_cs_track_init(track);
  2428. if (p->rdev->family >= CHIP_CAYMAN)
  2429. tmp = p->rdev->config.cayman.tile_config;
  2430. else
  2431. tmp = p->rdev->config.evergreen.tile_config;
  2432. switch (tmp & 0xf) {
  2433. case 0:
  2434. track->npipes = 1;
  2435. break;
  2436. case 1:
  2437. default:
  2438. track->npipes = 2;
  2439. break;
  2440. case 2:
  2441. track->npipes = 4;
  2442. break;
  2443. case 3:
  2444. track->npipes = 8;
  2445. break;
  2446. }
  2447. switch ((tmp & 0xf0) >> 4) {
  2448. case 0:
  2449. track->nbanks = 4;
  2450. break;
  2451. case 1:
  2452. default:
  2453. track->nbanks = 8;
  2454. break;
  2455. case 2:
  2456. track->nbanks = 16;
  2457. break;
  2458. }
  2459. switch ((tmp & 0xf00) >> 8) {
  2460. case 0:
  2461. track->group_size = 256;
  2462. break;
  2463. case 1:
  2464. default:
  2465. track->group_size = 512;
  2466. break;
  2467. }
  2468. switch ((tmp & 0xf000) >> 12) {
  2469. case 0:
  2470. track->row_size = 1;
  2471. break;
  2472. case 1:
  2473. default:
  2474. track->row_size = 2;
  2475. break;
  2476. case 2:
  2477. track->row_size = 4;
  2478. break;
  2479. }
  2480. p->track = track;
  2481. }
  2482. do {
  2483. r = evergreen_cs_packet_parse(p, &pkt, p->idx);
  2484. if (r) {
  2485. kfree(p->track);
  2486. p->track = NULL;
  2487. return r;
  2488. }
  2489. p->idx += pkt.count + 2;
  2490. switch (pkt.type) {
  2491. case PACKET_TYPE0:
  2492. r = evergreen_cs_parse_packet0(p, &pkt);
  2493. break;
  2494. case PACKET_TYPE2:
  2495. break;
  2496. case PACKET_TYPE3:
  2497. r = evergreen_packet3_check(p, &pkt);
  2498. break;
  2499. default:
  2500. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  2501. kfree(p->track);
  2502. p->track = NULL;
  2503. return -EINVAL;
  2504. }
  2505. if (r) {
  2506. kfree(p->track);
  2507. p->track = NULL;
  2508. return r;
  2509. }
  2510. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  2511. #if 0
  2512. for (r = 0; r < p->ib->length_dw; r++) {
  2513. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib->ptr[r]);
  2514. mdelay(1);
  2515. }
  2516. #endif
  2517. kfree(p->track);
  2518. p->track = NULL;
  2519. return 0;
  2520. }
  2521. /* vm parser */
  2522. static bool evergreen_vm_reg_valid(u32 reg)
  2523. {
  2524. /* context regs are fine */
  2525. if (reg >= 0x28000)
  2526. return true;
  2527. /* check config regs */
  2528. switch (reg) {
  2529. case WAIT_UNTIL:
  2530. case GRBM_GFX_INDEX:
  2531. case CP_STRMOUT_CNTL:
  2532. case CP_COHER_CNTL:
  2533. case CP_COHER_SIZE:
  2534. case VGT_VTX_VECT_EJECT_REG:
  2535. case VGT_CACHE_INVALIDATION:
  2536. case VGT_GS_VERTEX_REUSE:
  2537. case VGT_PRIMITIVE_TYPE:
  2538. case VGT_INDEX_TYPE:
  2539. case VGT_NUM_INDICES:
  2540. case VGT_NUM_INSTANCES:
  2541. case VGT_COMPUTE_DIM_X:
  2542. case VGT_COMPUTE_DIM_Y:
  2543. case VGT_COMPUTE_DIM_Z:
  2544. case VGT_COMPUTE_START_X:
  2545. case VGT_COMPUTE_START_Y:
  2546. case VGT_COMPUTE_START_Z:
  2547. case VGT_COMPUTE_INDEX:
  2548. case VGT_COMPUTE_THREAD_GROUP_SIZE:
  2549. case VGT_HS_OFFCHIP_PARAM:
  2550. case PA_CL_ENHANCE:
  2551. case PA_SU_LINE_STIPPLE_VALUE:
  2552. case PA_SC_LINE_STIPPLE_STATE:
  2553. case PA_SC_ENHANCE:
  2554. case SQ_DYN_GPR_CNTL_PS_FLUSH_REQ:
  2555. case SQ_DYN_GPR_SIMD_LOCK_EN:
  2556. case SQ_CONFIG:
  2557. case SQ_GPR_RESOURCE_MGMT_1:
  2558. case SQ_GLOBAL_GPR_RESOURCE_MGMT_1:
  2559. case SQ_GLOBAL_GPR_RESOURCE_MGMT_2:
  2560. case SQ_CONST_MEM_BASE:
  2561. case SQ_STATIC_THREAD_MGMT_1:
  2562. case SQ_STATIC_THREAD_MGMT_2:
  2563. case SQ_STATIC_THREAD_MGMT_3:
  2564. case SPI_CONFIG_CNTL:
  2565. case SPI_CONFIG_CNTL_1:
  2566. case TA_CNTL_AUX:
  2567. case DB_DEBUG:
  2568. case DB_DEBUG2:
  2569. case DB_DEBUG3:
  2570. case DB_DEBUG4:
  2571. case DB_WATERMARKS:
  2572. case TD_PS_BORDER_COLOR_INDEX:
  2573. case TD_PS_BORDER_COLOR_RED:
  2574. case TD_PS_BORDER_COLOR_GREEN:
  2575. case TD_PS_BORDER_COLOR_BLUE:
  2576. case TD_PS_BORDER_COLOR_ALPHA:
  2577. case TD_VS_BORDER_COLOR_INDEX:
  2578. case TD_VS_BORDER_COLOR_RED:
  2579. case TD_VS_BORDER_COLOR_GREEN:
  2580. case TD_VS_BORDER_COLOR_BLUE:
  2581. case TD_VS_BORDER_COLOR_ALPHA:
  2582. case TD_GS_BORDER_COLOR_INDEX:
  2583. case TD_GS_BORDER_COLOR_RED:
  2584. case TD_GS_BORDER_COLOR_GREEN:
  2585. case TD_GS_BORDER_COLOR_BLUE:
  2586. case TD_GS_BORDER_COLOR_ALPHA:
  2587. case TD_HS_BORDER_COLOR_INDEX:
  2588. case TD_HS_BORDER_COLOR_RED:
  2589. case TD_HS_BORDER_COLOR_GREEN:
  2590. case TD_HS_BORDER_COLOR_BLUE:
  2591. case TD_HS_BORDER_COLOR_ALPHA:
  2592. case TD_LS_BORDER_COLOR_INDEX:
  2593. case TD_LS_BORDER_COLOR_RED:
  2594. case TD_LS_BORDER_COLOR_GREEN:
  2595. case TD_LS_BORDER_COLOR_BLUE:
  2596. case TD_LS_BORDER_COLOR_ALPHA:
  2597. case TD_CS_BORDER_COLOR_INDEX:
  2598. case TD_CS_BORDER_COLOR_RED:
  2599. case TD_CS_BORDER_COLOR_GREEN:
  2600. case TD_CS_BORDER_COLOR_BLUE:
  2601. case TD_CS_BORDER_COLOR_ALPHA:
  2602. case SQ_ESGS_RING_SIZE:
  2603. case SQ_GSVS_RING_SIZE:
  2604. case SQ_ESTMP_RING_SIZE:
  2605. case SQ_GSTMP_RING_SIZE:
  2606. case SQ_HSTMP_RING_SIZE:
  2607. case SQ_LSTMP_RING_SIZE:
  2608. case SQ_PSTMP_RING_SIZE:
  2609. case SQ_VSTMP_RING_SIZE:
  2610. case SQ_ESGS_RING_ITEMSIZE:
  2611. case SQ_ESTMP_RING_ITEMSIZE:
  2612. case SQ_GSTMP_RING_ITEMSIZE:
  2613. case SQ_GSVS_RING_ITEMSIZE:
  2614. case SQ_GS_VERT_ITEMSIZE:
  2615. case SQ_GS_VERT_ITEMSIZE_1:
  2616. case SQ_GS_VERT_ITEMSIZE_2:
  2617. case SQ_GS_VERT_ITEMSIZE_3:
  2618. case SQ_GSVS_RING_OFFSET_1:
  2619. case SQ_GSVS_RING_OFFSET_2:
  2620. case SQ_GSVS_RING_OFFSET_3:
  2621. case SQ_HSTMP_RING_ITEMSIZE:
  2622. case SQ_LSTMP_RING_ITEMSIZE:
  2623. case SQ_PSTMP_RING_ITEMSIZE:
  2624. case SQ_VSTMP_RING_ITEMSIZE:
  2625. case VGT_TF_RING_SIZE:
  2626. case SQ_ESGS_RING_BASE:
  2627. case SQ_GSVS_RING_BASE:
  2628. case SQ_ESTMP_RING_BASE:
  2629. case SQ_GSTMP_RING_BASE:
  2630. case SQ_HSTMP_RING_BASE:
  2631. case SQ_LSTMP_RING_BASE:
  2632. case SQ_PSTMP_RING_BASE:
  2633. case SQ_VSTMP_RING_BASE:
  2634. case CAYMAN_VGT_OFFCHIP_LDS_BASE:
  2635. case CAYMAN_SQ_EX_ALLOC_TABLE_SLOTS:
  2636. return true;
  2637. default:
  2638. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  2639. return false;
  2640. }
  2641. }
  2642. static int evergreen_vm_packet3_check(struct radeon_device *rdev,
  2643. u32 *ib, struct radeon_cs_packet *pkt)
  2644. {
  2645. u32 idx = pkt->idx + 1;
  2646. u32 idx_value = ib[idx];
  2647. u32 start_reg, end_reg, reg, i;
  2648. switch (pkt->opcode) {
  2649. case PACKET3_NOP:
  2650. case PACKET3_SET_BASE:
  2651. case PACKET3_CLEAR_STATE:
  2652. case PACKET3_INDEX_BUFFER_SIZE:
  2653. case PACKET3_DISPATCH_DIRECT:
  2654. case PACKET3_DISPATCH_INDIRECT:
  2655. case PACKET3_MODE_CONTROL:
  2656. case PACKET3_SET_PREDICATION:
  2657. case PACKET3_COND_EXEC:
  2658. case PACKET3_PRED_EXEC:
  2659. case PACKET3_DRAW_INDIRECT:
  2660. case PACKET3_DRAW_INDEX_INDIRECT:
  2661. case PACKET3_INDEX_BASE:
  2662. case PACKET3_DRAW_INDEX_2:
  2663. case PACKET3_CONTEXT_CONTROL:
  2664. case PACKET3_DRAW_INDEX_OFFSET:
  2665. case PACKET3_INDEX_TYPE:
  2666. case PACKET3_DRAW_INDEX:
  2667. case PACKET3_DRAW_INDEX_AUTO:
  2668. case PACKET3_DRAW_INDEX_IMMD:
  2669. case PACKET3_NUM_INSTANCES:
  2670. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  2671. case PACKET3_STRMOUT_BUFFER_UPDATE:
  2672. case PACKET3_DRAW_INDEX_OFFSET_2:
  2673. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  2674. case PACKET3_MPEG_INDEX:
  2675. case PACKET3_WAIT_REG_MEM:
  2676. case PACKET3_MEM_WRITE:
  2677. case PACKET3_SURFACE_SYNC:
  2678. case PACKET3_EVENT_WRITE:
  2679. case PACKET3_EVENT_WRITE_EOP:
  2680. case PACKET3_EVENT_WRITE_EOS:
  2681. case PACKET3_SET_CONTEXT_REG:
  2682. case PACKET3_SET_BOOL_CONST:
  2683. case PACKET3_SET_LOOP_CONST:
  2684. case PACKET3_SET_RESOURCE:
  2685. case PACKET3_SET_SAMPLER:
  2686. case PACKET3_SET_CTL_CONST:
  2687. case PACKET3_SET_RESOURCE_OFFSET:
  2688. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  2689. case PACKET3_SET_RESOURCE_INDIRECT:
  2690. case CAYMAN_PACKET3_DEALLOC_STATE:
  2691. break;
  2692. case PACKET3_COND_WRITE:
  2693. if (idx_value & 0x100) {
  2694. reg = ib[idx + 5] * 4;
  2695. if (!evergreen_vm_reg_valid(reg))
  2696. return -EINVAL;
  2697. }
  2698. break;
  2699. case PACKET3_COPY_DW:
  2700. if (idx_value & 0x2) {
  2701. reg = ib[idx + 3] * 4;
  2702. if (!evergreen_vm_reg_valid(reg))
  2703. return -EINVAL;
  2704. }
  2705. break;
  2706. case PACKET3_SET_CONFIG_REG:
  2707. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  2708. end_reg = 4 * pkt->count + start_reg - 4;
  2709. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  2710. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  2711. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  2712. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  2713. return -EINVAL;
  2714. }
  2715. for (i = 0; i < pkt->count; i++) {
  2716. reg = start_reg + (4 * i);
  2717. if (!evergreen_vm_reg_valid(reg))
  2718. return -EINVAL;
  2719. }
  2720. break;
  2721. default:
  2722. return -EINVAL;
  2723. }
  2724. return 0;
  2725. }
  2726. int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  2727. {
  2728. int ret = 0;
  2729. u32 idx = 0;
  2730. struct radeon_cs_packet pkt;
  2731. do {
  2732. pkt.idx = idx;
  2733. pkt.type = CP_PACKET_GET_TYPE(ib->ptr[idx]);
  2734. pkt.count = CP_PACKET_GET_COUNT(ib->ptr[idx]);
  2735. pkt.one_reg_wr = 0;
  2736. switch (pkt.type) {
  2737. case PACKET_TYPE0:
  2738. dev_err(rdev->dev, "Packet0 not allowed!\n");
  2739. ret = -EINVAL;
  2740. break;
  2741. case PACKET_TYPE2:
  2742. idx += 1;
  2743. break;
  2744. case PACKET_TYPE3:
  2745. pkt.opcode = CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  2746. ret = evergreen_vm_packet3_check(rdev, ib->ptr, &pkt);
  2747. idx += pkt.count + 2;
  2748. break;
  2749. default:
  2750. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  2751. ret = -EINVAL;
  2752. break;
  2753. }
  2754. if (ret)
  2755. break;
  2756. } while (idx < ib->length_dw);
  2757. return ret;
  2758. }