Subversion Repositories Kolibri OS

Rev

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