Subversion Repositories Kolibri OS

Rev

Rev 1313 | Rev 1404 | 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. display_t *rdisplay;
  11.  
  12. static cursor_t*  __stdcall select_cursor(cursor_t *cursor);
  13. static void       __stdcall move_cursor(cursor_t *cursor, int x, int y);
  14.  
  15. extern void destroy_cursor(void);
  16.  
  17. void disable_mouse(void)
  18. {};
  19.  
  20. int init_cursor(cursor_t *cursor)
  21. {
  22.     struct radeon_device *rdev;
  23.  
  24.     uint32_t *bits;
  25.     uint32_t *src;
  26.  
  27.     int       i,j;
  28.     int       r;
  29.  
  30.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  31.  
  32.     r = radeon_object_create(rdev, NULL, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  33.                      false,
  34.                      RADEON_GEM_DOMAIN_VRAM,
  35.                      false, &cursor->robj);
  36.  
  37.     if (unlikely(r != 0))
  38.         return r;
  39.  
  40.     radeon_object_pin(cursor->robj, TTM_PL_FLAG_VRAM, NULL);
  41.  
  42.     r = radeon_object_kmap(cursor->robj, &bits);
  43.     if (r) {
  44.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  45.          return r;
  46.     };
  47.  
  48.     src = cursor->data;
  49.  
  50.     for(i = 0; i < 32; i++)
  51.     {
  52.         for(j = 0; j < 32; j++)
  53.             *bits++ = *src++;
  54.         for(j = 32; j < CURSOR_WIDTH; j++)
  55.             *bits++ = 0;
  56.     }
  57.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  58.         *bits++ = 0;
  59.  
  60.     radeon_object_kunmap(cursor->robj);
  61.  
  62.  //   cursor->header.destroy = destroy_cursor;
  63.  
  64.     return 0;
  65. };
  66.  
  67. void fini_cursor(cursor_t *cursor)
  68. {
  69.     list_del(&cursor->list);
  70.     radeon_object_unpin(cursor->robj);
  71.     KernelFree(cursor->data);
  72.     __DestroyObject(cursor);
  73. };
  74.  
  75.  
  76. static void radeon_show_cursor()
  77. {
  78.     struct radeon_device *rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  79.  
  80.     if (ASIC_IS_AVIVO(rdev)) {
  81.         WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL);
  82.         WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
  83.                  (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
  84.     } else {
  85.         WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
  86.         WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
  87.                       (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
  88.              ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
  89.     }
  90. }
  91.  
  92. cursor_t* __stdcall select_cursor(cursor_t *cursor)
  93. {
  94.     struct radeon_device *rdev;
  95.     cursor_t *old;
  96.     uint32_t  gpu_addr;
  97.  
  98.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  99.  
  100.     old = rdisplay->cursor;
  101.  
  102.     rdisplay->cursor = cursor;
  103.  //   gpu_addr = cursor->robj->gpu_addr;
  104.  
  105.     if (ASIC_IS_AVIVO(rdev))
  106.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS,  gpu_addr);
  107.     else {
  108.         WREG32(RADEON_CUR_OFFSET, gpu_addr - rdev->mc.vram_location);
  109.     }
  110.  
  111.     return old;
  112. };
  113.  
  114. static void radeon_lock_cursor(bool lock)
  115. {
  116.     struct radeon_device *rdev;
  117.  
  118.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  119.  
  120.     uint32_t cur_lock;
  121.  
  122.     if (ASIC_IS_AVIVO(rdev)) {
  123.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE);
  124.         if (lock)
  125.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  126.         else
  127.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  128.         WREG32(AVIVO_D1CUR_UPDATE, cur_lock);
  129.     } else {
  130.         cur_lock = RREG32(RADEON_CUR_OFFSET);
  131.         if (lock)
  132.             cur_lock |= RADEON_CUR_LOCK;
  133.         else
  134.             cur_lock &= ~RADEON_CUR_LOCK;
  135.         WREG32(RADEON_CUR_OFFSET, cur_lock);
  136.     }
  137. }
  138.  
  139.  
  140. void __stdcall move_cursor(cursor_t *cursor, int x, int y)
  141. {
  142.     struct radeon_device *rdev;
  143.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  144.  
  145.     int hot_x = cursor->hot_x;
  146.     int hot_y = cursor->hot_y;
  147.  
  148.     radeon_lock_cursor(true);
  149.     if (ASIC_IS_AVIVO(rdev))
  150.     {
  151.         int w = 32;
  152.         int i = 0;
  153.  
  154.         WREG32(AVIVO_D1CUR_POSITION, (x << 16) | y);
  155.         WREG32(AVIVO_D1CUR_HOT_SPOT, (hot_x << 16) | hot_y);
  156.         WREG32(AVIVO_D1CUR_SIZE, ((w - 1) << 16) | 31);
  157.     } else {
  158.         uint32_t  gpu_addr;
  159.  
  160.         WREG32(RADEON_CUR_HORZ_VERT_OFF,
  161.                (RADEON_CUR_LOCK | (hot_x << 16) | hot_y ));
  162.         WREG32(RADEON_CUR_HORZ_VERT_POSN,
  163.                (RADEON_CUR_LOCK | (x << 16) | y));
  164.  
  165. //        gpu_addr = cursor->robj->gpu_addr;
  166.  
  167.         /* offset is from DISP(2)_BASE_ADDRESS */
  168.         WREG32(RADEON_CUR_OFFSET,
  169.          (gpu_addr - rdev->mc.vram_location + (hot_y * 256)));
  170.     }
  171.     radeon_lock_cursor(false);
  172. }
  173.  
  174. void __stdcall restore_cursor(int x, int y)
  175. {
  176. };
  177.  
  178.  
  179. bool init_display(struct radeon_device *rdev, mode_t *usermode)
  180. {
  181.     struct drm_device   *dev;
  182.  
  183.     cursor_t            *cursor;
  184.     bool                 retval = true;
  185.     u32_t                ifl;
  186.  
  187.     ENTER();
  188.  
  189.     rdisplay = GetDisplay();
  190.  
  191.     dev = rdisplay->ddev = rdev->ddev;
  192.  
  193.     ifl = safe_cli();
  194.     {
  195.         list_for_each_entry(cursor, &rdisplay->cursors, list)
  196.         {
  197.             init_cursor(cursor);
  198.         };
  199.  
  200.         rdisplay->restore_cursor(0,0);
  201.         rdisplay->init_cursor    = init_cursor;
  202.         rdisplay->select_cursor  = select_cursor;
  203.         rdisplay->show_cursor    = NULL;
  204.         rdisplay->move_cursor    = move_cursor;
  205.         rdisplay->restore_cursor = restore_cursor;
  206.         rdisplay->disable_mouse  = disable_mouse;
  207.  
  208.         select_cursor(rdisplay->cursor);
  209.         radeon_show_cursor();
  210.     };
  211.     safe_sti(ifl);
  212.  
  213.     LEAVE();
  214.  
  215.     return retval;
  216. };
  217.  
  218.  
  219.  
  220.