All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David E. Box" <david.e.box@linux.intel.com>
To: david.e.box@linux.intel.com, rajvi.jingar@linux.intel.com,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, hdegoede@redhat.com,
	ilpo.jarvinen@linux.intel.com
Subject: [PATCH V2 4/9] platform/x86/intel/sdsi: Add attribute to read the current meter state
Date: Tue, 27 Feb 2024 16:00:11 -0800	[thread overview]
Message-ID: <20240228000016.1685518-5-david.e.box@linux.intel.com> (raw)
In-Reply-To: <20240228000016.1685518-1-david.e.box@linux.intel.com>

The meter_certificate file provides access to metering information that may
be attested but is only updated every 8 hours. Add new attribute,
meter_current, to allow reading an untested snapshot of the current values.

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---

V2 - make control_flags a parameter to be eventually passed to
     sdsi_mbox_cmd_read(). This removes the need for a lock which had been
     added to protect control_flags when it was a member of the private
     struct.

 drivers/platform/x86/intel/sdsi.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c
index bb3eaf5eb382..277e4f4b20ac 100644
--- a/drivers/platform/x86/intel/sdsi.c
+++ b/drivers/platform/x86/intel/sdsi.c
@@ -68,6 +68,7 @@
 #define CTRL_COMPLETE			BIT(6)
 #define CTRL_READY			BIT(7)
 #define CTRL_INBAND_LOCK		BIT(32)
+#define CTRL_METER_ENABLE_DRAM		BIT(33)
 #define CTRL_STATUS			GENMASK(15, 8)
 #define CTRL_PACKET_SIZE		GENMASK(31, 16)
 #define CTRL_MSG_SIZE			GENMASK(63, 48)
@@ -95,6 +96,7 @@ enum sdsi_command {
 struct sdsi_mbox_info {
 	u64	*payload;
 	void	*buffer;
+	u64	control_flags;
 	int	size;
 };
 
@@ -250,7 +252,8 @@ static int sdsi_mbox_cmd_read(struct sdsi_priv *priv, struct sdsi_mbox_info *inf
 	control = FIELD_PREP(CTRL_EOM, 1) |
 		  FIELD_PREP(CTRL_SOM, 1) |
 		  FIELD_PREP(CTRL_RUN_BUSY, 1) |
-		  FIELD_PREP(CTRL_PACKET_SIZE, info->size);
+		  FIELD_PREP(CTRL_PACKET_SIZE, info->size) |
+		  info->control_flags;
 	writeq(control, priv->control_addr);
 
 	return sdsi_mbox_poll(priv, info, data_size);
@@ -424,8 +427,8 @@ static ssize_t provision_cap_write(struct file *filp, struct kobject *kobj,
 static BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG);
 
 static ssize_t
-certificate_read(u64 command, struct sdsi_priv *priv, char *buf, loff_t off,
-		 size_t count)
+certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv,
+		 char *buf, loff_t off, size_t count)
 {
 	struct sdsi_mbox_info info = {};
 	size_t size;
@@ -441,6 +444,7 @@ certificate_read(u64 command, struct sdsi_priv *priv, char *buf, loff_t off,
 
 	info.payload = &command;
 	info.size = sizeof(command);
+	info.control_flags = control_flags;
 
 	ret = mutex_lock_interruptible(&priv->mb_lock);
 	if (ret)
@@ -472,7 +476,7 @@ state_certificate_read(struct file *filp, struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct sdsi_priv *priv = dev_get_drvdata(dev);
 
-	return certificate_read(SDSI_CMD_READ_STATE, priv, buf, off, count);
+	return certificate_read(SDSI_CMD_READ_STATE, 0, priv, buf, off, count);
 }
 static BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG);
 
@@ -484,10 +488,23 @@ meter_certificate_read(struct file *filp, struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct sdsi_priv *priv = dev_get_drvdata(dev);
 
-	return certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
+	return certificate_read(SDSI_CMD_READ_METER, 0, priv, buf, off, count);
 }
 static BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG);
 
+static ssize_t
+meter_current_read(struct file *filp, struct kobject *kobj,
+		   struct bin_attribute *attr, char *buf, loff_t off,
+		   size_t count)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct sdsi_priv *priv = dev_get_drvdata(dev);
+
+	return certificate_read(SDSI_CMD_READ_METER, CTRL_METER_ENABLE_DRAM,
+				priv, buf, off, count);
+}
+static BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG);
+
 static ssize_t registers_read(struct file *filp, struct kobject *kobj,
 			      struct bin_attribute *attr, char *buf, loff_t off,
 			      size_t count)
