First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / r128 / r128.c
blob9e7f312e06a242db0536da67baf3b8339c3db4b5
1 /*
2 * Copyright © 2003 Anders Carlsson
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 Anders Carlsson not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Anders Carlsson 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 * ANDERS CARLSSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ANDERS CARLSSON 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.
22 #ifdef HAVE_CONFIG_H
23 #include <kdrive-config.h>
24 #endif
25 #include "r128.h"
27 static Bool
28 r128CardInit (KdCardInfo *card)
30 R128CardInfo *r128c;
32 r128c = (R128CardInfo *) xalloc (sizeof (R128CardInfo));
33 if (!r128c)
34 return FALSE;
36 r128MapReg (card, r128c);
38 if (!vesaInitialize (card, &r128c->vesa))
40 xfree (r128c);
41 return FALSE;
44 r128c->fifo_size = 0;
46 card->driver = r128c;
48 return TRUE;
51 static Bool
52 r128ScreenInit (KdScreenInfo *screen)
54 R128ScreenInfo *r128s;
55 int screen_size, memory;
57 r128s = (R128ScreenInfo *) xalloc (sizeof (R128ScreenInfo));
58 if (!r128s)
59 return FALSE;
60 memset (r128s, '\0', sizeof (R128ScreenInfo));
61 if (!vesaScreenInitialize (screen, &r128s->vesa))
63 xfree (r128s);
64 return FALSE;
66 #if 0
67 /* if (!r128c->reg)
68 screen->dumb = TRUE; */
70 if (r128s->vesa.mapping != VESA_LINEAR)
71 screen->dumb = TRUE;
73 fprintf (stderr, "vesa mapping is %d\n", r128s->vesa.mapping);
74 #endif
75 r128s->screen = r128s->vesa.fb;
77 memory = r128s->vesa.fb_size;
78 screen_size = screen->fb[0].byteStride * screen->height;
80 memory -= screen_size;
81 if (memory > screen->fb[0].byteStride)
83 r128s->off_screen = r128s->screen + screen_size;
84 r128s->off_screen_size = memory;
86 else
88 r128s->off_screen = 0;
89 r128s->off_screen_size = 0;
91 screen->driver = r128s;
92 return TRUE;
95 static Bool
96 r128InitScreen (ScreenPtr pScreen)
98 return vesaInitScreen (pScreen);
101 static Bool
102 r128FinishInitScreen (ScreenPtr pScreen)
104 Bool ret;
106 ret = vesaFinishInitScreen (pScreen);
108 return ret;
111 static void
112 r128Preserve (KdCardInfo *card)
114 vesaPreserve (card);
117 Bool
118 r128MapReg (KdCardInfo *card, R128CardInfo *r128c)
120 r128c->reg_base = (CARD8 *) KdMapDevice (R128_REG_BASE (card),
121 R128_REG_SIZE (card));
123 if (!r128c->reg_base)
125 return FALSE;
128 KdSetMappedMode (R128_REG_BASE (card),
129 R128_REG_SIZE (card),
130 KD_MAPPED_MODE_REGISTERS);
132 return TRUE;
135 void
136 r128UnmapReg (KdCardInfo *card, R128CardInfo *r128c)
138 if (r128c->reg_base)
140 KdResetMappedMode (R128_REG_BASE (card),
141 R128_REG_SIZE (card),
142 KD_MAPPED_MODE_REGISTERS);
143 KdUnmapDevice ((void *) r128c->reg_base, R128_REG_SIZE (card));
144 r128c->reg_base = 0;
148 void
149 r128SetMMIO (KdCardInfo *card, R128CardInfo *r128c)
151 if (!r128c->reg_base)
152 r128MapReg (card, r128c);
155 void
156 r128ResetMMIO (KdCardInfo *card, R128CardInfo *r128c)
158 r128UnmapReg (card, r128c);
162 static Bool
163 r128DPMS (ScreenPtr pScreen, int mode)
165 /* XXX */
166 return TRUE;
169 static Bool
170 r128Enable (ScreenPtr pScreen)
172 KdScreenPriv (pScreen);
173 R128CardInfo *r128c = pScreenPriv->card->driver;
175 if (!vesaEnable (pScreen))
176 return FALSE;
178 r128SetMMIO (pScreenPriv->card, r128c);
179 r128DPMS (pScreen, KD_DPMS_NORMAL);
181 return TRUE;
184 static void
185 r128Disable (ScreenPtr pScreen)
187 KdScreenPriv (pScreen);
188 R128CardInfo *r128c = pScreenPriv->card->driver;
190 r128ResetMMIO (pScreenPriv->card, r128c);
191 vesaDisable (pScreen);
194 static void
195 r128Restore (KdCardInfo *card)
197 R128CardInfo *r128c = card->driver;
199 r128ResetMMIO (card, r128c);
200 vesaRestore (card);
203 static void
204 r128ScreenFini (KdScreenInfo *screen)
206 R128ScreenInfo *r128s = (R128ScreenInfo *) screen->driver;
208 vesaScreenFini (screen);
209 xfree (r128s);
210 screen->driver = 0;
213 static void
214 r128CardFini (KdCardInfo *card)
216 R128CardInfo *r128c = (R128CardInfo *)card->driver;
218 r128UnmapReg (card, r128c);
219 vesaCardFini (card);
222 KdCardFuncs r128Funcs = {
223 r128CardInit, /* cardinit */
224 r128ScreenInit, /* scrinit */
225 r128InitScreen, /* initScreen */
226 r128FinishInitScreen, /* finishInitScreen */
227 vesaCreateResources,/* createRes */
228 r128Preserve, /* preserve */
229 r128Enable, /* enable */
230 r128DPMS, /* dpms */
231 r128Disable, /* disable */
232 r128Restore, /* restore */
233 r128ScreenFini, /* scrfini */
234 r128CardFini, /* cardfini */
236 0, /* initCursor */
237 0, /* enableCursor */
238 0, /* disableCursor */
239 0, /* finiCursor */
240 0, /* recolorCursor */
242 r128DrawInit, /* initAccel */
243 r128DrawEnable, /* enableAccel */
244 r128DrawDisable, /* disableAccel */
245 r128DrawFini, /* finiAccel */
247 vesaGetColors, /* getColors */
248 vesaPutColors, /* putColors */