2
/**************************************************************************
4
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
7
Permission is hereby granted, free of charge, to any person obtaining a
8
copy of this software and associated documentation files (the
9
"Software"), to deal in the Software without restriction, including
10
without limitation the rights to use, copy, modify, merge, publish,
11
distribute, sub license, and/or sell copies of the Software, and to
12
permit persons to whom the Software is furnished to do so, subject to
13
the following conditions:
15
The above copyright notice and this permission notice (including the
16
next paragraph) shall be included in all copies or substantial portions
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
**************************************************************************/
28
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i740/i740_cursor.c,v 1.5 2002/10/21 13:32:58 alanh Exp $ */
32
* Daryll Strauss <daryll@precisioninsight.com>
37
#include "xf86_OSproc.h"
38
#include "xf86_ansic.h"
41
#include "xf86fbman.h"
47
static void I740LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
48
static void I740ShowCursor(ScrnInfoPtr pScrn);
49
static void I740HideCursor(ScrnInfoPtr pScrn);
50
static void I740SetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
51
static void I740SetCursorColors(ScrnInfoPtr pScrn, int bg, int fb);
52
static Bool I740UseHWCursor(ScreenPtr pScrn, CursorPtr pCurs);
55
I740CursorInit(ScreenPtr pScreen)
59
xf86CursorInfoPtr infoPtr;
62
pScrn = xf86Screens[pScreen->myNum];
63
pI740 = I740PTR(pScrn);
64
pI740->CursorInfoRec = infoPtr = xf86CreateCursorInfoRec();
65
if (!infoPtr) return FALSE;
67
infoPtr->MaxWidth = 64;
68
infoPtr->MaxHeight = 64;
69
infoPtr->Flags = HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
70
HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
71
HARDWARE_CURSOR_INVERT_MASK |
72
HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK |
73
HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
74
HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64;
76
infoPtr->SetCursorColors = I740SetCursorColors;
77
infoPtr->SetCursorPosition = I740SetCursorPosition;
78
infoPtr->LoadCursorImage = I740LoadCursorImage;
79
infoPtr->HideCursor = I740HideCursor;
80
infoPtr->ShowCursor = I740ShowCursor;
81
infoPtr->UseHWCursor = I740UseHWCursor;
84
* Allocate a region the full width and tall enough
85
* that at least 6K of video memory is consumed.
86
* Then use a 1 kilobyte piece that is 4K byte aligned
87
* within that region. KAO.
89
fbarea = xf86AllocateOffscreenArea(pScreen,
91
((6*1024)/(pScrn->displayWidth*pI740->cpp))+1,
95
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
96
"Hardware cursor disabled due to failure allocating offscreen memory.\n");
99
pI740->CursorStart = ((((fbarea->box.x1 + pScrn->displayWidth * fbarea->box.y1) * pI740->cpp)+4096)&0xfff000);
102
* Perhaps move the cursor to the beginning of the frame buffer
103
* so that it never fails?
105
if (pI740->CursorStart>4*1024*1024) {
106
pI740->CursorStart=0;
107
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
108
"Disabling hardware cursor due to large framebuffer\n");
110
return xf86InitCursor(pScreen, infoPtr);
114
I740UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) {
118
pScrn = xf86Screens[pScreen->myNum];
119
pI740 = I740PTR(pScrn);
120
if (pScrn->currentMode->Flags&V_DBLSCAN)
122
if (!pI740->CursorStart) return FALSE;
127
I740LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) {
132
pI740 = I740PTR(pScrn);
133
pcurs = (CARD8 *)(pI740->FbBase + pI740->CursorStart);
134
for (y = 0; y < 64; y++) {
135
for (x = 0; x < 64 / 4; x++) {
142
I740SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) {
146
pI740 = I740PTR(pScrn);
147
if (x >= 0) flag = CURSOR_X_POS;
152
pI740->writeControl(pI740, XRX, CURSOR_X_LO, x&0xFF);
153
pI740->writeControl(pI740, XRX, CURSOR_X_HI, (((x >> 8) & 0x07) | flag));
155
if (y >= 0) flag = CURSOR_Y_POS;
160
pI740->writeControl(pI740, XRX, CURSOR_Y_LO, y&0xFF);
161
pI740->writeControl(pI740, XRX, CURSOR_Y_HI, (((y >> 8) & 0x07) | flag));
165
I740ShowCursor(ScrnInfoPtr pScrn) {
169
pI740 = I740PTR(pScrn);
170
pI740->writeControl(pI740, XRX, CURSOR_BASEADDR_LO,
171
(pI740->CursorStart & 0x0000F000) >> 8);
172
pI740->writeControl(pI740, XRX, CURSOR_BASEADDR_HI,
173
(pI740->CursorStart & 0x003F0000) >> 16);
174
pI740->writeControl(pI740, XRX, CURSOR_CONTROL,
175
CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C);
177
tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
178
tmp |= HW_CURSOR_ENABLE;
179
pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
183
I740HideCursor(ScrnInfoPtr pScrn) {
187
pI740 = I740PTR(pScrn);
188
tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
189
tmp &= ~HW_CURSOR_ENABLE;
190
pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
194
I740SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) {
198
pI740 = I740PTR(pScrn);
199
tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
200
tmp |= EXTENDED_PALETTE;
201
pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
203
pI740->writeStandard(pI740, DACMASK, 0xFF);
204
pI740->writeStandard(pI740, DACWX, 0x04);
206
pI740->writeStandard(pI740, DACDATA, (bg & 0x00FF0000) >> 16);
207
pI740->writeStandard(pI740, DACDATA, (bg & 0x0000FF00) >> 8);
208
pI740->writeStandard(pI740, DACDATA, (bg & 0x000000FF));
210
pI740->writeStandard(pI740, DACDATA, (fg & 0x00FF0000) >> 16);
211
pI740->writeStandard(pI740, DACDATA, (fg & 0x0000FF00) >> 8);
212
pI740->writeStandard(pI740, DACDATA, (fg & 0x000000FF));
214
tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
215
tmp &= ~EXTENDED_PALETTE;
216
pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);