OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [drm/] [sis_mm.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* 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
3
 *
4
 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5
 * All rights reserved.
6
 *
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:
13
 *
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
16
 * Software.
17
 *
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.
25
 *
26
 * Authors:
27
 *    Sung-Ching Lin <sclin@sis.com.tw>
28
 *
29
 */
30
 
31
#include "sis.h"
32
#include <linux/sisfb.h>
33
#include "drmP.h"
34
#include "sis_drm.h"
35
#include "sis_drv.h"
36
#include "sis_ds.h"
37
 
38
#define MAX_CONTEXT 100
39
#define VIDEO_TYPE 0 
40
#define AGP_TYPE 1
41
 
42
typedef struct {
43
  int used;
44
  int context;
45
  set_t *sets[2]; /* 0 for video, 1 for AGP */
46
} sis_context_t;
47
 
48
static sis_context_t global_ppriv[MAX_CONTEXT];
49
 
50
static int add_alloc_set(int context, int type, unsigned int val)
51
{
52
  int i, retval = 0;
53
 
54
  for(i = 0; i < MAX_CONTEXT; i++)
55
    if(global_ppriv[i].used && global_ppriv[i].context == context){
56
      retval = setAdd(global_ppriv[i].sets[type], val);
57
      break;
58
    }
59
  return retval;
60
}
61
 
62
static int del_alloc_set(int context, int type, unsigned int val)
63
{
64
  int i, retval = 0;
65
  for(i = 0; i < MAX_CONTEXT; i++)
66
    if(global_ppriv[i].used && global_ppriv[i].context == context){
67
      retval = setDel(global_ppriv[i].sets[type], val);
68
      break;
69
    }
70
  return retval;
71
}
72
 
73
/* fb management via fb device */
74
#if 1
75
int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
76
                  unsigned long arg)
77
{
78
  drm_sis_mem_t fb;
79
  struct sis_memreq req;
80
  int retval = 0;
81
 
82
  if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb)))
83
          return -EFAULT;
84
 
85
  req.size = fb.size;
86
  sis_malloc(&req);
87
  if(req.offset){
88
    /* TODO */
89
    fb.offset = req.offset;
90
    fb.free = req.offset;
91
    if(!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)){
92
      DRM_DEBUG("adding to allocation set fails\n");
93
      sis_free(req.offset);
94
      retval = -1;
95
    }
96
  }
97
  else{
98
    fb.offset = 0;
99
    fb.size = 0;
100
    fb.free = 0;
101
  }
102
 
103
  if (copy_to_user((drm_sis_mem_t *)arg, &fb, sizeof(fb))) return -EFAULT;
104
 
105
  DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset);
106
 
107
  return retval;
108
}
109
 
110
int sis_fb_free(struct inode *inode, struct file *filp, unsigned int cmd,
111
                  unsigned long arg)
112
{
113
  drm_sis_mem_t fb;
114
  int retval = 0;
115
 
116
  if (copy_from_user(&fb, (drm_sis_mem_t *)arg, sizeof(fb)))
117
          return -EFAULT;
118
 
119
  if(!fb.free){
120
    return -1;
121
  }
122
 
123
  sis_free(fb.free);
124
  if(!del_alloc_set(fb.context, VIDEO_TYPE, fb.free))
125
    retval = -1;
126
 
127
  DRM_DEBUG("free fb, offset = %ld\n", fb.free);
128
 
129
  return retval;
130
}
131
 
132
#else
133
 
134
int sis_fb_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
135
                  unsigned long arg)
136
{
137
  return -1;
138
}
139
 
140
int sis_fb_free(struct inode *inode, struct file *filp, unsigned int cmd,
141
                  unsigned long arg)
142
{
143
  return 0;
144
}
145
 
146
#endif
147
 
148
/* agp memory management */
149
#if 1
150
 
151
static memHeap_t *AgpHeap = NULL;
152
 
153
int sisp_agp_init(struct inode *inode, struct file *filp, unsigned int cmd,
154
                  unsigned long arg)
155
{
156
  drm_sis_agp_t agp;
157
 
158
  if (copy_from_user(&agp, (drm_sis_agp_t *)arg, sizeof(agp)))
159
          return -EFAULT;
160
 
161
  AgpHeap = mmInit(agp.offset, agp.size);
162
 
163
  DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size);
164
 
165
  return 0;
