]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/sysfs.c
Let filters accept vendor and device 0xffff.
[pciutils.git] / lib / sysfs.c
index 70511b1fc3eed79f2e63bf614409afd2698b9e40..ea386fa8fbdfbf4a7dd616ef8469eed2c4bed7a7 100644 (file)
@@ -2,7 +2,7 @@
  *     The PCI Library -- Configuration Access via /sys/bus/pci
  *
  *     Copyright (c) 2003 Matthew Wilcox <willy@fc.hp.com>
- *     Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 static void
 sysfs_config(struct pci_access *a)
 {
-  a->method_params[PCI_ACCESS_SYS_BUS_PCI] = PATH_SYS_BUS_PCI;
+  pci_define_param(a, "sysfs.path", PCI_PATH_SYS_BUS_PCI, "Path to the sysfs device tree");
 }
 
 static inline char *
 sysfs_name(struct pci_access *a)
 {
-  return a->method_params[PCI_ACCESS_SYS_BUS_PCI];
+  return pci_get_param(a, "sysfs.path");
 }
 
 static int
@@ -39,7 +39,7 @@ sysfs_detect(struct pci_access *a)
 {
   if (access(sysfs_name(a), R_OK))
     {
-      a->debug("Cannot open %s", sysfs_name(a));
+      a->debug("...cannot open %s", sysfs_name(a));
       return 0;
     }
   a->debug("...using %s", sysfs_name(a));
@@ -105,24 +105,18 @@ sysfs_get_resources(struct pci_dev *d)
   file = fopen(namebuf, "r");
   if (!file)
     a->error("Cannot open %s: %s", namebuf, strerror(errno));
-  for (i = 0; i < 8; i++)
+  for (i = 0; i < 7; i++)
     {
       unsigned long long start, end, size;
       if (!fgets(buf, sizeof(buf), file))
        break;
       if (sscanf(buf, "%llx %llx", &start, &end) != 2)
        a->error("Syntax error in %s", namebuf);
-      if (start != (unsigned long long)(pciaddr_t) start ||
-         end != (unsigned long long)(pciaddr_t) end)
-       {
-         a->warning("Resource %d in %s has a 64-bit address, ignoring", namebuf);
-         start = end = 0;
-       }
       if (start)
        size = end - start + 1;
       else
        size = 0;
-      if (i < 7)
+      if (i < 6)
        {
          d->base_addr[i] = start;
          d->size[i] = size;
@@ -165,14 +159,18 @@ static void sysfs_scan(struct pci_access *a)
       d->bus = bus;
       d->dev = dev;
       d->func = func;
-      d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f;
       if (!a->buscentric)
        {
          sysfs_get_resources(d);
+         d->irq = sysfs_get_value(d, "irq");
+         /*
+          *  We could read these faster from the config registers, but we want to give
+          *  the kernel a chance to fix up ID's and especially classes of broken devices.
+          */
          d->vendor_id = sysfs_get_value(d, "vendor");
          d->device_id = sysfs_get_value(d, "device");
-         d->irq = sysfs_get_value(d, "irq");
-         d->known_fields = PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES;
+         d->device_class = sysfs_get_value(d, "class") >> 8;
+         d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES;
        }
       pci_link_dev(a, d);
     }
@@ -214,10 +212,7 @@ static int sysfs_read(struct pci_dev *d, int pos, byte *buf, int len)
       return 0;
     }
   else if (res != len)
-    {
-      d->access->warning("sysfs_read: tried to read %d bytes at %d, but got only %d", len, pos, res);
-      return 0;
-    }
+    return 0;
   return 1;
 }
 
@@ -236,7 +231,7 @@ static int sysfs_write(struct pci_dev *d, int pos, byte *buf, int len)
     }
   else if (res != len)
     {
-      d->access->warning("sysfs_write: tried to write %d bytes at %d, but got only %d", len, pos, res);
+      d->access->warning("sysfs_write: tried to write %d bytes at %d, but only %d succeeded", len, pos, res);
       return 0;
     }
   return 1;
@@ -255,7 +250,8 @@ static void sysfs_cleanup_dev(struct pci_dev *d)
 }
 
 struct pci_methods pm_linux_sysfs = {
-  "Linux-sysfs",
+  "linux-sysfs",
+  "The sys filesystem on Linux",
   sysfs_config,
   sysfs_detect,
   sysfs_init,