intel_decode.c 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  1. /*
  2. * Copyright © 2009-2011 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. #include <assert.h>
  24. #include <stdint.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <stdbool.h>
  28. #include <stdarg.h>
  29. #include <string.h>
  30. #include "libdrm_macros.h"
  31. #include "xf86drm.h"
  32. #include "intel_chipset.h"
  33. #include "intel_bufmgr.h"
  34. /* Struct for tracking drm_intel_decode state. */
  35. struct drm_intel_decode {
  36. /** stdio file where the output should land. Defaults to stdout. */
  37. FILE *out;
  38. /** PCI device ID. */
  39. uint32_t devid;
  40. /**
  41. * Shorthand device identifier: 3 is 915, 4 is 965, 5 is
  42. * Ironlake, etc.
  43. */
  44. int gen;
  45. /** GPU address of the start of the current packet. */
  46. uint32_t hw_offset;
  47. /** CPU virtual address of the start of the current packet. */
  48. uint32_t *data;
  49. /** DWORDs of remaining batchbuffer data starting from the packet. */
  50. uint32_t count;
  51. /** GPU address of the start of the batchbuffer data. */
  52. uint32_t base_hw_offset;
  53. /** CPU Virtual address of the start of the batchbuffer data. */
  54. uint32_t *base_data;
  55. /** Number of DWORDs of batchbuffer data. */
  56. uint32_t base_count;
  57. /** @{
  58. * GPU head and tail pointers, which will be noted in the dump, or ~0.
  59. */
  60. uint32_t head, tail;
  61. /** @} */
  62. /**
  63. * Whether to dump the dwords after MI_BATCHBUFFER_END.
  64. *
  65. * This sometimes provides clues in corrupted batchbuffers,
  66. * and is used by the intel-gpu-tools.
  67. */
  68. bool dump_past_end;
  69. bool overflowed;
  70. };
  71. static FILE *out;
  72. static uint32_t saved_s2 = 0, saved_s4 = 0;
  73. static char saved_s2_set = 0, saved_s4_set = 0;
  74. static uint32_t head_offset = 0xffffffff; /* undefined */
  75. static uint32_t tail_offset = 0xffffffff; /* undefined */
  76. #ifndef ARRAY_SIZE
  77. #define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
  78. #endif
  79. #define BUFFER_FAIL(_count, _len, _name) do { \
  80. fprintf(out, "Buffer size too small in %s (%d < %d)\n", \
  81. (_name), (_count), (_len)); \
  82. return _count; \
  83. } while (0)
  84. static float int_as_float(uint32_t intval)
  85. {
  86. union intfloat {
  87. uint32_t i;
  88. float f;
  89. } uval;
  90. uval.i = intval;
  91. return uval.f;
  92. }
  93. static void DRM_PRINTFLIKE(3, 4)
  94. instr_out(struct drm_intel_decode *ctx, unsigned int index,
  95. const char *fmt, ...)
  96. {
  97. va_list va;
  98. const char *parseinfo;
  99. uint32_t offset = ctx->hw_offset + index * 4;
  100. if (index > ctx->count) {
  101. if (!ctx->overflowed) {
  102. fprintf(out, "ERROR: Decode attempted to continue beyond end of batchbuffer\n");
  103. ctx->overflowed = true;
  104. }
  105. return;
  106. }
  107. if (offset == head_offset)
  108. parseinfo = "HEAD";
  109. else if (offset == tail_offset)
  110. parseinfo = "TAIL";
  111. else
  112. parseinfo = " ";
  113. fprintf(out, "0x%08x: %s 0x%08x: %s", offset, parseinfo,
  114. ctx->data[index], index == 0 ? "" : " ");
  115. va_start(va, fmt);
  116. vfprintf(out, fmt, va);
  117. va_end(va);
  118. }
  119. static int
  120. decode_MI_SET_CONTEXT(struct drm_intel_decode *ctx)
  121. {
  122. uint32_t data = ctx->data[1];
  123. if (ctx->gen > 7)
  124. return 1;
  125. instr_out(ctx, 0, "MI_SET_CONTEXT\n");
  126. instr_out(ctx, 1, "gtt offset = 0x%x%s%s\n",
  127. data & ~0xfff,
  128. data & (1<<1)? ", Force Restore": "",
  129. data & (1<<0)? ", Restore Inhibit": "");
  130. return 2;
  131. }
  132. static int
  133. decode_MI_WAIT_FOR_EVENT(struct drm_intel_decode *ctx)
  134. {
  135. const char *cc_wait;
  136. int cc_shift = 0;
  137. uint32_t data = ctx->data[0];
  138. if (ctx->gen <= 5)
  139. cc_shift = 9;
  140. else
  141. cc_shift = 16;
  142. switch ((data >> cc_shift) & 0x1f) {
  143. case 1:
  144. cc_wait = ", cc wait 1";
  145. break;
  146. case 2:
  147. cc_wait = ", cc wait 2";
  148. break;
  149. case 3:
  150. cc_wait = ", cc wait 3";
  151. break;
  152. case 4:
  153. cc_wait = ", cc wait 4";
  154. break;
  155. case 5:
  156. cc_wait = ", cc wait 4";
  157. break;
  158. default:
  159. cc_wait = "";
  160. break;
  161. }
  162. if (ctx->gen <= 5) {
  163. instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  164. data & (1<<18)? ", pipe B start vblank wait": "",
  165. data & (1<<17)? ", pipe A start vblank wait": "",
  166. data & (1<<16)? ", overlay flip pending wait": "",
  167. data & (1<<14)? ", pipe B hblank wait": "",
  168. data & (1<<13)? ", pipe A hblank wait": "",
  169. cc_wait,
  170. data & (1<<8)? ", plane C pending flip wait": "",
  171. data & (1<<7)? ", pipe B vblank wait": "",
  172. data & (1<<6)? ", plane B pending flip wait": "",
  173. data & (1<<5)? ", pipe B scan line wait": "",
  174. data & (1<<4)? ", fbc idle wait": "",
  175. data & (1<<3)? ", pipe A vblank wait": "",
  176. data & (1<<2)? ", plane A pending flip wait": "",
  177. data & (1<<1)? ", plane A scan line wait": "");
  178. } else {
  179. instr_out(ctx, 0, "MI_WAIT_FOR_EVENT%s%s%s%s%s%s%s%s%s%s%s%s\n",
  180. data & (1<<20)? ", sprite C pending flip wait": "", /* ivb */
  181. cc_wait,
  182. data & (1<<13)? ", pipe B hblank wait": "",
  183. data & (1<<11)? ", pipe B vblank wait": "",
  184. data & (1<<10)? ", sprite B pending flip wait": "",
  185. data & (1<<9)? ", plane B pending flip wait": "",
  186. data & (1<<8)? ", plane B scan line wait": "",
  187. data & (1<<5)? ", pipe A hblank wait": "",
  188. data & (1<<3)? ", pipe A vblank wait": "",
  189. data & (1<<2)? ", sprite A pending flip wait": "",
  190. data & (1<<1)? ", plane A pending flip wait": "",
  191. data & (1<<0)? ", plane A scan line wait": "");
  192. }
  193. return 1;
  194. }
  195. static int
  196. decode_mi(struct drm_intel_decode *ctx)
  197. {
  198. unsigned int opcode, len = -1;
  199. const char *post_sync_op = "";
  200. uint32_t *data = ctx->data;
  201. struct {
  202. uint32_t opcode;
  203. int len_mask;
  204. unsigned int min_len;
  205. unsigned int max_len;
  206. const char *name;
  207. int (*func)(struct drm_intel_decode *ctx);
  208. } opcodes_mi[] = {
  209. { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
  210. { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
  211. { 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
  212. { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
  213. { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
  214. { 0x04, 0, 1, 1, "MI_FLUSH" },
  215. { 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
  216. { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
  217. { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
  218. { 0x00, 0, 1, 1, "MI_NOOP" },
  219. { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
  220. { 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
  221. { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT", decode_MI_SET_CONTEXT },
  222. { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
  223. { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
  224. { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
  225. { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
  226. { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT", decode_MI_WAIT_FOR_EVENT },
  227. { 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
  228. { 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
  229. { 0x28, 0x3f, 3, 3, "MI_REPORT_PERF_COUNT" },
  230. { 0x29, 0xff, 3, 3, "MI_LOAD_REGISTER_MEM" },
  231. { 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH"},
  232. }, *opcode_mi = NULL;
  233. /* check instruction length */
  234. for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
  235. opcode++) {
  236. if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
  237. len = 1;
  238. if (opcodes_mi[opcode].max_len > 1) {
  239. len =
  240. (data[0] & opcodes_mi[opcode].len_mask) + 2;
  241. if (len < opcodes_mi[opcode].min_len
  242. || len > opcodes_mi[opcode].max_len) {
  243. fprintf(out,
  244. "Bad length (%d) in %s, [%d, %d]\n",
  245. len, opcodes_mi[opcode].name,
  246. opcodes_mi[opcode].min_len,
  247. opcodes_mi[opcode].max_len);
  248. }
  249. }
  250. opcode_mi = &opcodes_mi[opcode];
  251. break;
  252. }
  253. }
  254. if (opcode_mi && opcode_mi->func)
  255. return opcode_mi->func(ctx);
  256. switch ((data[0] & 0x1f800000) >> 23) {
  257. case 0x0a:
  258. instr_out(ctx, 0, "MI_BATCH_BUFFER_END\n");
  259. return -1;
  260. case 0x16:
  261. instr_out(ctx, 0, "MI_SEMAPHORE_MBOX%s%s%s%s %u\n",
  262. data[0] & (1 << 22) ? " global gtt," : "",
  263. data[0] & (1 << 21) ? " update semaphore," : "",
  264. data[0] & (1 << 20) ? " compare semaphore," : "",
  265. data[0] & (1 << 18) ? " use compare reg" : "",
  266. (data[0] & (0x3 << 16)) >> 16);
  267. instr_out(ctx, 1, "value\n");
  268. instr_out(ctx, 2, "address\n");
  269. return len;
  270. case 0x21:
  271. instr_out(ctx, 0, "MI_STORE_DATA_INDEX%s\n",
  272. data[0] & (1 << 21) ? " use per-process HWS," : "");
  273. instr_out(ctx, 1, "index\n");
  274. instr_out(ctx, 2, "dword\n");
  275. if (len == 4)
  276. instr_out(ctx, 3, "upper dword\n");
  277. return len;
  278. case 0x00:
  279. if (data[0] & (1 << 22))
  280. instr_out(ctx, 0,
  281. "MI_NOOP write NOPID reg, val=0x%x\n",
  282. data[0] & ((1 << 22) - 1));
  283. else
  284. instr_out(ctx, 0, "MI_NOOP\n");
  285. return len;
  286. case 0x26:
  287. switch (data[0] & (0x3 << 14)) {
  288. case (0 << 14):
  289. post_sync_op = "no write";
  290. break;
  291. case (1 << 14):
  292. post_sync_op = "write data";
  293. break;
  294. case (2 << 14):
  295. post_sync_op = "reserved";
  296. break;
  297. case (3 << 14):
  298. post_sync_op = "write TIMESTAMP";
  299. break;
  300. }
  301. instr_out(ctx, 0,
  302. "MI_FLUSH_DW%s%s%s%s post_sync_op='%s' %s%s\n",
  303. data[0] & (1 << 22) ?
  304. " enable protected mem (BCS-only)," : "",
  305. data[0] & (1 << 21) ? " store in hws," : "",
  306. data[0] & (1 << 18) ? " invalidate tlb," : "",
  307. data[0] & (1 << 17) ? " flush gfdt," : "",
  308. post_sync_op,
  309. data[0] & (1 << 8) ? " enable notify interrupt," : "",
  310. data[0] & (1 << 7) ?
  311. " invalidate video state (BCS-only)," : "");
  312. if (data[0] & (1 << 21))
  313. instr_out(ctx, 1, "hws index\n");
  314. else
  315. instr_out(ctx, 1, "address\n");
  316. instr_out(ctx, 2, "dword\n");
  317. if (len == 4)
  318. instr_out(ctx, 3, "upper dword\n");
  319. return len;
  320. }
  321. for (opcode = 0; opcode < sizeof(opcodes_mi) / sizeof(opcodes_mi[0]);
  322. opcode++) {
  323. if ((data[0] & 0x1f800000) >> 23 == opcodes_mi[opcode].opcode) {
  324. unsigned int i;
  325. instr_out(ctx, 0, "%s\n",
  326. opcodes_mi[opcode].name);
  327. for (i = 1; i < len; i++) {
  328. instr_out(ctx, i, "dword %d\n", i);
  329. }
  330. return len;
  331. }
  332. }
  333. instr_out(ctx, 0, "MI UNKNOWN\n");
  334. return 1;
  335. }
  336. static void
  337. decode_2d_br00(struct drm_intel_decode *ctx, const char *cmd)
  338. {
  339. instr_out(ctx, 0,
  340. "%s (rgb %sabled, alpha %sabled, src tile %d, dst tile %d)\n",
  341. cmd,
  342. (ctx->data[0] & (1 << 20)) ? "en" : "dis",
  343. (ctx->data[0] & (1 << 21)) ? "en" : "dis",
  344. (ctx->data[0] >> 15) & 1,
  345. (ctx->data[0] >> 11) & 1);
  346. }
  347. static void
  348. decode_2d_br01(struct drm_intel_decode *ctx)
  349. {
  350. const char *format;
  351. switch ((ctx->data[1] >> 24) & 0x3) {
  352. case 0:
  353. format = "8";
  354. break;
  355. case 1:
  356. format = "565";
  357. break;
  358. case 2:
  359. format = "1555";
  360. break;
  361. case 3:
  362. format = "8888";
  363. break;
  364. }
  365. instr_out(ctx, 1,
  366. "format %s, pitch %d, rop 0x%02x, "
  367. "clipping %sabled, %s%s \n",
  368. format,
  369. (short)(ctx->data[1] & 0xffff),
  370. (ctx->data[1] >> 16) & 0xff,
  371. ctx->data[1] & (1 << 30) ? "en" : "dis",
  372. ctx->data[1] & (1 << 31) ? "solid pattern enabled, " : "",
  373. ctx->data[1] & (1 << 31) ?
  374. "mono pattern transparency enabled, " : "");
  375. }
  376. static int
  377. decode_2d(struct drm_intel_decode *ctx)
  378. {
  379. unsigned int opcode, len;
  380. uint32_t *data = ctx->data;
  381. struct {
  382. uint32_t opcode;
  383. unsigned int min_len;
  384. unsigned int max_len;
  385. const char *name;
  386. } opcodes_2d[] = {
  387. { 0x40, 5, 5, "COLOR_BLT" },
  388. { 0x43, 6, 6, "SRC_COPY_BLT" },
  389. { 0x01, 8, 8, "XY_SETUP_BLT" },
  390. { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
  391. { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
  392. { 0x24, 2, 2, "XY_PIXEL_BLT" },
  393. { 0x25, 3, 3, "XY_SCANLINES_BLT" },
  394. { 0x26, 4, 4, "Y_TEXT_BLT" },
  395. { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
  396. { 0x50, 6, 6, "XY_COLOR_BLT" },
  397. { 0x51, 6, 6, "XY_PAT_BLT" },
  398. { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
  399. { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
  400. { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
  401. { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
  402. { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
  403. { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
  404. { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
  405. { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
  406. { 0x55, 9, 9, "XY_FULL_BLT" },
  407. { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
  408. { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
  409. { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
  410. { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
  411. { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT"},
  412. };
  413. switch ((data[0] & 0x1fc00000) >> 22) {
  414. case 0x25:
  415. instr_out(ctx, 0,
  416. "XY_SCANLINES_BLT (pattern seed (%d, %d), dst tile %d)\n",
  417. (data[0] >> 12) & 0x8,
  418. (data[0] >> 8) & 0x8, (data[0] >> 11) & 1);
  419. len = (data[0] & 0x000000ff) + 2;
  420. if (len != 3)
  421. fprintf(out, "Bad count in XY_SCANLINES_BLT\n");
  422. instr_out(ctx, 1, "dest (%d,%d)\n",
  423. data[1] & 0xffff, data[1] >> 16);
  424. instr_out(ctx, 2, "dest (%d,%d)\n",
  425. data[2] & 0xffff, data[2] >> 16);
  426. return len;
  427. case 0x01:
  428. decode_2d_br00(ctx, "XY_SETUP_BLT");
  429. len = (data[0] & 0x000000ff) + 2;
  430. if (len != 8)
  431. fprintf(out, "Bad count in XY_SETUP_BLT\n");
  432. decode_2d_br01(ctx);
  433. instr_out(ctx, 2, "cliprect (%d,%d)\n",
  434. data[2] & 0xffff, data[2] >> 16);
  435. instr_out(ctx, 3, "cliprect (%d,%d)\n",
  436. data[3] & 0xffff, data[3] >> 16);
  437. instr_out(ctx, 4, "setup dst offset 0x%08x\n",
  438. data[4]);
  439. instr_out(ctx, 5, "setup background color\n");
  440. instr_out(ctx, 6, "setup foreground color\n");
  441. instr_out(ctx, 7, "color pattern offset\n");
  442. return len;
  443. case 0x03:
  444. decode_2d_br00(ctx, "XY_SETUP_CLIP_BLT");
  445. len = (data[0] & 0x000000ff) + 2;
  446. if (len != 3)
  447. fprintf(out, "Bad count in XY_SETUP_CLIP_BLT\n");
  448. instr_out(ctx, 1, "cliprect (%d,%d)\n",
  449. data[1] & 0xffff, data[2] >> 16);
  450. instr_out(ctx, 2, "cliprect (%d,%d)\n",
  451. data[2] & 0xffff, data[3] >> 16);
  452. return len;
  453. case 0x11:
  454. decode_2d_br00(ctx, "XY_SETUP_MONO_PATTERN_SL_BLT");
  455. len = (data[0] & 0x000000ff) + 2;
  456. if (len != 9)
  457. fprintf(out,
  458. "Bad count in XY_SETUP_MONO_PATTERN_SL_BLT\n");
  459. decode_2d_br01(ctx);
  460. instr_out(ctx, 2, "cliprect (%d,%d)\n",
  461. data[2] & 0xffff, data[2] >> 16);
  462. instr_out(ctx, 3, "cliprect (%d,%d)\n",
  463. data[3] & 0xffff, data[3] >> 16);
  464. instr_out(ctx, 4, "setup dst offset 0x%08x\n",
  465. data[4]);
  466. instr_out(ctx, 5, "setup background color\n");
  467. instr_out(ctx, 6, "setup foreground color\n");
  468. instr_out(ctx, 7, "mono pattern dw0\n");
  469. instr_out(ctx, 8, "mono pattern dw1\n");
  470. return len;
  471. case 0x50:
  472. decode_2d_br00(ctx, "XY_COLOR_BLT");
  473. len = (data[0] & 0x000000ff) + 2;
  474. if (len != 6)
  475. fprintf(out, "Bad count in XY_COLOR_BLT\n");
  476. decode_2d_br01(ctx);
  477. instr_out(ctx, 2, "(%d,%d)\n",
  478. data[2] & 0xffff, data[2] >> 16);
  479. instr_out(ctx, 3, "(%d,%d)\n",
  480. data[3] & 0xffff, data[3] >> 16);
  481. instr_out(ctx, 4, "offset 0x%08x\n", data[4]);
  482. instr_out(ctx, 5, "color\n");
  483. return len;
  484. case 0x53:
  485. decode_2d_br00(ctx, "XY_SRC_COPY_BLT");
  486. len = (data[0] & 0x000000ff) + 2;
  487. if (len != 8)
  488. fprintf(out, "Bad count in XY_SRC_COPY_BLT\n");
  489. decode_2d_br01(ctx);
  490. instr_out(ctx, 2, "dst (%d,%d)\n",
  491. data[2] & 0xffff, data[2] >> 16);
  492. instr_out(ctx, 3, "dst (%d,%d)\n",
  493. data[3] & 0xffff, data[3] >> 16);
  494. instr_out(ctx, 4, "dst offset 0x%08x\n", data[4]);
  495. instr_out(ctx, 5, "src (%d,%d)\n",
  496. data[5] & 0xffff, data[5] >> 16);
  497. instr_out(ctx, 6, "src pitch %d\n",
  498. (short)(data[6] & 0xffff));
  499. instr_out(ctx, 7, "src offset 0x%08x\n", data[7]);
  500. return len;
  501. }
  502. for (opcode = 0; opcode < sizeof(opcodes_2d) / sizeof(opcodes_2d[0]);
  503. opcode++) {
  504. if ((data[0] & 0x1fc00000) >> 22 == opcodes_2d[opcode].opcode) {
  505. unsigned int i;
  506. len = 1;
  507. instr_out(ctx, 0, "%s\n",
  508. opcodes_2d[opcode].name);
  509. if (opcodes_2d[opcode].max_len > 1) {
  510. len = (data[0] & 0x000000ff) + 2;
  511. if (len < opcodes_2d[opcode].min_len ||
  512. len > opcodes_2d[opcode].max_len) {
  513. fprintf(out, "Bad count in %s\n",
  514. opcodes_2d[opcode].name);
  515. }
  516. }
  517. for (i = 1; i < len; i++) {
  518. instr_out(ctx, i, "dword %d\n", i);
  519. }
  520. return len;
  521. }
  522. }
  523. instr_out(ctx, 0, "2D UNKNOWN\n");
  524. return 1;
  525. }
  526. static int
  527. decode_3d_1c(struct drm_intel_decode *ctx)
  528. {
  529. uint32_t *data = ctx->data;
  530. uint32_t opcode;
  531. opcode = (data[0] & 0x00f80000) >> 19;
  532. switch (opcode) {
  533. case 0x11:
  534. instr_out(ctx, 0,
  535. "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
  536. return 1;
  537. case 0x10:
  538. instr_out(ctx, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
  539. data[0] & 1 ? "enabled" : "disabled");
  540. return 1;
  541. case 0x01:
  542. instr_out(ctx, 0, "3DSTATE_MAP_COORD_SET_I830\n");
  543. return 1;
  544. case 0x0a:
  545. instr_out(ctx, 0, "3DSTATE_MAP_CUBE_I830\n");
  546. return 1;
  547. case 0x05:
  548. instr_out(ctx, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
  549. return 1;
  550. }
  551. instr_out(ctx, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
  552. opcode);
  553. return 1;
  554. }
  555. /** Sets the string dstname to describe the destination of the PS instruction */
  556. static void
  557. i915_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
  558. {
  559. uint32_t a0 = data[i];
  560. int dst_nr = (a0 >> 14) & 0xf;
  561. char dstmask[8];
  562. const char *sat;
  563. if (do_mask) {
  564. if (((a0 >> 10) & 0xf) == 0xf) {
  565. dstmask[0] = 0;
  566. } else {
  567. int dstmask_index = 0;
  568. dstmask[dstmask_index++] = '.';
  569. if (a0 & (1 << 10))
  570. dstmask[dstmask_index++] = 'x';
  571. if (a0 & (1 << 11))
  572. dstmask[dstmask_index++] = 'y';
  573. if (a0 & (1 << 12))
  574. dstmask[dstmask_index++] = 'z';
  575. if (a0 & (1 << 13))
  576. dstmask[dstmask_index++] = 'w';
  577. dstmask[dstmask_index++] = 0;
  578. }
  579. if (a0 & (1 << 22))
  580. sat = ".sat";
  581. else
  582. sat = "";
  583. } else {
  584. dstmask[0] = 0;
  585. sat = "";
  586. }
  587. switch ((a0 >> 19) & 0x7) {
  588. case 0:
  589. if (dst_nr > 15)
  590. fprintf(out, "bad destination reg R%d\n", dst_nr);
  591. sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
  592. break;
  593. case 4:
  594. if (dst_nr > 0)
  595. fprintf(out, "bad destination reg oC%d\n", dst_nr);
  596. sprintf(dstname, "oC%s%s", dstmask, sat);
  597. break;
  598. case 5:
  599. if (dst_nr > 0)
  600. fprintf(out, "bad destination reg oD%d\n", dst_nr);
  601. sprintf(dstname, "oD%s%s", dstmask, sat);
  602. break;
  603. case 6:
  604. if (dst_nr > 3)
  605. fprintf(out, "bad destination reg U%d\n", dst_nr);
  606. sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
  607. break;
  608. default:
  609. sprintf(dstname, "RESERVED");
  610. break;
  611. }
  612. }
  613. static const char *
  614. i915_get_channel_swizzle(uint32_t select)
  615. {
  616. switch (select & 0x7) {
  617. case 0:
  618. return (select & 8) ? "-x" : "x";
  619. case 1:
  620. return (select & 8) ? "-y" : "y";
  621. case 2:
  622. return (select & 8) ? "-z" : "z";
  623. case 3:
  624. return (select & 8) ? "-w" : "w";
  625. case 4:
  626. return (select & 8) ? "-0" : "0";
  627. case 5:
  628. return (select & 8) ? "-1" : "1";
  629. default:
  630. return (select & 8) ? "-bad" : "bad";
  631. }
  632. }
  633. static void
  634. i915_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
  635. {
  636. switch (src_type) {
  637. case 0:
  638. sprintf(name, "R%d", src_nr);
  639. if (src_nr > 15)
  640. fprintf(out, "bad src reg %s\n", name);
  641. break;
  642. case 1:
  643. if (src_nr < 8)
  644. sprintf(name, "T%d", src_nr);
  645. else if (src_nr == 8)
  646. sprintf(name, "DIFFUSE");
  647. else if (src_nr == 9)
  648. sprintf(name, "SPECULAR");
  649. else if (src_nr == 10)
  650. sprintf(name, "FOG");
  651. else {
  652. fprintf(out, "bad src reg T%d\n", src_nr);
  653. sprintf(name, "RESERVED");
  654. }
  655. break;
  656. case 2:
  657. sprintf(name, "C%d", src_nr);
  658. if (src_nr > 31)
  659. fprintf(out, "bad src reg %s\n", name);
  660. break;
  661. case 4:
  662. sprintf(name, "oC");
  663. if (src_nr > 0)
  664. fprintf(out, "bad src reg oC%d\n", src_nr);
  665. break;
  666. case 5:
  667. sprintf(name, "oD");
  668. if (src_nr > 0)
  669. fprintf(out, "bad src reg oD%d\n", src_nr);
  670. break;
  671. case 6:
  672. sprintf(name, "U%d", src_nr);
  673. if (src_nr > 3)
  674. fprintf(out, "bad src reg %s\n", name);
  675. break;
  676. default:
  677. fprintf(out, "bad src reg type %d\n", src_type);
  678. sprintf(name, "RESERVED");
  679. break;
  680. }
  681. }
  682. static void i915_get_instruction_src0(uint32_t *data, int i, char *srcname)
  683. {
  684. uint32_t a0 = data[i];
  685. uint32_t a1 = data[i + 1];
  686. int src_nr = (a0 >> 2) & 0x1f;
  687. const char *swizzle_x = i915_get_channel_swizzle((a1 >> 28) & 0xf);
  688. const char *swizzle_y = i915_get_channel_swizzle((a1 >> 24) & 0xf);
  689. const char *swizzle_z = i915_get_channel_swizzle((a1 >> 20) & 0xf);
  690. const char *swizzle_w = i915_get_channel_swizzle((a1 >> 16) & 0xf);
  691. char swizzle[100];
  692. i915_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
  693. sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
  694. swizzle_w);
  695. if (strcmp(swizzle, ".xyzw") != 0)
  696. strcat(srcname, swizzle);
  697. }
  698. static void i915_get_instruction_src1(uint32_t *data, int i, char *srcname)
  699. {
  700. uint32_t a1 = data[i + 1];
  701. uint32_t a2 = data[i + 2];
  702. int src_nr = (a1 >> 8) & 0x1f;
  703. const char *swizzle_x = i915_get_channel_swizzle((a1 >> 4) & 0xf);
  704. const char *swizzle_y = i915_get_channel_swizzle((a1 >> 0) & 0xf);
  705. const char *swizzle_z = i915_get_channel_swizzle((a2 >> 28) & 0xf);
  706. const char *swizzle_w = i915_get_channel_swizzle((a2 >> 24) & 0xf);
  707. char swizzle[100];
  708. i915_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
  709. sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
  710. swizzle_w);
  711. if (strcmp(swizzle, ".xyzw") != 0)
  712. strcat(srcname, swizzle);
  713. }
  714. static void i915_get_instruction_src2(uint32_t *data, int i, char *srcname)
  715. {
  716. uint32_t a2 = data[i + 2];
  717. int src_nr = (a2 >> 16) & 0x1f;
  718. const char *swizzle_x = i915_get_channel_swizzle((a2 >> 12) & 0xf);
  719. const char *swizzle_y = i915_get_channel_swizzle((a2 >> 8) & 0xf);
  720. const char *swizzle_z = i915_get_channel_swizzle((a2 >> 4) & 0xf);
  721. const char *swizzle_w = i915_get_channel_swizzle((a2 >> 0) & 0xf);
  722. char swizzle[100];
  723. i915_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
  724. sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z,
  725. swizzle_w);
  726. if (strcmp(swizzle, ".xyzw") != 0)
  727. strcat(srcname, swizzle);
  728. }
  729. static void
  730. i915_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
  731. {
  732. switch (src_type) {
  733. case 0:
  734. sprintf(name, "R%d", src_nr);
  735. if (src_nr > 15)
  736. fprintf(out, "bad src reg %s\n", name);
  737. break;
  738. case 1:
  739. if (src_nr < 8)
  740. sprintf(name, "T%d", src_nr);
  741. else if (src_nr == 8)
  742. sprintf(name, "DIFFUSE");
  743. else if (src_nr == 9)
  744. sprintf(name, "SPECULAR");
  745. else if (src_nr == 10)
  746. sprintf(name, "FOG");
  747. else {
  748. fprintf(out, "bad src reg T%d\n", src_nr);
  749. sprintf(name, "RESERVED");
  750. }
  751. break;
  752. case 4:
  753. sprintf(name, "oC");
  754. if (src_nr > 0)
  755. fprintf(out, "bad src reg oC%d\n", src_nr);
  756. break;
  757. case 5:
  758. sprintf(name, "oD");
  759. if (src_nr > 0)
  760. fprintf(out, "bad src reg oD%d\n", src_nr);
  761. break;
  762. default:
  763. fprintf(out, "bad src reg type %d\n", src_type);
  764. sprintf(name, "RESERVED");
  765. break;
  766. }
  767. }
  768. static void
  769. i915_decode_alu1(struct drm_intel_decode *ctx,
  770. int i, char *instr_prefix, const char *op_name)
  771. {
  772. char dst[100], src0[100];
  773. i915_get_instruction_dst(ctx->data, i, dst, 1);
  774. i915_get_instruction_src0(ctx->data, i, src0);
  775. instr_out(ctx, i++, "%s: %s %s, %s\n", instr_prefix,
  776. op_name, dst, src0);
  777. instr_out(ctx, i++, "%s\n", instr_prefix);
  778. instr_out(ctx, i++, "%s\n", instr_prefix);
  779. }
  780. static void
  781. i915_decode_alu2(struct drm_intel_decode *ctx,
  782. int i, char *instr_prefix, const char *op_name)
  783. {
  784. char dst[100], src0[100], src1[100];
  785. i915_get_instruction_dst(ctx->data, i, dst, 1);
  786. i915_get_instruction_src0(ctx->data, i, src0);
  787. i915_get_instruction_src1(ctx->data, i, src1);
  788. instr_out(ctx, i++, "%s: %s %s, %s, %s\n", instr_prefix,
  789. op_name, dst, src0, src1);
  790. instr_out(ctx, i++, "%s\n", instr_prefix);
  791. instr_out(ctx, i++, "%s\n", instr_prefix);
  792. }
  793. static void
  794. i915_decode_alu3(struct drm_intel_decode *ctx,
  795. int i, char *instr_prefix, const char *op_name)
  796. {
  797. char dst[100], src0[100], src1[100], src2[100];
  798. i915_get_instruction_dst(ctx->data, i, dst, 1);
  799. i915_get_instruction_src0(ctx->data, i, src0);
  800. i915_get_instruction_src1(ctx->data, i, src1);
  801. i915_get_instruction_src2(ctx->data, i, src2);
  802. instr_out(ctx, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
  803. op_name, dst, src0, src1, src2);
  804. instr_out(ctx, i++, "%s\n", instr_prefix);
  805. instr_out(ctx, i++, "%s\n", instr_prefix);
  806. }
  807. static void
  808. i915_decode_tex(struct drm_intel_decode *ctx, int i,
  809. const char *instr_prefix, const char *tex_name)
  810. {
  811. uint32_t t0 = ctx->data[i];
  812. uint32_t t1 = ctx->data[i + 1];
  813. char dst_name[100];
  814. char addr_name[100];
  815. int sampler_nr;
  816. i915_get_instruction_dst(ctx->data, i, dst_name, 0);
  817. i915_get_instruction_addr((t1 >> 24) & 0x7,
  818. (t1 >> 17) & 0xf, addr_name);
  819. sampler_nr = t0 & 0xf;
  820. instr_out(ctx, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
  821. tex_name, dst_name, sampler_nr, addr_name);
  822. instr_out(ctx, i++, "%s\n", instr_prefix);
  823. instr_out(ctx, i++, "%s\n", instr_prefix);
  824. }
  825. static void
  826. i915_decode_dcl(struct drm_intel_decode *ctx, int i, char *instr_prefix)
  827. {
  828. uint32_t d0 = ctx->data[i];
  829. const char *sampletype;
  830. int dcl_nr = (d0 >> 14) & 0xf;
  831. const char *dcl_x = d0 & (1 << 10) ? "x" : "";
  832. const char *dcl_y = d0 & (1 << 11) ? "y" : "";
  833. const char *dcl_z = d0 & (1 << 12) ? "z" : "";
  834. const char *dcl_w = d0 & (1 << 13) ? "w" : "";
  835. char dcl_mask[10];
  836. switch ((d0 >> 19) & 0x3) {
  837. case 1:
  838. sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
  839. if (strcmp(dcl_mask, ".") == 0)
  840. fprintf(out, "bad (empty) dcl mask\n");
  841. if (dcl_nr > 10)
  842. fprintf(out, "bad T%d dcl register number\n", dcl_nr);
  843. if (dcl_nr < 8) {
  844. if (strcmp(dcl_mask, ".x") != 0 &&
  845. strcmp(dcl_mask, ".xy") != 0 &&
  846. strcmp(dcl_mask, ".xz") != 0 &&
  847. strcmp(dcl_mask, ".w") != 0 &&
  848. strcmp(dcl_mask, ".xyzw") != 0) {
  849. fprintf(out, "bad T%d.%s dcl mask\n", dcl_nr,
  850. dcl_mask);
  851. }
  852. instr_out(ctx, i++, "%s: DCL T%d%s\n",
  853. instr_prefix, dcl_nr, dcl_mask);
  854. } else {
  855. if (strcmp(dcl_mask, ".xz") == 0)
  856. fprintf(out, "errataed bad dcl mask %s\n",
  857. dcl_mask);
  858. else if (strcmp(dcl_mask, ".xw") == 0)
  859. fprintf(out, "errataed bad dcl mask %s\n",
  860. dcl_mask);
  861. else if (strcmp(dcl_mask, ".xzw") == 0)
  862. fprintf(out, "errataed bad dcl mask %s\n",
  863. dcl_mask);
  864. if (dcl_nr == 8) {
  865. instr_out(ctx, i++,
  866. "%s: DCL DIFFUSE%s\n", instr_prefix,
  867. dcl_mask);
  868. } else if (dcl_nr == 9) {
  869. instr_out(ctx, i++,
  870. "%s: DCL SPECULAR%s\n", instr_prefix,
  871. dcl_mask);
  872. } else if (dcl_nr == 10) {
  873. instr_out(ctx, i++,
  874. "%s: DCL FOG%s\n", instr_prefix,
  875. dcl_mask);
  876. }
  877. }
  878. instr_out(ctx, i++, "%s\n", instr_prefix);
  879. instr_out(ctx, i++, "%s\n", instr_prefix);
  880. break;
  881. case 3:
  882. switch ((d0 >> 22) & 0x3) {
  883. case 0:
  884. sampletype = "2D";
  885. break;
  886. case 1:
  887. sampletype = "CUBE";
  888. break;
  889. case 2:
  890. sampletype = "3D";
  891. break;
  892. default:
  893. sampletype = "RESERVED";
  894. break;
  895. }
  896. if (dcl_nr > 15)
  897. fprintf(out, "bad S%d dcl register number\n", dcl_nr);
  898. instr_out(ctx, i++, "%s: DCL S%d %s\n",
  899. instr_prefix, dcl_nr, sampletype);
  900. instr_out(ctx, i++, "%s\n", instr_prefix);
  901. instr_out(ctx, i++, "%s\n", instr_prefix);
  902. break;
  903. default:
  904. instr_out(ctx, i++, "%s: DCL RESERVED%d\n",
  905. instr_prefix, dcl_nr);
  906. instr_out(ctx, i++, "%s\n", instr_prefix);
  907. instr_out(ctx, i++, "%s\n", instr_prefix);
  908. }
  909. }
  910. static void
  911. i915_decode_instruction(struct drm_intel_decode *ctx,
  912. int i, char *instr_prefix)
  913. {
  914. switch ((ctx->data[i] >> 24) & 0x1f) {
  915. case 0x0:
  916. instr_out(ctx, i++, "%s: NOP\n", instr_prefix);
  917. instr_out(ctx, i++, "%s\n", instr_prefix);
  918. instr_out(ctx, i++, "%s\n", instr_prefix);
  919. break;
  920. case 0x01:
  921. i915_decode_alu2(ctx, i, instr_prefix, "ADD");
  922. break;
  923. case 0x02:
  924. i915_decode_alu1(ctx, i, instr_prefix, "MOV");
  925. break;
  926. case 0x03:
  927. i915_decode_alu2(ctx, i, instr_prefix, "MUL");
  928. break;
  929. case 0x04:
  930. i915_decode_alu3(ctx, i, instr_prefix, "MAD");
  931. break;
  932. case 0x05:
  933. i915_decode_alu3(ctx, i, instr_prefix, "DP2ADD");
  934. break;
  935. case 0x06:
  936. i915_decode_alu2(ctx, i, instr_prefix, "DP3");
  937. break;
  938. case 0x07:
  939. i915_decode_alu2(ctx, i, instr_prefix, "DP4");
  940. break;
  941. case 0x08:
  942. i915_decode_alu1(ctx, i, instr_prefix, "FRC");
  943. break;
  944. case 0x09:
  945. i915_decode_alu1(ctx, i, instr_prefix, "RCP");
  946. break;
  947. case 0x0a:
  948. i915_decode_alu1(ctx, i, instr_prefix, "RSQ");
  949. break;
  950. case 0x0b:
  951. i915_decode_alu1(ctx, i, instr_prefix, "EXP");
  952. break;
  953. case 0x0c:
  954. i915_decode_alu1(ctx, i, instr_prefix, "LOG");
  955. break;
  956. case 0x0d:
  957. i915_decode_alu2(ctx, i, instr_prefix, "CMP");
  958. break;
  959. case 0x0e:
  960. i915_decode_alu2(ctx, i, instr_prefix, "MIN");
  961. break;
  962. case 0x0f:
  963. i915_decode_alu2(ctx, i, instr_prefix, "MAX");
  964. break;
  965. case 0x10:
  966. i915_decode_alu1(ctx, i, instr_prefix, "FLR");
  967. break;
  968. case 0x11:
  969. i915_decode_alu1(ctx, i, instr_prefix, "MOD");
  970. break;
  971. case 0x12:
  972. i915_decode_alu1(ctx, i, instr_prefix, "TRC");
  973. break;
  974. case 0x13:
  975. i915_decode_alu2(ctx, i, instr_prefix, "SGE");
  976. break;
  977. case 0x14:
  978. i915_decode_alu2(ctx, i, instr_prefix, "SLT");
  979. break;
  980. case 0x15:
  981. i915_decode_tex(ctx, i, instr_prefix, "TEXLD");
  982. break;
  983. case 0x16:
  984. i915_decode_tex(ctx, i, instr_prefix, "TEXLDP");
  985. break;
  986. case 0x17:
  987. i915_decode_tex(ctx, i, instr_prefix, "TEXLDB");
  988. break;
  989. case 0x19:
  990. i915_decode_dcl(ctx, i, instr_prefix);
  991. break;
  992. default:
  993. instr_out(ctx, i++, "%s: unknown\n", instr_prefix);
  994. instr_out(ctx, i++, "%s\n", instr_prefix);
  995. instr_out(ctx, i++, "%s\n", instr_prefix);
  996. break;
  997. }
  998. }
  999. static const char *
  1000. decode_compare_func(uint32_t op)
  1001. {
  1002. switch (op & 0x7) {
  1003. case 0:
  1004. return "always";
  1005. case 1:
  1006. return "never";
  1007. case 2:
  1008. return "less";
  1009. case 3:
  1010. return "equal";
  1011. case 4:
  1012. return "lequal";
  1013. case 5:
  1014. return "greater";
  1015. case 6:
  1016. return "notequal";
  1017. case 7:
  1018. return "gequal";
  1019. }
  1020. return "";
  1021. }
  1022. static const char *
  1023. decode_stencil_op(uint32_t op)
  1024. {
  1025. switch (op & 0x7) {
  1026. case 0:
  1027. return "keep";
  1028. case 1:
  1029. return "zero";
  1030. case 2:
  1031. return "replace";
  1032. case 3:
  1033. return "incr_sat";
  1034. case 4:
  1035. return "decr_sat";
  1036. case 5:
  1037. return "greater";
  1038. case 6:
  1039. return "incr";
  1040. case 7:
  1041. return "decr";
  1042. }
  1043. return "";
  1044. }
  1045. #if 0
  1046. static const char *
  1047. decode_logic_op(uint32_t op)
  1048. {
  1049. switch (op & 0xf) {
  1050. case 0:
  1051. return "clear";
  1052. case 1:
  1053. return "nor";
  1054. case 2:
  1055. return "and_inv";
  1056. case 3:
  1057. return "copy_inv";
  1058. case 4:
  1059. return "and_rvrse";
  1060. case 5:
  1061. return "inv";
  1062. case 6:
  1063. return "xor";
  1064. case 7:
  1065. return "nand";
  1066. case 8:
  1067. return "and";
  1068. case 9:
  1069. return "equiv";
  1070. case 10:
  1071. return "noop";
  1072. case 11:
  1073. return "or_inv";
  1074. case 12:
  1075. return "copy";
  1076. case 13:
  1077. return "or_rvrse";
  1078. case 14:
  1079. return "or";
  1080. case 15:
  1081. return "set";
  1082. }
  1083. return "";
  1084. }
  1085. #endif
  1086. static const char *
  1087. decode_blend_fact(uint32_t op)
  1088. {
  1089. switch (op & 0xf) {
  1090. case 1:
  1091. return "zero";
  1092. case 2:
  1093. return "one";
  1094. case 3:
  1095. return "src_colr";
  1096. case 4:
  1097. return "inv_src_colr";
  1098. case 5:
  1099. return "src_alpha";
  1100. case 6:
  1101. return "inv_src_alpha";
  1102. case 7:
  1103. return "dst_alpha";
  1104. case 8:
  1105. return "inv_dst_alpha";
  1106. case 9:
  1107. return "dst_colr";
  1108. case 10:
  1109. return "inv_dst_colr";
  1110. case 11:
  1111. return "src_alpha_sat";
  1112. case 12:
  1113. return "cnst_colr";
  1114. case 13:
  1115. return "inv_cnst_colr";
  1116. case 14:
  1117. return "cnst_alpha";
  1118. case 15:
  1119. return "inv_const_alpha";
  1120. }
  1121. return "";
  1122. }
  1123. static const char *
  1124. decode_tex_coord_mode(uint32_t mode)
  1125. {
  1126. switch (mode & 0x7) {
  1127. case 0:
  1128. return "wrap";
  1129. case 1:
  1130. return "mirror";
  1131. case 2:
  1132. return "clamp_edge";
  1133. case 3:
  1134. return "cube";
  1135. case 4:
  1136. return "clamp_border";
  1137. case 5:
  1138. return "mirror_once";
  1139. }
  1140. return "";
  1141. }
  1142. static const char *
  1143. decode_sample_filter(uint32_t mode)
  1144. {
  1145. switch (mode & 0x7) {
  1146. case 0:
  1147. return "nearest";
  1148. case 1:
  1149. return "linear";
  1150. case 2:
  1151. return "anisotropic";
  1152. case 3:
  1153. return "4x4_1";
  1154. case 4:
  1155. return "4x4_2";
  1156. case 5:
  1157. return "4x4_flat";
  1158. case 6:
  1159. return "6x5_mono";
  1160. }
  1161. return "";
  1162. }
  1163. static int
  1164. decode_3d_1d(struct drm_intel_decode *ctx)
  1165. {
  1166. unsigned int len, i, c, idx, word, map, sampler, instr;
  1167. const char *format, *zformat, *type;
  1168. uint32_t opcode;
  1169. uint32_t *data = ctx->data;
  1170. uint32_t devid = ctx->devid;
  1171. struct {
  1172. uint32_t opcode;
  1173. int i830_only;
  1174. unsigned int min_len;
  1175. unsigned int max_len;
  1176. const char *name;
  1177. } opcodes_3d_1d[] = {
  1178. { 0x86, 0, 4, 4, "3DSTATE_CHROMA_KEY" },
  1179. { 0x88, 0, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
  1180. { 0x99, 0, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
  1181. { 0x9a, 0, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
  1182. { 0x98, 0, 2, 2, "3DSTATE_DEFAULT_Z" },
  1183. { 0x97, 0, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
  1184. { 0x9d, 0, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
  1185. { 0x9e, 0, 4, 4, "3DSTATE_MONO_FILTER" },
  1186. { 0x89, 0, 4, 4, "3DSTATE_FOG_MODE" },
  1187. { 0x8f, 0, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
  1188. { 0x83, 0, 2, 2, "3DSTATE_SPAN_STIPPLE" },
  1189. { 0x8c, 1, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM_I830" },
  1190. { 0x8b, 1, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM_I830" },
  1191. { 0x8d, 1, 3, 3, "3DSTATE_W_STATE_I830" },
  1192. { 0x01, 1, 2, 2, "3DSTATE_COLOR_FACTOR_I830" },
  1193. { 0x02, 1, 2, 2, "3DSTATE_MAP_COORD_SETBIND_I830"},
  1194. }, *opcode_3d_1d;
  1195. opcode = (data[0] & 0x00ff0000) >> 16;
  1196. switch (opcode) {
  1197. case 0x07:
  1198. /* This instruction is unusual. A 0 length means just
  1199. * 1 DWORD instead of 2. The 0 length is specified in
  1200. * one place to be unsupported, but stated to be
  1201. * required in another, and 0 length LOAD_INDIRECTs
  1202. * appear to cause no harm at least.
  1203. */
  1204. instr_out(ctx, 0, "3DSTATE_LOAD_INDIRECT\n");
  1205. len = (data[0] & 0x000000ff) + 1;
  1206. i = 1;
  1207. if (data[0] & (0x01 << 8)) {
  1208. instr_out(ctx, i++, "SIS.0\n");
  1209. instr_out(ctx, i++, "SIS.1\n");
  1210. }
  1211. if (data[0] & (0x02 << 8)) {
  1212. instr_out(ctx, i++, "DIS.0\n");
  1213. }
  1214. if (data[0] & (0x04 << 8)) {
  1215. instr_out(ctx, i++, "SSB.0\n");
  1216. instr_out(ctx, i++, "SSB.1\n");
  1217. }
  1218. if (data[0] & (0x08 << 8)) {
  1219. instr_out(ctx, i++, "MSB.0\n");
  1220. instr_out(ctx, i++, "MSB.1\n");
  1221. }
  1222. if (data[0] & (0x10 << 8)) {
  1223. instr_out(ctx, i++, "PSP.0\n");
  1224. instr_out(ctx, i++, "PSP.1\n");
  1225. }
  1226. if (data[0] & (0x20 << 8)) {
  1227. instr_out(ctx, i++, "PSC.0\n");
  1228. instr_out(ctx, i++, "PSC.1\n");
  1229. }
  1230. if (len != i) {
  1231. fprintf(out, "Bad count in 3DSTATE_LOAD_INDIRECT\n");
  1232. return len;
  1233. }
  1234. return len;
  1235. case 0x04:
  1236. instr_out(ctx, 0,
  1237. "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
  1238. len = (data[0] & 0x0000000f) + 2;
  1239. i = 1;
  1240. for (word = 0; word <= 8; word++) {
  1241. if (data[0] & (1 << (4 + word))) {
  1242. /* save vertex state for decode */
  1243. if (!IS_GEN2(devid)) {
  1244. int tex_num;
  1245. if (word == 2) {
  1246. saved_s2_set = 1;
  1247. saved_s2 = data[i];
  1248. }
  1249. if (word == 4) {
  1250. saved_s4_set = 1;
  1251. saved_s4 = data[i];
  1252. }
  1253. switch (word) {
  1254. case 0:
  1255. instr_out(ctx, i,
  1256. "S0: vbo offset: 0x%08x%s\n",
  1257. data[i] & (~1),
  1258. data[i] & 1 ?
  1259. ", auto cache invalidate disabled"
  1260. : "");
  1261. break;
  1262. case 1:
  1263. instr_out(ctx, i,
  1264. "S1: vertex width: %i, vertex pitch: %i\n",
  1265. (data[i] >> 24) &
  1266. 0x3f,
  1267. (data[i] >> 16) &
  1268. 0x3f);
  1269. break;
  1270. case 2:
  1271. instr_out(ctx, i,
  1272. "S2: texcoord formats: ");
  1273. for (tex_num = 0;
  1274. tex_num < 8; tex_num++) {
  1275. switch ((data[i] >>
  1276. tex_num *
  1277. 4) & 0xf) {
  1278. case 0:
  1279. fprintf(out,
  1280. "%i=2D ",
  1281. tex_num);
  1282. break;
  1283. case 1:
  1284. fprintf(out,
  1285. "%i=3D ",
  1286. tex_num);
  1287. break;
  1288. case 2:
  1289. fprintf(out,
  1290. "%i=4D ",
  1291. tex_num);
  1292. break;
  1293. case 3:
  1294. fprintf(out,
  1295. "%i=1D ",
  1296. tex_num);
  1297. break;
  1298. case 4:
  1299. fprintf(out,
  1300. "%i=2D_16 ",
  1301. tex_num);
  1302. break;
  1303. case 5:
  1304. fprintf(out,
  1305. "%i=4D_16 ",
  1306. tex_num);
  1307. break;
  1308. case 0xf:
  1309. fprintf(out,
  1310. "%i=NP ",
  1311. tex_num);
  1312. break;
  1313. }
  1314. }
  1315. fprintf(out, "\n");
  1316. break;
  1317. case 3:
  1318. instr_out(ctx, i,
  1319. "S3: not documented\n");
  1320. break;
  1321. case 4:
  1322. {
  1323. const char *cullmode = "";
  1324. const char *vfmt_xyzw = "";
  1325. switch ((data[i] >> 13)
  1326. & 0x3) {
  1327. case 0:
  1328. cullmode =
  1329. "both";
  1330. break;
  1331. case 1:
  1332. cullmode =
  1333. "none";
  1334. break;
  1335. case 2:
  1336. cullmode = "cw";
  1337. break;
  1338. case 3:
  1339. cullmode =
  1340. "ccw";
  1341. break;
  1342. }
  1343. switch (data[i] &
  1344. (7 << 6 | 1 <<
  1345. 2)) {
  1346. case 1 << 6:
  1347. vfmt_xyzw =
  1348. "XYZ,";
  1349. break;
  1350. case 2 << 6:
  1351. vfmt_xyzw =
  1352. "XYZW,";
  1353. break;
  1354. case 3 << 6:
  1355. vfmt_xyzw =
  1356. "XY,";
  1357. break;
  1358. case 4 << 6:
  1359. vfmt_xyzw =
  1360. "XYW,";
  1361. break;
  1362. case 1 << 6 | 1 << 2:
  1363. vfmt_xyzw =
  1364. "XYZF,";
  1365. break;
  1366. case 2 << 6 | 1 << 2:
  1367. vfmt_xyzw =
  1368. "XYZWF,";
  1369. break;
  1370. case 3 << 6 | 1 << 2:
  1371. vfmt_xyzw =
  1372. "XYF,";
  1373. break;
  1374. case 4 << 6 | 1 << 2:
  1375. vfmt_xyzw =
  1376. "XYWF,";
  1377. break;
  1378. }
  1379. instr_out(ctx, i,
  1380. "S4: point_width=%i, line_width=%.1f,"
  1381. "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s "
  1382. "%s%s%s%s%s\n",
  1383. (data[i] >>
  1384. 23) & 0x1ff,
  1385. ((data[i] >>
  1386. 19) & 0xf) /
  1387. 2.0,
  1388. data[i] & (0xf
  1389. <<
  1390. 15)
  1391. ?
  1392. " flatshade="
  1393. : "",
  1394. data[i] & (1
  1395. <<
  1396. 18)
  1397. ? "Alpha," :
  1398. "",
  1399. data[i] & (1
  1400. <<
  1401. 17)
  1402. ? "Fog," : "",
  1403. data[i] & (1
  1404. <<
  1405. 16)
  1406. ? "Specular,"
  1407. : "",
  1408. data[i] & (1
  1409. <<
  1410. 15)
  1411. ? "Color," :
  1412. "", cullmode,
  1413. data[i] & (1
  1414. <<
  1415. 12)
  1416. ?
  1417. "PointWidth,"
  1418. : "",
  1419. data[i] & (1
  1420. <<
  1421. 11)
  1422. ? "SpecFog," :
  1423. "",
  1424. data[i] & (1
  1425. <<
  1426. 10)
  1427. ? "Color," :
  1428. "",
  1429. data[i] & (1
  1430. <<
  1431. 9)
  1432. ? "DepthOfs,"
  1433. : "",
  1434. vfmt_xyzw,
  1435. data[i] & (1
  1436. <<
  1437. 9)
  1438. ? "FogParam,"
  1439. : "",
  1440. data[i] & (1
  1441. <<
  1442. 5)
  1443. ?
  1444. "force default diffuse, "
  1445. : "",
  1446. data[i] & (1
  1447. <<
  1448. 4)
  1449. ?
  1450. "force default specular, "
  1451. : "",
  1452. data[i] & (1
  1453. <<
  1454. 3)
  1455. ?
  1456. "local depth ofs enable, "
  1457. : "",
  1458. data[i] & (1
  1459. <<
  1460. 1)
  1461. ?
  1462. "point sprite enable, "
  1463. : "",
  1464. data[i] & (1
  1465. <<
  1466. 0)
  1467. ?
  1468. "line AA enable, "
  1469. : "");
  1470. break;
  1471. }
  1472. case 5:
  1473. {
  1474. instr_out(ctx, i,
  1475. "S5:%s%s%s%s%s"
  1476. "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
  1477. "stencil_fail=%s, stencil_pass_z_fail=%s, "
  1478. "stencil_pass_z_pass=%s, %s%s%s%s\n",
  1479. data[i] & (0xf
  1480. <<
  1481. 28)
  1482. ?
  1483. " write_disable="
  1484. : "",
  1485. data[i] & (1
  1486. <<
  1487. 31)
  1488. ? "Alpha," :
  1489. "",
  1490. data[i] & (1
  1491. <<
  1492. 30)
  1493. ? "Red," : "",
  1494. data[i] & (1
  1495. <<
  1496. 29)
  1497. ? "Green," :
  1498. "",
  1499. data[i] & (1
  1500. <<
  1501. 28)
  1502. ? "Blue," :
  1503. "",
  1504. data[i] & (1
  1505. <<
  1506. 27)
  1507. ?
  1508. " force default point size,"
  1509. : "",
  1510. data[i] & (1
  1511. <<
  1512. 26)
  1513. ?
  1514. " last pixel enable,"
  1515. : "",
  1516. data[i] & (1
  1517. <<
  1518. 25)
  1519. ?
  1520. " global depth ofs enable,"
  1521. : "",
  1522. data[i] & (1
  1523. <<
  1524. 24)
  1525. ?
  1526. " fog enable,"
  1527. : "",
  1528. (data[i] >>
  1529. 16) & 0xff,
  1530. decode_compare_func
  1531. (data[i] >>
  1532. 13),
  1533. decode_stencil_op
  1534. (data[i] >>
  1535. 10),
  1536. decode_stencil_op
  1537. (data[i] >>
  1538. 7),
  1539. decode_stencil_op
  1540. (data[i] >>
  1541. 4),
  1542. data[i] & (1
  1543. <<
  1544. 3)
  1545. ?
  1546. "stencil write enable, "
  1547. : "",
  1548. data[i] & (1
  1549. <<
  1550. 2)
  1551. ?
  1552. "stencil test enable, "
  1553. : "",
  1554. data[i] & (1
  1555. <<
  1556. 1)
  1557. ?
  1558. "color dither enable, "
  1559. : "",
  1560. data[i] & (1
  1561. <<
  1562. 0)
  1563. ?
  1564. "logicop enable, "
  1565. : "");
  1566. }
  1567. break;
  1568. case 6:
  1569. instr_out(ctx, i,
  1570. "S6: %salpha_test=%s, alpha_ref=0x%x, "
  1571. "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
  1572. "%s%stristrip_provoking_vertex=%i\n",
  1573. data[i] & (1 << 31) ?
  1574. "alpha test enable, "
  1575. : "",
  1576. decode_compare_func
  1577. (data[i] >> 28),
  1578. data[i] & (0xff <<
  1579. 20),
  1580. decode_compare_func
  1581. (data[i] >> 16),
  1582. data[i] & (1 << 15) ?
  1583. "cbuf blend enable, "
  1584. : "",
  1585. decode_blend_fact(data
  1586. [i]
  1587. >>
  1588. 8),
  1589. decode_blend_fact(data
  1590. [i]
  1591. >>
  1592. 4),
  1593. data[i] & (1 << 3) ?
  1594. "depth write enable, "
  1595. : "",
  1596. data[i] & (1 << 2) ?
  1597. "cbuf write enable, "
  1598. : "",
  1599. data[i] & (0x3));
  1600. break;
  1601. case 7:
  1602. instr_out(ctx, i,
  1603. "S7: depth offset constant: 0x%08x\n",
  1604. data[i]);
  1605. break;
  1606. }
  1607. } else {
  1608. instr_out(ctx, i,
  1609. "S%d: 0x%08x\n", word, data[i]);
  1610. }
  1611. i++;
  1612. }
  1613. }
  1614. if (len != i) {
  1615. fprintf(out,
  1616. "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
  1617. }
  1618. return len;
  1619. case 0x03:
  1620. instr_out(ctx, 0,
  1621. "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
  1622. len = (data[0] & 0x0000000f) + 2;
  1623. i = 1;
  1624. for (word = 6; word <= 14; word++) {
  1625. if (data[0] & (1 << word)) {
  1626. if (word == 6)
  1627. instr_out(ctx, i++,
  1628. "TBCF\n");
  1629. else if (word >= 7 && word <= 10) {
  1630. instr_out(ctx, i++,
  1631. "TB%dC\n", word - 7);
  1632. instr_out(ctx, i++,
  1633. "TB%dA\n", word - 7);
  1634. } else if (word >= 11 && word <= 14) {
  1635. instr_out(ctx, i,
  1636. "TM%dS0: offset=0x%08x, %s\n",
  1637. word - 11,
  1638. data[i] & 0xfffffffe,
  1639. data[i] & 1 ? "use fence" :
  1640. "");
  1641. i++;
  1642. instr_out(ctx, i,
  1643. "TM%dS1: height=%i, width=%i, %s\n",
  1644. word - 11, data[i] >> 21,
  1645. (data[i] >> 10) & 0x3ff,
  1646. data[i] & 2 ? (data[i] & 1 ?
  1647. "y-tiled" :
  1648. "x-tiled") :
  1649. "");
  1650. i++;
  1651. instr_out(ctx, i,
  1652. "TM%dS2: pitch=%i, \n",
  1653. word - 11,
  1654. ((data[i] >> 21) + 1) * 4);
  1655. i++;
  1656. instr_out(ctx, i++,
  1657. "TM%dS3\n", word - 11);
  1658. instr_out(ctx, i++,
  1659. "TM%dS4: dflt color\n",
  1660. word - 11);
  1661. }
  1662. }
  1663. }
  1664. if (len != i) {
  1665. fprintf(out,
  1666. "Bad count in 3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
  1667. }
  1668. return len;
  1669. case 0x00:
  1670. instr_out(ctx, 0, "3DSTATE_MAP_STATE\n");
  1671. len = (data[0] & 0x0000003f) + 2;
  1672. instr_out(ctx, 1, "mask\n");
  1673. i = 2;
  1674. for (map = 0; map <= 15; map++) {
  1675. if (data[1] & (1 << map)) {
  1676. int width, height, pitch, dword;
  1677. const char *tiling;
  1678. dword = data[i];
  1679. instr_out(ctx, i++,
  1680. "map %d MS2 %s%s%s\n", map,
  1681. dword & (1 << 31) ?
  1682. "untrusted surface, " : "",
  1683. dword & (1 << 1) ?
  1684. "vertical line stride enable, " : "",
  1685. dword & (1 << 0) ?
  1686. "vertical ofs enable, " : "");
  1687. dword = data[i];
  1688. width = ((dword >> 10) & ((1 << 11) - 1)) + 1;
  1689. height = ((dword >> 21) & ((1 << 11) - 1)) + 1;
  1690. tiling = "none";
  1691. if (dword & (1 << 2))
  1692. tiling = "fenced";
  1693. else if (dword & (1 << 1))
  1694. tiling = dword & (1 << 0) ? "Y" : "X";
  1695. type = " BAD";
  1696. format = "BAD";
  1697. switch ((dword >> 7) & 0x7) {
  1698. case 1:
  1699. type = "8b";
  1700. switch ((dword >> 3) & 0xf) {
  1701. case 0:
  1702. format = "I";
  1703. break;
  1704. case 1:
  1705. format = "L";
  1706. break;
  1707. case 4:
  1708. format = "A";
  1709. break;
  1710. case 5:
  1711. format = " mono";
  1712. break;
  1713. }
  1714. break;
  1715. case 2:
  1716. type = "16b";
  1717. switch ((dword >> 3) & 0xf) {
  1718. case 0:
  1719. format = " rgb565";
  1720. break;
  1721. case 1:
  1722. format = " argb1555";
  1723. break;
  1724. case 2:
  1725. format = " argb4444";
  1726. break;
  1727. case 5:
  1728. format = " ay88";
  1729. break;
  1730. case 6:
  1731. format = " bump655";
  1732. break;
  1733. case 7:
  1734. format = "I";
  1735. break;
  1736. case 8:
  1737. format = "L";
  1738. break;
  1739. case 9:
  1740. format = "A";
  1741. break;
  1742. }
  1743. break;
  1744. case 3:
  1745. type = "32b";
  1746. switch ((dword >> 3) & 0xf) {
  1747. case 0:
  1748. format = " argb8888";
  1749. break;
  1750. case 1:
  1751. format = " abgr8888";
  1752. break;
  1753. case 2:
  1754. format = " xrgb8888";
  1755. break;
  1756. case 3:
  1757. format = " xbgr8888";
  1758. break;
  1759. case 4:
  1760. format = " qwvu8888";
  1761. break;
  1762. case 5:
  1763. format = " axvu8888";
  1764. break;
  1765. case 6:
  1766. format = " lxvu8888";
  1767. break;
  1768. case 7:
  1769. format = " xlvu8888";
  1770. break;
  1771. case 8:
  1772. format = " argb2101010";
  1773. break;
  1774. case 9:
  1775. format = " abgr2101010";
  1776. break;
  1777. case 10:
  1778. format = " awvu2101010";
  1779. break;
  1780. case 11:
  1781. format = " gr1616";
  1782. break;
  1783. case 12:
  1784. format = " vu1616";
  1785. break;
  1786. case 13:
  1787. format = " xI824";
  1788. break;
  1789. case 14:
  1790. format = " xA824";
  1791. break;
  1792. case 15:
  1793. format = " xL824";
  1794. break;
  1795. }
  1796. break;
  1797. case 5:
  1798. type = "422";
  1799. switch ((dword >> 3) & 0xf) {
  1800. case 0:
  1801. format = " yuv_swapy";
  1802. break;
  1803. case 1:
  1804. format = " yuv";
  1805. break;
  1806. case 2:
  1807. format = " yuv_swapuv";
  1808. break;
  1809. case 3:
  1810. format = " yuv_swapuvy";
  1811. break;
  1812. }
  1813. break;
  1814. case 6:
  1815. type = "compressed";
  1816. switch ((dword >> 3) & 0x7) {
  1817. case 0:
  1818. format = " dxt1";
  1819. break;
  1820. case 1:
  1821. format = " dxt2_3";
  1822. break;
  1823. case 2:
  1824. format = " dxt4_5";
  1825. break;
  1826. case 3:
  1827. format = " fxt1";
  1828. break;
  1829. case 4:
  1830. format = " dxt1_rb";
  1831. break;
  1832. }
  1833. break;
  1834. case 7:
  1835. type = "4b indexed";
  1836. switch ((dword >> 3) & 0xf) {
  1837. case 7:
  1838. format = " argb8888";
  1839. break;
  1840. }
  1841. break;
  1842. }
  1843. dword = data[i];
  1844. instr_out(ctx, i++,
  1845. "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
  1846. map, width, height, type, format,
  1847. tiling,
  1848. dword & (1 << 9) ? " palette select" :
  1849. "");
  1850. dword = data[i];
  1851. pitch =
  1852. 4 * (((dword >> 21) & ((1 << 11) - 1)) + 1);
  1853. instr_out(ctx, i++,
  1854. "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
  1855. map, pitch, (dword >> 9) & 0x3f,
  1856. dword & 0xff, (dword >> 15) & 0x3f,
  1857. dword & (1 << 8) ? "miplayout legacy"
  1858. : "miplayout right");
  1859. }
  1860. }
  1861. if (len != i) {
  1862. fprintf(out, "Bad count in 3DSTATE_MAP_STATE\n");
  1863. return len;
  1864. }
  1865. return len;
  1866. case 0x06:
  1867. instr_out(ctx, 0,
  1868. "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
  1869. len = (data[0] & 0x000000ff) + 2;
  1870. i = 2;
  1871. for (c = 0; c <= 31; c++) {
  1872. if (data[1] & (1 << c)) {
  1873. instr_out(ctx, i, "C%d.X = %f\n", c,
  1874. int_as_float(data[i]));
  1875. i++;
  1876. instr_out(ctx, i, "C%d.Y = %f\n",
  1877. c, int_as_float(data[i]));
  1878. i++;
  1879. instr_out(ctx, i, "C%d.Z = %f\n",
  1880. c, int_as_float(data[i]));
  1881. i++;
  1882. instr_out(ctx, i, "C%d.W = %f\n",
  1883. c, int_as_float(data[i]));
  1884. i++;
  1885. }
  1886. }
  1887. if (len != i) {
  1888. fprintf(out,
  1889. "Bad count in 3DSTATE_PIXEL_SHADER_CONSTANTS\n");
  1890. }
  1891. return len;
  1892. case 0x05:
  1893. instr_out(ctx, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
  1894. len = (data[0] & 0x000000ff) + 2;
  1895. if ((len - 1) % 3 != 0 || len > 370) {
  1896. fprintf(out,
  1897. "Bad count in 3DSTATE_PIXEL_SHADER_PROGRAM\n");
  1898. }
  1899. i = 1;
  1900. for (instr = 0; instr < (len - 1) / 3; instr++) {
  1901. char instr_prefix[10];
  1902. sprintf(instr_prefix, "PS%03d", instr);
  1903. i915_decode_instruction(ctx, i,
  1904. instr_prefix);
  1905. i += 3;
  1906. }
  1907. return len;
  1908. case 0x01:
  1909. if (IS_GEN2(devid))
  1910. break;
  1911. instr_out(ctx, 0, "3DSTATE_SAMPLER_STATE\n");
  1912. instr_out(ctx, 1, "mask\n");
  1913. len = (data[0] & 0x0000003f) + 2;
  1914. i = 2;
  1915. for (sampler = 0; sampler <= 15; sampler++) {
  1916. if (data[1] & (1 << sampler)) {
  1917. uint32_t dword;
  1918. const char *mip_filter = "";
  1919. dword = data[i];
  1920. switch ((dword >> 20) & 0x3) {
  1921. case 0:
  1922. mip_filter = "none";
  1923. break;
  1924. case 1:
  1925. mip_filter = "nearest";
  1926. break;
  1927. case 3:
  1928. mip_filter = "linear";
  1929. break;
  1930. }
  1931. instr_out(ctx, i++,
  1932. "sampler %d SS2:%s%s%s "
  1933. "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
  1934. "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n",
  1935. sampler,
  1936. dword & (1 << 31) ? " reverse gamma,"
  1937. : "",
  1938. dword & (1 << 30) ? " packed2planar,"
  1939. : "",
  1940. dword & (1 << 29) ?
  1941. " colorspace conversion," : "",
  1942. (dword >> 22) & 0x1f, mip_filter,
  1943. decode_sample_filter(dword >> 17),
  1944. decode_sample_filter(dword >> 14),
  1945. ((dword >> 5) & 0x1ff) / (0x10 * 1.0),
  1946. dword & (1 << 4) ? " shadow," : "",
  1947. dword & (1 << 3) ? 4 : 2,
  1948. decode_compare_func(dword));
  1949. dword = data[i];
  1950. instr_out(ctx, i++,
  1951. "sampler %d SS3: min_lod=%.2f,%s "
  1952. "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
  1953. sampler,
  1954. ((dword >> 24) & 0xff) / (0x10 * 1.0),
  1955. dword & (1 << 17) ?
  1956. " kill pixel enable," : "",
  1957. decode_tex_coord_mode(dword >> 12),
  1958. decode_tex_coord_mode(dword >> 9),
  1959. decode_tex_coord_mode(dword >> 6),
  1960. dword & (1 << 5) ?
  1961. " normalized coords," : "",
  1962. (dword >> 1) & 0xf,
  1963. dword & (1 << 0) ? " deinterlacer," :
  1964. "");
  1965. dword = data[i];
  1966. instr_out(ctx, i++,
  1967. "sampler %d SS4: border color\n",
  1968. sampler);
  1969. }
  1970. }
  1971. if (len != i) {
  1972. fprintf(out, "Bad count in 3DSTATE_SAMPLER_STATE\n");
  1973. }
  1974. return len;
  1975. case 0x85:
  1976. len = (data[0] & 0x0000000f) + 2;
  1977. if (len != 2)
  1978. fprintf(out,
  1979. "Bad count in 3DSTATE_DEST_BUFFER_VARIABLES\n");
  1980. instr_out(ctx, 0,
  1981. "3DSTATE_DEST_BUFFER_VARIABLES\n");
  1982. switch ((data[1] >> 8) & 0xf) {
  1983. case 0x0:
  1984. format = "g8";
  1985. break;
  1986. case 0x1:
  1987. format = "x1r5g5b5";
  1988. break;
  1989. case 0x2:
  1990. format = "r5g6b5";
  1991. break;
  1992. case 0x3:
  1993. format = "a8r8g8b8";
  1994. break;
  1995. case 0x4:
  1996. format = "ycrcb_swapy";
  1997. break;
  1998. case 0x5:
  1999. format = "ycrcb_normal";
  2000. break;
  2001. case 0x6:
  2002. format = "ycrcb_swapuv";
  2003. break;
  2004. case 0x7:
  2005. format = "ycrcb_swapuvy";
  2006. break;
  2007. case 0x8:
  2008. format = "a4r4g4b4";
  2009. break;
  2010. case 0x9:
  2011. format = "a1r5g5b5";
  2012. break;
  2013. case 0xa:
  2014. format = "a2r10g10b10";
  2015. break;
  2016. default:
  2017. format = "BAD";
  2018. break;
  2019. }
  2020. switch ((data[1] >> 2) & 0x3) {
  2021. case 0x0:
  2022. zformat = "u16";
  2023. break;
  2024. case 0x1:
  2025. zformat = "f16";
  2026. break;
  2027. case 0x2:
  2028. zformat = "u24x8";
  2029. break;
  2030. default:
  2031. zformat = "BAD";
  2032. break;
  2033. }
  2034. instr_out(ctx, 1,
  2035. "%s format, %s depth format, early Z %sabled\n",
  2036. format, zformat,
  2037. (data[1] & (1 << 31)) ? "en" : "dis");
  2038. return len;
  2039. case 0x8e:
  2040. {
  2041. const char *name, *tiling;
  2042. len = (data[0] & 0x0000000f) + 2;
  2043. if (len != 3)
  2044. fprintf(out,
  2045. "Bad count in 3DSTATE_BUFFER_INFO\n");
  2046. switch ((data[1] >> 24) & 0x7) {
  2047. case 0x3:
  2048. name = "color";
  2049. break;
  2050. case 0x7:
  2051. name = "depth";
  2052. break;
  2053. default:
  2054. name = "unknown";
  2055. break;
  2056. }
  2057. tiling = "none";
  2058. if (data[1] & (1 << 23))
  2059. tiling = "fenced";
  2060. else if (data[1] & (1 << 22))
  2061. tiling = data[1] & (1 << 21) ? "Y" : "X";
  2062. instr_out(ctx, 0, "3DSTATE_BUFFER_INFO\n");
  2063. instr_out(ctx, 1,
  2064. "%s, tiling = %s, pitch=%d\n", name, tiling,
  2065. data[1] & 0xffff);
  2066. instr_out(ctx, 2, "address\n");
  2067. return len;
  2068. }
  2069. case 0x81:
  2070. len = (data[0] & 0x0000000f) + 2;
  2071. if (len != 3)
  2072. fprintf(out,
  2073. "Bad count in 3DSTATE_SCISSOR_RECTANGLE\n");
  2074. instr_out(ctx, 0, "3DSTATE_SCISSOR_RECTANGLE\n");
  2075. instr_out(ctx, 1, "(%d,%d)\n",
  2076. data[1] & 0xffff, data[1] >> 16);
  2077. instr_out(ctx, 2, "(%d,%d)\n",
  2078. data[2] & 0xffff, data[2] >> 16);
  2079. return len;
  2080. case 0x80:
  2081. len = (data[0] & 0x0000000f) + 2;
  2082. if (len != 5)
  2083. fprintf(out,
  2084. "Bad count in 3DSTATE_DRAWING_RECTANGLE\n");
  2085. instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
  2086. instr_out(ctx, 1, "%s\n",
  2087. data[1] & (1 << 30) ? "depth ofs disabled " : "");
  2088. instr_out(ctx, 2, "(%d,%d)\n",
  2089. data[2] & 0xffff, data[2] >> 16);
  2090. instr_out(ctx, 3, "(%d,%d)\n",
  2091. data[3] & 0xffff, data[3] >> 16);
  2092. instr_out(ctx, 4, "(%d,%d)\n",
  2093. data[4] & 0xffff, data[4] >> 16);
  2094. return len;
  2095. case 0x9c:
  2096. len = (data[0] & 0x0000000f) + 2;
  2097. if (len != 7)
  2098. fprintf(out, "Bad count in 3DSTATE_CLEAR_PARAMETERS\n");
  2099. instr_out(ctx, 0, "3DSTATE_CLEAR_PARAMETERS\n");
  2100. instr_out(ctx, 1, "prim_type=%s, clear=%s%s%s\n",
  2101. data[1] & (1 << 16) ? "CLEAR_RECT" : "ZONE_INIT",
  2102. data[1] & (1 << 2) ? "color," : "",
  2103. data[1] & (1 << 1) ? "depth," : "",
  2104. data[1] & (1 << 0) ? "stencil," : "");
  2105. instr_out(ctx, 2, "clear color\n");
  2106. instr_out(ctx, 3, "clear depth/stencil\n");
  2107. instr_out(ctx, 4, "color value (rgba8888)\n");
  2108. instr_out(ctx, 5, "depth value %f\n",
  2109. int_as_float(data[5]));
  2110. instr_out(ctx, 6, "clear stencil\n");
  2111. return len;
  2112. }
  2113. for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
  2114. opcode_3d_1d = &opcodes_3d_1d[idx];
  2115. if (opcode_3d_1d->i830_only && !IS_GEN2(devid))
  2116. continue;
  2117. if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
  2118. len = 1;
  2119. instr_out(ctx, 0, "%s\n",
  2120. opcode_3d_1d->name);
  2121. if (opcode_3d_1d->max_len > 1) {
  2122. len = (data[0] & 0x0000ffff) + 2;
  2123. if (len < opcode_3d_1d->min_len ||
  2124. len > opcode_3d_1d->max_len) {
  2125. fprintf(out, "Bad count in %s\n",
  2126. opcode_3d_1d->name);
  2127. }
  2128. }
  2129. for (i = 1; i < len; i++) {
  2130. instr_out(ctx, i, "dword %d\n", i);
  2131. }
  2132. return len;
  2133. }
  2134. }
  2135. instr_out(ctx, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n",
  2136. opcode);
  2137. return 1;
  2138. }
  2139. static int
  2140. decode_3d_primitive(struct drm_intel_decode *ctx)
  2141. {
  2142. uint32_t *data = ctx->data;
  2143. uint32_t count = ctx->count;
  2144. char immediate = (data[0] & (1 << 23)) == 0;
  2145. unsigned int len, i, j, ret;
  2146. const char *primtype;
  2147. int original_s2 = saved_s2;
  2148. int original_s4 = saved_s4;
  2149. switch ((data[0] >> 18) & 0xf) {
  2150. case 0x0:
  2151. primtype = "TRILIST";
  2152. break;
  2153. case 0x1:
  2154. primtype = "TRISTRIP";
  2155. break;
  2156. case 0x2:
  2157. primtype = "TRISTRIP_REVERSE";
  2158. break;
  2159. case 0x3:
  2160. primtype = "TRIFAN";
  2161. break;
  2162. case 0x4:
  2163. primtype = "POLYGON";
  2164. break;
  2165. case 0x5:
  2166. primtype = "LINELIST";
  2167. break;
  2168. case 0x6:
  2169. primtype = "LINESTRIP";
  2170. break;
  2171. case 0x7:
  2172. primtype = "RECTLIST";
  2173. break;
  2174. case 0x8:
  2175. primtype = "POINTLIST";
  2176. break;
  2177. case 0x9:
  2178. primtype = "DIB";
  2179. break;
  2180. case 0xa:
  2181. primtype = "CLEAR_RECT";
  2182. saved_s4 = 3 << 6;
  2183. saved_s2 = ~0;
  2184. break;
  2185. default:
  2186. primtype = "unknown";
  2187. break;
  2188. }
  2189. /* XXX: 3DPRIM_DIB not supported */
  2190. if (immediate) {
  2191. len = (data[0] & 0x0003ffff) + 2;
  2192. instr_out(ctx, 0, "3DPRIMITIVE inline %s\n",
  2193. primtype);
  2194. if (count < len)
  2195. BUFFER_FAIL(count, len, "3DPRIMITIVE inline");
  2196. if (!saved_s2_set || !saved_s4_set) {
  2197. fprintf(out, "unknown vertex format\n");
  2198. for (i = 1; i < len; i++) {
  2199. instr_out(ctx, i,
  2200. " vertex data (%f float)\n",
  2201. int_as_float(data[i]));
  2202. }
  2203. } else {
  2204. unsigned int vertex = 0;
  2205. for (i = 1; i < len;) {
  2206. unsigned int tc;
  2207. #define VERTEX_OUT(fmt, ...) do { \
  2208. if (i < len) \
  2209. instr_out(ctx, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
  2210. else \
  2211. fprintf(out, " missing data in V%d\n", vertex); \
  2212. i++; \
  2213. } while (0)
  2214. VERTEX_OUT("X = %f", int_as_float(data[i]));
  2215. VERTEX_OUT("Y = %f", int_as_float(data[i]));
  2216. switch (saved_s4 >> 6 & 0x7) {
  2217. case 0x1:
  2218. VERTEX_OUT("Z = %f",
  2219. int_as_float(data[i]));
  2220. break;
  2221. case 0x2:
  2222. VERTEX_OUT("Z = %f",
  2223. int_as_float(data[i]));
  2224. VERTEX_OUT("W = %f",
  2225. int_as_float(data[i]));
  2226. break;
  2227. case 0x3:
  2228. break;
  2229. case 0x4:
  2230. VERTEX_OUT("W = %f",
  2231. int_as_float(data[i]));
  2232. break;
  2233. default:
  2234. fprintf(out, "bad S4 position mask\n");
  2235. }
  2236. if (saved_s4 & (1 << 10)) {
  2237. VERTEX_OUT
  2238. ("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
  2239. "B=0x%02x)", data[i] >> 24,
  2240. (data[i] >> 16) & 0xff,
  2241. (data[i] >> 8) & 0xff,
  2242. data[i] & 0xff);
  2243. }
  2244. if (saved_s4 & (1 << 11)) {
  2245. VERTEX_OUT
  2246. ("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
  2247. "B=0x%02x)", data[i] >> 24,
  2248. (data[i] >> 16) & 0xff,
  2249. (data[i] >> 8) & 0xff,
  2250. data[i] & 0xff);
  2251. }
  2252. if (saved_s4 & (1 << 12))
  2253. VERTEX_OUT("width = 0x%08x)", data[i]);
  2254. for (tc = 0; tc <= 7; tc++) {
  2255. switch ((saved_s2 >> (tc * 4)) & 0xf) {
  2256. case 0x0:
  2257. VERTEX_OUT("T%d.X = %f", tc,
  2258. int_as_float(data
  2259. [i]));
  2260. VERTEX_OUT("T%d.Y = %f", tc,
  2261. int_as_float(data
  2262. [i]));
  2263. break;
  2264. case 0x1:
  2265. VERTEX_OUT("T%d.X = %f", tc,
  2266. int_as_float(data
  2267. [i]));
  2268. VERTEX_OUT("T%d.Y = %f", tc,
  2269. int_as_float(data
  2270. [i]));
  2271. VERTEX_OUT("T%d.Z = %f", tc,
  2272. int_as_float(data
  2273. [i]));
  2274. break;
  2275. case 0x2:
  2276. VERTEX_OUT("T%d.X = %f", tc,
  2277. int_as_float(data
  2278. [i]));
  2279. VERTEX_OUT("T%d.Y = %f", tc,
  2280. int_as_float(data
  2281. [i]));
  2282. VERTEX_OUT("T%d.Z = %f", tc,
  2283. int_as_float(data
  2284. [i]));
  2285. VERTEX_OUT("T%d.W = %f", tc,
  2286. int_as_float(data
  2287. [i]));
  2288. break;
  2289. case 0x3:
  2290. VERTEX_OUT("T%d.X = %f", tc,
  2291. int_as_float(data
  2292. [i]));
  2293. break;
  2294. case 0x4:
  2295. VERTEX_OUT
  2296. ("T%d.XY = 0x%08x half-float",
  2297. tc, data[i]);
  2298. break;
  2299. case 0x5:
  2300. VERTEX_OUT
  2301. ("T%d.XY = 0x%08x half-float",
  2302. tc, data[i]);
  2303. VERTEX_OUT
  2304. ("T%d.ZW = 0x%08x half-float",
  2305. tc, data[i]);
  2306. break;
  2307. case 0xf:
  2308. break;
  2309. default:
  2310. fprintf(out,
  2311. "bad S2.T%d format\n",
  2312. tc);
  2313. }
  2314. }
  2315. vertex++;
  2316. }
  2317. }
  2318. ret = len;
  2319. } else {
  2320. /* indirect vertices */
  2321. len = data[0] & 0x0000ffff; /* index count */
  2322. if (data[0] & (1 << 17)) {
  2323. /* random vertex access */
  2324. if (count < (len + 1) / 2 + 1) {
  2325. BUFFER_FAIL(count, (len + 1) / 2 + 1,
  2326. "3DPRIMITIVE random indirect");
  2327. }
  2328. instr_out(ctx, 0,
  2329. "3DPRIMITIVE random indirect %s (%d)\n",
  2330. primtype, len);
  2331. if (len == 0) {
  2332. /* vertex indices continue until 0xffff is
  2333. * found
  2334. */
  2335. for (i = 1; i < count; i++) {
  2336. if ((data[i] & 0xffff) == 0xffff) {
  2337. instr_out(ctx, i,
  2338. " indices: (terminator)\n");
  2339. ret = i;
  2340. goto out;
  2341. } else if ((data[i] >> 16) == 0xffff) {
  2342. instr_out(ctx, i,
  2343. " indices: 0x%04x, (terminator)\n",
  2344. data[i] & 0xffff);
  2345. ret = i;
  2346. goto out;
  2347. } else {
  2348. instr_out(ctx, i,
  2349. " indices: 0x%04x, 0x%04x\n",
  2350. data[i] & 0xffff,
  2351. data[i] >> 16);
  2352. }
  2353. }
  2354. fprintf(out,
  2355. "3DPRIMITIVE: no terminator found in index buffer\n");
  2356. ret = count;
  2357. goto out;
  2358. } else {
  2359. /* fixed size vertex index buffer */
  2360. for (j = 1, i = 0; i < len; i += 2, j++) {
  2361. if (i * 2 == len - 1) {
  2362. instr_out(ctx, j,
  2363. " indices: 0x%04x\n",
  2364. data[j] & 0xffff);
  2365. } else {
  2366. instr_out(ctx, j,
  2367. " indices: 0x%04x, 0x%04x\n",
  2368. data[j] & 0xffff,
  2369. data[j] >> 16);
  2370. }
  2371. }
  2372. }
  2373. ret = (len + 1) / 2 + 1;
  2374. goto out;
  2375. } else {
  2376. /* sequential vertex access */
  2377. instr_out(ctx, 0,
  2378. "3DPRIMITIVE sequential indirect %s, %d starting from "
  2379. "%d\n", primtype, len, data[1] & 0xffff);
  2380. instr_out(ctx, 1, " start\n");
  2381. ret = 2;
  2382. goto out;
  2383. }
  2384. }
  2385. out:
  2386. saved_s2 = original_s2;
  2387. saved_s4 = original_s4;
  2388. return ret;
  2389. }
  2390. static int
  2391. decode_3d(struct drm_intel_decode *ctx)
  2392. {
  2393. uint32_t opcode;
  2394. unsigned int idx;
  2395. uint32_t *data = ctx->data;
  2396. struct {
  2397. uint32_t opcode;
  2398. unsigned int min_len;
  2399. unsigned int max_len;
  2400. const char *name;
  2401. } opcodes_3d[] = {
  2402. { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
  2403. { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
  2404. { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
  2405. { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
  2406. { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
  2407. { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
  2408. { 0x0d, 1, 1, "3DSTATE_MODES_4" },
  2409. { 0x0c, 1, 1, "3DSTATE_MODES_5" },
  2410. { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES"},
  2411. }, *opcode_3d;
  2412. opcode = (data[0] & 0x1f000000) >> 24;
  2413. switch (opcode) {
  2414. case 0x1f:
  2415. return decode_3d_primitive(ctx);
  2416. case 0x1d:
  2417. return decode_3d_1d(ctx);
  2418. case 0x1c:
  2419. return decode_3d_1c(ctx);
  2420. }
  2421. for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
  2422. opcode_3d = &opcodes_3d[idx];
  2423. if (opcode == opcode_3d->opcode) {
  2424. unsigned int len = 1, i;
  2425. instr_out(ctx, 0, "%s\n", opcode_3d->name);
  2426. if (opcode_3d->max_len > 1) {
  2427. len = (data[0] & 0xff) + 2;
  2428. if (len < opcode_3d->min_len ||
  2429. len > opcode_3d->max_len) {
  2430. fprintf(out, "Bad count in %s\n",
  2431. opcode_3d->name);
  2432. }
  2433. }
  2434. for (i = 1; i < len; i++) {
  2435. instr_out(ctx, i, "dword %d\n", i);
  2436. }
  2437. return len;
  2438. }
  2439. }
  2440. instr_out(ctx, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
  2441. return 1;
  2442. }
  2443. static const char *get_965_surfacetype(unsigned int surfacetype)
  2444. {
  2445. switch (surfacetype) {
  2446. case 0:
  2447. return "1D";
  2448. case 1:
  2449. return "2D";
  2450. case 2:
  2451. return "3D";
  2452. case 3:
  2453. return "CUBE";
  2454. case 4:
  2455. return "BUFFER";
  2456. case 7:
  2457. return "NULL";
  2458. default:
  2459. return "unknown";
  2460. }
  2461. }
  2462. static const char *get_965_depthformat(unsigned int depthformat)
  2463. {
  2464. switch (depthformat) {
  2465. case 0:
  2466. return "s8_z24float";
  2467. case 1:
  2468. return "z32float";
  2469. case 2:
  2470. return "z24s8";
  2471. case 5:
  2472. return "z16";
  2473. default:
  2474. return "unknown";
  2475. }
  2476. }
  2477. static const char *get_965_element_component(uint32_t data, int component)
  2478. {
  2479. uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
  2480. switch (component_control) {
  2481. case 0:
  2482. return "nostore";
  2483. case 1:
  2484. switch (component) {
  2485. case 0:
  2486. return "X";
  2487. case 1:
  2488. return "Y";
  2489. case 2:
  2490. return "Z";
  2491. case 3:
  2492. return "W";
  2493. default:
  2494. return "fail";
  2495. }
  2496. case 2:
  2497. return "0.0";
  2498. case 3:
  2499. return "1.0";
  2500. case 4:
  2501. return "0x1";
  2502. case 5:
  2503. return "VID";
  2504. default:
  2505. return "fail";
  2506. }
  2507. }
  2508. static const char *get_965_prim_type(uint32_t primtype)
  2509. {
  2510. switch (primtype) {
  2511. case 0x01:
  2512. return "point list";
  2513. case 0x02:
  2514. return "line list";
  2515. case 0x03:
  2516. return "line strip";
  2517. case 0x04:
  2518. return "tri list";
  2519. case 0x05:
  2520. return "tri strip";
  2521. case 0x06:
  2522. return "tri fan";
  2523. case 0x07:
  2524. return "quad list";
  2525. case 0x08:
  2526. return "quad strip";
  2527. case 0x09:
  2528. return "line list adj";
  2529. case 0x0a:
  2530. return "line strip adj";
  2531. case 0x0b:
  2532. return "tri list adj";
  2533. case 0x0c:
  2534. return "tri strip adj";
  2535. case 0x0d:
  2536. return "tri strip reverse";
  2537. case 0x0e:
  2538. return "polygon";
  2539. case 0x0f:
  2540. return "rect list";
  2541. case 0x10:
  2542. return "line loop";
  2543. case 0x11:
  2544. return "point list bf";
  2545. case 0x12:
  2546. return "line strip cont";
  2547. case 0x13:
  2548. return "line strip bf";
  2549. case 0x14:
  2550. return "line strip cont bf";
  2551. case 0x15:
  2552. return "tri fan no stipple";
  2553. default:
  2554. return "fail";
  2555. }
  2556. }
  2557. static int
  2558. i965_decode_urb_fence(struct drm_intel_decode *ctx, int len)
  2559. {
  2560. uint32_t vs_fence, clip_fence, gs_fence, sf_fence, vfe_fence, cs_fence;
  2561. uint32_t *data = ctx->data;
  2562. if (len != 3)
  2563. fprintf(out, "Bad count in URB_FENCE\n");
  2564. vs_fence = data[1] & 0x3ff;
  2565. gs_fence = (data[1] >> 10) & 0x3ff;
  2566. clip_fence = (data[1] >> 20) & 0x3ff;
  2567. sf_fence = data[2] & 0x3ff;
  2568. vfe_fence = (data[2] >> 10) & 0x3ff;
  2569. cs_fence = (data[2] >> 20) & 0x7ff;
  2570. instr_out(ctx, 0, "URB_FENCE: %s%s%s%s%s%s\n",
  2571. (data[0] >> 13) & 1 ? "cs " : "",
  2572. (data[0] >> 12) & 1 ? "vfe " : "",
  2573. (data[0] >> 11) & 1 ? "sf " : "",
  2574. (data[0] >> 10) & 1 ? "clip " : "",
  2575. (data[0] >> 9) & 1 ? "gs " : "",
  2576. (data[0] >> 8) & 1 ? "vs " : "");
  2577. instr_out(ctx, 1,
  2578. "vs fence: %d, clip_fence: %d, gs_fence: %d\n",
  2579. vs_fence, clip_fence, gs_fence);
  2580. instr_out(ctx, 2,
  2581. "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
  2582. sf_fence, vfe_fence, cs_fence);
  2583. if (gs_fence < vs_fence)
  2584. fprintf(out, "gs fence < vs fence!\n");
  2585. if (clip_fence < gs_fence)
  2586. fprintf(out, "clip fence < gs fence!\n");
  2587. if (sf_fence < clip_fence)
  2588. fprintf(out, "sf fence < clip fence!\n");
  2589. if (cs_fence < sf_fence)
  2590. fprintf(out, "cs fence < sf fence!\n");
  2591. return len;
  2592. }
  2593. static void
  2594. state_base_out(struct drm_intel_decode *ctx, unsigned int index,
  2595. const char *name)
  2596. {
  2597. if (ctx->data[index] & 1) {
  2598. instr_out(ctx, index,
  2599. "%s state base address 0x%08x\n", name,
  2600. ctx->data[index] & ~1);
  2601. } else {
  2602. instr_out(ctx, index, "%s state base not updated\n",
  2603. name);
  2604. }
  2605. }
  2606. static void
  2607. state_max_out(struct drm_intel_decode *ctx, unsigned int index,
  2608. const char *name)
  2609. {
  2610. if (ctx->data[index] & 1) {
  2611. if (ctx->data[index] == 1) {
  2612. instr_out(ctx, index,
  2613. "%s state upper bound disabled\n", name);
  2614. } else {
  2615. instr_out(ctx, index,
  2616. "%s state upper bound 0x%08x\n", name,
  2617. ctx->data[index] & ~1);
  2618. }
  2619. } else {
  2620. instr_out(ctx, index,
  2621. "%s state upper bound not updated\n", name);
  2622. }
  2623. }
  2624. static int
  2625. gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC(struct drm_intel_decode *ctx)
  2626. {
  2627. instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_CC\n");
  2628. instr_out(ctx, 1, "pointer to CC viewport\n");
  2629. return 2;
  2630. }
  2631. static int
  2632. gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP(struct drm_intel_decode *ctx)
  2633. {
  2634. instr_out(ctx, 0, "3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP\n");
  2635. instr_out(ctx, 1, "pointer to SF_CLIP viewport\n");
  2636. return 2;
  2637. }
  2638. static int
  2639. gen7_3DSTATE_BLEND_STATE_POINTERS(struct drm_intel_decode *ctx)
  2640. {
  2641. instr_out(ctx, 0, "3DSTATE_BLEND_STATE_POINTERS\n");
  2642. instr_out(ctx, 1, "pointer to BLEND_STATE at 0x%08x (%s)\n",
  2643. ctx->data[1] & ~1,
  2644. (ctx->data[1] & 1) ? "changed" : "unchanged");
  2645. return 2;
  2646. }
  2647. static int
  2648. gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS(struct drm_intel_decode *ctx)
  2649. {
  2650. instr_out(ctx, 0, "3DSTATE_DEPTH_STENCIL_STATE_POINTERS\n");
  2651. instr_out(ctx, 1,
  2652. "pointer to DEPTH_STENCIL_STATE at 0x%08x (%s)\n",
  2653. ctx->data[1] & ~1,
  2654. (ctx->data[1] & 1) ? "changed" : "unchanged");
  2655. return 2;
  2656. }
  2657. static int
  2658. gen7_3DSTATE_HIER_DEPTH_BUFFER(struct drm_intel_decode *ctx)
  2659. {
  2660. instr_out(ctx, 0, "3DSTATE_HIER_DEPTH_BUFFER\n");
  2661. instr_out(ctx, 1, "pitch %db\n",
  2662. (ctx->data[1] & 0x1ffff) + 1);
  2663. instr_out(ctx, 2, "pointer to HiZ buffer\n");
  2664. return 3;
  2665. }
  2666. static int
  2667. gen6_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
  2668. {
  2669. instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
  2670. instr_out(ctx, 1, "blend change %d\n", ctx->data[1] & 1);
  2671. instr_out(ctx, 2, "depth stencil change %d\n",
  2672. ctx->data[2] & 1);
  2673. instr_out(ctx, 3, "cc change %d\n", ctx->data[3] & 1);
  2674. return 4;
  2675. }
  2676. static int
  2677. gen7_3DSTATE_CC_STATE_POINTERS(struct drm_intel_decode *ctx)
  2678. {
  2679. instr_out(ctx, 0, "3DSTATE_CC_STATE_POINTERS\n");
  2680. instr_out(ctx, 1, "pointer to COLOR_CALC_STATE at 0x%08x "
  2681. "(%s)\n",
  2682. ctx->data[1] & ~1,
  2683. (ctx->data[1] & 1) ? "changed" : "unchanged");
  2684. return 2;
  2685. }
  2686. static int
  2687. gen7_3DSTATE_URB_unit(struct drm_intel_decode *ctx, const char *unit)
  2688. {
  2689. int start_kb = ((ctx->data[1] >> 25) & 0x3f) * 8;
  2690. /* the field is # of 512-bit rows - 1, we print bytes */
  2691. int entry_size = (((ctx->data[1] >> 16) & 0x1ff) + 1);
  2692. int nr_entries = ctx->data[1] & 0xffff;
  2693. instr_out(ctx, 0, "3DSTATE_URB_%s\n", unit);
  2694. instr_out(ctx, 1,
  2695. "%dKB start, size=%d 64B rows, nr_entries=%d, total size %dB\n",
  2696. start_kb, entry_size, nr_entries, nr_entries * 64 * entry_size);
  2697. return 2;
  2698. }
  2699. static int
  2700. gen7_3DSTATE_URB_VS(struct drm_intel_decode *ctx)
  2701. {
  2702. return gen7_3DSTATE_URB_unit(ctx, "VS");
  2703. }
  2704. static int
  2705. gen7_3DSTATE_URB_HS(struct drm_intel_decode *ctx)
  2706. {
  2707. return gen7_3DSTATE_URB_unit(ctx, "HS");
  2708. }
  2709. static int
  2710. gen7_3DSTATE_URB_DS(struct drm_intel_decode *ctx)
  2711. {
  2712. return gen7_3DSTATE_URB_unit(ctx, "DS");
  2713. }
  2714. static int
  2715. gen7_3DSTATE_URB_GS(struct drm_intel_decode *ctx)
  2716. {
  2717. return gen7_3DSTATE_URB_unit(ctx, "GS");
  2718. }
  2719. static int
  2720. gen7_3DSTATE_CONSTANT(struct drm_intel_decode *ctx, const char *unit)
  2721. {
  2722. int rlen[4];
  2723. rlen[0] = (ctx->data[1] >> 0) & 0xffff;
  2724. rlen[1] = (ctx->data[1] >> 16) & 0xffff;
  2725. rlen[2] = (ctx->data[2] >> 0) & 0xffff;
  2726. rlen[3] = (ctx->data[2] >> 16) & 0xffff;
  2727. instr_out(ctx, 0, "3DSTATE_CONSTANT_%s\n", unit);
  2728. instr_out(ctx, 1, "len 0 = %d, len 1 = %d\n", rlen[0], rlen[1]);
  2729. instr_out(ctx, 2, "len 2 = %d, len 3 = %d\n", rlen[2], rlen[3]);
  2730. instr_out(ctx, 3, "pointer to constbuf 0\n");
  2731. instr_out(ctx, 4, "pointer to constbuf 1\n");
  2732. instr_out(ctx, 5, "pointer to constbuf 2\n");
  2733. instr_out(ctx, 6, "pointer to constbuf 3\n");
  2734. return 7;
  2735. }
  2736. static int
  2737. gen7_3DSTATE_CONSTANT_VS(struct drm_intel_decode *ctx)
  2738. {
  2739. return gen7_3DSTATE_CONSTANT(ctx, "VS");
  2740. }
  2741. static int
  2742. gen7_3DSTATE_CONSTANT_GS(struct drm_intel_decode *ctx)
  2743. {
  2744. return gen7_3DSTATE_CONSTANT(ctx, "GS");
  2745. }
  2746. static int
  2747. gen7_3DSTATE_CONSTANT_PS(struct drm_intel_decode *ctx)
  2748. {
  2749. return gen7_3DSTATE_CONSTANT(ctx, "PS");
  2750. }
  2751. static int
  2752. gen7_3DSTATE_CONSTANT_DS(struct drm_intel_decode *ctx)
  2753. {
  2754. return gen7_3DSTATE_CONSTANT(ctx, "DS");
  2755. }
  2756. static int
  2757. gen7_3DSTATE_CONSTANT_HS(struct drm_intel_decode *ctx)
  2758. {
  2759. return gen7_3DSTATE_CONSTANT(ctx, "HS");
  2760. }
  2761. static int
  2762. gen6_3DSTATE_WM(struct drm_intel_decode *ctx)
  2763. {
  2764. instr_out(ctx, 0, "3DSTATE_WM\n");
  2765. instr_out(ctx, 1, "kernel start pointer 0\n");
  2766. instr_out(ctx, 2,
  2767. "SPF=%d, VME=%d, Sampler Count %d, "
  2768. "Binding table count %d\n",
  2769. (ctx->data[2] >> 31) & 1,
  2770. (ctx->data[2] >> 30) & 1,
  2771. (ctx->data[2] >> 27) & 7,
  2772. (ctx->data[2] >> 18) & 0xff);
  2773. instr_out(ctx, 3, "scratch offset\n");
  2774. instr_out(ctx, 4,
  2775. "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
  2776. "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
  2777. (ctx->data[4] & (1 << 30)) != 0,
  2778. (ctx->data[4] & (1 << 28)) != 0,
  2779. (ctx->data[4] & (1 << 27)) != 0,
  2780. (ctx->data[4] >> 16) & 0x7f,
  2781. (ctx->data[4] >> 8) & 0x7f,
  2782. (ctx->data[4] & 0x7f));
  2783. instr_out(ctx, 5,
  2784. "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
  2785. "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, "
  2786. "Dispatch32 %d, Dispatch16 %d, Dispatch8 %d\n",
  2787. ((ctx->data[5] >> 25) & 0x7f) + 1,
  2788. (ctx->data[5] & (1 << 22)) != 0,
  2789. (ctx->data[5] & (1 << 21)) != 0,
  2790. (ctx->data[5] & (1 << 20)) != 0,
  2791. (ctx->data[5] & (1 << 19)) != 0,
  2792. (ctx->data[5] & (1 << 8)) != 0,
  2793. (ctx->data[5] & (1 << 2)) != 0,
  2794. (ctx->data[5] & (1 << 1)) != 0,
  2795. (ctx->data[5] & (1 << 0)) != 0);
  2796. instr_out(ctx, 6,
  2797. "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
  2798. "Barycentric interp mode 0x%x, Point raster rule %d, "
  2799. "Multisample mode %d, "
  2800. "Multisample Dispatch mode %d\n",
  2801. (ctx->data[6] >> 20) & 0x3f,
  2802. (ctx->data[6] >> 18) & 3,
  2803. (ctx->data[6] >> 16) & 3,
  2804. (ctx->data[6] >> 10) & 0x3f,
  2805. (ctx->data[6] & (1 << 9)) != 0,
  2806. (ctx->data[6] >> 1) & 3,
  2807. (ctx->data[6] & 1));
  2808. instr_out(ctx, 7, "kernel start pointer 1\n");
  2809. instr_out(ctx, 8, "kernel start pointer 2\n");
  2810. return 9;
  2811. }
  2812. static int
  2813. gen7_3DSTATE_WM(struct drm_intel_decode *ctx)
  2814. {
  2815. const char *computed_depth = "";
  2816. const char *early_depth = "";
  2817. const char *zw_interp = "";
  2818. switch ((ctx->data[1] >> 23) & 0x3) {
  2819. case 0:
  2820. computed_depth = "";
  2821. break;
  2822. case 1:
  2823. computed_depth = "computed depth";
  2824. break;
  2825. case 2:
  2826. computed_depth = "computed depth >=";
  2827. break;
  2828. case 3:
  2829. computed_depth = "computed depth <=";
  2830. break;
  2831. }
  2832. switch ((ctx->data[1] >> 21) & 0x3) {
  2833. case 0:
  2834. early_depth = "";
  2835. break;
  2836. case 1:
  2837. early_depth = ", EDSC_PSEXEC";
  2838. break;
  2839. case 2:
  2840. early_depth = ", EDSC_PREPS";
  2841. break;
  2842. case 3:
  2843. early_depth = ", BAD EDSC";
  2844. break;
  2845. }
  2846. switch ((ctx->data[1] >> 17) & 0x3) {
  2847. case 0:
  2848. early_depth = "";
  2849. break;
  2850. case 1:
  2851. early_depth = ", BAD ZW interp";
  2852. break;
  2853. case 2:
  2854. early_depth = ", ZW centroid";
  2855. break;
  2856. case 3:
  2857. early_depth = ", ZW sample";
  2858. break;
  2859. }
  2860. instr_out(ctx, 0, "3DSTATE_WM\n");
  2861. instr_out(ctx, 1, "(%s%s%s%s%s%s)%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  2862. (ctx->data[1] & (1 << 11)) ? "PP " : "",
  2863. (ctx->data[1] & (1 << 12)) ? "PC " : "",
  2864. (ctx->data[1] & (1 << 13)) ? "PS " : "",
  2865. (ctx->data[1] & (1 << 14)) ? "NPP " : "",
  2866. (ctx->data[1] & (1 << 15)) ? "NPC " : "",
  2867. (ctx->data[1] & (1 << 16)) ? "NPS " : "",
  2868. (ctx->data[1] & (1 << 30)) ? ", depth clear" : "",
  2869. (ctx->data[1] & (1 << 29)) ? "" : ", disabled",
  2870. (ctx->data[1] & (1 << 28)) ? ", depth resolve" : "",
  2871. (ctx->data[1] & (1 << 27)) ? ", hiz resolve" : "",
  2872. (ctx->data[1] & (1 << 25)) ? ", kill" : "",
  2873. computed_depth,
  2874. early_depth,
  2875. zw_interp,
  2876. (ctx->data[1] & (1 << 20)) ? ", source depth" : "",
  2877. (ctx->data[1] & (1 << 19)) ? ", source W" : "",
  2878. (ctx->data[1] & (1 << 10)) ? ", coverage" : "",
  2879. (ctx->data[1] & (1 << 4)) ? ", poly stipple" : "",
  2880. (ctx->data[1] & (1 << 3)) ? ", line stipple" : "",
  2881. (ctx->data[1] & (1 << 2)) ? ", point UL" : ", point UR"
  2882. );
  2883. instr_out(ctx, 2, "MS\n");
  2884. return 3;
  2885. }
  2886. static int
  2887. gen4_3DPRIMITIVE(struct drm_intel_decode *ctx)
  2888. {
  2889. instr_out(ctx, 0,
  2890. "3DPRIMITIVE: %s %s\n",
  2891. get_965_prim_type((ctx->data[0] >> 10) & 0x1f),
  2892. (ctx->data[0] & (1 << 15)) ? "random" : "sequential");
  2893. instr_out(ctx, 1, "vertex count\n");
  2894. instr_out(ctx, 2, "start vertex\n");
  2895. instr_out(ctx, 3, "instance count\n");
  2896. instr_out(ctx, 4, "start instance\n");
  2897. instr_out(ctx, 5, "index bias\n");
  2898. return 6;
  2899. }
  2900. static int
  2901. gen7_3DPRIMITIVE(struct drm_intel_decode *ctx)
  2902. {
  2903. bool indirect = !!(ctx->data[0] & (1 << 10));
  2904. instr_out(ctx, 0,
  2905. "3DPRIMITIVE: %s%s\n",
  2906. indirect ? " indirect" : "",
  2907. (ctx->data[0] & (1 << 8)) ? " predicated" : "");
  2908. instr_out(ctx, 1, "%s %s\n",
  2909. get_965_prim_type(ctx->data[1] & 0x3f),
  2910. (ctx->data[1] & (1 << 8)) ? "random" : "sequential");
  2911. instr_out(ctx, 2, indirect ? "ignored" : "vertex count\n");
  2912. instr_out(ctx, 3, indirect ? "ignored" : "start vertex\n");
  2913. instr_out(ctx, 4, indirect ? "ignored" : "instance count\n");
  2914. instr_out(ctx, 5, indirect ? "ignored" : "start instance\n");
  2915. instr_out(ctx, 6, indirect ? "ignored" : "index bias\n");
  2916. return 7;
  2917. }
  2918. static int
  2919. decode_3d_965(struct drm_intel_decode *ctx)
  2920. {
  2921. uint32_t opcode;
  2922. unsigned int len;
  2923. unsigned int i, j, sba_len;
  2924. const char *desc1 = NULL;
  2925. uint32_t *data = ctx->data;
  2926. uint32_t devid = ctx->devid;
  2927. struct {
  2928. uint32_t opcode;
  2929. uint32_t len_mask;
  2930. int unsigned min_len;
  2931. int unsigned max_len;
  2932. const char *name;
  2933. int gen;
  2934. int (*func)(struct drm_intel_decode *ctx);
  2935. } opcodes_3d[] = {
  2936. { 0x6000, 0x00ff, 3, 3, "URB_FENCE" },
  2937. { 0x6001, 0xffff, 2, 2, "CS_URB_STATE" },
  2938. { 0x6002, 0x00ff, 2, 2, "CONSTANT_BUFFER" },
  2939. { 0x6101, 0xffff, 6, 10, "STATE_BASE_ADDRESS" },
  2940. { 0x6102, 0xffff, 2, 2, "STATE_SIP" },
  2941. { 0x6104, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
  2942. { 0x680b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
  2943. { 0x6904, 0xffff, 1, 1, "3DSTATE_PIPELINE_SELECT" },
  2944. { 0x7800, 0xffff, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
  2945. { 0x7801, 0x00ff, 4, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
  2946. { 0x7802, 0x00ff, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
  2947. { 0x7805, 0x00ff, 7, 7, "3DSTATE_DEPTH_BUFFER", 7 },
  2948. { 0x7805, 0x00ff, 3, 3, "3DSTATE_URB" },
  2949. { 0x7804, 0x00ff, 3, 3, "3DSTATE_CLEAR_PARAMS" },
  2950. { 0x7806, 0x00ff, 3, 3, "3DSTATE_STENCIL_BUFFER" },
  2951. { 0x790f, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 6 },
  2952. { 0x7807, 0x00ff, 3, 3, "3DSTATE_HIER_DEPTH_BUFFER", 7, gen7_3DSTATE_HIER_DEPTH_BUFFER },
  2953. { 0x7808, 0x00ff, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
  2954. { 0x7809, 0x00ff, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
  2955. { 0x780a, 0x00ff, 3, 3, "3DSTATE_INDEX_BUFFER" },
  2956. { 0x780b, 0xffff, 1, 1, "3DSTATE_VF_STATISTICS" },
  2957. { 0x780d, 0x00ff, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
  2958. { 0x780e, 0xffff, 4, 4, NULL, 6, gen6_3DSTATE_CC_STATE_POINTERS },
  2959. { 0x780e, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_CC_STATE_POINTERS },
  2960. { 0x780f, 0x00ff, 2, 2, "3DSTATE_SCISSOR_POINTERS" },
  2961. { 0x7810, 0x00ff, 6, 6, "3DSTATE_VS" },
  2962. { 0x7811, 0x00ff, 7, 7, "3DSTATE_GS" },
  2963. { 0x7812, 0x00ff, 4, 4, "3DSTATE_CLIP" },
  2964. { 0x7813, 0x00ff, 20, 20, "3DSTATE_SF", 6 },
  2965. { 0x7813, 0x00ff, 7, 7, "3DSTATE_SF", 7 },
  2966. { 0x7814, 0x00ff, 3, 3, "3DSTATE_WM", 7, gen7_3DSTATE_WM },
  2967. { 0x7814, 0x00ff, 9, 9, "3DSTATE_WM", 6, gen6_3DSTATE_WM },
  2968. { 0x7815, 0x00ff, 5, 5, "3DSTATE_CONSTANT_VS_STATE", 6 },
  2969. { 0x7815, 0x00ff, 7, 7, "3DSTATE_CONSTANT_VS", 7, gen7_3DSTATE_CONSTANT_VS },
  2970. { 0x7816, 0x00ff, 5, 5, "3DSTATE_CONSTANT_GS_STATE", 6 },
  2971. { 0x7816, 0x00ff, 7, 7, "3DSTATE_CONSTANT_GS", 7, gen7_3DSTATE_CONSTANT_GS },
  2972. { 0x7817, 0x00ff, 5, 5, "3DSTATE_CONSTANT_PS_STATE", 6 },
  2973. { 0x7817, 0x00ff, 7, 7, "3DSTATE_CONSTANT_PS", 7, gen7_3DSTATE_CONSTANT_PS },
  2974. { 0x7818, 0xffff, 2, 2, "3DSTATE_SAMPLE_MASK" },
  2975. { 0x7819, 0x00ff, 7, 7, "3DSTATE_CONSTANT_HS", 7, gen7_3DSTATE_CONSTANT_HS },
  2976. { 0x781a, 0x00ff, 7, 7, "3DSTATE_CONSTANT_DS", 7, gen7_3DSTATE_CONSTANT_DS },
  2977. { 0x781b, 0x00ff, 7, 7, "3DSTATE_HS" },
  2978. { 0x781c, 0x00ff, 4, 4, "3DSTATE_TE" },
  2979. { 0x781d, 0x00ff, 6, 6, "3DSTATE_DS" },
  2980. { 0x781e, 0x00ff, 3, 3, "3DSTATE_STREAMOUT" },
  2981. { 0x781f, 0x00ff, 14, 14, "3DSTATE_SBE" },
  2982. { 0x7820, 0x00ff, 8, 8, "3DSTATE_PS" },
  2983. { 0x7821, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP },
  2984. { 0x7823, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_VIEWPORT_STATE_POINTERS_CC },
  2985. { 0x7824, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_BLEND_STATE_POINTERS },
  2986. { 0x7825, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS },
  2987. { 0x7826, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_VS" },
  2988. { 0x7827, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_HS" },
  2989. { 0x7828, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_DS" },
  2990. { 0x7829, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_GS" },
  2991. { 0x782a, 0x00ff, 2, 2, "3DSTATE_BINDING_TABLE_POINTERS_PS" },
  2992. { 0x782b, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_VS" },
  2993. { 0x782c, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_HS" },
  2994. { 0x782d, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_DS" },
  2995. { 0x782e, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_GS" },
  2996. { 0x782f, 0x00ff, 2, 2, "3DSTATE_SAMPLER_STATE_POINTERS_PS" },
  2997. { 0x7830, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_VS },
  2998. { 0x7831, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_HS },
  2999. { 0x7832, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_DS },
  3000. { 0x7833, 0x00ff, 2, 2, NULL, 7, gen7_3DSTATE_URB_GS },
  3001. { 0x7900, 0xffff, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
  3002. { 0x7901, 0xffff, 5, 5, "3DSTATE_CONSTANT_COLOR" },
  3003. { 0x7905, 0xffff, 5, 7, "3DSTATE_DEPTH_BUFFER" },
  3004. { 0x7906, 0xffff, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
  3005. { 0x7907, 0xffff, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
  3006. { 0x7908, 0xffff, 3, 3, "3DSTATE_LINE_STIPPLE" },
  3007. { 0x7909, 0xffff, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
  3008. { 0x7909, 0xffff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
  3009. { 0x790a, 0xffff, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
  3010. { 0x790b, 0xffff, 4, 4, "3DSTATE_GS_SVB_INDEX" },
  3011. { 0x790d, 0xffff, 3, 3, "3DSTATE_MULTISAMPLE", 6 },
  3012. { 0x790d, 0xffff, 4, 4, "3DSTATE_MULTISAMPLE", 7 },
  3013. { 0x7910, 0x00ff, 2, 2, "3DSTATE_CLEAR_PARAMS" },
  3014. { 0x7912, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_VS" },
  3015. { 0x7913, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_HS" },
  3016. { 0x7914, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_DS" },
  3017. { 0x7915, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_GS" },
  3018. { 0x7916, 0x00ff, 2, 2, "3DSTATE_PUSH_CONSTANT_ALLOC_PS" },
  3019. { 0x7917, 0x00ff, 2, 2+128*2, "3DSTATE_SO_DECL_LIST" },
  3020. { 0x7918, 0x00ff, 4, 4, "3DSTATE_SO_BUFFER" },
  3021. { 0x7a00, 0x00ff, 4, 6, "PIPE_CONTROL" },
  3022. { 0x7b00, 0x00ff, 7, 7, NULL, 7, gen7_3DPRIMITIVE },
  3023. { 0x7b00, 0x00ff, 6, 6, NULL, 0, gen4_3DPRIMITIVE },
  3024. }, *opcode_3d = NULL;
  3025. opcode = (data[0] & 0xffff0000) >> 16;
  3026. for (i = 0; i < ARRAY_SIZE(opcodes_3d); i++) {
  3027. if (opcode != opcodes_3d[i].opcode)
  3028. continue;
  3029. /* If it's marked as not our gen, skip. */
  3030. if (opcodes_3d[i].gen && opcodes_3d[i].gen != ctx->gen)
  3031. continue;
  3032. opcode_3d = &opcodes_3d[i];
  3033. break;
  3034. }
  3035. if (opcode_3d) {
  3036. if (opcode_3d->max_len == 1)
  3037. len = 1;
  3038. else
  3039. len = (data[0] & opcode_3d->len_mask) + 2;
  3040. if (len < opcode_3d->min_len ||
  3041. len > opcode_3d->max_len) {
  3042. fprintf(out, "Bad length %d in %s, expected %d-%d\n",
  3043. len, opcode_3d->name,
  3044. opcode_3d->min_len, opcode_3d->max_len);
  3045. }
  3046. } else {
  3047. len = (data[0] & 0x0000ffff) + 2;
  3048. }
  3049. switch (opcode) {
  3050. case 0x6000:
  3051. return i965_decode_urb_fence(ctx, len);
  3052. case 0x6001:
  3053. instr_out(ctx, 0, "CS_URB_STATE\n");
  3054. instr_out(ctx, 1,
  3055. "entry_size: %d [%d bytes], n_entries: %d\n",
  3056. (data[1] >> 4) & 0x1f,
  3057. (((data[1] >> 4) & 0x1f) + 1) * 64, data[1] & 0x7);
  3058. return len;
  3059. case 0x6002:
  3060. instr_out(ctx, 0, "CONSTANT_BUFFER: %s\n",
  3061. (data[0] >> 8) & 1 ? "valid" : "invalid");
  3062. instr_out(ctx, 1,
  3063. "offset: 0x%08x, length: %d bytes\n", data[1] & ~0x3f,
  3064. ((data[1] & 0x3f) + 1) * 64);
  3065. return len;
  3066. case 0x6101:
  3067. i = 0;
  3068. instr_out(ctx, 0, "STATE_BASE_ADDRESS\n");
  3069. i++;
  3070. if (IS_GEN6(devid) || IS_GEN7(devid))
  3071. sba_len = 10;
  3072. else if (IS_GEN5(devid))
  3073. sba_len = 8;
  3074. else
  3075. sba_len = 6;
  3076. if (len != sba_len)
  3077. fprintf(out, "Bad count in STATE_BASE_ADDRESS\n");
  3078. state_base_out(ctx, i++, "general");
  3079. state_base_out(ctx, i++, "surface");
  3080. if (IS_GEN6(devid) || IS_GEN7(devid))
  3081. state_base_out(ctx, i++, "dynamic");
  3082. state_base_out(ctx, i++, "indirect");
  3083. if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
  3084. state_base_out(ctx, i++, "instruction");
  3085. state_max_out(ctx, i++, "general");
  3086. if (IS_GEN6(devid) || IS_GEN7(devid))
  3087. state_max_out(ctx, i++, "dynamic");
  3088. state_max_out(ctx, i++, "indirect");
  3089. if (IS_GEN5(devid) || IS_GEN6(devid) || IS_GEN7(devid))
  3090. state_max_out(ctx, i++, "instruction");
  3091. return len;
  3092. case 0x7800:
  3093. instr_out(ctx, 0, "3DSTATE_PIPELINED_POINTERS\n");
  3094. instr_out(ctx, 1, "VS state\n");
  3095. instr_out(ctx, 2, "GS state\n");
  3096. instr_out(ctx, 3, "Clip state\n");
  3097. instr_out(ctx, 4, "SF state\n");
  3098. instr_out(ctx, 5, "WM state\n");
  3099. instr_out(ctx, 6, "CC state\n");
  3100. return len;
  3101. case 0x7801:
  3102. if (len != 6 && len != 4)
  3103. fprintf(out,
  3104. "Bad count in 3DSTATE_BINDING_TABLE_POINTERS\n");
  3105. if (len == 6) {
  3106. instr_out(ctx, 0,
  3107. "3DSTATE_BINDING_TABLE_POINTERS\n");
  3108. instr_out(ctx, 1, "VS binding table\n");
  3109. instr_out(ctx, 2, "GS binding table\n");
  3110. instr_out(ctx, 3, "Clip binding table\n");
  3111. instr_out(ctx, 4, "SF binding table\n");
  3112. instr_out(ctx, 5, "WM binding table\n");
  3113. } else {
  3114. instr_out(ctx, 0,
  3115. "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
  3116. "GS mod %d, PS mod %d\n",
  3117. (data[0] & (1 << 8)) != 0,
  3118. (data[0] & (1 << 9)) != 0,
  3119. (data[0] & (1 << 12)) != 0);
  3120. instr_out(ctx, 1, "VS binding table\n");
  3121. instr_out(ctx, 2, "GS binding table\n");
  3122. instr_out(ctx, 3, "WM binding table\n");
  3123. }
  3124. return len;
  3125. case 0x7802:
  3126. instr_out(ctx, 0,
  3127. "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
  3128. "GS mod %d, PS mod %d\n", (data[0] & (1 << 8)) != 0,
  3129. (data[0] & (1 << 9)) != 0,
  3130. (data[0] & (1 << 12)) != 0);
  3131. instr_out(ctx, 1, "VS sampler state\n");
  3132. instr_out(ctx, 2, "GS sampler state\n");
  3133. instr_out(ctx, 3, "WM sampler state\n");
  3134. return len;
  3135. case 0x7805:
  3136. /* Actually 3DSTATE_DEPTH_BUFFER on gen7. */
  3137. if (ctx->gen == 7)
  3138. break;
  3139. instr_out(ctx, 0, "3DSTATE_URB\n");
  3140. instr_out(ctx, 1,
  3141. "VS entries %d, alloc size %d (1024bit row)\n",
  3142. data[1] & 0xffff, ((data[1] >> 16) & 0x07f) + 1);
  3143. instr_out(ctx, 2,
  3144. "GS entries %d, alloc size %d (1024bit row)\n",
  3145. (data[2] >> 8) & 0x3ff, (data[2] & 7) + 1);
  3146. return len;
  3147. case 0x7808:
  3148. if ((len - 1) % 4 != 0)
  3149. fprintf(out, "Bad count in 3DSTATE_VERTEX_BUFFERS\n");
  3150. instr_out(ctx, 0, "3DSTATE_VERTEX_BUFFERS\n");
  3151. for (i = 1; i < len;) {
  3152. int idx, access;
  3153. if (IS_GEN6(devid)) {
  3154. idx = 26;
  3155. access = 20;
  3156. } else {
  3157. idx = 27;
  3158. access = 26;
  3159. }
  3160. instr_out(ctx, i,
  3161. "buffer %d: %s, pitch %db\n", data[i] >> idx,
  3162. data[i] & (1 << access) ? "random" :
  3163. "sequential", data[i] & 0x07ff);
  3164. i++;
  3165. instr_out(ctx, i++, "buffer address\n");
  3166. instr_out(ctx, i++, "max index\n");
  3167. instr_out(ctx, i++, "mbz\n");
  3168. }
  3169. return len;
  3170. case 0x7809:
  3171. if ((len + 1) % 2 != 0)
  3172. fprintf(out, "Bad count in 3DSTATE_VERTEX_ELEMENTS\n");
  3173. instr_out(ctx, 0, "3DSTATE_VERTEX_ELEMENTS\n");
  3174. for (i = 1; i < len;) {
  3175. instr_out(ctx, i,
  3176. "buffer %d: %svalid, type 0x%04x, "
  3177. "src offset 0x%04x bytes\n",
  3178. data[i] >> ((IS_GEN6(devid) || IS_GEN7(devid)) ? 26 : 27),
  3179. data[i] & (1 << ((IS_GEN6(devid) || IS_GEN7(devid)) ? 25 : 26)) ?
  3180. "" : "in", (data[i] >> 16) & 0x1ff,
  3181. data[i] & 0x07ff);
  3182. i++;
  3183. instr_out(ctx, i, "(%s, %s, %s, %s), "
  3184. "dst offset 0x%02x bytes\n",
  3185. get_965_element_component(data[i], 0),
  3186. get_965_element_component(data[i], 1),
  3187. get_965_element_component(data[i], 2),
  3188. get_965_element_component(data[i], 3),
  3189. (data[i] & 0xff) * 4);
  3190. i++;
  3191. }
  3192. return len;
  3193. case 0x780d:
  3194. instr_out(ctx, 0,
  3195. "3DSTATE_VIEWPORT_STATE_POINTERS\n");
  3196. instr_out(ctx, 1, "clip\n");
  3197. instr_out(ctx, 2, "sf\n");
  3198. instr_out(ctx, 3, "cc\n");
  3199. return len;
  3200. case 0x780a:
  3201. instr_out(ctx, 0, "3DSTATE_INDEX_BUFFER\n");
  3202. instr_out(ctx, 1, "beginning buffer address\n");
  3203. instr_out(ctx, 2, "ending buffer address\n");
  3204. return len;
  3205. case 0x780f:
  3206. instr_out(ctx, 0, "3DSTATE_SCISSOR_POINTERS\n");
  3207. instr_out(ctx, 1, "scissor rect offset\n");
  3208. return len;
  3209. case 0x7810:
  3210. instr_out(ctx, 0, "3DSTATE_VS\n");
  3211. instr_out(ctx, 1, "kernel pointer\n");
  3212. instr_out(ctx, 2,
  3213. "SPF=%d, VME=%d, Sampler Count %d, "
  3214. "Binding table count %d\n", (data[2] >> 31) & 1,
  3215. (data[2] >> 30) & 1, (data[2] >> 27) & 7,
  3216. (data[2] >> 18) & 0xff);
  3217. instr_out(ctx, 3, "scratch offset\n");
  3218. instr_out(ctx, 4,
  3219. "Dispatch GRF start %d, VUE read length %d, "
  3220. "VUE read offset %d\n", (data[4] >> 20) & 0x1f,
  3221. (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
  3222. instr_out(ctx, 5,
  3223. "Max Threads %d, Vertex Cache %sable, "
  3224. "VS func %sable\n", ((data[5] >> 25) & 0x7f) + 1,
  3225. (data[5] & (1 << 1)) != 0 ? "dis" : "en",
  3226. (data[5] & 1) != 0 ? "en" : "dis");
  3227. return len;
  3228. case 0x7811:
  3229. instr_out(ctx, 0, "3DSTATE_GS\n");
  3230. instr_out(ctx, 1, "kernel pointer\n");
  3231. instr_out(ctx, 2,
  3232. "SPF=%d, VME=%d, Sampler Count %d, "
  3233. "Binding table count %d\n", (data[2] >> 31) & 1,
  3234. (data[2] >> 30) & 1, (data[2] >> 27) & 7,
  3235. (data[2] >> 18) & 0xff);
  3236. instr_out(ctx, 3, "scratch offset\n");
  3237. instr_out(ctx, 4,
  3238. "Dispatch GRF start %d, VUE read length %d, "
  3239. "VUE read offset %d\n", (data[4] & 0xf),
  3240. (data[4] >> 11) & 0x3f, (data[4] >> 4) & 0x3f);
  3241. instr_out(ctx, 5,
  3242. "Max Threads %d, Rendering %sable\n",
  3243. ((data[5] >> 25) & 0x7f) + 1,
  3244. (data[5] & (1 << 8)) != 0 ? "en" : "dis");
  3245. instr_out(ctx, 6,
  3246. "Reorder %sable, Discard Adjaceny %sable, "
  3247. "GS %sable\n",
  3248. (data[6] & (1 << 30)) != 0 ? "en" : "dis",
  3249. (data[6] & (1 << 29)) != 0 ? "en" : "dis",
  3250. (data[6] & (1 << 15)) != 0 ? "en" : "dis");
  3251. return len;
  3252. case 0x7812:
  3253. instr_out(ctx, 0, "3DSTATE_CLIP\n");
  3254. instr_out(ctx, 1,
  3255. "UserClip distance cull test mask 0x%x\n",
  3256. data[1] & 0xff);
  3257. instr_out(ctx, 2,
  3258. "Clip %sable, API mode %s, Viewport XY test %sable, "
  3259. "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
  3260. "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
  3261. "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
  3262. (data[2] & (1 << 31)) != 0 ? "en" : "dis",
  3263. (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
  3264. (data[2] & (1 << 28)) != 0 ? "en" : "dis",
  3265. (data[2] & (1 << 27)) != 0 ? "en" : "dis",
  3266. (data[2] & (1 << 26)) != 0 ? "en" : "dis",
  3267. (data[2] >> 13) & 7,
  3268. (data[2] & (1 << 9)) != 0 ? "dis" : "en",
  3269. (data[2] & (1 << 8)) != 0 ? "en" : "dis",
  3270. (data[2] >> 4) & 3, (data[2] >> 2) & 3,
  3271. (data[2] & 3));
  3272. instr_out(ctx, 3,
  3273. "Min PointWidth %d, Max PointWidth %d, "
  3274. "Force Zero RTAIndex %sable, Max VPIndex %d\n",
  3275. (data[3] >> 17) & 0x7ff, (data[3] >> 6) & 0x7ff,
  3276. (data[3] & (1 << 5)) != 0 ? "en" : "dis",
  3277. (data[3] & 0xf));
  3278. return len;
  3279. case 0x7813:
  3280. if (ctx->gen == 7)
  3281. break;
  3282. instr_out(ctx, 0, "3DSTATE_SF\n");
  3283. instr_out(ctx, 1,
  3284. "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
  3285. "VUE read offset %d\n", (data[1] >> 22) & 0x3f,
  3286. (data[1] & (1 << 21)) != 0 ? "en" : "dis",
  3287. (data[1] >> 11) & 0x1f, (data[1] >> 4) & 0x3f);
  3288. instr_out(ctx, 2,
  3289. "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
  3290. "VP transform %sable, FrontWinding_%s\n",
  3291. (data[2] & (1 << 11)) != 0 ? "en" : "dis",
  3292. (data[2] >> 5) & 3, (data[2] >> 3) & 3,
  3293. (data[2] & (1 << 1)) != 0 ? "en" : "dis",
  3294. (data[2] & 1) != 0 ? "CCW" : "CW");
  3295. instr_out(ctx, 3,
  3296. "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
  3297. (data[3] & (1 << 31)) != 0 ? "en" : "dis",
  3298. (data[3] >> 29) & 3,
  3299. (data[3] & (1 << 11)) != 0 ? "en" : "dis",
  3300. (data[3] >> 8) & 3);
  3301. instr_out(ctx, 4,
  3302. "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
  3303. (data[4] & (1 << 31)) != 0 ? "en" : "dis",
  3304. (data[4] & (1 << 12)) != 0 ? 4 : 8,
  3305. (data[4] & (1 << 11)) != 0);
  3306. instr_out(ctx, 5,
  3307. "Global Depth Offset Constant %f\n",
  3308. *(float *)(&data[5]));
  3309. instr_out(ctx, 6, "Global Depth Offset Scale %f\n",
  3310. *(float *)(&data[6]));
  3311. instr_out(ctx, 7, "Global Depth Offset Clamp %f\n",
  3312. *(float *)(&data[7]));
  3313. for (i = 0, j = 0; i < 8; i++, j += 2)
  3314. instr_out(ctx, i + 8,
  3315. "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
  3316. "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
  3317. j + 1,
  3318. (data[8 + i] & (1 << 31)) != 0 ? "W" : "",
  3319. (data[8 + i] & (1 << 30)) != 0 ? "Z" : "",
  3320. (data[8 + i] & (1 << 29)) != 0 ? "Y" : "",
  3321. (data[8 + i] & (1 << 28)) != 0 ? "X" : "",
  3322. (data[8 + i] >> 25) & 3,
  3323. (data[8 + i] >> 22) & 3,
  3324. (data[8 + i] >> 16) & 0x1f, j,
  3325. (data[8 + i] & (1 << 15)) != 0 ? "W" : "",
  3326. (data[8 + i] & (1 << 14)) != 0 ? "Z" : "",
  3327. (data[8 + i] & (1 << 13)) != 0 ? "Y" : "",
  3328. (data[8 + i] & (1 << 12)) != 0 ? "X" : "",
  3329. (data[8 + i] >> 9) & 3,
  3330. (data[8 + i] >> 6) & 3, (data[8 + i] & 0x1f));
  3331. instr_out(ctx, 16,
  3332. "Point Sprite TexCoord Enable\n");
  3333. instr_out(ctx, 17, "Const Interp Enable\n");
  3334. instr_out(ctx, 18,
  3335. "Attrib 7-0 WrapShortest Enable\n");
  3336. instr_out(ctx, 19,
  3337. "Attrib 15-8 WrapShortest Enable\n");
  3338. return len;
  3339. case 0x7900:
  3340. instr_out(ctx, 0, "3DSTATE_DRAWING_RECTANGLE\n");
  3341. instr_out(ctx, 1, "top left: %d,%d\n",
  3342. data[1] & 0xffff, (data[1] >> 16) & 0xffff);
  3343. instr_out(ctx, 2, "bottom right: %d,%d\n",
  3344. data[2] & 0xffff, (data[2] >> 16) & 0xffff);
  3345. instr_out(ctx, 3, "origin: %d,%d\n",
  3346. (int)data[3] & 0xffff, ((int)data[3] >> 16) & 0xffff);
  3347. return len;
  3348. case 0x7905:
  3349. instr_out(ctx, 0, "3DSTATE_DEPTH_BUFFER\n");
  3350. if (IS_GEN5(devid) || IS_GEN6(devid))
  3351. instr_out(ctx, 1,
  3352. "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Separate Stencil %d\n",
  3353. get_965_surfacetype(data[1] >> 29),
  3354. get_965_depthformat((data[1] >> 18) & 0x7),
  3355. (data[1] & 0x0001ffff) + 1,
  3356. data[1] & (1 << 27) ? "" : "not ",
  3357. (data[1] & (1 << 22)) != 0,
  3358. (data[1] & (1 << 21)) != 0);
  3359. else
  3360. instr_out(ctx, 1,
  3361. "%s, %s, pitch = %d bytes, %stiled\n",
  3362. get_965_surfacetype(data[1] >> 29),
  3363. get_965_depthformat((data[1] >> 18) & 0x7),
  3364. (data[1] & 0x0001ffff) + 1,
  3365. data[1] & (1 << 27) ? "" : "not ");
  3366. instr_out(ctx, 2, "depth offset\n");
  3367. instr_out(ctx, 3, "%dx%d\n",
  3368. ((data[3] & 0x0007ffc0) >> 6) + 1,
  3369. ((data[3] & 0xfff80000) >> 19) + 1);
  3370. instr_out(ctx, 4, "volume depth\n");
  3371. if (len >= 6)
  3372. instr_out(ctx, 5, "\n");
  3373. if (len >= 7) {
  3374. if (IS_GEN6(devid))
  3375. instr_out(ctx, 6, "\n");
  3376. else
  3377. instr_out(ctx, 6,
  3378. "render target view extent\n");
  3379. }
  3380. return len;
  3381. case 0x7a00:
  3382. if (IS_GEN6(devid) || IS_GEN7(devid)) {
  3383. if (len != 4 && len != 5)
  3384. fprintf(out, "Bad count in PIPE_CONTROL\n");
  3385. switch ((data[1] >> 14) & 0x3) {
  3386. case 0:
  3387. desc1 = "no write";
  3388. break;
  3389. case 1:
  3390. desc1 = "qword write";
  3391. break;
  3392. case 2:
  3393. desc1 = "PS_DEPTH_COUNT write";
  3394. break;
  3395. case 3:
  3396. desc1 = "TIMESTAMP write";
  3397. break;
  3398. }
  3399. instr_out(ctx, 0, "PIPE_CONTROL\n");
  3400. instr_out(ctx, 1,
  3401. "%s, %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  3402. desc1,
  3403. data[1] & (1 << 20) ? "cs stall, " : "",
  3404. data[1] & (1 << 19) ?
  3405. "global snapshot count reset, " : "",
  3406. data[1] & (1 << 18) ? "tlb invalidate, " : "",
  3407. data[1] & (1 << 17) ? "gfdt flush, " : "",
  3408. data[1] & (1 << 17) ? "media state clear, " :
  3409. "",
  3410. data[1] & (1 << 13) ? "depth stall, " : "",
  3411. data[1] & (1 << 12) ?
  3412. "render target cache flush, " : "",
  3413. data[1] & (1 << 11) ?
  3414. "instruction cache invalidate, " : "",
  3415. data[1] & (1 << 10) ?
  3416. "texture cache invalidate, " : "",
  3417. data[1] & (1 << 9) ?
  3418. "indirect state invalidate, " : "",
  3419. data[1] & (1 << 8) ? "notify irq, " : "",
  3420. data[1] & (1 << 7) ? "PIPE_CONTROL flush, " :
  3421. "",
  3422. data[1] & (1 << 6) ? "protect mem app_id, " :
  3423. "", data[1] & (1 << 5) ? "DC flush, " : "",
  3424. data[1] & (1 << 4) ? "vf fetch invalidate, " :
  3425. "",
  3426. data[1] & (1 << 3) ?
  3427. "constant cache invalidate, " : "",
  3428. data[1] & (1 << 2) ?
  3429. "state cache invalidate, " : "",
  3430. data[1] & (1 << 1) ? "stall at scoreboard, " :
  3431. "",
  3432. data[1] & (1 << 0) ? "depth cache flush, " :
  3433. "");
  3434. if (len == 5) {
  3435. instr_out(ctx, 2,
  3436. "destination address\n");
  3437. instr_out(ctx, 3,
  3438. "immediate dword low\n");
  3439. instr_out(ctx, 4,
  3440. "immediate dword high\n");
  3441. } else {
  3442. for (i = 2; i < len; i++) {
  3443. instr_out(ctx, i, "\n");
  3444. }
  3445. }
  3446. return len;
  3447. } else {
  3448. if (len != 4)
  3449. fprintf(out, "Bad count in PIPE_CONTROL\n");
  3450. switch ((data[0] >> 14) & 0x3) {
  3451. case 0:
  3452. desc1 = "no write";
  3453. break;
  3454. case 1:
  3455. desc1 = "qword write";
  3456. break;
  3457. case 2:
  3458. desc1 = "PS_DEPTH_COUNT write";
  3459. break;
  3460. case 3:
  3461. desc1 = "TIMESTAMP write";
  3462. break;
  3463. }
  3464. instr_out(ctx, 0,
  3465. "PIPE_CONTROL: %s, %sdepth stall, %sRC write flush, "
  3466. "%sinst flush\n",
  3467. desc1,
  3468. data[0] & (1 << 13) ? "" : "no ",
  3469. data[0] & (1 << 12) ? "" : "no ",
  3470. data[0] & (1 << 11) ? "" : "no ");
  3471. instr_out(ctx, 1, "destination address\n");
  3472. instr_out(ctx, 2, "immediate dword low\n");
  3473. instr_out(ctx, 3, "immediate dword high\n");
  3474. return len;
  3475. }
  3476. }
  3477. if (opcode_3d) {
  3478. if (opcode_3d->func) {
  3479. return opcode_3d->func(ctx);
  3480. } else {
  3481. instr_out(ctx, 0, "%s\n", opcode_3d->name);
  3482. for (i = 1; i < len; i++) {
  3483. instr_out(ctx, i, "dword %d\n", i);
  3484. }
  3485. return len;
  3486. }
  3487. }
  3488. instr_out(ctx, 0, "3D UNKNOWN: 3d_965 opcode = 0x%x\n",
  3489. opcode);
  3490. return 1;
  3491. }
  3492. static int
  3493. decode_3d_i830(struct drm_intel_decode *ctx)
  3494. {
  3495. unsigned int idx;
  3496. uint32_t opcode;
  3497. uint32_t *data = ctx->data;
  3498. struct {
  3499. uint32_t opcode;
  3500. unsigned int min_len;
  3501. unsigned int max_len;
  3502. const char *name;
  3503. } opcodes_3d[] = {
  3504. { 0x02, 1, 1, "3DSTATE_MODES_3" },
  3505. { 0x03, 1, 1, "3DSTATE_ENABLES_1" },
  3506. { 0x04, 1, 1, "3DSTATE_ENABLES_2" },
  3507. { 0x05, 1, 1, "3DSTATE_VFT0" },
  3508. { 0x06, 1, 1, "3DSTATE_AA" },
  3509. { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
  3510. { 0x08, 1, 1, "3DSTATE_MODES_1" },
  3511. { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
  3512. { 0x0a, 1, 1, "3DSTATE_VFT1" },
  3513. { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
  3514. { 0x0c, 1, 1, "3DSTATE_MODES_5" },
  3515. { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
  3516. { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
  3517. { 0x0f, 1, 1, "3DSTATE_MODES_2" },
  3518. { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
  3519. { 0x16, 1, 1, "3DSTATE_MODES_4"},
  3520. }, *opcode_3d;
  3521. opcode = (data[0] & 0x1f000000) >> 24;
  3522. switch (opcode) {
  3523. case 0x1f:
  3524. return decode_3d_primitive(ctx);
  3525. case 0x1d:
  3526. return decode_3d_1d(ctx);
  3527. case 0x1c:
  3528. return decode_3d_1c(ctx);
  3529. }
  3530. for (idx = 0; idx < ARRAY_SIZE(opcodes_3d); idx++) {
  3531. opcode_3d = &opcodes_3d[idx];
  3532. if ((data[0] & 0x1f000000) >> 24 == opcode_3d->opcode) {
  3533. unsigned int len = 1, i;
  3534. instr_out(ctx, 0, "%s\n", opcode_3d->name);
  3535. if (opcode_3d->max_len > 1) {
  3536. len = (data[0] & 0xff) + 2;
  3537. if (len < opcode_3d->min_len ||
  3538. len > opcode_3d->max_len) {
  3539. fprintf(out, "Bad count in %s\n",
  3540. opcode_3d->name);
  3541. }
  3542. }
  3543. for (i = 1; i < len; i++) {
  3544. instr_out(ctx, i, "dword %d\n", i);
  3545. }
  3546. return len;
  3547. }
  3548. }
  3549. instr_out(ctx, 0, "3D UNKNOWN: 3d_i830 opcode = 0x%x\n",
  3550. opcode);
  3551. return 1;
  3552. }
  3553. drm_public struct drm_intel_decode *
  3554. drm_intel_decode_context_alloc(uint32_t devid)
  3555. {
  3556. struct drm_intel_decode *ctx;
  3557. int gen = 0;
  3558. if (IS_GEN8(devid))
  3559. gen = 8;
  3560. else if (IS_GEN7(devid))
  3561. gen = 7;
  3562. else if (IS_GEN6(devid))
  3563. gen = 6;
  3564. else if (IS_GEN5(devid))
  3565. gen = 5;
  3566. else if (IS_GEN4(devid))
  3567. gen = 4;
  3568. else if (IS_GEN3(devid))
  3569. gen = 3;
  3570. else if (IS_GEN2(devid))
  3571. gen = 2;
  3572. else
  3573. /* Just assume future unknown platforms behave as gen8. */
  3574. gen = 8;
  3575. if (!gen)
  3576. return NULL;
  3577. ctx = calloc(1, sizeof(struct drm_intel_decode));
  3578. if (!ctx)
  3579. return NULL;
  3580. ctx->devid = devid;
  3581. ctx->gen = gen;
  3582. ctx->out = stdout;
  3583. return ctx;
  3584. }
  3585. drm_public void
  3586. drm_intel_decode_context_free(struct drm_intel_decode *ctx)
  3587. {
  3588. free(ctx);
  3589. }
  3590. drm_public void
  3591. drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx,
  3592. int dump_past_end)
  3593. {
  3594. ctx->dump_past_end = !!dump_past_end;
  3595. }
  3596. drm_public void
  3597. drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx,
  3598. void *data, uint32_t hw_offset, int count)
  3599. {
  3600. ctx->base_data = data;
  3601. ctx->base_hw_offset = hw_offset;
  3602. ctx->base_count = count;
  3603. }
  3604. drm_public void
  3605. drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx,
  3606. uint32_t head, uint32_t tail)
  3607. {
  3608. ctx->head = head;
  3609. ctx->tail = tail;
  3610. }
  3611. drm_public void
  3612. drm_intel_decode_set_output_file(struct drm_intel_decode *ctx,
  3613. FILE *output)
  3614. {
  3615. ctx->out = output;
  3616. }
  3617. /**
  3618. * Decodes an i830-i915 batch buffer, writing the output to stdout.
  3619. *
  3620. * \param data batch buffer contents
  3621. * \param count number of DWORDs to decode in the batch buffer
  3622. * \param hw_offset hardware address for the buffer
  3623. */
  3624. drm_public void
  3625. drm_intel_decode(struct drm_intel_decode *ctx)
  3626. {
  3627. int ret;
  3628. unsigned int index = 0;
  3629. uint32_t devid;
  3630. int size;
  3631. void *temp;
  3632. if (!ctx)
  3633. return;
  3634. /* Put a scratch page full of obviously undefined data after
  3635. * the batchbuffer. This lets us avoid a bunch of length
  3636. * checking in statically sized packets.
  3637. */
  3638. size = ctx->base_count * 4;
  3639. temp = malloc(size + 4096);
  3640. memcpy(temp, ctx->base_data, size);
  3641. memset((char *)temp + size, 0xd0, 4096);
  3642. ctx->data = temp;
  3643. ctx->hw_offset = ctx->base_hw_offset;
  3644. ctx->count = ctx->base_count;
  3645. devid = ctx->devid;
  3646. head_offset = ctx->head;
  3647. tail_offset = ctx->tail;
  3648. out = ctx->out;
  3649. saved_s2_set = 0;
  3650. saved_s4_set = 1;
  3651. while (ctx->count > 0) {
  3652. index = 0;
  3653. switch ((ctx->data[index] & 0xe0000000) >> 29) {
  3654. case 0x0:
  3655. ret = decode_mi(ctx);
  3656. /* If MI_BATCHBUFFER_END happened, then dump
  3657. * the rest of the output in case we some day
  3658. * want it in debugging, but don't decode it
  3659. * since it'll just confuse in the common
  3660. * case.
  3661. */
  3662. if (ret == -1) {
  3663. if (ctx->dump_past_end) {
  3664. index++;
  3665. } else {
  3666. for (index = index + 1; index < ctx->count;
  3667. index++) {
  3668. instr_out(ctx, index, "\n");
  3669. }
  3670. }
  3671. } else
  3672. index += ret;
  3673. break;
  3674. case 0x2:
  3675. index += decode_2d(ctx);
  3676. break;
  3677. case 0x3:
  3678. if (IS_9XX(devid) && !IS_GEN3(devid)) {
  3679. index +=
  3680. decode_3d_965(ctx);
  3681. } else if (IS_GEN3(devid)) {
  3682. index += decode_3d(ctx);
  3683. } else {
  3684. index +=
  3685. decode_3d_i830(ctx);
  3686. }
  3687. break;
  3688. default:
  3689. instr_out(ctx, index, "UNKNOWN\n");
  3690. index++;
  3691. break;
  3692. }
  3693. fflush(out);
  3694. if (ctx->count < index)
  3695. break;
  3696. ctx->count -= index;
  3697. ctx->data += index;
  3698. ctx->hw_offset += 4 * index;
  3699. }
  3700. free(temp);
  3701. }