Subversion Repositories Kolibri OS

Rev

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