UAPI: (Scripted) Remove redundant DRM UAPI header #inclusions from drivers/gpu/.
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / drivers / gpu / drm / nouveau / nv50_cursor.c
CommitLineData
6ee73861
BS
1/*
2 * Copyright (C) 2008 Maarten Maathuis.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include "drmP.h"
6ee73861
BS
28
29#define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
30#include "nouveau_reg.h"
31#include "nouveau_drv.h"
32#include "nouveau_crtc.h"
33#include "nv50_display.h"
34
35static void
36nv50_cursor_show(struct nouveau_crtc *nv_crtc, bool update)
37{
6ee73861 38 struct drm_device *dev = nv_crtc->base.dev;
ef8389a8 39 struct drm_nouveau_private *dev_priv = dev->dev_private;
59c0f578 40 struct nouveau_channel *evo = nv50_display(dev)->master;
6ee73861
BS
41 int ret;
42
ef2bb506 43 NV_DEBUG_KMS(dev, "\n");
6ee73861
BS
44
45 if (update && nv_crtc->cursor.visible)
46 return;
47
48 ret = RING_SPACE(evo, (dev_priv->chipset != 0x50 ? 5 : 3) + update * 2);
49 if (ret) {
50 NV_ERROR(dev, "no space while unhiding cursor\n");
51 return;
52 }
53
54 if (dev_priv->chipset != 0x50) {
6d597027 55 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
6ee73861
BS
56 OUT_RING(evo, NvEvoVRAM);
57 }
6d597027 58 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
6ee73861
BS
59 OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_SHOW);
60 OUT_RING(evo, nv_crtc->cursor.offset >> 8);
61
62 if (update) {
6d597027 63 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
6ee73861
BS
64 OUT_RING(evo, 0);
65 FIRE_RING(evo);
66 nv_crtc->cursor.visible = true;
67 }
68}
69
70static void
71nv50_cursor_hide(struct nouveau_crtc *nv_crtc, bool update)
72{
6ee73861 73 struct drm_device *dev = nv_crtc->base.dev;
ef8389a8 74 struct drm_nouveau_private *dev_priv = dev->dev_private;
59c0f578 75 struct nouveau_channel *evo = nv50_display(dev)->master;
6ee73861
BS
76 int ret;
77
ef2bb506 78 NV_DEBUG_KMS(dev, "\n");
6ee73861
BS
79
80 if (update && !nv_crtc->cursor.visible)
81 return;
82
83 ret = RING_SPACE(evo, (dev_priv->chipset != 0x50 ? 5 : 3) + update * 2);
84 if (ret) {
85 NV_ERROR(dev, "no space while hiding cursor\n");
86 return;
87 }
6d597027 88 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
6ee73861
BS
89 OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_HIDE);
90 OUT_RING(evo, 0);
91 if (dev_priv->chipset != 0x50) {
6d597027 92 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
6ee73861
BS
93 OUT_RING(evo, NV84_EVO_CRTC_CURSOR_DMA_HANDLE_NONE);
94 }
95
96 if (update) {
6d597027 97 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
6ee73861
BS
98 OUT_RING(evo, 0);
99 FIRE_RING(evo);
100 nv_crtc->cursor.visible = false;
101 }
102}
103
104static void
105nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
106{
107 struct drm_device *dev = nv_crtc->base.dev;
108
b334f2b3 109 nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y;
6ee73861
BS
110 nv_wr32(dev, NV50_PDISPLAY_CURSOR_USER_POS(nv_crtc->index),
111 ((y & 0xFFFF) << 16) | (x & 0xFFFF));
112 /* Needed to make the cursor move. */
113 nv_wr32(dev, NV50_PDISPLAY_CURSOR_USER_POS_CTRL(nv_crtc->index), 0);
114}
115
116static void
117nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
118{
ef2bb506 119 NV_DEBUG_KMS(nv_crtc->base.dev, "\n");
6ee73861
BS
120 if (offset == nv_crtc->cursor.offset)
121 return;
122
123 nv_crtc->cursor.offset = offset;
124 if (nv_crtc->cursor.visible) {
125 nv_crtc->cursor.visible = false;
126 nv_crtc->cursor.show(nv_crtc, true);
127 }
128}
129
130int
131nv50_cursor_init(struct nouveau_crtc *nv_crtc)
132{
133 nv_crtc->cursor.set_offset = nv50_cursor_set_offset;
134 nv_crtc->cursor.set_pos = nv50_cursor_set_pos;
135 nv_crtc->cursor.hide = nv50_cursor_hide;
136 nv_crtc->cursor.show = nv50_cursor_show;
137 return 0;
138}