Subversion Repositories Kolibri OS

Rev

Rev 5271 | 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/radeon_drm.h>
  4. #include "radeon.h"
  5. #include "radeon_object.h"
  6. #include "bitmap.h"
  7. #include <display.h>
  8.  
  9. #include "r100d.h"
  10.  
  11.  
  12. display_t *os_display;
  13.  
  14. static cursor_t*  __stdcall select_cursor(cursor_t *cursor);
  15. static void       __stdcall move_cursor(cursor_t *cursor, int x, int y);
  16.  
  17. extern void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor);
  18.  
  19. void disable_mouse(void)
  20. {};
  21.  
  22. int init_cursor(cursor_t *cursor)
  23. {
  24.     struct radeon_device *rdev;
  25.  
  26.     uint32_t *bits;
  27.     uint32_t *src;
  28.  
  29.     int       i,j;
  30.     int       r;
  31.  
  32.     rdev = (struct radeon_device *)os_display->ddev->dev_private;
  33.  
  34.     r = radeon_bo_create(rdev, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  35.                      4096, false, RADEON_GEM_DOMAIN_VRAM, 0, NULL, NULL, (struct radeon_bo**)&cursor->cobj);
  36.  
  37.     if (unlikely(r != 0))
  38.         return r;
  39.  
  40.     r = radeon_bo_reserve(cursor->cobj, false);
  41.     if (unlikely(r != 0))
  42.         return r;
  43.  
  44.     r = radeon_bo_pin(cursor->cobj, RADEON_GEM_DOMAIN_VRAM, NULL);
  45.     if (unlikely(r != 0))
  46.         return r;
  47.  
  48.     r = radeon_bo_kmap(cursor->cobj, (void**)&bits);
  49.     if (r) {
  50.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  51.          return r;
  52.     };
  53.  
  54.     src = cursor->data;
  55.  
  56.     for(i = 0; i < 32; i++)
  57.     {
  58.         for(j = 0; j < 32; j++)
  59.             *bits++ = *src++;
  60.         for(j = 32; j < CURSOR_WIDTH; j++)
  61.             *bits++ = 0;
  62.     }
  63.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  64.         *bits++ = 0;
  65.  
  66.     radeon_bo_kunmap(cursor->cobj);
  67.  
  68.  //   cursor->header.destroy = destroy_cursor;
  69.  
  70.     return 0;
  71. };
  72.  
  73. void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor)
  74. {
  75.     list_del(&cursor->list);
  76.     radeon_bo_unpin(cursor->cobj);
  77.     KernelFree(cursor->data);
  78.     __DestroyObject(cursor);
  79. };
  80.  
  81. static void radeon_show_cursor()
  82. {
  83.     struct radeon_device *rdev = (struct radeon_device *)os_display->ddev->dev_private;
  84.  
  85.  
  86.     if (ASIC_IS_DCE4(rdev)) {
  87.         WREG32(RADEON_MM_INDEX, EVERGREEN_CUR_CONTROL);
  88.         WREG32(RADEON_MM_DATA, EVERGREEN_CURSOR_EN |
  89.                EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT));
  90.     } else if (ASIC_IS_AVIVO(rdev)) {
  91.         WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL);
  92.         WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
  93.                  (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
  94.     } else {
  95.         WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
  96.         WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
  97.                       (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
  98.              ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
  99.     }
  100. }
  101.  
  102. cursor_t* __stdcall select_cursor(cursor_t *cursor)
  103. {
  104.     struct radeon_device *rdev;
  105.     cursor_t *old;
  106.     uint32_t  gpu_addr;
  107.  
  108.     rdev = (struct radeon_device *)os_display->ddev->dev_private;
  109.  
  110.     old = os_display->cursor;
  111.  
  112.     os_display->cursor = cursor;
  113.     gpu_addr = radeon_bo_gpu_offset(cursor->cobj);
  114.  
  115.     if (ASIC_IS_DCE4(rdev))
  116.     {
  117.         WREG32(EVERGREEN_CUR_SURFACE_ADDRESS_HIGH, 0);
  118.         WREG32(EVERGREEN_CUR_SURFACE_ADDRESS, gpu_addr);
  119.     }
  120.     else if (ASIC_IS_AVIVO(rdev))
  121.     {
  122.         if (rdev->family >= CHIP_RV770)
  123.             WREG32(R700_D1CUR_SURFACE_ADDRESS_HIGH, 0);
  124.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS,  gpu_addr);
  125.     }
  126.     else {
  127.         WREG32(RADEON_CUR_OFFSET, gpu_addr - rdev->mc.vram_start);
  128.     }
  129.  
  130.     return old;
  131. };
  132.  
  133. static void radeon_lock_cursor(bool lock)
  134. {
  135.     struct radeon_device *rdev;
  136.  
  137.     rdev = (struct radeon_device *)os_display->ddev->dev_private;
  138.  
  139.     uint32_t cur_lock;
  140.  
  141.         if (ASIC_IS_DCE4(rdev)) {
  142.                 cur_lock = RREG32(EVERGREEN_CUR_UPDATE);
  143.                 if (lock)
  144.                         cur_lock |= EVERGREEN_CURSOR_UPDATE_LOCK;
  145.                 else
  146.                         cur_lock &= ~EVERGREEN_CURSOR_UPDATE_LOCK;
  147.         WREG32(EVERGREEN_CUR_UPDATE, cur_lock);
  148.         } else if (ASIC_IS_AVIVO(rdev)) {
  149.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE);
  150.         if (lock)
  151.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  152.         else
  153.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  154.         WREG32(AVIVO_D1CUR_UPDATE, cur_lock);
  155.     } else {
  156.         cur_lock = RREG32(RADEON_CUR_OFFSET);
  157.         if (lock)
  158.             cur_lock |= RADEON_CUR_LOCK;
  159.         else
  160.             cur_lock &= ~RADEON_CUR_LOCK;
  161.         WREG32(RADEON_CUR_OFFSET, cur_lock);
  162.     }
  163. }
  164.  
  165.  
  166. void __stdcall move_cursor(cursor_t *cursor, int x, int y)
  167. {
  168.     struct radeon_device *rdev;
  169.     rdev = (struct radeon_device *)os_display->ddev->dev_private;
  170.  
  171.     int hot_x = cursor->hot_x;
  172.     int hot_y = cursor->hot_y;
  173.     int w     = 32;
  174.  
  175.     radeon_lock_cursor(true);
  176.  
  177.     if (ASIC_IS_DCE4(rdev)) {
  178.         WREG32(EVERGREEN_CUR_POSITION,(x << 16) | y);
  179.         WREG32(EVERGREEN_CUR_HOT_SPOT, (hot_x << 16) | hot_y);
  180.         WREG32(EVERGREEN_CUR_SIZE, ((w - 1) << 16) | 31);
  181.     } else if (ASIC_IS_AVIVO(rdev)) {
  182.         WREG32(AVIVO_D1CUR_POSITION, (x << 16) | y);
  183.         WREG32(AVIVO_D1CUR_HOT_SPOT, (hot_x << 16) | hot_y);
  184.         WREG32(AVIVO_D1CUR_SIZE, ((w - 1) << 16) | 31);
  185.     } else {
  186.  
  187.         uint32_t  gpu_addr;
  188.         int       xorg =0, yorg=0;
  189.  
  190.         x = x - hot_x;
  191.         y = y - hot_y;
  192.  
  193.         if( x < 0 )
  194.         {
  195.             xorg = -x + 1;
  196.             x = 0;
  197.         }
  198.  
  199.         if( y < 0 )
  200.         {
  201.             yorg = -hot_y + 1;
  202.             y = 0;
  203.         };
  204.  
  205.         WREG32(RADEON_CUR_HORZ_VERT_OFF,
  206.                (RADEON_CUR_LOCK | (xorg << 16) | yorg ));
  207.         WREG32(RADEON_CUR_HORZ_VERT_POSN,
  208.                (RADEON_CUR_LOCK | (x << 16) | y));
  209.  
  210.         gpu_addr = radeon_bo_gpu_offset(cursor->cobj);
  211.  
  212.         /* offset is from DISP(2)_BASE_ADDRESS */
  213.         WREG32(RADEON_CUR_OFFSET,
  214.          (gpu_addr - rdev->mc.vram_start + (yorg * 256)));
  215.     }
  216.     radeon_lock_cursor(false);
  217. }
  218.  
  219. void __stdcall restore_cursor(int x, int y)
  220. {
  221. };
  222.  
  223.  
  224. bool init_display(struct radeon_device *rdev, videomode_t *usermode)
  225. {
  226.     struct drm_device   *dev;
  227.  
  228.     cursor_t *cursor;
  229.     bool      retval = true;
  230.     u32       ifl;
  231.  
  232.     ENTER();
  233.  
  234.     os_display = GetDisplay();
  235.  
  236.     dev = os_display->ddev = rdev->ddev;
  237.  
  238.     ifl = safe_cli();
  239.     {
  240.         list_for_each_entry(cursor, &os_display->cursors, list)
  241.         {
  242.             init_cursor(cursor);
  243.         };
  244.  
  245.         os_display->restore_cursor(0,0);
  246.         os_display->init_cursor    = init_cursor;
  247.         os_display->select_cursor  = select_cursor;
  248.         os_display->show_cursor    = NULL;
  249.         os_display->move_cursor    = move_cursor;
  250.         os_display->restore_cursor = restore_cursor;
  251.         os_display->disable_mouse  = disable_mouse;
  252.  
  253.         select_cursor(os_display->cursor);
  254.         radeon_show_cursor();
  255.     };
  256.     safe_sti(ifl);
  257.  
  258. //    init_bitmaps();
  259.  
  260.     LEAVE();
  261.  
  262.     return retval;
  263. };
  264.  
  265.  
  266. struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
  267. {
  268. #define BYTES_PER_LONG (BITS_PER_LONG/8)
  269. #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
  270.     int fb_info_size = sizeof(struct fb_info);
  271.     struct fb_info *info;
  272.     char *p;
  273.  
  274.     if (size)
  275.         fb_info_size += PADDING;
  276.  
  277.     p = kzalloc(fb_info_size + size, GFP_KERNEL);
  278.  
  279.     if (!p)
  280.         return NULL;
  281.  
  282.     info = (struct fb_info *) p;
  283.  
  284.     if (size)
  285.         info->par = p + fb_info_size;
  286.  
  287.     return info;
  288. #undef PADDING
  289. #undef BYTES_PER_LONG
  290. }
  291.  
  292. void framebuffer_release(struct fb_info *info)
  293. {
  294.     kfree(info);
  295. }
  296.  
  297.  
  298. /* 23 bits of float fractional data */
  299. #define I2F_FRAC_BITS  23
  300. #define I2F_MASK ((1 << I2F_FRAC_BITS) - 1)
  301.  
  302. /*
  303.  * Converts unsigned integer into 32-bit IEEE floating point representation.
  304.  * Will be exact from 0 to 2^24.  Above that, we round towards zero
  305.  * as the fractional bits will not fit in a float.  (It would be better to
  306.  * round towards even as the fpu does, but that is slower.)
  307.  */
  308. __pure uint32_t int2float(uint32_t x)
  309. {
  310.     uint32_t msb, exponent, fraction;
  311.  
  312.     /* Zero is special */
  313.     if (!x) return 0;
  314.  
  315.     /* Get location of the most significant bit */
  316.     msb = __fls(x);
  317.  
  318.     /*
  319.      * Use a rotate instead of a shift because that works both leftwards
  320.      * and rightwards due to the mod(32) behaviour.  This means we don't
  321.      * need to check to see if we are above 2^24 or not.
  322.      */
  323.     fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
  324.     exponent = (127 + msb) << I2F_FRAC_BITS;
  325.  
  326.     return fraction + exponent;
  327. }
  328.  
  329.