From: "David E. Box" <david.e.box@linux.intel.com>
To: netdev@vger.kernel.org, ilpo.jarvinen@linux.intel.com,
david.e.box@linux.intel.com,
sathyanarayanan.kuppuswamy@linux.intel.com
Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org
Subject: [PATCH 6/8] platform/x86/intel/sdsi: Add attribute to read the current meter state
Date: Wed, 31 Jan 2024 17:07:45 -0800 [thread overview]
Message-ID: <20240201010747.471141-7-david.e.box@linux.intel.com> (raw)
In-Reply-To: <20240201010747.471141-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>
---
drivers/platform/x86/intel/sdsi.c | 42 ++++++++++++++++++++++++++++---
drivers/platform/x86/intel/sdsi.h | 2 ++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c
index 287780fe65bb..171899b4a671 100644
--- a/drivers/platform/x86/intel/sdsi.c
+++ b/drivers/platform/x86/intel/sdsi.c
@@ -62,6 +62,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)
@@ -235,8 +236,10 @@ 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) |
+ priv->control_flags;
writeq(control, priv->control_addr);
+ priv->control_flags = 0;
return sdsi_mbox_poll(priv, info, data_size);
}
@@ -468,11 +471,42 @@ meter_certificate_read(struct file *filp, struct kobject *kobj,
{
struct device *dev = kobj_to_dev(kobj);
struct sdsi_priv *priv = dev_get_drvdata(dev);
+ int ret;
- return certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
+ ret = mutex_lock_interruptible(&priv->meter_lock);
+ if (ret)
+ return ret;
+
+ ret = certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
+
+ mutex_unlock(&priv->meter_lock);
+
+ return ret;
}
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);
+ int ret;
+
+ ret = mutex_lock_interruptible(&priv->meter_lock);
+ if (ret)
+ return ret;
+
+ priv->control_flags = CTRL_METER_ENABLE_DRAM;
+ ret = certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count);
+
+ mutex_unlock(&priv->meter_lock);
+
+ return ret;
+}
+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)
@@ -503,6 +537,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
@@ -522,7 +557,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;
@@ -725,6 +760,7 @@ static int sdsi_probe(struct auxiliary_device *auxdev, const struct auxiliary_de
priv->dev = &auxdev->dev;
priv->id = auxdev->id;
mutex_init(&priv->mb_lock);
+ mutex_init(&priv->meter_lock);
auxiliary_set_drvdata(auxdev, priv);
/* Get the SDSi discovery table */
diff --git a/drivers/platform/x86/intel/sdsi.h b/drivers/platform/x86/intel/sdsi.h
index 256618eb3136..e20cf279212e 100644
--- a/drivers/platform/x86/intel/sdsi.h
+++ b/drivers/platform/x86/intel/sdsi.h
@@ -18,12 +18,14 @@ struct device;
struct sdsi_priv {
struct mutex mb_lock; /* Mailbox access lock */
+ struct mutex meter_lock;
struct device *dev;
struct intel_vsec_device *ivdev;
struct list_head node;
void __iomem *control_addr;
void __iomem *mbox_addr;
void __iomem *regs_addr;
+ u64 control_flags;
int control_size;
int maibox_size;
int registers_size;
--
2.34.1
next prev parent reply other threads:[~2024-02-01 1:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 1:07 [PATCH 0/8] Intel On Demand: Add netlink interface for SPDM attestation David E. Box
2024-02-01 1:07 ` [PATCH 1/8] platform/x86/intel/sdsi: Set message size during writes David E. Box
2024-02-01 16:49 ` Kuppuswamy Sathyanarayanan
2024-02-08 13:42 ` Ilpo Järvinen
2024-02-08 21:49 ` Kuppuswamy Sathyanarayanan
2024-02-01 1:07 ` [PATCH 2/8] platform/x86/intel/sdsi: Combine read and write mailbox flows David E. Box
2024-02-01 17:31 ` Kuppuswamy Sathyanarayanan
2024-02-01 18:11 ` David E. Box
2024-02-08 13:38 ` Ilpo Järvinen
2024-02-01 1:07 ` [PATCH 3/8] platform/x86/intel/sdsi: Add header file David E. Box
2024-02-08 13:41 ` Ilpo Järvinen
2024-02-08 21:52 ` Kuppuswamy Sathyanarayanan
2024-02-01 1:07 ` [PATCH 4/8] platform/x86/intel/sdsi: Add netlink SPDM transport David E. Box
2024-02-01 9:26 ` Jiri Pirko
2024-02-01 16:42 ` David E. Box
2024-02-01 18:00 ` Jiri Pirko
2024-02-01 1:07 ` [PATCH 5/8] platform/x86/intel/sdsi: Add in-band BIOS lock support David E. Box
2024-02-08 13:52 ` Ilpo Järvinen
2024-02-01 1:07 ` David E. Box [this message]
2024-02-08 14:43 ` [PATCH 6/8] platform/x86/intel/sdsi: Add attribute to read the current meter state Ilpo Järvinen
2024-02-01 1:07 ` [PATCH 7/8] tools: Fix errors in meter_certificate display David E. Box
2024-02-08 14:46 ` Ilpo Järvinen
2024-02-01 1:07 ` [PATCH 8/8] tools: intel_sdsi: Add current meter support David E. Box
2024-02-08 14:52 ` Ilpo Järvinen
2024-02-01 3:49 ` [PATCH 0/8] Intel On Demand: Add netlink interface for SPDM attestation Stephen Hemminger
2024-02-01 16:53 ` Kuppuswamy Sathyanarayanan
2024-02-02 1:42 ` Jakub Kicinski
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=20240201010747.471141-7-david.e.box@linux.intel.com \
--to=david.e.box@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sathyanarayanan.kuppuswamy@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.