OSDN Git Service

vgaarb: update stub interface
[android-x86/external-libpciaccess.git] / src / common_bridge.c
index 68a535e..7f26bdc 100644 (file)
@@ -55,8 +55,17 @@ read_bridge_info( struct pci_device_private * priv )
 {
     uint8_t  buf[0x40];
     pciaddr_t bytes;
+    int err;
 
 
+    /* Make sure the device has been probed.  If not, header_type won't be
+     * set and the rest of this function will fail.
+     */
+    err = pci_device_probe(& priv->base);
+    if (err) {
+       return err;
+    }
+
     switch ( priv->header_type & 0x7f ) {
     case 0x00:
        break;
@@ -261,8 +270,8 @@ pci_device_get_bridge_buses(struct pci_device * dev, int *primary_bus,
        return ENODEV;
     }
 
-    if (priv->bridge.pci == NULL) {
-       read_bridge_info(priv);
+    if (!priv->bridge.pci) {
+       return ENODEV;
     }
 
     switch ((dev->device_class >> 8) & 0x0ff) {
@@ -283,15 +292,31 @@ pci_device_get_bridge_buses(struct pci_device * dev, int *primary_bus,
        break;
 
     case 0x04:
+    if (priv->bridge.pci == NULL)
+        read_bridge_info(priv);
+    if (priv->header_type == 0x01) {
        *primary_bus = priv->bridge.pci->primary_bus;
        *secondary_bus = priv->bridge.pci->secondary_bus;
        *subordinate_bus = priv->bridge.pci->subordinate_bus;
+    } else {
+       *primary_bus = dev->bus;
+       *secondary_bus = -1;
+       *subordinate_bus = -1;
+    }
        break;
 
     case 0x07:
+    if (priv->bridge.pcmcia == NULL)
+        read_bridge_info(priv);
+    if (priv->header_type == 0x02) {
        *primary_bus = priv->bridge.pcmcia->primary_bus;
        *secondary_bus = priv->bridge.pcmcia->card_bus;
        *subordinate_bus = priv->bridge.pcmcia->subordinate_bus;
+    } else {
+       *primary_bus = dev->bus;
+       *secondary_bus = -1;
+       *subordinate_bus = -1;
+    }
        break;
     }