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.
27 #include "via_context.h"
28 #include "via_ioctl.h"
31 #include <sys/ioctl.h>
34 via_alloc_draw_buffer(viaContextPtr vmesa
, viaBuffer
*buf
)
37 mem
.context
= vmesa
->hHWContext
;
41 if (ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_ALLOCMEM
, &mem
))
45 buf
->offset
= mem
.offset
;
46 buf
->map
= (char *)vmesa
->driScreen
->pFB
+ mem
.offset
;
47 buf
->index
= mem
.index
;
52 via_free_draw_buffer(viaContextPtr vmesa
, viaBuffer
*buf
)
58 mem
.context
= vmesa
->hHWContext
;
59 mem
.index
= buf
->index
;
61 ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_FREEMEM
, &mem
);
67 via_alloc_dma_buffer(viaContextPtr vmesa
)
69 drm_via_dma_init_t init
;
71 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
72 vmesa
->dma
= (GLubyte
*) malloc(VIA_DMA_BUFSIZ
);
75 * Check whether AGP DMA has been initialized.
77 init
.func
= VIA_DMA_INITIALIZED
;
79 ( 0 == drmCommandWrite(vmesa
->driFd
, DRM_VIA_DMA_INIT
,
80 &init
, sizeof(init
)));
82 printf("unichrome_dri.so: Using AGP.\n");
84 printf("unichrome_dri.so: Using PCI.\n");
86 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
87 return ((vmesa
->dma
) ? GL_TRUE
: GL_FALSE
);
91 via_free_dma_buffer(viaContextPtr vmesa
)
99 via_alloc_texture(viaContextPtr vmesa
, viaTextureObjectPtr t
)
102 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
103 fb
.context
= vmesa
->hHWContext
;
104 fb
.size
= t
->texMem
.size
;
107 fprintf(stderr
, "texture size = %d\n", fb
.size
);
108 fprintf(stderr
, "texture type = %d\n", fb
.type
);
110 if (ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_ALLOCMEM
, &fb
)) {
111 fprintf(stderr
, "via_alloc_texture fail\n");
115 t
->texMem
.offset
= fb
.offset
;
116 t
->texMem
.index
= fb
.index
;
117 if (VIA_DEBUG
) fprintf(stderr
, "texture index = %d\n", (GLuint
)fb
.index
);
119 t
->bufAddr
= (unsigned char *)(fb
.offset
+ (GLuint
)vmesa
->driScreen
->pFB
);
120 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
123 /*=* John Sheng [2003.5.31] agp tex *=*/
125 via_alloc_texture_agp(viaContextPtr vmesa
, viaTextureObjectPtr t
)
128 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
129 fb
.context
= vmesa
->hHWContext
;
130 fb
.size
= t
->texMem
.size
;
133 fprintf(stderr
, "texture_agp size = %d\n", fb
.size
);
134 fprintf(stderr
, "texture type = %d\n", fb
.type
);
136 if (ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_ALLOCMEM
, &fb
)) {
137 fprintf(stderr
, "via_alloc_texture_agp fail\n");
141 t
->texMem
.offset
= fb
.offset
;
142 t
->texMem
.index
= fb
.index
;
143 if (VIA_DEBUG
) fprintf(stderr
, "texture agp index = %d\n", (GLuint
)fb
.index
);
145 t
->bufAddr
= (unsigned char *)((GLuint
)vmesa
->viaScreen
->agpLinearStart
+ fb
.offset
);
146 /*=* John Sheng [2003.5.31] agp tex *=*/
148 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
153 via_free_texture(viaContextPtr vmesa
, viaTextureObjectPtr t
)
157 fprintf(stderr
, "via_free_texture: index = %d\n",
159 fprintf(stderr
, "via_free_texture: size = %d\n",
163 fprintf(stderr
, "!mesa\n");
167 fb
.context
= vmesa
->hHWContext
;
168 fb
.index
= t
->texMem
.index
;
170 /*=* John Sheng [2003.5.31] agp tex *=*/
176 if (ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_FREEMEM
, &fb
)) {
177 if(vmesa
->shareCtx
) {
178 fb
.context
= ((viaContextPtr
)((GLcontext
*)(vmesa
->shareCtx
)->DriverCtx
))->hHWContext
;
179 if (ioctl(vmesa
->driFd
, DRM_IOCTL_VIA_FREEMEM
, &fb
)) {
180 fprintf(stderr
, "via_free_texture fail\n");
184 fprintf(stderr
, "via_free_texture fail\n");