Commit | Line | Data |
---|---|---|
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 | ||
760285e7 | 27 | #include <drm/drmP.h> |
6ee73861 | 28 | |
77145f1c BS |
29 | #include "nouveau_drm.h" |
30 | #include "nouveau_dma.h" | |
6ee73861 BS |
31 | #include "nouveau_crtc.h" |
32 | #include "nv50_display.h" | |
33 | ||
34 | static void | |
35 | nv50_cursor_show(struct nouveau_crtc *nv_crtc, bool update) | |
36 | { | |
6ee73861 | 37 | struct drm_device *dev = nv_crtc->base.dev; |
77145f1c | 38 | struct nouveau_drm *drm = nouveau_drm(dev); |
59c0f578 | 39 | struct nouveau_channel *evo = nv50_display(dev)->master; |
6ee73861 BS |
40 | int ret; |
41 | ||
77145f1c | 42 | NV_DEBUG(drm, "\n"); |
6ee73861 BS |
43 | |
44 | if (update && nv_crtc->cursor.visible) | |
45 | return; | |
46 | ||
77145f1c | 47 | ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2); |
6ee73861 | 48 | if (ret) { |
77145f1c | 49 | NV_ERROR(drm, "no space while unhiding cursor\n"); |
6ee73861 BS |
50 | return; |
51 | } | |
52 | ||
77145f1c | 53 | if (nv_device(drm->device)->chipset != 0x50) { |
6d597027 | 54 | BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1); |
6ee73861 BS |
55 | OUT_RING(evo, NvEvoVRAM); |
56 | } | |
6d597027 | 57 | BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2); |
6ee73861 BS |
58 | OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_SHOW); |
59 | OUT_RING(evo, nv_crtc->cursor.offset >> 8); | |
60 | ||
61 | if (update) { | |
6d597027 | 62 | BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1); |
6ee73861 BS |
63 | OUT_RING(evo, 0); |
64 | FIRE_RING(evo); | |
65 | nv_crtc->cursor.visible = true; | |
66 | } | |
67 | } | |
68 | ||
69 | static void | |
70 | nv50_cursor_hide(struct nouveau_crtc *nv_crtc, bool update) | |
71 | { | |
6ee73861 | 72 | struct drm_device *dev = nv_crtc->base.dev; |
77145f1c | 73 | struct nouveau_drm *drm = nouveau_drm(dev); |
59c0f578 | 74 | struct nouveau_channel *evo = nv50_display(dev)->master; |
6ee73861 BS |
75 | int ret; |
76 | ||
77145f1c | 77 | NV_DEBUG(drm, "\n"); |
6ee73861 BS |
78 | |
79 | if (update && !nv_crtc->cursor.visible) | |
80 | return; | |
81 | ||
77145f1c | 82 | ret = RING_SPACE(evo, (nv_device(drm->device)->chipset != 0x50 ? 5 : 3) + update * 2); |
6ee73861 | 83 | if (ret) { |
77145f1c | 84 | NV_ERROR(drm, "no space while hiding cursor\n"); |
6ee73861 BS |
85 | return; |
86 | } | |
6d597027 | 87 | BEGIN_NV04(evo, 0, NV50_EVO_CRTC(nv_crtc->index, CURSOR_CTRL), 2); |
6ee73861 BS |
88 | OUT_RING(evo, NV50_EVO_CRTC_CURSOR_CTRL_HIDE); |
89 | OUT_RING(evo, 0); | |
77145f1c | 90 | if (nv_device(drm->device)->chipset != 0x50) { |
6d597027 | 91 | BEGIN_NV04(evo, 0, NV84_EVO_CRTC(nv_crtc->index, CURSOR_DMA), 1); |
6ee73861 BS |
92 | OUT_RING(evo, NV84_EVO_CRTC_CURSOR_DMA_HANDLE_NONE); |
93 | } | |
94 | ||
95 | if (update) { | |
6d597027 | 96 | BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1); |
6ee73861 BS |
97 | OUT_RING(evo, 0); |
98 | FIRE_RING(evo); | |
99 | nv_crtc->cursor.visible = false; | |
100 | } | |
101 | } | |
102 | ||
103 | static void | |
104 | nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y) | |
105 | { | |
77145f1c | 106 | struct nouveau_device *device = nouveau_dev(nv_crtc->base.dev); |
6ee73861 | 107 | |
b334f2b3 | 108 | nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y; |
77145f1c | 109 | nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS(nv_crtc->index), |
6ee73861 BS |
110 | ((y & 0xFFFF) << 16) | (x & 0xFFFF)); |
111 | /* Needed to make the cursor move. */ | |
77145f1c | 112 | nv_wr32(device, NV50_PDISPLAY_CURSOR_USER_POS_CTRL(nv_crtc->index), 0); |
6ee73861 BS |
113 | } |
114 | ||
115 | static void | |
116 | nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset) | |
117 | { | |
6ee73861 BS |
118 | if (offset == nv_crtc->cursor.offset) |
119 | return; | |
120 | ||
121 | nv_crtc->cursor.offset = offset; | |
122 | if (nv_crtc->cursor.visible) { | |
123 | nv_crtc->cursor.visible = false; | |
124 | nv_crtc->cursor.show(nv_crtc, true); | |
125 | } | |
126 | } | |
127 | ||
128 | int | |
129 | nv50_cursor_init(struct nouveau_crtc *nv_crtc) | |
130 | { | |
131 | nv_crtc->cursor.set_offset = nv50_cursor_set_offset; | |
132 | nv_crtc->cursor.set_pos = nv50_cursor_set_pos; | |
133 | nv_crtc->cursor.hide = nv50_cursor_hide; | |
134 | nv_crtc->cursor.show = nv50_cursor_show; | |
135 | return 0; | |
136 | } |