Subversion Repositories Kolibri OS

Rev

Rev 1221 | Rev 1233 | 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. int        init_cursor(cursor_t *cursor);
  38. cursor_t*  __stdcall select_cursor(cursor_t *cursor);
  39. void       __stdcall move_cursor(cursor_t *cursor, int x, int y);
  40. void       __stdcall restore_cursor(int x, int y);
  41.  
  42. struct tag_display
  43. {
  44.     int  x;
  45.     int  y;
  46.     int  width;
  47.     int  height;
  48.     int  bpp;
  49.     int  vrefresh;
  50.     int  pitch;
  51.     int  lfb;
  52.  
  53.     struct drm_device *ddev;
  54.     struct drm_crtc   *crtc;
  55.  
  56.     struct list_head   cursors;
  57.  
  58.     cursor_t   *cursor;
  59.     int       (*init_cursor)(cursor_t*);
  60.     cursor_t* (__stdcall *select_cursor)(cursor_t*);
  61.     void      (*show_cursor)(int show);
  62.     void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
  63.     void      (__stdcall *restore_cursor)(int x, int y);
  64.  
  65. };
  66.  
  67.  
  68. static display_t *rdisplay;
  69.  
  70.  
  71. void set_crtc(struct drm_crtc *crtc)
  72. {
  73.     ENTER();
  74.     rdisplay->crtc = crtc;
  75.     LEAVE();
  76. }
  77.  
  78. int init_cursor(cursor_t *cursor)
  79. {
  80.     struct radeon_device *rdev;
  81.  
  82.     uint32_t *bits;
  83.     uint32_t *src;
  84.  
  85.     int       i,j;
  86.     int       r;
  87.  
  88.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  89.  
  90.     r = radeon_object_create(rdev, NULL, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  91.                      false,
  92.                      RADEON_GEM_DOMAIN_VRAM,
  93.                      false, &cursor->robj);
  94.  
  95.     if (unlikely(r != 0))
  96.         return r;
  97.  
  98.     radeon_object_pin(cursor->robj, RADEON_GEM_DOMAIN_VRAM, NULL);
  99.  
  100.     r = radeon_object_kmap(cursor->robj, &bits);
  101.     if (r) {
  102.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  103.          return r;
  104.     };
  105.  
  106.     src = cursor->data;
  107.  
  108.     for(i = 0; i < 32; i++)
  109.     {
  110.         for(j = 0; j < 32; j++)
  111.             *bits++ = *src++;
  112.         for(j = 32; j < CURSOR_WIDTH; j++)
  113.             *bits++ = 0;
  114.     }
  115.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  116.         *bits++ = 0;
  117.  
  118.     radeon_object_kunmap(cursor->robj);
  119.  
  120.     return 0;
  121. };
  122.  
  123. static void radeon_show_cursor(struct drm_crtc *crtc)
  124. {
  125.     struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  126.     struct radeon_device *rdev = crtc->dev->dev_private;
  127.  
  128.     if (ASIC_IS_AVIVO(rdev)) {
  129.         WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL + radeon_crtc->crtc_offset);
  130.         WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
  131.                  (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
  132.     } else {
  133.         switch (radeon_crtc->crtc_id) {
  134.         case 0:
  135.             WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
  136.             break;
  137.         case 1:
  138.             WREG32(RADEON_MM_INDEX, RADEON_CRTC2_GEN_CNTL);
  139.             break;
  140.         default:
  141.             return;
  142.         }
  143.  
  144.         WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
  145.                       (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
  146.              ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
  147.     }
  148. }
  149.  
  150. int pre_init_display(struct radeon_device *rdev)
  151. {
  152.     cursor_t  *cursor;
  153.  
  154.     ENTER();
  155.  
  156.     rdisplay = GetDisplay();
  157.  
  158.     rdisplay->ddev = rdev->ddev;
  159.  
  160.     list_for_each_entry(cursor, &rdisplay->cursors, list)
  161.     {
  162.         init_cursor(cursor);
  163.     };
  164.  
  165.     LEAVE();
  166.  
  167.     return 1;
  168. };
  169.  
  170. int post_init_display(struct radeon_device *rdev)
  171. {
  172.     cursor_t  *cursor;
  173.  
  174.     ENTER();
  175.  
  176.     select_cursor(rdisplay->cursor);
  177.  
  178.     radeon_show_cursor(rdisplay->crtc);
  179.  
  180.     rdisplay->init_cursor   = init_cursor;
  181.     rdisplay->select_cursor = select_cursor;
  182.     rdisplay->show_cursor   = NULL;
  183.     rdisplay->move_cursor   = move_cursor;
  184.     rdisplay->restore_cursor = restore_cursor;
  185.  
  186.     LEAVE();
  187.  
  188.     return 1;
  189. };
  190.  
  191. static void radeon_lock_cursor(struct drm_crtc *crtc, bool lock)
  192. {
  193.     struct radeon_device *rdev = crtc->dev->dev_private;
  194.     struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  195.     uint32_t cur_lock;
  196.  
  197.     if (ASIC_IS_AVIVO(rdev)) {
  198.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset);
  199.         if (lock)
  200.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  201.         else
  202.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  203.         WREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset, cur_lock);
  204.     } else {
  205.         cur_lock = RREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset);
  206.         if (lock)
  207.             cur_lock |= RADEON_CUR_LOCK;
  208.         else
  209.             cur_lock &= ~RADEON_CUR_LOCK;
  210.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset, cur_lock);
  211.     }
  212. }
  213.  
  214. cursor_t* __stdcall select_cursor(cursor_t *cursor)
  215. {
  216.     struct radeon_device *rdev;
  217.     struct radeon_crtc   *radeon_crtc;
  218.     cursor_t *old;
  219.     uint32_t  gpu_addr;
  220.  
  221.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  222.     radeon_crtc = to_radeon_crtc(rdisplay->crtc);
  223.  
  224.     old = rdisplay->cursor;
  225.  
  226.     rdisplay->cursor = cursor;
  227.     gpu_addr = cursor->robj->gpu_addr;
  228.  
  229.     if (ASIC_IS_AVIVO(rdev))
  230.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS + radeon_crtc->crtc_offset, gpu_addr);
  231.     else {
  232.         radeon_crtc->legacy_cursor_offset = gpu_addr - radeon_crtc->legacy_display_base_addr;
  233.         /* offset is from DISP(2)_BASE_ADDRESS */
  234.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset, radeon_crtc->legacy_cursor_offset);
  235.     }
  236.  
  237.     return old;
  238. };
  239.  
  240.  
  241. void __stdcall move_cursor(cursor_t *cursor, int x, int y)
  242. {
  243.     struct radeon_device *rdev;
  244.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  245.     struct drm_crtc *crtc = rdisplay->crtc;
  246.     struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  247.  
  248.     int hot_x = cursor->hot_x;
  249.     int hot_y = cursor->hot_y;
  250.  
  251.     radeon_lock_cursor(crtc, true);
  252.     if (ASIC_IS_AVIVO(rdev))
  253.     {
  254.         int w = 32;
  255.         int i = 0;
  256.         struct drm_crtc *crtc_p;
  257.  
  258.         /* avivo cursor are offset into the total surface */
  259. //        x += crtc->x;
  260. //        y += crtc->y;
  261.  
  262. //        DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
  263. #if 0
  264.         /* avivo cursor image can't end on 128 pixel boundry or
  265.          * go past the end of the frame if both crtcs are enabled
  266.          */
  267.         list_for_each_entry(crtc_p, &crtc->dev->mode_config.crtc_list, head) {
  268.             if (crtc_p->enabled)
  269.                 i++;
  270.         }
  271.         if (i > 1) {
  272.             int cursor_end, frame_end;
  273.  
  274.             cursor_end = x + w;
  275.             frame_end = crtc->x + crtc->mode.crtc_hdisplay;
  276.             if (cursor_end >= frame_end) {
  277.                 w = w - (cursor_end - frame_end);
  278.                 if (!(frame_end & 0x7f))
  279.                     w--;
  280.             } else {
  281.                 if (!(cursor_end & 0x7f))
  282.                     w--;
  283.             }
  284.             if (w <= 0)
  285.                 w = 1;
  286.         }
  287. #endif
  288.         WREG32(AVIVO_D1CUR_POSITION + radeon_crtc->crtc_offset,
  289.                (x << 16) | y);
  290.         WREG32(AVIVO_D1CUR_HOT_SPOT + radeon_crtc->crtc_offset,
  291.                (hot_x << 16) | hot_y);
  292.         WREG32(AVIVO_D1CUR_SIZE + radeon_crtc->crtc_offset,
  293.                ((w - 1) << 16) | 31);
  294.     } else {
  295.         if (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)
  296.             y *= 2;
  297.  
  298.         WREG32(RADEON_CUR_HORZ_VERT_OFF + radeon_crtc->crtc_offset,
  299.                (RADEON_CUR_LOCK | (hot_x << 16) | (hot_y << 16)));
  300.         WREG32(RADEON_CUR_HORZ_VERT_POSN + radeon_crtc->crtc_offset,
  301.                (RADEON_CUR_LOCK | (x << 16) | y));
  302.  
  303.         /* offset is from DISP(2)_BASE_ADDRESS */
  304.         WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset,
  305.          (radeon_crtc->legacy_cursor_offset + (hot_y * 256)));
  306.     }
  307.     radeon_lock_cursor(crtc, false);
  308. }
  309.  
  310. void __stdcall restore_cursor(int x, int y)
  311. {
  312. };
  313.  
  314.