Char: cyclades, clear interrupts before releasing
[safe/jmp/linux-2.6] / drivers / char / agp / frontend.c
index 3dfb664..679d7f9 100644 (file)
@@ -41,9 +41,9 @@
 #include <asm/pgtable.h>
 #include "agp.h"
 
-static struct agp_front_data agp_fe;
+struct agp_front_data agp_fe;
 
-static struct agp_memory *agp_find_mem_by_key(int key)
+struct agp_memory *agp_find_mem_by_key(int key)
 {
        struct agp_memory *curr;
 
@@ -151,51 +151,27 @@ static void agp_add_seg_to_client(struct agp_client *client,
        client->segments = seg;
 }
 
-/* Originally taken from linux/mm/mmap.c from the array
- * protection_map.
- * The original really should be exported to modules, or
- * some routine which does the conversion for you
- */
-
-static const pgprot_t my_protect_map[16] =
-{
-       __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
-       __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
-};
-
 static pgprot_t agp_convert_mmap_flags(int prot)
 {
-#define _trans(x,bit1,bit2) \
-((bit1==bit2)?(x&bit1):(x&bit1)?bit2:0)
-
        unsigned long prot_bits;
-       pgprot_t temp;
-
-       prot_bits = _trans(prot, PROT_READ, VM_READ) |
-           _trans(prot, PROT_WRITE, VM_WRITE) |
-           _trans(prot, PROT_EXEC, VM_EXEC);
-
-       prot_bits |= VM_SHARED;
 
-       temp = my_protect_map[prot_bits & 0x0000000f];
-
-       return temp;
+       prot_bits = calc_vm_prot_bits(prot) | VM_SHARED;
+       return vm_get_page_prot(prot_bits);
 }
 
-static int agp_create_segment(struct agp_client *client, struct agp_region *region)
+int agp_create_segment(struct agp_client *client, struct agp_region *region)
 {
        struct agp_segment_priv **ret_seg;
        struct agp_segment_priv *seg;
        struct agp_segment *user_seg;
        size_t i;
 
-       seg = kmalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL);
+       seg = kzalloc((sizeof(struct agp_segment_priv) * region->seg_count), GFP_KERNEL);
        if (seg == NULL) {
                kfree(region->seg_list);
                region->seg_list = NULL;
                return -ENOMEM;
        }
-       memset(seg, 0, (sizeof(struct agp_segment_priv) * region->seg_count));
        user_seg = region->seg_list;
 
        for (i = 0; i < region->seg_count; i++) {
@@ -235,7 +211,7 @@ static void agp_insert_into_pool(struct agp_memory * temp)
 
 /* File private list routines */
 
-static struct agp_file_private *agp_find_private(pid_t pid)
+struct agp_file_private *agp_find_private(pid_t pid)
 {
        struct agp_file_private *curr;
 
@@ -290,13 +266,13 @@ static void agp_remove_file_private(struct agp_file_private * priv)
  * Wrappers for agp_free_memory & agp_allocate_memory
  * These make sure that internal lists are kept updated.
  */
-static void agp_free_memory_wrap(struct agp_memory *memory)
+void agp_free_memory_wrap(struct agp_memory *memory)
 {
        agp_remove_from_pool(memory);
        agp_free_memory(memory);
 }
 
-static struct agp_memory *agp_allocate_memory_wrap(size_t pg_count, u32 type)
+struct agp_memory *agp_allocate_memory_wrap(size_t pg_count, u32 type)
 {
        struct agp_memory *memory;
 
@@ -332,14 +308,11 @@ static struct agp_controller *agp_create_controller(pid_t id)
 {
        struct agp_controller *controller;
 
-       controller = kmalloc(sizeof(struct agp_controller), GFP_KERNEL);
-
+       controller = kzalloc(sizeof(struct agp_controller), GFP_KERNEL);
        if (controller == NULL)
                return NULL;
 
-       memset(controller, 0, sizeof(struct agp_controller));
        controller->pid = id;
-
        return controller;
 }
 
@@ -511,7 +484,7 @@ static struct agp_controller *agp_find_controller_for_client(pid_t id)
        return NULL;
 }
 
-static struct agp_client *agp_find_client_by_pid(pid_t id)
+struct agp_client *agp_find_client_by_pid(pid_t id)
 {
        struct agp_client *temp;
 
@@ -536,22 +509,20 @@ static void agp_insert_client(struct agp_client *client)
        agp_fe.current_controller->num_clients++;
 }
 
-static struct agp_client *agp_create_client(pid_t id)
+struct agp_client *agp_create_client(pid_t id)
 {
        struct agp_client *new_client;
 
-       new_client = kmalloc(sizeof(struct agp_client), GFP_KERNEL);
-
+       new_client = kzalloc(sizeof(struct agp_client), GFP_KERNEL);
        if (new_client == NULL)
                return NULL;
 
-       memset(new_client, 0, sizeof(struct agp_client));
        new_client->pid = id;
        agp_insert_client(new_client);
        return new_client;
 }
 
-static int agp_remove_client(pid_t id)
+int agp_remove_client(pid_t id)
 {
        struct agp_client *client;
        struct agp_client *prev_client;
@@ -598,7 +569,7 @@ static int agp_mmap(struct file *file, struct vm_area_struct *vma)
        struct agp_file_private *priv = file->private_data;
        struct agp_kern_info kerninfo;
 
-       down(&(agp_fe.agp_mutex));
+       mutex_lock(&(agp_fe.agp_mutex));
 
        if (agp_fe.backend_acquired != TRUE)
                goto out_eperm;
@@ -633,7 +604,7 @@ static int agp_mmap(struct file *file, struct vm_area_struct *vma)
                                            size, vma->vm_page_prot)) {
                        goto out_again;
                }
-               up(&(agp_fe.agp_mutex));
+               mutex_unlock(&(agp_fe.agp_mutex));
                return 0;
        }
 
@@ -649,20 +620,20 @@ static int agp_mmap(struct file *file, struct vm_area_struct *vma)
                                            size, vma->vm_page_prot)) {
                        goto out_again;
                }
