On Tue, Jun 13, 2006 at 12:54:37PM -0400, Bill Nottingham wrote:
> The reason we do this is because the class, vendor, and device ID fields in
> sysfs are correct with respect to applied PCI quirks. The config data (at
> least at the point we added the patch) is not. (Hooray for PPC.)

Aha.  That makes sense; I suspect most PCI devices don't allow the OS to
write that field ;-)  I didn't like the 'read it byte-by-byte' part of
the patch, so I changed it to pci_get_word().

Martin, now that we have a reason, what do you think to this patch?

--- pciutils-2.2.1/lib/sysfs.c.devicetype       2005-09-21 07:51:00.000000000 
-0400
+++ pciutils-2.2.1/lib/sysfs.c  2005-12-13 17:02:12.000000000 -0500
@@ -164,7 +164,6 @@
          sysfs_get_resources(d);
          d->irq = sysfs_get_value(d, "irq");
          d->known_fields = PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | 
PCI_FILL_SIZES;
-#if 0
          /*
           *  We prefer reading these from the config registers, it's faster.
           *  However, it would be possible and maybe even useful to hack the 
kernel
@@ -173,8 +172,8 @@
           */
          d->vendor_id = sysfs_get_value(d, "vendor");
          d->device_id = sysfs_get_value(d, "device");
-         d->known_fields |= PCI_FILL_IDENT;
-#endif
+         d->device_class = sysfs_get_value(d, "class") >> 8;
+         d->known_fields |= PCI_FILL_IDENT | PCI_FILL_CLASS;
        }
       pci_link_dev(a, d);
     }
--- pciutils-2.2.1/lib/pci.h.devicetype 2005-09-10 08:10:54.000000000 -0400
+++ pciutils-2.2.1/lib/pci.h    2005-12-13 17:02:12.000000000 -0500
@@ -84,6 +84,7 @@
   /* These fields are set by pci_fill_info() */
   int known_fields;                    /* Set of info fields already known */
   u16 vendor_id, device_id;            /* Identity of the device */
+  u16 device_class;                    /* PCI device class */
   int irq;                             /* IRQ number */
   pciaddr_t base_addr[6];              /* Base addresses */
   pciaddr_t size[6];                   /* Region sizes */
@@ -118,6 +119,7 @@
 #define PCI_FILL_BASES         4
 #define PCI_FILL_ROM_BASE      8
 #define PCI_FILL_SIZES         16
+#define PCI_FILL_CLASS         32
 #define PCI_FILL_RESCAN                0x10000
 
 void pci_setup_cache(struct pci_dev *, u8 *cache, int len);
--- pciutils-2.2.1/lib/generic.c.devicetype     2004-08-13 16:15:23.000000000 
-0400
+++ pciutils-2.2.1/lib/generic.c        2005-12-13 17:02:12.000000000 -0500
@@ -46,7 +46,8 @@
          d->func = t->func;
          d->vendor_id = vd & 0xffff;
          d->device_id = vd >> 16U;
-         d->known_fields = PCI_FILL_IDENT;
+         d->device_class = pci_read_word(t, PCI_CLASS_DEVICE);
+         d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS;
          d->hdrtype = ht;
          pci_link_dev(a, d);
          switch (ht)
@@ -86,6 +87,8 @@
       d->vendor_id = pci_read_word(d, PCI_VENDOR_ID);
       d->device_id = pci_read_word(d, PCI_DEVICE_ID);
     }
+  if (flags & PCI_FILL_CLASS)
+      d->device_class = pci_read_word(d, PCI_CLASS_DEVICE);
   if (flags & PCI_FILL_IRQ)
     d->irq = pci_read_byte(d, PCI_INTERRUPT_LINE);
   if (flags & PCI_FILL_BASES)
--- pciutils-2.2.1/lib/example.c.devicetype     2000-03-09 03:38:33.000000000 
-0500
+++ pciutils-2.2.1/lib/example.c        2005-12-13 17:02:12.000000000 -0500
@@ -21,7 +21,7 @@
   pci_scan_bus(pacc);          /* We want to get the list of devices */
   for(dev=pacc->devices; dev; dev=dev->next)   /* Iterate over all devices */
     {
-      pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);     /* Fill in 
header info we need */
+      pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);    
/* Fill in header info we need */
       c = pci_read_word(dev, PCI_CLASS_DEVICE);        /* Read config register 
directly */
       printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d 
base0=%lx\n",
             dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id,
--- pciutils-2.2.1/lspci.c.devicetype   2005-11-26 06:48:29.000000000 -0500
+++ pciutils-2.2.1/lspci.c      2005-12-13 17:04:39.000000000 -0500
@@ -123,7 +123,7 @@
        d->config_cached += 64;
     }
   pci_setup_cache(p, d->config, d->config_cached);
-  pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | 
PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
+  pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | 
PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
   return d;
 }
 
@@ -255,7 +255,7 @@
   printf(" %s: %s",
         pci_lookup_name(pacc, classbuf, sizeof(classbuf),
                         PCI_LOOKUP_CLASS,
-                        get_conf_word(d, PCI_CLASS_DEVICE)),
+                        p->device_class),
         pci_lookup_name(pacc, devbuf, sizeof(devbuf),
                         PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE,
                         p->vendor_id, p->device_id));
@@ -267,7 +267,7 @@
       c = get_conf_byte(d, PCI_CLASS_PROG);
       x = pci_lookup_name(pacc, devbuf, sizeof(devbuf),
                          PCI_LOOKUP_PROGIF | PCI_LOOKUP_NO_NUMBERS,
-                         get_conf_word(d, PCI_CLASS_DEVICE), c);
+                         p->device_class, c);
       if (c || x)
        {
          printf(" (prog-if %02x", c);
@@ -1585,7 +1585,7 @@
   struct pci_dev *p = d->dev;
   word status = get_conf_word(d, PCI_STATUS);
   word cmd = get_conf_word(d, PCI_COMMAND);
-  word class = get_conf_word(d, PCI_CLASS_DEVICE);
+  word class = p->device_class;
   byte bist = get_conf_byte(d, PCI_BIST);
   byte htype = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
   byte latency = get_conf_byte(d, PCI_LATENCY_TIMER);
@@ -1783,7 +1783,7 @@
       show_slot_name(d);
       putchar('\n');
       printf("Class:\t%s\n",
-            pci_lookup_name(pacc, classbuf, sizeof(classbuf), 
PCI_LOOKUP_CLASS, get_conf_word(d, PCI_CLASS_DEVICE)));
+            pci_lookup_name(pacc, classbuf, sizeof(classbuf), 
PCI_LOOKUP_CLASS, p->device_class));
       printf("Vendor:\t%s\n",
             pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, 
p->vendor_id, p->device_id));
       printf("Device:\t%s\n",
@@ -1805,7 +1805,7 @@
       show_slot_name(d);
       printf(" \"%s\" \"%s\" \"%s\"",
             pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS,
-                            get_conf_word(d, PCI_CLASS_DEVICE)),
+                            p->device_class),
             pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR,
                             p->vendor_id, p->device_id),
             pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE,
@@ -1929,7 +1929,7 @@
   last_br = &host_bridge.chain;
   for(d=first_dev; d; d=d->next)
     {
-      word class = get_conf_word(d, PCI_CLASS_DEVICE);
+      word class = d->dev->device_class;
       byte ht = get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f;
       if (class == PCI_CLASS_BRIDGE_PCI &&
          (ht == PCI_HEADER_TYPE_BRIDGE || ht == PCI_HEADER_TYPE_CARDBUS))


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to