Subversion Repositories Kolibri OS

Rev

Rev 1428 | Rev 1877 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <drm/drmP.h>
  3. #include <drm.h>
  4. #include <drm_mm.h>
  5. #include "radeon_drm.h"
  6. #include "radeon.h"
  7. #include "radeon_object.h"
  8. #include "display.h"
  9.  
  10. #include "r100d.h"
  11.  
  12.  
  13. display_t *rdisplay;
  14.  
  15. static cursor_t*  __stdcall select_cursor(cursor_t *cursor);
  16. static void       __stdcall move_cursor(cursor_t *cursor, int x, int y);
  17.  
  18. extern void destroy_cursor(void);
  19.  
  20. void disable_mouse(void)
  21. {};
  22.  
  23. int init_cursor(cursor_t *cursor)
  24. {
  25.     struct radeon_device *rdev;
  26.  
  27.     uint32_t *bits;
  28.     uint32_t *src;
  29.  
  30.     int       i,j;
  31.     int       r;
  32.  
  33.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  34.  
  35.     r = radeon_bo_create(rdev, NULL, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  36.                      false, RADEON_GEM_DOMAIN_VRAM, &cursor->robj);
  37.  
  38.     if (unlikely(r != 0))
  39.         return r;
  40.  
  41.     r = radeon_bo_reserve(cursor->robj, false);
  42.     if (unlikely(r != 0))
  43.         return r;
  44.  
  45.     r = radeon_bo_pin(cursor->robj, RADEON_GEM_DOMAIN_VRAM, NULL);
  46.     if (unlikely(r != 0))
  47.         return r;
  48.  
  49.     r = radeon_bo_kmap(cursor->robj, (void**)&bits);
  50.     if (r) {
  51.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  52.          return r;
  53.     };
  54.  
  55.     src = cursor->data;
  56.  
  57.     for(i = 0; i < 32; i++)
  58.     {
  59.         for(j = 0; j < 32; j++)
  60.             *bits++ = *src++;
  61.         for(j = 32; j < CURSOR_WIDTH; j++)
  62.             *bits++ = 0;
  63.     }
  64.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  65.         *bits++ = 0;
  66.  
  67.     radeon_bo_kunmap(cursor->robj);
  68.  
  69.  //   cursor->header.destroy = destroy_cursor;
  70.  
  71.     return 0;
  72. };
  73.  
  74. void fini_cursor(cursor_t *cursor)
  75. {
  76.     list_del(&cursor->list);
  77.     radeon_bo_unpin(cursor->robj);
  78.     KernelFree(cursor->data);
  79.     __DestroyObject(cursor);
  80. };
  81.  
  82.  
  83. static void radeon_show_cursor()
  84. {
  85.     struct radeon_device *rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  86.  
  87.     if (ASIC_IS_AVIVO(rdev)) {
  88.         WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL);
  89.         WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
  90.                  (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
  91.     } else {
  92.         WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
  93.         WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
  94.                       (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
  95.              ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
  96.     }
  97. }
  98.  
  99. cursor_t* __stdcall select_cursor(cursor_t *cursor)
  100. {
  101.     struct radeon_device *rdev;
  102.     cursor_t *old;
  103.     uint32_t  gpu_addr;
  104.  
  105.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  106.  
  107.     old = rdisplay->cursor;
  108.  
  109.     rdisplay->cursor = cursor;
  110.     gpu_addr = radeon_bo_gpu_offset(cursor->robj);
  111.  
  112.     if (ASIC_IS_AVIVO(rdev))
  113.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS,  gpu_addr);
  114.     else {
  115.         WREG32(RADEON_CUR_OFFSET, gpu_addr - rdev->mc.vram_start);
  116.     }
  117.  
  118.     return old;
  119. };
  120.  
  121. static void radeon_lock_cursor(bool lock)
  122. {
  123.     struct radeon_device *rdev;
  124.  
  125.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  126.  
  127.     uint32_t cur_lock;
  128.  
  129.     if (ASIC_IS_AVIVO(rdev)) {
  130.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE);
  131.         if (lock)
  132.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  133.         else
  134.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  135.         WREG32(AVIVO_D1CUR_UPDATE, cur_lock);
  136.     } else {
  137.         cur_lock = RREG32(RADEON_CUR_OFFSET);
  138.         if (lock)
  139.             cur_lock |= RADEON_CUR_LOCK;
  140.         else
  141.             cur_lock &= ~RADEON_CUR_LOCK;
  142.         WREG32(RADEON_CUR_OFFSET, cur_lock);
  143.     }
  144. }
  145.  
  146.  
  147. void __stdcall move_cursor(cursor_t *cursor, int x, int y)
  148. {
  149.     struct radeon_device *rdev;
  150.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  151.  
  152.     int hot_x = cursor->hot_x;
  153.     int hot_y = cursor->hot_y;
  154.  
  155.     radeon_lock_cursor(true);
  156.     if (ASIC_IS_AVIVO(rdev))
  157.     {
  158.         int w = 32;
  159.  
  160.         WREG32(AVIVO_D1CUR_POSITION, (x << 16) | y);
  161.         WREG32(AVIVO_D1CUR_HOT_SPOT, (hot_x << 16) | hot_y);
  162.         WREG32(AVIVO_D1CUR_SIZE, ((w - 1) << 16) | 31);
  163.     } else {
  164.  
  165.         uint32_t  gpu_addr;
  166.         int       xorg =0, yorg=0;
  167.  
  168.         x = x - hot_x;
  169.         y = y - hot_y;
  170.  
  171.         if( x < 0 )
  172.         {
  173.             xorg = -x + 1;
  174.             x = 0;
  175.         }
  176.  
  177.         if( y < 0 )
  178.         {
  179.             yorg = -hot_y + 1;
  180.             y = 0;
  181.         };
  182.  
  183.         WREG32(RADEON_CUR_HORZ_VERT_OFF,
  184.                (RADEON_CUR_LOCK | (xorg << 16) | yorg ));
  185.         WREG32(RADEON_CUR_HORZ_VERT_POSN,
  186.                (RADEON_CUR_LOCK | (x << 16) | y));
  187.  
  188.         gpu_addr = radeon_bo_gpu_offset(cursor->robj);
  189.  
  190.         /* offset is from DISP(2)_BASE_ADDRESS */
  191.         WREG32(RADEON_CUR_OFFSET,
  192.          (gpu_addr - rdev->mc.vram_start + (yorg * 256)));
  193.     }
  194.     radeon_lock_cursor(false);
  195. }
  196.  
  197. void __stdcall restore_cursor(int x, int y)
  198. {
  199. };
  200.  
  201.  
  202. bool init_display(struct radeon_device *rdev, videomode_t *usermode)
  203. {
  204.     struct drm_device   *dev;
  205.  
  206.     cursor_t            *cursor;
  207.     bool                 retval = true;
  208.     u32_t                ifl;
  209.  
  210.     ENTER();
  211.  
  212.     rdisplay = GetDisplay();
  213.  
  214.     dev = rdisplay->ddev = rdev->ddev;
  215.  
  216.     ifl = safe_cli();
  217.     {
  218.         list_for_each_entry(cursor, &rdisplay->cursors, list)
  219.         {
  220.             init_cursor(cursor);
  221.         };
  222.  
  223.         rdisplay->restore_cursor(0,0);
  224.         rdisplay->init_cursor    = init_cursor;
  225.         rdisplay->select_cursor  = select_cursor;
  226.         rdisplay->show_cursor    = NULL;
  227.         rdisplay->move_cursor    = move_cursor;
  228.         rdisplay->restore_cursor = restore_cursor;
  229.         rdisplay->disable_mouse  = disable_mouse;
  230.  
  231.         select_cursor(rdisplay->cursor);
  232.         radeon_show_cursor();
  233.     };
  234.     safe_sti(ifl);
  235.  
  236.     LEAVE();
  237.  
  238.     return retval;
  239. };
  240.  
  241.  
  242. struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
  243. {
  244. #define BYTES_PER_LONG (BITS_PER_LONG/8)
  245. #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
  246.     int fb_info_size = sizeof(struct fb_info);
  247.     struct fb_info *info;
  248.     char *p;
  249.  
  250.     if (size)
  251.         fb_info_size += PADDING;
  252.  
  253.     p = kzalloc(fb_info_size + size, GFP_KERNEL);
  254.  
  255.     if (!p)
  256.         return NULL;
  257.  
  258.     info = (struct fb_info *) p;
  259.  
  260.     if (size)
  261.         info->par = p + fb_info_size;
  262.  
  263.     return info;
  264. #undef PADDING
  265. #undef BYTES_PER_LONG
  266. }
  267.  
  268. void framebuffer_release(struct fb_info *info)
  269. {
  270.     kfree(info);
  271. }
  272.  
  273. #define PACKET3_PAINT_MULTI             0x9A
  274. #       define R5XX_GMC_CLR_CMP_CNTL_DIS        (1    << 28)
  275. #       define R5XX_GMC_WR_MSK_DIS              (1    << 30)
  276. #       define R5XX_ROP3_P                0x00f00000
  277.  
  278. #define R5XX_SC_TOP_LEFT                  0x16ec
  279. #define R5XX_SC_BOTTOM_RIGHT              0x16f0
  280. #       define R5XX_SC_SIGN_MASK_LO       0x8000
  281. #       define R5XX_SC_SIGN_MASK_HI       0x80000000
  282.  
  283. #define R5XX_DEFAULT_SC_BOTTOM_RIGHT      0x16e8
  284. #       define R5XX_DEFAULT_SC_RIGHT_MAX  (0x1fff <<  0)
  285. #       define R5XX_DEFAULT_SC_BOTTOM_MAX (0x1fff << 16)
  286.  
  287.  
  288. int r100_2D_test(struct radeon_device *rdev)
  289. {
  290.  
  291.     uint32_t   pitch;
  292.     uint32_t   offset;
  293.  
  294.     int        r;
  295.  
  296.     ENTER();
  297.  
  298.     pitch  = (1024*4)/64;
  299.     offset = rdev->mc.vram_start;
  300.  
  301.     r = radeon_ring_lock(rdev, 16);
  302.     if (r) {
  303.         DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  304.         return r;
  305.     }
  306.     radeon_ring_write(rdev, PACKET0(R5XX_SC_TOP_LEFT, 0));
  307.     radeon_ring_write(rdev, 0);
  308.  
  309.     radeon_ring_write(rdev, PACKET0(R5XX_SC_BOTTOM_RIGHT, 0));
  310.     radeon_ring_write(rdev, RADEON_DEFAULT_SC_RIGHT_MAX |
  311.                             RADEON_DEFAULT_SC_BOTTOM_MAX);
  312.  
  313.     radeon_ring_write(rdev, PACKET0(R5XX_DEFAULT_SC_BOTTOM_RIGHT, 0));
  314.     radeon_ring_write(rdev, RADEON_DEFAULT_SC_RIGHT_MAX |
  315.                             RADEON_DEFAULT_SC_BOTTOM_MAX);
  316.  
  317.     radeon_ring_write(rdev, PACKET3(PACKET3_PAINT_MULTI, 4));
  318.     radeon_ring_write(rdev, RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  319.                             RADEON_GMC_BRUSH_SOLID_COLOR      |
  320.                             RADEON_GMC_DST_32BPP              |
  321.                             RADEON_GMC_SRC_DATATYPE_COLOR     |
  322.                             R5XX_GMC_CLR_CMP_CNTL_DIS         |
  323.                             R5XX_GMC_WR_MSK_DIS               |
  324.                             R5XX_ROP3_P);
  325.  
  326.     radeon_ring_write(rdev, (pitch<<22)|(offset>>10));
  327.     radeon_ring_write(rdev, 0x0000FF00);
  328.     radeon_ring_write(rdev, (64<<16)|64);
  329.     radeon_ring_write(rdev, (128<<16)|128);
  330.  
  331.     radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0));
  332.     radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL);
  333.     radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
  334.     radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN |
  335.                             RADEON_WAIT_HOST_IDLECLEAN |
  336.                             RADEON_WAIT_DMA_GUI_IDLE);
  337.  
  338.     radeon_ring_unlock_commit(rdev);
  339.  
  340.     LEAVE();
  341.     return r;
  342. }
  343.  
  344.  
  345. #include "r600_reg_auto_r6xx.h"
  346. #include "r600_reg_r6xx.h"
  347. #include "r600d.h"
  348.  
  349. const u32 r6xx_default_state[] =
  350. {
  351.     0xc0002400,
  352.     0x00000000,
  353.     0xc0012800,
  354.     0x80000000,
  355.     0x80000000,
  356.     0xc0004600,
  357.     0x00000016,
  358.     0xc0016800,
  359.     0x00000010,
  360.     0x00028000,
  361.     0xc0016800,
  362.     0x00000010,
  363.     0x00008000,
  364.     0xc0016800,
  365.     0x00000542,
  366.     0x07000003,
  367.     0xc0016800,
  368.     0x000005c5,
  369.     0x00000000,
  370.     0xc0016800,
  371.     0x00000363,
  372.     0x00000000,
  373.     0xc0016800,
  374.     0x0000060c,
  375.     0x82000000,
  376.     0xc0016800,
  377.     0x0000060e,
  378.     0x01020204,
  379.     0xc0016f00,
  380.     0x00000000,
  381.     0x00000000,
  382.     0xc0016f00,
  383.     0x00000001,
  384.     0x00000000,
  385.     0xc0096900,
  386.     0x0000022a,
  387.     0x00000000,
  388.     0x00000000,
  389.     0x00000000,
  390.     0x00000000,
  391.     0x00000000,
  392.     0x00000000,
  393.     0x00000000,
  394.     0x00000000,
  395.     0x00000000,
  396.     0xc0016900,
  397.     0x00000004,
  398.     0x00000000,
  399.     0xc0016900,
  400.     0x0000000a,
  401.     0x00000000,
  402.     0xc0016900,
  403.     0x0000000b,
  404.     0x00000000,
  405.     0xc0016900,
  406.     0x0000010c,
  407.     0x00000000,
  408.     0xc0016900,
  409.     0x0000010d,
  410.     0x00000000,
  411.     0xc0016900,
  412.     0x00000200,
  413.     0x00000000,
  414.     0xc0016900,
  415.     0x00000343,
  416.     0x00000060,
  417.     0xc0016900,
  418.     0x00000344,
  419.     0x00000040,
  420.     0xc0016900,
  421.     0x00000351,
  422.     0x0000aa00,
  423.     0xc0016900,
  424.     0x00000104,
  425.     0x00000000,
  426.     0xc0016900,
  427.     0x0000010e,
  428.     0x00000000,
  429.     0xc0046900,
  430.     0x00000105,
  431.     0x00000000,
  432.     0x00000000,
  433.     0x00000000,
  434.     0x00000000,
  435.     0xc0036900,
  436.     0x00000109,
  437.     0x00000000,
  438.     0x00000000,
  439.     0x00000000,
  440.     0xc0046900,
  441.     0x0000030c,
  442.     0x01000000,
  443.     0x00000000,
  444.     0x00000000,
  445.     0x00000000,
  446.     0xc0046900,
  447.     0x00000048,
  448.     0x3f800000,
  449.     0x00000000,
  450.     0x3f800000,
  451.     0x3f800000,
  452.     0xc0016900,
  453.     0x0000008e,
  454.     0x0000000f,
  455.     0xc0016900,
  456.     0x00000080,
  457.     0x00000000,
  458.     0xc0016900,
  459.     0x00000083,
  460.     0x0000ffff,
  461.     0xc0016900,
  462.     0x00000084,
  463.     0x00000000,
  464.     0xc0016900,
  465.     0x00000085,
  466.     0x20002000,
  467.     0xc0016900,
  468.     0x00000086,
  469.     0x00000000,
  470.     0xc0016900,
  471.     0x00000087,
  472.     0x20002000,
  473.     0xc0016900,
  474.     0x00000088,
  475.     0x00000000,
  476.     0xc0016900,
  477.     0x00000089,
  478.     0x20002000,
  479.     0xc0016900,
  480.     0x0000008a,
  481.     0x00000000,
  482.     0xc0016900,
  483.     0x0000008b,
  484.     0x20002000,
  485.     0xc0016900,
  486.     0x0000008c,
  487.     0x00000000,
  488.     0xc0016900,
  489.     0x00000094,
  490.     0x80000000,
  491.     0xc0016900,
  492.     0x00000095,
  493.     0x20002000,
  494.     0xc0026900,
  495.     0x000000b4,
  496.     0x00000000,
  497.     0x3f800000,
  498.     0xc0016900,
  499.     0x00000096,
  500.     0x80000000,
  501.     0xc0016900,
  502.     0x00000097,
  503.     0x20002000,
  504.     0xc0026900,
  505.     0x000000b6,
  506.     0x00000000,
  507.     0x3f800000,
  508.     0xc0016900,
  509.     0x00000098,
  510.     0x80000000,
  511.     0xc0016900,
  512.     0x00000099,
  513.     0x20002000,
  514.     0xc0026900,
  515.     0x000000b8,
  516.     0x00000000,
  517.     0x3f800000,
  518.     0xc0016900,
  519.     0x0000009a,
  520.     0x80000000,
  521.     0xc0016900,
  522.     0x0000009b,
  523.     0x20002000,
  524.     0xc0026900,
  525.     0x000000ba,
  526.     0x00000000,
  527.     0x3f800000,
  528.     0xc0016900,
  529.     0x0000009c,
  530.     0x80000000,
  531.     0xc0016900,
  532.     0x0000009d,
  533.     0x20002000,
  534.     0xc0026900,
  535.     0x000000bc,
  536.     0x00000000,
  537.     0x3f800000,
  538.     0xc0016900,
  539.     0x0000009e,
  540.     0x80000000,
  541.     0xc0016900,
  542.     0x0000009f,
  543.     0x20002000,
  544.     0xc0026900,
  545.     0x000000be,
  546.     0x00000000,
  547.     0x3f800000,
  548.     0xc0016900,
  549.     0x000000a0,
  550.     0x80000000,
  551.     0xc0016900,
  552.     0x000000a1,
  553.     0x20002000,
  554.     0xc0026900,
  555.     0x000000c0,
  556.     0x00000000,
  557.     0x3f800000,
  558.     0xc0016900,
  559.     0x000000a2,
  560.     0x80000000,
  561.     0xc0016900,
  562.     0x000000a3,
  563.     0x20002000,
  564.     0xc0026900,
  565.     0x000000c2,
  566.     0x00000000,
  567.     0x3f800000,
  568.     0xc0016900,
  569.     0x000000a4,
  570.     0x80000000,
  571.     0xc0016900,
  572.     0x000000a5,
  573.     0x20002000,
  574.     0xc0026900,
  575.     0x000000c4,
  576.     0x00000000,
  577.     0x3f800000,
  578.     0xc0016900,
  579.     0x000000a6,
  580.     0x80000000,
  581.     0xc0016900,
  582.     0x000000a7,
  583.     0x20002000,
  584.     0xc0026900,
  585.     0x000000c6,
  586.     0x00000000,
  587.     0x3f800000,
  588.     0xc0016900,
  589.     0x000000a8,
  590.     0x80000000,
  591.     0xc0016900,
  592.     0x000000a9,
  593.     0x20002000,
  594.     0xc0026900,
  595.     0x000000c8,
  596.     0x00000000,
  597.     0x3f800000,
  598.     0xc0016900,
  599.     0x000000aa,
  600.     0x80000000,
  601.     0xc0016900,
  602.     0x000000ab,
  603.     0x20002000,
  604.     0xc0026900,
  605.     0x000000ca,
  606.     0x00000000,
  607.     0x3f800000,
  608.     0xc0016900,
  609.     0x000000ac,
  610.     0x80000000,
  611.     0xc0016900,
  612.     0x000000ad,
  613.     0x20002000,
  614.     0xc0026900,
  615.     0x000000cc,
  616.     0x00000000,
  617.     0x3f800000,
  618.     0xc0016900,
  619.     0x000000ae,
  620.     0x80000000,
  621.     0xc0016900,
  622.     0x000000af,
  623.     0x20002000,
  624.     0xc0026900,
  625.     0x000000ce,
  626.     0x00000000,
  627.     0x3f800000,
  628.     0xc0016900,
  629.     0x000000b0,
  630.     0x80000000,
  631.     0xc0016900,
  632.     0x000000b1,
  633.     0x20002000,
  634.     0xc0026900,
  635.     0x000000d0,
  636.     0x00000000,
  637.     0x3f800000,
  638.     0xc0016900,
  639.     0x000000b2,
  640.     0x80000000,
  641.     0xc0016900,
  642.     0x000000b3,
  643.     0x20002000,
  644.     0xc0026900,
  645.     0x000000d2,
  646.     0x00000000,
  647.     0x3f800000,
  648.     0xc0016900,
  649.     0x00000293,
  650.     0x00004010,
  651.     0xc0016900,
  652.     0x00000300,
  653.     0x00000000,
  654.     0xc0016900,
  655.     0x00000301,
  656.     0x00000000,
  657.     0xc0016900,
  658.     0x00000312,
  659.     0xffffffff,
  660.     0xc0016900,
  661.     0x00000307,
  662.     0x00000000,
  663.     0xc0016900,
  664.     0x00000308,
  665.     0x00000000,
  666.     0xc0016900,
  667.     0x00000283,
  668.     0x00000000,
  669.     0xc0016900,
  670.     0x00000292,
  671.     0x00000000,
  672.     0xc0066900,
  673.     0x0000010f,
  674.     0x00000000,
  675.     0x00000000,
  676.     0x00000000,
  677.     0x00000000,
  678.     0x00000000,
  679.     0x00000000,
  680.     0xc0016900,
  681.     0x00000206,
  682.     0x00000000,
  683.     0xc0016900,
  684.     0x00000207,
  685.     0x00000000,
  686.     0xc0016900,
  687.     0x00000208,
  688.     0x00000000,
  689.     0xc0046900,
  690.     0x00000303,
  691.     0x3f800000,
  692.     0x3f800000,
  693.     0x3f800000,
  694.     0x3f800000,
  695.     0xc0016900,
  696.     0x00000205,
  697.     0x00000004,
  698.     0xc0016900,
  699.     0x00000280,
  700.     0x00000000,
  701.     0xc0016900,
  702.     0x00000281,
  703.     0x00000000,
  704.     0xc0016900,
  705.     0x0000037e,
  706.     0x00000000,
  707.     0xc0016900,
  708.     0x00000382,
  709.     0x00000000,
  710.     0xc0016900,
  711.     0x00000380,
  712.     0x00000000,
  713.     0xc0016900,
  714.     0x00000383,
  715.     0x00000000,
  716.     0xc0016900,
  717.     0x00000381,
  718.     0x00000000,
  719.     0xc0016900,
  720.     0x00000282,
  721.     0x00000008,
  722.     0xc0016900,
  723.     0x00000302,
  724.     0x0000002d,
  725.     0xc0016900,
  726.     0x0000037f,
  727.     0x00000000,
  728.     0xc0016900,
  729.     0x000001b2,
  730.     0x00000000,
  731.     0xc0016900,
  732.     0x000001b6,
  733.     0x00000000,
  734.     0xc0016900,
  735.     0x000001b7,
  736.     0x00000000,
  737.     0xc0016900,
  738.     0x000001b8,
  739.     0x00000000,
  740.     0xc0016900,
  741.     0x000001b9,
  742.     0x00000000,
  743.     0xc0016900,
  744.     0x00000225,
  745.     0x00000000,
  746.     0xc0016900,
  747.     0x00000229,
  748.     0x00000000,
  749.     0xc0016900,
  750.     0x00000237,
  751.     0x00000000,
  752.     0xc0016900,
  753.     0x00000100,
  754.     0x00000800,
  755.     0xc0016900,
  756.     0x00000101,
  757.     0x00000000,
  758.     0xc0016900,
  759.     0x00000102,
  760.     0x00000000,
  761.     0xc0016900,
  762.     0x000002a8,
  763.     0x00000000,
  764.     0xc0016900,
  765.     0x000002a9,
  766.     0x00000000,
  767.     0xc0016900,
  768.     0x00000103,
  769.     0x00000000,
  770.     0xc0016900,
  771.     0x00000284,
  772.     0x00000000,
  773.     0xc0016900,
  774.     0x00000290,
  775.     0x00000000,
  776.     0xc0016900,
  777.     0x00000285,
  778.     0x00000000,
  779.     0xc0016900,
  780.     0x00000286,
  781.     0x00000000,
  782.     0xc0016900,
  783.     0x00000287,
  784.     0x00000000,
  785.     0xc0016900,
  786.     0x00000288,
  787.     0x00000000,
  788.     0xc0016900,
  789.     0x00000289,
  790.     0x00000000,
  791.     0xc0016900,
  792.     0x0000028a,
  793.     0x00000000,
  794.     0xc0016900,
  795.     0x0000028b,
  796.     0x00000000,
  797.     0xc0016900,
  798.     0x0000028c,
  799.     0x00000000,
  800.     0xc0016900,
  801.     0x0000028d,
  802.     0x00000000,
  803.     0xc0016900,
  804.     0x0000028e,
  805.     0x00000000,
  806.     0xc0016900,
  807.     0x0000028f,
  808.     0x00000000,
  809.     0xc0016900,
  810.     0x000002a1,
  811.     0x00000000,
  812.     0xc0016900,
  813.     0x000002a5,
  814.     0x00000000,
  815.     0xc0016900,
  816.     0x000002ac,
  817.     0x00000000,
  818.     0xc0016900,
  819.     0x000002ad,
  820.     0x00000000,
  821.     0xc0016900,
  822.     0x000002ae,
  823.     0x00000000,
  824.     0xc0016900,
  825.     0x000002c8,
  826.     0x00000000,
  827.     0xc0016900,
  828.     0x00000206,
  829.     0x00000100,
  830.     0xc0016900,
  831.     0x00000204,
  832.     0x00010000,
  833.     0xc0036e00,
  834.     0x00000000,
  835.     0x00000012,
  836.     0x00000000,
  837.     0x00000000,
  838.     0xc0016900,
  839.     0x0000008f,
  840.     0x0000000f,
  841.     0xc0016900,
  842.     0x000001e8,
  843.     0x00000001,
  844.     0xc0016900,
  845.     0x00000202,
  846.     0x00cc0000,
  847.     0xc0016900,
  848.     0x00000205,
  849.     0x00000244,
  850.     0xc0016900,
  851.     0x00000203,
  852.     0x00000210,
  853.     0xc0016900,
  854.     0x000001b1,
  855.     0x00000000,
  856.     0xc0016900,
  857.     0x00000185,
  858.     0x00000000,
  859.     0xc0016900,
  860.     0x000001b3,
  861.     0x00000001,
  862.     0xc0016900,
  863.     0x000001b4,
  864.     0x00000000,
  865.     0xc0016900,
  866.     0x00000191,
  867.     0x00000b00,
  868.     0xc0016900,
  869.     0x000001b5,
  870.     0x00000000,
  871. };
  872.  
  873.  
  874.  
  875. const u32 r7xx_default_state[] =
  876. {
  877.     0xc0012800,
  878.     0x80000000,
  879.     0x80000000,
  880.     0xc0004600,
  881.     0x00000016,
  882.     0xc0016800,
  883.     0x00000010,
  884.     0x00028000,
  885.     0xc0016800,
  886.     0x00000010,
  887.     0x00008000,
  888.     0xc0016800,
  889.     0x00000542,
  890.     0x07000002,
  891.     0xc0016800,
  892.     0x000005c5,
  893.     0x00000000,
  894.     0xc0016800,
  895.     0x00000363,
  896.     0x00004000,
  897.     0xc0016800,
  898.     0x0000060c,
  899.     0x00000000,
  900.     0xc0016800,
  901.     0x0000060e,
  902.     0x00420204,
  903.     0xc0016f00,
  904.     0x00000000,
  905.     0x00000000,
  906.     0xc0016f00,
  907.     0x00000001,
  908.     0x00000000,
  909.     0xc0096900,
  910.     0x0000022a,
  911.     0x00000000,
  912.     0x00000000,
  913.     0x00000000,
  914.     0x00000000,
  915.     0x00000000,
  916.     0x00000000,
  917.     0x00000000,
  918.     0x00000000,
  919.     0x00000000,
  920.     0xc0016900,
  921.     0x00000004,
  922.     0x00000000,
  923.     0xc0016900,
  924.     0x0000000a,
  925.     0x00000000,
  926.     0xc0016900,
  927.     0x0000000b,
  928.     0x00000000,
  929.     0xc0016900,
  930.     0x0000010c,
  931.     0x00000000,
  932.     0xc0016900,
  933.     0x0000010d,
  934.     0x00000000,
  935.     0xc0016900,
  936.     0x00000200,
  937.     0x00000000,
  938.     0xc0016900,
  939.     0x00000343,
  940.     0x00000060,
  941.     0xc0016900,
  942.     0x00000344,
  943.     0x00000000,
  944.     0xc0016900,
  945.     0x00000351,
  946.     0x0000aa00,
  947.     0xc0016900,
  948.     0x00000104,
  949.     0x00000000,
  950.     0xc0016900,
  951.     0x0000010e,
  952.     0x00000000,
  953.     0xc0046900,
  954.     0x00000105,
  955.     0x00000000,
  956.     0x00000000,
  957.     0x00000000,
  958.     0x00000000,
  959.     0xc0046900,
  960.     0x0000030c,
  961.     0x01000000,
  962.     0x00000000,
  963.     0x00000000,
  964.     0x00000000,
  965.     0xc0016900,
  966.     0x0000008e,
  967.     0x0000000f,
  968.     0xc0016900,
  969.     0x00000080,
  970.     0x00000000,
  971.     0xc0016900,
  972.     0x00000083,
  973.     0x0000ffff,
  974.     0xc0016900,
  975.     0x00000084,
  976.     0x00000000,
  977.     0xc0016900,
  978.     0x00000085,
  979.     0x20002000,
  980.     0xc0016900,
  981.     0x00000086,
  982.     0x00000000,
  983.     0xc0016900,
  984.     0x00000087,
  985.     0x20002000,
  986.     0xc0016900,
  987.     0x00000088,
  988.     0x00000000,
  989.     0xc0016900,
  990.     0x00000089,
  991.     0x20002000,
  992.     0xc0016900,
  993.     0x0000008a,
  994.     0x00000000,
  995.     0xc0016900,
  996.     0x0000008b,
  997.     0x20002000,
  998.     0xc0016900,
  999.     0x0000008c,
  1000.     0xaaaaaaaa,
  1001.     0xc0016900,
  1002.     0x00000094,
  1003.     0x80000000,
  1004.     0xc0016900,
  1005.     0x00000095,
  1006.     0x20002000,
  1007.     0xc0026900,
  1008.     0x000000b4,
  1009.     0x00000000,
  1010.     0x3f800000,
  1011.     0xc0016900,
  1012.     0x00000096,
  1013.     0x80000000,
  1014.     0xc0016900,
  1015.     0x00000097,
  1016.     0x20002000,
  1017.     0xc0026900,
  1018.     0x000000b6,
  1019.     0x00000000,
  1020.     0x3f800000,
  1021.     0xc0016900,
  1022.     0x00000098,
  1023.     0x80000000,
  1024.     0xc0016900,
  1025.     0x00000099,
  1026.     0x20002000,
  1027.     0xc0026900,
  1028.     0x000000b8,
  1029.     0x00000000,
  1030.     0x3f800000,
  1031.     0xc0016900,
  1032.     0x0000009a,
  1033.     0x80000000,
  1034.     0xc0016900,
  1035.     0x0000009b,
  1036.     0x20002000,
  1037.     0xc0026900,
  1038.     0x000000ba,
  1039.     0x00000000,
  1040.     0x3f800000,
  1041.     0xc0016900,
  1042.     0x0000009c,
  1043.     0x80000000,
  1044.     0xc0016900,
  1045.     0x0000009d,
  1046.     0x20002000,
  1047.     0xc0026900,
  1048.     0x000000bc,
  1049.     0x00000000,
  1050.     0x3f800000,
  1051.     0xc0016900,
  1052.     0x0000009e,
  1053.     0x80000000,
  1054.     0xc0016900,
  1055.     0x0000009f,
  1056.     0x20002000,
  1057.     0xc0026900,
  1058.     0x000000be,
  1059.     0x00000000,
  1060.     0x3f800000,
  1061.     0xc0016900,
  1062.     0x000000a0,
  1063.     0x80000000,
  1064.     0xc0016900,
  1065.     0x000000a1,
  1066.     0x20002000,
  1067.     0xc0026900,
  1068.     0x000000c0,
  1069.     0x00000000,
  1070.     0x3f800000,
  1071.     0xc0016900,
  1072.     0x000000a2,
  1073.     0x80000000,
  1074.     0xc0016900,
  1075.     0x000000a3,
  1076.     0x20002000,
  1077.     0xc0026900,
  1078.     0x000000c2,
  1079.     0x00000000,
  1080.     0x3f800000,
  1081.     0xc0016900,
  1082.     0x000000a4,
  1083.     0x80000000,
  1084.     0xc0016900,
  1085.     0x000000a5,
  1086.     0x20002000,
  1087.     0xc0026900,
  1088.     0x000000c4,
  1089.     0x00000000,
  1090.     0x3f800000,
  1091.     0xc0016900,
  1092.     0x000000a6,
  1093.     0x80000000,
  1094.     0xc0016900,
  1095.     0x000000a7,
  1096.     0x20002000,
  1097.     0xc0026900,
  1098.     0x000000c6,
  1099.     0x00000000,
  1100.     0x3f800000,
  1101.     0xc0016900,
  1102.     0x000000a8,
  1103.     0x80000000,
  1104.     0xc0016900,
  1105.     0x000000a9,
  1106.     0x20002000,
  1107.     0xc0026900,
  1108.     0x000000c8,
  1109.     0x00000000,
  1110.     0x3f800000,
  1111.     0xc0016900,
  1112.     0x000000aa,
  1113.     0x80000000,
  1114.     0xc0016900,
  1115.     0x000000ab,
  1116.     0x20002000,
  1117.     0xc0026900,
  1118.     0x000000ca,
  1119.     0x00000000,
  1120.     0x3f800000,
  1121.     0xc0016900,
  1122.     0x000000ac,
  1123.     0x80000000,
  1124.     0xc0016900,
  1125.     0x000000ad,
  1126.     0x20002000,
  1127.     0xc0026900,
  1128.     0x000000cc,
  1129.     0x00000000,
  1130.     0x3f800000,
  1131.     0xc0016900,
  1132.     0x000000ae,
  1133.     0x80000000,
  1134.     0xc0016900,
  1135.     0x000000af,
  1136.     0x20002000,
  1137.     0xc0026900,
  1138.     0x000000ce,
  1139.     0x00000000,
  1140.     0x3f800000,
  1141.     0xc0016900,
  1142.     0x000000b0,
  1143.     0x80000000,
  1144.     0xc0016900,
  1145.     0x000000b1,
  1146.     0x20002000,
  1147.     0xc0026900,
  1148.     0x000000d0,
  1149.     0x00000000,
  1150.     0x3f800000,
  1151.     0xc0016900,
  1152.     0x000000b2,
  1153.     0x80000000,
  1154.     0xc0016900,
  1155.     0x000000b3,
  1156.     0x20002000,
  1157.     0xc0026900,
  1158.     0x000000d2,
  1159.     0x00000000,
  1160.     0x3f800000,
  1161.     0xc0016900,
  1162.     0x00000293,
  1163.     0x00514000,
  1164.     0xc0016900,
  1165.     0x00000300,
  1166.     0x00000000,
  1167.     0xc0016900,
  1168.     0x00000301,
  1169.     0x00000000,
  1170.     0xc0016900,
  1171.     0x00000312,
  1172.     0xffffffff,
  1173.     0xc0016900,
  1174.     0x00000307,
  1175.     0x00000000,
  1176.     0xc0016900,
  1177.     0x00000308,
  1178.     0x00000000,
  1179.     0xc0016900,
  1180.     0x00000283,
  1181.     0x00000000,
  1182.     0xc0016900,
  1183.     0x00000292,
  1184.     0x00000000,
  1185.     0xc0066900,
  1186.     0x0000010f,
  1187.     0x00000000,
  1188.     0x00000000,
  1189.     0x00000000,
  1190.     0x00000000,
  1191.     0x00000000,
  1192.     0x00000000,
  1193.     0xc0016900,
  1194.     0x00000206,
  1195.     0x00000000,
  1196.     0xc0016900,
  1197.     0x00000207,
  1198.     0x00000000,
  1199.     0xc0016900,
  1200.     0x00000208,
  1201.     0x00000000,
  1202.     0xc0046900,
  1203.     0x00000303,
  1204.     0x3f800000,
  1205.     0x3f800000,
  1206.     0x3f800000,
  1207.     0x3f800000,
  1208.     0xc0016900,
  1209.     0x00000205,
  1210.     0x00000004,
  1211.     0xc0016900,
  1212.     0x00000280,
  1213.     0x00000000,
  1214.     0xc0016900,
  1215.     0x00000281,
  1216.     0x00000000,
  1217.     0xc0016900,
  1218.     0x0000037e,
  1219.     0x00000000,
  1220.     0xc0016900,
  1221.     0x00000382,
  1222.     0x00000000,
  1223.     0xc0016900,
  1224.     0x00000380,
  1225.     0x00000000,
  1226.     0xc0016900,
  1227.     0x00000383,
  1228.     0x00000000,
  1229.     0xc0016900,
  1230.     0x00000381,
  1231.     0x00000000,
  1232.     0xc0016900,
  1233.     0x00000282,
  1234.     0x00000008,
  1235.     0xc0016900,
  1236.     0x00000302,
  1237.     0x0000002d,
  1238.     0xc0016900,
  1239.     0x0000037f,
  1240.     0x00000000,
  1241.     0xc0016900,
  1242.     0x000001b2,
  1243.     0x00000001,
  1244.     0xc0016900,
  1245.     0x000001b6,
  1246.     0x00000000,
  1247.     0xc0016900,
  1248.     0x000001b7,
  1249.     0x00000000,
  1250.     0xc0016900,
  1251.     0x000001b8,
  1252.     0x00000000,
  1253.     0xc0016900,
  1254.     0x000001b9,
  1255.     0x00000000,
  1256.     0xc0016900,
  1257.     0x00000225,
  1258.     0x00000000,
  1259.     0xc0016900,
  1260.     0x00000229,
  1261.     0x00000000,
  1262.     0xc0016900,
  1263.     0x00000237,
  1264.     0x00000000,
  1265.     0xc0016900,
  1266.     0x00000100,
  1267.     0x00000800,
  1268.     0xc0016900,
  1269.     0x00000101,
  1270.     0x00000000,
  1271.     0xc0016900,
  1272.     0x00000102,
  1273.     0x00000000,
  1274.     0xc0016900,
  1275.     0x000002a8,
  1276.     0x00000000,
  1277.     0xc0016900,
  1278.     0x000002a9,
  1279.     0x00000000,
  1280.     0xc0016900,
  1281.     0x00000103,
  1282.     0x00000000,
  1283.     0xc0016900,
  1284.     0x00000284,
  1285.     0x00000000,
  1286.     0xc0016900,
  1287.     0x00000290,
  1288.     0x00000000,
  1289.     0xc0016900,
  1290.     0x00000285,
  1291.     0x00000000,
  1292.     0xc0016900,
  1293.     0x00000286,
  1294.     0x00000000,
  1295.     0xc0016900,
  1296.     0x00000287,
  1297.     0x00000000,
  1298.     0xc0016900,
  1299.     0x00000288,
  1300.     0x00000000,
  1301.     0xc0016900,
  1302.     0x00000289,
  1303.     0x00000000,
  1304.     0xc0016900,
  1305.     0x0000028a,
  1306.     0x00000000,
  1307.     0xc0016900,
  1308.     0x0000028b,
  1309.     0x00000000,
  1310.     0xc0016900,
  1311.     0x0000028c,
  1312.     0x00000000,
  1313.     0xc0016900,
  1314.     0x0000028d,
  1315.     0x00000000,
  1316.     0xc0016900,
  1317.     0x0000028e,
  1318.     0x00000000,
  1319.     0xc0016900,
  1320.     0x0000028f,
  1321.     0x00000000,
  1322.     0xc0016900,
  1323.     0x000002a1,
  1324.     0x00000000,
  1325.     0xc0016900,
  1326.     0x000002a5,
  1327.     0x00000000,
  1328.     0xc0016900,
  1329.     0x000002ac,
  1330.     0x00000000,
  1331.     0xc0016900,
  1332.     0x000002ad,
  1333.     0x00000000,
  1334.     0xc0016900,
  1335.     0x000002ae,
  1336.     0x00000000,
  1337.     0xc0016900,
  1338.     0x000002c8,
  1339.     0x00000000,
  1340.     0xc0016900,
  1341.     0x00000206,
  1342.     0x00000100,
  1343.     0xc0016900,
  1344.     0x00000204,
  1345.     0x00010000,
  1346.     0xc0036e00,
  1347.     0x00000000,
  1348.     0x00000012,
  1349.     0x00000000,
  1350.     0x00000000,
  1351.     0xc0016900,
  1352.     0x0000008f,
  1353.     0x0000000f,
  1354.     0xc0016900,
  1355.     0x000001e8,
  1356.     0x00000001,
  1357.     0xc0016900,
  1358.     0x00000202,
  1359.     0x00cc0000,
  1360.     0xc0016900,
  1361.     0x00000205,
  1362.     0x00000244,
  1363.     0xc0016900,
  1364.     0x00000203,
  1365.     0x00000210,
  1366.     0xc0016900,
  1367.     0x000001b1,
  1368.     0x00000000,
  1369.     0xc0016900,
  1370.     0x00000185,
  1371.     0x00000000,
  1372.     0xc0016900,
  1373.     0x000001b3,
  1374.     0x00000001,
  1375.     0xc0016900,
  1376.     0x000001b4,
  1377.     0x00000000,
  1378.     0xc0016900,
  1379.     0x00000191,
  1380.     0x00000b00,
  1381.     0xc0016900,
  1382.     0x000001b5,
  1383.     0x00000000,
  1384. };
  1385.  
  1386. const u32 r6xx_default_size = ARRAY_SIZE(r6xx_default_state);
  1387. const u32 r7xx_default_size = ARRAY_SIZE(r7xx_default_state);
  1388.  
  1389.  
  1390. int R600_solid_ps(struct radeon_device *rdev, uint32_t* shader);
  1391. int R600_solid_vs(struct radeon_device *rdev, uint32_t* shader);
  1392.  
  1393. #define COLOR_8_8_8_8         0x1a
  1394.  
  1395. /* emits 21 on rv770+, 23 on r600 */
  1396. static void
  1397. set_render_target(struct radeon_device *rdev, int format,
  1398.           int w, int h, u64 gpu_addr)
  1399. {
  1400.     u32 cb_color_info;
  1401.     int pitch, slice;
  1402.  
  1403.     h = (h + 7) & ~7;
  1404.     if (h < 8)
  1405.         h = 8;
  1406.  
  1407.     cb_color_info = ((format << 2) | (1 << 27));
  1408.     pitch = (w / 8) - 1;
  1409.     slice = ((w * h) / 64) - 1;
  1410.  
  1411.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1412.     radeon_ring_write(rdev, (CB_COLOR0_BASE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1413.     radeon_ring_write(rdev, gpu_addr >> 8);
  1414.  
  1415.     if (rdev->family > CHIP_R600 && rdev->family < CHIP_RV770) {
  1416.         radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_BASE_UPDATE, 0));
  1417.         radeon_ring_write(rdev, 2 << 0);
  1418.     }
  1419.  
  1420.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1421.     radeon_ring_write(rdev, (CB_COLOR0_SIZE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1422.     radeon_ring_write(rdev, (pitch << 0) | (slice << 10));
  1423.  
  1424.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1425.     radeon_ring_write(rdev, (CB_COLOR0_VIEW - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1426.     radeon_ring_write(rdev, 0);
  1427.  
  1428.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1429.     radeon_ring_write(rdev, (CB_COLOR0_INFO - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1430.     radeon_ring_write(rdev, cb_color_info);
  1431.  
  1432.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1433.     radeon_ring_write(rdev, (CB_COLOR0_TILE - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1434.     radeon_ring_write(rdev, 0);
  1435.  
  1436.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1437.     radeon_ring_write(rdev, (CB_COLOR0_FRAG - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1438.     radeon_ring_write(rdev, 0);
  1439.  
  1440.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  1441.     radeon_ring_write(rdev, (CB_COLOR0_MASK - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1442.     radeon_ring_write(rdev, 0);
  1443. }
  1444.  
  1445.  
  1446. /* emits 5dw */
  1447. static void
  1448. cp_set_surface_sync(struct radeon_device *rdev,
  1449.             u32 sync_type, u32 size,
  1450.             u64 mc_addr)
  1451. {
  1452.     u32 cp_coher_size;
  1453.  
  1454.     if (size == 0xffffffff)
  1455.         cp_coher_size = 0xffffffff;
  1456.     else
  1457.         cp_coher_size = ((size + 255) >> 8);
  1458.  
  1459.     radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_SYNC, 3));
  1460.     radeon_ring_write(rdev, sync_type);
  1461.     radeon_ring_write(rdev, cp_coher_size);
  1462.     radeon_ring_write(rdev, mc_addr >> 8);
  1463.     radeon_ring_write(rdev, 10); /* poll interval */
  1464. }
  1465.  
  1466. /* emits 14 */
  1467. static void
  1468. set_default_state(struct radeon_device *rdev,
  1469.                   u64 state_gpu_addr, u32 state_len)
  1470. {
  1471.     u32 sq_config, sq_gpr_resource_mgmt_1, sq_gpr_resource_mgmt_2;
  1472.     u32 sq_thread_resource_mgmt, sq_stack_resource_mgmt_1, sq_stack_resource_mgmt_2;
  1473.     int num_ps_gprs, num_vs_gprs, num_temp_gprs, num_gs_gprs, num_es_gprs;
  1474.     int num_ps_threads, num_vs_threads, num_gs_threads, num_es_threads;
  1475.     int num_ps_stack_entries, num_vs_stack_entries, num_gs_stack_entries, num_es_stack_entries;
  1476.     u64 gpu_addr;
  1477.     int dwords;
  1478.  
  1479.     switch (rdev->family) {
  1480.     case CHIP_R600:
  1481.         num_ps_gprs = 192;
  1482.         num_vs_gprs = 56;
  1483.         num_temp_gprs = 4;
  1484.         num_gs_gprs = 0;
  1485.         num_es_gprs = 0;
  1486.         num_ps_threads = 136;
  1487.         num_vs_threads = 48;
  1488.         num_gs_threads = 4;
  1489.         num_es_threads = 4;
  1490.         num_ps_stack_entries = 128;
  1491.         num_vs_stack_entries = 128;
  1492.         num_gs_stack_entries = 0;
  1493.         num_es_stack_entries = 0;
  1494.         break;
  1495.     case CHIP_RV630:
  1496.     case CHIP_RV635:
  1497.         num_ps_gprs = 84;
  1498.         num_vs_gprs = 36;
  1499.         num_temp_gprs = 4;
  1500.         num_gs_gprs = 0;
  1501.         num_es_gprs = 0;
  1502.         num_ps_threads = 144;
  1503.         num_vs_threads = 40;
  1504.         num_gs_threads = 4;
  1505.         num_es_threads = 4;
  1506.         num_ps_stack_entries = 40;
  1507.         num_vs_stack_entries = 40;
  1508.         num_gs_stack_entries = 32;
  1509.         num_es_stack_entries = 16;
  1510.         break;
  1511.     case CHIP_RV610:
  1512.     case CHIP_RV620:
  1513.     case CHIP_RS780:
  1514.     case CHIP_RS880:
  1515.     default:
  1516.         num_ps_gprs = 84;
  1517.         num_vs_gprs = 36;
  1518.         num_temp_gprs = 4;
  1519.         num_gs_gprs = 0;
  1520.         num_es_gprs = 0;
  1521.         num_ps_threads = 136;
  1522.         num_vs_threads = 48;
  1523.         num_gs_threads = 4;
  1524.         num_es_threads = 4;
  1525.         num_ps_stack_entries = 40;
  1526.         num_vs_stack_entries = 40;
  1527.         num_gs_stack_entries = 32;
  1528.         num_es_stack_entries = 16;
  1529.         break;
  1530.     case CHIP_RV670:
  1531.         num_ps_gprs = 144;
  1532.         num_vs_gprs = 40;
  1533.         num_temp_gprs = 4;
  1534.         num_gs_gprs = 0;
  1535.         num_es_gprs = 0;
  1536.         num_ps_threads = 136;
  1537.         num_vs_threads = 48;
  1538.         num_gs_threads = 4;
  1539.         num_es_threads = 4;
  1540.         num_ps_stack_entries = 40;
  1541.         num_vs_stack_entries = 40;
  1542.         num_gs_stack_entries = 32;
  1543.         num_es_stack_entries = 16;
  1544.         break;
  1545.     case CHIP_RV770:
  1546.         num_ps_gprs = 192;
  1547.         num_vs_gprs = 56;
  1548.         num_temp_gprs = 4;
  1549.         num_gs_gprs = 0;
  1550.         num_es_gprs = 0;
  1551.         num_ps_threads = 188;
  1552.         num_vs_threads = 60;
  1553.         num_gs_threads = 0;
  1554.         num_es_threads = 0;
  1555.         num_ps_stack_entries = 256;
  1556.         num_vs_stack_entries = 256;
  1557.         num_gs_stack_entries = 0;
  1558.         num_es_stack_entries = 0;
  1559.         break;
  1560.     case CHIP_RV730:
  1561.     case CHIP_RV740:
  1562.         num_ps_gprs = 84;
  1563.         num_vs_gprs = 36;
  1564.         num_temp_gprs = 4;
  1565.         num_gs_gprs = 0;
  1566.         num_es_gprs = 0;
  1567.         num_ps_threads = 188;
  1568.         num_vs_threads = 60;
  1569.         num_gs_threads = 0;
  1570.         num_es_threads = 0;
  1571.         num_ps_stack_entries = 128;
  1572.         num_vs_stack_entries = 128;
  1573.         num_gs_stack_entries = 0;
  1574.         num_es_stack_entries = 0;
  1575.         break;
  1576.     case CHIP_RV710:
  1577.         num_ps_gprs = 192;
  1578.         num_vs_gprs = 56;
  1579.         num_temp_gprs = 4;
  1580.         num_gs_gprs = 0;
  1581.         num_es_gprs = 0;
  1582.         num_ps_threads = 144;
  1583.         num_vs_threads = 48;
  1584.         num_gs_threads = 0;
  1585.         num_es_threads = 0;
  1586.         num_ps_stack_entries = 128;
  1587.         num_vs_stack_entries = 128;
  1588.         num_gs_stack_entries = 0;
  1589.         num_es_stack_entries = 0;
  1590.         break;
  1591.     }
  1592.  
  1593.     if ((rdev->family == CHIP_RV610) ||
  1594.         (rdev->family == CHIP_RV620) ||
  1595.         (rdev->family == CHIP_RS780) ||
  1596.         (rdev->family == CHIP_RS880) ||
  1597.         (rdev->family == CHIP_RV710))
  1598.         sq_config = 0;
  1599.     else
  1600.         sq_config = VC_ENABLE;
  1601.  
  1602.     sq_config |= (DX9_CONSTS |
  1603.               ALU_INST_PREFER_VECTOR |
  1604.               PS_PRIO(0) |
  1605.               VS_PRIO(1) |
  1606.               GS_PRIO(2) |
  1607.               ES_PRIO(3));
  1608.  
  1609.     sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(num_ps_gprs) |
  1610.                   NUM_VS_GPRS(num_vs_gprs) |
  1611.                   NUM_CLAUSE_TEMP_GPRS(num_temp_gprs));
  1612.     sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(num_gs_gprs) |
  1613.                   NUM_ES_GPRS(num_es_gprs));
  1614.     sq_thread_resource_mgmt = (NUM_PS_THREADS(num_ps_threads) |
  1615.                    NUM_VS_THREADS(num_vs_threads) |
  1616.                    NUM_GS_THREADS(num_gs_threads) |
  1617.                    NUM_ES_THREADS(num_es_threads));
  1618.     sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(num_ps_stack_entries) |
  1619.                     NUM_VS_STACK_ENTRIES(num_vs_stack_entries));
  1620.     sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(num_gs_stack_entries) |
  1621.                     NUM_ES_STACK_ENTRIES(num_es_stack_entries));
  1622.  
  1623.     /* emit an IB pointing at default state */
  1624.     dwords   = (state_len + 0xf) & ~0xf;
  1625.     gpu_addr = state_gpu_addr;
  1626.  
  1627.     radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  1628.     radeon_ring_write(rdev, gpu_addr & 0xFFFFFFFC);
  1629.     radeon_ring_write(rdev, upper_32_bits(gpu_addr) & 0xFF);
  1630.     radeon_ring_write(rdev, dwords);
  1631.  
  1632.     radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
  1633.     radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
  1634.     /* SQ config */
  1635.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 6));
  1636.     radeon_ring_write(rdev, (SQ_CONFIG - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  1637.     radeon_ring_write(rdev, sq_config);
  1638.     radeon_ring_write(rdev, sq_gpr_resource_mgmt_1);
  1639.     radeon_ring_write(rdev, sq_gpr_resource_mgmt_2);
  1640.     radeon_ring_write(rdev, sq_thread_resource_mgmt);
  1641.     radeon_ring_write(rdev, sq_stack_resource_mgmt_1);
  1642.     radeon_ring_write(rdev, sq_stack_resource_mgmt_2);
  1643. }
  1644.  
  1645. /* emits 12 */
  1646. static void
  1647. set_scissors(struct radeon_device *rdev, int x1, int y1,
  1648.          int x2, int y2)
  1649. {
  1650.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  1651.     radeon_ring_write(rdev, (PA_SC_SCREEN_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1652.     radeon_ring_write(rdev, (x1 << 0) | (y1 << 16));
  1653.     radeon_ring_write(rdev, (x2 << 0) | (y2 << 16));
  1654.  
  1655.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  1656.     radeon_ring_write(rdev, (PA_SC_GENERIC_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1657.     radeon_ring_write(rdev, (x1 << 0) | (y1 << 16) | (1 << 31));
  1658.     radeon_ring_write(rdev, (x2 << 0) | (y2 << 16));
  1659.  
  1660.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
  1661.     radeon_ring_write(rdev, (PA_SC_WINDOW_SCISSOR_TL - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  1662.     radeon_ring_write(rdev, (x1 << 0) | (y1 << 16) | (1 << 31));
  1663.     radeon_ring_write(rdev, (x2 << 0) | (y2 << 16));
  1664. }
  1665.  
  1666. static void
  1667. draw_auto(struct radeon_device *rdev)
  1668. {
  1669.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1670.     radeon_ring_write(rdev, (VGT_PRIMITIVE_TYPE - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  1671.     radeon_ring_write(rdev, DI_PT_RECTLIST);
  1672.  
  1673.     radeon_ring_write(rdev, PACKET3(PACKET3_INDEX_TYPE, 0));
  1674.     radeon_ring_write(rdev, DI_INDEX_SIZE_16_BIT);
  1675.  
  1676.     radeon_ring_write(rdev, PACKET3(PACKET3_NUM_INSTANCES, 0));
  1677.     radeon_ring_write(rdev, 1);
  1678.  
  1679.     radeon_ring_write(rdev, PACKET3(PACKET3_DRAW_INDEX_AUTO, 1));
  1680.     radeon_ring_write(rdev, 3);
  1681.     radeon_ring_write(rdev, DI_SRC_SEL_AUTO_INDEX);
  1682.  
  1683. }
  1684.  
  1685. /* ALU clause insts */
  1686. #define SRC0_SEL(x)        (x)
  1687. #define SRC1_SEL(x)        (x)
  1688. #define SRC2_SEL(x)        (x)
  1689. /* src[0-2]_sel */
  1690. /*   0-127 GPR */
  1691. /* 128-159 kcache constants bank 0 */
  1692. /* 160-191 kcache constants bank 1 */
  1693. /* 248-255 special SQ_ALU_SRC_* (0, 1, etc.) */
  1694.  
  1695. #define SRC0_REL(x)        (x)
  1696. #define SRC1_REL(x)        (x)
  1697. #define SRC2_REL(x)        (x)
  1698. /* elem */
  1699. #define SRC0_ELEM(x)        (x)
  1700. #define SRC1_ELEM(x)        (x)
  1701. #define SRC2_ELEM(x)        (x)
  1702. #define ELEM_X        0
  1703. #define ELEM_Y        1
  1704. #define ELEM_Z        2
  1705. #define ELEM_W        3
  1706. /* neg */
  1707. #define SRC0_NEG(x)        (x)
  1708. #define SRC1_NEG(x)        (x)
  1709. #define SRC2_NEG(x)        (x)
  1710. /* im */
  1711. #define INDEX_MODE(x)    (x)        /* SQ_INDEX_* */
  1712. /* ps */
  1713. #define PRED_SEL(x)      (x)        /* SQ_PRED_SEL_* */
  1714. /* last */
  1715. #define LAST(x)          (x)
  1716. /* abs */
  1717. #define SRC0_ABS(x)       (x)
  1718. #define SRC1_ABS(x)       (x)
  1719. /* uem */
  1720. #define UPDATE_EXECUTE_MASK(x) (x)
  1721. /* up */
  1722. #define UPDATE_PRED(x)      (x)
  1723. /* wm */
  1724. #define WRITE_MASK(x)   (x)
  1725. /* fm */
  1726. #define FOG_MERGE(x)    (x)
  1727. /* omod */
  1728. #define OMOD(x)        (x)      /* SQ_ALU_OMOD_* */
  1729. /* alu inst */
  1730. #define ALU_INST(x)        (x)      /* SQ_ALU_INST_* */
  1731. /*bs */
  1732. #define BANK_SWIZZLE(x)        (x)  /* SQ_ALU_VEC_* */
  1733. #define DST_GPR(x)        (x)
  1734. #define DST_REL(x)        (x)
  1735. #define DST_ELEM(x)       (x)
  1736. #define CLAMP(x)          (x)
  1737.  
  1738. #define ALU_DWORD0(src0_sel, s0r, s0e, s0n, src1_sel, s1r, s1e, s1n, im, ps, last) \
  1739.         (((src0_sel) << 0) | ((s0r) << 9) | ((s0e) << 10) | ((s0n) << 12) | \
  1740.          ((src1_sel) << 13) | ((s1r) << 22) | ((s1e) << 23) | ((s1n) << 25) | \
  1741.      ((im) << 26) | ((ps) << 29) | ((last) << 31))
  1742.  
  1743. /* R7xx has alu_inst at a different slot, and no fog merge any more (no fix function fog any more) */
  1744. #define R6xx_ALU_DWORD1_OP2(s0a, s1a, uem, up, wm, fm, omod, alu_inst, bs, dst_gpr, dr, de, clamp) \
  1745.         (((s0a) << 0) | ((s1a) << 1) | ((uem) << 2) | ((up) << 3) | ((wm) << 4) | \
  1746.          ((fm) << 5) | ((omod) << 6) | ((alu_inst) << 8) | ((bs) << 18) | ((dst_gpr) << 21) | \
  1747.      ((dr) << 28) | ((de) << 29) | ((clamp) << 31))
  1748.  
  1749. #define R7xx_ALU_DWORD1_OP2(s0a, s1a, uem, up, wm, omod, alu_inst, bs, dst_gpr, dr, de, clamp) \
  1750.         (((s0a) << 0) | ((s1a) << 1) | ((uem) << 2) | ((up) << 3) | ((wm) << 4) | \
  1751.          ((omod) << 5) | ((alu_inst) << 7) | ((bs) << 18) | ((dst_gpr) << 21) | \
  1752.      ((dr) << 28) | ((de) << 29) | ((clamp) << 31))
  1753.  
  1754. /* This is a general chipset macro, but due to selection by chipid typically not usable in static arrays */
  1755. /* Fog is NOT USED on R7xx, even if specified. */
  1756. #define ALU_DWORD1_OP2(chipid, s0a, s1a, uem, up, wm, fm, omod, alu_inst, bs, dst_gpr, dr, de, clamp) \
  1757.     ((chipid) < CHIP_RV770 ? \
  1758.      R6xx_ALU_DWORD1_OP2(s0a, s1a, uem, up, wm, fm, omod, alu_inst, bs, dst_gpr, dr, de, clamp) : \
  1759.      R7xx_ALU_DWORD1_OP2(s0a, s1a, uem, up, wm, omod, alu_inst, bs, dst_gpr, dr, de, clamp))
  1760.  
  1761. #define ALU_DWORD1_OP3(src2_sel, s2r, s2e, s2n, alu_inst, bs, dst_gpr, dr, de, clamp) \
  1762.         (((src2_sel) << 0) | ((s2r) << 9) | ((s2e) << 10) | ((s2n) << 12) | \
  1763.          ((alu_inst) << 13) | ((bs) << 18) | ((dst_gpr) << 21) | ((dr) << 28) | \
  1764.      ((de) << 29) | ((clamp) << 31))
  1765.  
  1766. /* CF insts */
  1767. /* addr */
  1768. #define ADDR(x)  (x)
  1769. /* pc */
  1770. #define POP_COUNT(x)      (x)
  1771. /* const */
  1772. #define CF_CONST(x)       (x)
  1773. /* cond */
  1774. #define COND(x)        (x)      /* SQ_COND_* */
  1775. /* count */
  1776. #define I_COUNT(x)        ((x) ? ((x) - 1) : 0)
  1777. /*r7xx */
  1778. #define COUNT_3(x)        (x)
  1779. /* call count */
  1780. #define CALL_COUNT(x)     (x)
  1781. /* eop */
  1782. #define END_OF_PROGRAM(x)   (x)
  1783. /* vpm */
  1784. #define VALID_PIXEL_MODE(x) (x)
  1785. /* cf inst */
  1786. #define CF_INST(x)        (x)       /* SQ_CF_INST_* */
  1787.  
  1788. /* wqm */
  1789. #define WHOLE_QUAD_MODE(x)  (x)
  1790. /* barrier */
  1791. #define BARRIER(x)          (x)
  1792. /*kb0 */
  1793. #define KCACHE_BANK0(x)          (x)
  1794. /*kb1 */
  1795. #define KCACHE_BANK1(x)          (x)
  1796. /* km0/1 */
  1797. #define KCACHE_MODE0(x)          (x)
  1798. #define KCACHE_MODE1(x)          (x)    /* SQ_CF_KCACHE_* */
  1799. /* */
  1800. #define KCACHE_ADDR0(x)          (x)
  1801. #define KCACHE_ADDR1(x)          (x)
  1802. /* uw */
  1803. #define USES_WATERFALL(x)        (x)
  1804.  
  1805. #define ARRAY_BASE(x)        (x)
  1806. /* export pixel */
  1807. #define CF_PIXEL_MRT0         0
  1808. #define CF_PIXEL_MRT1         1
  1809. #define CF_PIXEL_MRT2         2
  1810. #define CF_PIXEL_MRT3         3
  1811. #define CF_PIXEL_MRT4         4
  1812. #define CF_PIXEL_MRT5         5
  1813. #define CF_PIXEL_MRT6         6
  1814. #define CF_PIXEL_MRT7         7
  1815. /* *_FOG: r6xx only */
  1816. #define CF_PIXEL_MRT0_FOG     16
  1817. #define CF_PIXEL_MRT1_FOG     17
  1818. #define CF_PIXEL_MRT2_FOG     18
  1819. #define CF_PIXEL_MRT3_FOG     19
  1820. #define CF_PIXEL_MRT4_FOG     20
  1821. #define CF_PIXEL_MRT5_FOG     21
  1822. #define CF_PIXEL_MRT6_FOG     22
  1823. #define CF_PIXEL_MRT7_FOG     23
  1824. #define CF_PIXEL_Z            61
  1825. /* export pos */
  1826. #define CF_POS0               60
  1827. #define CF_POS1               61
  1828. #define CF_POS2               62
  1829. #define CF_POS3               63
  1830. /* export param */
  1831. /* 0...31 */
  1832. #define TYPE(x)              (x)    /* SQ_EXPORT_* */
  1833. #if 0
  1834. /* type export */
  1835. #define SQ_EXPORT_PIXEL              0
  1836. #define SQ_EXPORT_POS                1
  1837. #define SQ_EXPORT_PARAM              2
  1838. /* reserved 3 */
  1839. /* type mem */
  1840. #define SQ_EXPORT_WRITE              0
  1841. #define SQ_EXPORT_WRITE_IND          1
  1842. #define SQ_EXPORT_WRITE_ACK          2
  1843. #define SQ_EXPORT_WRITE_IND_ACK      3
  1844. #endif
  1845.  
  1846. #define RW_GPR(x)            (x)
  1847. #define RW_REL(x)            (x)
  1848. #define ABSOLUTE                  0
  1849. #define RELATIVE                  1
  1850. #define INDEX_GPR(x)            (x)
  1851. #define ELEM_SIZE(x)            (x ? (x - 1) : 0)
  1852. #define COMP_MASK(x)            (x)
  1853. #define R6xx_ELEM_LOOP(x)            (x)
  1854. #define BURST_COUNT(x)          (x ? (x - 1) : 0)
  1855.  
  1856. /* swiz */
  1857. #define SRC_SEL_X(x)    (x)     /* SQ_SEL_* each */
  1858. #define SRC_SEL_Y(x)    (x)
  1859. #define SRC_SEL_Z(x)    (x)
  1860. #define SRC_SEL_W(x)    (x)
  1861.  
  1862. #define CF_DWORD0(addr) (addr)
  1863. /* R7xx has another entry (COUNT3), but that is only used for adding a bit to count. */
  1864. /* We allow one more bit for count in the argument of the macro on R7xx instead. */
  1865. /* R6xx: [0,7]  R7xx: [1,16] */
  1866. #define CF_DWORD1(pc, cf_const, cond, count, call_count, eop, vpm, cf_inst, wqm, b) \
  1867.         (((pc) << 0) | ((cf_const) << 3) | ((cond) << 8) | (((count) & 7) << 10) | (((count) >> 3) << 19) | \
  1868.          ((call_count) << 13) | ((eop) << 21) | ((vpm) << 22) | ((cf_inst) << 23) | ((wqm) << 30) | ((b) << 31))
  1869.  
  1870. #define CF_ALU_DWORD0(addr, kb0, kb1, km0) (((addr) << 0) | ((kb0) << 22) | ((kb1) << 26) | ((km0) << 30))
  1871. #define CF_ALU_DWORD1(km1, kcache_addr0, kcache_addr1, count, uw, cf_inst, wqm, b) \
  1872.         (((km1) << 0) | ((kcache_addr0) << 2) | ((kcache_addr1) << 10) | \
  1873.      ((count) << 18) | ((uw) << 25) | ((cf_inst) << 26) | ((wqm) << 30) | ((b) << 31))
  1874.  
  1875. #define CF_ALLOC_IMP_EXP_DWORD0(array_base, type, rw_gpr, rr, index_gpr, es) \
  1876.      (((array_base) << 0) | ((type) << 13) | ((rw_gpr) << 15) | ((rr) << 22) | ((index_gpr) << 23) | \
  1877.           ((es) << 30))
  1878. /* R7xx apparently doesn't have the ELEM_LOOP entry any more */
  1879. /* We still expose it, but ELEM_LOOP is explicitely R6xx now. */
  1880. /* TODO: is this just forgotten in the docs, or really not available any more? */
  1881. #define CF_ALLOC_IMP_EXP_DWORD1_BUF(array_size, comp_mask, el, bc, eop, vpm, cf_inst, wqm, b) \
  1882.         (((array_size) << 0) | ((comp_mask) << 12) | ((el) << 16) | ((bc) << 17) | \
  1883.      ((eop) << 21) | ((vpm) << 22) | ((cf_inst) << 23) | ((wqm) << 30) | ((b) << 31))
  1884. #define CF_ALLOC_IMP_EXP_DWORD1_SWIZ(sel_x, sel_y, sel_z, sel_w, el, bc, eop, vpm, cf_inst, wqm, b) \
  1885.         (((sel_x) << 0) | ((sel_y) << 3) | ((sel_z) << 6) | ((sel_w) << 9) | ((el) << 16) | \
  1886.      ((bc) << 17) | ((eop) << 21) | ((vpm) << 22) | ((cf_inst) << 23) | \
  1887.      ((wqm) << 30) | ((b) << 31))
  1888.  
  1889. /* VTX clause insts */
  1890. /* vxt insts */
  1891. #define VTX_INST(x)        (x)      /* SQ_VTX_INST_* */
  1892.  
  1893. /* fetch type */
  1894. #define FETCH_TYPE(x)        (x)    /* SQ_VTX_FETCH_* */
  1895.  
  1896. #define FETCH_WHOLE_QUAD(x)        (x)
  1897. #define BUFFER_ID(x)        (x)
  1898. #define SRC_GPR(x)          (x)
  1899. #define SRC_REL(x)          (x)
  1900. #define MEGA_FETCH_COUNT(x)        ((x) ? ((x) - 1) : 0)
  1901.  
  1902. #define SEMANTIC_ID(x)        (x)
  1903. #define DST_SEL_X(x)          (x)
  1904. #define DST_SEL_Y(x)          (x)
  1905. #define DST_SEL_Z(x)          (x)
  1906. #define DST_SEL_W(x)          (x)
  1907. #define USE_CONST_FIELDS(x)   (x)
  1908. #define DATA_FORMAT(x)        (x)
  1909. /* num format */
  1910. #define NUM_FORMAT_ALL(x)     (x)   /* SQ_NUM_FORMAT_* */
  1911. /* format comp */
  1912. #define FORMAT_COMP_ALL(x)     (x)  /* SQ_FORMAT_COMP_* */
  1913. /* sma */
  1914. #define SRF_MODE_ALL(x)     (x)
  1915. #define SRF_MODE_ZERO_CLAMP_MINUS_ONE      0
  1916. #define SRF_MODE_NO_ZERO                   1
  1917. #define OFFSET(x)     (x)
  1918. /* endian swap */
  1919. #define ENDIAN_SWAP(x)     (x)      /* SQ_ENDIAN_* */
  1920. #define CONST_BUF_NO_STRIDE(x)     (x)
  1921. /* mf */
  1922. #define MEGA_FETCH(x)     (x)
  1923.  
  1924. #define VTX_DWORD0(vtx_inst, ft, fwq, buffer_id, src_gpr, sr, ssx, mfc) \
  1925.         (((vtx_inst) << 0) | ((ft) << 5) | ((fwq) << 7) | ((buffer_id) << 8) | \
  1926.      ((src_gpr) << 16) | ((sr) << 23) | ((ssx) << 24) | ((mfc) << 26))
  1927. #define VTX_DWORD1_SEM(semantic_id, dsx, dsy, dsz, dsw, ucf, data_format, nfa, fca, sma) \
  1928.         (((semantic_id) << 0) | ((dsx) << 9) | ((dsy) << 12) | ((dsz) << 15) | ((dsw) << 18) | \
  1929.      ((ucf) << 21) | ((data_format) << 22) | ((nfa) << 28) | ((fca) << 30) | ((sma) << 31))
  1930. #define VTX_DWORD1_GPR(dst_gpr, dr, dsx, dsy, dsz, dsw, ucf, data_format, nfa, fca, sma) \
  1931.         (((dst_gpr) << 0) | ((dr) << 7) | ((dsx) << 9) | ((dsy) << 12) | ((dsz) << 15) | ((dsw) << 18) | \
  1932.      ((ucf) << 21) | ((data_format) << 22) | ((nfa) << 28) | ((fca) << 30) | ((sma) << 31))
  1933. #define VTX_DWORD2(offset, es, cbns, mf) \
  1934.      (((offset) << 0) | ((es) << 16) | ((cbns) << 18) | ((mf) << 19))
  1935. #define VTX_DWORD_PAD 0x00000000
  1936.  
  1937.  
  1938. int R600_solid_vs(struct radeon_device *rdev, uint32_t* shader)
  1939. {
  1940.     int i=0;
  1941.  
  1942.     /* 0 */
  1943.     shader[i++] = CF_DWORD0(ADDR(4));
  1944.     shader[i++] = CF_DWORD1(POP_COUNT(0),
  1945.                 CF_CONST(0),
  1946.                 COND(SQ_CF_COND_ACTIVE),
  1947.                 I_COUNT(1),
  1948.                 CALL_COUNT(0),
  1949.                 END_OF_PROGRAM(0),
  1950.                 VALID_PIXEL_MODE(0),
  1951.                 CF_INST(SQ_CF_INST_VTX),
  1952.                 WHOLE_QUAD_MODE(0),
  1953.                 BARRIER(1));
  1954.     /* 1 */
  1955.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD0(ARRAY_BASE(CF_POS0),
  1956.                       TYPE(SQ_EXPORT_POS),
  1957.                       RW_GPR(1),
  1958.                       RW_REL(ABSOLUTE),
  1959.                       INDEX_GPR(0),
  1960.                       ELEM_SIZE(0));
  1961.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD1_SWIZ(SRC_SEL_X(SQ_SEL_X),
  1962.                            SRC_SEL_Y(SQ_SEL_Y),
  1963.                            SRC_SEL_Z(SQ_SEL_Z),
  1964.                            SRC_SEL_W(SQ_SEL_W),
  1965.                            R6xx_ELEM_LOOP(0),
  1966.                            BURST_COUNT(1),
  1967.                            END_OF_PROGRAM(0),
  1968.                            VALID_PIXEL_MODE(0),
  1969.                            CF_INST(SQ_CF_INST_EXPORT_DONE),
  1970.                            WHOLE_QUAD_MODE(0),
  1971.                            BARRIER(1));
  1972.     /* 2 - always export a param whether it's used or not */
  1973.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD0(ARRAY_BASE(0),
  1974.                       TYPE(SQ_EXPORT_PARAM),
  1975.                       RW_GPR(0),
  1976.                       RW_REL(ABSOLUTE),
  1977.                       INDEX_GPR(0),
  1978.                       ELEM_SIZE(0));
  1979.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD1_SWIZ(SRC_SEL_X(SQ_SEL_X),
  1980.                            SRC_SEL_Y(SQ_SEL_Y),
  1981.                            SRC_SEL_Z(SQ_SEL_Z),
  1982.                            SRC_SEL_W(SQ_SEL_W),
  1983.                            R6xx_ELEM_LOOP(0),
  1984.                            BURST_COUNT(0),
  1985.                            END_OF_PROGRAM(1),
  1986.                            VALID_PIXEL_MODE(0),
  1987.                            CF_INST(SQ_CF_INST_EXPORT_DONE),
  1988.                            WHOLE_QUAD_MODE(0),
  1989.                            BARRIER(0));
  1990.     /* 3 - padding */
  1991.     shader[i++] = 0x00000000;
  1992.     shader[i++] = 0x00000000;
  1993.     /* 4/5 */
  1994.     shader[i++] = VTX_DWORD0(VTX_INST(SQ_VTX_INST_FETCH),
  1995.                  FETCH_TYPE(SQ_VTX_FETCH_VERTEX_DATA),
  1996.                  FETCH_WHOLE_QUAD(0),
  1997.                  BUFFER_ID(0),
  1998.                  SRC_GPR(0),
  1999.                  SRC_REL(ABSOLUTE),
  2000.                  SRC_SEL_X(SQ_SEL_X),
  2001.                  MEGA_FETCH_COUNT(8));
  2002.     shader[i++] = VTX_DWORD1_GPR(DST_GPR(1),
  2003.                  DST_REL(0),
  2004.                  DST_SEL_X(SQ_SEL_X),
  2005.                  DST_SEL_Y(SQ_SEL_Y),
  2006.                  DST_SEL_Z(SQ_SEL_0),
  2007.                  DST_SEL_W(SQ_SEL_1),
  2008.                  USE_CONST_FIELDS(0),
  2009.                  DATA_FORMAT(FMT_32_32_FLOAT), /* xxx */
  2010.                  NUM_FORMAT_ALL(SQ_NUM_FORMAT_NORM), /* xxx */
  2011.                  FORMAT_COMP_ALL(SQ_FORMAT_COMP_SIGNED), /* xxx */
  2012.                  SRF_MODE_ALL(SRF_MODE_ZERO_CLAMP_MINUS_ONE));
  2013.     shader[i++] = VTX_DWORD2(OFFSET(0),
  2014.                  ENDIAN_SWAP(ENDIAN_NONE),
  2015.                  CONST_BUF_NO_STRIDE(0),
  2016.                  MEGA_FETCH(1));
  2017.     shader[i++] = VTX_DWORD_PAD;
  2018.  
  2019.     return i;
  2020. }
  2021.  
  2022. int R600_solid_ps(struct radeon_device *rdev, uint32_t* shader)
  2023. {
  2024.     int i=0;
  2025.  
  2026.     /* 0 */
  2027.     shader[i++] = CF_ALU_DWORD0(ADDR(2),
  2028.                 KCACHE_BANK0(0),
  2029.                 KCACHE_BANK1(0),
  2030.                 KCACHE_MODE0(SQ_CF_KCACHE_NOP));
  2031.     shader[i++] = CF_ALU_DWORD1(KCACHE_MODE1(SQ_CF_KCACHE_NOP),
  2032.                 KCACHE_ADDR0(0),
  2033.                 KCACHE_ADDR1(0),
  2034.                 I_COUNT(4),
  2035.                 USES_WATERFALL(0),
  2036.                 CF_INST(SQ_CF_INST_ALU),
  2037.                 WHOLE_QUAD_MODE(0),
  2038.                 BARRIER(1));
  2039.     /* 1 */
  2040.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD0(ARRAY_BASE(CF_PIXEL_MRT0),
  2041.                       TYPE(SQ_EXPORT_PIXEL),
  2042.                       RW_GPR(0),
  2043.                       RW_REL(ABSOLUTE),
  2044.                       INDEX_GPR(0),
  2045.                       ELEM_SIZE(1));
  2046.     shader[i++] = CF_ALLOC_IMP_EXP_DWORD1_SWIZ(SRC_SEL_X(SQ_SEL_X),
  2047.                            SRC_SEL_Y(SQ_SEL_Y),
  2048.                            SRC_SEL_Z(SQ_SEL_Z),
  2049.                            SRC_SEL_W(SQ_SEL_W),
  2050.                            R6xx_ELEM_LOOP(0),
  2051.                            BURST_COUNT(1),
  2052.                            END_OF_PROGRAM(1),
  2053.                            VALID_PIXEL_MODE(0),
  2054.                            CF_INST(SQ_CF_INST_EXPORT_DONE),
  2055.                            WHOLE_QUAD_MODE(0),
  2056.                            BARRIER(1));
  2057.  
  2058.     /* 2 */
  2059.     shader[i++] = ALU_DWORD0(SRC0_SEL(256),
  2060.                  SRC0_REL(ABSOLUTE),
  2061.                  SRC0_ELEM(ELEM_X),
  2062.                  SRC0_NEG(0),
  2063.                  SRC1_SEL(0),
  2064.                  SRC1_REL(ABSOLUTE),
  2065.                  SRC1_ELEM(ELEM_X),
  2066.                  SRC1_NEG(0),
  2067.                  INDEX_MODE(SQ_INDEX_AR_X),
  2068.                  PRED_SEL(SQ_PRED_SEL_OFF),
  2069.                  LAST(0));
  2070.     shader[i++] = ALU_DWORD1_OP2(rdev->family,
  2071.                  SRC0_ABS(0),
  2072.                  SRC1_ABS(0),
  2073.                  UPDATE_EXECUTE_MASK(0),
  2074.                  UPDATE_PRED(0),
  2075.                  WRITE_MASK(1),
  2076.                  FOG_MERGE(0),
  2077.                  OMOD(SQ_ALU_OMOD_OFF),
  2078.                  ALU_INST(SQ_OP2_INST_MOV),
  2079.                  BANK_SWIZZLE(SQ_ALU_VEC_012),
  2080.                  DST_GPR(0),
  2081.                  DST_REL(ABSOLUTE),
  2082.                  DST_ELEM(ELEM_X),
  2083.                  CLAMP(1));
  2084.     /* 3 */
  2085.     shader[i++] = ALU_DWORD0(SRC0_SEL(256),
  2086.                  SRC0_REL(ABSOLUTE),
  2087.                  SRC0_ELEM(ELEM_Y),
  2088.                  SRC0_NEG(0),
  2089.                  SRC1_SEL(0),
  2090.                  SRC1_REL(ABSOLUTE),
  2091.                  SRC1_ELEM(ELEM_Y),
  2092.                  SRC1_NEG(0),
  2093.                  INDEX_MODE(SQ_INDEX_AR_X),
  2094.                  PRED_SEL(SQ_PRED_SEL_OFF),
  2095.                  LAST(0));
  2096.     shader[i++] = ALU_DWORD1_OP2(rdev->family,
  2097.                  SRC0_ABS(0),
  2098.                  SRC1_ABS(0),
  2099.                  UPDATE_EXECUTE_MASK(0),
  2100.                  UPDATE_PRED(0),
  2101.                  WRITE_MASK(1),
  2102.                  FOG_MERGE(0),
  2103.                  OMOD(SQ_ALU_OMOD_OFF),
  2104.                  ALU_INST(SQ_OP2_INST_MOV),
  2105.                  BANK_SWIZZLE(SQ_ALU_VEC_012),
  2106.                  DST_GPR(0),
  2107.                  DST_REL(ABSOLUTE),
  2108.                  DST_ELEM(ELEM_Y),
  2109.                  CLAMP(1));
  2110.     /* 4 */
  2111.     shader[i++] = ALU_DWORD0(SRC0_SEL(256),
  2112.                  SRC0_REL(ABSOLUTE),
  2113.                  SRC0_ELEM(ELEM_Z),
  2114.                  SRC0_NEG(0),
  2115.                  SRC1_SEL(0),
  2116.                  SRC1_REL(ABSOLUTE),
  2117.                  SRC1_ELEM(ELEM_Z),
  2118.                  SRC1_NEG(0),
  2119.                  INDEX_MODE(SQ_INDEX_AR_X),
  2120.                  PRED_SEL(SQ_PRED_SEL_OFF),
  2121.                  LAST(0));
  2122.     shader[i++] = ALU_DWORD1_OP2(rdev->family,
  2123.                  SRC0_ABS(0),
  2124.                  SRC1_ABS(0),
  2125.                  UPDATE_EXECUTE_MASK(0),
  2126.                  UPDATE_PRED(0),
  2127.                  WRITE_MASK(1),
  2128.                  FOG_MERGE(0),
  2129.                  OMOD(SQ_ALU_OMOD_OFF),
  2130.                  ALU_INST(SQ_OP2_INST_MOV),
  2131.                  BANK_SWIZZLE(SQ_ALU_VEC_012),
  2132.                  DST_GPR(0),
  2133.                  DST_REL(ABSOLUTE),
  2134.                  DST_ELEM(ELEM_Z),
  2135.                  CLAMP(1));
  2136.     /* 5 */
  2137.     shader[i++] = ALU_DWORD0(SRC0_SEL(256),
  2138.                  SRC0_REL(ABSOLUTE),
  2139.                  SRC0_ELEM(ELEM_W),
  2140.                  SRC0_NEG(0),
  2141.                  SRC1_SEL(0),
  2142.                  SRC1_REL(ABSOLUTE),
  2143.                  SRC1_ELEM(ELEM_W),
  2144.                  SRC1_NEG(0),
  2145.                  INDEX_MODE(SQ_INDEX_AR_X),
  2146.                  PRED_SEL(SQ_PRED_SEL_OFF),
  2147.                  LAST(1));
  2148.     shader[i++] = ALU_DWORD1_OP2(rdev->family,
  2149.                  SRC0_ABS(0),
  2150.                  SRC1_ABS(0),
  2151.                  UPDATE_EXECUTE_MASK(0),
  2152.                  UPDATE_PRED(0),
  2153.                  WRITE_MASK(1),
  2154.                  FOG_MERGE(0),
  2155.                  OMOD(SQ_ALU_OMOD_OFF),
  2156.                  ALU_INST(SQ_OP2_INST_MOV),
  2157.                  BANK_SWIZZLE(SQ_ALU_VEC_012),
  2158.                  DST_GPR(0),
  2159.                  DST_REL(ABSOLUTE),
  2160.                  DST_ELEM(ELEM_W),
  2161.                  CLAMP(1));
  2162.  
  2163.     return i;
  2164. }
  2165.  
  2166. static inline void
  2167. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  2168. {
  2169.     __memcpy((void __force *)dst, src, count);
  2170. }
  2171.  
  2172. #define EFLOAT(val)                         \
  2173. do {                                        \
  2174.     union { float f; uint32_t d; } a;       \
  2175.     a.f = (val);                            \
  2176.     radeon_ring_write(rdev, a.d);           \
  2177. } while (0)
  2178.  
  2179. int r600_2D_test(struct radeon_device *rdev)
  2180. {
  2181.     uint32_t   ps_shader[16];
  2182.     uint32_t   vs_shader[16];
  2183.  
  2184.     u32        packet2s[16];
  2185.     int        num_packet2s = 0;
  2186.  
  2187.     uint32_t   pitch;
  2188.     uint32_t   offset;
  2189.  
  2190.     int        state_len;
  2191.     int        dwords;
  2192.     u32        obj_size;
  2193.  
  2194.     u32        state_offset   = 0;
  2195.     u64        state_gpu_addr = 0;
  2196.  
  2197.     u32        vs_offset;
  2198.     u32        ps_offset;
  2199.     u32        vb_offset;
  2200.  
  2201.     int        vs_size;
  2202.     int        ps_size;
  2203.  
  2204.     float     *vb;
  2205.     void      *ptr;
  2206.  
  2207.     struct radeon_bo *state_obj;
  2208.  
  2209.     int        r;
  2210.  
  2211.     ENTER();
  2212.  
  2213.     pitch  = (1024*4)/64;
  2214.     offset = rdev->mc.vram_start;
  2215.     ps_size = R600_solid_ps(rdev, ps_shader);
  2216.     vs_size = R600_solid_vs(rdev, vs_shader);
  2217.  
  2218.     if (rdev->family >= CHIP_RV770)
  2219.         state_len = r7xx_default_size;
  2220.     else
  2221.         state_len = r6xx_default_size;
  2222.  
  2223.     dwords = state_len;
  2224.  
  2225.     while (dwords & 0xf) {
  2226.         packet2s[num_packet2s++] = PACKET2(0);
  2227.         dwords++;
  2228.     }
  2229.  
  2230.     obj_size = dwords * 4;
  2231.     obj_size = ALIGN(obj_size, 256);
  2232.  
  2233.     vs_offset = obj_size;
  2234.     obj_size += vs_size * 4;
  2235.     obj_size = ALIGN(obj_size, 256);
  2236.  
  2237.     ps_offset = obj_size;
  2238.     obj_size += ps_size * 4;
  2239.     obj_size = ALIGN(obj_size, 256);
  2240.  
  2241.     vb_offset = obj_size;
  2242.     obj_size += 32*4;
  2243.     obj_size = ALIGN(obj_size, 256);
  2244.  
  2245.     r = radeon_bo_create(rdev, NULL, obj_size, true, RADEON_GEM_DOMAIN_VRAM,
  2246.                 &state_obj);
  2247.     if (r) {
  2248.         DRM_ERROR("r600 failed to allocate state buffer\n");
  2249.         return r;
  2250.     }
  2251.  
  2252.     DRM_DEBUG("r6xx state allocated bo %08x vs %08x ps %08x\n",
  2253.           obj_size, vs_offset, ps_offset);
  2254.  
  2255.     r = radeon_bo_pin(state_obj, RADEON_GEM_DOMAIN_VRAM,
  2256.                       &state_gpu_addr);
  2257.     if (r) {
  2258.         DRM_ERROR("failed to pin state object %d\n", r);
  2259.         return r;
  2260.     };
  2261.  
  2262.     r = radeon_bo_kmap(state_obj, &ptr);
  2263.     if (r) {
  2264.         DRM_ERROR("failed to map state object %d\n", r);
  2265.         return r;
  2266.     };
  2267.  
  2268.     if (rdev->family >= CHIP_RV770)
  2269.         memcpy_toio(ptr + state_offset,
  2270.                 r7xx_default_state, state_len * 4);
  2271.     else
  2272.         memcpy_toio(ptr + state_offset,
  2273.                 r6xx_default_state, state_len * 4);
  2274.  
  2275.     if (num_packet2s)
  2276.         memcpy_toio(ptr + state_offset + (state_len * 4),
  2277.                     packet2s, num_packet2s * 4);
  2278.  
  2279.     memcpy(ptr + vs_offset, vs_shader, vs_size * 4);
  2280.     memcpy(ptr + ps_offset, ps_shader, ps_size * 4);
  2281.  
  2282.  
  2283.     vb = (float*)(ptr + vb_offset);
  2284.  
  2285.     vb[0] = (float)64;
  2286.     vb[1] = (float)64;
  2287.  
  2288.     vb[2] = (float)64;
  2289.     vb[3] = (float)(64+128);
  2290.  
  2291.     vb[4] = (float)(64+128);
  2292.     vb[5] = (float)(64+128);
  2293.  
  2294.     int vb_index = 3;
  2295.     int vb_size = vb_index * 8;
  2296.     int vtx_num_entries = vb_size / 4;
  2297.  
  2298. //    radeon_bo_kunmap(state_obj);
  2299.  
  2300.     r = radeon_ring_lock(rdev, 1024);
  2301.     if (r) {
  2302.         DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2303.         return r;
  2304.     }
  2305.  
  2306.     set_default_state(rdev, state_gpu_addr, state_len);
  2307.  
  2308.  
  2309.     u64 gpu_addr;
  2310.     u32 sq_pgm_resources;
  2311.  
  2312.     /* setup shader regs */
  2313.  
  2314.     /* VS */
  2315.  
  2316.     sq_pgm_resources = (2 << 0);
  2317.     gpu_addr = state_gpu_addr + vs_offset;
  2318.  
  2319.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2320.     radeon_ring_write(rdev, (SQ_PGM_START_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2321.     radeon_ring_write(rdev, gpu_addr >> 8);
  2322.  
  2323.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2324.     radeon_ring_write(rdev, (SQ_PGM_RESOURCES_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2325.     radeon_ring_write(rdev, sq_pgm_resources);
  2326.  
  2327.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2328.     radeon_ring_write(rdev, (SQ_PGM_CF_OFFSET_VS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2329.     radeon_ring_write(rdev, 0);
  2330.  
  2331.     /* PS */
  2332.  
  2333.     sq_pgm_resources = (1 << 0);
  2334.     gpu_addr = state_gpu_addr + ps_offset;
  2335.  
  2336.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2337.     radeon_ring_write(rdev, (SQ_PGM_START_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2338.     radeon_ring_write(rdev, gpu_addr >> 8);
  2339.  
  2340.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2341.     radeon_ring_write(rdev, (SQ_PGM_RESOURCES_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2342.     radeon_ring_write(rdev, sq_pgm_resources | (1 << 28));
  2343.  
  2344.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2345.     radeon_ring_write(rdev, (SQ_PGM_EXPORTS_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2346.     radeon_ring_write(rdev, 2);
  2347.  
  2348.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONTEXT_REG, 1));
  2349.     radeon_ring_write(rdev, (SQ_PGM_CF_OFFSET_PS - PACKET3_SET_CONTEXT_REG_OFFSET) >> 2);
  2350.     radeon_ring_write(rdev, 0);
  2351.  
  2352.     gpu_addr = state_gpu_addr + vs_offset;
  2353.     cp_set_surface_sync(rdev, PACKET3_SH_ACTION_ENA, 512, gpu_addr);
  2354.  
  2355.  
  2356.     set_render_target(rdev, COLOR_8_8_8_8, 1024, 768,  /* FIXME */
  2357.                       rdev->mc.vram_start);
  2358.  
  2359.     set_scissors(rdev, 0, 0, 1024, 768);
  2360.  
  2361.  
  2362.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_ALU_CONST, 4));
  2363.     radeon_ring_write(rdev, (SQ_ALU_CONSTANT0_0 - PACKET3_SET_ALU_CONST_OFFSET) >> 2);
  2364.     EFLOAT(0.0f);                   /* r */
  2365.     EFLOAT(1.0f);                   /* g */
  2366.     EFLOAT(0.0f);                   /* b */
  2367.     EFLOAT(1.0f);                   /* a */
  2368.  
  2369.     u32 sq_vtx_constant_word2;
  2370.  
  2371.     gpu_addr = state_gpu_addr + vb_offset;
  2372.  
  2373.     sq_vtx_constant_word2 = ((upper_32_bits(gpu_addr) & 0xff) | (8 << 8));
  2374.  
  2375.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_RESOURCE, 7));
  2376.     radeon_ring_write(rdev, 0x460);
  2377.     radeon_ring_write(rdev, gpu_addr & 0xffffffff);        /* 0: BASE_ADDRESS */
  2378.     radeon_ring_write(rdev, (vtx_num_entries << 2) - 1);   /* 1: SIZE */
  2379.     radeon_ring_write(rdev, sq_vtx_constant_word2);        /* 2: BASE_HI, STRIDE, CLAMP, FORMAT, ENDIAN */
  2380.     radeon_ring_write(rdev, 1 << 0);                       /* 3: MEM_REQUEST_SIZE ?!? */
  2381.     radeon_ring_write(rdev, 0);
  2382.     radeon_ring_write(rdev, 0);
  2383.     radeon_ring_write(rdev, SQ_TEX_VTX_VALID_BUFFER << 30);
  2384.  
  2385.     if ((rdev->family == CHIP_RV610) ||
  2386.         (rdev->family == CHIP_RV620) ||
  2387.         (rdev->family == CHIP_RS780) ||
  2388.         (rdev->family == CHIP_RS880) ||
  2389.         (rdev->family == CHIP_RV710))
  2390.         cp_set_surface_sync(rdev,
  2391.                     PACKET3_TC_ACTION_ENA, 24, gpu_addr);
  2392.     else
  2393.         cp_set_surface_sync(rdev,
  2394.                     PACKET3_VC_ACTION_ENA, 24, gpu_addr);
  2395.  
  2396.     draw_auto(rdev);
  2397.  
  2398.     cp_set_surface_sync(rdev, PACKET3_CB_ACTION_ENA | PACKET3_CB0_DEST_BASE_ENA,
  2399.                         1024*4*512, offset);
  2400.  
  2401.     radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
  2402.     radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
  2403.     /* wait for 3D idle clean */
  2404.     radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2405.     radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2406.     radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
  2407.  
  2408.     radeon_ring_unlock_commit(rdev);
  2409.  
  2410.     r600_ring_test(rdev);
  2411.  
  2412.     LEAVE();
  2413.     return r;
  2414. }
  2415.