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