Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include <stdint.h>
  3. #include <drm/drmP.h>
  4. #include <drm.h>
  5. #include <drm_mm.h>
  6. #include "radeon_drm.h"
  7. #include "radeon.h"
  8. #include "radeon_object.h"
  9.  
  10. #define CURSOR_WIDTH 64
  11. #define CURSOR_HEIGHT 64
  12.  
  13. typedef struct tag_object  kobj_t;
  14. typedef struct tag_display display_t;
  15.  
  16. struct tag_object
  17. {
  18.     uint32_t   magic;
  19.     void      *destroy;
  20.     kobj_t    *fd;
  21.     kobj_t    *bk;
  22.     uint32_t   pid;
  23. };
  24.  
  25. typedef struct
  26. {
  27.     kobj_t     header;
  28.  
  29.     uint32_t  *data;
  30.     uint32_t   hot_x;
  31.     uint32_t   hot_y;
  32.  
  33.     struct list_head      list;
  34.     struct radeon_object *robj;
  35. }cursor_t;
  36.  
  37. struct tag_display
  38. {
  39.     int  x;
  40.     int  y;
  41.     int  width;
  42.     int  height;
  43.     int  bpp;
  44.     int  vrefresh;
  45.     int  pitch;
  46.     int  lfb;
  47.  
  48.     struct drm_device *ddev;
  49.     struct drm_crtc   *crtc;
  50.  
  51.     struct list_head   cursors;
  52.  
  53.     cursor_t   *cursor;
  54.     int       (*init_cursor)(cursor_t*);
  55.     cursor_t* (*select_cursor)(display_t*, cursor_t*);
  56.     void      (*show_cursor)(int show);
  57.     void      (*move_cursor)(int x, int y);
  58. };
  59.  
  60.  
  61. display_t *rdisplay;
  62.  
  63. int init_cursor(cursor_t *cursor)
  64. {
  65.     struct radeon_device *rdev;
  66.  
  67.     uint32_t *bits;
  68.     uint32_t *src;
  69.  
  70.     int       i,j;
  71.     int       r;
  72.  
  73.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  74.  
  75.     r = radeon_object_create(rdev, NULL, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  76.                      false,
  77.                      RADEON_GEM_DOMAIN_VRAM,
  78.                      false, &cursor->robj);
  79.  
  80.     if (unlikely(r != 0))
  81.         return r;
  82.  
  83.     radeon_object_pin(cursor->robj, RADEON_GEM_DOMAIN_VRAM, NULL);
  84.  
  85.     r = radeon_object_kmap(cursor->robj, &bits);
  86.     if (r) {
  87.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  88.          return r;
  89.     };
  90.  
  91.     src = cursor->data;
  92.  
  93.     for(i = 0; i < 32; i++)
  94.     {
  95.         for(j = 0; j < 32; j++)
  96.             *bits++ = *src++;
  97.         for(j = 0; j < CURSOR_WIDTH-32; j++)
  98.             *bits++ = 0;
  99.     }
  100.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  101.         *bits++ = 0;
  102.  
  103.     radeon_object_kunmap(cursor->robj);
  104.  
  105.     return 0;
  106. };
  107.  
  108. int init_display(struct radeon_device *rdev)
  109. {
  110.     cursor_t  *cursor;
  111.  
  112. //    rdisplay = get_display();
  113.  
  114.     rdisplay->ddev = rdev->ddev;
  115.  
  116.     list_for_each_entry(cursor, &rdisplay->cursors, list)
  117.     {
  118.         init_cursor(cursor);
  119.     };
  120.     return 1;
  121. };
  122.  
  123. static void radeon_lock_cursor(struct drm_crtc *crtc, bool lock)
  124. {
  125.     struct radeon_device *rdev = crtc->dev->dev_private;
  126.     struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  127.     uint32_t cur_lock;
  128.  
  129.     if (ASIC_IS_AVIVO(rdev)) {
  130.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset);
  131.         if (lock)
  132.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  133.         else
  134.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  135.         WREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset, cur_lock);
  136.     } else {
  137.         cur_lock = RREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset);
  138.         if (lock)
  139.             cur_lock |= RADEON_CUR_LOCK;
  140.         else
  141.             cur_lock &= ~RADEON_CUR_LOCK;
  142.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset, cur_lock);
  143.     }
  144. }
  145.  
  146. cursor_t* select_cursor(display_t *display, cursor_t *cursor)
  147. {
  148.     struct radeon_device *rdev;
  149.     struct radeon_crtc   *radeon_crtc;
  150.     cursor_t *old;
  151.     uint32_t  gpu_addr;
  152.  
  153.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  154.     radeon_crtc = to_radeon_crtc(rdisplay->crtc);
  155.  
  156.     old = display->cursor;
  157.  
  158.     display->cursor = cursor;
  159.     gpu_addr = cursor->robj->gpu_addr;
  160.  
  161.     if (ASIC_IS_AVIVO(rdev))
  162.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS + radeon_crtc->crtc_offset, gpu_addr);
  163.     else {
  164.         radeon_crtc->legacy_cursor_offset = gpu_addr - radeon_crtc->legacy_display_base_addr;
  165.         /* offset is from DISP(2)_BASE_ADDRESS */
  166.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset, radeon_crtc->legacy_cursor_offset);
  167.     }
  168.     return old;
  169. };
  170.  
  171.  
  172. int radeon_cursor_move(display_t *display, int x, int y)
  173. {
  174.     struct drm_crtc *crtc = rdisplay->crtc;
  175.     struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  176.     struct radeon_device *rdev = crtc->dev->dev_private;
  177.  
  178.     int hot_x = rdisplay->cursor->hot_x - 1;
  179.     int hot_y = rdisplay->cursor->hot_y - 1;
  180.  
  181.     radeon_lock_cursor(crtc, true);
  182.     if (ASIC_IS_AVIVO(rdev))
  183.     {
  184.         int w = 32;
  185.         int i = 0;
  186.         struct drm_crtc *crtc_p;
  187.  
  188.         /* avivo cursor are offset into the total surface */
  189.         x += crtc->x;
  190.         y += crtc->y;
  191.  
  192. //        DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  193. #if 0
  194.         /* avivo cursor image can't end on 128 pixel boundry or
  195.          * go past the end of the frame if both crtcs are enabled
  196.          */
  197.         list_for_each_entry(crtc_p, &crtc->dev->mode_config.crtc_list, head) {
  198.             if (crtc_p->enabled)
  199.                 i++;
  200.         }
  201.         if (i > 1) {
  202.             int cursor_end, frame_end;
  203.  
  204.             cursor_end = x + w;
  205.             frame_end = crtc->x + crtc->mode.crtc_hdisplay;
  206.             if (cursor_end >= frame_end) {
  207.                 w = w - (cursor_end - frame_end);
  208.                 if (!(frame_end & 0x7f))
  209.                     w--;
  210.             } else {
  211.                 if (!(cursor_end & 0x7f))
  212.                     w--;
  213.             }
  214.             if (w <= 0)
  215.                 w = 1;
  216.         }
  217. #endif
  218.  
  219.         WREG32(AVIVO_D1CUR_POSITION + radeon_crtc->crtc_offset,
  220.                (x << 16) | y);
  221.         WREG32(AVIVO_D1CUR_HOT_SPOT + radeon_crtc->crtc_offset,
  222.                (hot_x << 16) | hot_y-1);
  223.         WREG32(AVIVO_D1CUR_SIZE + radeon_crtc->crtc_offset,
  224.                ((w - 1) << 16) | 31);
  225.     } else {
  226.         if (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)
  227.             y *= 2;
  228.  
  229.         WREG32(RADEON_CUR_HORZ_VERT_OFF + radeon_crtc->crtc_offset,
  230.                (RADEON_CUR_LOCK | (hot_x << 16) | (hot_y << 16)));
  231.         WREG32(RADEON_CUR_HORZ_VERT_POSN + radeon_crtc->crtc_offset,
  232.                (RADEON_CUR_LOCK | (x << 16) | y));
  233.  
  234.         /* offset is from DISP(2)_BASE_ADDRESS */
  235.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset,
  236.          (radeon_crtc->legacy_cursor_offset + (hot_y * 256)));
  237.     }
  238.     radeon_lock_cursor(crtc, false);
  239.  
  240.     return 0;
  241. }
  242.  
  243.  
  244.