First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / via / via.c
blobb8e1036aa1fcbccd958809367eea559f526e4f03
1 /*
2 * Copyright © 2004 Ralph Thomas
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 Ralph Thomas not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Ralph Thomas 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 * RALPH THOMAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL RALPH THOMAS 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 ** VIA CLE266 driver
24 ** Copyright 2004 (C) Ralph Thomas <ralpht@gmail.com>
26 ** http://www.viatech.com.tw/
29 #include "via.h"
30 #include "viadraw.h"
33 ** viaCardInit( KdCardInfo* card )
35 ** Description:
36 ** Create card specific structures, map chip registers and initialize the
37 ** VESA driver. We make the VESA driver do boring stuff for us, like set
38 ** up a framebuffer and program a mode.
40 ** Parameters:
41 ** card Information stucture for the card we want to bring up.
42 ** It should be a VIA card.
44 ** Return:
45 ** TRUE Initialization went ok.
46 ** FALSE Initialization failed.
48 static Bool
49 viaCardInit( KdCardInfo* card ) {
50 ViaCardInfo* viac;
52 viac = (ViaCardInfo*) xalloc( sizeof( ViaCardInfo ) );
53 if( !viac ) return FALSE;
54 memset( viac, '\0', sizeof( ViaCardInfo ) );
57 viaMapReg( card, viac );
59 if( !vesaInitialize( card, &viac->vesa ) ) {
60 xfree( viac );
61 return FALSE;
64 card->driver = viac;
66 return TRUE;
70 ** Bool viaScreenInit( KdScreenInfo* screen )
72 ** Description:
73 ** Initialize a single screen, described by the screen parameter.
74 ** This is where fairly low-level screen related things get setup,
75 ** such as video mode and resolution. Currently that all gets
76 ** handed off to the VESA driver.
78 ** Parameters:
79 ** screen Information structure for the screen to enable.
81 ** Return:
82 ** TRUE Screen was initialized successfully
83 ** FALSE Screen initialization failed
85 static Bool
86 viaScreenInit( KdScreenInfo* screen ) {
87 ViaCardInfo* viac = screen->card->driver;
88 ViaScreenInfo* vias;
90 vias = (ViaScreenInfo*) xalloc( sizeof( ViaScreenInfo ) );
91 if( !vias ) return FALSE;
92 memset( vias, '\0', sizeof( ViaScreenInfo ) );
94 if( !vesaScreenInitialize( screen, &vias->vesa ) ) {
95 xfree( vias );
96 return FALSE;
100 ** XXX: What does this do?
102 if( !viac->mapBase )
103 screen->dumb = TRUE;
104 if( vias->vesa.mapping != VESA_LINEAR )
105 screen->dumb = TRUE;
107 screen->driver = vias;
108 return TRUE;
112 ** Bool viaInitScreen( ScreenPtr pScreen )
114 ** Description:
115 ** High level screen initialization occurs here. We could register XV
116 ** adaptors, etc, here.
118 ** Arguments:
119 ** pScreen X screen information
121 ** Return:
122 ** TRUE Initialization was successful,
123 ** FALSE Initialization failed.
125 static Bool
126 viaInitScreen( ScreenPtr pScreen ) {
127 return vesaInitScreen( pScreen );
131 ** Bool viaFinishInitScreen
133 ** Description:
134 ** Finish up any high-level screen initialization. Per-Screen extension
135 ** initialization can be done here.
137 ** Arguments:
138 ** pScreen X screen information
140 ** Return:
141 ** TRUE Initialization was successful.
142 ** FALSE Initialization failed.
144 static Bool
145 viaFinishInitScreen( ScreenPtr pScreen ) {
146 return vesaFinishInitScreen( pScreen );
150 ** Bool viaCreateResources( ScreenPtr pScreen )
152 ** Description:
153 ** Do any screen specific configuration.
155 ** Arguments:
156 ** pScreen X screen information
158 ** Return:
159 ** TRUE configuration was successful.
160 ** FALSE configuration failed.
162 static Bool
163 viaCreateResources( ScreenPtr pScreen ) {
164 return vesaCreateResources( pScreen );
168 ** void viaPreserve( KdCardInfo* card )
170 ** Description:
171 ** Save the current state of the chip, so that it can be restored by
172 ** viaRestore at a later time.
174 ** Arguments:
175 ** card Information structure for the chip we want to preserve the
176 ** state of.
178 ** Return:
179 ** None.
181 ** See Also:
182 ** viaRestore
184 static void
185 viaPreserve( KdCardInfo* card ) {
186 vesaPreserve( card );
190 ** void viaRestore( KdCardInfo* card )
192 ** Description:
193 ** Restore the previous state of the chip, as saved by viaPreserve
194 ** earlier.
196 ** Arguments:
197 ** card Information structure for the chip we want to restore the
198 ** state of.
200 ** Return:
201 ** None.
203 ** See Also:
204 ** viaPreserve
206 static void viaRestore( KdCardInfo* card ) {
207 ViaCardInfo* viac = card->driver;
209 viaResetMMIO( card, viac );
210 vesaRestore( card );
214 ** Bool viaEnable( ScreenPtr pScreen )
216 ** Description:
217 ** This is where we set the card up for drawing the specified screen, e.g.:
218 ** set the mode and mmap the framebuffer.
220 ** Arguments:
221 ** pScreen X screen information
223 ** Return:
224 ** TRUE the screen was enabled
225 ** FALSE the screen could not be enabled
227 static Bool
228 viaEnable( ScreenPtr pScreen ) {
229 KdScreenPriv( pScreen );
230 ViaCardInfo* viac = pScreenPriv->card->driver;
232 if( !vesaEnable( pScreen ) ) return FALSE;
234 viaSetMMIO( pScreenPriv->card, viac );
236 if( !viac->mapBase ) {
237 ErrorF( "Could not map CLE266 graphics registers" );
238 return FALSE;
241 return TRUE;
245 ** void viaDisable( ScreenPtr pScreen )
247 ** Description:
248 ** Shut down drawing: save some state and unmap the framebuffer.
250 ** Arguments:
251 ** pScreen X screen information
253 ** Return:
254 ** None.
256 static void
257 viaDisable( ScreenPtr pScreen ) {
258 KdScreenPriv( pScreen );
259 ViaCardInfo* viac = pScreenPriv->card->driver;
261 viaResetMMIO( pScreenPriv->card, viac );
262 vesaDisable( pScreen );
266 ** void viaScreenFini( KdScreenInfo* screen )
268 ** Description:
269 ** Release memory and resources allocated by viaScreenInit.
271 ** Arguments:
272 ** screen Information structure for the screen to release.
274 ** Return:
275 ** None.
277 ** See Also:
278 ** viaScreenInit
280 static void
281 viaScreenFini( KdScreenInfo* screen ) {
282 ViaScreenInfo* vias = screen->driver;
284 vesaScreenFini( screen );
285 xfree( vias );
286 screen->driver = 0;
290 ** void viaCardFini( KdCardInfo* card )
292 ** Description:
293 ** Release memory and resources allocated by viaCardInit.
295 ** Arguments:
296 ** card Information structure for the chip to release.
298 ** Return:
299 ** None.
301 ** See Also:
302 ** viaCardInit
304 static void
305 viaCardFini( KdCardInfo* card ) {
306 ViaCardInfo* viac = card->driver;
308 viaUnmapReg( card, viac );
309 vesaCardFini( card );
310 xfree( viac );
314 ** void viaSetMMIO( KdCardInfo* card, ViaCardInfo* viac )
316 ** Description:
317 ** Map the card's registers, if they're not already
318 ** mapped.
320 ** Arguments:
321 ** card generic chip information
322 ** viac VIA-driver specific chip information
324 ** Return:
325 ** None.
327 void viaSetMMIO( KdCardInfo* card, ViaCardInfo* viac ) {
328 if( !viac->mapBase ) viaMapReg( card, viac );
332 ** void viaResetMMIO( KdCardInfo* card, ViaCardInfo* viac )
334 ** Description:
335 ** Unmap chip's registers.
337 ** Arguments:
338 ** card generic chip information
339 ** viac VIA-driver specific chip information
341 ** Return:
342 ** None.
344 void viaResetMMIO( KdCardInfo* card, ViaCardInfo* viac ) {
345 viaUnmapReg( card, viac );
349 ** Bool viaMapReg( KdCardInfo* card, ViaCardInfo* viac )
351 ** Description:
352 ** Map the chip's registers into our address space.
354 ** Arguments:
355 ** card the card information
356 ** viac the VIA-driver specific card information
358 ** Return:
359 ** TRUE the registers were succesfully mapped
360 ** FALSE the registers could not be mapped
362 Bool
363 viaMapReg( KdCardInfo* card, ViaCardInfo* viac ) {
364 viac->mapBase = (VOL8*) KdMapDevice( VIA_REG_BASE( card ),
365 VIA_REG_SIZE( card ) );
367 if( !viac->mapBase ) {
368 ErrorF( "Couldn't allocate viac->mapBase\n" );
369 return FALSE;
372 KdSetMappedMode( VIA_REG_BASE( card ), VIA_REG_SIZE( card ),
373 KD_MAPPED_MODE_REGISTERS );
376 ** Enable extended IO space
378 VGAOUT8( 0x3C4, 0x10 );
379 VGAOUT8( 0x3C5, 0x01 );
381 return TRUE;
385 ** void viaUnmapReg( KdCardInfo* card, ViaCardInfo* viac )
387 ** Description:
388 ** Unmap the the chip's registers.
390 ** Arguments:
391 ** card the card information
392 ** viac the VIA-driver specific card information
394 ** Return:
395 ** None.
397 void
398 viaUnmapReg( KdCardInfo* card, ViaCardInfo* viac ) {
399 if( !viac->mapBase ) return;
401 KdResetMappedMode( VIA_REG_BASE( card ), VIA_REG_SIZE( card ),
402 KD_MAPPED_MODE_REGISTERS );
403 KdUnmapDevice( (void*) viac->mapBase, VIA_REG_SIZE( card ) );
404 viac->mapBase = 0;
407 KdCardFuncs viaFuncs = {
408 viaCardInit, /* cardinit */
409 viaScreenInit, /* scrinit */
410 viaInitScreen, /* initScreen */
411 viaFinishInitScreen, /* finishInitScreen */
412 viaCreateResources, /* createRes */
413 viaPreserve, /* preserve */
414 viaEnable, /* enable */
415 vesaDPMS, /* dpms */
416 viaDisable, /* disable */
417 viaRestore, /* restore */
418 viaScreenFini, /* scrfini */
419 viaCardFini, /* cardfini */
421 0, /* initCursor */
422 0, /* enableCursor */
423 0, /* disableCursor */
424 0, /* finiCursor */
425 0, /* recolorCursor */
427 viaDrawInit, /* initAccel */
428 viaDrawEnable, /* enableAccel */
429 viaDrawDisable, /* disableAccel */
430 viaDrawFini, /* finiAccel */
432 vesaGetColors, /* getColors */
433 vesaPutColors, /* putColors */