silence the 'using AGP/PCI' string unless VIA_DEBUG is used.
[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_draw_buffer(viaContextPtr vmesa, viaBuffer *buf)
35 {
36 drm_via_mem_t mem;
37 mem.context = vmesa->hHWContext;
38 mem.size = buf->size;
39 mem.type = VIDEO;
40
41 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &mem))
42 return GL_FALSE;
43
44
45 buf->offset = mem.offset;
46 buf->map = (char *)vmesa->driScreen->pFB + mem.offset;
47 buf->index = mem.index;
48 return GL_TRUE;
49 }
50
51 void
52 via_free_draw_buffer(viaContextPtr vmesa, viaBuffer *buf)
53 {
54 drm_via_mem_t mem;
55
56 if (!vmesa) return;
57
58 mem.context = vmesa->hHWContext;
59 mem.index = buf->index;
60 mem.type = VIDEO;
61 ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &mem);
62 buf->map = NULL;
63 }
64
65
66 GLboolean
67 via_alloc_dma_buffer(viaContextPtr vmesa)
68 {
69 drm_via_dma_init_t init;
70
71 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
72 vmesa->dma = (GLubyte *) malloc(VIA_DMA_BUFSIZ);
73
74 /*
75 * Check whether AGP DMA has been initialized.
76 */
77 init.func = VIA_DMA_INITIALIZED;
78 vmesa->useAgp =
79 ( 0 == drmCommandWrite(vmesa->driFd, DRM_VIA_DMA_INIT,
80 &init, sizeof(init)));
81 if (VIA_DEBUG) {
82 if (vmesa->useAgp)
83 fprintf(stderr, "unichrome_dri.so: Using AGP.\n");
84 else
85 fprintf(stderr, "unichrome_dri.so: Using PCI.\n");
86
87 fprintf(stderr, "%s - out\n", __FUNCTION__);
88 }
89
90 return ((vmesa->dma) ? GL_TRUE : GL_FALSE);
91 }
92
93 void
94 via_free_dma_buffer(viaContextPtr vmesa)
95 {
96 if (!vmesa) return;
97 free(vmesa->dma);
98 vmesa->dma = 0;
99 }
100
101 GLboolean
102 via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
103 {
104 drm_via_mem_t fb;
105 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
106 fb.context = vmesa->hHWContext;
107 fb.size = t->texMem.size;
108 fb.type = VIDEO;
109 if (VIA_DEBUG) {
110 fprintf(stderr, "texture size = %d\n", fb.size);
111 fprintf(stderr, "texture type = %d\n", fb.type);
112 }
113 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
114 fprintf(stderr, "via_alloc_texture fail\n");
115 return GL_FALSE;
116 }
117
118 t->texMem.offset = fb.offset;
119 t->texMem.index = fb.index;
120 if (VIA_DEBUG) fprintf(stderr, "texture index = %d\n", (GLuint)fb.index);
121
122 t->bufAddr = (unsigned char *)(fb.offset + (GLuint)vmesa->driScreen->pFB);
123 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
124 return GL_TRUE;
125 }
126 /*=* John Sheng [2003.5.31] agp tex *=*/
127 GLboolean
128 via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t)
129 {
130 drm_via_mem_t fb;
131 if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
132 fb.context = vmesa->hHWContext;
133 fb.size = t->texMem.size;
134 fb.type = AGP;
135 if (VIA_DEBUG) {
136 fprintf(stderr, "texture_agp size = %d\n", fb.size);
137 fprintf(stderr, "texture type = %d\n", fb.type);
138 }
139 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
140 fprintf(stderr, "via_alloc_texture_agp fail\n");
141 return GL_FALSE;
142 }
143
144 t->texMem.offset = fb.offset;
145 t->texMem.index = fb.index;
146 if (VIA_DEBUG) fprintf(stderr, "texture agp index = %d\n", (GLuint)fb.index);
147
148 t->bufAddr = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset);
149 /*=* John Sheng [2003.5.31] agp tex *=*/
150 t->inAGP = GL_TRUE;
151 if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
152 return GL_TRUE;
153 }
154
155 void
156 via_free_texture(viaContextPtr vmesa, viaTextureObjectPtr t)
157 {
158 drm_via_mem_t fb;
159 if (VIA_DEBUG) {
160 fprintf(stderr, "via_free_texture: index = %d\n",
161 t->texMem.index);
162 fprintf(stderr, "via_free_texture: size = %d\n",
163 t->texMem.size);
164 }
165 if (!vmesa) {
166 fprintf(stderr, "!mesa\n");
167 return;
168 }
169
170 fb.context = vmesa->hHWContext;
171 fb.index = t->texMem.index;
172
173 /*=* John Sheng [2003.5.31] agp tex *=*/
174 if(t->inAGP)
175 fb.type = AGP;
176 else
177 fb.type = VIDEO;
178
179 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
180 if(vmesa->shareCtx) {
181 fb.context = ((viaContextPtr)((GLcontext *)(vmesa->shareCtx)->DriverCtx))->hHWContext;
182 if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) {
183 fprintf(stderr, "via_free_texture fail\n");
184 }
185 }
186 else
187 fprintf(stderr, "via_free_texture fail\n");
188 }
189
190 t->bufAddr = NULL;
191 }