2009-10-21 11:33:33 +02:00
|
|
|
|
|
|
|
#include <drm/drmP.h>
|
2014-09-01 13:49:48 +02:00
|
|
|
#include <drm/radeon_drm.h>
|
2009-10-21 11:33:33 +02:00
|
|
|
#include "radeon.h"
|
|
|
|
#include "radeon_object.h"
|
2016-03-11 11:55:22 +01:00
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
#include <display.h>
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2010-03-01 07:55:30 +01:00
|
|
|
#include "r100d.h"
|
|
|
|
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
display_t *os_display;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
static cursor_t* __stdcall select_cursor(cursor_t *cursor);
|
|
|
|
static void __stdcall move_cursor(cursor_t *cursor, int x, int y);
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2011-09-12 21:51:02 +02:00
|
|
|
extern void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor);
|
2009-12-10 20:32:56 +01:00
|
|
|
|
|
|
|
void disable_mouse(void)
|
|
|
|
{};
|
|
|
|
|
2009-10-21 11:33:33 +02:00
|
|
|
int init_cursor(cursor_t *cursor)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
|
|
|
|
|
|
|
uint32_t *bits;
|
|
|
|
uint32_t *src;
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
int r;
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
rdev = (struct radeon_device *)os_display->ddev->dev_private;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2011-06-24 12:44:10 +02:00
|
|
|
r = radeon_bo_create(rdev, CURSOR_WIDTH*CURSOR_HEIGHT*4,
|
2015-01-05 20:15:42 +01:00
|
|
|
4096, false, RADEON_GEM_DOMAIN_VRAM, 0, NULL, NULL, (struct radeon_bo**)&cursor->cobj);
|
2009-10-21 11:33:33 +02:00
|
|
|
|
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
r = radeon_bo_reserve(cursor->cobj, false);
|
2010-02-12 14:55:15 +01:00
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
r = radeon_bo_pin(cursor->cobj, RADEON_GEM_DOMAIN_VRAM, NULL);
|
2010-02-12 14:55:15 +01:00
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
r = radeon_bo_kmap(cursor->cobj, (void**)&bits);
|
2009-10-21 11:33:33 +02:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("radeon: failed to map cursor (%d).\n", r);
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
src = cursor->data;
|
|
|
|
|
|
|
|
for(i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
for(j = 0; j < 32; j++)
|
|
|
|
*bits++ = *src++;
|
2009-10-24 01:46:58 +02:00
|
|
|
for(j = 32; j < CURSOR_WIDTH; j++)
|
2009-10-21 11:33:33 +02:00
|
|
|
*bits++ = 0;
|
|
|
|
}
|
|
|
|
for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
|
|
|
|
*bits++ = 0;
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
radeon_bo_kunmap(cursor->cobj);
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2011-06-24 12:44:10 +02:00
|
|
|
// cursor->header.destroy = destroy_cursor;
|
2009-12-10 20:32:56 +01:00
|
|
|
|
2009-10-21 11:33:33 +02:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2011-09-12 21:51:02 +02:00
|
|
|
void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor)
|
2009-12-10 20:32:56 +01:00
|
|
|
{
|
|
|
|
list_del(&cursor->list);
|
2015-01-05 20:15:42 +01:00
|
|
|
radeon_bo_unpin(cursor->cobj);
|
2009-12-10 20:32:56 +01:00
|
|
|
KernelFree(cursor->data);
|
|
|
|
__DestroyObject(cursor);
|
|
|
|
};
|
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
static void radeon_show_cursor()
|
2009-10-24 01:46:58 +02:00
|
|
|
{
|
2014-09-01 13:49:48 +02:00
|
|
|
struct radeon_device *rdev = (struct radeon_device *)os_display->ddev->dev_private;
|
2009-10-24 01:46:58 +02:00
|
|
|
|
2011-07-15 08:38:31 +02:00
|
|
|
|
|
|
|
if (ASIC_IS_DCE4(rdev)) {
|
|
|
|
WREG32(RADEON_MM_INDEX, EVERGREEN_CUR_CONTROL);
|
|
|
|
WREG32(RADEON_MM_DATA, EVERGREEN_CURSOR_EN |
|
|
|
|
EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT));
|
|
|
|
} else if (ASIC_IS_AVIVO(rdev)) {
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL);
|
2009-10-24 01:46:58 +02:00
|
|
|
WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
|
|
|
|
(AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
|
|
|
|
} else {
|
2009-11-16 12:28:19 +01:00
|
|
|
WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
|
2009-10-24 01:46:58 +02:00
|
|
|
WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
|
|
|
|
(RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
|
|
|
|
~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor_t* __stdcall select_cursor(cursor_t *cursor)
|
2009-10-21 11:33:33 +02:00
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
|
|
|
cursor_t *old;
|
|
|
|
uint32_t gpu_addr;
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
rdev = (struct radeon_device *)os_display->ddev->dev_private;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
old = os_display->cursor;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
os_display->cursor = cursor;
|
2015-01-05 20:15:42 +01:00
|
|
|
gpu_addr = radeon_bo_gpu_offset(cursor->cobj);
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2011-07-15 08:38:31 +02:00
|
|
|
if (ASIC_IS_DCE4(rdev))
|
|
|
|
{
|
|
|
|
WREG32(EVERGREEN_CUR_SURFACE_ADDRESS_HIGH, 0);
|
|
|
|
WREG32(EVERGREEN_CUR_SURFACE_ADDRESS, gpu_addr);
|
|
|
|
}
|
|
|
|
else if (ASIC_IS_AVIVO(rdev))
|
|
|
|
{
|
|
|
|
if (rdev->family >= CHIP_RV770)
|
|
|
|
WREG32(R700_D1CUR_SURFACE_ADDRESS_HIGH, 0);
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(AVIVO_D1CUR_SURFACE_ADDRESS, gpu_addr);
|
2011-07-15 08:38:31 +02:00
|
|
|
}
|
2009-10-21 11:33:33 +02:00
|
|
|
else {
|
2010-03-10 11:23:24 +01:00
|
|
|
WREG32(RADEON_CUR_OFFSET, gpu_addr - rdev->mc.vram_start);
|
2009-10-21 11:33:33 +02:00
|
|
|
}
|
2009-10-24 01:46:58 +02:00
|
|
|
|
2009-10-21 11:33:33 +02:00
|
|
|
return old;
|
|
|
|
};
|
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
static void radeon_lock_cursor(bool lock)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
rdev = (struct radeon_device *)os_display->ddev->dev_private;
|
2009-11-02 21:36:12 +01:00
|
|
|
|
|
|
|
uint32_t cur_lock;
|
|
|
|
|
2011-07-15 08:38:31 +02:00
|
|
|
if (ASIC_IS_DCE4(rdev)) {
|
|
|
|
cur_lock = RREG32(EVERGREEN_CUR_UPDATE);
|
|
|
|
if (lock)
|
|
|
|
cur_lock |= EVERGREEN_CURSOR_UPDATE_LOCK;
|
|
|
|
else
|
|
|
|
cur_lock &= ~EVERGREEN_CURSOR_UPDATE_LOCK;
|
|
|
|
WREG32(EVERGREEN_CUR_UPDATE, cur_lock);
|
|
|
|
} else if (ASIC_IS_AVIVO(rdev)) {
|
2009-11-02 21:36:12 +01:00
|
|
|
cur_lock = RREG32(AVIVO_D1CUR_UPDATE);
|
|
|
|
if (lock)
|
|
|
|
cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
|
|
|
|
else
|
|
|
|
cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
|
|
|
|
WREG32(AVIVO_D1CUR_UPDATE, cur_lock);
|
|
|
|
} else {
|
|
|
|
cur_lock = RREG32(RADEON_CUR_OFFSET);
|
|
|
|
if (lock)
|
|
|
|
cur_lock |= RADEON_CUR_LOCK;
|
|
|
|
else
|
|
|
|
cur_lock &= ~RADEON_CUR_LOCK;
|
|
|
|
WREG32(RADEON_CUR_OFFSET, cur_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-10-24 01:46:58 +02:00
|
|
|
void __stdcall move_cursor(cursor_t *cursor, int x, int y)
|
2009-10-21 11:33:33 +02:00
|
|
|
{
|
2009-10-24 01:46:58 +02:00
|
|
|
struct radeon_device *rdev;
|
2014-09-01 13:49:48 +02:00
|
|
|
rdev = (struct radeon_device *)os_display->ddev->dev_private;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-10-24 01:46:58 +02:00
|
|
|
int hot_x = cursor->hot_x;
|
|
|
|
int hot_y = cursor->hot_y;
|
2011-07-15 08:38:31 +02:00
|
|
|
int w = 32;
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
radeon_lock_cursor(true);
|
|
|
|
|
2011-07-15 08:38:31 +02:00
|
|
|
if (ASIC_IS_DCE4(rdev)) {
|
|
|
|
WREG32(EVERGREEN_CUR_POSITION,(x << 16) | y);
|
|
|
|
WREG32(EVERGREEN_CUR_HOT_SPOT, (hot_x << 16) | hot_y);
|
|
|
|
WREG32(EVERGREEN_CUR_SIZE, ((w - 1) << 16) | 31);
|
|
|
|
} else if (ASIC_IS_AVIVO(rdev)) {
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(AVIVO_D1CUR_POSITION, (x << 16) | y);
|
|
|
|
WREG32(AVIVO_D1CUR_HOT_SPOT, (hot_x << 16) | hot_y);
|
|
|
|
WREG32(AVIVO_D1CUR_SIZE, ((w - 1) << 16) | 31);
|
2009-11-16 12:28:19 +01:00
|
|
|
} else {
|
2010-02-12 14:55:15 +01:00
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
uint32_t gpu_addr;
|
2010-02-12 14:55:15 +01:00
|
|
|
int xorg =0, yorg=0;
|
|
|
|
|
|
|
|
x = x - hot_x;
|
|
|
|
y = y - hot_y;
|
|
|
|
|
|
|
|
if( x < 0 )
|
|
|
|
{
|
|
|
|
xorg = -x + 1;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( y < 0 )
|
|
|
|
{
|
|
|
|
yorg = -hot_y + 1;
|
|
|
|
y = 0;
|
|
|
|
};
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(RADEON_CUR_HORZ_VERT_OFF,
|
2010-02-12 14:55:15 +01:00
|
|
|
(RADEON_CUR_LOCK | (xorg << 16) | yorg ));
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(RADEON_CUR_HORZ_VERT_POSN,
|
2009-10-21 11:33:33 +02:00
|
|
|
(RADEON_CUR_LOCK | (x << 16) | y));
|
|
|
|
|
2015-01-05 20:15:42 +01:00
|
|
|
gpu_addr = radeon_bo_gpu_offset(cursor->cobj);
|
2009-11-02 21:36:12 +01:00
|
|
|
|
2009-10-21 11:33:33 +02:00
|
|
|
/* offset is from DISP(2)_BASE_ADDRESS */
|
2009-11-02 21:36:12 +01:00
|
|
|
WREG32(RADEON_CUR_OFFSET,
|
2010-03-10 11:23:24 +01:00
|
|
|
(gpu_addr - rdev->mc.vram_start + (yorg * 256)));
|
2009-10-21 11:33:33 +02:00
|
|
|
}
|
2009-11-02 21:36:12 +01:00
|
|
|
radeon_lock_cursor(false);
|
2009-10-21 11:33:33 +02:00
|
|
|
}
|
|
|
|
|
2009-10-24 01:46:58 +02:00
|
|
|
void __stdcall restore_cursor(int x, int y)
|
|
|
|
{
|
|
|
|
};
|
2009-10-21 11:33:33 +02:00
|
|
|
|
2009-10-24 23:42:25 +02:00
|
|
|
|
2010-02-12 14:55:15 +01:00
|
|
|
bool init_display(struct radeon_device *rdev, videomode_t *usermode)
|
2009-10-24 23:42:25 +02:00
|
|
|
{
|
2009-11-16 12:28:19 +01:00
|
|
|
struct drm_device *dev;
|
2009-11-02 21:36:12 +01:00
|
|
|
|
2014-12-27 16:58:21 +01:00
|
|
|
cursor_t *cursor;
|
|
|
|
bool retval = true;
|
|
|
|
u32 ifl;
|
2009-10-24 23:42:25 +02:00
|
|
|
|
|
|
|
ENTER();
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
os_display = GetDisplay();
|
2009-10-24 23:42:25 +02:00
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
dev = os_display->ddev = rdev->ddev;
|
2009-10-24 23:42:25 +02:00
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
ifl = safe_cli();
|
|
|
|
{
|
2014-09-01 13:49:48 +02:00
|
|
|
list_for_each_entry(cursor, &os_display->cursors, list)
|
2009-11-16 12:28:19 +01:00
|
|
|
{
|
|
|
|
init_cursor(cursor);
|
|
|
|
};
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
os_display->restore_cursor(0,0);
|
|
|
|
os_display->init_cursor = init_cursor;
|
|
|
|
os_display->select_cursor = select_cursor;
|
|
|
|
os_display->show_cursor = NULL;
|
|
|
|
os_display->move_cursor = move_cursor;
|
|
|
|
os_display->restore_cursor = restore_cursor;
|
|
|
|
os_display->disable_mouse = disable_mouse;
|
2009-10-24 23:42:25 +02:00
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
select_cursor(os_display->cursor);
|
2009-11-02 21:36:12 +01:00
|
|
|
radeon_show_cursor();
|
2009-10-24 23:42:25 +02:00
|
|
|
};
|
2009-11-02 21:36:12 +01:00
|
|
|
safe_sti(ifl);
|
2009-10-26 23:40:01 +01:00
|
|
|
|
2013-07-05 09:43:48 +02:00
|
|
|
// init_bitmaps();
|
2012-12-16 20:05:06 +01:00
|
|
|
|
2009-10-26 23:40:01 +01:00
|
|
|
LEAVE();
|
|
|
|
|
2009-11-02 21:36:12 +01:00
|
|
|
return retval;
|
|
|
|
};
|
2009-10-26 23:40:01 +01:00
|
|
|
|
|
|
|
|
2010-02-12 14:55:15 +01:00
|
|
|
struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
|
|
|
|
{
|
|
|
|
#define BYTES_PER_LONG (BITS_PER_LONG/8)
|
|
|
|
#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
|
|
|
|
int fb_info_size = sizeof(struct fb_info);
|
|
|
|
struct fb_info *info;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
fb_info_size += PADDING;
|
|
|
|
|
|
|
|
p = kzalloc(fb_info_size + size, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
info = (struct fb_info *) p;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
info->par = p + fb_info_size;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
#undef PADDING
|
|
|
|
#undef BYTES_PER_LONG
|
|
|
|
}
|
|
|
|
|
|
|
|
void framebuffer_release(struct fb_info *info)
|
|
|
|
{
|
|
|
|
kfree(info);
|
|
|
|
}
|
2009-10-26 23:40:01 +01:00
|
|
|
|
2011-06-24 12:44:10 +02:00
|
|
|
|
2012-11-03 03:41:31 +01:00
|
|
|
/* 23 bits of float fractional data */
|
|
|
|
#define I2F_FRAC_BITS 23
|
|
|
|
#define I2F_MASK ((1 << I2F_FRAC_BITS) - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts unsigned integer into 32-bit IEEE floating point representation.
|
|
|
|
* Will be exact from 0 to 2^24. Above that, we round towards zero
|
|
|
|
* as the fractional bits will not fit in a float. (It would be better to
|
|
|
|
* round towards even as the fpu does, but that is slower.)
|
|
|
|
*/
|
|
|
|
__pure uint32_t int2float(uint32_t x)
|
|
|
|
{
|
|
|
|
uint32_t msb, exponent, fraction;
|
|
|
|
|
|
|
|
/* Zero is special */
|
|
|
|
if (!x) return 0;
|
|
|
|
|
|
|
|
/* Get location of the most significant bit */
|
|
|
|
msb = __fls(x);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use a rotate instead of a shift because that works both leftwards
|
|
|
|
* and rightwards due to the mod(32) behaviour. This means we don't
|
|
|
|
* need to check to see if we are above 2^24 or not.
|
|
|
|
*/
|
|
|
|
fraction = ror32(x, (msb - I2F_FRAC_BITS) & 0x1f) & I2F_MASK;
|
|
|
|
exponent = (127 + msb) << I2F_FRAC_BITS;
|
|
|
|
|
|
|
|
return fraction + exponent;
|
|
|
|
}
|
|
|
|
|