2 * Copyright © 2003 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #include <kdrive-config.h>
31 nvidiaCardInit (KdCardInfo
*card
)
33 NvidiaCardInfo
*nvidiac
;
35 nvidiac
= (NvidiaCardInfo
*) xalloc (sizeof (NvidiaCardInfo
));
39 (void) nvidiaMapReg (card
, nvidiac
);
41 if (!vesaInitialize (card
, &nvidiac
->vesa
))
47 card
->driver
= nvidiac
;
53 nvidiaScreenInit (KdScreenInfo
*screen
)
55 NvidiaCardInfo
*nvidiac
= screen
->card
->driver
;
56 NvidiaScreenInfo
*nvidias
;
57 int screen_size
, memory
;
59 nvidias
= (NvidiaScreenInfo
*) xalloc (sizeof (NvidiaScreenInfo
));
62 memset (nvidias
, '\0', sizeof (NvidiaScreenInfo
));
63 if (!vesaScreenInitialize (screen
, &nvidias
->vesa
))
68 if (!nvidiac
->reg_base
)
70 if (nvidias
->vesa
.mapping
!= VESA_LINEAR
)
72 nvidias
->screen
= nvidias
->vesa
.fb
;
73 memory
= nvidias
->vesa
.fb_size
;
74 screen_size
= screen
->fb
[0].byteStride
* screen
->height
;
75 if (nvidias
->screen
&& memory
>= screen_size
+ 2048)
78 nvidias
->cursor_base
= nvidias
->screen
+ memory
- 2048;
81 nvidias
->cursor_base
= 0;
82 screen
->softCursor
= TRUE
; /* XXX for now */
83 memory
-= screen_size
;
84 if (memory
> screen
->fb
[0].byteStride
)
86 nvidias
->off_screen
= nvidias
->screen
+ screen_size
;
87 nvidias
->off_screen_size
= memory
;
91 nvidias
->off_screen
= 0;
92 nvidias
->off_screen_size
= 0;
94 screen
->driver
= nvidias
;
99 nvidiaInitScreen (ScreenPtr pScreen
)
103 KdScreenPriv(pScreen
);
104 NvidiaCardInfo
*nvidiac
= pScreenPriv
->screen
->card
->driver
;
105 if (nvidiac
->media_reg
&& nvidiac
->reg
)
106 nvidiaInitVideo(pScreen
);
109 return vesaInitScreen (pScreen
);
114 nvidiaRandRSetConfig (ScreenPtr pScreen
,
117 RRScreenSizePtr pSize
)
119 kaaWaitSync (pScreen
);
121 if (!vesaRandRSetConfig (pScreen
, rotation
, rate
, pSize
))
128 nvidiaRandRInit (ScreenPtr pScreen
)
132 pScrPriv
->rrSetConfig
= nvidiaRandRSetConfig
;
137 nvidiaFinishInitScreen (ScreenPtr pScreen
)
140 ret
= vesaFinishInitScreen (pScreen
);
142 nvidiaRandRInit (pScreen
);
148 nvidiaPreserve (KdCardInfo
*card
)
154 nvidiaOutb (NvidiaCardInfo
*nvidiac
, CARD16 port
, CARD8 val
)
156 asm volatile ("outb %b0,%w1" : : "a" (val
), "d" (port
));
160 nvidiaInb (NvidiaCardInfo
*nvidiac
, CARD16 port
)
163 asm volatile ("inb %w1,%b0" : "=a" (v
) : "d" (port
));
168 nvidiaGetIndex (NvidiaCardInfo
*nvidiac
, CARD16 addr
, CARD16 data
, CARD8 id
)
171 DBGOUT ("nvidiaGetIndex(0x%x,0x%x)\n", addr
, id
);
172 nvidiaOutb (nvidiac
, addr
, id
);
173 ret
= nvidiaInb (nvidiac
, data
);
174 DBGOUT (" -> 0x%x\n", ret
);
179 nvidiaSetIndex (NvidiaCardInfo
*nvidiac
, CARD16 addr
, CARD16 data
, CARD8 id
, CARD8 val
)
181 DBGOUT ("nvidiaSetIndex(0x%x,0x%x) = 0x%x\n", addr
, id
, val
);
182 nvidiaOutb (nvidiac
, addr
, id
);
183 nvidiaOutb (nvidiac
, data
, val
);
186 static void vgaLockUnlock (NvidiaCardInfo
*nvidiac
, Bool lock
)
190 cr11
= nvidiaGetIndex (nvidiac
, 0x3d4, 0x3d5, 0x11);
191 if (lock
) cr11
|= 0x80;
193 nvidiaSetIndex (nvidiac
, 0x3d4, 0x3d5, 0x11, cr11
);
197 static void nvidiaLockUnlock (NvidiaCardInfo
*nvidiac
, Bool lock
)
199 if (NVIDIA_IS_3(nvidiac
))
200 nvidiaSetIndex (nvidiac
, 0x3c4, 0x3c5, 0x06, lock
? 0x99 : 0x57);
202 nvidiaSetIndex (nvidiac
, 0x3c4, 0x3c5, 0x1f, lock
? 0x99 : 0x57);
203 vgaLockUnlock(nvidiac
, lock
);
207 nvidiaMapReg (KdCardInfo
*card
, NvidiaCardInfo
*nvidiac
)
209 nvidiac
->reg_base
= (CARD8
*) KdMapDevice (NVIDIA_REG_BASE(card
),
210 NVIDIA_REG_SIZE(card
));
212 if (!nvidiac
->reg_base
)
221 nvidiac
->mmio
= (CARD8
*) (nvidiac
->reg_base
+ NVIDIA_MMIO_OFF(card
));
222 nvidiac
->rop
= (NvidiaRop
*) (nvidiac
->reg_base
+ NVIDIA_ROP_OFF(card
));
223 nvidiac
->rect
= (NvidiaRectangle
*) (nvidiac
->reg_base
+ NVIDIA_RECTANGLE_OFF(card
));
224 nvidiac
->blt
= (NvidiaScreenBlt
*) (nvidiac
->reg_base
+ NVIDIA_BLT_OFF(card
));
225 nvidiac
->busy
= (NvidiaBusy
*) (nvidiac
->reg_base
+ NVIDIA_BUSY_OFF(card
));
226 KdSetMappedMode (NVIDIA_REG_BASE(card
),
227 NVIDIA_REG_SIZE(card
),
228 KD_MAPPED_MODE_REGISTERS
);
233 nvidiaUnmapReg (KdCardInfo
*card
, NvidiaCardInfo
*nvidiac
)
235 if (nvidiac
->reg_base
)
237 KdResetMappedMode (NVIDIA_REG_BASE(card
),
238 NVIDIA_REG_SIZE(card
),
239 KD_MAPPED_MODE_REGISTERS
);
240 KdUnmapDevice ((void *) nvidiac
->reg_base
, NVIDIA_REG_SIZE(card
));
241 nvidiac
->reg_base
= 0;
249 nvidiaSetMMIO (KdCardInfo
*card
, NvidiaCardInfo
*nvidiac
)
251 if (!nvidiac
->reg_base
)
252 nvidiaMapReg (card
, nvidiac
);
253 nvidiaLockUnlock (nvidiac
, FALSE
);
254 nvidiac
->fifo_free
= 0;
255 nvidiac
->fifo_size
= nvidiac
->rop
->FifoFree
.FifoFree
;
259 nvidiaResetMMIO (KdCardInfo
*card
, NvidiaCardInfo
*nvidiac
)
261 nvidiaUnmapReg (card
, nvidiac
);
262 nvidiaLockUnlock (nvidiac
, TRUE
);
266 nvidiaEnable (ScreenPtr pScreen
)
268 KdScreenPriv(pScreen
);
269 NvidiaCardInfo
*nvidiac
= pScreenPriv
->card
->driver
;
271 if (!vesaEnable (pScreen
))
274 nvidiaSetMMIO (pScreenPriv
->card
, nvidiac
);
276 KdXVEnable (pScreen
);
282 nvidiaDisable (ScreenPtr pScreen
)
284 KdScreenPriv(pScreen
);
285 NvidiaCardInfo
*nvidiac
= pScreenPriv
->card
->driver
;
288 KdXVDisable (pScreen
);
290 nvidiaResetMMIO (pScreenPriv
->card
, nvidiac
);
291 vesaDisable (pScreen
);
295 nvidiaDPMS (ScreenPtr pScreen
, int mode
)
297 return vesaDPMS (pScreen
, mode
);
301 nvidiaRestore (KdCardInfo
*card
)
303 NvidiaCardInfo
*nvidiac
= card
->driver
;
305 nvidiaResetMMIO (card
, nvidiac
);
310 nvidiaScreenFini (KdScreenInfo
*screen
)
312 NvidiaScreenInfo
*nvidias
= (NvidiaScreenInfo
*) screen
->driver
;
314 vesaScreenFini (screen
);
320 nvidiaCardFini (KdCardInfo
*card
)
322 NvidiaCardInfo
*nvidiac
= card
->driver
;
324 nvidiaUnmapReg (card
, nvidiac
);
328 #define nvidiaCursorInit 0 /* initCursor */
329 #define nvidiaCursorEnable 0 /* enableCursor */
330 #define nvidiaCursorDisable 0 /* disableCursor */
331 #define nvidiaCursorFini 0 /* finiCursor */
332 #define nvidiaRecolorCursor 0 /* recolorCursor */
334 KdCardFuncs nvidiaFuncs
= {
335 nvidiaCardInit
, /* cardinit */
336 nvidiaScreenInit
, /* scrinit */
337 nvidiaInitScreen
, /* initScreen */
338 nvidiaFinishInitScreen
, /* finishInitScreen */
339 vesaCreateResources
, /* createRes */
340 nvidiaPreserve
, /* preserve */
341 nvidiaEnable
, /* enable */
342 nvidiaDPMS
, /* dpms */
343 nvidiaDisable
, /* disable */
344 nvidiaRestore
, /* restore */
345 nvidiaScreenFini
, /* scrfini */
346 nvidiaCardFini
, /* cardfini */
348 nvidiaCursorInit
, /* initCursor */
349 nvidiaCursorEnable
, /* enableCursor */
350 nvidiaCursorDisable
, /* disableCursor */
351 nvidiaCursorFini
, /* finiCursor */
352 nvidiaRecolorCursor
, /* recolorCursor */
354 nvidiaDrawInit
, /* initAccel */
355 nvidiaDrawEnable
, /* enableAccel */
356 nvidiaDrawDisable
, /* disableAccel */
357 nvidiaDrawFini
, /* finiAccel */
359 vesaGetColors
, /* getColors */
360 vesaPutColors
, /* putColors */