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.
24 ** Copyright 2004 (C) Ralph Thomas <ralpht@gmail.com>
26 ** http://www.viatech.com.tw/
33 ** viaCardInit( KdCardInfo* card )
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.
41 ** card Information stucture for the card we want to bring up.
42 ** It should be a VIA card.
45 ** TRUE Initialization went ok.
46 ** FALSE Initialization failed.
49 viaCardInit( KdCardInfo
* card
) {
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
) ) {
70 ** Bool viaScreenInit( KdScreenInfo* screen )
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.
79 ** screen Information structure for the screen to enable.
82 ** TRUE Screen was initialized successfully
83 ** FALSE Screen initialization failed
86 viaScreenInit( KdScreenInfo
* screen
) {
87 ViaCardInfo
* viac
= screen
->card
->driver
;
90 vias
= (ViaScreenInfo
*) xalloc( sizeof( ViaScreenInfo
) );
91 if( !vias
) return FALSE
;
92 memset( vias
, '\0', sizeof( ViaScreenInfo
) );
94 if( !vesaScreenInitialize( screen
, &vias
->vesa
) ) {
100 ** XXX: What does this do?
104 if( vias
->vesa
.mapping
!= VESA_LINEAR
)
107 screen
->driver
= vias
;
112 ** Bool viaInitScreen( ScreenPtr pScreen )
115 ** High level screen initialization occurs here. We could register XV
116 ** adaptors, etc, here.
119 ** pScreen X screen information
122 ** TRUE Initialization was successful,
123 ** FALSE Initialization failed.
126 viaInitScreen( ScreenPtr pScreen
) {
127 return vesaInitScreen( pScreen
);
131 ** Bool viaFinishInitScreen
134 ** Finish up any high-level screen initialization. Per-Screen extension
135 ** initialization can be done here.
138 ** pScreen X screen information
141 ** TRUE Initialization was successful.
142 ** FALSE Initialization failed.
145 viaFinishInitScreen( ScreenPtr pScreen
) {
146 return vesaFinishInitScreen( pScreen
);
150 ** Bool viaCreateResources( ScreenPtr pScreen )
153 ** Do any screen specific configuration.
156 ** pScreen X screen information
159 ** TRUE configuration was successful.
160 ** FALSE configuration failed.
163 viaCreateResources( ScreenPtr pScreen
) {
164 return vesaCreateResources( pScreen
);
168 ** void viaPreserve( KdCardInfo* card )
171 ** Save the current state of the chip, so that it can be restored by
172 ** viaRestore at a later time.
175 ** card Information structure for the chip we want to preserve the
185 viaPreserve( KdCardInfo
* card
) {
186 vesaPreserve( card
);
190 ** void viaRestore( KdCardInfo* card )
193 ** Restore the previous state of the chip, as saved by viaPreserve
197 ** card Information structure for the chip we want to restore the
206 static void viaRestore( KdCardInfo
* card
) {
207 ViaCardInfo
* viac
= card
->driver
;
209 viaResetMMIO( card
, viac
);
214 ** Bool viaEnable( ScreenPtr pScreen )
217 ** This is where we set the card up for drawing the specified screen, e.g.:
218 ** set the mode and mmap the framebuffer.
221 ** pScreen X screen information
224 ** TRUE the screen was enabled
225 ** FALSE the screen could not be enabled
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" );
245 ** void viaDisable( ScreenPtr pScreen )
248 ** Shut down drawing: save some state and unmap the framebuffer.
251 ** pScreen X screen information
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 )
269 ** Release memory and resources allocated by viaScreenInit.
272 ** screen Information structure for the screen to release.
281 viaScreenFini( KdScreenInfo
* screen
) {
282 ViaScreenInfo
* vias
= screen
->driver
;
284 vesaScreenFini( screen
);
290 ** void viaCardFini( KdCardInfo* card )
293 ** Release memory and resources allocated by viaCardInit.
296 ** card Information structure for the chip to release.
305 viaCardFini( KdCardInfo
* card
) {
306 ViaCardInfo
* viac
= card
->driver
;
308 viaUnmapReg( card
, viac
);
309 vesaCardFini( card
);
314 ** void viaSetMMIO( KdCardInfo* card, ViaCardInfo* viac )
317 ** Map the card's registers, if they're not already
321 ** card generic chip information
322 ** viac VIA-driver specific chip information
327 void viaSetMMIO( KdCardInfo
* card
, ViaCardInfo
* viac
) {
328 if( !viac
->mapBase
) viaMapReg( card
, viac
);
332 ** void viaResetMMIO( KdCardInfo* card, ViaCardInfo* viac )
335 ** Unmap chip's registers.
338 ** card generic chip information
339 ** viac VIA-driver specific chip information
344 void viaResetMMIO( KdCardInfo
* card
, ViaCardInfo
* viac
) {
345 viaUnmapReg( card
, viac
);
349 ** Bool viaMapReg( KdCardInfo* card, ViaCardInfo* viac )
352 ** Map the chip's registers into our address space.
355 ** card the card information
356 ** viac the VIA-driver specific card information
359 ** TRUE the registers were succesfully mapped
360 ** FALSE the registers could not be mapped
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" );
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 );
385 ** void viaUnmapReg( KdCardInfo* card, ViaCardInfo* viac )
388 ** Unmap the the chip's registers.
391 ** card the card information
392 ** viac the VIA-driver specific card information
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
) );
407 KdCardFuncs viaFuncs
= {
408 viaCardInit
, /* cardinit */
409 viaScreenInit
, /* scrinit */
410 viaInitScreen
, /* initScreen */
411 viaFinishInitScreen
, /* finishInitScreen */
412 viaCreateResources
, /* createRes */
413 viaPreserve
, /* preserve */
414 viaEnable
, /* enable */
416 viaDisable
, /* disable */
417 viaRestore
, /* restore */
418 viaScreenFini
, /* scrfini */
419 viaCardFini
, /* cardfini */
422 0, /* enableCursor */
423 0, /* disableCursor */
425 0, /* recolorCursor */
427 viaDrawInit
, /* initAccel */
428 viaDrawEnable
, /* enableAccel */
429 viaDrawDisable
, /* disableAccel */
430 viaDrawFini
, /* finiAccel */
432 vesaGetColors
, /* getColors */
433 vesaPutColors
, /* putColors */