-               up(&(agp_fe.agp_mutex));
+               mutex_unlock(&(agp_fe.agp_mutex));
                return 0;
        }
 
 out_eperm:
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return -EPERM;
 
 out_inval:
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return -EINVAL;
 
 out_again:
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return -EAGAIN;
 }
 
@@ -670,7 +641,7 @@ static int agp_release(struct inode *inode, struct file *file)
 {
        struct agp_file_private *priv = file->private_data;
 
-       down(&(agp_fe.agp_mutex));
+       mutex_lock(&(agp_fe.agp_mutex));
 
        DBG("priv=%p", priv);
 
@@ -693,7 +664,7 @@ static int agp_release(struct inode *inode, struct file *file)
        agp_remove_file_private(priv);
        kfree(priv);
        file->private_data = NULL;
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return 0;
 }
 
@@ -704,16 +675,15 @@ static int agp_open(struct inode *inode, struct file *file)
        struct agp_client *client;
        int rc = -ENXIO;
 
-       down(&(agp_fe.agp_mutex));
+       mutex_lock(&(agp_fe.agp_mutex));
 
        if (minor != AGPGART_MINOR)
                goto err_out;
 
-       priv = kmalloc(sizeof(struct agp_file_private), GFP_KERNEL);
+       priv = kzalloc(sizeof(struct agp_file_private), GFP_KERNEL);
        if (priv == NULL)
                goto err_out_nomem;
 
-       memset(priv, 0, sizeof(struct agp_file_private));
        set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags);
        priv->my_pid = current->pid;
 
@@ -730,13 +700,13 @@ static int agp_open(struct inode *inode, struct file *file)
        file->private_data = (void *) priv;
        agp_insert_file_private(priv);
        DBG("private=%p, client=%p", priv, client);
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return 0;
 
 err_out_nomem:
        rc = -ENOMEM;
 err_out:
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return rc;
 }
 
