1 /**************************************************************************
3 Copyright 2003 Eric Anholt
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 **************************************************************************/
28 * Eric Anholt <anholt@FreeBSD.org>
33 #include "main/context.h"
35 #include "main/imports.h"
36 #include "main/framebuffer.h"
37 #include "main/renderbuffer.h"
39 #include "sis_context.h"
45 #include "GL/internal/dri_interface.h"
47 #define SIS_AGP_DISABLE(def) \
48 DRI_CONF_OPT_BEGIN(agp_disable,bool,def) \
49 DRI_CONF_DESC(en,"Disable AGP vertex dispatch") \
52 PUBLIC
const char __driConfigOptions
[] =
54 DRI_CONF_SECTION_QUALITY
55 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
57 DRI_CONF_SECTION_DEBUG
59 DRI_CONF_NO_RAST(false)
62 static const GLuint __driNConfigOptions
= 3;
64 extern const struct dri_extension card_extensions
[];
66 static const __DRIconfig
**
67 sisFillInModes(__DRIscreen
*psp
, int bpp
)
69 __DRIconfig
**configs
;
70 unsigned depth_buffer_factor
;
71 unsigned back_buffer_factor
;
74 static const GLenum back_buffer_modes
[] = {
75 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
77 uint8_t depth_bits_array
[4];
78 uint8_t stencil_bits_array
[4];
79 uint8_t msaa_samples_array
[1];
81 depth_bits_array
[0] = 0;
82 stencil_bits_array
[0] = 0;
83 depth_bits_array
[1] = 16;
84 stencil_bits_array
[1] = 0;
85 depth_bits_array
[2] = 24;
86 stencil_bits_array
[2] = 8;
87 depth_bits_array
[3] = 32;
88 stencil_bits_array
[3] = 0;
90 msaa_samples_array
[0] = 0;
92 depth_buffer_factor
= 4;
93 back_buffer_factor
= 2;
97 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
100 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
103 configs
= driCreateConfigs(fb_format
, fb_type
, depth_bits_array
,
104 stencil_bits_array
, depth_buffer_factor
,
105 back_buffer_modes
, back_buffer_factor
,
106 msaa_samples_array
, 1);
107 if (configs
== NULL
) {
108 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
, __LINE__
);
112 return (const __DRIconfig
**) configs
;
116 /* Create the device specific screen private data struct.
119 sisCreateScreen( __DRIscreen
*sPriv
)
121 sisScreenPtr sisScreen
;
122 SISDRIPtr sisDRIPriv
= (SISDRIPtr
)sPriv
->pDevPriv
;
124 if (sPriv
->devPrivSize
!= sizeof(SISDRIRec
)) {
125 fprintf(stderr
,"\nERROR! sizeof(SISDRIRec) does not match passed size from device driver\n");
129 /* Allocate the private area */
130 sisScreen
= (sisScreenPtr
)CALLOC( sizeof(*sisScreen
) );
131 if ( sisScreen
== NULL
)
134 sisScreen
->screenX
= sisDRIPriv
->width
;
135 sisScreen
->screenY
= sisDRIPriv
->height
;
136 sisScreen
->cpp
= sisDRIPriv
->bytesPerPixel
;
137 sisScreen
->deviceID
= sisDRIPriv
->deviceID
;
138 sisScreen
->AGPCmdBufOffset
= sisDRIPriv
->AGPCmdBufOffset
;
139 sisScreen
->AGPCmdBufSize
= sisDRIPriv
->AGPCmdBufSize
;
140 sisScreen
->sarea_priv_offset
= sizeof(drm_sarea_t
);
142 sisScreen
->mmio
.handle
= sisDRIPriv
->regs
.handle
;
143 sisScreen
->mmio
.size
= sisDRIPriv
->regs
.size
;
144 if ( drmMap( sPriv
->fd
, sisScreen
->mmio
.handle
, sisScreen
->mmio
.size
,
145 &sisScreen
->mmio
.map
) )
151 if (sisDRIPriv
->agp
.size
) {
152 sisScreen
->agp
.handle
= sisDRIPriv
->agp
.handle
;
153 sisScreen
->agpBaseOffset
= drmAgpBase(sPriv
->fd
);
154 sisScreen
->agp
.size
= sisDRIPriv
->agp
.size
;
155 if ( drmMap( sPriv
->fd
, sisScreen
->agp
.handle
, sisScreen
->agp
.size
,
156 &sisScreen
->agp
.map
) )
158 sisScreen
->agp
.size
= 0;
162 sisScreen
->driScreen
= sPriv
;
164 /* parse information in __driConfigOptions */
165 driParseOptionInfo(&sisScreen
->optionCache
,
166 __driConfigOptions
, __driNConfigOptions
);
171 /* Destroy the device specific screen private data struct.
174 sisDestroyScreen( __DRIscreen
*sPriv
)
176 sisScreenPtr sisScreen
= (sisScreenPtr
)sPriv
->private;
178 if ( sisScreen
== NULL
)
181 if (sisScreen
->agp
.size
!= 0)
182 drmUnmap( sisScreen
->agp
.map
, sisScreen
->agp
.size
);
183 drmUnmap( sisScreen
->mmio
.map
, sisScreen
->mmio
.size
);
186 sPriv
->private = NULL
;
190 /* Create and initialize the Mesa and driver specific pixmap buffer
194 sisCreateBuffer( __DRIscreen
*driScrnPriv
,
195 __DRIdrawable
*driDrawPriv
,
196 const __GLcontextModes
*mesaVis
,
199 /*sisScreenPtr screen = (sisScreenPtr) driScrnPriv->private;*/
200 struct gl_framebuffer
*fb
;
203 return GL_FALSE
; /* not implemented */
205 fb
= _mesa_create_framebuffer(mesaVis
);
207 _mesa_add_soft_renderbuffers(fb
,
208 GL_FALSE
, /* color */
209 GL_FALSE
, /* depth */
210 mesaVis
->stencilBits
> 0,
211 mesaVis
->accumRedBits
> 0,
212 GL_FALSE
, /* alpha */
214 driDrawPriv
->driverPrivate
= (void *) fb
;
216 return (driDrawPriv
->driverPrivate
!= NULL
);
221 sisDestroyBuffer(__DRIdrawable
*driDrawPriv
)
223 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
226 static void sisCopyBuffer( __DRIdrawable
*dPriv
)
228 sisContextPtr smesa
= (sisContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
231 while ((*smesa
->FrameCountPtr
) - MMIO_READ(0x8a2c) > SIS_MAX_FRAME_LENGTH
)
236 for (i
= 0; i
< dPriv
->numClipRects
; i
++) {
237 drm_clip_rect_t
*box
= &dPriv
->pClipRects
[i
];
240 MMIO(REG_SRC_ADDR
, smesa
->back
.offset
);
241 MMIO(REG_SRC_PITCH
, smesa
->back
.pitch
| ((smesa
->bytesPerPixel
== 4) ?
242 BLIT_DEPTH_32
: BLIT_DEPTH_16
));
243 MMIO(REG_SRC_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
244 MMIO(REG_DST_X_Y
, ((box
->x1
- dPriv
->x
) << 16) | (box
->y1
- dPriv
->y
));
245 MMIO(REG_DST_ADDR
, smesa
->front
.offset
);
246 MMIO(REG_DST_PITCH_HEIGHT
, (smesa
->virtualY
<< 16) | smesa
->front
.pitch
);
247 MMIO(REG_WIDTH_HEIGHT
, ((box
->y2
- box
->y1
) << 16) | (box
->x2
- box
->x1
));
248 MMIO(REG_BLIT_CMD
, CMD_DIR_X_INC
| CMD_DIR_Y_INC
| CMD_ROP_SRC
);
249 MMIO(REG_CommandQueue
, -1);
252 *(GLint
*)(smesa
->IOBase
+0x8a2c) = *smesa
->FrameCountPtr
;
253 (*smesa
->FrameCountPtr
)++;
259 /* Copy the back color buffer to the front color buffer */
261 sisSwapBuffers(__DRIdrawable
*dPriv
)
263 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
264 sisContextPtr smesa
= (sisContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
265 GLcontext
*ctx
= smesa
->glCtx
;
267 if (ctx
->Visual
.doubleBufferMode
) {
268 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
269 sisCopyBuffer( dPriv
);
272 /* XXX this shouldn't be an error but we can't handle it for now */
273 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
279 * This is the driver specific part of the createNewScreen entry point.
281 * \todo maybe fold this into intelInitDriver
283 * \return the __GLcontextModes supported by this driver
285 static const __DRIconfig
**
286 sisInitScreen(__DRIscreen
*psp
)
288 static const __DRIversion ddx_expected
= {0, 8, 0};
289 static const __DRIversion dri_expected
= {4, 0, 0};
290 static const __DRIversion drm_expected
= {1, 0, 0};
291 static const char *driver_name
= "SiS";
292 SISDRIPtr dri_priv
= (SISDRIPtr
)psp
->pDevPriv
;
294 if (!driCheckDriDdxDrmVersions2(driver_name
,
295 &psp
->dri_version
, &dri_expected
,
296 &psp
->ddx_version
, &ddx_expected
,
297 &psp
->drm_version
, &drm_expected
))
300 psp
->private = sisCreateScreen(psp
);
303 sisDestroyScreen(psp
);
307 return sisFillInModes(psp
, dri_priv
->bytesPerPixel
* 8);
310 const struct __DriverAPIRec driDriverAPI
= {
311 .InitScreen
= sisInitScreen
,
312 .DestroyScreen
= sisDestroyScreen
,
313 .CreateContext
= sisCreateContext
,
314 .DestroyContext
= sisDestroyContext
,
315 .CreateBuffer
= sisCreateBuffer
,
316 .DestroyBuffer
= sisDestroyBuffer
,
317 .SwapBuffers
= sisSwapBuffers
,
318 .MakeCurrent
= sisMakeCurrent
,
319 .UnbindContext
= sisUnbindContext
,
321 .GetDrawableMSC
= NULL
,
324 .SwapBuffersMSC
= NULL
328 /* This is the table of extensions that the loader will dlsym() for. */
329 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
330 &driCoreExtension
.base
,
331 &driLegacyExtension
.base
,