@@ -518,6 +535,7 @@ static struct bin_attribute *sdsi_bin_attrs[] = {
 	&bin_attr_registers,
 	&bin_attr_state_certificate,
 	&bin_attr_meter_certificate,
+	&bin_attr_meter_current,
 	&bin_attr_provision_akc,
 	&bin_attr_provision_cap,
 	NULL
@@ -537,7 +555,7 @@ sdsi_battr_is_visible(struct kobject *kobj, struct bin_attribute *attr, int n)
 	if (!(priv->features & SDSI_FEATURE_SDSI))
 		return 0;
 
-	if (attr == &bin_attr_meter_certificate)
+	if (attr == &bin_attr_meter_certificate || attr == &bin_attr_meter_current)
 		return (priv->features & SDSI_FEATURE_METERING) ?
 				attr->attr.mode : 0;
 
-- 
2.34.1


  parent reply	other threads:[~2024-02-28  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28  0:00 [PATCH V2 0/9] Intel On Demand changes David E. Box
2024-02-28  0:00 ` [PATCH V2 1/9] platform/x86/intel/sdsi: Set message size during writes David E. Box
2024-02-28  2:34   ` Kuppuswamy Sathyanarayanan
2024-02-28  0:00 ` [PATCH V2 2/9] platform/x86/intel/sdsi: Combine read and write mailbox flows David E. Box
2024-02-28  2:38   ` Kuppuswamy Sathyanarayanan
2024-02-28 18:10     ` David E. Box
2024-03-04 13:25     ` Ilpo Järvinen
2024-02-28 20:45   ` Kuppuswamy Sathyanarayanan
2024-02-28  0:00 ` [PATCH V2 3/9] platform/x86/intel/sdsi: Add in-band BIOS lock support David E. Box
2024-03-04 13:26   ` Ilpo Järvinen
2024-02-28  0:00 ` David E. Box [this message]
2024-02-28  2:41   ` [PATCH V2 4/9] platform/x86/intel/sdsi: Add attribute to read the current meter state Kuppuswamy Sathyanarayanan
2024-03-04 13:29   ` Ilpo Järvinen
2024-02-28  0:00 ` [PATCH V2 5/9] tools/arch/x86/intel_sdsi: Fix maximum meter bundle length David E. Box
2024-02-28  2:54   ` Kuppuswamy Sathyanarayanan
2024-02-28  0:00 ` [PATCH V2 6/9] tools/arch/x86/intel_sdsi: Add missing version field David E. Box
2024-02-28  2:57   ` Kuppuswamy Sathyanarayanan
2024-02-28  0:00 ` [PATCH V2 7/9] tools/arch/x86/intel_sdsi: Fix meter_certificate decoding David E. Box
2024-02-28  2:58   ` Kuppuswamy Sathyanarayanan
2024-03-04 13:32   ` Ilpo Järvinen
2024-02-28  0:00 ` [PATCH V2 8/9] platform/x86/intel/sdsi: Simplify ascii printing David E. Box
2024-02-28  2:59   ` Kuppuswamy Sathyanarayanan
2024-02-28  0:00 ` [PATCH V2 9/9] tools: intel_sdsi: Add current meter support David E. Box
2024-02-28  3:31   ` Kuppuswamy Sathyanarayanan
2024-03-04 13:34   ` Ilpo Järvinen

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=20240228000016.1685518-5-david.e.box@linux.intel.com \
    --to=david.e.box@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rajvi.jingar@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.