Subversion Repositories Kolibri OS

Rev

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