Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2243102rbb; Tue, 27 Feb 2024 16:02:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWSFRr3fwwmf+zfyElwRCIo70TDY96dpWGLAVGjl50lHRQTRfTtIpNY6IpPOUy7JeYxvaISX4NuSvnZABENGVwrEjsQxzBn2z2ebPmyJg== X-Google-Smtp-Source: AGHT+IFvzdI8M3PanVma7vtDbEakLp1m097iSRVxcS1PeIV1FwwMTgnwHK5UARNVFb7a8Jzi1Nfl X-Received: by 2002:a05:6a00:1789:b0:6e5:58a5:ceb2 with SMTP id s9-20020a056a00178900b006e558a5ceb2mr1814911pfg.29.1709078565200; Tue, 27 Feb 2024 16:02:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709078565; cv=pass; d=google.com; s=arc-20160816; b=ymTeRrIk5dukoI9cVj9gWMY/aQhT/qApaAPo4qTxSgXUkg/unO7oC56TF8NwF6SDg7 PTqn8VvOD1B5wXcLFoe6uOcXqXdW0En9dul9bQNQMSwDbxtYbanEMgsHyrDBWXTL9QuJ uwaBlCL+qd6aOcNPS5vKzvtuABlxrOkKofc+zAOFLlN6d6EFhqK74swZ83TkVHs69m7P CIPSCkT6Jsekpn3N0G+Tu3IwYJxw5dCzyVv97xJ/6ttHXkqf4YLZWeT1zJdkjP9qJBz0 VpDnVgrPqzr+Hoa7j7bprPKnN8FjRbPPdMZxPk3SraSu1c79nRy0Rsq9nBQnSk9CISaD 9iUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=VKyV+kp8ioT0XJqfV5eLJvP8bag3OU6ulFSGUYN8mcQ=; fh=x4bFVqj5qD52f35ITnpIMR9XPjt+nAjpv5WW2CLFX0Q=; b=Dl+QAfwr5/UFNX42r9FB+OJO0gg2/bbTNfqzxBBQqJ0JqZ2dg/6Pk/Hyn3hIDHlxKG B49tvqDhbmRAROhEUKXH8ZfS7sSMzKEbeLWUfvTeZ7KAL51W3Vx6fb7s2kDSYUzoZoJ/ Lv73uKTGb6KqSaXx81rqVIt2zVvdfj3MELG4Cyp73GQrTcOgyS9b9m4slYNIlHHICkYU z0x62rxFIC0zDxe25MnseWYlykzEG2B8zwNAX1DgEn+M53ByOUf2rTRYksaFe+Qq4305 KDIKR82ZnF964ClYoHrFu6qPKduLsGFxikaL144ltahs/W2kRcRhpAIf2lWj6JI+8Rld jUEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YPO6Qff9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jo35-20020a056a0090a300b006e52cc9c8adsi4337389pfb.71.2024.02.27.16.02.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:02:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YPO6Qff9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 76810284890 for ; Wed, 28 Feb 2024 00:01:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC25E3307B; Wed, 28 Feb 2024 00:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YPO6Qff9" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C579E33CC; Wed, 28 Feb 2024 00:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709078422; cv=none; b=ntw9/8RNIa0wawuXWHJeMbbt0/IquTAdPaARZ/abdm++FVOxw15D5OislvXHhcjsUQsYLzLzi/A9PyBDB7UDVH/pMeAhKAfpJ+EPBj0e6B1y0+D5vPsyS8QubQCDCjZaYX9UQj/llofagaLperv5rFSTzzQAgoJDv74ftz6Kg8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709078422; c=relaxed/simple; bh=H/oVc0/R243WLhuh35k20xoR6ierm4mlpBoLWVy2YYA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kjHkY6Q55jVkp+kExPNeBRyqBKqEa0KONd3ZndLoIShaito6O2myhsngk9zGtsjoHyfu9vWCICHJ5ahGKbM/7UwmssQtjZaZsGK74jc4NjkmjKQq35zfjgMsSLZbbrdl0TTo5qlDxLw4ERg2emcfkDH9DGDv7yOmpUW+9Z+K3zE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YPO6Qff9; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709078421; x=1740614421; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=H/oVc0/R243WLhuh35k20xoR6ierm4mlpBoLWVy2YYA=; b=YPO6Qff9DIGG1P/5TaAa/jFyoxD7X+9fkvBFPkFhTUZ0pP90pkqvrmVj i+flQJhfJry7wvVDU7yGRroEsj6nLY9fjDN9QiVzgobwyxPmyMdvnlJbI jsH/BMC+0sFRFZobnWtQrtLEJmFa2/Jxu70r1AIsjbjdmmVRjo93+pmWB r4ZLRMxEvRmgHYqPlSlpEmeiC5wTTDMfPnSM10xzINJN9q9XOM8DKJ04n zo6HngSz4GQ6u9Rv1wdhebqDSiO5r+65d62yXkk7mMjr5GJqDBCO4okuU hR7uQWyU0ej0KVImY4y+J3exHLcWeElcqPulUfZbowhHW/NL4oHL84Qms w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="25919835" X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="25919835" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 16:00:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,189,1705392000"; d="scan'208";a="7439168" Received: from linux.intel.com ([10.54.29.200]) by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 16:00:17 -0800 Received: from debox1-desk4.lan (unknown [10.251.6.149]) by linux.intel.com (Postfix) with ESMTP id 1231B580D7F; Tue, 27 Feb 2024 16:00:17 -0800 (PST) From: "David E. Box" 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 Message-Id: <20240228000016.1685518-5-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228000016.1685518-1-david.e.box@linux.intel.com> References: <20240228000016.1685518-1-david.e.box@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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