From patchwork Sat Aug 6 08:27:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin.peres@ensi-bourges.fr X-Patchwork-Id: 1041112 X-Patchwork-Delegate: bhelgaas@google.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p768Z0Am026901 for ; Sat, 6 Aug 2011 08:35:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752487Ab1HFIfA (ORCPT ); Sat, 6 Aug 2011 04:35:00 -0400 Received: from mail.ensi-bourges.fr ([195.221.38.25]:41482 "EHLO ensi-bourges.fr" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752483Ab1HFIe7 (ORCPT ); Sat, 6 Aug 2011 04:34:59 -0400 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 06 Aug 2011 08:35:00 +0000 (UTC) X-Greylist: delayed 399 seconds by postgrey-1.27 at vger.kernel.org; Sat, 06 Aug 2011 04:34:58 EDT Received: (qmail 19729 invoked from network); 6 Aug 2011 08:27:10 -0000 Received: from unknown (HELO localhost.localdomain) (Authenticated?user?:martin.peres@[222.255.132.5]) (envelope-sender ) by mail.ensi-bourges.fr (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 6 Aug 2011 08:27:10 -0000 From: martin.peres@ensi-bourges.fr To: linux-pci@vger.kernel.org Cc: Martin Peres Subject: [PATCH] parse the power budgeting table Date: Sat, 6 Aug 2011 10:27:02 +0200 Message-Id: <1312619222-10093-1-git-send-email-martin.peres@ensi-bourges.fr> X-Mailer: git-send-email 1.7.6 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Martin Peres --- 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 #include +#include #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);