166
}
167
 
168
int sisp_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
169
                  unsigned long arg)
170
{
171
  drm_sis_mem_t agp;
172
  PMemBlock block;
173
  int retval = 0;
174
 
175
  if(!AgpHeap)
176
    return -1;
177
 
178
  if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp)))
179
          return -EFAULT;
180
 
181
  block = mmAllocMem(AgpHeap, agp.size, 0, 0);
182
  if(block){
183
    /* TODO */
184
    agp.offset = block->ofs;
185
    agp.free = (unsigned long)block;
186
    if(!add_alloc_set(agp.context, AGP_TYPE, agp.free)){
187
      DRM_DEBUG("adding to allocation set fails\n");
188
      mmFreeMem((PMemBlock)agp.free);
189
      retval = -1;
190
    }
191
  }
192
  else{
193
    agp.offset = 0;
194
    agp.size = 0;
195
    agp.free = 0;
196
  }
197
 
198
  if (copy_to_user((drm_sis_mem_t *)arg, &agp, sizeof(agp))) return -EFAULT;
199
 
200
  DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset);
201
 
202
  return retval;
203
}
204
 
205
int sisp_agp_free(struct inode *inode, struct file *filp, unsigned int cmd,
206
                  unsigned long arg)
207
{
208
  drm_sis_mem_t agp;
209
  int retval = 0;
210
 
211
  if(!AgpHeap)
212
    return -1;
213
 
214
  if (copy_from_user(&agp, (drm_sis_mem_t *)arg, sizeof(agp)))
215
          return -EFAULT;
216
 
217
  if(!agp.free){
218
    return -1;
219
  }
220
 
221
  mmFreeMem((PMemBlock)agp.free);
222
  if(!del_alloc_set(agp.context, AGP_TYPE, agp.free))
223
    retval = -1;
224
 
225
  DRM_DEBUG("free agp, free = %ld\n", agp.free);
226
 
227
  return retval;
228
}
229
 
230
#endif
231
 
232
int sis_init_context(int context)
233
{
234
        int i;
235
 
236
        for(i = 0; i < MAX_CONTEXT ; i++)
237
          if(global_ppriv[i].used && (global_ppriv[i].context == context))
238
            break;
239
 
240
        if(i >= MAX_CONTEXT){
241
          for(i = 0; i < MAX_CONTEXT ; i++){
242
            if(!global_ppriv[i].used){
243
              global_ppriv[i].context = context;
244
              global_ppriv[i].used = 1;
245
              global_ppriv[i].sets[0] = setInit();
246
              global_ppriv[i].sets[1] = setInit();
247
              DRM_DEBUG("init allocation set, socket=%d, context = %d\n",
248
                         i, context);
249
              break;
250
            }
251
          }
252
          if((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) ||
253
             (global_ppriv[i].sets[1] == NULL)){
254
            return 0;
255
          }
256
        }
257
 
258
        return 1;
259
}
260
 
261
int sis_final_context(int context)
262
{
263
        int i;
264
 
265
        for(i=0; i<MAX_CONTEXT; i++)
266
          if(global_ppriv[i].used && (global_ppriv[i].context == context))
267
            break;
268
 
269
        if(i < MAX_CONTEXT){
270
          set_t *set;
271
          unsigned int item;
272
          int retval;
273
 
274
          DRM_DEBUG("find socket %d, context = %d\n", i, context);
275
 
276
          /* Video Memory */
277
          set = global_ppriv[i].sets[0];
278
          retval = setFirst(set, &item);
279
          while(retval){
280
            DRM_DEBUG("free video memory 0x%x\n", item);
281
            sis_free(item);
282
            retval = setNext(set, &item);
283
          }
284
          setDestroy(set);
285
 
286
          /* AGP Memory */
287
          set = global_ppriv[i].sets[1];
288
          retval = setFirst(set, &item);
289
          while(retval){
290
            DRM_DEBUG("free agp memory 0x%x\n", item);
291
            mmFreeMem((PMemBlock)item);
292
            retval = setNext(set, &item);
293
          }
294
          setDestroy(set);
295
 
296
          global_ppriv[i].used = 0;
297
        }
298
 
299
        /* turn-off auto-flip */
300
        /* TODO */
301
#if defined(SIS_STEREO)
302
        flip_final();
303
#endif
304
 
305
        return 1;
306
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.