]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/hurd.c
Makefile: don't hardcode gcc
[pciutils.git] / lib / hurd.c
index 0a529043db7ec9e0d8d0b2c858b3136778ee0398..90cf89f7c0695aa8bc1cdf0f4d6cbf9e6c2a57e3 100644 (file)
@@ -88,20 +88,25 @@ hurd_cleanup_dev(struct pci_dev *d)
   pci_mfree(d->aux);
 }
 
-static int
+static mach_port_t
 device_port_lookup(struct pci_dev *d)
 {
-  mach_port_t device_port;
   char server[NAME_MAX];
+  mach_port_t device_port = *((mach_port_t *) d->aux);
+
+  if (device_port != MACH_PORT_NULL)
+    return device_port;
 
   snprintf(server, NAME_MAX, "%s/%04x/%02x/%02x/%01u/%s",
-     _SERVERS_BUS_PCI, d->domain, d->bus, d->dev, d->func,
-     FILE_CONFIG_NAME);
+    _SERVERS_BUS_PCI, d->domain, d->bus, d->dev, d->func,
+    FILE_CONFIG_NAME);
   device_port = file_name_lookup(server, 0, 0);
 
-  *((mach_port_t *) d->aux) = device_port;
+  if (device_port == MACH_PORT_NULL)
+    d->access->error("Cannot find the PCI arbiter");
 
-  return d->aux != MACH_PORT_NULL;
+  *((mach_port_t *) d->aux) = device_port;
+  return device_port;
 }
 
 /* Walk through the FS tree to see what is allowed for us */
@@ -113,8 +118,6 @@ enum_devices(const char *parent, struct pci_access *a, int domain, int bus,
   DIR *dir;
   struct dirent *entry;
   char path[NAME_MAX];
-  uint32_t vd;
-  uint8_t ht;
   struct pci_dev *d;
 
   dir = opendir(parent);
@@ -186,25 +189,7 @@ enum_devices(const char *parent, struct pci_access *a, int domain, int bus,
          d->bus = bus;
          d->dev = dev;
          d->func = func;
-
-         /* Get the arbiter port */
-         if (!device_port_lookup(d))
-           {
-             if (closedir(dir) < 0)
-               a->warning("Cannot close directory: %s (%s)", parent,
-                          strerror(errno));
-             a->error("Cannot find the PCI arbiter");
-           }
-
          pci_link_dev(a, d);
-
-         vd = pci_read_long(d, PCI_VENDOR_ID);
-         ht = pci_read_byte(d, PCI_HEADER_TYPE);
-
-         d->vendor_id = vd & 0xffff;
-         d->device_id = vd >> 16U;
-         d->known_fields = PCI_FILL_IDENT;
-         d->hdrtype = ht;
        }
     }
 
@@ -230,42 +215,27 @@ hurd_read(struct pci_dev *d, int pos, byte * buf, int len)
   int err;
   size_t nread;
   char *data;
-  mach_port_t device_port;
-
-  nread = len;
-  if (*((mach_port_t *) d->aux) == MACH_PORT_NULL)
-    {
-      /* We still don't have the port for this device */
-      if (device_port_lookup(d))
-       {
-         d->access->error("Cannot find the PCI arbiter");
-       }
-    }
-  device_port = *((mach_port_t *) d->aux);
+  mach_port_t device_port = device_port_lookup(d);
 
   if (len > 4)
-    err = !pci_generic_block_read(d, pos, buf, nread);
-  else
-    {
-      data = (char *) buf;
-      err = pci_conf_read(device_port, pos, &data, &nread, len);
+    return pci_generic_block_read(d, pos, buf, len);
 
-      if (data != (char *) buf)
-       {
-         if (nread > (size_t) len)     /* Sanity check for bogus server.  */
-           {
-             vm_deallocate(mach_task_self(), (vm_address_t) data, nread);
-             return 0;
-           }
+  data = (char *) buf;
+  err = pci_conf_read(device_port, pos, &data, &nread, len);
 
-         memcpy(buf, data, nread);
+  if (data != (char *) buf)
+    {
+      if (nread > (size_t) len)        /* Sanity check for bogus server.  */
+       {
          vm_deallocate(mach_task_self(), (vm_address_t) data, nread);
+         return 0;
        }
+
+      memcpy(buf, data, nread);
+      vm_deallocate(mach_task_self(), (vm_address_t) data, nread);
     }
-  if (err)
-    return 0;
 
-  return nread == (size_t) len;
+  return !err && nread == (size_t) len;
 }
 
 /*
@@ -278,27 +248,14 @@ hurd_write(struct pci_dev *d, int pos, byte * buf, int len)
 {
   int err;
   size_t nwrote;
-  mach_port_t device_port;
-
-  nwrote = len;
-  if (*((mach_port_t *) d->aux) == MACH_PORT_NULL)
-    {
-      /* We still don't have the port for this device */
-      if (device_port_lookup(d))
-       {
-         d->access->error("Cannot find the PCI arbiter");
-       }
-    }
-  device_port = *((mach_port_t *) d->aux);
+  mach_port_t device_port = device_port_lookup(d);
 
   if (len > 4)
-    err = !pci_generic_block_write(d, pos, buf, len);
-  else
-    err = pci_conf_write(device_port, pos, (char *) buf, len, &nwrote);
-  if (err)
-    return 0;
+    return pci_generic_block_write(d, pos, buf, len);
+
+  err = pci_conf_write(device_port, pos, (char *) buf, len, &nwrote);
 
-  return nwrote == (size_t) len;
+  return !err && nwrote == (size_t) len;
 }
 
 /* Get requested info from the server */
@@ -306,7 +263,7 @@ hurd_write(struct pci_dev *d, int pos, byte * buf, int len)
 static void
 hurd_fill_regions(struct pci_dev *d)
 {
-  mach_port_t device_port = *((mach_port_t *) d->aux);
+  mach_port_t device_port = device_port_lookup(d);
   struct pci_bar regions[6];
   char *buf = (char *) &regions;
   size_t size = sizeof(regions);
@@ -346,7 +303,7 @@ static void
 hurd_fill_rom(struct pci_dev *d)
 {
   struct pci_xrom_bar rom;
-  mach_port_t device_port = *((mach_port_t *) d->aux);
+  mach_port_t device_port = device_port_lookup(d);
   char *buf = (char *) &rom;
   size_t size = sizeof(rom);