Xv: work around some overlay bandwidth problems - may break things though
[nouveau] / src / nv50_cursor.c
1 /*
2  * Copyright (c) 2007 NVIDIA, Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <string.h>
29
30 #include <cursorstr.h>
31
32 #include "nv_include.h"
33 #include "nv50_type.h"
34 #include "nv50_cursor.h"
35 #include "nv50_display.h"
36
37 #define CURSOR_PTR ((CARD32*)pNv->Cursor->map)
38
39 void NV50SetCursorPosition(xf86CrtcPtr crtc, int x, int y)
40 {
41     NVPtr pNv = NVPTR(crtc->scrn);
42     const int headOff = 0x1000*NV50CrtcGetHead(crtc);
43
44     x &= 0xffff;
45     y &= 0xffff;
46     pNv->REGS[(0x00647084 + headOff)/4] = y << 16 | x;
47     pNv->REGS[(0x00647080 + headOff)/4] = 0;
48 }
49
50 void NV50LoadCursorARGB(xf86CrtcPtr crtc, CARD32 *src)
51 {
52     NVPtr pNv = NVPTR(crtc->scrn);
53     CARD32 *dst = CURSOR_PTR;
54
55     /* Assume cursor is 64x64 */
56     memcpy(dst, src, 64 * 64 * 4);
57 }
58
59 Bool NV50CursorAcquire(ScrnInfoPtr pScrn)
60 {
61     NVPtr pNv = NVPTR(pScrn);
62     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
63     int i;
64
65     if(!pNv->HWCursor) return TRUE;
66
67     /* Initialize the cursor on each head */
68     for(i = 0; i < xf86_config->num_crtc; i++) {
69         const int headOff = 0x10 * NV50CrtcGetHead(xf86_config->crtc[i]);
70
71         pNv->REGS[(0x00610270+headOff)/4] = 0x2000;
72         while(pNv->REGS[(0x00610270+headOff)/4] & 0x30000);
73
74         pNv->REGS[(0x00610270+headOff)/4] = 1;
75         while((pNv->REGS[(0x00610270+headOff)/4] & 0x30000) != 0x10000);
76     }
77
78     return TRUE;
79 }
80
81 void NV50CursorRelease(ScrnInfoPtr pScrn)
82 {
83     NVPtr pNv = NVPTR(pScrn);
84     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
85     int i;
86
87     if(!pNv->HWCursor) return;
88
89     /* Release the cursor on each head */
90     for(i = 0; i < xf86_config->num_crtc; i++) {
91         const int headOff = 0x10 * NV50CrtcGetHead(xf86_config->crtc[i]);
92
93         pNv->REGS[(0x00610270+headOff)/4] = 0;
94         while(pNv->REGS[(0x00610270+headOff)/4] & 0x30000);
95     }
96 }
97
98 Bool NV50CursorInit(ScreenPtr pScreen)
99 {
100     return xf86_cursors_init(pScreen, 64, 64,
101             HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
102             HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 |
103             HARDWARE_CURSOR_ARGB);
104 }