Subversion Repositories Kolibri OS

Rev

Rev 1403 | Rev 1430 | 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_bo_create(rdev, NULL, CURSOR_WIDTH*CURSOR_HEIGHT*4,
  33.                      false, RADEON_GEM_DOMAIN_VRAM, &cursor->robj);
  34.  
  35.     if (unlikely(r != 0))
  36.         return r;
  37.  
  38.     r = radeon_bo_reserve(cursor->robj, false);
  39.     if (unlikely(r != 0))
  40.         return r;
  41.  
  42.     r = radeon_bo_pin(cursor->robj, RADEON_GEM_DOMAIN_VRAM, NULL);
  43.     if (unlikely(r != 0))
  44.         return r;
  45.  
  46.     r = radeon_bo_kmap(cursor->robj, (void**)&bits);
  47.     if (r) {
  48.          DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
  49.          return r;
  50.     };
  51.  
  52.     src = cursor->data;
  53.  
  54.     for(i = 0; i < 32; i++)
  55.     {
  56.         for(j = 0; j < 32; j++)
  57.             *bits++ = *src++;
  58.         for(j = 32; j < CURSOR_WIDTH; j++)
  59.             *bits++ = 0;
  60.     }
  61.     for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
  62.         *bits++ = 0;
  63.  
  64.     radeon_bo_kunmap(cursor->robj);
  65.  
  66.  //   cursor->header.destroy = destroy_cursor;
  67.  
  68.     return 0;
  69. };
  70.  
  71. void fini_cursor(cursor_t *cursor)
  72. {
  73.     list_del(&cursor->list);
  74.     radeon_bo_unpin(cursor->robj);
  75.     KernelFree(cursor->data);
  76.     __DestroyObject(cursor);
  77. };
  78.  
  79.  
  80. static void radeon_show_cursor()
  81. {
  82.     struct radeon_device *rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  83.  
  84.     if (ASIC_IS_AVIVO(rdev)) {
  85.         WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL);
  86.         WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
  87.                  (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
  88.     } else {
  89.         WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
  90.         WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
  91.                       (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
  92.              ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
  93.     }
  94. }
  95.  
  96. cursor_t* __stdcall select_cursor(cursor_t *cursor)
  97. {
  98.     struct radeon_device *rdev;
  99.     cursor_t *old;
  100.     uint32_t  gpu_addr;
  101.  
  102.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  103.  
  104.     old = rdisplay->cursor;
  105.  
  106.     rdisplay->cursor = cursor;
  107.     gpu_addr = radeon_bo_gpu_offset(cursor->robj);
  108.  
  109.     if (ASIC_IS_AVIVO(rdev))
  110.         WREG32(AVIVO_D1CUR_SURFACE_ADDRESS,  gpu_addr);
  111.     else {
  112.         WREG32(RADEON_CUR_OFFSET, gpu_addr - rdev->mc.vram_location);
  113.     }
  114.  
  115.     return old;
  116. };
  117.  
  118. static void radeon_lock_cursor(bool lock)
  119. {
  120.     struct radeon_device *rdev;
  121.  
  122.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  123.  
  124.     uint32_t cur_lock;
  125.  
  126.     if (ASIC_IS_AVIVO(rdev)) {
  127.         cur_lock = RREG32(AVIVO_D1CUR_UPDATE);
  128.         if (lock)
  129.             cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
  130.         else
  131.             cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
  132.         WREG32(AVIVO_D1CUR_UPDATE, cur_lock);
  133.     } else {
  134.         cur_lock = RREG32(RADEON_CUR_OFFSET);
  135.         if (lock)
  136.             cur_lock |= RADEON_CUR_LOCK;
  137.         else
  138.             cur_lock &= ~RADEON_CUR_LOCK;
  139.         WREG32(RADEON_CUR_OFFSET, cur_lock);
  140.     }
  141. }
  142.  
  143.  
  144. void __stdcall move_cursor(cursor_t *cursor, int x, int y)
  145. {
  146.     struct radeon_device *rdev;
  147.     rdev = (struct radeon_device *)rdisplay->ddev->dev_private;
  148.  
  149.     int hot_x = cursor->hot_x;
  150.     int hot_y = cursor->hot_y;
  151.  
  152.     radeon_lock_cursor(true);
  153.     if (ASIC_IS_AVIVO(rdev))
  154.     {
  155.         int w = 32;
  156.  
  157.         WREG32(AVIVO_D1CUR_POSITION, (x << 16) | y);
  158.         WREG32(AVIVO_D1CUR_HOT_SPOT, (hot_x << 16) | hot_y);
  159.         WREG32(AVIVO_D1CUR_SIZE, ((w - 1) << 16) | 31);
  160.     } else {
  161.  
  162.         uint32_t  gpu_addr;
  163.         int       xorg =0, yorg=0;
  164.  
  165.         x = x - hot_x;
  166.         y = y - hot_y;
  167.  
  168.         if( x < 0 )
  169.         {
  170.             xorg = -x + 1;
  171.             x = 0;
  172.         }
  173.  
  174.         if( y < 0 )
  175.         {
  176.             yorg = -hot_y + 1;
  177.             y = 0;
  178.         };
  179.  
  180.         WREG32(RADEON_CUR_HORZ_VERT_OFF,
  181.                (RADEON_CUR_LOCK | (xorg << 16) | yorg ));
  182.         WREG32(RADEON_CUR_HORZ_VERT_POSN,
  183.                (RADEON_CUR_LOCK | (x << 16) | y));
  184.  
  185.         gpu_addr = radeon_bo_gpu_offset(cursor->robj);
  186.  
  187.         /* offset is from DISP(2)_BASE_ADDRESS */
  188.         WREG32(RADEON_CUR_OFFSET,
  189.          (gpu_addr - rdev->mc.vram_location + (yorg * 256)));
  190.     }
  191.     radeon_lock_cursor(false);
  192. }
  193.  
  194. void __stdcall restore_cursor(int x, int y)
  195. {
  196. };
  197.  
  198.  
  199. bool init_display(struct radeon_device *rdev, videomode_t *usermode)
  200. {
  201.     struct drm_device   *dev;
  202.  
  203.     cursor_t            *cursor;
  204.     bool                 retval = true;
  205.     u32_t                ifl;
  206.  
  207.     ENTER();
  208.  
  209.     rdisplay = GetDisplay();
  210.  
  211.     dev = rdisplay->ddev = rdev->ddev;
  212.  
  213.     ifl = safe_cli();
  214.     {
  215.         list_for_each_entry(cursor, &rdisplay->cursors, list)
  216.         {
  217.             init_cursor(cursor);
  218.         };
  219.  
  220.         rdisplay->restore_cursor(0,0);
  221.         rdisplay->init_cursor    = init_cursor;
  222.         rdisplay->select_cursor  = select_cursor;
  223.         rdisplay->show_cursor    = NULL;
  224.         rdisplay->move_cursor    = move_cursor;
  225.         rdisplay->restore_cursor = restore_cursor;
  226.         rdisplay->disable_mouse  = disable_mouse;
  227.  
  228.         select_cursor(rdisplay->cursor);
  229.         radeon_show_cursor();
  230.     };
  231.     safe_sti(ifl);
  232.  
  233.     LEAVE();
  234.  
  235.     return retval;
  236. };
  237.  
  238.  
  239. struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
  240. {
  241. #define BYTES_PER_LONG (BITS_PER_LONG/8)
  242. #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
  243.     int fb_info_size = sizeof(struct fb_info);
  244.     struct fb_info *info;
  245.     char *p;
  246.  
  247.     if (size)
  248.         fb_info_size += PADDING;
  249.  
  250.     p = kzalloc(fb_info_size + size, GFP_KERNEL);
  251.  
  252.     if (!p)
  253.         return NULL;
  254.  
  255.     info = (struct fb_info *) p;
  256.  
  257.     if (size)
  258.         info->par = p + fb_info_size;
  259.  
  260.     return info;
  261. #undef PADDING
  262. #undef BYTES_PER_LONG
  263. }
  264.  
  265. void framebuffer_release(struct fb_info *info)
  266. {
  267.     kfree(info);
  268. }
  269.  
  270.