OSDN Git Service

nouveau: install libdrm_nouveau with libdrm
[android-x86/external-libdrm.git] / shared-core / via_mm.c
index 89d762f..45790dc 100644 (file)
@@ -42,7 +42,7 @@ static int via_agp_free(drm_via_mem_t * mem);
 static int via_fb_alloc(drm_via_mem_t * mem);
 static int via_fb_free(drm_via_mem_t * mem);
 
-static int add_alloc_set(int context, int type, unsigned int val)
+static int add_alloc_set(int context, int type, unsigned long val)
 {
        int i, retval = 0;
 
@@ -56,7 +56,7 @@ static int add_alloc_set(int context, int type, unsigned int val)
        return retval;
 }
 
-static int del_alloc_set(int context, int type, unsigned int val)
+static int del_alloc_set(int context, int type, unsigned long val)
 {
        int i, retval = 0;
 
@@ -72,16 +72,14 @@ static int del_alloc_set(int context, int type, unsigned int val)
 /* agp memory management */
 static memHeap_t *AgpHeap = NULL;
 
-int via_agp_init(DRM_IOCTL_ARGS)
+int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_via_agp_t agp;
+       drm_via_agp_t *agp = data;
 
-       DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data,
-                                sizeof(agp));
+       AgpHeap = via_mmInit(agp->offset, agp->size);
 
-       AgpHeap = via_mmInit(agp.offset, agp.size);
-
-       DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)agp.offset, (unsigned long)agp.size);
+       DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)agp->offset,
+                 (unsigned long)agp->size);
 
        return 0;
 }
@@ -89,15 +87,14 @@ int via_agp_init(DRM_IOCTL_ARGS)
 /* fb memory management */
 static memHeap_t *FBHeap = NULL;
 
-int via_fb_init(DRM_IOCTL_ARGS)
+int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_via_fb_t fb;
-
-       DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb));
+       drm_via_fb_t *fb = data;
 
        FBHeap = via_mmInit(fb.offset, fb.size);
 
-       DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)fb.offset, (unsigned long)fb.size);
+       DRM_DEBUG("offset = %lu, size = %lu", (unsigned long)fb.offset,
+                 (unsigned long)fb.size);
 
        return 0;
 }
@@ -173,7 +170,6 @@ int via_final_context(struct drm_device *dev, int context)
        }
        via_release_futex(dev_priv, context); 
        
-                       
 #if defined(__linux__)
        /* Linux specific until context tracking code gets ported to BSD */
        /* Last context, perform cleanup */
@@ -190,30 +186,18 @@ int via_final_context(struct drm_device *dev, int context)
        return 1;
 }
 
-int via_mem_alloc(DRM_IOCTL_ARGS)
+int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_file_t *priv = filp->private_data;
-       drm_via_mem_t mem;
-
-       DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
-                                sizeof(mem));
-
-       if (!drm_check_context(priv, mem.context)) {
-               return DRM_ERR(EINVAL);
-       }
+       drm_via_mem_t *mem = data;
 
        switch (mem.type) {
-       case VIDEO:
-               if (via_fb_alloc(&mem) < 0)
+       case VIA_MEM_VIDEO:
+               if (via_fb_alloc(mem) < 0)
                        return -EFAULT;
-               DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
-                                      sizeof(mem));
                return 0;
-       case AGP:
-               if (via_agp_alloc(&mem) < 0)
+       case VIA_MEM_AGP:
+               if (via_agp_alloc(mem) < 0)
                        return -EFAULT;
-               DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
-                                      sizeof(mem));
                return 0;
        }
 
@@ -236,7 +220,7 @@ static int via_fb_alloc(drm_via_mem_t * mem)
        if (block) {
                fb.offset = block->ofs;
                fb.free = (unsigned long)block;
-               if (!add_alloc_set(fb.context, VIDEO, fb.free)) {
+               if (!add_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
                        DRM_DEBUG("adding to allocation set fails\n");
                        via_mmFreeMem((PMemBlock) fb.free);
                        retval = -1;
@@ -273,7 +257,7 @@ static int via_agp_alloc(drm_via_mem_t * mem)
        if (block) {
                agp.offset = block->ofs;
                agp.free = (unsigned long)block;
-               if (!add_alloc_set(agp.context, AGP, agp.free)) {
+               if (!add_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
                        DRM_DEBUG("adding to allocation set fails\n");
                        via_mmFreeMem((PMemBlock) agp.free);
                        retval = -1;
@@ -292,26 +276,18 @@ static int via_agp_alloc(drm_via_mem_t * mem)
        return retval;
 }
 
-int via_mem_free(DRM_IOCTL_ARGS)
+int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-       drm_file_t *priv = filp->private_data;
-       drm_via_mem_t mem;
+       drm_via_mem_t *mem = data;
 
-       DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
-                                sizeof(mem));
-
-       if (!drm_check_context(priv, mem.context)) {
-               return DRM_ERR(EINVAL);
-       }
-
-       switch (mem.type) {
+       switch (mem->type) {
 
-       case VIDEO:
-               if (via_fb_free(&mem) == 0)
+       case VIA_MEM_VIDEO:
+               if (via_fb_free(mem) == 0)
                        return 0;
                break;
-       case AGP:
-               if (via_agp_free(&mem) == 0)
+       case VIA_MEM_AGP:
+               if (via_agp_free(mem) == 0)
                        return 0;
                break;
        }
@@ -338,7 +314,7 @@ static int via_fb_free(drm_via_mem_t * mem)
 
        via_mmFreeMem((PMemBlock) fb.free);
 
-       if (!del_alloc_set(fb.context, VIDEO, fb.free)) {
+       if (!del_alloc_set(fb.context, VIA_MEM_VIDEO, fb.free)) {
                retval = -1;
        }
 
@@ -361,11 +337,11 @@ static int via_agp_free(drm_via_mem_t * mem)
 
        via_mmFreeMem((PMemBlock) agp.free);
 
-       if (!del_alloc_set(agp.context, AGP, agp.free)) {
+       if (!del_alloc_set(agp.context, VIA_MEM_AGP, agp.free)) {
                retval = -1;
        }
 
-       DRM_DEBUG("free agp, free = %ld\n", agp.free);
+       DRM_DEBUG("free agp, free = %ld\n", agp.nfree);
 
        return retval;
 }