First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / mga / mga.c
blob2ae35d143583022965327b11b8aabd9044caef9e
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 "mga.h"
27 static Bool
28 mgaCardInit (KdCardInfo *card)
30 MgaCardInfo *mgac;
32 mgac = (MgaCardInfo *) xalloc (sizeof (MgaCardInfo));
33 if (!mgac)
34 return FALSE;
36 mgaMapReg (card, mgac);
38 if (!vesaInitialize (card, &mgac->vesa))
40 xfree (mgac);
41 return FALSE;
44 mgac->fifo_size = 0;
46 card->driver = mgac;
48 return TRUE;
51 static Bool
52 mgaScreenInit (KdScreenInfo *screen)
54 MgaScreenInfo *mgas;
56 mgas = (MgaScreenInfo *) xalloc (sizeof (MgaScreenInfo));
57 if (!mgas)
58 return FALSE;
59 memset (mgas, '\0', sizeof (MgaScreenInfo));
60 if (!vesaScreenInitialize (screen, &mgas->vesa))
62 xfree (mgas);
63 return FALSE;
65 #if 0
66 /* if (!mgac->reg)
67 screen->dumb = TRUE; */
69 if (mgas->vesa.mapping != VESA_LINEAR)
70 screen->dumb = TRUE;
72 fprintf (stderr, "vesa mapping is %d\n", mgas->vesa.mapping);
73 #endif
74 screen->driver = mgas;
75 return TRUE;
78 static Bool
79 mgaInitScreen (ScreenPtr pScreen)
81 return vesaInitScreen (pScreen);
84 static Bool
85 mgaFinishInitScreen (ScreenPtr pScreen)
87 Bool ret;
89 ret = vesaFinishInitScreen (pScreen);
91 return ret;
94 static Bool
95 mgaCreateResources (ScreenPtr pScreen)
97 return vesaCreateResources (pScreen);
100 static void
101 mgaPreserve (KdCardInfo *card)
103 vesaPreserve (card);
106 Bool
107 mgaMapReg (KdCardInfo *card, MgaCardInfo *mgac)
109 mgac->reg_base = (CARD8 *) KdMapDevice (MGA_REG_BASE (card),
110 MGA_REG_SIZE (card));
112 if (!mgac->reg_base)
114 return FALSE;
117 KdSetMappedMode (MGA_REG_BASE (card),
118 MGA_REG_SIZE (card),
119 KD_MAPPED_MODE_REGISTERS);
121 return TRUE;
124 void
125 mgaUnmapReg (KdCardInfo *card, MgaCardInfo *mgac)
127 if (mgac->reg_base)
129 KdResetMappedMode (MGA_REG_BASE (card),
130 MGA_REG_SIZE (card),
131 KD_MAPPED_MODE_REGISTERS);
132 KdUnmapDevice ((void *) mgac->reg_base, MGA_REG_SIZE (card));
133 mgac->reg_base = 0;
134 /* mgac->reg = 0; */
138 void
139 mgaSetMMIO (KdCardInfo *card, MgaCardInfo *mgac)
141 if (!mgac->reg_base)
142 mgaMapReg (card, mgac);
145 void
146 mgaResetMMIO (KdCardInfo *card, MgaCardInfo *mgac)
148 mgaUnmapReg (card, mgac);
151 static Bool
152 mgaDPMS (ScreenPtr pScreen, int mode)
154 /* XXX */
155 return TRUE;
158 static Bool
159 mgaEnable (ScreenPtr pScreen)
161 KdScreenPriv (pScreen);
162 MgaCardInfo *mgac = pScreenPriv->card->driver;
164 if (!vesaEnable (pScreen))
165 return FALSE;
167 mgaSetMMIO (pScreenPriv->card, mgac);
168 mgaDPMS (pScreen, KD_DPMS_NORMAL);
170 return TRUE;
173 static void
174 mgaDisable (ScreenPtr pScreen)
176 KdScreenPriv (pScreen);
177 MgaCardInfo *mgac = pScreenPriv->card->driver;
179 mgaResetMMIO (pScreenPriv->card, mgac);
181 vesaDisable (pScreen);
184 static void
185 mgaRestore (KdCardInfo *card)
187 MgaCardInfo *mgac = card->driver;
189 mgaResetMMIO (card, mgac);
190 vesaRestore (card);
193 static void
194 mgaScreenFini (KdScreenInfo *screen)
196 MgaScreenInfo *mgas = (MgaScreenInfo *) screen->driver;
198 vesaScreenFini (screen);
199 xfree (mgas);
200 screen->driver = 0;
203 static void
204 mgaCardFini (KdCardInfo *card)
206 MgaCardInfo *mgac = (MgaCardInfo *)card->driver;
208 mgaUnmapReg (card, mgac);
209 vesaCardFini (card);
212 KdCardFuncs mgaFuncs = {
213 mgaCardInit, /* cardinit */
214 mgaScreenInit, /* scrinit */
215 mgaInitScreen, /* initScreen */
216 mgaFinishInitScreen, /* finishInitScreen */
217 mgaCreateResources, /* createRes */
218 mgaPreserve, /* preserve */
219 mgaEnable, /* enable */
220 mgaDPMS, /* dpms */
221 mgaDisable, /* disable */
222 mgaRestore, /* restore */
223 mgaScreenFini, /* scrfini */
224 mgaCardFini, /* cardfini */
226 0, /* initCursor */
227 0, /* enableCursor */
228 0, /* disableCursor */
229 0, /* finiCursor */
230 0, /* recolorCursor */
232 mgaDrawInit, /* initAccel */
233 mgaDrawEnable, /* enableAccel */
234 mgaDrawDisable, /* disableAccel */
235 mgaDrawFini, /* finiAccel */
237 vesaGetColors, /* getColors */
238 vesaPutColors, /* putColors */