Home | History | Annotate | Line # | Download | only in radeon
      1  1.2  riastrad /*	$NetBSD: radeon_cursor.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2007-8 Advanced Micro Devices, Inc.
      5  1.1  riastrad  * Copyright 2008 Red Hat Inc.
      6  1.1  riastrad  *
      7  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      8  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      9  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     10  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     11  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     12  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     15  1.1  riastrad  * all copies or substantial portions of the Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     21  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     22  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     23  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  * Authors: Dave Airlie
     26  1.1  riastrad  *          Alex Deucher
     27  1.1  riastrad  */
     28  1.3  riastrad 
     29  1.2  riastrad #include <sys/cdefs.h>
     30  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_cursor.c,v 1.3 2021/12/18 23:45:43 riastradh Exp $");
     31  1.2  riastrad 
     32  1.3  riastrad #include <drm/drm_device.h>
     33  1.1  riastrad #include <drm/radeon_drm.h>
     34  1.3  riastrad 
     35  1.1  riastrad #include "radeon.h"
     36  1.1  riastrad 
     37  1.1  riastrad static void radeon_lock_cursor(struct drm_crtc *crtc, bool lock)
     38  1.1  riastrad {
     39  1.1  riastrad 	struct radeon_device *rdev = crtc->dev->dev_private;
     40  1.1  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
     41  1.1  riastrad 	uint32_t cur_lock;
     42  1.1  riastrad 
     43  1.1  riastrad 	if (ASIC_IS_DCE4(rdev)) {
     44  1.1  riastrad 		cur_lock = RREG32(EVERGREEN_CUR_UPDATE + radeon_crtc->crtc_offset);
     45  1.1  riastrad 		if (lock)
     46  1.1  riastrad 			cur_lock |= EVERGREEN_CURSOR_UPDATE_LOCK;
     47  1.1  riastrad 		else
     48  1.1  riastrad 			cur_lock &= ~EVERGREEN_CURSOR_UPDATE_LOCK;
     49  1.1  riastrad 		WREG32(EVERGREEN_CUR_UPDATE + radeon_crtc->crtc_offset, cur_lock);
     50  1.1  riastrad 	} else if (ASIC_IS_AVIVO(rdev)) {
     51  1.1  riastrad 		cur_lock = RREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset);
     52  1.1  riastrad 		if (lock)
     53  1.1  riastrad 			cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK;
     54  1.1  riastrad 		else
     55  1.1  riastrad 			cur_lock &= ~AVIVO_D1CURSOR_UPDATE_LOCK;
     56  1.1  riastrad 		WREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset, cur_lock);
     57  1.1  riastrad 	} else {
     58  1.1  riastrad 		cur_lock = RREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset);
     59  1.1  riastrad 		if (lock)
     60  1.1  riastrad 			cur_lock |= RADEON_CUR_LOCK;
     61  1.1  riastrad 		else
     62  1.1  riastrad 			cur_lock &= ~RADEON_CUR_LOCK;
     63  1.1  riastrad 		WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset, cur_lock);
     64  1.1  riastrad 	}
     65  1.1  riastrad }
     66  1.1  riastrad 
     67  1.1  riastrad static void radeon_hide_cursor(struct drm_crtc *crtc)
     68  1.1  riastrad {
     69  1.1  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
     70  1.1  riastrad 	struct radeon_device *rdev = crtc->dev->dev_private;
     71  1.1  riastrad 
     72  1.1  riastrad 	if (ASIC_IS_DCE4(rdev)) {
     73  1.1  riastrad 		WREG32_IDX(EVERGREEN_CUR_CONTROL + radeon_crtc->crtc_offset,
     74  1.1  riastrad 			   EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT) |
     75  1.1  riastrad 			   EVERGREEN_CURSOR_URGENT_CONTROL(EVERGREEN_CURSOR_URGENT_1_2));
     76  1.1  riastrad 	} else if (ASIC_IS_AVIVO(rdev)) {
     77  1.1  riastrad 		WREG32_IDX(AVIVO_D1CUR_CONTROL + radeon_crtc->crtc_offset,
     78  1.1  riastrad 			   (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
     79  1.1  riastrad 	} else {
     80  1.1  riastrad 		u32 reg;
     81  1.1  riastrad 		switch (radeon_crtc->crtc_id) {
     82  1.1  riastrad 		case 0:
     83  1.1  riastrad 			reg = RADEON_CRTC_GEN_CNTL;
     84  1.1  riastrad 			break;
     85  1.1  riastrad 		case 1:
     86  1.1  riastrad 			reg = RADEON_CRTC2_GEN_CNTL;
     87  1.1  riastrad 			break;
     88  1.1  riastrad 		default:
     89  1.1  riastrad 			return;
     90  1.1  riastrad 		}
     91  1.1  riastrad 		WREG32_IDX(reg, RREG32_IDX(reg) & ~RADEON_CRTC_CUR_EN);
     92  1.1  riastrad 	}
     93  1.1  riastrad }
     94  1.1  riastrad 
     95  1.1  riastrad static void radeon_show_cursor(struct drm_crtc *crtc)
     96  1.1  riastrad {
     97  1.1  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
     98  1.1  riastrad 	struct radeon_device *rdev = crtc->dev->dev_private;
     99  1.1  riastrad 
    100  1.2  riastrad 	if (radeon_crtc->cursor_out_of_bounds)
    101  1.2  riastrad 		return;
    102  1.2  riastrad 
    103  1.1  riastrad 	if (ASIC_IS_DCE4(rdev)) {
    104  1.2  riastrad 		WREG32(EVERGREEN_CUR_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
    105  1.2  riastrad 		       upper_32_bits(radeon_crtc->cursor_addr));
    106  1.2  riastrad 		WREG32(EVERGREEN_CUR_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
    107  1.2  riastrad 		       lower_32_bits(radeon_crtc->cursor_addr));
    108  1.1  riastrad 		WREG32(RADEON_MM_INDEX, EVERGREEN_CUR_CONTROL + radeon_crtc->crtc_offset);
    109  1.1  riastrad 		WREG32(RADEON_MM_DATA, EVERGREEN_CURSOR_EN |
    110  1.1  riastrad 		       EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT) |
    111  1.1  riastrad 		       EVERGREEN_CURSOR_URGENT_CONTROL(EVERGREEN_CURSOR_URGENT_1_2));
    112  1.1  riastrad 	} else if (ASIC_IS_AVIVO(rdev)) {
    113  1.2  riastrad 		if (rdev->family >= CHIP_RV770) {
    114  1.2  riastrad 			if (radeon_crtc->crtc_id)
    115  1.2  riastrad 				WREG32(R700_D2CUR_SURFACE_ADDRESS_HIGH,
    116  1.2  riastrad 				       upper_32_bits(radeon_crtc->cursor_addr));
    117  1.2  riastrad 			else
    118  1.2  riastrad 				WREG32(R700_D1CUR_SURFACE_ADDRESS_HIGH,
    119  1.2  riastrad 				       upper_32_bits(radeon_crtc->cursor_addr));
    120  1.2  riastrad 		}
    121  1.2  riastrad 
    122  1.2  riastrad 		WREG32(AVIVO_D1CUR_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
    123  1.2  riastrad 		       lower_32_bits(radeon_crtc->cursor_addr));
    124  1.1  riastrad 		WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL + radeon_crtc->crtc_offset);
    125  1.1  riastrad 		WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN |
    126  1.1  riastrad 		       (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT));
    127  1.1  riastrad 	} else {
    128  1.2  riastrad 		/* offset is from DISP(2)_BASE_ADDRESS */
    129  1.2  riastrad 		WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset,
    130  1.2  riastrad 		       radeon_crtc->cursor_addr - radeon_crtc->legacy_display_base_addr);
    131  1.2  riastrad 
    132  1.1  riastrad 		switch (radeon_crtc->crtc_id) {
    133  1.1  riastrad 		case 0:
    134  1.1  riastrad 			WREG32(RADEON_MM_INDEX, RADEON_CRTC_GEN_CNTL);
    135  1.1  riastrad 			break;
    136  1.1  riastrad 		case 1:
    137  1.1  riastrad 			WREG32(RADEON_MM_INDEX, RADEON_CRTC2_GEN_CNTL);
    138  1.1  riastrad 			break;
    139  1.1  riastrad 		default:
    140  1.1  riastrad 			return;
    141  1.1  riastrad 		}
    142  1.1  riastrad 
    143  1.1  riastrad 		WREG32_P(RADEON_MM_DATA, (RADEON_CRTC_CUR_EN |
    144  1.1  riastrad 					  (RADEON_CRTC_CUR_MODE_24BPP << RADEON_CRTC_CUR_MODE_SHIFT)),
    145  1.1  riastrad 			 ~(RADEON_CRTC_CUR_EN | RADEON_CRTC_CUR_MODE_MASK));
    146  1.1  riastrad 	}
    147  1.1  riastrad }
    148  1.1  riastrad 
    149  1.2  riastrad static int radeon_cursor_move_locked(struct drm_crtc *crtc, int x, int y)
    150  1.1  riastrad {
    151  1.1  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
    152  1.1  riastrad 	struct radeon_device *rdev = crtc->dev->dev_private;
    153  1.1  riastrad 	int xorigin = 0, yorigin = 0;
    154  1.1  riastrad 	int w = radeon_crtc->cursor_width;
    155  1.1  riastrad 
    156  1.2  riastrad 	radeon_crtc->cursor_x = x;
    157  1.2  riastrad 	radeon_crtc->cursor_y = y;
    158  1.2  riastrad 
    159  1.1  riastrad 	if (ASIC_IS_AVIVO(rdev)) {
    160  1.1  riastrad 		/* avivo cursor are offset into the total surface */
    161  1.1  riastrad 		x += crtc->x;
    162  1.1  riastrad 		y += crtc->y;
    163  1.1  riastrad 	}
    164  1.1  riastrad 
    165  1.2  riastrad 	if (x < 0)
    166  1.1  riastrad 		xorigin = min(-x, radeon_crtc->max_cursor_width - 1);
    167  1.2  riastrad 	if (y < 0)
    168  1.1  riastrad 		yorigin = min(-y, radeon_crtc->max_cursor_height - 1);
    169  1.2  riastrad 
    170  1.2  riastrad 	if (!ASIC_IS_AVIVO(rdev)) {
    171  1.2  riastrad 		x += crtc->x;
    172  1.2  riastrad 		y += crtc->y;
    173  1.1  riastrad 	}
    174  1.2  riastrad 	DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
    175  1.1  riastrad 
    176  1.1  riastrad 	/* fixed on DCE6 and newer */
    177  1.1  riastrad 	if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE6(rdev)) {
    178  1.1  riastrad 		int i = 0;
    179  1.1  riastrad 		struct drm_crtc *crtc_p;
    180  1.1  riastrad 
    181  1.1  riastrad 		/*
    182  1.1  riastrad 		 * avivo cursor image can't end on 128 pixel boundary or
    183  1.1  riastrad 		 * go past the end of the frame if both crtcs are enabled
    184  1.1  riastrad 		 *
    185  1.1  riastrad 		 * NOTE: It is safe to access crtc->enabled of other crtcs
    186  1.1  riastrad 		 * without holding either the mode_config lock or the other
    187  1.1  riastrad 		 * crtc's lock as long as write access to this flag _always_
    188  1.1  riastrad 		 * grabs all locks.
    189  1.1  riastrad 		 */
    190  1.1  riastrad 		list_for_each_entry(crtc_p, &crtc->dev->mode_config.crtc_list, head) {
    191  1.1  riastrad 			if (crtc_p->enabled)
    192  1.1  riastrad 				i++;
    193  1.1  riastrad 		}
    194  1.1  riastrad 		if (i > 1) {
    195  1.1  riastrad 			int cursor_end, frame_end;
    196  1.1  riastrad 
    197  1.2  riastrad 			cursor_end = x + w;
    198  1.1  riastrad 			frame_end = crtc->x + crtc->mode.crtc_hdisplay;
    199  1.1  riastrad 			if (cursor_end >= frame_end) {
    200  1.1  riastrad 				w = w - (cursor_end - frame_end);
    201  1.1  riastrad 				if (!(frame_end & 0x7f))
    202  1.1  riastrad 					w--;
    203  1.2  riastrad 			} else if (cursor_end <= 0) {
    204  1.2  riastrad 				goto out_of_bounds;
    205  1.2  riastrad 			} else if (!(cursor_end & 0x7f)) {
    206  1.2  riastrad 				w--;
    207  1.1  riastrad 			}
    208  1.1  riastrad 			if (w <= 0) {
    209  1.2  riastrad 				goto out_of_bounds;
    210  1.1  riastrad 			}
    211  1.1  riastrad 		}
    212  1.1  riastrad 	}
    213  1.1  riastrad 
    214  1.2  riastrad 	if (x <= (crtc->x - w) || y <= (crtc->y - radeon_crtc->cursor_height) ||
    215  1.2  riastrad 	    x >= (crtc->x + crtc->mode.hdisplay) ||
    216  1.2  riastrad 	    y >= (crtc->y + crtc->mode.vdisplay))
    217  1.2  riastrad 		goto out_of_bounds;
    218  1.2  riastrad 
    219  1.2  riastrad 	x += xorigin;
    220  1.2  riastrad 	y += yorigin;
    221  1.2  riastrad 
    222  1.1  riastrad 	if (ASIC_IS_DCE4(rdev)) {
    223  1.1  riastrad 		WREG32(EVERGREEN_CUR_POSITION + radeon_crtc->crtc_offset, (x << 16) | y);
    224  1.1  riastrad 		WREG32(EVERGREEN_CUR_HOT_SPOT + radeon_crtc->crtc_offset, (xorigin << 16) | yorigin);
    225  1.1  riastrad 		WREG32(EVERGREEN_CUR_SIZE + radeon_crtc->crtc_offset,
    226  1.1  riastrad 		       ((w - 1) << 16) | (radeon_crtc->cursor_height - 1));
    227  1.1  riastrad 	} else if (ASIC_IS_AVIVO(rdev)) {
    228  1.1  riastrad 		WREG32(AVIVO_D1CUR_POSITION + radeon_crtc->crtc_offset, (x << 16) | y);
    229  1.1  riastrad 		WREG32(AVIVO_D1CUR_HOT_SPOT + radeon_crtc->crtc_offset, (xorigin << 16) | yorigin);
    230  1.1  riastrad 		WREG32(AVIVO_D1CUR_SIZE + radeon_crtc->crtc_offset,
    231  1.1  riastrad 		       ((w - 1) << 16) | (radeon_crtc->cursor_height - 1));
    232  1.1  riastrad 	} else {
    233  1.2  riastrad 		x -= crtc->x;
    234  1.2  riastrad 		y -= crtc->y;
    235  1.2  riastrad 
    236  1.1  riastrad 		if (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)
    237  1.1  riastrad 			y *= 2;
    238  1.1  riastrad 
    239  1.1  riastrad 		WREG32(RADEON_CUR_HORZ_VERT_OFF + radeon_crtc->crtc_offset,
    240  1.1  riastrad 		       (RADEON_CUR_LOCK
    241  1.1  riastrad 			| (xorigin << 16)
    242  1.1  riastrad 			| yorigin));
    243  1.1  riastrad 		WREG32(RADEON_CUR_HORZ_VERT_POSN + radeon_crtc->crtc_offset,
    244  1.1  riastrad 		       (RADEON_CUR_LOCK
    245  1.1  riastrad 			| (x << 16)
    246  1.1  riastrad 			| y));
    247  1.1  riastrad 		/* offset is from DISP(2)_BASE_ADDRESS */
    248  1.2  riastrad 		WREG32(RADEON_CUR_OFFSET + radeon_crtc->crtc_offset,
    249  1.2  riastrad 		       radeon_crtc->cursor_addr - radeon_crtc->legacy_display_base_addr +
    250  1.2  riastrad 		       yorigin * 256);
    251  1.2  riastrad 	}
    252  1.2  riastrad 
    253  1.2  riastrad 	if (radeon_crtc->cursor_out_of_bounds) {
    254  1.2  riastrad 		radeon_crtc->cursor_out_of_bounds = false;
    255  1.2  riastrad 		if (radeon_crtc->cursor_bo)
    256  1.2  riastrad 			radeon_show_cursor(crtc);
    257  1.2  riastrad 	}
    258  1.2  riastrad 
    259  1.2  riastrad 	return 0;
    260  1.2  riastrad 
    261  1.2  riastrad  out_of_bounds:
    262  1.2  riastrad 	if (!radeon_crtc->cursor_out_of_bounds) {
    263  1.2  riastrad 		radeon_hide_cursor(crtc);
    264  1.2  riastrad 		radeon_crtc->cursor_out_of_bounds = true;
    265  1.1  riastrad 	}
    266  1.2  riastrad 	return 0;
    267  1.2  riastrad }
    268  1.2  riastrad 
    269  1.2  riastrad int radeon_crtc_cursor_move(struct drm_crtc *crtc,
    270  1.2  riastrad 			    int x, int y)
    271  1.2  riastrad {
    272  1.2  riastrad 	int ret;
    273  1.2  riastrad 
    274  1.2  riastrad 	radeon_lock_cursor(crtc, true);
    275  1.2  riastrad 	ret = radeon_cursor_move_locked(crtc, x, y);
    276  1.1  riastrad 	radeon_lock_cursor(crtc, false);
    277  1.1  riastrad 
    278  1.2  riastrad 	return ret;
    279  1.2  riastrad }
    280  1.2  riastrad 
    281  1.2  riastrad int radeon_crtc_cursor_set2(struct drm_crtc *crtc,
    282  1.2  riastrad 			    struct drm_file *file_priv,
    283  1.2  riastrad 			    uint32_t handle,
    284  1.2  riastrad 			    uint32_t width,
    285  1.2  riastrad 			    uint32_t height,
    286  1.2  riastrad 			    int32_t hot_x,
    287  1.2  riastrad 			    int32_t hot_y)
    288  1.2  riastrad {
    289  1.2  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
    290  1.2  riastrad 	struct radeon_device *rdev = crtc->dev->dev_private;
    291  1.2  riastrad 	struct drm_gem_object *obj;
    292  1.2  riastrad 	struct radeon_bo *robj;
    293  1.2  riastrad 	int ret;
    294  1.2  riastrad 
    295  1.2  riastrad 	if (!handle) {
    296  1.2  riastrad 		/* turn off cursor */
    297  1.2  riastrad 		radeon_hide_cursor(crtc);
    298  1.2  riastrad 		obj = NULL;
    299  1.2  riastrad 		goto unpin;
    300  1.2  riastrad 	}
    301  1.2  riastrad 
    302  1.2  riastrad 	if ((width > radeon_crtc->max_cursor_width) ||
    303  1.2  riastrad 	    (height > radeon_crtc->max_cursor_height)) {
    304  1.2  riastrad 		DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
    305  1.2  riastrad 		return -EINVAL;
    306  1.2  riastrad 	}
    307  1.2  riastrad 
    308  1.3  riastrad 	obj = drm_gem_object_lookup(file_priv, handle);
    309  1.2  riastrad 	if (!obj) {
    310  1.2  riastrad 		DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, radeon_crtc->crtc_id);
    311  1.2  riastrad 		return -ENOENT;
    312  1.2  riastrad 	}
    313  1.2  riastrad 
    314  1.2  riastrad 	robj = gem_to_radeon_bo(obj);
    315  1.2  riastrad 	ret = radeon_bo_reserve(robj, false);
    316  1.2  riastrad 	if (ret != 0) {
    317  1.3  riastrad 		drm_gem_object_put_unlocked(obj);
    318  1.2  riastrad 		return ret;
    319  1.2  riastrad 	}
    320  1.2  riastrad 	/* Only 27 bit offset for legacy cursor */
    321  1.2  riastrad 	ret = radeon_bo_pin_restricted(robj, RADEON_GEM_DOMAIN_VRAM,
    322  1.2  riastrad 				       ASIC_IS_AVIVO(rdev) ? 0 : 1 << 27,
    323  1.2  riastrad 				       &radeon_crtc->cursor_addr);
    324  1.2  riastrad 	radeon_bo_unreserve(robj);
    325  1.2  riastrad 	if (ret) {
    326  1.2  riastrad 		DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
    327  1.3  riastrad 		drm_gem_object_put_unlocked(obj);
    328  1.2  riastrad 		return ret;
    329  1.2  riastrad 	}
    330  1.2  riastrad 
    331  1.2  riastrad 	radeon_lock_cursor(crtc, true);
    332  1.2  riastrad 
    333  1.2  riastrad 	if (width != radeon_crtc->cursor_width ||
    334  1.2  riastrad 	    height != radeon_crtc->cursor_height ||
    335  1.2  riastrad 	    hot_x != radeon_crtc->cursor_hot_x ||
    336  1.2  riastrad 	    hot_y != radeon_crtc->cursor_hot_y) {
    337  1.2  riastrad 		int x, y;
    338  1.2  riastrad 
    339  1.2  riastrad 		x = radeon_crtc->cursor_x + radeon_crtc->cursor_hot_x - hot_x;
    340  1.2  riastrad 		y = radeon_crtc->cursor_y + radeon_crtc->cursor_hot_y - hot_y;
    341  1.2  riastrad 
    342  1.2  riastrad 		radeon_crtc->cursor_width = width;
    343  1.2  riastrad 		radeon_crtc->cursor_height = height;
    344  1.2  riastrad 		radeon_crtc->cursor_hot_x = hot_x;
    345  1.2  riastrad 		radeon_crtc->cursor_hot_y = hot_y;
    346  1.2  riastrad 
    347  1.2  riastrad 		radeon_cursor_move_locked(crtc, x, y);
    348  1.2  riastrad 	}
    349  1.2  riastrad 
    350  1.2  riastrad 	radeon_show_cursor(crtc);
    351  1.2  riastrad 
    352  1.2  riastrad 	radeon_lock_cursor(crtc, false);
    353  1.2  riastrad 
    354  1.2  riastrad unpin:
    355  1.2  riastrad 	if (radeon_crtc->cursor_bo) {
    356  1.2  riastrad 		struct radeon_bo *robj = gem_to_radeon_bo(radeon_crtc->cursor_bo);
    357  1.2  riastrad 		ret = radeon_bo_reserve(robj, false);
    358  1.2  riastrad 		if (likely(ret == 0)) {
    359  1.2  riastrad 			radeon_bo_unpin(robj);
    360  1.2  riastrad 			radeon_bo_unreserve(robj);
    361  1.2  riastrad 		}
    362  1.3  riastrad 		drm_gem_object_put_unlocked(radeon_crtc->cursor_bo);
    363  1.2  riastrad 	}
    364  1.2  riastrad 
    365  1.2  riastrad 	radeon_crtc->cursor_bo = obj;
    366  1.1  riastrad 	return 0;
    367  1.1  riastrad }
    368  1.2  riastrad 
    369  1.2  riastrad /**
    370  1.2  riastrad  * radeon_cursor_reset - Re-set the current cursor, if any.
    371  1.2  riastrad  *
    372  1.2  riastrad  * @crtc: drm crtc
    373  1.2  riastrad  *
    374  1.2  riastrad  * If the CRTC passed in currently has a cursor assigned, this function
    375  1.2  riastrad  * makes sure it's visible.
    376  1.2  riastrad  */
    377  1.2  riastrad void radeon_cursor_reset(struct drm_crtc *crtc)
    378  1.2  riastrad {
    379  1.2  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
    380  1.2  riastrad 
    381  1.2  riastrad 	if (radeon_crtc->cursor_bo) {
    382  1.2  riastrad 		radeon_lock_cursor(crtc, true);
    383  1.2  riastrad 
    384  1.2  riastrad 		radeon_cursor_move_locked(crtc, radeon_crtc->cursor_x,
    385  1.2  riastrad 					  radeon_crtc->cursor_y);
    386  1.2  riastrad 
    387  1.2  riastrad 		radeon_show_cursor(crtc);
    388  1.2  riastrad 
    389  1.2  riastrad 		radeon_lock_cursor(crtc, false);
    390  1.2  riastrad 	}
    391  1.2  riastrad }
    392