First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / sis300 / sis.c
blob30b7ac2c593e4ede1c45866b2bbea0050ffeb323
1 /*
2 * Copyright © 2003 Eric Anholt
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 Eric Anholt not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Eric Anholt 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 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ERIC ANHOLT 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.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #include "sis.h"
27 #include "sis_reg.h"
29 struct pci_id_entry sis_pci_ids[] = {
30 {0x1039, 0x0300, 0x1, "SiS 300/305"},
31 {0x1039, 0x5300, 0x1, "SiS 540"},
32 {0x1039, 0x6300, 0x1, "SiS 630"},
33 {0x1039, 0x7300, 0x1, "SiS 730"},
34 {0, 0, 0, NULL}
37 static Bool
38 SiSCardInit(KdCardInfo *card)
40 SiSCardInfo *sisc;
41 Bool initialized = FALSE;
43 sisc = xcalloc(sizeof(SiSCardInfo), 1);
44 if (sisc == NULL)
45 return FALSE;
47 #ifdef KDRIVEFBDEV
48 if (!initialized && fbdevInitialize(card, &sisc->backend_priv.fbdev)) {
49 sisc->use_fbdev = TRUE;
50 initialized = TRUE;
51 sisc->backend_funcs.cardfini = fbdevCardFini;
52 sisc->backend_funcs.scrfini = fbdevScreenFini;
53 sisc->backend_funcs.initScreen = fbdevInitScreen;
54 sisc->backend_funcs.finishInitScreen = fbdevFinishInitScreen;
55 sisc->backend_funcs.createRes = fbdevCreateResources;
56 sisc->backend_funcs.preserve = fbdevPreserve;
57 sisc->backend_funcs.restore = fbdevRestore;
58 sisc->backend_funcs.dpms = fbdevDPMS;
59 sisc->backend_funcs.enable = fbdevEnable;
60 sisc->backend_funcs.disable = fbdevDisable;
61 sisc->backend_funcs.getColors = fbdevGetColors;
62 sisc->backend_funcs.putColors = fbdevPutColors;
64 #endif
65 #ifdef KDRIVEVESA
66 if (!initialized && vesaInitialize(card, &sisc->backend_priv.vesa)) {
67 sisc->use_vesa = TRUE;
68 initialized = TRUE;
69 sisc->backend_funcs.cardfini = vesaCardFini;
70 sisc->backend_funcs.scrfini = vesaScreenFini;
71 sisc->backend_funcs.initScreen = vesaInitScreen;
72 sisc->backend_funcs.finishInitScreen = vesaFinishInitScreen;
73 sisc->backend_funcs.createRes = vesaCreateResources;
74 sisc->backend_funcs.preserve = vesaPreserve;
75 sisc->backend_funcs.restore = vesaRestore;
76 sisc->backend_funcs.dpms = vesaDPMS;
77 sisc->backend_funcs.enable = vesaEnable;
78 sisc->backend_funcs.disable = vesaDisable;
79 sisc->backend_funcs.getColors = vesaGetColors;
80 sisc->backend_funcs.putColors = vesaPutColors;
82 #endif
84 if (!initialized || !SiSMapReg(card, sisc)) {
85 xfree(sisc);
86 return FALSE;
89 card->driver = sisc;
91 return TRUE;
94 static void
95 SiSCardFini(KdCardInfo *card)
97 SiSCardInfo *sisc = (SiSCardInfo *)card->driver;
99 SiSUnmapReg(card, sisc);
100 sisc->backend_funcs.cardfini(card);
103 static Bool
104 SiSScreenInit(KdScreenInfo *screen)
106 SiSScreenInfo *siss;
107 SiSCardInfo(screen);
108 int success = FALSE;
110 siss = xcalloc(sizeof(SiSScreenInfo), 1);
111 if (siss == NULL)
112 return FALSE;
114 siss->sisc = sisc;
116 screen->driver = siss;
118 #ifdef KDRIVEFBDEV
119 if (sisc->use_fbdev) {
120 success = fbdevScreenInitialize(screen,
121 &siss->backend_priv.fbdev);
122 screen->memory_size = sisc->backend_priv.fbdev.fix.smem_len;
123 screen->off_screen_base =
124 sisc->backend_priv.fbdev.var.yres_virtual *
125 screen->fb[0].byteStride;
127 #endif
128 #ifdef KDRIVEVESA
129 if (sisc->use_vesa) {
130 if (screen->fb[0].depth == 0)
131 screen->fb[0].depth = 16;
132 success = vesaScreenInitialize(screen,
133 &siss->backend_priv.vesa);
135 #endif
136 if (!success) {
137 screen->driver = NULL;
138 xfree(siss);
139 return FALSE;
142 return TRUE;
145 static void
146 SiSScreenFini(KdScreenInfo *screen)
148 SiSScreenInfo *siss = (SiSScreenInfo *)screen->driver;
149 SiSCardInfo *sisc = screen->card->driver;
151 sisc->backend_funcs.scrfini(screen);
152 xfree(siss);
153 screen->driver = 0;
156 Bool
157 SiSMapReg(KdCardInfo *card, SiSCardInfo *sisc)
159 sisc->reg_base = (CARD8 *)KdMapDevice(SIS_REG_BASE(card),
160 SIS_REG_SIZE(card));
162 if (sisc->reg_base == NULL)
163 return FALSE;
165 KdSetMappedMode(SIS_REG_BASE(card), SIS_REG_SIZE(card),
166 KD_MAPPED_MODE_REGISTERS);
168 return TRUE;
171 void
172 SiSUnmapReg(KdCardInfo *card, SiSCardInfo *sisc)
174 if (sisc->reg_base) {
175 KdResetMappedMode(SIS_REG_BASE(card), SIS_REG_SIZE(card),
176 KD_MAPPED_MODE_REGISTERS);
177 KdUnmapDevice((void *)sisc->reg_base, SIS_REG_SIZE(card));
178 sisc->reg_base = 0;
182 static Bool
183 SiSInitScreen(ScreenPtr pScreen)
185 KdScreenPriv(pScreen);
186 SiSCardInfo(pScreenPriv);
188 return sisc->backend_funcs.initScreen(pScreen);
191 static Bool
192 SiSFinishInitScreen(ScreenPtr pScreen)
194 KdScreenPriv(pScreen);
195 SiSCardInfo(pScreenPriv);
197 return sisc->backend_funcs.finishInitScreen(pScreen);
200 static Bool
201 SiSCreateResources(ScreenPtr pScreen)
203 KdScreenPriv(pScreen);
204 SiSCardInfo(pScreenPriv);
206 return sisc->backend_funcs.createRes(pScreen);
209 static void
210 SiSPreserve(KdCardInfo *card)
212 SiSCardInfo *sisc = card->driver;
214 sisc->backend_funcs.preserve(card);
217 static void
218 SiSRestore(KdCardInfo *card)
220 SiSCardInfo *sisc = card->driver;
222 SiSUnmapReg(card, sisc);
224 sisc->backend_funcs.restore(card);
227 static Bool
228 SiSDPMS(ScreenPtr pScreen, int mode)
230 KdScreenPriv(pScreen);
231 SiSCardInfo(pScreenPriv);
233 return sisc->backend_funcs.dpms(pScreen, mode);
236 static Bool
237 SiSEnable(ScreenPtr pScreen)
239 KdScreenPriv(pScreen);
240 SiSCardInfo(pScreenPriv);
242 if (!sisc->backend_funcs.enable(pScreen))
243 return FALSE;
245 if ((sisc->reg_base == NULL) && !SiSMapReg(pScreenPriv->screen->card,
246 sisc))
247 return FALSE;
249 SiSDPMS(pScreen, KD_DPMS_NORMAL);
251 return TRUE;
254 static void
255 SiSDisable(ScreenPtr pScreen)
257 KdScreenPriv(pScreen);
258 SiSCardInfo(pScreenPriv);
260 SiSUnmapReg(pScreenPriv->card, sisc);
262 sisc->backend_funcs.disable(pScreen);
265 static void
266 SiSGetColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
268 KdScreenPriv(pScreen);
269 SiSCardInfo(pScreenPriv);
271 sisc->backend_funcs.getColors(pScreen, fb, n, pdefs);
274 static void
275 SiSPutColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
277 KdScreenPriv(pScreen);
278 SiSCardInfo(pScreenPriv);
280 sisc->backend_funcs.putColors(pScreen, fb, n, pdefs);
283 KdCardFuncs SiSFuncs = {
284 SiSCardInit, /* cardinit */
285 SiSScreenInit, /* scrinit */
286 SiSInitScreen, /* initScreen */
287 SiSFinishInitScreen, /* finishInitScreen */
288 SiSCreateResources, /* createRes */
289 SiSPreserve, /* preserve */
290 SiSEnable, /* enable */
291 SiSDPMS, /* dpms */
292 SiSDisable, /* disable */
293 SiSRestore, /* restore */
294 SiSScreenFini, /* scrfini */
295 SiSCardFini, /* cardfini */
297 0, /* initCursor */
298 0, /* enableCursor */
299 0, /* disableCursor */
300 0, /* finiCursor */
301 0, /* recolorCursor */
303 SiSDrawInit, /* initAccel */
304 SiSDrawEnable, /* enableAccel */
305 SiSDrawSync, /* syncAccel */
306 SiSDrawDisable, /* disableAccel */
307 SiSDrawFini, /* finiAccel */
309 SiSGetColors, /* getColors */
310 SiSPutColors, /* putColors */