From: "Kobayashi,Daisuke" <kobayashi.da-06@fujitsu.com>
To: linux-pci@vger.kernel.org, kw@linux.com
Cc: "Kobayashi,Daisuke" <kobayashi.da-06@fujitsu.com>
Subject: [PATCH v4] Export PBEC Data register into sysfs
Date: Wed, 11 Sep 2024 10:20:53 +0900 [thread overview]
Message-ID: <20240911012053.345286-1-kobayashi.da-06@fujitsu.com> (raw)
This proposal aims to add a feature that outputs PCIe device power
consumption information to sysfs.
Add support for PBEC (Power Budgeting Extended Capability) output
to the PCIe driver. PBEC is defined in the
PCIe specification(PCIe r6.0, sec 7.8.1) and is
a standard method for obtaining device power consumption information.
PCIe devices can significantly impact the overall power consumption of
a system. However, obtaining PCIe device power consumption information
has traditionally been difficult.
The PBEC Data register changes depending on the value of the PBEC Data
Select register. To obtain all PBEC Data register values defined in the
device, obtain the value of the PBEC Data register while changing the
value of the PBEC Data Select register.
Signed-off-by: "Kobayashi,Daisuke" <kobayashi.da-06@fujitsu.com>
---
Documentation/ABI/testing/sysfs-bus-pci | 17 +++++++++++++++
drivers/pci/pci-sysfs.c | 28 +++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index ecf47559f495..be1911d948ef 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -500,3 +500,20 @@ Description:
console drivers from the device. Raw users of pci-sysfs
resourceN attributes must be terminated prior to resizing.
Success of the resizing operation is not guaranteed.
+
+What: /sys/bus/pci/devices/.../power_budget
+Date: September 2024
+Contact: Kobayashi Daisuke <kobayashi.da-06@fujitsu.com>
+Description:
+ This file provides information about the PCIe power budget
+ for the device. It is a read-only file that outputs the values
+ of the Power Budgeting Data Register for each power state as a
+ series of 32-bit hexadecimal values. Each line represents a
+ single Power Budgeting Data register entry, containing the
+ power budget for a specific power state.
+
+ The specific interpretation of these values depends on the
+ device and the PCIe specification. Refer to the PCIe
+ specification for detailed information about the Power
+ Budgeting Data register, including the encoding of power
+ states and the interpretation of Base Power and Data Scale.
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 2321fdfefd7d..c52814a33597 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -182,6 +182,33 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(resource);
+static ssize_t power_budget_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pci_dev *pci_dev = to_pci_dev(dev);
+ size_t len = 0;
+ int i, pos;
+ u32 data;
+
+ pos = pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_PWR);
+ if (!pos)
+ return -EINVAL;
+
+ for (i = 0; i < 0xff; i++) {
+ pci_write_config_byte(pci_dev, pos + PCI_PWR_DSR, (u8)i);
+ pci_read_config_dword(pci_dev, pos + PCI_PWR_DATA, &data);
+ if (!data) {
+ if (len == 0)
+ return -EINVAL;
+ break;
+ }
+ len += sysfs_emit_at(buf, len, "%04x\n", data);
+ }
+
+ return len;
+}
+static DEVICE_ATTR_RO(power_budget);
+
static ssize_t max_link_speed_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -629,6 +656,7 @@ static struct attribute *pcie_dev_attrs[] = {
&dev_attr_current_link_width.attr,
&dev_attr_max_link_width.attr,
&dev_attr_max_link_speed.attr,
+ &dev_attr_power_budget.attr,
NULL,
};
--
2.45.0
next reply other threads:[~2024-09-11 1:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 1:20 Kobayashi,Daisuke [this message]
2024-09-24 7:39 ` [PATCH v4] Export PBEC Data register into sysfs Daisuke Kobayashi (Fujitsu)
2024-10-15 1:04 ` Daisuke Kobayashi (Fujitsu)
2024-10-31 7:37 ` Daisuke Kobayashi (Fujitsu)
2024-11-01 11:04 ` Jonathan Cameron
2024-11-06 8:58 ` Daisuke Kobayashi (Fujitsu)
2024-11-07 15:55 ` Krzysztof Wilczyński
2024-11-14 2:27 ` Daisuke Kobayashi (Fujitsu)
2024-11-14 9:37 ` Daisuke Kobayashi (Fujitsu)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240911012053.345286-1-kobayashi.da-06@fujitsu.com \
--to=kobayashi.da-06@fujitsu.com \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox