summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/unichrome/via_fb.c
blob: 44503c7288c3b8c101de85a2ab0fc2d67d41e19d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include <assert.h>

#include "via_context.h"
#include "via_ioctl.h"
#include "via_fb.h"
#include <sys/ioctl.h>

GLboolean
via_alloc_back_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;
    unsigned char *pFB;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
    fb.context = vmesa->hHWContext;
    fb.size = vmesa->back.size;
    fb.type = VIDEO;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
#endif
    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
        return GL_FALSE;
    
    pFB = vmesa->driScreen->pFB;
    
    vmesa->back.offset = fb.offset;
    vmesa->back.map = (char *)(fb.offset + (GLuint)pFB);
    vmesa->back.index = fb.index;
#ifdef DEBUG    
    if (VIA_DEBUG) {
	fprintf(stderr, "back offset = %08x\n", vmesa->back.offset);
	fprintf(stderr, "back index = %d\n", vmesa->back.index);
    }

    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif    
    return GL_TRUE;
}

GLboolean
via_alloc_front_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;
    unsigned char *pFB;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
    fb.context = vmesa->hHWContext;
    fb.size = vmesa->back.size;
    fb.type = VIDEO;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
#endif
    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
        return GL_FALSE;
    
    pFB = vmesa->driScreen->pFB;
    
    vmesa->front.offset = fb.offset;
    vmesa->front.map = (char *)(fb.offset + (GLuint)pFB);
    vmesa->front.index = fb.index;
#ifdef DEBUG    
    if (VIA_DEBUG) {
	fprintf(stderr, "front offset = %08x\n", vmesa->front.offset);
	fprintf(stderr, "front index = %d\n", vmesa->front.index);
    }


    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif    
    return GL_TRUE;
}

void
via_free_back_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;

    if (!vmesa) return;
    fb.context = vmesa->hHWContext;
    fb.index = vmesa->back.index;
    fb.type = VIDEO;
    ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
    vmesa->back.map = NULL;
}

void
via_free_front_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;

    if (!vmesa) return;
    fb.context = vmesa->hHWContext;
    fb.index = vmesa->front.index;
    fb.type = VIDEO;
    ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
    vmesa->front.map = NULL;
}

GLboolean
via_alloc_depth_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;
    unsigned char *pFB;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);    
#endif	
    fb.context = vmesa->hHWContext;
    fb.size = vmesa->depth.size;
    fb.type = VIDEO;

    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
	return GL_FALSE;
    }

    pFB = vmesa->driScreen->pFB;
    
    vmesa->depth.offset = fb.offset;
    vmesa->depth.map = (char *)(fb.offset + (GLuint)pFB);
    vmesa->depth.index = fb.index;
#ifdef DEBUG    
    if (VIA_DEBUG) {
	fprintf(stderr, "depth offset = %08x\n", vmesa->depth.offset);
	fprintf(stderr, "depth index = %d\n", vmesa->depth.index);    
    }	

    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);    
#endif
    return GL_TRUE;
}

void
via_free_depth_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;
	
    if (!vmesa) return;
    fb.context = vmesa->hHWContext;
    fb.index = vmesa->depth.index;
    fb.type = VIDEO;
    ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
    vmesa->depth.map = NULL;
}

GLboolean
via_alloc_dma_buffer(viaContextPtr vmesa)
{
    drm_via_mem_t fb;
    drmVIADMABuf dma;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
    if (vmesa->viaScreen->agpLinearStart) {
	/* Allocate DMA in AGP memory*/
	fb.context = vmesa->hHWContext;
	fb.size = vmesa->dma[0].size;
	fb.type = AGP;
	if (!ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
	    vmesa->dma[0].offset = fb.offset;
	    vmesa->dma[0].index = fb.index;
	    vmesa->dma[0].map = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset);
	    if (!ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
		vmesa->dma[1].offset = fb.offset;
		vmesa->dma[1].index = fb.index;
		vmesa->dma[1].map = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset); 	
		vmesa->useAgp = GL_TRUE;
		
		return GL_TRUE;
	    } 
	    else {
		/* release dma[0]*/
		return GL_FALSE;		
	    }
	}
	return GL_FALSE;	
    } 
    else {
	/* Allocate DMA in System memory */
	dma.size = vmesa->dma[0].size;

	if (drmVIAAllocateDMA(vmesa->driFd,&dma) < 0) {
	    return GL_FALSE;
	}

	vmesa->dma[0].offset = 0;
	vmesa->dma[0].map = (unsigned char *)dma.address;
	vmesa->dma[0].index = dma.index;

	drmVIAAllocateDMA(vmesa->driFd, &dma);

	vmesa->dma[1].offset = 0;
	vmesa->dma[1].map = (unsigned char *)dma.address;
	vmesa->dma[1].index = dma.index;
	vmesa->useAgp = GL_FALSE;
	
	return GL_TRUE;
    }
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif
}

