[PATCH] parse the power budgeting table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Peres <martin.peres@xxxxxxxxxxxxxxx>

---
 Makefile   |    2 +-
 ls-ecaps.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index d67f7d6..4a82d0d 100644
--- a/Makefile
+++ b/Makefile
@@ -86,7 +86,7 @@ example: example.o lib/$(PCILIB)
 example.o: example.c $(PCIINC)
 
 %: %.o
-	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
+	$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -lm -o $@
 
 %.8 %.7: %.man
 	M=`echo $(DATE) | sed 's/-01-/-January-/;s/-02-/-February-/;s/-03-/-March-/;s/-04-/-April-/;s/-05-/-May-/;s/-06-/-June-/;s/-07-/-July-/;s/-08-/-August-/;s/-09-/-September-/;s/-10-/-October-/;s/-11-/-November-/;s/-12-/-December-/;s/\(.*\)-\(.*\)-\(.*\)/\3 \2 \1/'` ; sed <$< >$@ "s/@TODAY@/$$M/;s/@VERSION@/pciutils-$(VERSION)/;s#@IDSDIR@#$(IDSDIR)#"
diff --git a/ls-ecaps.c b/ls-ecaps.c
index cd342aa..0eb4f82 100644
--- a/ls-ecaps.c
+++ b/ls-ecaps.c
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <math.h>
 
 #include "lspci.h"
 
@@ -448,6 +449,83 @@ cap_evendor(struct device *d, int where)
     BITS(hdr, 20, 12));
 }
 
+static void
+cap_pb(struct device *d, int where)
+{
+  u16 i, w;
+  u16 base, scale, pm_sub, pm_state, type, rail;
+  const char *type_s, *rail_s;
+
+  printf("Power Budgeting\n");
+  if (verbose < 2)
+    return;
+
+  i = 0;
+  do {
+    pci_write_byte(d->dev, where + PCI_PWR_DSR, i);
+
+    w = pci_read_word(d->dev, where + PCI_PWR_DATA);
+    
+    if (!w)
+      return;
+    
+    base = PCI_PWR_DATA_BASE(w);
+    scale = PCI_PWR_DATA_SCALE(w);
+    pm_sub = PCI_PWR_DATA_PM_SUB(w);
+    pm_state = PCI_PWR_DATA_PM_STATE(w);
+    type = PCI_PWR_DATA_TYPE(w);
+    rail = PCI_PWR_DATA_RAIL(w);
+
+    printf("\t\tPB%i: ", i);
+    printf("Power %.3fW, ", base / pow(10, scale));
+
+    printf("%s PM_Sub, ", pm_sub == 0 ? "Default":"Custom");
+    printf("D%i PM_State, ", pm_state);
+    switch(type) {
+      case 0:
+        type_s = "PME_Aux";
+        break;
+      case 1:
+        type_s = "Auxiliary";
+        break;
+      case 2:
+        type_s = "Idle";
+        break;
+      case 3:
+        type_s = "Sustained";
+        break;
+      case 7:
+        type_s = "Maximum";
+        break;
+      default:
+        type_s = "Reserved";
+        break;
+    }
+    printf("%s Type, ", type_s);
+
+    switch(rail) {
+      case 0:
+        rail_s = "12V";
+        break;
+      case 1:
+        rail_s = "3.3V";
+        break;
+      case 2:
+        rail_s = "1.8V";
+        break;
+      case 7:
+        rail_s = "Thermal";
+        break;
+      default:
+        rail_s = "Reserved";
+        break;
+    }
+    printf("%s Power Rail\n", rail_s);
+
+    i++;
+  } while(1);
+}
+
 void
 show_ext_caps(struct device *d)
 {
@@ -488,7 +566,7 @@ show_ext_caps(struct device *d)
 	    cap_dsn(d, where);
 	    break;
 	  case PCI_EXT_CAP_ID_PB:
-	    printf("Power Budgeting <?>\n");
+	    cap_pb(d, where);
 	    break;
 	  case PCI_EXT_CAP_ID_RCLINK:
 	    cap_rclink(d, where);
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux