blob: ba047e9251b3033e3f438f65a2448407adc18cc7 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
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"
28#include "drm_mode.h"
29
Ben Skeggs77145f12012-07-31 16:16:21 +100030#include "nouveau_drm.h"
31#include "nouveau_dma.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100032#include "nouveau_crtc.h"
33#include "nv50_display.h"
34
35static void
36nv50_cursor_show(struct nouveau_crtc *nv_crtc, bool update)
37{
Ben Skeggs6ee73862009-12-11 19:24:15 +100038 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +100039 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs59c0f572011-02-01 10:24:41 +100040 struct nouveau_channel *evo = nv50_display(dev)->master;
Ben Skeggs6ee73862009-12-11 19:24:15 +100041 int ret;
42
Ben Skeggs77145f12012-07-31 16:16:21 +100043 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100044
45 if (update && nv_crtc->cursor.visible)
46 return;
47
Ben Skeggs77145f12012-07-31 16:16:21 +100048 ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +100049 if (ret) {
Ben Skeggs77145f12012-07-31 16:16:21 +100050 NV_ERROR(drm, "no space while unhiding cursor\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100051 return;
52 }
53
Ben Skeggs77145f12012-07-31 16:16:21 +100054 if (nv_device(drm->device)->chipset != 0x50) {
Ben Skeggs6d597022012-04-01 21:09:13 +100055 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100056 OUT_RING(evo, NvEvoVRAM);
57 }
Ben Skeggs6d597022012-04-01 21:09:13 +100058 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +100059 OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_SHOW);
60 OUT_RING(evo, nv_crtc->cursor.offset >> 8);
61
62 if (update) {
Ben Skeggs6d597022012-04-01 21:09:13 +100063 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100064 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{
Ben Skeggs6ee73862009-12-11 19:24:15 +100073 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs77145f12012-07-31 16:16:21 +100074 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs59c0f572011-02-01 10:24:41 +100075 struct nouveau_channel *evo = nv50_display(dev)->master;
Ben Skeggs6ee73862009-12-11 19:24:15 +100076 int ret;
77
Ben Skeggs77145f12012-07-31 16:16:21 +100078 NV_DEBUG(drm, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100079
80 if (update && !nv_crtc->cursor.visible)
81 return;
82
Ben Skeggs77145f12012-07-31 16:16:21 +100083 ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +100084 if (ret) {
Ben Skeggs77145f12012-07-31 16:16:21 +100085 NV_ERROR(drm, "no space while hiding cursor\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +100086 return;
87 }
Ben Skeggs6d597022012-04-01 21:09:13 +100088 BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2);
Ben Skeggs6ee73862009-12-11 19:24:15 +100089 OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_HIDE);
90 OUT_RING(evo, 0);
Ben Skeggs77145f12012-07-31 16:16:21 +100091 if (nv_device(drm->device)->chipset != 0x50) {
Ben Skeggs6d597022012-04-01 21:09:13 +100092 BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100093 OUT_RING(evo, NV84_EVO_CRTC_CURSOR_DMA_HANDLE_NONE);
94 }
95
96 if (update) {
Ben Skeggs6d597022012-04-01 21:09:13 +100097 BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +100098 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{
Ben Skeggs77145f12012-07-31 16:16:21 +1000107 struct nouveau_device *device = nouveau_dev(nv_crtc->base.dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000108
Maarten Maathuisb334f2b2010-05-09 14:49:52 +0200109 nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y;
Ben Skeggs77145f12012-07-31 16:16:21 +1000110 nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS(nv_crtc->index),
Ben Skeggs6ee73862009-12-11 19:24:15 +1000111 ((y & 0xFFFF) << 16) | (x & 0xFFFF));
112 /* Needed to make the cursor move. */
Ben Skeggs77145f12012-07-31 16:16:21 +1000113 nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS_CTRL(nv_crtc->index), 0);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000114}
115
116static void
117nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
118{
Ben Skeggs6ee73862009-12-11 19:24:15 +1000119 if (offset == nv_crtc->cursor.offset)
120 return;
121
122 nv_crtc->cursor.offset = offset;
123 if (nv_crtc->cursor.visible) {
124 nv_crtc->cursor.visible = false;
125 nv_crtc->cursor.show(nv_crtc, true);
126 }
127}
128
129int
130nv50_cursor_init(struct nouveau_crtc *nv_crtc)
131{
132 nv_crtc->cursor.set_offset = nv50_cursor_set_offset;
133 nv_crtc->cursor.set_pos = nv50_cursor_set_pos;
134 nv_crtc->cursor.hide = nv50_cursor_hide;
135 nv_crtc->cursor.show = nv50_cursor_show;
136 return 0;
137}