2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
32 #include "simple_list.h"
34 #include "via_state.h"
38 #include "via_ioctl.h"
39 #include "via_screen.h"
43 extern viaContextPtr current_mesa
;
45 static drmBufMapPtr
via_create_empty_buffers(void)
49 retval
= (drmBufMapPtr
)MALLOC(sizeof(drmBufMap
));
50 if (retval
== NULL
) return NULL
;
51 memset(retval
, 0, sizeof(drmBufMap
));
53 retval
->list
= (drmBufPtr
)MALLOC(sizeof(drmBuf
) * VIA_DMA_BUF_NR
);
54 if (retval
->list
== NULL
) {
58 memset(retval
->list
, 0, sizeof(drmBuf
) * VIA_DMA_BUF_NR
);
63 viaInitDriver(__DRIscreenPrivate
*sPriv
)
65 viaScreenPrivate
*viaScreen
;
66 VIADRIPtr gDRIPriv
= (VIADRIPtr
)sPriv
->pDevPriv
;
68 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
70 if (!driCheckDriDdxDrmVersions(sPriv
, "Via", 4, 0, 4, 0, 1, 1))
73 /* Allocate the private area */
74 viaScreen
= (viaScreenPrivate
*) CALLOC(sizeof(viaScreenPrivate
));
76 __driUtilMessage("viaInitDriver: alloc viaScreenPrivate struct failed");
80 viaScreen
->driScrnPriv
= sPriv
;
81 sPriv
->private = (void *)viaScreen
;
83 viaScreen
->deviceID
= gDRIPriv
->deviceID
;
84 viaScreen
->width
= gDRIPriv
->width
;
85 viaScreen
->height
= gDRIPriv
->height
;
86 viaScreen
->mem
= gDRIPriv
->mem
;
87 viaScreen
->bitsPerPixel
= gDRIPriv
->bytesPerPixel
<< 3;
88 viaScreen
->bytesPerPixel
= gDRIPriv
->bytesPerPixel
;
89 viaScreen
->fbOffset
= 0;
90 viaScreen
->fbSize
= gDRIPriv
->fbSize
;
92 viaScreen
->drixinerama
= gDRIPriv
->drixinerama
;
94 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
95 viaScreen
->VQEnable
= gDRIPriv
->VQEnable
;
98 fprintf(stderr
, "deviceID = %08x\n", viaScreen
->deviceID
);
99 fprintf(stderr
, "width = %08x\n", viaScreen
->width
);
100 fprintf(stderr
, "height = %08x\n", viaScreen
->height
);
101 fprintf(stderr
, "cpp = %08x\n", viaScreen
->cpp
);
102 fprintf(stderr
, "fbOffset = %08x\n", viaScreen
->fbOffset
);
107 if (gDRIPriv->bitsPerPixel == 15)
108 viaScreen->fbFormat = DV_PF_555;
110 viaScreen->fbFormat = DV_PF_565;
113 viaScreen
->bufs
= via_create_empty_buffers();
114 if (viaScreen
->bufs
== NULL
) {
115 __driUtilMessage("viaInitDriver: via_create_empty_buffers() failed");
120 if (drmMap(sPriv
->fd
,
121 gDRIPriv
->regs
.handle
,
123 (drmAddress
*)&viaScreen
->reg
) != 0) {
125 sPriv
->private = NULL
;
126 __driUtilMessage("viaInitDriver: drmMap regs failed");
130 if (gDRIPriv
->agp
.size
) {
131 if (drmMap(sPriv
->fd
,
132 gDRIPriv
->agp
.handle
,
134 (drmAddress
*)&viaScreen
->agpLinearStart
) != 0) {
136 drmUnmap(viaScreen
->reg
, gDRIPriv
->agp
.size
);
137 sPriv
->private = NULL
;
138 __driUtilMessage("viaInitDriver: drmMap agp failed");
141 viaScreen
->agpBase
= (GLuint
*)gDRIPriv
->agp
.handle
;
143 viaScreen
->agpLinearStart
= 0;
145 viaScreen
->sareaPrivOffset
= gDRIPriv
->sarea_priv_offset
;
147 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
153 viaDestroyScreen(__DRIscreenPrivate
*sPriv
)
155 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
156 VIADRIPtr gDRIPriv
= (VIADRIPtr
)sPriv
->pDevPriv
;
158 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
160 drmUnmap(viaScreen
->reg
, gDRIPriv
->regs
.size
);
161 if (gDRIPriv
->agp
.size
)
162 drmUnmap(viaScreen
->agpLinearStart
, gDRIPriv
->agp
.size
);
164 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
167 sPriv
->private = NULL
;
171 viaCreateBuffer(__DRIscreenPrivate
*driScrnPriv
,
172 __DRIdrawablePrivate
*driDrawPriv
,
173 const __GLcontextModes
*mesaVis
,
176 viaContextPtr vmesa
= current_mesa
;
178 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
180 /*=* John Sheng [2003.7.2] for visual config & patch viewperf *=*/
181 if (mesaVis
->depthBits
== 32 && vmesa
->depthBits
== 16) {
182 vmesa
->depthBits
= mesaVis
->depthBits
;
183 vmesa
->depth
.size
*= 2;
184 vmesa
->depth
.pitch
*= 2;
185 vmesa
->depth
.bpp
*= 2;
186 if (vmesa
->depth
.map
)
187 via_free_depth_buffer(vmesa
);
188 if (!via_alloc_depth_buffer(vmesa
)) {
189 via_free_depth_buffer(vmesa
);
193 ((__GLcontextModes
*)mesaVis
)->depthBits
= 16; /* XXX : sure you want to change read-only data? */
197 driDrawPriv
->driverPrivate
= (void *)
198 _mesa_create_framebuffer(mesaVis
,
199 GL_FALSE
, /* software depth buffer? */
200 mesaVis
->stencilBits
> 0,
201 mesaVis
->accumRedBits
> 0,
202 GL_FALSE
/* s/w alpha planes */);
204 if (vmesa
) vmesa
->drawType
= GLX_PBUFFER_BIT
;
206 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
208 return (driDrawPriv
->driverPrivate
!= NULL
);
211 driDrawPriv
->driverPrivate
= (void *)
212 _mesa_create_framebuffer(mesaVis
,
213 GL_FALSE
, /* software depth buffer? */
214 mesaVis
->stencilBits
> 0,
215 mesaVis
->accumRedBits
> 0,
216 GL_FALSE
/* s/w alpha planes */);
218 if (vmesa
) vmesa
->drawType
= GLX_WINDOW_BIT
;
220 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
222 return (driDrawPriv
->driverPrivate
!= NULL
);
228 viaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
231 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
233 _mesa_destroy_framebuffer((GLframebuffer
*)(driDrawPriv
->driverPrivate
));
235 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
241 /* Initialize the fullscreen mode.
244 XMesaOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
246 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
247 vmesa
->doPageFlip
= 1;
248 vmesa
->currentPage
= 0;
252 /* Shut down the fullscreen mode.
255 XMesaCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
257 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
259 if (vmesa
->currentPage
== 1) {
261 vmesa
->currentPage
= 0;
264 vmesa
->doPageFlip
= GL_FALSE
;
265 vmesa
->Setup
[VIA_DESTREG_DI0
] = vmesa
->driScreen
->front_offset
;
271 static struct __DriverAPIRec viaAPI
= {
285 * This is the bootstrap function for the driver.
286 * The __driCreateScreen name is the symbol that libGL.so fetches.
287 * Return: pointer to a __DRIscreenPrivate.
290 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
291 int numConfigs
, __GLXvisualConfig
*config
)
293 __DRIscreenPrivate
*psp
;
294 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &viaAPI
);
298 void *__driCreateScreen(struct DRIDriverRec
*driver
,
299 struct DRIDriverContextRec
*driverContext
)
301 __DRIscreenPrivate
*psp
;
302 psp
= __driUtilCreateScreen(driver
, driverContext
, &viaAPI
);