include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / gpu / vga / vgaarb.c
index 199138f..441e38c 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/spinlock.h>
 #include <linux/poll.h>
 #include <linux/miscdevice.h>
+#include <linux/slab.h>
 
 #include <linux/uaccess.h>
 
@@ -609,7 +610,6 @@ void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes)
 }
 EXPORT_SYMBOL(vga_set_legacy_decoding);
 
-/* return number of active VGA devices */
 /* call with NULL to unregister */
 int vga_client_register(struct pci_dev *pdev, void *cookie,
                        void (*irq_set_state)(void *cookie, bool state),
@@ -689,7 +689,7 @@ EXPORT_SYMBOL(vga_client_register);
  * the arbiter.
  */
 
-#define MAX_USER_CARDS         16
+#define MAX_USER_CARDS         CONFIG_VGA_ARB_MAX_GPUS
 #define PCI_INVALID_CARD       ((struct pci_dev *)-1UL)
 
 /*
@@ -831,7 +831,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                curr_pos += 5;
                remaining -= 5;
 
-               pr_devel("client 0x%X called 'lock'\n", (int)priv);
+               pr_devel("client 0x%p called 'lock'\n", priv);
 
                if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
                        ret_val = -EPROTO;
@@ -867,7 +867,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                curr_pos += 7;
                remaining -= 7;
 
-               pr_devel("client 0x%X called 'unlock'\n", (int)priv);
+               pr_devel("client 0x%p called 'unlock'\n", priv);
 
                if (strncmp(curr_pos, "all", 3) == 0)
                        io_state = VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM;
@@ -917,7 +917,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                curr_pos += 8;
                remaining -= 8;
 
-               pr_devel("client 0x%X called 'trylock'\n", (int)priv);
+               pr_devel("client 0x%p called 'trylock'\n", priv);
 
                if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
                        ret_val = -EPROTO;
@@ -955,14 +955,15 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                }
 
        } else if (strncmp(curr_pos, "target ", 7) == 0) {
+               struct pci_bus *pbus;
                unsigned int domain, bus, devfn;
                struct vga_device *vgadev;
 
                curr_pos += 7;
                remaining -= 7;
-               pr_devel("client 0x%X called 'target'\n", (int)priv);
+               pr_devel("client 0x%p called 'target'\n", priv);
                /* if target is default */
-               if (!strncmp(buf, "default", 7))
+               if (!strncmp(curr_pos, "default", 7))
                        pdev = pci_dev_get(vga_default_device());
                else {
                        if (!vga_pci_str_to_vars(curr_pos, remaining,
@@ -970,18 +971,31 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                                ret_val = -EPROTO;
                                goto done;
                        }
-
-                       pdev = pci_get_bus_and_slot(bus, devfn);
+                       pr_devel("vgaarb: %s ==> %x:%x:%x.%x\n", curr_pos,
+                               domain, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+
+                       pbus = pci_find_bus(domain, bus);
+                       pr_devel("vgaarb: pbus %p\n", pbus);
+                       if (pbus == NULL) {
+                               pr_err("vgaarb: invalid PCI domain and/or bus address %x:%x\n",
+                                       domain, bus);
+                               ret_val = -ENODEV;
+                               goto done;
+                       }
+                       pdev = pci_get_slot(pbus, devfn);
+                       pr_devel("vgaarb: pdev %p\n", pdev);
                        if (!pdev) {
-                               pr_info("vgaarb: invalid PCI address!\n");
+                               pr_err("vgaarb: invalid PCI address %x:%x\n",
+                                       bus, devfn);
                                ret_val = -ENODEV;
                                goto done;
                        }
                }
 
                vgadev = vgadev_find(pdev);
+               pr_devel("vgaarb: vgadev %p\n", vgadev);
                if (vgadev == NULL) {
-                       pr_info("vgaarb: this pci device is not a vga device\n");
+                       pr_err("vgaarb: this pci device is not a vga device\n");
                        pci_dev_put(pdev);
                        ret_val = -ENODEV;
                        goto done;
@@ -999,7 +1013,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
                        }
                }
                if (i == MAX_USER_CARDS) {
-                       pr_err("vgaarb: maximum user cards number reached!\n");
+                       pr_err("vgaarb: maximum user cards (%d) number reached!\n",
+                               MAX_USER_CARDS);
                        pci_dev_put(pdev);
                        /* XXX: which value to return? */
                        ret_val =  -ENOMEM;
@@ -1014,7 +1029,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
        } else if (strncmp(curr_pos, "decodes ", 8) == 0) {
                curr_pos += 8;
                remaining -= 8;
-               pr_devel("vgaarb: client 0x%X called 'decodes'\n", (int)priv);
+               pr_devel("vgaarb: client 0x%p called 'decodes'\n", priv);
 
                if (!vga_str_to_iostate(curr_pos, remaining, &io_state)) {
                        ret_val = -EPROTO;