Subversion Repositories Kolibri OS

Rev

Rev 5368 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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