Remove #ifdef DEBUG's in code, but still allow compiler to remove debug
[mesa.git] / src / mesa / drivers / dri / unichrome / via_fb.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 */
24
25 #include <assert.h>
26
27 #include "via_context.h"
28 #include "via_ioctl.h"
29 #include "via_fb.h"
30 #include "xf86drm.h"
31 #include <sys/ioctl.h>
32
33 GLboolean
34 via_alloc_back_buffer(viaContextPtr vmesa)
35 {
36 drm_via_mem_t fb;
37 unsigned char *pFB;
38 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
39 fb.context = vmesa->hHWContext;
40 fb.size = vmesa->back.size;
41 fb.type = VIDEO;
42 if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
43 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
44 return GL_FALSE;
45
46 pFB = vmesa->driScreen->pFB;
47
48 vmesa->back.offset = fb.offset;
49 vmesa->back.map = (char *)(fb.offset + (GLuint)pFB);
50 vmesa->back.index = fb.index;
51 if (VIA_DEBUG) {
52 fprintf(stderr, "back offset = %08x\n", vmesa->back.offset);
53 fprintf(stderr, "back index = %d\n", vmesa->back.index);
54 }
55
56 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
57 return GL_TRUE;
58 }
59
60 GLboolean
61 via_alloc_front_buffer(viaContextPtr vmesa)
62 {
63 drm_via_mem_t fb;
64 unsigned char *pFB;
65 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
66 fb.context = vmesa->hHWContext;
67 fb.size = vmesa->back.size;
68 fb.type = VIDEO;
69 if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
70 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
71 return GL_FALSE;
72
73 pFB = vmesa->driScreen->pFB;
74
75 vmesa->front.offset = fb.offset;
76 vmesa->front.map = (char *)(fb.offset + (GLuint)pFB);
77 vmesa->front.index = fb.index;
78 if (VIA_DEBUG) {
79 fprintf(stderr, "front offset = %08x\n", vmesa->front.offset);
80 fprintf(stderr, "front index = %d\n", vmesa->front.index);
81 }
82
83
84 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
85 return GL_TRUE;
86 }
87
88 void
89 via_free_back_buffer(viaContextPtr vmesa)
90 {
91 drm_via_mem_t fb;
92
93 if (!vmesa) return;
94 fb.context = vmesa->hHWContext;
95 fb.index = vmesa->back.index;
96 fb.type = VIDEO;
97 ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
98 vmesa->back.map = NULL;
99 }
100
101 void
102 via_free_front_buffer(viaContextPtr vmesa)
103 {
104 drm_via_mem_t fb;
105
106 if (!vmesa) return;
107 fb.context = vmesa->hHWContext;
108 fb.index = vmesa->front.index;
109 fb.type = VIDEO;
110 ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
111 vmesa->front.map = NULL;
112 }
113
114 GLboolean
115 via_alloc_depth_buffer(viaContextPtr vmesa)
116 {
117 drm_via_mem_t fb;
118 unsigned char *pFB;
119 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
120 fb.context = vmesa->hHWContext;
121 fb.size = vmesa->depth.size;
122 fb.type = VIDEO;
123
124 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
125 return GL_FALSE;
126 }
127
128 pFB = vmesa->driScreen->pFB;
129
130 vmesa->depth.offset = fb.offset;
131 vmesa->depth.map = (char *)(fb.offset + (GLuint)pFB);
132 vmesa->depth.index = fb.index;
133 if (VIA_DEBUG) {
134 fprintf(stderr, "depth offset = %08x\n", vmesa->depth.offset);
135 fprintf(stderr, "depth index = %d\n", vmesa->depth.index);
136 }
137
138 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
139 return GL_TRUE;
140 }
141
142 void
143 via_free_depth_buffer(viaContextPtr vmesa)
144 {
145 drm_via_mem_t fb;
146
147 if (!vmesa) return;
148 fb.context = vmesa->hHWContext;
149 fb.index = vmesa->depth.index;
150 fb.type = VIDEO;
151 ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
152 vmesa->depth.map = NULL;
153 }
154
155 GLboolean
156 via_alloc_dma_buffer(viaContextPtr vmesa)
157 {
158 drmVIADMAInit init;
159
160 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
161 vmesa->dma = (GLuint *) malloc(VIA_DMA_BUFSIZ);
162
163 /*
164 * Check whether AGP DMA has been initialized.
165 */
166
167 init.func = VIA_DMA_INITIALIZED;
168 vmesa->useAgp =
169 ( 0 == drmCommandWrite(vmesa->driFd, DRM_VIA_DMA_INIT,
170 &init, sizeof(init)));
171 if (vmesa->useAgp)
172 printf("unichrome_dri.so: Using AGP.\n");
173 else
174 printf("unichrome_dri.so: Using PCI.\n");
175
176 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
177 return ((vmesa->dma) ? GL_TRUE : GL_FALSE);
178 }
179
180 void
181 via_free_dma_buffer(viaContextPtr vmesa)
182 {
183 if (!vmesa) return;
184 free(vmesa->dma);
185 vmesa->dma = 0;
186 }
187
188 GLboolean
189 via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
190 {
191 drm_via_mem_t fb;
192 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
193 fb.context = vmesa->hHWContext;
194 fb.size = t->texMem.size;
195 fb.type = VIDEO;
196 if (VIA_DEBUG) {
197 fprintf(stderr, "texture size = %d\n", fb.size);
198 fprintf(stderr, "texture type = %d\n", fb.type);
199 }
200 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
201 fprintf(stderr, "via_alloc_texture fail\n");
202 return GL_FALSE;
203 }
204
205 t->texMem.offset = fb.offset;
206 t->texMem.index = fb.index;
207 if (VIA_DEBUG) fprintf(stderr, "texture index = %d\n", (GLuint)fb.index);
208
209 t->bufAddr = (unsigned char *)(fb.offset + (GLuint)vmesa->driScreen->pFB);
210 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
211 return GL_TRUE;
212 }
213 /*=* John Sheng [2003.5.31] agp tex *=*/
214 GLboolean
215 via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t)
216 {
217 drm_via_mem_t fb;
218 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
219 fb.context = vmesa->hHWContext;
220 fb.size = t->texMem.size;
221 fb.type = AGP;
222 if (VIA_DEBUG) {
223 fprintf(stderr, "texture_agp size = %d\n", fb.size);
224 fprintf(stderr, "texture type = %d\n", fb.type);
225 }
226 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
227 fprintf(stderr, "via_alloc_texture_agp fail\n");
228 return GL_FALSE;
229 }
230
231 t->texMem.offset = fb.offset;
232 t->texMem.index = fb.index;
233 if (VIA_DEBUG) fprintf(stderr, "texture agp index = %d\n", (GLuint)fb.index);
234
235 t->bufAddr = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset);
236 /*=* John Sheng [2003.5.31] agp tex *=*/
237 t->inAGP = GL_TRUE;
238 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
239 return GL_TRUE;
240 }
241
242 void
243 via_free_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
244 {
245 drm_via_mem_t fb;
246 if (VIA_DEBUG) {
247 fprintf(stderr, "via_free_texture: index = %d\n",
248 t->texMem.index);
249 fprintf(stderr, "via_free_texture: size = %d\n",
250 t->texMem.size);
251 }
252 if (!vmesa) {
253 fprintf(stderr, "!mesa\n");
254 return;
255 }
256
257 fb.context = vmesa->hHWContext;
258 fb.index = t->texMem.index;
259
260 /*=* John Sheng [2003.5.31] agp tex *=*/
261 if(t->inAGP)
262 fb.type = AGP;
263 else
264 fb.type = VIDEO;
265
266 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
267 if(vmesa->shareCtx) {
268 fb.context = ((viaContextPtr)((GLcontext *)(vmesa->shareCtx)->DriverCtx))->hHWContext;
269 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
270 fprintf(stderr, "via_free_texture fail\n");
271 }
272 }
273 else
274 fprintf(stderr, "via_free_texture fail\n");
275 }
276
277 t->bufAddr = NULL;
278 }