]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
Factorize out a hwloc_pci_find_linkspeed() in m...
authorBrice Goglin <brice.goglin@inria.fr>
Wed, 15 May 2013 12:33:31 +0000 (12:33 +0000)
committerBrice Goglin <brice.goglin@inria.fr>
Wed, 15 May 2013 12:33:31 +0000 (12:33 +0000)
Factorize out a hwloc_pci_find_linkspeed() in misc.h as well

This commit was SVN r5625.

include/hwloc/rename.h
include/private/misc.h
src/topology-pci.c

index 94c396624620547943e6331482bbc75e8f96ede9..367547852644fd71163f5fa3590f74e8e00b336d 100644 (file)
@@ -468,12 +468,8 @@ extern "C" {
 #define hwloc_fls32 HWLOC_NAME(fls32)
 #define hwloc_weight_long HWLOC_NAME(weight_long)
 
-#define HWLOC_PCI_CAPABILITY_LIST HWLOC_NAME_CAPS(PCI_CAPABILITY_LIST)
-#define HWLOC_PCI_STATUS_CAP_LIST HWLOC_NAME_CAPS(PCI_STATUS_CAP_LIST)
-#define HWLOC_PCI_CAP_LIST_ID HWLOC_NAME_CAPS(PCI_CAP_LIST_ID)
-#define HWLOC_PCI_CAP_LIST_NEXT HWLOC_NAME_CAPS(PCI_CAP_LIST_NEXT)
-#define HWLOC_PCI_STATUS HWLOC_NAME_CAPS(PCI_STATUS)
 #define hwloc_pci_find_cap HWLOC_NAME(pci_find_cap)
+#define hwloc_pci_find_linkspeed HWLOC_NAME(pci_find_linkspeed)
 
 /* private/cpuid.h */
 
index 4aade04b2b9fd14c04b2c066ca16aa24c075a580..5db28e148a8bfc596d626ea43a68a2ba377144f2 100644 (file)
@@ -384,4 +384,30 @@ hwloc_pci_find_cap(const unsigned char *config, size_t config_size, unsigned cap
   return 0;
 }
 
+#define HWLOC_PCI_EXP_LNKSTA 0x12
+#define HWLOC_PCI_EXP_LNKSTA_SPEED 0x000f
+#define HWLOC_PCI_EXP_LNKSTA_WIDTH 0x03f0
+
+static __hwloc_inline int
+hwloc_pci_find_linkspeed(const unsigned char *config, size_t config_size,
+                        unsigned offset, float *linkspeed)
+{
+  unsigned linksta, speed, width;
+  float lanespeed;
+
+  if (offset + HWLOC_PCI_EXP_LNKSTA + 4 >= config_size)
+    return -1;
+
+  memcpy(&linksta, &config[offset + HWLOC_PCI_EXP_LNKSTA], 4);
+  speed = linksta & HWLOC_PCI_EXP_LNKSTA_SPEED; /* PCIe generation */
+  width = (linksta & HWLOC_PCI_EXP_LNKSTA_WIDTH) >> 4; /* how many lanes */
+  /* PCIe Gen1 = 2.5GT/s signal-rate per lane with 8/10 encoding    = 0.25GB/s data-rate per lane
+   * PCIe Gen2 = 5  GT/s signal-rate per lane with 8/10 encoding    = 0.5 GB/s data-rate per lane
+   * PCIe Gen3 = 8  GT/s signal-rate per lane with 128/130 encoding = 1   GB/s data-rate per lane
+   */
+  lanespeed = speed <= 2 ? 2.5 * speed * 0.8 : 8.0 * 128/130; /* Gbit/s per lane */
+  *linkspeed = lanespeed * width / 8; /* GB/s */
+  return 0;
+}
+
 #endif /* HWLOC_PRIVATE_MISC_H */
index 0251beb8ff3ed99157ab894ae85aa214da967990..d508ae8f240f6e26e2c1baca598eaa935c0ada7b 100644 (file)
 #define PCI_SUBORDINATE_BUS 0x1a
 #endif
 
-#ifndef PCI_EXP_LNKSTA
-#define PCI_EXP_LNKSTA 18
-#endif
-
-#ifndef PCI_EXP_LNKSTA_SPEED
-#define PCI_EXP_LNKSTA_SPEED 0x000f
-#endif
-#ifndef PCI_EXP_LNKSTA_WIDTH
-#define PCI_EXP_LNKSTA_WIDTH 0x03f0
-#endif
-
 #ifndef PCI_CAP_ID_EXP
 #define PCI_CAP_ID_EXP 0x10
 #endif
@@ -515,23 +504,9 @@ hwloc_look_pci(struct hwloc_backend *backend)
 #else
     offset = hwloc_pci_find_cap(config_space_cache, config_space_cachesize, PCI_CAP_ID_EXP);
 #endif /* HWLOC_HAVE_PCI_FIND_CAP */
-    if (offset > 0) {
-      if (offset + PCI_EXP_LNKSTA + 4 >= config_space_cachesize) {
-        fprintf(stderr, "cannot read PCI_EXP_LNKSTA cap at %d (only %d cached)\n", offset + PCI_EXP_LNKSTA, CONFIG_SPACE_CACHESIZE);
-      } else {
-        unsigned linksta, speed, width;
-        float lanespeed;
-        memcpy(&linksta, &config_space_cache[offset + PCI_EXP_LNKSTA], 4);
-        speed = linksta & PCI_EXP_LNKSTA_SPEED; /* PCIe generation */
-        width = (linksta & PCI_EXP_LNKSTA_WIDTH) >> 4; /* how many lanes */
-       /* PCIe Gen1 = 2.5GT/s signal-rate per lane with 8/10 encoding    = 0.25GB/s data-rate per lane
-        * PCIe Gen2 = 5  GT/s signal-rate per lane with 8/10 encoding    = 0.5 GB/s data-rate per lane
-        * PCIe Gen3 = 8  GT/s signal-rate per lane with 128/130 encoding = 1   GB/s data-rate per lane
-        */
-        lanespeed = speed <= 2 ? 2.5 * speed * 0.8 : 8.0 * 128/130; /* Gbit/s per lane */
-        obj->attr->pcidev.linkspeed = lanespeed * width / 8; /* GB/s */
-      }
-    }
+    if (offset > 0)
+      hwloc_pci_find_linkspeed(config_space_cache, config_space_cachesize, offset,
+                              &obj->attr->pcidev.linkspeed);
 
     if (isbridge) {
       HWLOC_BUILD_ASSERT(PCI_PRIMARY_BUS < CONFIG_SPACE_CACHESIZE);