1 /* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 * Sung-Ching Lin <sclin@sis.com.tw>
31 #include <linux/config.h>
33 #include "video/sisfb.h"
39 #define MAX_CONTEXT 100
46 set_t *sets[2]; /* 0 for video, 1 for AGP */
49 static sis_context_t global_ppriv[MAX_CONTEXT];
51 static int add_alloc_set(int context, int type, unsigned int val)
55 for(i = 0; i < MAX_CONTEXT; i++)
56 if(global_ppriv[i].used && global_ppriv[i].context == context){
57 retval = setAdd(global_ppriv[i].sets[type], val);
63 static int del_alloc_set(int context, int type, unsigned int val)
66 for(i = 0; i < MAX_CONTEXT; i++)
67 if(global_ppriv[i].used && global_ppriv[i].context == context){
68 retval = setDel(global_ppriv[i].sets[type], val);
74 /* fb management via fb device */
76 int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
80 struct sis_memreq req;
83 if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb)))
90 fb.offset = req.offset;
92 if(!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)){
93 DRM_DEBUG("adding to allocation set fails\n");
104 if (copy_to_user((drm_sis_mem_t *)arg, &fb, sizeof(fb))) return -EFAULT;
106 DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset);
111 int sis_fb_free(struct inode *inode, struct file *filp, unsigned int cmd,
117 if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb)))
125 if(!del_alloc_set(fb.context, VIDEO_TYPE, fb.free))
128 DRM_DEBUG("free fb, offset = %d\n", fb.free);
135 int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
141 int sis_fb_free(struct inode *inode, struct file *filp, unsigned int cmd,
149 /* agp memory management */
152 static memHeap_t *AgpHeap = NULL;
154 int sisp_agp_init(struct inode *inode, struct file *filp, unsigned int cmd,
159 if (copy_from_user(&agp, (drm_sis_agp_t *)arg, sizeof(agp)))
162 AgpHeap = mmInit(agp.offset, agp.size);
164 DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
169 int sisp_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
179 if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp)))
182 block = mmAllocMem(AgpHeap, agp.size, 0, 0);
185 agp.offset = block->ofs;
186 agp.free = (unsigned long)block;
187 if(!add_alloc_set(agp.context, AGP_TYPE, agp.free)){
188 DRM_DEBUG("adding to allocation set fails\n");
189 mmFreeMem((PMemBlock)(unsigned long)agp.free);
199 if (copy_to_user((drm_sis_mem_t *)arg, &agp, sizeof(agp))) return -EFAULT;
201 DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset);
206 int sisp_agp_free(struct inode *inode, struct file *filp, unsigned int cmd,
215 if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp)))
222 mmFreeMem((PMemBlock)(unsigned long)agp.free);
223 if(!del_alloc_set(agp.context, AGP_TYPE, agp.free))
226 DRM_DEBUG("free agp, free = %d\n", agp.free);
233 int sis_init_context(int context)
237 for(i = 0; i < MAX_CONTEXT ; i++)
238 if(global_ppriv[i].used && (global_ppriv[i].context == context))
241 if(i >= MAX_CONTEXT){
242 for(i = 0; i < MAX_CONTEXT ; i++){
243 if(!global_ppriv[i].used){
244 global_ppriv[i].context = context;
245 global_ppriv[i].used = 1;
246 global_ppriv[i].sets[0] = setInit();
247 global_ppriv[i].sets[1] = setInit();
248 DRM_DEBUG("init allocation set, socket=%d, context = %d\n",
253 if((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
254 (global_ppriv[i].sets[1] == NULL)){
262 int sis_final_context(int context)
266 for(i=0; i<MAX_CONTEXT; i++)
267 if(global_ppriv[i].used && (global_ppriv[i].context == context))
275 DRM_DEBUG("find socket %d, context = %d\n", i, context);
278 set = global_ppriv[i].sets[0];
279 retval = setFirst(set, &item);
281 DRM_DEBUG("free video memory 0x%x\n", item);
283 retval = setNext(set, &item);
288 set = global_ppriv[i].sets[1];
289 retval = setFirst(set, &item);
291 DRM_DEBUG("free agp memory 0x%x\n", item);
292 mmFreeMem((PMemBlock)(unsigned long)item);
293 retval = setNext(set, &item);
297 global_ppriv[i].used = 0;
300 /* turn-off auto-flip */
302 #if defined(SIS_STEREO)