evergreen_cs.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584
  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 <drm/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. #define REG_SAFE_BM_SIZE ARRAY_SIZE(evergreen_reg_safe_bm)
  36. int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,
  37. struct radeon_bo_list **cs_reloc);
  38. struct evergreen_cs_track {
  39. u32 group_size;
  40. u32 nbanks;
  41. u32 npipes;
  42. u32 row_size;
  43. /* value we track */
  44. u32 nsamples; /* unused */
  45. struct radeon_bo *cb_color_bo[12];
  46. u32 cb_color_bo_offset[12];
  47. struct radeon_bo *cb_color_fmask_bo[8]; /* unused */
  48. struct radeon_bo *cb_color_cmask_bo[8]; /* unused */
  49. u32 cb_color_info[12];
  50. u32 cb_color_view[12];
  51. u32 cb_color_pitch[12];
  52. u32 cb_color_slice[12];
  53. u32 cb_color_slice_idx[12];
  54. u32 cb_color_attrib[12];
  55. u32 cb_color_cmask_slice[8];/* unused */
  56. u32 cb_color_fmask_slice[8];/* unused */
  57. u32 cb_target_mask;
  58. u32 cb_shader_mask; /* unused */
  59. u32 vgt_strmout_config;
  60. u32 vgt_strmout_buffer_config;
  61. struct radeon_bo *vgt_strmout_bo[4];
  62. u32 vgt_strmout_bo_offset[4];
  63. u32 vgt_strmout_size[4];
  64. u32 db_depth_control;
  65. u32 db_depth_view;
  66. u32 db_depth_slice;
  67. u32 db_depth_size;
  68. u32 db_z_info;
  69. u32 db_z_read_offset;
  70. u32 db_z_write_offset;
  71. struct radeon_bo *db_z_read_bo;
  72. struct radeon_bo *db_z_write_bo;
  73. u32 db_s_info;
  74. u32 db_s_read_offset;
  75. u32 db_s_write_offset;
  76. struct radeon_bo *db_s_read_bo;
  77. struct radeon_bo *db_s_write_bo;
  78. bool sx_misc_kill_all_prims;
  79. bool cb_dirty;
  80. bool db_dirty;
  81. bool streamout_dirty;
  82. u32 htile_offset;
  83. u32 htile_surface;
  84. struct radeon_bo *htile_bo;
  85. unsigned long indirect_draw_buffer_size;
  86. const unsigned *reg_safe_bm;
  87. };
  88. static u32 evergreen_cs_get_aray_mode(u32 tiling_flags)
  89. {
  90. if (tiling_flags & RADEON_TILING_MACRO)
  91. return ARRAY_2D_TILED_THIN1;
  92. else if (tiling_flags & RADEON_TILING_MICRO)
  93. return ARRAY_1D_TILED_THIN1;
  94. else
  95. return ARRAY_LINEAR_GENERAL;
  96. }
  97. static u32 evergreen_cs_get_num_banks(u32 nbanks)
  98. {
  99. switch (nbanks) {
  100. case 2:
  101. return ADDR_SURF_2_BANK;
  102. case 4:
  103. return ADDR_SURF_4_BANK;
  104. case 8:
  105. default:
  106. return ADDR_SURF_8_BANK;
  107. case 16:
  108. return ADDR_SURF_16_BANK;
  109. }
  110. }
  111. static void evergreen_cs_track_init(struct evergreen_cs_track *track)
  112. {
  113. int i;
  114. for (i = 0; i < 8; i++) {
  115. track->cb_color_fmask_bo[i] = NULL;
  116. track->cb_color_cmask_bo[i] = NULL;
  117. track->cb_color_cmask_slice[i] = 0;
  118. track->cb_color_fmask_slice[i] = 0;
  119. }
  120. for (i = 0; i < 12; i++) {
  121. track->cb_color_bo[i] = NULL;
  122. track->cb_color_bo_offset[i] = 0xFFFFFFFF;
  123. track->cb_color_info[i] = 0;
  124. track->cb_color_view[i] = 0xFFFFFFFF;
  125. track->cb_color_pitch[i] = 0;
  126. track->cb_color_slice[i] = 0xfffffff;
  127. track->cb_color_slice_idx[i] = 0;
  128. }
  129. track->cb_target_mask = 0xFFFFFFFF;
  130. track->cb_shader_mask = 0xFFFFFFFF;
  131. track->cb_dirty = true;
  132. track->db_depth_slice = 0xffffffff;
  133. track->db_depth_view = 0xFFFFC000;
  134. track->db_depth_size = 0xFFFFFFFF;
  135. track->db_depth_control = 0xFFFFFFFF;
  136. track->db_z_info = 0xFFFFFFFF;
  137. track->db_z_read_offset = 0xFFFFFFFF;
  138. track->db_z_write_offset = 0xFFFFFFFF;
  139. track->db_z_read_bo = NULL;
  140. track->db_z_write_bo = NULL;
  141. track->db_s_info = 0xFFFFFFFF;
  142. track->db_s_read_offset = 0xFFFFFFFF;
  143. track->db_s_write_offset = 0xFFFFFFFF;
  144. track->db_s_read_bo = NULL;
  145. track->db_s_write_bo = NULL;
  146. track->db_dirty = true;
  147. track->htile_bo = NULL;
  148. track->htile_offset = 0xFFFFFFFF;
  149. track->htile_surface = 0;
  150. for (i = 0; i < 4; i++) {
  151. track->vgt_strmout_size[i] = 0;
  152. track->vgt_strmout_bo[i] = NULL;
  153. track->vgt_strmout_bo_offset[i] = 0xFFFFFFFF;
  154. }
  155. track->streamout_dirty = true;
  156. track->sx_misc_kill_all_prims = false;
  157. }
  158. struct eg_surface {
  159. /* value gathered from cs */
  160. unsigned nbx;
  161. unsigned nby;
  162. unsigned format;
  163. unsigned mode;
  164. unsigned nbanks;
  165. unsigned bankw;
  166. unsigned bankh;
  167. unsigned tsplit;
  168. unsigned mtilea;
  169. unsigned nsamples;
  170. /* output value */
  171. unsigned bpe;
  172. unsigned layer_size;
  173. unsigned palign;
  174. unsigned halign;
  175. unsigned long base_align;
  176. };
  177. static int evergreen_surface_check_linear(struct radeon_cs_parser *p,
  178. struct eg_surface *surf,
  179. const char *prefix)
  180. {
  181. surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
  182. surf->base_align = surf->bpe;
  183. surf->palign = 1;
  184. surf->halign = 1;
  185. return 0;
  186. }
  187. static int evergreen_surface_check_linear_aligned(struct radeon_cs_parser *p,
  188. struct eg_surface *surf,
  189. const char *prefix)
  190. {
  191. struct evergreen_cs_track *track = p->track;
  192. unsigned palign;
  193. palign = MAX(64, track->group_size / surf->bpe);
  194. surf->layer_size = surf->nbx * surf->nby * surf->bpe * surf->nsamples;
  195. surf->base_align = track->group_size;
  196. surf->palign = palign;
  197. surf->halign = 1;
  198. if (surf->nbx & (palign - 1)) {
  199. if (prefix) {
  200. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
  201. __func__, __LINE__, prefix, surf->nbx, palign);
  202. }
  203. return -EINVAL;
  204. }
  205. return 0;
  206. }
  207. static int evergreen_surface_check_1d(struct radeon_cs_parser *p,
  208. struct eg_surface *surf,
  209. const char *prefix)
  210. {
  211. struct evergreen_cs_track *track = p->track;
  212. unsigned palign;
  213. palign = track->group_size / (8 * surf->bpe * surf->nsamples);
  214. palign = MAX(8, palign);
  215. surf->layer_size = surf->nbx * surf->nby * surf->bpe;
  216. surf->base_align = track->group_size;
  217. surf->palign = palign;
  218. surf->halign = 8;
  219. if ((surf->nbx & (palign - 1))) {
  220. if (prefix) {
  221. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d (%d %d %d)\n",
  222. __func__, __LINE__, prefix, surf->nbx, palign,
  223. track->group_size, surf->bpe, surf->nsamples);
  224. }
  225. return -EINVAL;
  226. }
  227. if ((surf->nby & (8 - 1))) {
  228. if (prefix) {
  229. dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with 8\n",
  230. __func__, __LINE__, prefix, surf->nby);
  231. }
  232. return -EINVAL;
  233. }
  234. return 0;
  235. }
  236. static int evergreen_surface_check_2d(struct radeon_cs_parser *p,
  237. struct eg_surface *surf,
  238. const char *prefix)
  239. {
  240. struct evergreen_cs_track *track = p->track;
  241. unsigned palign, halign, tileb, slice_pt;
  242. unsigned mtile_pr, mtile_ps, mtileb;
  243. tileb = 64 * surf->bpe * surf->nsamples;
  244. slice_pt = 1;
  245. if (tileb > surf->tsplit) {
  246. slice_pt = tileb / surf->tsplit;
  247. }
  248. tileb = tileb / slice_pt;
  249. /* macro tile width & height */
  250. palign = (8 * surf->bankw * track->npipes) * surf->mtilea;
  251. halign = (8 * surf->bankh * surf->nbanks) / surf->mtilea;
  252. mtileb = (palign / 8) * (halign / 8) * tileb;
  253. mtile_pr = surf->nbx / palign;
  254. mtile_ps = (mtile_pr * surf->nby) / halign;
  255. surf->layer_size = mtile_ps * mtileb * slice_pt;
  256. surf->base_align = (palign / 8) * (halign / 8) * tileb;
  257. surf->palign = palign;
  258. surf->halign = halign;
  259. if ((surf->nbx & (palign - 1))) {
  260. if (prefix) {
  261. dev_warn(p->dev, "%s:%d %s pitch %d invalid must be aligned with %d\n",
  262. __func__, __LINE__, prefix, surf->nbx, palign);
  263. }
  264. return -EINVAL;
  265. }
  266. if ((surf->nby & (halign - 1))) {
  267. if (prefix) {
  268. dev_warn(p->dev, "%s:%d %s height %d invalid must be aligned with %d\n",
  269. __func__, __LINE__, prefix, surf->nby, halign);
  270. }
  271. return -EINVAL;
  272. }
  273. return 0;
  274. }
  275. static int evergreen_surface_check(struct radeon_cs_parser *p,
  276. struct eg_surface *surf,
  277. const char *prefix)
  278. {
  279. /* some common value computed here */
  280. surf->bpe = r600_fmt_get_blocksize(surf->format);
  281. switch (surf->mode) {
  282. case ARRAY_LINEAR_GENERAL:
  283. return evergreen_surface_check_linear(p, surf, prefix);
  284. case ARRAY_LINEAR_ALIGNED:
  285. return evergreen_surface_check_linear_aligned(p, surf, prefix);
  286. case ARRAY_1D_TILED_THIN1:
  287. return evergreen_surface_check_1d(p, surf, prefix);
  288. case ARRAY_2D_TILED_THIN1:
  289. return evergreen_surface_check_2d(p, surf, prefix);
  290. default:
  291. dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
  292. __func__, __LINE__, prefix, surf->mode);
  293. return -EINVAL;
  294. }
  295. return -EINVAL;
  296. }
  297. static int evergreen_surface_value_conv_check(struct radeon_cs_parser *p,
  298. struct eg_surface *surf,
  299. const char *prefix)
  300. {
  301. switch (surf->mode) {
  302. case ARRAY_2D_TILED_THIN1:
  303. break;
  304. case ARRAY_LINEAR_GENERAL:
  305. case ARRAY_LINEAR_ALIGNED:
  306. case ARRAY_1D_TILED_THIN1:
  307. return 0;
  308. default:
  309. dev_warn(p->dev, "%s:%d %s invalid array mode %d\n",
  310. __func__, __LINE__, prefix, surf->mode);
  311. return -EINVAL;
  312. }
  313. switch (surf->nbanks) {
  314. case 0: surf->nbanks = 2; break;
  315. case 1: surf->nbanks = 4; break;
  316. case 2: surf->nbanks = 8; break;
  317. case 3: surf->nbanks = 16; break;
  318. default:
  319. dev_warn(p->dev, "%s:%d %s invalid number of banks %d\n",
  320. __func__, __LINE__, prefix, surf->nbanks);
  321. return -EINVAL;
  322. }
  323. switch (surf->bankw) {
  324. case 0: surf->bankw = 1; break;
  325. case 1: surf->bankw = 2; break;
  326. case 2: surf->bankw = 4; break;
  327. case 3: surf->bankw = 8; break;
  328. default:
  329. dev_warn(p->dev, "%s:%d %s invalid bankw %d\n",
  330. __func__, __LINE__, prefix, surf->bankw);
  331. return -EINVAL;
  332. }
  333. switch (surf->bankh) {
  334. case 0: surf->bankh = 1; break;
  335. case 1: surf->bankh = 2; break;
  336. case 2: surf->bankh = 4; break;
  337. case 3: surf->bankh = 8; break;
  338. default:
  339. dev_warn(p->dev, "%s:%d %s invalid bankh %d\n",
  340. __func__, __LINE__, prefix, surf->bankh);
  341. return -EINVAL;
  342. }
  343. switch (surf->mtilea) {
  344. case 0: surf->mtilea = 1; break;
  345. case 1: surf->mtilea = 2; break;
  346. case 2: surf->mtilea = 4; break;
  347. case 3: surf->mtilea = 8; break;
  348. default:
  349. dev_warn(p->dev, "%s:%d %s invalid macro tile aspect %d\n",
  350. __func__, __LINE__, prefix, surf->mtilea);
  351. return -EINVAL;
  352. }
  353. switch (surf->tsplit) {
  354. case 0: surf->tsplit = 64; break;
  355. case 1: surf->tsplit = 128; break;
  356. case 2: surf->tsplit = 256; break;
  357. case 3: surf->tsplit = 512; break;
  358. case 4: surf->tsplit = 1024; break;
  359. case 5: surf->tsplit = 2048; break;
  360. case 6: surf->tsplit = 4096; break;
  361. default:
  362. dev_warn(p->dev, "%s:%d %s invalid tile split %d\n",
  363. __func__, __LINE__, prefix, surf->tsplit);
  364. return -EINVAL;
  365. }
  366. return 0;
  367. }
  368. static int evergreen_cs_track_validate_cb(struct radeon_cs_parser *p, unsigned id)
  369. {
  370. struct evergreen_cs_track *track = p->track;
  371. struct eg_surface surf;
  372. unsigned pitch, slice, mslice;
  373. unsigned long offset;
  374. int r;
  375. mslice = G_028C6C_SLICE_MAX(track->cb_color_view[id]) + 1;
  376. pitch = track->cb_color_pitch[id];
  377. slice = track->cb_color_slice[id];
  378. surf.nbx = (pitch + 1) * 8;
  379. surf.nby = ((slice + 1) * 64) / surf.nbx;
  380. surf.mode = G_028C70_ARRAY_MODE(track->cb_color_info[id]);
  381. surf.format = G_028C70_FORMAT(track->cb_color_info[id]);
  382. surf.tsplit = G_028C74_TILE_SPLIT(track->cb_color_attrib[id]);
  383. surf.nbanks = G_028C74_NUM_BANKS(track->cb_color_attrib[id]);
  384. surf.bankw = G_028C74_BANK_WIDTH(track->cb_color_attrib[id]);
  385. surf.bankh = G_028C74_BANK_HEIGHT(track->cb_color_attrib[id]);
  386. surf.mtilea = G_028C74_MACRO_TILE_ASPECT(track->cb_color_attrib[id]);
  387. surf.nsamples = 1;
  388. if (!r600_fmt_is_valid_color(surf.format)) {
  389. dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08x)\n",
  390. __func__, __LINE__, surf.format,
  391. id, track->cb_color_info[id]);
  392. return -EINVAL;
  393. }
  394. r = evergreen_surface_value_conv_check(p, &surf, "cb");
  395. if (r) {
  396. return r;
  397. }
  398. r = evergreen_surface_check(p, &surf, "cb");
  399. if (r) {
  400. dev_warn(p->dev, "%s:%d cb[%d] invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  401. __func__, __LINE__, id, track->cb_color_pitch[id],
  402. track->cb_color_slice[id], track->cb_color_attrib[id],
  403. track->cb_color_info[id]);
  404. return r;
  405. }
  406. offset = track->cb_color_bo_offset[id] << 8;
  407. if (offset & (surf.base_align - 1)) {
  408. dev_warn(p->dev, "%s:%d cb[%d] bo base %ld not aligned with %ld\n",
  409. __func__, __LINE__, id, offset, surf.base_align);
  410. return -EINVAL;
  411. }
  412. offset += surf.layer_size * mslice;
  413. if (offset > radeon_bo_size(track->cb_color_bo[id])) {
  414. /* old ddx are broken they allocate bo with w*h*bpp but
  415. * program slice with ALIGN(h, 8), catch this and patch
  416. * command stream.
  417. */
  418. if (!surf.mode) {
  419. uint32_t *ib = p->ib.ptr;
  420. unsigned long tmp, nby, bsize, size, min = 0;
  421. /* find the height the ddx wants */
  422. if (surf.nby > 8) {
  423. min = surf.nby - 8;
  424. }
  425. bsize = radeon_bo_size(track->cb_color_bo[id]);
  426. tmp = track->cb_color_bo_offset[id] << 8;
  427. for (nby = surf.nby; nby > min; nby--) {
  428. size = nby * surf.nbx * surf.bpe * surf.nsamples;
  429. if ((tmp + size * mslice) <= bsize) {
  430. break;
  431. }
  432. }
  433. if (nby > min) {
  434. surf.nby = nby;
  435. slice = ((nby * surf.nbx) / 64) - 1;
  436. if (!evergreen_surface_check(p, &surf, "cb")) {
  437. /* check if this one works */
  438. tmp += surf.layer_size * mslice;
  439. if (tmp <= bsize) {
  440. ib[track->cb_color_slice_idx[id]] = slice;
  441. goto old_ddx_ok;
  442. }
  443. }
  444. }
  445. }
  446. dev_warn(p->dev, "%s:%d cb[%d] bo too small (layer size %d, "
  447. "offset %d, max layer %d, bo size %ld, slice %d)\n",
  448. __func__, __LINE__, id, surf.layer_size,
  449. track->cb_color_bo_offset[id] << 8, mslice,
  450. radeon_bo_size(track->cb_color_bo[id]), slice);
  451. dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
  452. __func__, __LINE__, surf.nbx, surf.nby,
  453. surf.mode, surf.bpe, surf.nsamples,
  454. surf.bankw, surf.bankh,
  455. surf.tsplit, surf.mtilea);
  456. return -EINVAL;
  457. }
  458. old_ddx_ok:
  459. return 0;
  460. }
  461. static int evergreen_cs_track_validate_htile(struct radeon_cs_parser *p,
  462. unsigned nbx, unsigned nby)
  463. {
  464. struct evergreen_cs_track *track = p->track;
  465. unsigned long size;
  466. if (track->htile_bo == NULL) {
  467. dev_warn(p->dev, "%s:%d htile enabled without htile surface 0x%08x\n",
  468. __func__, __LINE__, track->db_z_info);
  469. return -EINVAL;
  470. }
  471. if (G_028ABC_LINEAR(track->htile_surface)) {
  472. /* pitch must be 16 htiles aligned == 16 * 8 pixel aligned */
  473. nbx = round_up(nbx, 16 * 8);
  474. /* height is npipes htiles aligned == npipes * 8 pixel aligned */
  475. nby = round_up(nby, track->npipes * 8);
  476. } else {
  477. /* always assume 8x8 htile */
  478. /* align is htile align * 8, htile align vary according to
  479. * number of pipe and tile width and nby
  480. */
  481. switch (track->npipes) {
  482. case 8:
  483. /* HTILE_WIDTH = 8 & HTILE_HEIGHT = 8*/
  484. nbx = round_up(nbx, 64 * 8);
  485. nby = round_up(nby, 64 * 8);
  486. break;
  487. case 4:
  488. /* HTILE_WIDTH = 8 & HTILE_HEIGHT = 8*/
  489. nbx = round_up(nbx, 64 * 8);
  490. nby = round_up(nby, 32 * 8);
  491. break;
  492. case 2:
  493. /* HTILE_WIDTH = 8 & HTILE_HEIGHT = 8*/
  494. nbx = round_up(nbx, 32 * 8);
  495. nby = round_up(nby, 32 * 8);
  496. break;
  497. case 1:
  498. /* HTILE_WIDTH = 8 & HTILE_HEIGHT = 8*/
  499. nbx = round_up(nbx, 32 * 8);
  500. nby = round_up(nby, 16 * 8);
  501. break;
  502. default:
  503. dev_warn(p->dev, "%s:%d invalid num pipes %d\n",
  504. __func__, __LINE__, track->npipes);
  505. return -EINVAL;
  506. }
  507. }
  508. /* compute number of htile */
  509. nbx = nbx >> 3;
  510. nby = nby >> 3;
  511. /* size must be aligned on npipes * 2K boundary */
  512. size = roundup(nbx * nby * 4, track->npipes * (2 << 10));
  513. size += track->htile_offset;
  514. if (size > radeon_bo_size(track->htile_bo)) {
  515. dev_warn(p->dev, "%s:%d htile surface too small %ld for %ld (%d %d)\n",
  516. __func__, __LINE__, radeon_bo_size(track->htile_bo),
  517. size, nbx, nby);
  518. return -EINVAL;
  519. }
  520. return 0;
  521. }
  522. static int evergreen_cs_track_validate_stencil(struct radeon_cs_parser *p)
  523. {
  524. struct evergreen_cs_track *track = p->track;
  525. struct eg_surface surf;
  526. unsigned pitch, slice, mslice;
  527. unsigned long offset;
  528. int r;
  529. mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
  530. pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
  531. slice = track->db_depth_slice;
  532. surf.nbx = (pitch + 1) * 8;
  533. surf.nby = ((slice + 1) * 64) / surf.nbx;
  534. surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
  535. surf.format = G_028044_FORMAT(track->db_s_info);
  536. surf.tsplit = G_028044_TILE_SPLIT(track->db_s_info);
  537. surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
  538. surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
  539. surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
  540. surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
  541. surf.nsamples = 1;
  542. if (surf.format != 1) {
  543. dev_warn(p->dev, "%s:%d stencil invalid format %d\n",
  544. __func__, __LINE__, surf.format);
  545. return -EINVAL;
  546. }
  547. /* replace by color format so we can use same code */
  548. surf.format = V_028C70_COLOR_8;
  549. r = evergreen_surface_value_conv_check(p, &surf, "stencil");
  550. if (r) {
  551. return r;
  552. }
  553. r = evergreen_surface_check(p, &surf, NULL);
  554. if (r) {
  555. /* old userspace doesn't compute proper depth/stencil alignment
  556. * check that alignment against a bigger byte per elements and
  557. * only report if that alignment is wrong too.
  558. */
  559. surf.format = V_028C70_COLOR_8_8_8_8;
  560. r = evergreen_surface_check(p, &surf, "stencil");
  561. if (r) {
  562. dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  563. __func__, __LINE__, track->db_depth_size,
  564. track->db_depth_slice, track->db_s_info, track->db_z_info);
  565. }
  566. return r;
  567. }
  568. offset = track->db_s_read_offset << 8;
  569. if (offset & (surf.base_align - 1)) {
  570. dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
  571. __func__, __LINE__, offset, surf.base_align);
  572. return -EINVAL;
  573. }
  574. offset += surf.layer_size * mslice;
  575. if (offset > radeon_bo_size(track->db_s_read_bo)) {
  576. dev_warn(p->dev, "%s:%d stencil read bo too small (layer size %d, "
  577. "offset %ld, max layer %d, bo size %ld)\n",
  578. __func__, __LINE__, surf.layer_size,
  579. (unsigned long)track->db_s_read_offset << 8, mslice,
  580. radeon_bo_size(track->db_s_read_bo));
  581. dev_warn(p->dev, "%s:%d stencil invalid (0x%08x 0x%08x 0x%08x 0x%08x)\n",
  582. __func__, __LINE__, track->db_depth_size,
  583. track->db_depth_slice, track->db_s_info, track->db_z_info);
  584. return -EINVAL;
  585. }
  586. offset = track->db_s_write_offset << 8;
  587. if (offset & (surf.base_align - 1)) {
  588. dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
  589. __func__, __LINE__, offset, surf.base_align);
  590. return -EINVAL;
  591. }
  592. offset += surf.layer_size * mslice;
  593. if (offset > radeon_bo_size(track->db_s_write_bo)) {
  594. dev_warn(p->dev, "%s:%d stencil write bo too small (layer size %d, "
  595. "offset %ld, max layer %d, bo size %ld)\n",
  596. __func__, __LINE__, surf.layer_size,
  597. (unsigned long)track->db_s_write_offset << 8, mslice,
  598. radeon_bo_size(track->db_s_write_bo));
  599. return -EINVAL;
  600. }
  601. /* hyperz */
  602. if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
  603. r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
  604. if (r) {
  605. return r;
  606. }
  607. }
  608. return 0;
  609. }
  610. static int evergreen_cs_track_validate_depth(struct radeon_cs_parser *p)
  611. {
  612. struct evergreen_cs_track *track = p->track;
  613. struct eg_surface surf;
  614. unsigned pitch, slice, mslice;
  615. unsigned long offset;
  616. int r;
  617. mslice = G_028008_SLICE_MAX(track->db_depth_view) + 1;
  618. pitch = G_028058_PITCH_TILE_MAX(track->db_depth_size);
  619. slice = track->db_depth_slice;
  620. surf.nbx = (pitch + 1) * 8;
  621. surf.nby = ((slice + 1) * 64) / surf.nbx;
  622. surf.mode = G_028040_ARRAY_MODE(track->db_z_info);
  623. surf.format = G_028040_FORMAT(track->db_z_info);
  624. surf.tsplit = G_028040_TILE_SPLIT(track->db_z_info);
  625. surf.nbanks = G_028040_NUM_BANKS(track->db_z_info);
  626. surf.bankw = G_028040_BANK_WIDTH(track->db_z_info);
  627. surf.bankh = G_028040_BANK_HEIGHT(track->db_z_info);
  628. surf.mtilea = G_028040_MACRO_TILE_ASPECT(track->db_z_info);
  629. surf.nsamples = 1;
  630. switch (surf.format) {
  631. case V_028040_Z_16:
  632. surf.format = V_028C70_COLOR_16;
  633. break;
  634. case V_028040_Z_24:
  635. case V_028040_Z_32_FLOAT:
  636. surf.format = V_028C70_COLOR_8_8_8_8;
  637. break;
  638. default:
  639. dev_warn(p->dev, "%s:%d depth invalid format %d\n",
  640. __func__, __LINE__, surf.format);
  641. return -EINVAL;
  642. }
  643. r = evergreen_surface_value_conv_check(p, &surf, "depth");
  644. if (r) {
  645. dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
  646. __func__, __LINE__, track->db_depth_size,
  647. track->db_depth_slice, track->db_z_info);
  648. return r;
  649. }
  650. r = evergreen_surface_check(p, &surf, "depth");
  651. if (r) {
  652. dev_warn(p->dev, "%s:%d depth invalid (0x%08x 0x%08x 0x%08x)\n",
  653. __func__, __LINE__, track->db_depth_size,
  654. track->db_depth_slice, track->db_z_info);
  655. return r;
  656. }
  657. offset = track->db_z_read_offset << 8;
  658. if (offset & (surf.base_align - 1)) {
  659. dev_warn(p->dev, "%s:%d stencil read bo base %ld not aligned with %ld\n",
  660. __func__, __LINE__, offset, surf.base_align);
  661. return -EINVAL;
  662. }
  663. offset += surf.layer_size * mslice;
  664. if (offset > radeon_bo_size(track->db_z_read_bo)) {
  665. dev_warn(p->dev, "%s:%d depth read bo too small (layer size %d, "
  666. "offset %ld, max layer %d, bo size %ld)\n",
  667. __func__, __LINE__, surf.layer_size,
  668. (unsigned long)track->db_z_read_offset << 8, mslice,
  669. radeon_bo_size(track->db_z_read_bo));
  670. return -EINVAL;
  671. }
  672. offset = track->db_z_write_offset << 8;
  673. if (offset & (surf.base_align - 1)) {
  674. dev_warn(p->dev, "%s:%d stencil write bo base %ld not aligned with %ld\n",
  675. __func__, __LINE__, offset, surf.base_align);
  676. return -EINVAL;
  677. }
  678. offset += surf.layer_size * mslice;
  679. if (offset > radeon_bo_size(track->db_z_write_bo)) {
  680. dev_warn(p->dev, "%s:%d depth write bo too small (layer size %d, "
  681. "offset %ld, max layer %d, bo size %ld)\n",
  682. __func__, __LINE__, surf.layer_size,
  683. (unsigned long)track->db_z_write_offset << 8, mslice,
  684. radeon_bo_size(track->db_z_write_bo));
  685. return -EINVAL;
  686. }
  687. /* hyperz */
  688. if (G_028040_TILE_SURFACE_ENABLE(track->db_z_info)) {
  689. r = evergreen_cs_track_validate_htile(p, surf.nbx, surf.nby);
  690. if (r) {
  691. return r;
  692. }
  693. }
  694. return 0;
  695. }
  696. static int evergreen_cs_track_validate_texture(struct radeon_cs_parser *p,
  697. struct radeon_bo *texture,
  698. struct radeon_bo *mipmap,
  699. unsigned idx)
  700. {
  701. struct eg_surface surf;
  702. unsigned long toffset, moffset;
  703. unsigned dim, llevel, mslice, width, height, depth, i;
  704. u32 texdw[8];
  705. int r;
  706. texdw[0] = radeon_get_ib_value(p, idx + 0);
  707. texdw[1] = radeon_get_ib_value(p, idx + 1);
  708. texdw[2] = radeon_get_ib_value(p, idx + 2);
  709. texdw[3] = radeon_get_ib_value(p, idx + 3);
  710. texdw[4] = radeon_get_ib_value(p, idx + 4);
  711. texdw[5] = radeon_get_ib_value(p, idx + 5);
  712. texdw[6] = radeon_get_ib_value(p, idx + 6);
  713. texdw[7] = radeon_get_ib_value(p, idx + 7);
  714. dim = G_030000_DIM(texdw[0]);
  715. llevel = G_030014_LAST_LEVEL(texdw[5]);
  716. mslice = G_030014_LAST_ARRAY(texdw[5]) + 1;
  717. width = G_030000_TEX_WIDTH(texdw[0]) + 1;
  718. height = G_030004_TEX_HEIGHT(texdw[1]) + 1;
  719. depth = G_030004_TEX_DEPTH(texdw[1]) + 1;
  720. surf.format = G_03001C_DATA_FORMAT(texdw[7]);
  721. surf.nbx = (G_030000_PITCH(texdw[0]) + 1) * 8;
  722. surf.nbx = r600_fmt_get_nblocksx(surf.format, surf.nbx);
  723. surf.nby = r600_fmt_get_nblocksy(surf.format, height);
  724. surf.mode = G_030004_ARRAY_MODE(texdw[1]);
  725. surf.tsplit = G_030018_TILE_SPLIT(texdw[6]);
  726. surf.nbanks = G_03001C_NUM_BANKS(texdw[7]);
  727. surf.bankw = G_03001C_BANK_WIDTH(texdw[7]);
  728. surf.bankh = G_03001C_BANK_HEIGHT(texdw[7]);
  729. surf.mtilea = G_03001C_MACRO_TILE_ASPECT(texdw[7]);
  730. surf.nsamples = 1;
  731. toffset = texdw[2] << 8;
  732. moffset = texdw[3] << 8;
  733. if (!r600_fmt_is_valid_texture(surf.format, p->family)) {
  734. dev_warn(p->dev, "%s:%d texture invalid format %d\n",
  735. __func__, __LINE__, surf.format);
  736. return -EINVAL;
  737. }
  738. switch (dim) {
  739. case V_030000_SQ_TEX_DIM_1D:
  740. case V_030000_SQ_TEX_DIM_2D:
  741. case V_030000_SQ_TEX_DIM_CUBEMAP:
  742. case V_030000_SQ_TEX_DIM_1D_ARRAY:
  743. case V_030000_SQ_TEX_DIM_2D_ARRAY:
  744. depth = 1;
  745. break;
  746. case V_030000_SQ_TEX_DIM_2D_MSAA:
  747. case V_030000_SQ_TEX_DIM_2D_ARRAY_MSAA:
  748. surf.nsamples = 1 << llevel;
  749. llevel = 0;
  750. depth = 1;
  751. break;
  752. case V_030000_SQ_TEX_DIM_3D:
  753. break;
  754. default:
  755. dev_warn(p->dev, "%s:%d texture invalid dimension %d\n",
  756. __func__, __LINE__, dim);
  757. return -EINVAL;
  758. }
  759. r = evergreen_surface_value_conv_check(p, &surf, "texture");
  760. if (r) {
  761. return r;
  762. }
  763. /* align height */
  764. evergreen_surface_check(p, &surf, NULL);
  765. surf.nby = ALIGN(surf.nby, surf.halign);
  766. r = evergreen_surface_check(p, &surf, "texture");
  767. if (r) {
  768. dev_warn(p->dev, "%s:%d texture invalid 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  769. __func__, __LINE__, texdw[0], texdw[1], texdw[4],
  770. texdw[5], texdw[6], texdw[7]);
  771. return r;
  772. }
  773. /* check texture size */
  774. if (toffset & (surf.base_align - 1)) {
  775. dev_warn(p->dev, "%s:%d texture bo base %ld not aligned with %ld\n",
  776. __func__, __LINE__, toffset, surf.base_align);
  777. return -EINVAL;
  778. }
  779. if (surf.nsamples <= 1 && moffset & (surf.base_align - 1)) {
  780. dev_warn(p->dev, "%s:%d mipmap bo base %ld not aligned with %ld\n",
  781. __func__, __LINE__, moffset, surf.base_align);
  782. return -EINVAL;
  783. }
  784. if (dim == SQ_TEX_DIM_3D) {
  785. toffset += surf.layer_size * depth;
  786. } else {
  787. toffset += surf.layer_size * mslice;
  788. }
  789. if (toffset > radeon_bo_size(texture)) {
  790. dev_warn(p->dev, "%s:%d texture bo too small (layer size %d, "
  791. "offset %ld, max layer %d, depth %d, bo size %ld) (%d %d)\n",
  792. __func__, __LINE__, surf.layer_size,
  793. (unsigned long)texdw[2] << 8, mslice,
  794. depth, radeon_bo_size(texture),
  795. surf.nbx, surf.nby);
  796. return -EINVAL;
  797. }
  798. if (!mipmap) {
  799. if (llevel) {
  800. dev_warn(p->dev, "%s:%i got NULL MIP_ADDRESS relocation\n",
  801. __func__, __LINE__);
  802. return -EINVAL;
  803. } else {
  804. return 0; /* everything's ok */
  805. }
  806. }
  807. /* check mipmap size */
  808. for (i = 1; i <= llevel; i++) {
  809. unsigned w, h, d;
  810. w = r600_mip_minify(width, i);
  811. h = r600_mip_minify(height, i);
  812. d = r600_mip_minify(depth, i);
  813. surf.nbx = r600_fmt_get_nblocksx(surf.format, w);
  814. surf.nby = r600_fmt_get_nblocksy(surf.format, h);
  815. switch (surf.mode) {
  816. case ARRAY_2D_TILED_THIN1:
  817. if (surf.nbx < surf.palign || surf.nby < surf.halign) {
  818. surf.mode = ARRAY_1D_TILED_THIN1;
  819. }
  820. /* recompute alignment */
  821. evergreen_surface_check(p, &surf, NULL);
  822. break;
  823. case ARRAY_LINEAR_GENERAL:
  824. case ARRAY_LINEAR_ALIGNED:
  825. case ARRAY_1D_TILED_THIN1:
  826. break;
  827. default:
  828. dev_warn(p->dev, "%s:%d invalid array mode %d\n",
  829. __func__, __LINE__, surf.mode);
  830. return -EINVAL;
  831. }
  832. surf.nbx = ALIGN(surf.nbx, surf.palign);
  833. surf.nby = ALIGN(surf.nby, surf.halign);
  834. r = evergreen_surface_check(p, &surf, "mipmap");
  835. if (r) {
  836. return r;
  837. }
  838. if (dim == SQ_TEX_DIM_3D) {
  839. moffset += surf.layer_size * d;
  840. } else {
  841. moffset += surf.layer_size * mslice;
  842. }
  843. if (moffset > radeon_bo_size(mipmap)) {
  844. dev_warn(p->dev, "%s:%d mipmap [%d] bo too small (layer size %d, "
  845. "offset %ld, coffset %ld, max layer %d, depth %d, "
  846. "bo size %ld) level0 (%d %d %d)\n",
  847. __func__, __LINE__, i, surf.layer_size,
  848. (unsigned long)texdw[3] << 8, moffset, mslice,
  849. d, radeon_bo_size(mipmap),
  850. width, height, depth);
  851. dev_warn(p->dev, "%s:%d problematic surf: (%d %d) (%d %d %d %d %d %d %d)\n",
  852. __func__, __LINE__, surf.nbx, surf.nby,
  853. surf.mode, surf.bpe, surf.nsamples,
  854. surf.bankw, surf.bankh,
  855. surf.tsplit, surf.mtilea);
  856. return -EINVAL;
  857. }
  858. }
  859. return 0;
  860. }
  861. static int evergreen_cs_track_check(struct radeon_cs_parser *p)
  862. {
  863. struct evergreen_cs_track *track = p->track;
  864. unsigned tmp, i;
  865. int r;
  866. unsigned buffer_mask = 0;
  867. /* check streamout */
  868. if (track->streamout_dirty && track->vgt_strmout_config) {
  869. for (i = 0; i < 4; i++) {
  870. if (track->vgt_strmout_config & (1 << i)) {
  871. buffer_mask |= (track->vgt_strmout_buffer_config >> (i * 4)) & 0xf;
  872. }
  873. }
  874. for (i = 0; i < 4; i++) {
  875. if (buffer_mask & (1 << i)) {
  876. if (track->vgt_strmout_bo[i]) {
  877. u64 offset = (u64)track->vgt_strmout_bo_offset[i] +
  878. (u64)track->vgt_strmout_size[i];
  879. if (offset > radeon_bo_size(track->vgt_strmout_bo[i])) {
  880. DRM_ERROR("streamout %d bo too small: 0x%llx, 0x%lx\n",
  881. i, offset,
  882. radeon_bo_size(track->vgt_strmout_bo[i]));
  883. return -EINVAL;
  884. }
  885. } else {
  886. dev_warn(p->dev, "No buffer for streamout %d\n", i);
  887. return -EINVAL;
  888. }
  889. }
  890. }
  891. track->streamout_dirty = false;
  892. }
  893. if (track->sx_misc_kill_all_prims)
  894. return 0;
  895. /* check that we have a cb for each enabled target
  896. */
  897. if (track->cb_dirty) {
  898. tmp = track->cb_target_mask;
  899. for (i = 0; i < 8; i++) {
  900. u32 format = G_028C70_FORMAT(track->cb_color_info[i]);
  901. if (format != V_028C70_COLOR_INVALID &&
  902. (tmp >> (i * 4)) & 0xF) {
  903. /* at least one component is enabled */
  904. if (track->cb_color_bo[i] == NULL) {
  905. dev_warn(p->dev, "%s:%d mask 0x%08X | 0x%08X no cb for %d\n",
  906. __func__, __LINE__, track->cb_target_mask, track->cb_shader_mask, i);
  907. return -EINVAL;
  908. }
  909. /* check cb */
  910. r = evergreen_cs_track_validate_cb(p, i);
  911. if (r) {
  912. return r;
  913. }
  914. }
  915. }
  916. track->cb_dirty = false;
  917. }
  918. if (track->db_dirty) {
  919. /* Check stencil buffer */
  920. if (G_028044_FORMAT(track->db_s_info) != V_028044_STENCIL_INVALID &&
  921. G_028800_STENCIL_ENABLE(track->db_depth_control)) {
  922. r = evergreen_cs_track_validate_stencil(p);
  923. if (r)
  924. return r;
  925. }
  926. /* Check depth buffer */
  927. if (G_028040_FORMAT(track->db_z_info) != V_028040_Z_INVALID &&
  928. G_028800_Z_ENABLE(track->db_depth_control)) {
  929. r = evergreen_cs_track_validate_depth(p);
  930. if (r)
  931. return r;
  932. }
  933. track->db_dirty = false;
  934. }
  935. return 0;
  936. }
  937. /**
  938. * evergreen_cs_packet_parse_vline() - parse userspace VLINE packet
  939. * @parser: parser structure holding parsing context.
  940. *
  941. * This is an Evergreen(+)-specific function for parsing VLINE packets.
  942. * Real work is done by r600_cs_common_vline_parse function.
  943. * Here we just set up ASIC-specific register table and call
  944. * the common implementation function.
  945. */
  946. static int evergreen_cs_packet_parse_vline(struct radeon_cs_parser *p)
  947. {
  948. static uint32_t vline_start_end[6] = {
  949. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC0_REGISTER_OFFSET,
  950. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC1_REGISTER_OFFSET,
  951. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC2_REGISTER_OFFSET,
  952. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC3_REGISTER_OFFSET,
  953. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC4_REGISTER_OFFSET,
  954. EVERGREEN_VLINE_START_END + EVERGREEN_CRTC5_REGISTER_OFFSET
  955. };
  956. static uint32_t vline_status[6] = {
  957. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
  958. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
  959. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
  960. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
  961. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
  962. EVERGREEN_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET
  963. };
  964. return r600_cs_common_vline_parse(p, vline_start_end, vline_status);
  965. }
  966. static int evergreen_packet0_check(struct radeon_cs_parser *p,
  967. struct radeon_cs_packet *pkt,
  968. unsigned idx, unsigned reg)
  969. {
  970. int r;
  971. switch (reg) {
  972. case EVERGREEN_VLINE_START_END:
  973. r = evergreen_cs_packet_parse_vline(p);
  974. if (r) {
  975. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  976. idx, reg);
  977. return r;
  978. }
  979. break;
  980. default:
  981. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  982. reg, idx);
  983. return -EINVAL;
  984. }
  985. return 0;
  986. }
  987. static int evergreen_cs_parse_packet0(struct radeon_cs_parser *p,
  988. struct radeon_cs_packet *pkt)
  989. {
  990. unsigned reg, i;
  991. unsigned idx;
  992. int r;
  993. idx = pkt->idx + 1;
  994. reg = pkt->reg;
  995. for (i = 0; i <= pkt->count; i++, idx++, reg += 4) {
  996. r = evergreen_packet0_check(p, pkt, idx, reg);
  997. if (r) {
  998. return r;
  999. }
  1000. }
  1001. return 0;
  1002. }
  1003. /**
  1004. * evergreen_cs_handle_reg() - process registers that need special handling.
  1005. * @parser: parser structure holding parsing context
  1006. * @reg: register we are testing
  1007. * @idx: index into the cs buffer
  1008. */
  1009. static int evergreen_cs_handle_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
  1010. {
  1011. struct evergreen_cs_track *track = (struct evergreen_cs_track *)p->track;
  1012. struct radeon_bo_list *reloc;
  1013. u32 tmp, *ib;
  1014. int r;
  1015. ib = p->ib.ptr;
  1016. switch (reg) {
  1017. /* force following reg to 0 in an attempt to disable out buffer
  1018. * which will need us to better understand how it works to perform
  1019. * security check on it (Jerome)
  1020. */
  1021. case SQ_ESGS_RING_SIZE:
  1022. case SQ_GSVS_RING_SIZE:
  1023. case SQ_ESTMP_RING_SIZE:
  1024. case SQ_GSTMP_RING_SIZE:
  1025. case SQ_HSTMP_RING_SIZE:
  1026. case SQ_LSTMP_RING_SIZE:
  1027. case SQ_PSTMP_RING_SIZE:
  1028. case SQ_VSTMP_RING_SIZE:
  1029. case SQ_ESGS_RING_ITEMSIZE:
  1030. case SQ_ESTMP_RING_ITEMSIZE:
  1031. case SQ_GSTMP_RING_ITEMSIZE:
  1032. case SQ_GSVS_RING_ITEMSIZE:
  1033. case SQ_GS_VERT_ITEMSIZE:
  1034. case SQ_GS_VERT_ITEMSIZE_1:
  1035. case SQ_GS_VERT_ITEMSIZE_2:
  1036. case SQ_GS_VERT_ITEMSIZE_3:
  1037. case SQ_GSVS_RING_OFFSET_1:
  1038. case SQ_GSVS_RING_OFFSET_2:
  1039. case SQ_GSVS_RING_OFFSET_3:
  1040. case SQ_HSTMP_RING_ITEMSIZE:
  1041. case SQ_LSTMP_RING_ITEMSIZE:
  1042. case SQ_PSTMP_RING_ITEMSIZE:
  1043. case SQ_VSTMP_RING_ITEMSIZE:
  1044. case VGT_TF_RING_SIZE:
  1045. /* get value to populate the IB don't remove */
  1046. /*tmp =radeon_get_ib_value(p, idx);
  1047. ib[idx] = 0;*/
  1048. break;
  1049. case SQ_ESGS_RING_BASE:
  1050. case SQ_GSVS_RING_BASE:
  1051. case SQ_ESTMP_RING_BASE:
  1052. case SQ_GSTMP_RING_BASE:
  1053. case SQ_HSTMP_RING_BASE:
  1054. case SQ_LSTMP_RING_BASE:
  1055. case SQ_PSTMP_RING_BASE:
  1056. case SQ_VSTMP_RING_BASE:
  1057. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1058. if (r) {
  1059. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1060. "0x%04X\n", reg);
  1061. return -EINVAL;
  1062. }
  1063. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1064. break;
  1065. case DB_DEPTH_CONTROL:
  1066. track->db_depth_control = radeon_get_ib_value(p, idx);
  1067. track->db_dirty = true;
  1068. break;
  1069. case CAYMAN_DB_EQAA:
  1070. if (p->rdev->family < CHIP_CAYMAN) {
  1071. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1072. "0x%04X\n", reg);
  1073. return -EINVAL;
  1074. }
  1075. break;
  1076. case CAYMAN_DB_DEPTH_INFO:
  1077. if (p->rdev->family < CHIP_CAYMAN) {
  1078. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1079. "0x%04X\n", reg);
  1080. return -EINVAL;
  1081. }
  1082. break;
  1083. case DB_Z_INFO:
  1084. track->db_z_info = radeon_get_ib_value(p, idx);
  1085. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1086. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1087. if (r) {
  1088. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1089. "0x%04X\n", reg);
  1090. return -EINVAL;
  1091. }
  1092. ib[idx] &= ~Z_ARRAY_MODE(0xf);
  1093. track->db_z_info &= ~Z_ARRAY_MODE(0xf);
  1094. ib[idx] |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1095. track->db_z_info |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1096. if (reloc->tiling_flags & RADEON_TILING_MACRO) {
  1097. unsigned bankw, bankh, mtaspect, tile_split;
  1098. evergreen_tiling_fields(reloc->tiling_flags,
  1099. &bankw, &bankh, &mtaspect,
  1100. &tile_split);
  1101. ib[idx] |= DB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1102. ib[idx] |= DB_TILE_SPLIT(tile_split) |
  1103. DB_BANK_WIDTH(bankw) |
  1104. DB_BANK_HEIGHT(bankh) |
  1105. DB_MACRO_TILE_ASPECT(mtaspect);
  1106. }
  1107. }
  1108. track->db_dirty = true;
  1109. break;
  1110. case DB_STENCIL_INFO:
  1111. track->db_s_info = radeon_get_ib_value(p, idx);
  1112. track->db_dirty = true;
  1113. break;
  1114. case DB_DEPTH_VIEW:
  1115. track->db_depth_view = radeon_get_ib_value(p, idx);
  1116. track->db_dirty = true;
  1117. break;
  1118. case DB_DEPTH_SIZE:
  1119. track->db_depth_size = radeon_get_ib_value(p, idx);
  1120. track->db_dirty = true;
  1121. break;
  1122. case R_02805C_DB_DEPTH_SLICE:
  1123. track->db_depth_slice = radeon_get_ib_value(p, idx);
  1124. track->db_dirty = true;
  1125. break;
  1126. case DB_Z_READ_BASE:
  1127. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1128. if (r) {
  1129. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1130. "0x%04X\n", reg);
  1131. return -EINVAL;
  1132. }
  1133. track->db_z_read_offset = radeon_get_ib_value(p, idx);
  1134. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1135. track->db_z_read_bo = reloc->robj;
  1136. track->db_dirty = true;
  1137. break;
  1138. case DB_Z_WRITE_BASE:
  1139. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1140. if (r) {
  1141. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1142. "0x%04X\n", reg);
  1143. return -EINVAL;
  1144. }
  1145. track->db_z_write_offset = radeon_get_ib_value(p, idx);
  1146. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1147. track->db_z_write_bo = reloc->robj;
  1148. track->db_dirty = true;
  1149. break;
  1150. case DB_STENCIL_READ_BASE:
  1151. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1152. if (r) {
  1153. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1154. "0x%04X\n", reg);
  1155. return -EINVAL;
  1156. }
  1157. track->db_s_read_offset = radeon_get_ib_value(p, idx);
  1158. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1159. track->db_s_read_bo = reloc->robj;
  1160. track->db_dirty = true;
  1161. break;
  1162. case DB_STENCIL_WRITE_BASE:
  1163. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1164. if (r) {
  1165. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1166. "0x%04X\n", reg);
  1167. return -EINVAL;
  1168. }
  1169. track->db_s_write_offset = radeon_get_ib_value(p, idx);
  1170. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1171. track->db_s_write_bo = reloc->robj;
  1172. track->db_dirty = true;
  1173. break;
  1174. case VGT_STRMOUT_CONFIG:
  1175. track->vgt_strmout_config = radeon_get_ib_value(p, idx);
  1176. track->streamout_dirty = true;
  1177. break;
  1178. case VGT_STRMOUT_BUFFER_CONFIG:
  1179. track->vgt_strmout_buffer_config = radeon_get_ib_value(p, idx);
  1180. track->streamout_dirty = true;
  1181. break;
  1182. case VGT_STRMOUT_BUFFER_BASE_0:
  1183. case VGT_STRMOUT_BUFFER_BASE_1:
  1184. case VGT_STRMOUT_BUFFER_BASE_2:
  1185. case VGT_STRMOUT_BUFFER_BASE_3:
  1186. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1187. if (r) {
  1188. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1189. "0x%04X\n", reg);
  1190. return -EINVAL;
  1191. }
  1192. tmp = (reg - VGT_STRMOUT_BUFFER_BASE_0) / 16;
  1193. track->vgt_strmout_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
  1194. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1195. track->vgt_strmout_bo[tmp] = reloc->robj;
  1196. track->streamout_dirty = true;
  1197. break;
  1198. case VGT_STRMOUT_BUFFER_SIZE_0:
  1199. case VGT_STRMOUT_BUFFER_SIZE_1:
  1200. case VGT_STRMOUT_BUFFER_SIZE_2:
  1201. case VGT_STRMOUT_BUFFER_SIZE_3:
  1202. tmp = (reg - VGT_STRMOUT_BUFFER_SIZE_0) / 16;
  1203. /* size in register is DWs, convert to bytes */
  1204. track->vgt_strmout_size[tmp] = radeon_get_ib_value(p, idx) * 4;
  1205. track->streamout_dirty = true;
  1206. break;
  1207. case CP_COHER_BASE:
  1208. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1209. if (r) {
  1210. dev_warn(p->dev, "missing reloc for CP_COHER_BASE "
  1211. "0x%04X\n", reg);
  1212. return -EINVAL;
  1213. }
  1214. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1215. break;
  1216. case CB_TARGET_MASK:
  1217. track->cb_target_mask = radeon_get_ib_value(p, idx);
  1218. track->cb_dirty = true;
  1219. break;
  1220. case CB_SHADER_MASK:
  1221. track->cb_shader_mask = radeon_get_ib_value(p, idx);
  1222. track->cb_dirty = true;
  1223. break;
  1224. case PA_SC_AA_CONFIG:
  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. tmp = radeon_get_ib_value(p, idx) & MSAA_NUM_SAMPLES_MASK;
  1231. track->nsamples = 1 << tmp;
  1232. break;
  1233. case CAYMAN_PA_SC_AA_CONFIG:
  1234. if (p->rdev->family < CHIP_CAYMAN) {
  1235. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1236. "0x%04X\n", reg);
  1237. return -EINVAL;
  1238. }
  1239. tmp = radeon_get_ib_value(p, idx) & CAYMAN_MSAA_NUM_SAMPLES_MASK;
  1240. track->nsamples = 1 << tmp;
  1241. break;
  1242. case CB_COLOR0_VIEW:
  1243. case CB_COLOR1_VIEW:
  1244. case CB_COLOR2_VIEW:
  1245. case CB_COLOR3_VIEW:
  1246. case CB_COLOR4_VIEW:
  1247. case CB_COLOR5_VIEW:
  1248. case CB_COLOR6_VIEW:
  1249. case CB_COLOR7_VIEW:
  1250. tmp = (reg - CB_COLOR0_VIEW) / 0x3c;
  1251. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  1252. track->cb_dirty = true;
  1253. break;
  1254. case CB_COLOR8_VIEW:
  1255. case CB_COLOR9_VIEW:
  1256. case CB_COLOR10_VIEW:
  1257. case CB_COLOR11_VIEW:
  1258. tmp = ((reg - CB_COLOR8_VIEW) / 0x1c) + 8;
  1259. track->cb_color_view[tmp] = radeon_get_ib_value(p, idx);
  1260. track->cb_dirty = true;
  1261. break;
  1262. case CB_COLOR0_INFO:
  1263. case CB_COLOR1_INFO:
  1264. case CB_COLOR2_INFO:
  1265. case CB_COLOR3_INFO:
  1266. case CB_COLOR4_INFO:
  1267. case CB_COLOR5_INFO:
  1268. case CB_COLOR6_INFO:
  1269. case CB_COLOR7_INFO:
  1270. tmp = (reg - CB_COLOR0_INFO) / 0x3c;
  1271. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  1272. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1273. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1274. if (r) {
  1275. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1276. "0x%04X\n", reg);
  1277. return -EINVAL;
  1278. }
  1279. ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1280. track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1281. }
  1282. track->cb_dirty = true;
  1283. break;
  1284. case CB_COLOR8_INFO:
  1285. case CB_COLOR9_INFO:
  1286. case CB_COLOR10_INFO:
  1287. case CB_COLOR11_INFO:
  1288. tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
  1289. track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
  1290. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1291. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1292. if (r) {
  1293. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1294. "0x%04X\n", reg);
  1295. return -EINVAL;
  1296. }
  1297. ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1298. track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  1299. }
  1300. track->cb_dirty = true;
  1301. break;
  1302. case CB_COLOR0_PITCH:
  1303. case CB_COLOR1_PITCH:
  1304. case CB_COLOR2_PITCH:
  1305. case CB_COLOR3_PITCH:
  1306. case CB_COLOR4_PITCH:
  1307. case CB_COLOR5_PITCH:
  1308. case CB_COLOR6_PITCH:
  1309. case CB_COLOR7_PITCH:
  1310. tmp = (reg - CB_COLOR0_PITCH) / 0x3c;
  1311. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  1312. track->cb_dirty = true;
  1313. break;
  1314. case CB_COLOR8_PITCH:
  1315. case CB_COLOR9_PITCH:
  1316. case CB_COLOR10_PITCH:
  1317. case CB_COLOR11_PITCH:
  1318. tmp = ((reg - CB_COLOR8_PITCH) / 0x1c) + 8;
  1319. track->cb_color_pitch[tmp] = radeon_get_ib_value(p, idx);
  1320. track->cb_dirty = true;
  1321. break;
  1322. case CB_COLOR0_SLICE:
  1323. case CB_COLOR1_SLICE:
  1324. case CB_COLOR2_SLICE:
  1325. case CB_COLOR3_SLICE:
  1326. case CB_COLOR4_SLICE:
  1327. case CB_COLOR5_SLICE:
  1328. case CB_COLOR6_SLICE:
  1329. case CB_COLOR7_SLICE:
  1330. tmp = (reg - CB_COLOR0_SLICE) / 0x3c;
  1331. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  1332. track->cb_color_slice_idx[tmp] = idx;
  1333. track->cb_dirty = true;
  1334. break;
  1335. case CB_COLOR8_SLICE:
  1336. case CB_COLOR9_SLICE:
  1337. case CB_COLOR10_SLICE:
  1338. case CB_COLOR11_SLICE:
  1339. tmp = ((reg - CB_COLOR8_SLICE) / 0x1c) + 8;
  1340. track->cb_color_slice[tmp] = radeon_get_ib_value(p, idx);
  1341. track->cb_color_slice_idx[tmp] = idx;
  1342. track->cb_dirty = true;
  1343. break;
  1344. case CB_COLOR0_ATTRIB:
  1345. case CB_COLOR1_ATTRIB:
  1346. case CB_COLOR2_ATTRIB:
  1347. case CB_COLOR3_ATTRIB:
  1348. case CB_COLOR4_ATTRIB:
  1349. case CB_COLOR5_ATTRIB:
  1350. case CB_COLOR6_ATTRIB:
  1351. case CB_COLOR7_ATTRIB:
  1352. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1353. if (r) {
  1354. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1355. "0x%04X\n", reg);
  1356. return -EINVAL;
  1357. }
  1358. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1359. if (reloc->tiling_flags & RADEON_TILING_MACRO) {
  1360. unsigned bankw, bankh, mtaspect, tile_split;
  1361. evergreen_tiling_fields(reloc->tiling_flags,
  1362. &bankw, &bankh, &mtaspect,
  1363. &tile_split);
  1364. ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1365. ib[idx] |= CB_TILE_SPLIT(tile_split) |
  1366. CB_BANK_WIDTH(bankw) |
  1367. CB_BANK_HEIGHT(bankh) |
  1368. CB_MACRO_TILE_ASPECT(mtaspect);
  1369. }
  1370. }
  1371. tmp = ((reg - CB_COLOR0_ATTRIB) / 0x3c);
  1372. track->cb_color_attrib[tmp] = ib[idx];
  1373. track->cb_dirty = true;
  1374. break;
  1375. case CB_COLOR8_ATTRIB:
  1376. case CB_COLOR9_ATTRIB:
  1377. case CB_COLOR10_ATTRIB:
  1378. case CB_COLOR11_ATTRIB:
  1379. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1380. if (r) {
  1381. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1382. "0x%04X\n", reg);
  1383. return -EINVAL;
  1384. }
  1385. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  1386. if (reloc->tiling_flags & RADEON_TILING_MACRO) {
  1387. unsigned bankw, bankh, mtaspect, tile_split;
  1388. evergreen_tiling_fields(reloc->tiling_flags,
  1389. &bankw, &bankh, &mtaspect,
  1390. &tile_split);
  1391. ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  1392. ib[idx] |= CB_TILE_SPLIT(tile_split) |
  1393. CB_BANK_WIDTH(bankw) |
  1394. CB_BANK_HEIGHT(bankh) |
  1395. CB_MACRO_TILE_ASPECT(mtaspect);
  1396. }
  1397. }
  1398. tmp = ((reg - CB_COLOR8_ATTRIB) / 0x1c) + 8;
  1399. track->cb_color_attrib[tmp] = ib[idx];
  1400. track->cb_dirty = true;
  1401. break;
  1402. case CB_COLOR0_FMASK:
  1403. case CB_COLOR1_FMASK:
  1404. case CB_COLOR2_FMASK:
  1405. case CB_COLOR3_FMASK:
  1406. case CB_COLOR4_FMASK:
  1407. case CB_COLOR5_FMASK:
  1408. case CB_COLOR6_FMASK:
  1409. case CB_COLOR7_FMASK:
  1410. tmp = (reg - CB_COLOR0_FMASK) / 0x3c;
  1411. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1412. if (r) {
  1413. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  1414. return -EINVAL;
  1415. }
  1416. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1417. track->cb_color_fmask_bo[tmp] = reloc->robj;
  1418. break;
  1419. case CB_COLOR0_CMASK:
  1420. case CB_COLOR1_CMASK:
  1421. case CB_COLOR2_CMASK:
  1422. case CB_COLOR3_CMASK:
  1423. case CB_COLOR4_CMASK:
  1424. case CB_COLOR5_CMASK:
  1425. case CB_COLOR6_CMASK:
  1426. case CB_COLOR7_CMASK:
  1427. tmp = (reg - CB_COLOR0_CMASK) / 0x3c;
  1428. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1429. if (r) {
  1430. dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
  1431. return -EINVAL;
  1432. }
  1433. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1434. track->cb_color_cmask_bo[tmp] = reloc->robj;
  1435. break;
  1436. case CB_COLOR0_FMASK_SLICE:
  1437. case CB_COLOR1_FMASK_SLICE:
  1438. case CB_COLOR2_FMASK_SLICE:
  1439. case CB_COLOR3_FMASK_SLICE:
  1440. case CB_COLOR4_FMASK_SLICE:
  1441. case CB_COLOR5_FMASK_SLICE:
  1442. case CB_COLOR6_FMASK_SLICE:
  1443. case CB_COLOR7_FMASK_SLICE:
  1444. tmp = (reg - CB_COLOR0_FMASK_SLICE) / 0x3c;
  1445. track->cb_color_fmask_slice[tmp] = radeon_get_ib_value(p, idx);
  1446. break;
  1447. case CB_COLOR0_CMASK_SLICE:
  1448. case CB_COLOR1_CMASK_SLICE:
  1449. case CB_COLOR2_CMASK_SLICE:
  1450. case CB_COLOR3_CMASK_SLICE:
  1451. case CB_COLOR4_CMASK_SLICE:
  1452. case CB_COLOR5_CMASK_SLICE:
  1453. case CB_COLOR6_CMASK_SLICE:
  1454. case CB_COLOR7_CMASK_SLICE:
  1455. tmp = (reg - CB_COLOR0_CMASK_SLICE) / 0x3c;
  1456. track->cb_color_cmask_slice[tmp] = radeon_get_ib_value(p, idx);
  1457. break;
  1458. case CB_COLOR0_BASE:
  1459. case CB_COLOR1_BASE:
  1460. case CB_COLOR2_BASE:
  1461. case CB_COLOR3_BASE:
  1462. case CB_COLOR4_BASE:
  1463. case CB_COLOR5_BASE:
  1464. case CB_COLOR6_BASE:
  1465. case CB_COLOR7_BASE:
  1466. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1467. if (r) {
  1468. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1469. "0x%04X\n", reg);
  1470. return -EINVAL;
  1471. }
  1472. tmp = (reg - CB_COLOR0_BASE) / 0x3c;
  1473. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  1474. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1475. track->cb_color_bo[tmp] = reloc->robj;
  1476. track->cb_dirty = true;
  1477. break;
  1478. case CB_COLOR8_BASE:
  1479. case CB_COLOR9_BASE:
  1480. case CB_COLOR10_BASE:
  1481. case CB_COLOR11_BASE:
  1482. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1483. if (r) {
  1484. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1485. "0x%04X\n", reg);
  1486. return -EINVAL;
  1487. }
  1488. tmp = ((reg - CB_COLOR8_BASE) / 0x1c) + 8;
  1489. track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx);
  1490. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1491. track->cb_color_bo[tmp] = reloc->robj;
  1492. track->cb_dirty = true;
  1493. break;
  1494. case DB_HTILE_DATA_BASE:
  1495. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1496. if (r) {
  1497. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1498. "0x%04X\n", reg);
  1499. return -EINVAL;
  1500. }
  1501. track->htile_offset = radeon_get_ib_value(p, idx);
  1502. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1503. track->htile_bo = reloc->robj;
  1504. track->db_dirty = true;
  1505. break;
  1506. case DB_HTILE_SURFACE:
  1507. /* 8x8 only */
  1508. track->htile_surface = radeon_get_ib_value(p, idx);
  1509. /* force 8x8 htile width and height */
  1510. ib[idx] |= 3;
  1511. track->db_dirty = true;
  1512. break;
  1513. case CB_IMMED0_BASE:
  1514. case CB_IMMED1_BASE:
  1515. case CB_IMMED2_BASE:
  1516. case CB_IMMED3_BASE:
  1517. case CB_IMMED4_BASE:
  1518. case CB_IMMED5_BASE:
  1519. case CB_IMMED6_BASE:
  1520. case CB_IMMED7_BASE:
  1521. case CB_IMMED8_BASE:
  1522. case CB_IMMED9_BASE:
  1523. case CB_IMMED10_BASE:
  1524. case CB_IMMED11_BASE:
  1525. case SQ_PGM_START_FS:
  1526. case SQ_PGM_START_ES:
  1527. case SQ_PGM_START_VS:
  1528. case SQ_PGM_START_GS:
  1529. case SQ_PGM_START_PS:
  1530. case SQ_PGM_START_HS:
  1531. case SQ_PGM_START_LS:
  1532. case SQ_CONST_MEM_BASE:
  1533. case SQ_ALU_CONST_CACHE_GS_0:
  1534. case SQ_ALU_CONST_CACHE_GS_1:
  1535. case SQ_ALU_CONST_CACHE_GS_2:
  1536. case SQ_ALU_CONST_CACHE_GS_3:
  1537. case SQ_ALU_CONST_CACHE_GS_4:
  1538. case SQ_ALU_CONST_CACHE_GS_5:
  1539. case SQ_ALU_CONST_CACHE_GS_6:
  1540. case SQ_ALU_CONST_CACHE_GS_7:
  1541. case SQ_ALU_CONST_CACHE_GS_8:
  1542. case SQ_ALU_CONST_CACHE_GS_9:
  1543. case SQ_ALU_CONST_CACHE_GS_10:
  1544. case SQ_ALU_CONST_CACHE_GS_11:
  1545. case SQ_ALU_CONST_CACHE_GS_12:
  1546. case SQ_ALU_CONST_CACHE_GS_13:
  1547. case SQ_ALU_CONST_CACHE_GS_14:
  1548. case SQ_ALU_CONST_CACHE_GS_15:
  1549. case SQ_ALU_CONST_CACHE_PS_0:
  1550. case SQ_ALU_CONST_CACHE_PS_1:
  1551. case SQ_ALU_CONST_CACHE_PS_2:
  1552. case SQ_ALU_CONST_CACHE_PS_3:
  1553. case SQ_ALU_CONST_CACHE_PS_4:
  1554. case SQ_ALU_CONST_CACHE_PS_5:
  1555. case SQ_ALU_CONST_CACHE_PS_6:
  1556. case SQ_ALU_CONST_CACHE_PS_7:
  1557. case SQ_ALU_CONST_CACHE_PS_8:
  1558. case SQ_ALU_CONST_CACHE_PS_9:
  1559. case SQ_ALU_CONST_CACHE_PS_10:
  1560. case SQ_ALU_CONST_CACHE_PS_11:
  1561. case SQ_ALU_CONST_CACHE_PS_12:
  1562. case SQ_ALU_CONST_CACHE_PS_13:
  1563. case SQ_ALU_CONST_CACHE_PS_14:
  1564. case SQ_ALU_CONST_CACHE_PS_15:
  1565. case SQ_ALU_CONST_CACHE_VS_0:
  1566. case SQ_ALU_CONST_CACHE_VS_1:
  1567. case SQ_ALU_CONST_CACHE_VS_2:
  1568. case SQ_ALU_CONST_CACHE_VS_3:
  1569. case SQ_ALU_CONST_CACHE_VS_4:
  1570. case SQ_ALU_CONST_CACHE_VS_5:
  1571. case SQ_ALU_CONST_CACHE_VS_6:
  1572. case SQ_ALU_CONST_CACHE_VS_7:
  1573. case SQ_ALU_CONST_CACHE_VS_8:
  1574. case SQ_ALU_CONST_CACHE_VS_9:
  1575. case SQ_ALU_CONST_CACHE_VS_10:
  1576. case SQ_ALU_CONST_CACHE_VS_11:
  1577. case SQ_ALU_CONST_CACHE_VS_12:
  1578. case SQ_ALU_CONST_CACHE_VS_13:
  1579. case SQ_ALU_CONST_CACHE_VS_14:
  1580. case SQ_ALU_CONST_CACHE_VS_15:
  1581. case SQ_ALU_CONST_CACHE_HS_0:
  1582. case SQ_ALU_CONST_CACHE_HS_1:
  1583. case SQ_ALU_CONST_CACHE_HS_2:
  1584. case SQ_ALU_CONST_CACHE_HS_3:
  1585. case SQ_ALU_CONST_CACHE_HS_4:
  1586. case SQ_ALU_CONST_CACHE_HS_5:
  1587. case SQ_ALU_CONST_CACHE_HS_6:
  1588. case SQ_ALU_CONST_CACHE_HS_7:
  1589. case SQ_ALU_CONST_CACHE_HS_8:
  1590. case SQ_ALU_CONST_CACHE_HS_9:
  1591. case SQ_ALU_CONST_CACHE_HS_10:
  1592. case SQ_ALU_CONST_CACHE_HS_11:
  1593. case SQ_ALU_CONST_CACHE_HS_12:
  1594. case SQ_ALU_CONST_CACHE_HS_13:
  1595. case SQ_ALU_CONST_CACHE_HS_14:
  1596. case SQ_ALU_CONST_CACHE_HS_15:
  1597. case SQ_ALU_CONST_CACHE_LS_0:
  1598. case SQ_ALU_CONST_CACHE_LS_1:
  1599. case SQ_ALU_CONST_CACHE_LS_2:
  1600. case SQ_ALU_CONST_CACHE_LS_3:
  1601. case SQ_ALU_CONST_CACHE_LS_4:
  1602. case SQ_ALU_CONST_CACHE_LS_5:
  1603. case SQ_ALU_CONST_CACHE_LS_6:
  1604. case SQ_ALU_CONST_CACHE_LS_7:
  1605. case SQ_ALU_CONST_CACHE_LS_8:
  1606. case SQ_ALU_CONST_CACHE_LS_9:
  1607. case SQ_ALU_CONST_CACHE_LS_10:
  1608. case SQ_ALU_CONST_CACHE_LS_11:
  1609. case SQ_ALU_CONST_CACHE_LS_12:
  1610. case SQ_ALU_CONST_CACHE_LS_13:
  1611. case SQ_ALU_CONST_CACHE_LS_14:
  1612. case SQ_ALU_CONST_CACHE_LS_15:
  1613. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1614. if (r) {
  1615. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1616. "0x%04X\n", reg);
  1617. return -EINVAL;
  1618. }
  1619. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1620. break;
  1621. case SX_MEMORY_EXPORT_BASE:
  1622. if (p->rdev->family >= CHIP_CAYMAN) {
  1623. dev_warn(p->dev, "bad SET_CONFIG_REG "
  1624. "0x%04X\n", reg);
  1625. return -EINVAL;
  1626. }
  1627. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1628. if (r) {
  1629. dev_warn(p->dev, "bad SET_CONFIG_REG "
  1630. "0x%04X\n", reg);
  1631. return -EINVAL;
  1632. }
  1633. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1634. break;
  1635. case CAYMAN_SX_SCATTER_EXPORT_BASE:
  1636. if (p->rdev->family < CHIP_CAYMAN) {
  1637. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1638. "0x%04X\n", reg);
  1639. return -EINVAL;
  1640. }
  1641. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1642. if (r) {
  1643. dev_warn(p->dev, "bad SET_CONTEXT_REG "
  1644. "0x%04X\n", reg);
  1645. return -EINVAL;
  1646. }
  1647. ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  1648. break;
  1649. case SX_MISC:
  1650. track->sx_misc_kill_all_prims = (radeon_get_ib_value(p, idx) & 0x1) != 0;
  1651. break;
  1652. default:
  1653. dev_warn(p->dev, "forbidden register 0x%08x at %d\n", reg, idx);
  1654. return -EINVAL;
  1655. }
  1656. return 0;
  1657. }
  1658. /**
  1659. * evergreen_is_safe_reg() - check if register is authorized or not
  1660. * @parser: parser structure holding parsing context
  1661. * @reg: register we are testing
  1662. *
  1663. * This function will test against reg_safe_bm and return true
  1664. * if register is safe or false otherwise.
  1665. */
  1666. static inline bool evergreen_is_safe_reg(struct radeon_cs_parser *p, u32 reg)
  1667. {
  1668. struct evergreen_cs_track *track = p->track;
  1669. u32 m, i;
  1670. i = (reg >> 7);
  1671. if (unlikely(i >= REG_SAFE_BM_SIZE)) {
  1672. return false;
  1673. }
  1674. m = 1 << ((reg >> 2) & 31);
  1675. if (!(track->reg_safe_bm[i] & m))
  1676. return true;
  1677. return false;
  1678. }
  1679. static int evergreen_packet3_check(struct radeon_cs_parser *p,
  1680. struct radeon_cs_packet *pkt)
  1681. {
  1682. struct radeon_bo_list *reloc;
  1683. struct evergreen_cs_track *track;
  1684. uint32_t *ib;
  1685. unsigned idx;
  1686. unsigned i;
  1687. unsigned start_reg, end_reg, reg;
  1688. int r;
  1689. u32 idx_value;
  1690. track = (struct evergreen_cs_track *)p->track;
  1691. ib = p->ib.ptr;
  1692. idx = pkt->idx + 1;
  1693. idx_value = radeon_get_ib_value(p, idx);
  1694. switch (pkt->opcode) {
  1695. case PACKET3_SET_PREDICATION:
  1696. {
  1697. int pred_op;
  1698. int tmp;
  1699. uint64_t offset;
  1700. if (pkt->count != 1) {
  1701. DRM_ERROR("bad SET PREDICATION\n");
  1702. return -EINVAL;
  1703. }
  1704. tmp = radeon_get_ib_value(p, idx + 1);
  1705. pred_op = (tmp >> 16) & 0x7;
  1706. /* for the clear predicate operation */
  1707. if (pred_op == 0)
  1708. return 0;
  1709. if (pred_op > 2) {
  1710. DRM_ERROR("bad SET PREDICATION operation %d\n", pred_op);
  1711. return -EINVAL;
  1712. }
  1713. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1714. if (r) {
  1715. DRM_ERROR("bad SET PREDICATION\n");
  1716. return -EINVAL;
  1717. }
  1718. offset = reloc->gpu_offset +
  1719. (idx_value & 0xfffffff0) +
  1720. ((u64)(tmp & 0xff) << 32);
  1721. ib[idx + 0] = offset;
  1722. ib[idx + 1] = (tmp & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  1723. }
  1724. break;
  1725. case PACKET3_CONTEXT_CONTROL:
  1726. if (pkt->count != 1) {
  1727. DRM_ERROR("bad CONTEXT_CONTROL\n");
  1728. return -EINVAL;
  1729. }
  1730. break;
  1731. case PACKET3_INDEX_TYPE:
  1732. case PACKET3_NUM_INSTANCES:
  1733. case PACKET3_CLEAR_STATE:
  1734. if (pkt->count) {
  1735. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1736. return -EINVAL;
  1737. }
  1738. break;
  1739. case CAYMAN_PACKET3_DEALLOC_STATE:
  1740. if (p->rdev->family < CHIP_CAYMAN) {
  1741. DRM_ERROR("bad PACKET3_DEALLOC_STATE\n");
  1742. return -EINVAL;
  1743. }
  1744. if (pkt->count) {
  1745. DRM_ERROR("bad INDEX_TYPE/NUM_INSTANCES/CLEAR_STATE\n");
  1746. return -EINVAL;
  1747. }
  1748. break;
  1749. case PACKET3_INDEX_BASE:
  1750. {
  1751. uint64_t offset;
  1752. if (pkt->count != 1) {
  1753. DRM_ERROR("bad INDEX_BASE\n");
  1754. return -EINVAL;
  1755. }
  1756. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1757. if (r) {
  1758. DRM_ERROR("bad INDEX_BASE\n");
  1759. return -EINVAL;
  1760. }
  1761. offset = reloc->gpu_offset +
  1762. idx_value +
  1763. ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
  1764. ib[idx+0] = offset;
  1765. ib[idx+1] = upper_32_bits(offset) & 0xff;
  1766. r = evergreen_cs_track_check(p);
  1767. if (r) {
  1768. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1769. return r;
  1770. }
  1771. break;
  1772. }
  1773. case PACKET3_INDEX_BUFFER_SIZE:
  1774. {
  1775. if (pkt->count != 0) {
  1776. DRM_ERROR("bad INDEX_BUFFER_SIZE\n");
  1777. return -EINVAL;
  1778. }
  1779. break;
  1780. }
  1781. case PACKET3_DRAW_INDEX:
  1782. {
  1783. uint64_t offset;
  1784. if (pkt->count != 3) {
  1785. DRM_ERROR("bad DRAW_INDEX\n");
  1786. return -EINVAL;
  1787. }
  1788. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1789. if (r) {
  1790. DRM_ERROR("bad DRAW_INDEX\n");
  1791. return -EINVAL;
  1792. }
  1793. offset = reloc->gpu_offset +
  1794. idx_value +
  1795. ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
  1796. ib[idx+0] = offset;
  1797. ib[idx+1] = upper_32_bits(offset) & 0xff;
  1798. r = evergreen_cs_track_check(p);
  1799. if (r) {
  1800. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1801. return r;
  1802. }
  1803. break;
  1804. }
  1805. case PACKET3_DRAW_INDEX_2:
  1806. {
  1807. uint64_t offset;
  1808. if (pkt->count != 4) {
  1809. DRM_ERROR("bad DRAW_INDEX_2\n");
  1810. return -EINVAL;
  1811. }
  1812. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1813. if (r) {
  1814. DRM_ERROR("bad DRAW_INDEX_2\n");
  1815. return -EINVAL;
  1816. }
  1817. offset = reloc->gpu_offset +
  1818. radeon_get_ib_value(p, idx+1) +
  1819. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  1820. ib[idx+1] = offset;
  1821. ib[idx+2] = upper_32_bits(offset) & 0xff;
  1822. r = evergreen_cs_track_check(p);
  1823. if (r) {
  1824. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1825. return r;
  1826. }
  1827. break;
  1828. }
  1829. case PACKET3_DRAW_INDEX_AUTO:
  1830. if (pkt->count != 1) {
  1831. DRM_ERROR("bad DRAW_INDEX_AUTO\n");
  1832. return -EINVAL;
  1833. }
  1834. r = evergreen_cs_track_check(p);
  1835. if (r) {
  1836. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1837. return r;
  1838. }
  1839. break;
  1840. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  1841. if (pkt->count != 2) {
  1842. DRM_ERROR("bad DRAW_INDEX_MULTI_AUTO\n");
  1843. return -EINVAL;
  1844. }
  1845. r = evergreen_cs_track_check(p);
  1846. if (r) {
  1847. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1848. return r;
  1849. }
  1850. break;
  1851. case PACKET3_DRAW_INDEX_IMMD:
  1852. if (pkt->count < 2) {
  1853. DRM_ERROR("bad DRAW_INDEX_IMMD\n");
  1854. return -EINVAL;
  1855. }
  1856. r = evergreen_cs_track_check(p);
  1857. if (r) {
  1858. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1859. return r;
  1860. }
  1861. break;
  1862. case PACKET3_DRAW_INDEX_OFFSET:
  1863. if (pkt->count != 2) {
  1864. DRM_ERROR("bad DRAW_INDEX_OFFSET\n");
  1865. return -EINVAL;
  1866. }
  1867. r = evergreen_cs_track_check(p);
  1868. if (r) {
  1869. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1870. return r;
  1871. }
  1872. break;
  1873. case PACKET3_DRAW_INDEX_OFFSET_2:
  1874. if (pkt->count != 3) {
  1875. DRM_ERROR("bad DRAW_INDEX_OFFSET_2\n");
  1876. return -EINVAL;
  1877. }
  1878. r = evergreen_cs_track_check(p);
  1879. if (r) {
  1880. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1881. return r;
  1882. }
  1883. break;
  1884. case PACKET3_SET_BASE:
  1885. {
  1886. /*
  1887. DW 1 HEADER Header of the packet. Shader_Type in bit 1 of the Header will correspond to the shader type of the Load, see Type-3 Packet.
  1888. 2 BASE_INDEX Bits [3:0] BASE_INDEX - Base Index specifies which base address is specified in the last two DWs.
  1889. 0001: DX11 Draw_Index_Indirect Patch Table Base: Base address for Draw_Index_Indirect data.
  1890. 3 ADDRESS_LO Bits [31:3] - Lower bits of QWORD-Aligned Address. Bits [2:0] - Reserved
  1891. 4 ADDRESS_HI Bits [31:8] - Reserved. Bits [7:0] - Upper bits of Address [47:32]
  1892. */
  1893. if (pkt->count != 2) {
  1894. DRM_ERROR("bad SET_BASE\n");
  1895. return -EINVAL;
  1896. }
  1897. /* currently only supporting setting indirect draw buffer base address */
  1898. if (idx_value != 1) {
  1899. DRM_ERROR("bad SET_BASE\n");
  1900. return -EINVAL;
  1901. }
  1902. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1903. if (r) {
  1904. DRM_ERROR("bad SET_BASE\n");
  1905. return -EINVAL;
  1906. }
  1907. track->indirect_draw_buffer_size = radeon_bo_size(reloc->robj);
  1908. ib[idx+1] = reloc->gpu_offset;
  1909. ib[idx+2] = upper_32_bits(reloc->gpu_offset) & 0xff;
  1910. break;
  1911. }
  1912. case PACKET3_DRAW_INDIRECT:
  1913. case PACKET3_DRAW_INDEX_INDIRECT:
  1914. {
  1915. u64 size = pkt->opcode == PACKET3_DRAW_INDIRECT ? 16 : 20;
  1916. /*
  1917. DW 1 HEADER
  1918. 2 DATA_OFFSET Bits [31:0] + byte aligned offset where the required data structure starts. Bits 1:0 are zero
  1919. 3 DRAW_INITIATOR Draw Initiator Register. Written to the VGT_DRAW_INITIATOR register for the assigned context
  1920. */
  1921. if (pkt->count != 1) {
  1922. DRM_ERROR("bad DRAW_INDIRECT\n");
  1923. return -EINVAL;
  1924. }
  1925. if (idx_value + size > track->indirect_draw_buffer_size) {
  1926. dev_warn(p->dev, "DRAW_INDIRECT buffer too small %u + %llu > %lu\n",
  1927. idx_value, size, track->indirect_draw_buffer_size);
  1928. return -EINVAL;
  1929. }
  1930. r = evergreen_cs_track_check(p);
  1931. if (r) {
  1932. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1933. return r;
  1934. }
  1935. break;
  1936. }
  1937. case PACKET3_DISPATCH_DIRECT:
  1938. if (pkt->count != 3) {
  1939. DRM_ERROR("bad DISPATCH_DIRECT\n");
  1940. return -EINVAL;
  1941. }
  1942. r = evergreen_cs_track_check(p);
  1943. if (r) {
  1944. dev_warn(p->dev, "%s:%d invalid cmd stream %d\n", __func__, __LINE__, idx);
  1945. return r;
  1946. }
  1947. break;
  1948. case PACKET3_DISPATCH_INDIRECT:
  1949. if (pkt->count != 1) {
  1950. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  1951. return -EINVAL;
  1952. }
  1953. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1954. if (r) {
  1955. DRM_ERROR("bad DISPATCH_INDIRECT\n");
  1956. return -EINVAL;
  1957. }
  1958. ib[idx+0] = idx_value + (u32)(reloc->gpu_offset & 0xffffffff);
  1959. r = evergreen_cs_track_check(p);
  1960. if (r) {
  1961. dev_warn(p->dev, "%s:%d invalid cmd stream\n", __func__, __LINE__);
  1962. return r;
  1963. }
  1964. break;
  1965. case PACKET3_WAIT_REG_MEM:
  1966. if (pkt->count != 5) {
  1967. DRM_ERROR("bad WAIT_REG_MEM\n");
  1968. return -EINVAL;
  1969. }
  1970. /* bit 4 is reg (0) or mem (1) */
  1971. if (idx_value & 0x10) {
  1972. uint64_t offset;
  1973. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1974. if (r) {
  1975. DRM_ERROR("bad WAIT_REG_MEM\n");
  1976. return -EINVAL;
  1977. }
  1978. offset = reloc->gpu_offset +
  1979. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  1980. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  1981. ib[idx+1] = (ib[idx+1] & 0x3) | (offset & 0xfffffffc);
  1982. ib[idx+2] = upper_32_bits(offset) & 0xff;
  1983. } else if (idx_value & 0x100) {
  1984. DRM_ERROR("cannot use PFP on REG wait\n");
  1985. return -EINVAL;
  1986. }
  1987. break;
  1988. case PACKET3_CP_DMA:
  1989. {
  1990. u32 command, size, info;
  1991. u64 offset, tmp;
  1992. if (pkt->count != 4) {
  1993. DRM_ERROR("bad CP DMA\n");
  1994. return -EINVAL;
  1995. }
  1996. command = radeon_get_ib_value(p, idx+4);
  1997. size = command & 0x1fffff;
  1998. info = radeon_get_ib_value(p, idx+1);
  1999. if ((((info & 0x60000000) >> 29) != 0) || /* src = GDS or DATA */
  2000. (((info & 0x00300000) >> 20) != 0) || /* dst = GDS */
  2001. ((((info & 0x00300000) >> 20) == 0) &&
  2002. (command & PACKET3_CP_DMA_CMD_DAS)) || /* dst = register */
  2003. ((((info & 0x60000000) >> 29) == 0) &&
  2004. (command & PACKET3_CP_DMA_CMD_SAS))) { /* src = register */
  2005. /* non mem to mem copies requires dw aligned count */
  2006. if (size % 4) {
  2007. DRM_ERROR("CP DMA command requires dw count alignment\n");
  2008. return -EINVAL;
  2009. }
  2010. }
  2011. if (command & PACKET3_CP_DMA_CMD_SAS) {
  2012. /* src address space is register */
  2013. /* GDS is ok */
  2014. if (((info & 0x60000000) >> 29) != 1) {
  2015. DRM_ERROR("CP DMA SAS not supported\n");
  2016. return -EINVAL;
  2017. }
  2018. } else {
  2019. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  2020. DRM_ERROR("CP DMA SAIC only supported for registers\n");
  2021. return -EINVAL;
  2022. }
  2023. /* src address space is memory */
  2024. if (((info & 0x60000000) >> 29) == 0) {
  2025. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2026. if (r) {
  2027. DRM_ERROR("bad CP DMA SRC\n");
  2028. return -EINVAL;
  2029. }
  2030. tmp = radeon_get_ib_value(p, idx) +
  2031. ((u64)(radeon_get_ib_value(p, idx+1) & 0xff) << 32);
  2032. offset = reloc->gpu_offset + tmp;
  2033. if ((tmp + size) > radeon_bo_size(reloc->robj)) {
  2034. dev_warn(p->dev, "CP DMA src buffer too small (%llu %lu)\n",
  2035. tmp + size, radeon_bo_size(reloc->robj));
  2036. return -EINVAL;
  2037. }
  2038. ib[idx] = offset;
  2039. ib[idx+1] = (ib[idx+1] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  2040. } else if (((info & 0x60000000) >> 29) != 2) {
  2041. DRM_ERROR("bad CP DMA SRC_SEL\n");
  2042. return -EINVAL;
  2043. }
  2044. }
  2045. if (command & PACKET3_CP_DMA_CMD_DAS) {
  2046. /* dst address space is register */
  2047. /* GDS is ok */
  2048. if (((info & 0x00300000) >> 20) != 1) {
  2049. DRM_ERROR("CP DMA DAS not supported\n");
  2050. return -EINVAL;
  2051. }
  2052. } else {
  2053. /* dst address space is memory */
  2054. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  2055. DRM_ERROR("CP DMA DAIC only supported for registers\n");
  2056. return -EINVAL;
  2057. }
  2058. if (((info & 0x00300000) >> 20) == 0) {
  2059. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2060. if (r) {
  2061. DRM_ERROR("bad CP DMA DST\n");
  2062. return -EINVAL;
  2063. }
  2064. tmp = radeon_get_ib_value(p, idx+2) +
  2065. ((u64)(radeon_get_ib_value(p, idx+3) & 0xff) << 32);
  2066. offset = reloc->gpu_offset + tmp;
  2067. if ((tmp + size) > radeon_bo_size(reloc->robj)) {
  2068. dev_warn(p->dev, "CP DMA dst buffer too small (%llu %lu)\n",
  2069. tmp + size, radeon_bo_size(reloc->robj));
  2070. return -EINVAL;
  2071. }
  2072. ib[idx+2] = offset;
  2073. ib[idx+3] = upper_32_bits(offset) & 0xff;
  2074. } else {
  2075. DRM_ERROR("bad CP DMA DST_SEL\n");
  2076. return -EINVAL;
  2077. }
  2078. }
  2079. break;
  2080. }
  2081. case PACKET3_SURFACE_SYNC:
  2082. if (pkt->count != 3) {
  2083. DRM_ERROR("bad SURFACE_SYNC\n");
  2084. return -EINVAL;
  2085. }
  2086. /* 0xffffffff/0x0 is flush all cache flag */
  2087. if (radeon_get_ib_value(p, idx + 1) != 0xffffffff ||
  2088. radeon_get_ib_value(p, idx + 2) != 0) {
  2089. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2090. if (r) {
  2091. DRM_ERROR("bad SURFACE_SYNC\n");
  2092. return -EINVAL;
  2093. }
  2094. ib[idx+2] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  2095. }
  2096. break;
  2097. case PACKET3_EVENT_WRITE:
  2098. if (pkt->count != 2 && pkt->count != 0) {
  2099. DRM_ERROR("bad EVENT_WRITE\n");
  2100. return -EINVAL;
  2101. }
  2102. if (pkt->count) {
  2103. uint64_t offset;
  2104. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2105. if (r) {
  2106. DRM_ERROR("bad EVENT_WRITE\n");
  2107. return -EINVAL;
  2108. }
  2109. offset = reloc->gpu_offset +
  2110. (radeon_get_ib_value(p, idx+1) & 0xfffffff8) +
  2111. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2112. ib[idx+1] = offset & 0xfffffff8;
  2113. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2114. }
  2115. break;
  2116. case PACKET3_EVENT_WRITE_EOP:
  2117. {
  2118. uint64_t offset;
  2119. if (pkt->count != 4) {
  2120. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  2121. return -EINVAL;
  2122. }
  2123. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2124. if (r) {
  2125. DRM_ERROR("bad EVENT_WRITE_EOP\n");
  2126. return -EINVAL;
  2127. }
  2128. offset = reloc->gpu_offset +
  2129. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  2130. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2131. ib[idx+1] = offset & 0xfffffffc;
  2132. ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  2133. break;
  2134. }
  2135. case PACKET3_EVENT_WRITE_EOS:
  2136. {
  2137. uint64_t offset;
  2138. if (pkt->count != 3) {
  2139. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  2140. return -EINVAL;
  2141. }
  2142. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2143. if (r) {
  2144. DRM_ERROR("bad EVENT_WRITE_EOS\n");
  2145. return -EINVAL;
  2146. }
  2147. offset = reloc->gpu_offset +
  2148. (radeon_get_ib_value(p, idx+1) & 0xfffffffc) +
  2149. ((u64)(radeon_get_ib_value(p, idx+2) & 0xff) << 32);
  2150. ib[idx+1] = offset & 0xfffffffc;
  2151. ib[idx+2] = (ib[idx+2] & 0xffffff00) | (upper_32_bits(offset) & 0xff);
  2152. break;
  2153. }
  2154. case PACKET3_SET_CONFIG_REG:
  2155. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  2156. end_reg = 4 * pkt->count + start_reg - 4;
  2157. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  2158. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  2159. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  2160. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  2161. return -EINVAL;
  2162. }
  2163. for (reg = start_reg, idx++; reg <= end_reg; reg += 4, idx++) {
  2164. if (evergreen_is_safe_reg(p, reg))
  2165. continue;
  2166. r = evergreen_cs_handle_reg(p, reg, idx);
  2167. if (r)
  2168. return r;
  2169. }
  2170. break;
  2171. case PACKET3_SET_CONTEXT_REG:
  2172. start_reg = (idx_value << 2) + PACKET3_SET_CONTEXT_REG_START;
  2173. end_reg = 4 * pkt->count + start_reg - 4;
  2174. if ((start_reg < PACKET3_SET_CONTEXT_REG_START) ||
  2175. (start_reg >= PACKET3_SET_CONTEXT_REG_END) ||
  2176. (end_reg >= PACKET3_SET_CONTEXT_REG_END)) {
  2177. DRM_ERROR("bad PACKET3_SET_CONTEXT_REG\n");
  2178. return -EINVAL;
  2179. }
  2180. for (reg = start_reg, idx++; reg <= end_reg; reg += 4, idx++) {
  2181. if (evergreen_is_safe_reg(p, reg))
  2182. continue;
  2183. r = evergreen_cs_handle_reg(p, reg, idx);
  2184. if (r)
  2185. return r;
  2186. }
  2187. break;
  2188. case PACKET3_SET_RESOURCE:
  2189. if (pkt->count % 8) {
  2190. DRM_ERROR("bad SET_RESOURCE\n");
  2191. return -EINVAL;
  2192. }
  2193. start_reg = (idx_value << 2) + PACKET3_SET_RESOURCE_START;
  2194. end_reg = 4 * pkt->count + start_reg - 4;
  2195. if ((start_reg < PACKET3_SET_RESOURCE_START) ||
  2196. (start_reg >= PACKET3_SET_RESOURCE_END) ||
  2197. (end_reg >= PACKET3_SET_RESOURCE_END)) {
  2198. DRM_ERROR("bad SET_RESOURCE\n");
  2199. return -EINVAL;
  2200. }
  2201. for (i = 0; i < (pkt->count / 8); i++) {
  2202. struct radeon_bo *texture, *mipmap;
  2203. u32 toffset, moffset;
  2204. u32 size, offset, mip_address, tex_dim;
  2205. switch (G__SQ_CONSTANT_TYPE(radeon_get_ib_value(p, idx+1+(i*8)+7))) {
  2206. case SQ_TEX_VTX_VALID_TEXTURE:
  2207. /* tex base */
  2208. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2209. if (r) {
  2210. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  2211. return -EINVAL;
  2212. }
  2213. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  2214. ib[idx+1+(i*8)+1] |=
  2215. TEX_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->tiling_flags));
  2216. if (reloc->tiling_flags & RADEON_TILING_MACRO) {
  2217. unsigned bankw, bankh, mtaspect, tile_split;
  2218. evergreen_tiling_fields(reloc->tiling_flags,
  2219. &bankw, &bankh, &mtaspect,
  2220. &tile_split);
  2221. ib[idx+1+(i*8)+6] |= TEX_TILE_SPLIT(tile_split);
  2222. ib[idx+1+(i*8)+7] |=
  2223. TEX_BANK_WIDTH(bankw) |
  2224. TEX_BANK_HEIGHT(bankh) |
  2225. MACRO_TILE_ASPECT(mtaspect) |
  2226. TEX_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
  2227. }
  2228. }
  2229. texture = reloc->robj;
  2230. toffset = (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  2231. /* tex mip base */
  2232. tex_dim = ib[idx+1+(i*8)+0] & 0x7;
  2233. mip_address = ib[idx+1+(i*8)+3];
  2234. if ((tex_dim == SQ_TEX_DIM_2D_MSAA || tex_dim == SQ_TEX_DIM_2D_ARRAY_MSAA) &&
  2235. !mip_address &&
  2236. !radeon_cs_packet_next_is_pkt3_nop(p)) {
  2237. /* MIP_ADDRESS should point to FMASK for an MSAA texture.
  2238. * It should be 0 if FMASK is disabled. */
  2239. moffset = 0;
  2240. mipmap = NULL;
  2241. } else {
  2242. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2243. if (r) {
  2244. DRM_ERROR("bad SET_RESOURCE (tex)\n");
  2245. return -EINVAL;
  2246. }
  2247. moffset = (u32)((reloc->gpu_offset >> 8) & 0xffffffff);
  2248. mipmap = reloc->robj;
  2249. }
  2250. r = evergreen_cs_track_validate_texture(p, texture, mipmap, idx+1+(i*8));
  2251. if (r)
  2252. return r;
  2253. ib[idx+1+(i*8)+2] += toffset;
  2254. ib[idx+1+(i*8)+3] += moffset;
  2255. break;
  2256. case SQ_TEX_VTX_VALID_BUFFER:
  2257. {
  2258. uint64_t offset64;
  2259. /* vtx base */
  2260. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2261. if (r) {
  2262. DRM_ERROR("bad SET_RESOURCE (vtx)\n");
  2263. return -EINVAL;
  2264. }
  2265. offset = radeon_get_ib_value(p, idx+1+(i*8)+0);
  2266. size = radeon_get_ib_value(p, idx+1+(i*8)+1);
  2267. if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
  2268. /* force size to size of the buffer */
  2269. dev_warn(p->dev, "vbo resource seems too big for the bo\n");
  2270. ib[idx+1+(i*8)+1] = radeon_bo_size(reloc->robj) - offset;
  2271. }
  2272. offset64 = reloc->gpu_offset + offset;
  2273. ib[idx+1+(i*8)+0] = offset64;
  2274. ib[idx+1+(i*8)+2] = (ib[idx+1+(i*8)+2] & 0xffffff00) |
  2275. (upper_32_bits(offset64) & 0xff);
  2276. break;
  2277. }
  2278. case SQ_TEX_VTX_INVALID_TEXTURE:
  2279. case SQ_TEX_VTX_INVALID_BUFFER:
  2280. default:
  2281. DRM_ERROR("bad SET_RESOURCE\n");
  2282. return -EINVAL;
  2283. }
  2284. }
  2285. break;
  2286. case PACKET3_SET_ALU_CONST:
  2287. /* XXX fix me ALU const buffers only */
  2288. break;
  2289. case PACKET3_SET_BOOL_CONST:
  2290. start_reg = (idx_value << 2) + PACKET3_SET_BOOL_CONST_START;
  2291. end_reg = 4 * pkt->count + start_reg - 4;
  2292. if ((start_reg < PACKET3_SET_BOOL_CONST_START) ||
  2293. (start_reg >= PACKET3_SET_BOOL_CONST_END) ||
  2294. (end_reg >= PACKET3_SET_BOOL_CONST_END)) {
  2295. DRM_ERROR("bad SET_BOOL_CONST\n");
  2296. return -EINVAL;
  2297. }
  2298. break;
  2299. case PACKET3_SET_LOOP_CONST:
  2300. start_reg = (idx_value << 2) + PACKET3_SET_LOOP_CONST_START;
  2301. end_reg = 4 * pkt->count + start_reg - 4;
  2302. if ((start_reg < PACKET3_SET_LOOP_CONST_START) ||
  2303. (start_reg >= PACKET3_SET_LOOP_CONST_END) ||
  2304. (end_reg >= PACKET3_SET_LOOP_CONST_END)) {
  2305. DRM_ERROR("bad SET_LOOP_CONST\n");
  2306. return -EINVAL;
  2307. }
  2308. break;
  2309. case PACKET3_SET_CTL_CONST:
  2310. start_reg = (idx_value << 2) + PACKET3_SET_CTL_CONST_START;
  2311. end_reg = 4 * pkt->count + start_reg - 4;
  2312. if ((start_reg < PACKET3_SET_CTL_CONST_START) ||
  2313. (start_reg >= PACKET3_SET_CTL_CONST_END) ||
  2314. (end_reg >= PACKET3_SET_CTL_CONST_END)) {
  2315. DRM_ERROR("bad SET_CTL_CONST\n");
  2316. return -EINVAL;
  2317. }
  2318. break;
  2319. case PACKET3_SET_SAMPLER:
  2320. if (pkt->count % 3) {
  2321. DRM_ERROR("bad SET_SAMPLER\n");
  2322. return -EINVAL;
  2323. }
  2324. start_reg = (idx_value << 2) + PACKET3_SET_SAMPLER_START;
  2325. end_reg = 4 * pkt->count + start_reg - 4;
  2326. if ((start_reg < PACKET3_SET_SAMPLER_START) ||
  2327. (start_reg >= PACKET3_SET_SAMPLER_END) ||
  2328. (end_reg >= PACKET3_SET_SAMPLER_END)) {
  2329. DRM_ERROR("bad SET_SAMPLER\n");
  2330. return -EINVAL;
  2331. }
  2332. break;
  2333. case PACKET3_STRMOUT_BUFFER_UPDATE:
  2334. if (pkt->count != 4) {
  2335. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (invalid count)\n");
  2336. return -EINVAL;
  2337. }
  2338. /* Updating memory at DST_ADDRESS. */
  2339. if (idx_value & 0x1) {
  2340. u64 offset;
  2341. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2342. if (r) {
  2343. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing dst reloc)\n");
  2344. return -EINVAL;
  2345. }
  2346. offset = radeon_get_ib_value(p, idx+1);
  2347. offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
  2348. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2349. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE dst bo too small: 0x%llx, 0x%lx\n",
  2350. offset + 4, radeon_bo_size(reloc->robj));
  2351. return -EINVAL;
  2352. }
  2353. offset += reloc->gpu_offset;
  2354. ib[idx+1] = offset;
  2355. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2356. }
  2357. /* Reading data from SRC_ADDRESS. */
  2358. if (((idx_value >> 1) & 0x3) == 2) {
  2359. u64 offset;
  2360. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2361. if (r) {
  2362. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE (missing src reloc)\n");
  2363. return -EINVAL;
  2364. }
  2365. offset = radeon_get_ib_value(p, idx+3);
  2366. offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2367. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2368. DRM_ERROR("bad STRMOUT_BUFFER_UPDATE src bo too small: 0x%llx, 0x%lx\n",
  2369. offset + 4, radeon_bo_size(reloc->robj));
  2370. return -EINVAL;
  2371. }
  2372. offset += reloc->gpu_offset;
  2373. ib[idx+3] = offset;
  2374. ib[idx+4] = upper_32_bits(offset) & 0xff;
  2375. }
  2376. break;
  2377. case PACKET3_MEM_WRITE:
  2378. {
  2379. u64 offset;
  2380. if (pkt->count != 3) {
  2381. DRM_ERROR("bad MEM_WRITE (invalid count)\n");
  2382. return -EINVAL;
  2383. }
  2384. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2385. if (r) {
  2386. DRM_ERROR("bad MEM_WRITE (missing reloc)\n");
  2387. return -EINVAL;
  2388. }
  2389. offset = radeon_get_ib_value(p, idx+0);
  2390. offset += ((u64)(radeon_get_ib_value(p, idx+1) & 0xff)) << 32UL;
  2391. if (offset & 0x7) {
  2392. DRM_ERROR("bad MEM_WRITE (address not qwords aligned)\n");
  2393. return -EINVAL;
  2394. }
  2395. if ((offset + 8) > radeon_bo_size(reloc->robj)) {
  2396. DRM_ERROR("bad MEM_WRITE bo too small: 0x%llx, 0x%lx\n",
  2397. offset + 8, radeon_bo_size(reloc->robj));
  2398. return -EINVAL;
  2399. }
  2400. offset += reloc->gpu_offset;
  2401. ib[idx+0] = offset;
  2402. ib[idx+1] = upper_32_bits(offset) & 0xff;
  2403. break;
  2404. }
  2405. case PACKET3_COPY_DW:
  2406. if (pkt->count != 4) {
  2407. DRM_ERROR("bad COPY_DW (invalid count)\n");
  2408. return -EINVAL;
  2409. }
  2410. if (idx_value & 0x1) {
  2411. u64 offset;
  2412. /* SRC is memory. */
  2413. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2414. if (r) {
  2415. DRM_ERROR("bad COPY_DW (missing src reloc)\n");
  2416. return -EINVAL;
  2417. }
  2418. offset = radeon_get_ib_value(p, idx+1);
  2419. offset += ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
  2420. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2421. DRM_ERROR("bad COPY_DW src bo too small: 0x%llx, 0x%lx\n",
  2422. offset + 4, radeon_bo_size(reloc->robj));
  2423. return -EINVAL;
  2424. }
  2425. offset += reloc->gpu_offset;
  2426. ib[idx+1] = offset;
  2427. ib[idx+2] = upper_32_bits(offset) & 0xff;
  2428. } else {
  2429. /* SRC is a reg. */
  2430. reg = radeon_get_ib_value(p, idx+1) << 2;
  2431. if (!evergreen_is_safe_reg(p, reg)) {
  2432. dev_warn(p->dev, "forbidden register 0x%08x at %d\n",
  2433. reg, idx + 1);
  2434. return -EINVAL;
  2435. }
  2436. }
  2437. if (idx_value & 0x2) {
  2438. u64 offset;
  2439. /* DST is memory. */
  2440. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  2441. if (r) {
  2442. DRM_ERROR("bad COPY_DW (missing dst reloc)\n");
  2443. return -EINVAL;
  2444. }
  2445. offset = radeon_get_ib_value(p, idx+3);
  2446. offset += ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2447. if ((offset + 4) > radeon_bo_size(reloc->robj)) {
  2448. DRM_ERROR("bad COPY_DW dst bo too small: 0x%llx, 0x%lx\n",
  2449. offset + 4, radeon_bo_size(reloc->robj));
  2450. return -EINVAL;
  2451. }
  2452. offset += reloc->gpu_offset;
  2453. ib[idx+3] = offset;
  2454. ib[idx+4] = upper_32_bits(offset) & 0xff;
  2455. } else {
  2456. /* DST is a reg. */
  2457. reg = radeon_get_ib_value(p, idx+3) << 2;
  2458. if (!evergreen_is_safe_reg(p, reg)) {
  2459. dev_warn(p->dev, "forbidden register 0x%08x at %d\n",
  2460. reg, idx + 3);
  2461. return -EINVAL;
  2462. }
  2463. }
  2464. break;
  2465. case PACKET3_NOP:
  2466. break;
  2467. default:
  2468. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  2469. return -EINVAL;
  2470. }
  2471. return 0;
  2472. }
  2473. int evergreen_cs_parse(struct radeon_cs_parser *p)
  2474. {
  2475. struct radeon_cs_packet pkt;
  2476. struct evergreen_cs_track *track;
  2477. u32 tmp;
  2478. int r;
  2479. if (p->track == NULL) {
  2480. /* initialize tracker, we are in kms */
  2481. track = kzalloc(sizeof(*track), GFP_KERNEL);
  2482. if (track == NULL)
  2483. return -ENOMEM;
  2484. evergreen_cs_track_init(track);
  2485. if (p->rdev->family >= CHIP_CAYMAN) {
  2486. tmp = p->rdev->config.cayman.tile_config;
  2487. track->reg_safe_bm = cayman_reg_safe_bm;
  2488. } else {
  2489. tmp = p->rdev->config.evergreen.tile_config;
  2490. track->reg_safe_bm = evergreen_reg_safe_bm;
  2491. }
  2492. BUILD_BUG_ON(ARRAY_SIZE(cayman_reg_safe_bm) != REG_SAFE_BM_SIZE);
  2493. BUILD_BUG_ON(ARRAY_SIZE(evergreen_reg_safe_bm) != REG_SAFE_BM_SIZE);
  2494. switch (tmp & 0xf) {
  2495. case 0:
  2496. track->npipes = 1;
  2497. break;
  2498. case 1:
  2499. default:
  2500. track->npipes = 2;
  2501. break;
  2502. case 2:
  2503. track->npipes = 4;
  2504. break;
  2505. case 3:
  2506. track->npipes = 8;
  2507. break;
  2508. }
  2509. switch ((tmp & 0xf0) >> 4) {
  2510. case 0:
  2511. track->nbanks = 4;
  2512. break;
  2513. case 1:
  2514. default:
  2515. track->nbanks = 8;
  2516. break;
  2517. case 2:
  2518. track->nbanks = 16;
  2519. break;
  2520. }
  2521. switch ((tmp & 0xf00) >> 8) {
  2522. case 0:
  2523. track->group_size = 256;
  2524. break;
  2525. case 1:
  2526. default:
  2527. track->group_size = 512;
  2528. break;
  2529. }
  2530. switch ((tmp & 0xf000) >> 12) {
  2531. case 0:
  2532. track->row_size = 1;
  2533. break;
  2534. case 1:
  2535. default:
  2536. track->row_size = 2;
  2537. break;
  2538. case 2:
  2539. track->row_size = 4;
  2540. break;
  2541. }
  2542. p->track = track;
  2543. }
  2544. do {
  2545. r = radeon_cs_packet_parse(p, &pkt, p->idx);
  2546. if (r) {
  2547. kfree(p->track);
  2548. p->track = NULL;
  2549. return r;
  2550. }
  2551. p->idx += pkt.count + 2;
  2552. switch (pkt.type) {
  2553. case RADEON_PACKET_TYPE0:
  2554. r = evergreen_cs_parse_packet0(p, &pkt);
  2555. break;
  2556. case RADEON_PACKET_TYPE2:
  2557. break;
  2558. case RADEON_PACKET_TYPE3:
  2559. r = evergreen_packet3_check(p, &pkt);
  2560. break;
  2561. default:
  2562. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  2563. kfree(p->track);
  2564. p->track = NULL;
  2565. return -EINVAL;
  2566. }
  2567. if (r) {
  2568. kfree(p->track);
  2569. p->track = NULL;
  2570. return r;
  2571. }
  2572. } while (p->idx < p->chunk_ib->length_dw);
  2573. #if 0
  2574. for (r = 0; r < p->ib.length_dw; r++) {
  2575. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib.ptr[r]);
  2576. mdelay(1);
  2577. }
  2578. #endif
  2579. kfree(p->track);
  2580. p->track = NULL;
  2581. return 0;
  2582. }
  2583. /**
  2584. * evergreen_dma_cs_parse() - parse the DMA IB
  2585. * @p: parser structure holding parsing context.
  2586. *
  2587. * Parses the DMA IB from the CS ioctl and updates
  2588. * the GPU addresses based on the reloc information and
  2589. * checks for errors. (Evergreen-Cayman)
  2590. * Returns 0 for success and an error on failure.
  2591. **/
  2592. int evergreen_dma_cs_parse(struct radeon_cs_parser *p)
  2593. {
  2594. struct radeon_cs_chunk *ib_chunk = p->chunk_ib;
  2595. struct radeon_bo_list *src_reloc, *dst_reloc, *dst2_reloc;
  2596. u32 header, cmd, count, sub_cmd;
  2597. uint32_t *ib = p->ib.ptr;
  2598. u32 idx;
  2599. u64 src_offset, dst_offset, dst2_offset;
  2600. int r;
  2601. do {
  2602. if (p->idx >= ib_chunk->length_dw) {
  2603. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  2604. p->idx, ib_chunk->length_dw);
  2605. return -EINVAL;
  2606. }
  2607. idx = p->idx;
  2608. header = radeon_get_ib_value(p, idx);
  2609. cmd = GET_DMA_CMD(header);
  2610. count = GET_DMA_COUNT(header);
  2611. sub_cmd = GET_DMA_SUB_CMD(header);
  2612. switch (cmd) {
  2613. case DMA_PACKET_WRITE:
  2614. r = r600_dma_cs_next_reloc(p, &dst_reloc);
  2615. if (r) {
  2616. DRM_ERROR("bad DMA_PACKET_WRITE\n");
  2617. return -EINVAL;
  2618. }
  2619. switch (sub_cmd) {
  2620. /* tiled */
  2621. case 8:
  2622. dst_offset = radeon_get_ib_value(p, idx+1);
  2623. dst_offset <<= 8;
  2624. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2625. p->idx += count + 7;
  2626. break;
  2627. /* linear */
  2628. case 0:
  2629. dst_offset = radeon_get_ib_value(p, idx+1);
  2630. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+2) & 0xff)) << 32;
  2631. ib[idx+1] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2632. ib[idx+2] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2633. p->idx += count + 3;
  2634. break;
  2635. default:
  2636. DRM_ERROR("bad DMA_PACKET_WRITE [%6d] 0x%08x sub cmd is not 0 or 8\n", idx, header);
  2637. return -EINVAL;
  2638. }
  2639. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2640. dev_warn(p->dev, "DMA write buffer too small (%llu %lu)\n",
  2641. dst_offset, radeon_bo_size(dst_reloc->robj));
  2642. return -EINVAL;
  2643. }
  2644. break;
  2645. case DMA_PACKET_COPY:
  2646. r = r600_dma_cs_next_reloc(p, &src_reloc);
  2647. if (r) {
  2648. DRM_ERROR("bad DMA_PACKET_COPY\n");
  2649. return -EINVAL;
  2650. }
  2651. r = r600_dma_cs_next_reloc(p, &dst_reloc);
  2652. if (r) {
  2653. DRM_ERROR("bad DMA_PACKET_COPY\n");
  2654. return -EINVAL;
  2655. }
  2656. switch (sub_cmd) {
  2657. /* Copy L2L, DW aligned */
  2658. case 0x00:
  2659. /* L2L, dw */
  2660. src_offset = radeon_get_ib_value(p, idx+2);
  2661. src_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2662. dst_offset = radeon_get_ib_value(p, idx+1);
  2663. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
  2664. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2665. dev_warn(p->dev, "DMA L2L, dw src buffer too small (%llu %lu)\n",
  2666. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2667. return -EINVAL;
  2668. }
  2669. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2670. dev_warn(p->dev, "DMA L2L, dw dst buffer too small (%llu %lu)\n",
  2671. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2672. return -EINVAL;
  2673. }
  2674. ib[idx+1] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2675. ib[idx+2] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2676. ib[idx+3] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2677. ib[idx+4] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2678. p->idx += 5;
  2679. break;
  2680. /* Copy L2T/T2L */
  2681. case 0x08:
  2682. /* detile bit */
  2683. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2684. /* tiled src, linear dst */
  2685. src_offset = radeon_get_ib_value(p, idx+1);
  2686. src_offset <<= 8;
  2687. ib[idx+1] += (u32)(src_reloc->gpu_offset >> 8);
  2688. dst_offset = radeon_get_ib_value(p, idx + 7);
  2689. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
  2690. ib[idx+7] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2691. ib[idx+8] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2692. } else {
  2693. /* linear src, tiled dst */
  2694. src_offset = radeon_get_ib_value(p, idx+7);
  2695. src_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
  2696. ib[idx+7] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2697. ib[idx+8] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2698. dst_offset = radeon_get_ib_value(p, idx+1);
  2699. dst_offset <<= 8;
  2700. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2701. }
  2702. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2703. dev_warn(p->dev, "DMA L2T, src buffer too small (%llu %lu)\n",
  2704. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2705. return -EINVAL;
  2706. }
  2707. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2708. dev_warn(p->dev, "DMA L2T, dst buffer too small (%llu %lu)\n",
  2709. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2710. return -EINVAL;
  2711. }
  2712. p->idx += 9;
  2713. break;
  2714. /* Copy L2L, byte aligned */
  2715. case 0x40:
  2716. /* L2L, byte */
  2717. src_offset = radeon_get_ib_value(p, idx+2);
  2718. src_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2719. dst_offset = radeon_get_ib_value(p, idx+1);
  2720. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0xff)) << 32;
  2721. if ((src_offset + count) > radeon_bo_size(src_reloc->robj)) {
  2722. dev_warn(p->dev, "DMA L2L, byte src buffer too small (%llu %lu)\n",
  2723. src_offset + count, radeon_bo_size(src_reloc->robj));
  2724. return -EINVAL;
  2725. }
  2726. if ((dst_offset + count) > radeon_bo_size(dst_reloc->robj)) {
  2727. dev_warn(p->dev, "DMA L2L, byte dst buffer too small (%llu %lu)\n",
  2728. dst_offset + count, radeon_bo_size(dst_reloc->robj));
  2729. return -EINVAL;
  2730. }
  2731. ib[idx+1] += (u32)(dst_reloc->gpu_offset & 0xffffffff);
  2732. ib[idx+2] += (u32)(src_reloc->gpu_offset & 0xffffffff);
  2733. ib[idx+3] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2734. ib[idx+4] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2735. p->idx += 5;
  2736. break;
  2737. /* Copy L2L, partial */
  2738. case 0x41:
  2739. /* L2L, partial */
  2740. if (p->family < CHIP_CAYMAN) {
  2741. DRM_ERROR("L2L Partial is cayman only !\n");
  2742. return -EINVAL;
  2743. }
  2744. ib[idx+1] += (u32)(src_reloc->gpu_offset & 0xffffffff);
  2745. ib[idx+2] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2746. ib[idx+4] += (u32)(dst_reloc->gpu_offset & 0xffffffff);
  2747. ib[idx+5] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2748. p->idx += 9;
  2749. break;
  2750. /* Copy L2L, DW aligned, broadcast */
  2751. case 0x44:
  2752. /* L2L, dw, broadcast */
  2753. r = r600_dma_cs_next_reloc(p, &dst2_reloc);
  2754. if (r) {
  2755. DRM_ERROR("bad L2L, dw, broadcast DMA_PACKET_COPY\n");
  2756. return -EINVAL;
  2757. }
  2758. dst_offset = radeon_get_ib_value(p, idx+1);
  2759. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+4) & 0xff)) << 32;
  2760. dst2_offset = radeon_get_ib_value(p, idx+2);
  2761. dst2_offset |= ((u64)(radeon_get_ib_value(p, idx+5) & 0xff)) << 32;
  2762. src_offset = radeon_get_ib_value(p, idx+3);
  2763. src_offset |= ((u64)(radeon_get_ib_value(p, idx+6) & 0xff)) << 32;
  2764. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2765. dev_warn(p->dev, "DMA L2L, dw, broadcast src buffer too small (%llu %lu)\n",
  2766. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2767. return -EINVAL;
  2768. }
  2769. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2770. dev_warn(p->dev, "DMA L2L, dw, broadcast dst buffer too small (%llu %lu)\n",
  2771. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2772. return -EINVAL;
  2773. }
  2774. if ((dst2_offset + (count * 4)) > radeon_bo_size(dst2_reloc->robj)) {
  2775. dev_warn(p->dev, "DMA L2L, dw, broadcast dst2 buffer too small (%llu %lu)\n",
  2776. dst2_offset + (count * 4), radeon_bo_size(dst2_reloc->robj));
  2777. return -EINVAL;
  2778. }
  2779. ib[idx+1] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2780. ib[idx+2] += (u32)(dst2_reloc->gpu_offset & 0xfffffffc);
  2781. ib[idx+3] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2782. ib[idx+4] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2783. ib[idx+5] += upper_32_bits(dst2_reloc->gpu_offset) & 0xff;
  2784. ib[idx+6] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2785. p->idx += 7;
  2786. break;
  2787. /* Copy L2T Frame to Field */
  2788. case 0x48:
  2789. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2790. DRM_ERROR("bad L2T, frame to fields DMA_PACKET_COPY\n");
  2791. return -EINVAL;
  2792. }
  2793. r = r600_dma_cs_next_reloc(p, &dst2_reloc);
  2794. if (r) {
  2795. DRM_ERROR("bad L2T, frame to fields DMA_PACKET_COPY\n");
  2796. return -EINVAL;
  2797. }
  2798. dst_offset = radeon_get_ib_value(p, idx+1);
  2799. dst_offset <<= 8;
  2800. dst2_offset = radeon_get_ib_value(p, idx+2);
  2801. dst2_offset <<= 8;
  2802. src_offset = radeon_get_ib_value(p, idx+8);
  2803. src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
  2804. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2805. dev_warn(p->dev, "DMA L2T, frame to fields src buffer too small (%llu %lu)\n",
  2806. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2807. return -EINVAL;
  2808. }
  2809. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2810. dev_warn(p->dev, "DMA L2T, frame to fields buffer too small (%llu %lu)\n",
  2811. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2812. return -EINVAL;
  2813. }
  2814. if ((dst2_offset + (count * 4)) > radeon_bo_size(dst2_reloc->robj)) {
  2815. dev_warn(p->dev, "DMA L2T, frame to fields buffer too small (%llu %lu)\n",
  2816. dst2_offset + (count * 4), radeon_bo_size(dst2_reloc->robj));
  2817. return -EINVAL;
  2818. }
  2819. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2820. ib[idx+2] += (u32)(dst2_reloc->gpu_offset >> 8);
  2821. ib[idx+8] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2822. ib[idx+9] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2823. p->idx += 10;
  2824. break;
  2825. /* Copy L2T/T2L, partial */
  2826. case 0x49:
  2827. /* L2T, T2L partial */
  2828. if (p->family < CHIP_CAYMAN) {
  2829. DRM_ERROR("L2T, T2L Partial is cayman only !\n");
  2830. return -EINVAL;
  2831. }
  2832. /* detile bit */
  2833. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2834. /* tiled src, linear dst */
  2835. ib[idx+1] += (u32)(src_reloc->gpu_offset >> 8);
  2836. ib[idx+7] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2837. ib[idx+8] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2838. } else {
  2839. /* linear src, tiled dst */
  2840. ib[idx+7] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2841. ib[idx+8] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2842. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2843. }
  2844. p->idx += 12;
  2845. break;
  2846. /* Copy L2T broadcast */
  2847. case 0x4b:
  2848. /* L2T, broadcast */
  2849. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2850. DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
  2851. return -EINVAL;
  2852. }
  2853. r = r600_dma_cs_next_reloc(p, &dst2_reloc);
  2854. if (r) {
  2855. DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
  2856. return -EINVAL;
  2857. }
  2858. dst_offset = radeon_get_ib_value(p, idx+1);
  2859. dst_offset <<= 8;
  2860. dst2_offset = radeon_get_ib_value(p, idx+2);
  2861. dst2_offset <<= 8;
  2862. src_offset = radeon_get_ib_value(p, idx+8);
  2863. src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
  2864. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2865. dev_warn(p->dev, "DMA L2T, broadcast src buffer too small (%llu %lu)\n",
  2866. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2867. return -EINVAL;
  2868. }
  2869. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2870. dev_warn(p->dev, "DMA L2T, broadcast dst buffer too small (%llu %lu)\n",
  2871. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2872. return -EINVAL;
  2873. }
  2874. if ((dst2_offset + (count * 4)) > radeon_bo_size(dst2_reloc->robj)) {
  2875. dev_warn(p->dev, "DMA L2T, broadcast dst2 buffer too small (%llu %lu)\n",
  2876. dst2_offset + (count * 4), radeon_bo_size(dst2_reloc->robj));
  2877. return -EINVAL;
  2878. }
  2879. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2880. ib[idx+2] += (u32)(dst2_reloc->gpu_offset >> 8);
  2881. ib[idx+8] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2882. ib[idx+9] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2883. p->idx += 10;
  2884. break;
  2885. /* Copy L2T/T2L (tile units) */
  2886. case 0x4c:
  2887. /* L2T, T2L */
  2888. /* detile bit */
  2889. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2890. /* tiled src, linear dst */
  2891. src_offset = radeon_get_ib_value(p, idx+1);
  2892. src_offset <<= 8;
  2893. ib[idx+1] += (u32)(src_reloc->gpu_offset >> 8);
  2894. dst_offset = radeon_get_ib_value(p, idx+7);
  2895. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
  2896. ib[idx+7] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2897. ib[idx+8] += upper_32_bits(dst_reloc->gpu_offset) & 0xff;
  2898. } else {
  2899. /* linear src, tiled dst */
  2900. src_offset = radeon_get_ib_value(p, idx+7);
  2901. src_offset |= ((u64)(radeon_get_ib_value(p, idx+8) & 0xff)) << 32;
  2902. ib[idx+7] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2903. ib[idx+8] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2904. dst_offset = radeon_get_ib_value(p, idx+1);
  2905. dst_offset <<= 8;
  2906. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2907. }
  2908. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2909. dev_warn(p->dev, "DMA L2T, T2L src buffer too small (%llu %lu)\n",
  2910. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2911. return -EINVAL;
  2912. }
  2913. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2914. dev_warn(p->dev, "DMA L2T, T2L dst buffer too small (%llu %lu)\n",
  2915. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2916. return -EINVAL;
  2917. }
  2918. p->idx += 9;
  2919. break;
  2920. /* Copy T2T, partial (tile units) */
  2921. case 0x4d:
  2922. /* T2T partial */
  2923. if (p->family < CHIP_CAYMAN) {
  2924. DRM_ERROR("L2T, T2L Partial is cayman only !\n");
  2925. return -EINVAL;
  2926. }
  2927. ib[idx+1] += (u32)(src_reloc->gpu_offset >> 8);
  2928. ib[idx+4] += (u32)(dst_reloc->gpu_offset >> 8);
  2929. p->idx += 13;
  2930. break;
  2931. /* Copy L2T broadcast (tile units) */
  2932. case 0x4f:
  2933. /* L2T, broadcast */
  2934. if (radeon_get_ib_value(p, idx + 2) & (1 << 31)) {
  2935. DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
  2936. return -EINVAL;
  2937. }
  2938. r = r600_dma_cs_next_reloc(p, &dst2_reloc);
  2939. if (r) {
  2940. DRM_ERROR("bad L2T, broadcast DMA_PACKET_COPY\n");
  2941. return -EINVAL;
  2942. }
  2943. dst_offset = radeon_get_ib_value(p, idx+1);
  2944. dst_offset <<= 8;
  2945. dst2_offset = radeon_get_ib_value(p, idx+2);
  2946. dst2_offset <<= 8;
  2947. src_offset = radeon_get_ib_value(p, idx+8);
  2948. src_offset |= ((u64)(radeon_get_ib_value(p, idx+9) & 0xff)) << 32;
  2949. if ((src_offset + (count * 4)) > radeon_bo_size(src_reloc->robj)) {
  2950. dev_warn(p->dev, "DMA L2T, broadcast src buffer too small (%llu %lu)\n",
  2951. src_offset + (count * 4), radeon_bo_size(src_reloc->robj));
  2952. return -EINVAL;
  2953. }
  2954. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2955. dev_warn(p->dev, "DMA L2T, broadcast dst buffer too small (%llu %lu)\n",
  2956. dst_offset + (count * 4), radeon_bo_size(dst_reloc->robj));
  2957. return -EINVAL;
  2958. }
  2959. if ((dst2_offset + (count * 4)) > radeon_bo_size(dst2_reloc->robj)) {
  2960. dev_warn(p->dev, "DMA L2T, broadcast dst2 buffer too small (%llu %lu)\n",
  2961. dst2_offset + (count * 4), radeon_bo_size(dst2_reloc->robj));
  2962. return -EINVAL;
  2963. }
  2964. ib[idx+1] += (u32)(dst_reloc->gpu_offset >> 8);
  2965. ib[idx+2] += (u32)(dst2_reloc->gpu_offset >> 8);
  2966. ib[idx+8] += (u32)(src_reloc->gpu_offset & 0xfffffffc);
  2967. ib[idx+9] += upper_32_bits(src_reloc->gpu_offset) & 0xff;
  2968. p->idx += 10;
  2969. break;
  2970. default:
  2971. DRM_ERROR("bad DMA_PACKET_COPY [%6d] 0x%08x invalid sub cmd\n", idx, header);
  2972. return -EINVAL;
  2973. }
  2974. break;
  2975. case DMA_PACKET_CONSTANT_FILL:
  2976. r = r600_dma_cs_next_reloc(p, &dst_reloc);
  2977. if (r) {
  2978. DRM_ERROR("bad DMA_PACKET_CONSTANT_FILL\n");
  2979. return -EINVAL;
  2980. }
  2981. dst_offset = radeon_get_ib_value(p, idx+1);
  2982. dst_offset |= ((u64)(radeon_get_ib_value(p, idx+3) & 0x00ff0000)) << 16;
  2983. if ((dst_offset + (count * 4)) > radeon_bo_size(dst_reloc->robj)) {
  2984. dev_warn(p->dev, "DMA constant fill buffer too small (%llu %lu)\n",
  2985. dst_offset, radeon_bo_size(dst_reloc->robj));
  2986. return -EINVAL;
  2987. }
  2988. ib[idx+1] += (u32)(dst_reloc->gpu_offset & 0xfffffffc);
  2989. ib[idx+3] += (upper_32_bits(dst_reloc->gpu_offset) << 16) & 0x00ff0000;
  2990. p->idx += 4;
  2991. break;
  2992. case DMA_PACKET_NOP:
  2993. p->idx += 1;
  2994. break;
  2995. default:
  2996. DRM_ERROR("Unknown packet type %d at %d !\n", cmd, idx);
  2997. return -EINVAL;
  2998. }
  2999. } while (p->idx < p->chunk_ib->length_dw);
  3000. #if 0
  3001. for (r = 0; r < p->ib->length_dw; r++) {
  3002. printk(KERN_INFO "%05d 0x%08X\n", r, p->ib.ptr[r]);
  3003. mdelay(1);
  3004. }
  3005. #endif
  3006. return 0;
  3007. }
  3008. /* vm parser */
  3009. static bool evergreen_vm_reg_valid(u32 reg)
  3010. {
  3011. /* context regs are fine */
  3012. if (reg >= 0x28000)
  3013. return true;
  3014. /* check config regs */
  3015. switch (reg) {
  3016. case WAIT_UNTIL:
  3017. case GRBM_GFX_INDEX:
  3018. case CP_STRMOUT_CNTL:
  3019. case CP_COHER_CNTL:
  3020. case CP_COHER_SIZE:
  3021. case VGT_VTX_VECT_EJECT_REG:
  3022. case VGT_CACHE_INVALIDATION:
  3023. case VGT_GS_VERTEX_REUSE:
  3024. case VGT_PRIMITIVE_TYPE:
  3025. case VGT_INDEX_TYPE:
  3026. case VGT_NUM_INDICES:
  3027. case VGT_NUM_INSTANCES:
  3028. case VGT_COMPUTE_DIM_X:
  3029. case VGT_COMPUTE_DIM_Y:
  3030. case VGT_COMPUTE_DIM_Z:
  3031. case VGT_COMPUTE_START_X:
  3032. case VGT_COMPUTE_START_Y:
  3033. case VGT_COMPUTE_START_Z:
  3034. case VGT_COMPUTE_INDEX:
  3035. case VGT_COMPUTE_THREAD_GROUP_SIZE:
  3036. case VGT_HS_OFFCHIP_PARAM:
  3037. case PA_CL_ENHANCE:
  3038. case PA_SU_LINE_STIPPLE_VALUE:
  3039. case PA_SC_LINE_STIPPLE_STATE:
  3040. case PA_SC_ENHANCE:
  3041. case SQ_DYN_GPR_CNTL_PS_FLUSH_REQ:
  3042. case SQ_DYN_GPR_SIMD_LOCK_EN:
  3043. case SQ_CONFIG:
  3044. case SQ_GPR_RESOURCE_MGMT_1:
  3045. case SQ_GLOBAL_GPR_RESOURCE_MGMT_1:
  3046. case SQ_GLOBAL_GPR_RESOURCE_MGMT_2:
  3047. case SQ_CONST_MEM_BASE:
  3048. case SQ_STATIC_THREAD_MGMT_1:
  3049. case SQ_STATIC_THREAD_MGMT_2:
  3050. case SQ_STATIC_THREAD_MGMT_3:
  3051. case SPI_CONFIG_CNTL:
  3052. case SPI_CONFIG_CNTL_1:
  3053. case TA_CNTL_AUX:
  3054. case DB_DEBUG:
  3055. case DB_DEBUG2:
  3056. case DB_DEBUG3:
  3057. case DB_DEBUG4:
  3058. case DB_WATERMARKS:
  3059. case TD_PS_BORDER_COLOR_INDEX:
  3060. case TD_PS_BORDER_COLOR_RED:
  3061. case TD_PS_BORDER_COLOR_GREEN:
  3062. case TD_PS_BORDER_COLOR_BLUE:
  3063. case TD_PS_BORDER_COLOR_ALPHA:
  3064. case TD_VS_BORDER_COLOR_INDEX:
  3065. case TD_VS_BORDER_COLOR_RED:
  3066. case TD_VS_BORDER_COLOR_GREEN:
  3067. case TD_VS_BORDER_COLOR_BLUE:
  3068. case TD_VS_BORDER_COLOR_ALPHA:
  3069. case TD_GS_BORDER_COLOR_INDEX:
  3070. case TD_GS_BORDER_COLOR_RED:
  3071. case TD_GS_BORDER_COLOR_GREEN:
  3072. case TD_GS_BORDER_COLOR_BLUE:
  3073. case TD_GS_BORDER_COLOR_ALPHA:
  3074. case TD_HS_BORDER_COLOR_INDEX:
  3075. case TD_HS_BORDER_COLOR_RED:
  3076. case TD_HS_BORDER_COLOR_GREEN:
  3077. case TD_HS_BORDER_COLOR_BLUE:
  3078. case TD_HS_BORDER_COLOR_ALPHA:
  3079. case TD_LS_BORDER_COLOR_INDEX:
  3080. case TD_LS_BORDER_COLOR_RED:
  3081. case TD_LS_BORDER_COLOR_GREEN:
  3082. case TD_LS_BORDER_COLOR_BLUE:
  3083. case TD_LS_BORDER_COLOR_ALPHA:
  3084. case TD_CS_BORDER_COLOR_INDEX:
  3085. case TD_CS_BORDER_COLOR_RED:
  3086. case TD_CS_BORDER_COLOR_GREEN:
  3087. case TD_CS_BORDER_COLOR_BLUE:
  3088. case TD_CS_BORDER_COLOR_ALPHA:
  3089. case SQ_ESGS_RING_SIZE:
  3090. case SQ_GSVS_RING_SIZE:
  3091. case SQ_ESTMP_RING_SIZE:
  3092. case SQ_GSTMP_RING_SIZE:
  3093. case SQ_HSTMP_RING_SIZE:
  3094. case SQ_LSTMP_RING_SIZE:
  3095. case SQ_PSTMP_RING_SIZE:
  3096. case SQ_VSTMP_RING_SIZE:
  3097. case SQ_ESGS_RING_ITEMSIZE:
  3098. case SQ_ESTMP_RING_ITEMSIZE:
  3099. case SQ_GSTMP_RING_ITEMSIZE:
  3100. case SQ_GSVS_RING_ITEMSIZE:
  3101. case SQ_GS_VERT_ITEMSIZE:
  3102. case SQ_GS_VERT_ITEMSIZE_1:
  3103. case SQ_GS_VERT_ITEMSIZE_2:
  3104. case SQ_GS_VERT_ITEMSIZE_3:
  3105. case SQ_GSVS_RING_OFFSET_1:
  3106. case SQ_GSVS_RING_OFFSET_2:
  3107. case SQ_GSVS_RING_OFFSET_3:
  3108. case SQ_HSTMP_RING_ITEMSIZE:
  3109. case SQ_LSTMP_RING_ITEMSIZE:
  3110. case SQ_PSTMP_RING_ITEMSIZE:
  3111. case SQ_VSTMP_RING_ITEMSIZE:
  3112. case VGT_TF_RING_SIZE:
  3113. case SQ_ESGS_RING_BASE:
  3114. case SQ_GSVS_RING_BASE:
  3115. case SQ_ESTMP_RING_BASE:
  3116. case SQ_GSTMP_RING_BASE:
  3117. case SQ_HSTMP_RING_BASE:
  3118. case SQ_LSTMP_RING_BASE:
  3119. case SQ_PSTMP_RING_BASE:
  3120. case SQ_VSTMP_RING_BASE:
  3121. case CAYMAN_VGT_OFFCHIP_LDS_BASE:
  3122. case CAYMAN_SQ_EX_ALLOC_TABLE_SLOTS:
  3123. return true;
  3124. default:
  3125. DRM_ERROR("Invalid register 0x%x in CS\n", reg);
  3126. return false;
  3127. }
  3128. }
  3129. static int evergreen_vm_packet3_check(struct radeon_device *rdev,
  3130. u32 *ib, struct radeon_cs_packet *pkt)
  3131. {
  3132. u32 idx = pkt->idx + 1;
  3133. u32 idx_value = ib[idx];
  3134. u32 start_reg, end_reg, reg, i;
  3135. u32 command, info;
  3136. switch (pkt->opcode) {
  3137. case PACKET3_NOP:
  3138. break;
  3139. case PACKET3_SET_BASE:
  3140. if (idx_value != 1) {
  3141. DRM_ERROR("bad SET_BASE");
  3142. return -EINVAL;
  3143. }
  3144. break;
  3145. case PACKET3_CLEAR_STATE:
  3146. case PACKET3_INDEX_BUFFER_SIZE:
  3147. case PACKET3_DISPATCH_DIRECT:
  3148. case PACKET3_DISPATCH_INDIRECT:
  3149. case PACKET3_MODE_CONTROL:
  3150. case PACKET3_SET_PREDICATION:
  3151. case PACKET3_COND_EXEC:
  3152. case PACKET3_PRED_EXEC:
  3153. case PACKET3_DRAW_INDIRECT:
  3154. case PACKET3_DRAW_INDEX_INDIRECT:
  3155. case PACKET3_INDEX_BASE:
  3156. case PACKET3_DRAW_INDEX_2:
  3157. case PACKET3_CONTEXT_CONTROL:
  3158. case PACKET3_DRAW_INDEX_OFFSET:
  3159. case PACKET3_INDEX_TYPE:
  3160. case PACKET3_DRAW_INDEX:
  3161. case PACKET3_DRAW_INDEX_AUTO:
  3162. case PACKET3_DRAW_INDEX_IMMD:
  3163. case PACKET3_NUM_INSTANCES:
  3164. case PACKET3_DRAW_INDEX_MULTI_AUTO:
  3165. case PACKET3_STRMOUT_BUFFER_UPDATE:
  3166. case PACKET3_DRAW_INDEX_OFFSET_2:
  3167. case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
  3168. case PACKET3_MPEG_INDEX:
  3169. case PACKET3_WAIT_REG_MEM:
  3170. case PACKET3_MEM_WRITE:
  3171. case PACKET3_SURFACE_SYNC:
  3172. case PACKET3_EVENT_WRITE:
  3173. case PACKET3_EVENT_WRITE_EOP:
  3174. case PACKET3_EVENT_WRITE_EOS:
  3175. case PACKET3_SET_CONTEXT_REG:
  3176. case PACKET3_SET_BOOL_CONST:
  3177. case PACKET3_SET_LOOP_CONST:
  3178. case PACKET3_SET_RESOURCE:
  3179. case PACKET3_SET_SAMPLER:
  3180. case PACKET3_SET_CTL_CONST:
  3181. case PACKET3_SET_RESOURCE_OFFSET:
  3182. case PACKET3_SET_CONTEXT_REG_INDIRECT:
  3183. case PACKET3_SET_RESOURCE_INDIRECT:
  3184. case CAYMAN_PACKET3_DEALLOC_STATE:
  3185. break;
  3186. case PACKET3_COND_WRITE:
  3187. if (idx_value & 0x100) {
  3188. reg = ib[idx + 5] * 4;
  3189. if (!evergreen_vm_reg_valid(reg))
  3190. return -EINVAL;
  3191. }
  3192. break;
  3193. case PACKET3_COPY_DW:
  3194. if (idx_value & 0x2) {
  3195. reg = ib[idx + 3] * 4;
  3196. if (!evergreen_vm_reg_valid(reg))
  3197. return -EINVAL;
  3198. }
  3199. break;
  3200. case PACKET3_SET_CONFIG_REG:
  3201. start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
  3202. end_reg = 4 * pkt->count + start_reg - 4;
  3203. if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
  3204. (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
  3205. (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
  3206. DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
  3207. return -EINVAL;
  3208. }
  3209. for (i = 0; i < pkt->count; i++) {
  3210. reg = start_reg + (4 * i);
  3211. if (!evergreen_vm_reg_valid(reg))
  3212. return -EINVAL;
  3213. }
  3214. break;
  3215. case PACKET3_CP_DMA:
  3216. command = ib[idx + 4];
  3217. info = ib[idx + 1];
  3218. if ((((info & 0x60000000) >> 29) != 0) || /* src = GDS or DATA */
  3219. (((info & 0x00300000) >> 20) != 0) || /* dst = GDS */
  3220. ((((info & 0x00300000) >> 20) == 0) &&
  3221. (command & PACKET3_CP_DMA_CMD_DAS)) || /* dst = register */
  3222. ((((info & 0x60000000) >> 29) == 0) &&
  3223. (command & PACKET3_CP_DMA_CMD_SAS))) { /* src = register */
  3224. /* non mem to mem copies requires dw aligned count */
  3225. if ((command & 0x1fffff) % 4) {
  3226. DRM_ERROR("CP DMA command requires dw count alignment\n");
  3227. return -EINVAL;
  3228. }
  3229. }
  3230. if (command & PACKET3_CP_DMA_CMD_SAS) {
  3231. /* src address space is register */
  3232. if (((info & 0x60000000) >> 29) == 0) {
  3233. start_reg = idx_value << 2;
  3234. if (command & PACKET3_CP_DMA_CMD_SAIC) {
  3235. reg = start_reg;
  3236. if (!evergreen_vm_reg_valid(reg)) {
  3237. DRM_ERROR("CP DMA Bad SRC register\n");
  3238. return -EINVAL;
  3239. }
  3240. } else {
  3241. for (i = 0; i < (command & 0x1fffff); i++) {
  3242. reg = start_reg + (4 * i);
  3243. if (!evergreen_vm_reg_valid(reg)) {
  3244. DRM_ERROR("CP DMA Bad SRC register\n");
  3245. return -EINVAL;
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. if (command & PACKET3_CP_DMA_CMD_DAS) {
  3252. /* dst address space is register */
  3253. if (((info & 0x00300000) >> 20) == 0) {
  3254. start_reg = ib[idx + 2];
  3255. if (command & PACKET3_CP_DMA_CMD_DAIC) {
  3256. reg = start_reg;
  3257. if (!evergreen_vm_reg_valid(reg)) {
  3258. DRM_ERROR("CP DMA Bad DST register\n");
  3259. return -EINVAL;
  3260. }
  3261. } else {
  3262. for (i = 0; i < (command & 0x1fffff); i++) {
  3263. reg = start_reg + (4 * i);
  3264. if (!evergreen_vm_reg_valid(reg)) {
  3265. DRM_ERROR("CP DMA Bad DST register\n");
  3266. return -EINVAL;
  3267. }
  3268. }
  3269. }
  3270. }
  3271. }
  3272. break;
  3273. default:
  3274. return -EINVAL;
  3275. }
  3276. return 0;
  3277. }
  3278. int evergreen_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3279. {
  3280. int ret = 0;
  3281. u32 idx = 0;
  3282. struct radeon_cs_packet pkt;
  3283. do {
  3284. pkt.idx = idx;
  3285. pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
  3286. pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
  3287. pkt.one_reg_wr = 0;
  3288. switch (pkt.type) {
  3289. case RADEON_PACKET_TYPE0:
  3290. dev_err(rdev->dev, "Packet0 not allowed!\n");
  3291. ret = -EINVAL;
  3292. break;
  3293. case RADEON_PACKET_TYPE2:
  3294. idx += 1;
  3295. break;
  3296. case RADEON_PACKET_TYPE3:
  3297. pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
  3298. ret = evergreen_vm_packet3_check(rdev, ib->ptr, &pkt);
  3299. idx += pkt.count + 2;
  3300. break;
  3301. default:
  3302. dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
  3303. ret = -EINVAL;
  3304. break;
  3305. }
  3306. if (ret)
  3307. break;
  3308. } while (idx < ib->length_dw);
  3309. return ret;
  3310. }
  3311. /**
  3312. * evergreen_dma_ib_parse() - parse the DMA IB for VM
  3313. * @rdev: radeon_device pointer
  3314. * @ib: radeon_ib pointer
  3315. *
  3316. * Parses the DMA IB from the VM CS ioctl
  3317. * checks for errors. (Cayman-SI)
  3318. * Returns 0 for success and an error on failure.
  3319. **/
  3320. int evergreen_dma_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
  3321. {
  3322. u32 idx = 0;
  3323. u32 header, cmd, count, sub_cmd;
  3324. do {
  3325. header = ib->ptr[idx];
  3326. cmd = GET_DMA_CMD(header);
  3327. count = GET_DMA_COUNT(header);
  3328. sub_cmd = GET_DMA_SUB_CMD(header);
  3329. switch (cmd) {
  3330. case DMA_PACKET_WRITE:
  3331. switch (sub_cmd) {
  3332. /* tiled */
  3333. case 8:
  3334. idx += count + 7;
  3335. break;
  3336. /* linear */
  3337. case 0:
  3338. idx += count + 3;
  3339. break;
  3340. default:
  3341. DRM_ERROR("bad DMA_PACKET_WRITE [%6d] 0x%08x sub cmd is not 0 or 8\n", idx, ib->ptr[idx]);
  3342. return -EINVAL;
  3343. }
  3344. break;
  3345. case DMA_PACKET_COPY:
  3346. switch (sub_cmd) {
  3347. /* Copy L2L, DW aligned */
  3348. case 0x00:
  3349. idx += 5;
  3350. break;
  3351. /* Copy L2T/T2L */
  3352. case 0x08:
  3353. idx += 9;
  3354. break;
  3355. /* Copy L2L, byte aligned */
  3356. case 0x40:
  3357. idx += 5;
  3358. break;
  3359. /* Copy L2L, partial */
  3360. case 0x41:
  3361. idx += 9;
  3362. break;
  3363. /* Copy L2L, DW aligned, broadcast */
  3364. case 0x44:
  3365. idx += 7;
  3366. break;
  3367. /* Copy L2T Frame to Field */
  3368. case 0x48:
  3369. idx += 10;
  3370. break;
  3371. /* Copy L2T/T2L, partial */
  3372. case 0x49:
  3373. idx += 12;
  3374. break;
  3375. /* Copy L2T broadcast */
  3376. case 0x4b:
  3377. idx += 10;
  3378. break;
  3379. /* Copy L2T/T2L (tile units) */
  3380. case 0x4c:
  3381. idx += 9;
  3382. break;
  3383. /* Copy T2T, partial (tile units) */
  3384. case 0x4d:
  3385. idx += 13;
  3386. break;
  3387. /* Copy L2T broadcast (tile units) */
  3388. case 0x4f:
  3389. idx += 10;
  3390. break;
  3391. default:
  3392. DRM_ERROR("bad DMA_PACKET_COPY [%6d] 0x%08x invalid sub cmd\n", idx, ib->ptr[idx]);
  3393. return -EINVAL;
  3394. }
  3395. break;
  3396. case DMA_PACKET_CONSTANT_FILL:
  3397. idx += 4;
  3398. break;
  3399. case DMA_PACKET_NOP:
  3400. idx += 1;
  3401. break;
  3402. default:
  3403. DRM_ERROR("Unknown packet type %d at %d !\n", cmd, idx);
  3404. return -EINVAL;
  3405. }
  3406. } while (idx < ib->length_dw);
  3407. return 0;
  3408. }