First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / pm2 / pm2.c
blob148f03abdc4c2f6d4f26c8c98c2d0207454abf0a
1 #ifdef HAVE_CONFIG_H
2 #include <kdrive-config.h>
3 #endif
4 #include "kdrive.h"
5 #include "kaa.h"
7 #include "pm2.h"
9 #define PARTPROD(a,b,c) (((a)<<6) | ((b)<<3) | (c))
11 char bppand[4] = { 0x03, /* 8bpp */
12 0x01, /* 16bpp */
13 0x00, /* 24bpp */
14 0x00 /* 32bpp */};
16 int partprodPermedia[] = {
17 -1,
18 PARTPROD(0,0,1), PARTPROD(0,1,1), PARTPROD(1,1,1), PARTPROD(1,1,2),
19 PARTPROD(1,2,2), PARTPROD(2,2,2), PARTPROD(1,2,3), PARTPROD(2,2,3),
20 PARTPROD(1,3,3), PARTPROD(2,3,3), PARTPROD(1,2,4), PARTPROD(3,3,3),
21 PARTPROD(1,3,4), PARTPROD(2,3,4), -1, PARTPROD(3,3,4),
22 PARTPROD(1,4,4), PARTPROD(2,4,4), -1, PARTPROD(3,4,4),
23 -1, PARTPROD(2,3,5), -1, PARTPROD(4,4,4),
24 PARTPROD(1,4,5), PARTPROD(2,4,5), PARTPROD(3,4,5), -1,
25 -1, -1, -1, PARTPROD(4,4,5),
26 PARTPROD(1,5,5), PARTPROD(2,5,5), -1, PARTPROD(3,5,5),
27 -1, -1, -1, PARTPROD(4,5,5),
28 -1, -1, -1, PARTPROD(3,4,6),
29 -1, -1, -1, PARTPROD(5,5,5),
30 PARTPROD(1,5,6), PARTPROD(2,5,6), -1, PARTPROD(3,5,6),
31 -1, -1, -1, PARTPROD(4,5,6),
32 -1, -1, -1, -1,
33 -1, -1, -1, PARTPROD(5,5,6),
34 -1, -1, -1, -1,
35 -1, -1, -1, -1,
36 -1, -1, -1, -1,
37 -1, -1, -1, -1,
38 -1, -1, -1, -1,
39 -1, -1, -1, -1,
40 -1, -1, -1, -1,
41 -1, -1, -1, -1,
42 -1, -1, -1, -1,
43 -1, -1, -1, -1,
44 -1, -1, -1, -1,
45 -1, -1, -1, -1,
46 -1, -1, -1, -1,
47 -1, -1, -1, -1,
48 -1, -1, -1, -1,
49 -1, -1, -1, -1,
50 0};
52 static Bool
53 pmMapReg(KdCardInfo *card, PM2CardInfo *pm2c)
55 pm2c->reg_base = (CARD8 *)KdMapDevice(PM2_REG_BASE(card),
56 PM2_REG_SIZE(card));
58 if (pm2c->reg_base == NULL)
59 return FALSE;
61 KdSetMappedMode(PM2_REG_BASE(card), PM2_REG_SIZE(card),
62 KD_MAPPED_MODE_REGISTERS);
64 return TRUE;
67 static void
68 pmUnmapReg(KdCardInfo *card, PM2CardInfo *pm2c)
70 if (pm2c->reg_base) {
71 KdResetMappedMode(PM2_REG_BASE(card), PM2_REG_SIZE(card),
72 KD_MAPPED_MODE_REGISTERS);
73 KdUnmapDevice((void *)pm2c->reg_base, PM2_REG_SIZE(card));
74 pm2c->reg_base = 0;
78 Bool
79 pmCardInit (KdCardInfo *card)
81 PM2CardInfo *pm2c;
83 pm2c = (PM2CardInfo *) xalloc (sizeof (PM2CardInfo));
84 if (!pm2c)
85 return FALSE;
86 memset (pm2c, '\0', sizeof (PM2CardInfo));
88 (void) pmMapReg (card, pm2c);
90 if (!vesaInitialize (card, &pm2c->vesa))
92 xfree (pm2c);
93 return FALSE;
96 pm2c->InFifoSpace = 0;
98 card->driver = pm2c;
100 return TRUE;
103 static void
104 pmCardFini (KdCardInfo *card)
106 PM2CardInfo *pm2c = (PM2CardInfo *) card->driver;
108 pmUnmapReg (card, pm2c);
109 vesaCardFini (card);
112 Bool
113 pmScreenInit (KdScreenInfo *screen)
115 PM2CardInfo *pm2c = screen->card->driver;
116 PM2ScreenInfo *pm2s;
117 int screen_size, memory;
119 pm2s = (PM2ScreenInfo *) xalloc (sizeof (PM2ScreenInfo));
120 if (!pm2s)
121 return FALSE;
122 memset (pm2s, '\0', sizeof (PM2ScreenInfo));
124 if (!vesaScreenInitialize (screen, &pm2s->vesa))
126 xfree (pm2s);
127 return FALSE;
130 pm2c->pprod = partprodPermedia[screen->width >> 5];
131 pm2c->bppalign = bppand[(screen->fb[0].bitsPerPixel>>3)-1];
133 pm2s->screen = pm2s->vesa.fb;
134 memory = pm2s->vesa.fb_size;
136 screen_size = screen->fb[0].byteStride * screen->height;
138 if (pm2s->screen && memory >= screen_size + 2048)
140 memory -= 2048;
141 pm2s->cursor_base = pm2s->screen + memory - 2048;
143 else
144 pm2s->cursor_base = 0;
145 memory -= screen_size;
146 if (memory > screen->fb[0].byteStride)
148 pm2s->off_screen = pm2s->screen + screen_size;
149 pm2s->off_screen_size = memory;
151 else
153 pm2s->off_screen = 0;
154 pm2s->off_screen_size = 0;
157 switch (screen->fb[0].bitsPerPixel) {
158 case 8:
159 pm2c->BppShift = 2;
160 break;
161 case 16:
162 pm2c->BppShift = 1;
163 break;
164 case 24:
165 pm2c->BppShift = 2;
166 break;
167 case 32:
168 pm2c->BppShift = 0;
169 break;
172 screen->driver = pm2s;
174 return TRUE;
177 static void
178 pmScreenFini (KdScreenInfo *screen)
180 PM2ScreenInfo *pm2s = (PM2ScreenInfo *) screen->driver;
182 vesaScreenFini (screen);
183 xfree (pm2s);
184 screen->driver = 0;
187 static Bool
188 pmInitScreen (ScreenPtr pScreen)
190 return vesaInitScreen (pScreen);
193 #ifdef RANDR
194 static Bool
195 pmRandRSetConfig (ScreenPtr pScreen,
196 Rotation rotation,
197 int rate,
198 RRScreenSizePtr pSize)
200 kaaWaitSync (pScreen);
202 if (!vesaRandRSetConfig (pScreen, rotation, rate, pSize))
203 return FALSE;
205 return TRUE;
208 static void
209 pmRandRInit (ScreenPtr pScreen)
211 rrScrPriv(pScreen);
213 pScrPriv->rrSetConfig = pmRandRSetConfig;
215 #endif
217 static Bool
218 pmFinishInitScreen (ScreenPtr pScreen)
220 Bool ret;
221 ret = vesaFinishInitScreen (pScreen);
222 #ifdef RANDR
223 pmRandRInit (pScreen);
224 #endif
225 return ret;
228 static void
229 pmPreserve(KdCardInfo *card)
231 vesaPreserve(card);
234 static void
235 pmRestore(KdCardInfo *card)
237 vesaRestore (card);
240 static Bool
241 pmEnable (ScreenPtr pScreen)
243 if (!vesaEnable (pScreen))
244 return FALSE;
246 #ifdef XV
247 KdXVEnable (pScreen);
248 #endif
250 return TRUE;
253 static void
254 pmDisable(ScreenPtr pScreen)
256 #ifdef XV
257 KdXVDisable (pScreen);
258 #endif
259 vesaDisable (pScreen);
262 static Bool
263 pmDPMS(ScreenPtr pScreen, int mode)
265 return vesaDPMS (pScreen, mode);
268 KdCardFuncs PM2Funcs = {
269 pmCardInit, /* cardinit */
270 pmScreenInit, /* scrinit */
271 pmInitScreen, /* initScreen */
272 pmFinishInitScreen, /* finishInitScreen */
273 vesaCreateResources, /* createRes */
274 pmPreserve, /* preserve */
275 pmEnable, /* enable */
276 pmDPMS, /* dpms */
277 pmDisable, /* disable */
278 pmRestore, /* restore */
279 pmScreenFini, /* scrfini */
280 pmCardFini, /* cardfini */
282 0, /* initCursor */
283 0, /* enableCursor */
284 0, /* disableCursor */
285 0, /* finiCursor */
286 NULL, /* recolorCursor */
288 pmDrawInit, /* initAccel */
289 pmDrawEnable, /* enableAccel */
290 pmDrawDisable, /* disableAccel */
291 pmDrawFini, /* finiAccel */
293 vesaGetColors, /* getColors */
294 vesaPutColors, /* putColors */