void
via_free_dma_buffer(viaContextPtr vmesa)
{
    drmVIADMABuf dma;
    drm_via_mem_t fb;
    
    
    if (!vmesa) return;
    
    /* Release AGP command buffer */
    if (vmesa->useAgp) {
	fb.context = vmesa->hHWContext;
	fb.index = vmesa->dma[0].index;
	fb.type = AGP;
	ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
	vmesa->dma[0].map = NULL;    
	fb.index = vmesa->dma[1].index;
	ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
	vmesa->dma[1].map = NULL;    
    }
    /* Release System command buffer */
    else {
	/*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
	/*dma.address = (unsigned long *)vmesa->dma[0].offset;*/
	dma.address = (unsigned long *)vmesa->dma[0].map;
	/*=* John Sheng [2003.6.16] fix pci path *=*/
	dma.size = (unsigned int)vmesa->dma[0].size;
	drmVIAReleaseDMA(vmesa->driFd, &dma);
	/*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
	/*dma.address = (unsigned long *)vmesa->dma[1].offset;*/
	dma.address = (unsigned long *)vmesa->dma[1].map;
	/*=* John Sheng [2003.6.16] fix pci path *=*/
	dma.size = (unsigned int)vmesa->dma[1].size;
	drmVIAReleaseDMA(vmesa->driFd, &dma);
	/*=* John Sheng [2003.7.18] viewperf frames/sec *=*/
	/*vmesa->dma[0].offset = 0;
	vmesa->dma[1].offset = 0;*/
	vmesa->dma[0].map = 0;
	vmesa->dma[1].map = 0;
    }
} 

GLboolean
via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
{
    drm_via_mem_t fb;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
    fb.context = vmesa->hHWContext;
    fb.size = t->texMem.size;
    fb.type = VIDEO;
#ifdef DEBUG    
    if (VIA_DEBUG) {
	fprintf(stderr, "texture size = %d\n", fb.size);
	fprintf(stderr, "texture type = %d\n", fb.type);
    }
#endif
    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
	fprintf(stderr, "via_alloc_texture fail\n");
        return GL_FALSE;
    }	
    
    t->texMem.offset = fb.offset;
    t->texMem.index = fb.index;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "texture index = %d\n", (GLuint)fb.index);
#endif
    
    t->bufAddr = (unsigned char *)(fb.offset + (GLuint)vmesa->driScreen->pFB);
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);    
#endif
    return GL_TRUE;
}
/*=* John Sheng [2003.5.31]  agp tex *=*/
GLboolean
via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t)
{
    drm_via_mem_t fb;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
    fb.context = vmesa->hHWContext;
    fb.size = t->texMem.size;
    fb.type = AGP;
#ifdef DEBUG    
    if (VIA_DEBUG) {
	fprintf(stderr, "texture_agp size = %d\n", fb.size);
	fprintf(stderr, "texture type = %d\n", fb.type);
    }
#endif
    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
	fprintf(stderr, "via_alloc_texture_agp fail\n");
        return GL_FALSE;
    }	
    
    t->texMem.offset = fb.offset;
    t->texMem.index = fb.index;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "texture agp index = %d\n", (GLuint)fb.index);
#endif
    
    t->bufAddr = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset); 	
    /*=* John Sheng [2003.5.31]  agp tex *=*/
    t->inAGP = GL_TRUE;
#ifdef DEBUG    
    if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);    
#endif
    return GL_TRUE;
}

void
via_free_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
{
    drm_via_mem_t fb;
#ifdef DEBUG    	
    if (VIA_DEBUG) {
	fprintf(stderr, "via_free_texture: index = %d\n",
            t->texMem.index);
	fprintf(stderr, "via_free_texture: size = %d\n",
            t->texMem.size);
    }
#endif
    if (!vmesa) {
	fprintf(stderr, "!mesa\n");
	return;
    }
    
    fb.context = vmesa->hHWContext;
    fb.index = t->texMem.index;
    
    /*=* John Sheng [2003.5.31]  agp tex *=*/
    if(t->inAGP)
	fb.type = AGP;
    else
        fb.type = VIDEO;
	    
    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
	if(vmesa->shareCtx) {
	    fb.context = ((viaContextPtr)((GLcontext *)(vmesa->shareCtx)->DriverCtx))->hHWContext;
	    if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
		fprintf(stderr, "via_free_texture fail\n");
	    }
	}
	else
	    fprintf(stderr, "via_free_texture fail\n");
    }

    t->bufAddr = NULL;
}