@@ -776,7 +746,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
        return 0;
 }
 
-static int agpioc_acquire_wrap(struct agp_file_private *priv)
+int agpioc_acquire_wrap(struct agp_file_private *priv)
 {
        struct agp_controller *controller;
 
@@ -788,7 +758,7 @@ static int agpioc_acquire_wrap(struct agp_file_private *priv)
        if (agp_fe.current_controller != NULL)
                return -EBUSY;
 
-       if(!agp_bridge)
+       if (!agp_bridge)
                return -ENODEV;
 
         if (atomic_read(&agp_bridge->agp_in_use))
@@ -819,14 +789,14 @@ static int agpioc_acquire_wrap(struct agp_file_private *priv)
        return 0;
 }
 
-static int agpioc_release_wrap(struct agp_file_private *priv)
+int agpioc_release_wrap(struct agp_file_private *priv)
 {
        DBG("");
        agp_controller_release_current(agp_fe.current_controller, priv);
        return 0;
 }
 
-static int agpioc_setup_wrap(struct agp_file_private *priv, void __user *arg)
+int agpioc_setup_wrap(struct agp_file_private *priv, void __user *arg)
 {
        struct agp_setup mode;
 
@@ -906,7 +876,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
        return -EINVAL;
 }
 
-static int agpioc_protect_wrap(struct agp_file_private *priv)
+int agpioc_protect_wrap(struct agp_file_private *priv)
 {
        DBG("");
        /* This function is not currently implemented */
@@ -922,6 +892,9 @@ static int agpioc_allocate_wrap(struct agp_file_private *priv, void __user *arg)
        if (copy_from_user(&alloc, arg, sizeof(struct agp_allocate)))
                return -EFAULT;
 
+       if (alloc.type >= AGP_USER_TYPES)
+               return -EINVAL;
+
        memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type);
 
        if (memory == NULL)
@@ -937,7 +910,7 @@ static int agpioc_allocate_wrap(struct agp_file_private *priv, void __user *arg)
        return 0;
 }
 
-static int agpioc_deallocate_wrap(struct agp_file_private *priv, int arg)
+int agpioc_deallocate_wrap(struct agp_file_private *priv, int arg)
 {
        struct agp_memory *memory;
 
@@ -992,7 +965,7 @@ static int agp_ioctl(struct inode *inode, struct file *file,
        int ret_val = -ENOTTY;
 
        DBG("priv=%p, cmd=%x", curr_priv, cmd);
-       down(&(agp_fe.agp_mutex));
+       mutex_lock(&(agp_fe.agp_mutex));
 
        if ((agp_fe.current_controller == NULL) &&
            (cmd != AGPIOC_ACQUIRE)) {
@@ -1062,17 +1035,20 @@ static int agp_ioctl(struct inode *inode, struct file *file,
 
 ioctl_out:
        DBG("ioctl returns %d\n", ret_val);
-       up(&(agp_fe.agp_mutex));
+       mutex_unlock(&(agp_fe.agp_mutex));
        return ret_val;
 }
 
-static struct file_operations agp_fops =
+static const struct file_operations agp_fops =
 {
        .owner          = THIS_MODULE,
        .llseek         = no_llseek,
        .read           = agp_read,
        .write          = agp_write,
        .ioctl          = agp_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = compat_agp_ioctl,
+#endif
        .mmap           = agp_mmap,
        .open           = agp_open,
        .release        = agp_release,
@@ -1088,7 +1064,7 @@ static struct miscdevice agp_miscdev =
 int agp_frontend_initialize(void)
 {
        memset(&agp_fe, 0, sizeof(struct agp_front_data));
-       sema_init(&(agp_fe.agp_mutex), 1);
+       mutex_init(&(agp_fe.agp_mutex));
 
        if (misc_register(&agp_miscdev)) {
                printk(KERN_ERR PFX "unable to get minor: %d\n", AGPGART_MINOR);