OSDN Git Service

vgaarb: add support for targetting default device
[android-x86/external-libpciaccess.git] / src / common_vgaarb.c
index 55b3868..79d3f93 100644 (file)
@@ -42,7 +42,6 @@ int
 pci_device_vgaarb_init(void)
 {
     if ((pci_sys->vgaarb_fd = open ("/dev/vga_arbiter", O_RDWR)) < 0) {
-        fprintf(stderr, "device open failed");
         return errno;
     }
 
@@ -52,8 +51,7 @@ pci_device_vgaarb_init(void)
 void
 pci_device_vgaarb_fini(void)
 {
-    if (close(pci_sys->vgaarb_fd) != 0)
-        fprintf(stderr, "device close failed");
+    close(pci_sys->vgaarb_fd);
 }
 
 /**
@@ -82,12 +80,16 @@ vgaarb_write(int fd, char *buf, int len)
         if (errno == EBUSY)
             return 2;
 
+#ifdef DEBUG
         fprintf(stderr, "write error");
+#endif
         return 1;
     }
     else if (ret != len) {
         /* it's need to receive the exactly amount required. */
+#ifdef DEBUG
         fprintf(stderr, "write error: wrote different than expected\n");
+#endif
         return 1;
     }
 
@@ -167,9 +169,13 @@ pci_device_vgaarb_set_target(struct pci_device *dev)
     int len;
     char buf[BUFSIZE];
     int ret;
+    int rsrc;
 
-    len = snprintf(buf, BUFSIZE, "target PCI:%d:%d:%d.%d",
-                   dev->domain, dev->bus, dev->dev, dev->func);
+    if (!dev)
+        len = snprintf(buf, BUFSIZE, "default");
+    else
+        len = snprintf(buf, BUFSIZE, "target PCI:%d:%d:%d.%d",
+                       dev->domain, dev->bus, dev->dev, dev->func);
 
     ret = vgaarb_write(pci_sys->vgaarb_fd, buf, len);
     if (ret)
@@ -179,7 +185,9 @@ pci_device_vgaarb_set_target(struct pci_device *dev)
     if (ret <= 0)
        return -1;
 
-    dev->vgaarb_rsrc = parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count);
+    rsrc = parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count);
+    if (dev)
+        dev->vgaarb_rsrc = rsrc;
     return 0;
 }