Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86/intel/sdsi: Add attribute to read the current meter state

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>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240411025856.2782476-5-david.e.box@linux.intel.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

David E. Box and committed by
Hans de Goede
46b5e5eb d9a4b2aa

+24 -6
+24 -6
drivers/platform/x86/intel/sdsi.c
··· 68 68 #define CTRL_COMPLETE BIT(6) 69 69 #define CTRL_READY BIT(7) 70 70 #define CTRL_INBAND_LOCK BIT(32) 71 + #define CTRL_METER_ENABLE_DRAM BIT(33) 71 72 #define CTRL_STATUS GENMASK(15, 8) 72 73 #define CTRL_PACKET_SIZE GENMASK(31, 16) 73 74 #define CTRL_MSG_SIZE GENMASK(63, 48) ··· 96 95 struct sdsi_mbox_info { 97 96 u64 *payload; 98 97 void *buffer; 98 + u64 control_flags; 99 99 int size; 100 100 }; 101 101 ··· 252 250 control = FIELD_PREP(CTRL_EOM, 1) | 253 251 FIELD_PREP(CTRL_SOM, 1) | 254 252 FIELD_PREP(CTRL_RUN_BUSY, 1) | 255 - FIELD_PREP(CTRL_PACKET_SIZE, info->size); 253 + FIELD_PREP(CTRL_PACKET_SIZE, info->size) | 254 + info->control_flags; 256 255 writeq(control, priv->control_addr); 257 256 258 257 return sdsi_mbox_poll(priv, info, data_size); ··· 427 424 static BIN_ATTR_WO(provision_cap, SDSI_SIZE_WRITE_MSG); 428 425 429 426 static ssize_t 430 - certificate_read(u64 command, struct sdsi_priv *priv, char *buf, loff_t off, 431 - size_t count) 427 + certificate_read(u64 command, u64 control_flags, struct sdsi_priv *priv, 428 + char *buf, loff_t off, size_t count) 432 429 { 433 430 struct sdsi_mbox_info info = {}; 434 431 size_t size; ··· 444 441 445 442 info.payload = &command; 446 443 info.size = sizeof(command); 444 + info.control_flags = control_flags; 447 445 448 446 ret = mutex_lock_interruptible(&priv->mb_lock); 449 447 if (ret) ··· 476 472 struct device *dev = kobj_to_dev(kobj); 477 473 struct sdsi_priv *priv = dev_get_drvdata(dev); 478 474 479 - return certificate_read(SDSI_CMD_READ_STATE, priv, buf, off, count); 475 + return certificate_read(SDSI_CMD_READ_STATE, 0, priv, buf, off, count); 480 476 } 481 477 static BIN_ATTR_ADMIN_RO(state_certificate, SDSI_SIZE_READ_MSG); 482 478 ··· 488 484 struct device *dev = kobj_to_dev(kobj); 489 485 struct sdsi_priv *priv = dev_get_drvdata(dev); 490 486 491 - return certificate_read(SDSI_CMD_READ_METER, priv, buf, off, count); 487 + return certificate_read(SDSI_CMD_READ_METER, 0, priv, buf, off, count); 492 488 } 493 489 static BIN_ATTR_ADMIN_RO(meter_certificate, SDSI_SIZE_READ_MSG); 490 + 491 + static ssize_t 492 + meter_current_read(struct file *filp, struct kobject *kobj, 493 + struct bin_attribute *attr, char *buf, loff_t off, 494 + size_t count) 495 + { 496 + struct device *dev = kobj_to_dev(kobj); 497 + struct sdsi_priv *priv = dev_get_drvdata(dev); 498 + 499 + return certificate_read(SDSI_CMD_READ_METER, CTRL_METER_ENABLE_DRAM, 500 + priv, buf, off, count); 501 + } 502 + static BIN_ATTR_ADMIN_RO(meter_current, SDSI_SIZE_READ_MSG); 494 503 495 504 static ssize_t registers_read(struct file *filp, struct kobject *kobj, 496 505 struct bin_attribute *attr, char *buf, loff_t off, ··· 535 518 &bin_attr_registers, 536 519 &bin_attr_state_certificate, 537 520 &bin_attr_meter_certificate, 521 + &bin_attr_meter_current, 538 522 &bin_attr_provision_akc, 539 523 &bin_attr_provision_cap, 540 524 NULL ··· 555 537 if (!(priv->features & SDSI_FEATURE_SDSI)) 556 538 return 0; 557 539 558 - if (attr == &bin_attr_meter_certificate) 540 + if (attr == &bin_attr_meter_certificate || attr == &bin_attr_meter_current) 559 541 return (priv->features & SDSI_FEATURE_METERING) ? 560 542 attr->attr.mode : 0; 561 543