From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 BF65253F6AE; Tue, 13 Oct 2026 19:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919792; cv=none; b=pi/psj/m95gHVVeaUpujZ/NP04J0PX2CaU1L3ZF3e94NI9C4OFTJTCPS9cZ5mZ2eXfQAulXhJKgUSNDOYzu4EWp7ElqR/Oia3QJEvuz1hTxZUTgZiYPyj3YA8xROLmGuFrUrqiM1YVZSlal8L4BL4qxF5aTs4Rpe6qwFlmjzm5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919792; c=relaxed/simple; bh=R6dsZrhu9NgBwhhSFSnog9rmIHrIC0UuWb7KJIsDK+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bq247vmvt3UdGt8RUOQjWbr2+SZ9V0Jtd//go4LpPG6cgy161RB+nRtcardQekGHqHFFkDV9ROFPHLfU+fFJzRZg+uNSEzPKpE/goRE/p8A9C6a/0SlDptn/93fijtlzBKB4+S2rLv158hImhyokPRATdW2GBp4dXYUJ1Trm2i4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QVyJOQm5; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QVyJOQm5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919789; x=1823455789; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R6dsZrhu9NgBwhhSFSnog9rmIHrIC0UuWb7KJIsDK+E=; b=QVyJOQm54i/xE2EelrZ//cUcbBJesdiYMNwGyUDACNld69FUXZ3sDXPz GgfmNgJBHPvngdOtmxSkuXZp+1jQnOpcfLxavUSMUr1IttbRNKE1xiLqF JGqRoL72fG98dS6x8UlxfqVQKxksoYHPMW9Fj8YDti0tsCNEAOha8pBeb p8XXRhW33LJcBqaFoR4gay4+C0SUblDeQCWX9d3ILVl4XupaQ+hB6A8m5 Q1fan18mO/8gX7ZLAnDDLx8vWbN1JYXQSRNGl2Dfn8ZbHUGQrelAiVL4O KQamdpYilpEUvYeRd07pAdMYUPutKWbJuI6UahCk6yL8/s4NjqESDm0pv Q==; X-CSE-ConnectionGUID: HJAqYcsHQd264fD9LsNxHg== X-CSE-MsgGUID: zKjHCdCkQzq2mYosCfjrdg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544108" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544108" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 X-CSE-ConnectionGUID: 4g/LgQhVSK+VGBq5ekVu0w== X-CSE-MsgGUID: 9qaBn0yoRfmMgR1GFv6ntA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167655" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 01/20] platform/x86/intel/tpmi: Use static strings for the feature device names Date: Tue, 13 Oct 2026 12:29:16 -0700 Message-ID: <20261013192935.2243291-2-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" tpmi_create_device() builds the auxiliary device name in an on-stack buffer and hands it to intel_vsec_add_aux(), which stores the pointer in auxdev->name without copying the string. The auxiliary device outlives tpmi_create_device(), so auxdev->name is left pointing into a stack frame that has already been torn down. Nothing dereferences auxdev->name after intel_vsec_add_aux() returns today: auxiliary_device_init() only checks it for NULL and both dev_set_name() calls copy into dev->kobj.name, while driver matching and the modalias use dev_name() instead. So this is a latent problem rather than a live one, but the auxiliary bus expects the name to outlive the device, and the other intel_vsec_add_aux() caller already passes a string literal. Convert intel_tpmi_name() into a lookup of a static array of string literals that already include the "tpmi-" prefix, and pass its return value straight to intel_vsec_add_aux(). Using a static array instead of a switch statement makes the lifetime of the returned strings obvious: they are valid for as long as the module is loaded. The snprintf() along with its on-stack buffer and length define are no longer needed. The resulting device names are unchanged, so the feature drivers keep matching on "intel_vsec.tpmi-" as before. No functional change intended. Reviewed-by: Andy Shevchenko Reviewed-by: Srinivas Pandruvada Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 41 +++++++++++++------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index 0153dd57838e..9b2bd0c8cbe2 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -47,6 +47,7 @@ */ =20 #include +#include #include #include #include @@ -579,33 +580,31 @@ static void tpmi_set_control_base(struct auxiliary_de= vice *auxdev, tpmi_info->tpmi_control_mem =3D mem; } =20 +/* + * The TPMI IDs are sparse, so the unused entries are left NULL and are + * rejected by the caller like any other unsupported feature. + */ +static const char * const intel_tpmi_names[] =3D { + [TPMI_ID_RAPL] =3D "tpmi-rapl", + [TPMI_ID_PEM] =3D "tpmi-pem", + [TPMI_ID_UNCORE] =3D "tpmi-uncore", + [TPMI_ID_SST] =3D "tpmi-sst", + [TPMI_ID_PLR] =3D "tpmi-plr", +}; + static const char *intel_tpmi_name(enum intel_tpmi_id id) { - switch (id) { - case TPMI_ID_RAPL: - return "rapl"; - case TPMI_ID_PEM: - return "pem"; - case TPMI_ID_UNCORE: - return "uncore"; - case TPMI_ID_SST: - return "sst"; - case TPMI_ID_PLR: - return "plr"; - default: + if (id >=3D ARRAY_SIZE(intel_tpmi_names)) return NULL; - } -} =20 -/* String Length for tpmi-"feature_name(upto 8 bytes)" */ -#define TPMI_FEATURE_NAME_LEN 14 + return intel_tpmi_names[id]; +} =20 static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, struct intel_tpmi_pm_feature *pfs, u64 pfs_start) { struct intel_vsec_device *vsec_dev =3D tpmi_info->vsec_dev; - char feature_id_name[TPMI_FEATURE_NAME_LEN]; struct intel_vsec_device *feature_vsec_dev; struct tpmi_feature_state feature_state; struct resource *res, *tmp; @@ -634,8 +633,6 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, feature_vsec_dev->num_resources =3D pfs->pfs_header.num_entries; res =3D feature_vsec_dev->resource; =20 - snprintf(feature_id_name, sizeof(feature_id_name), "tpmi-%s", name); - for (i =3D 0, tmp =3D res; i < pfs->pfs_header.num_entries; i++, tmp++) { u64 entry_size_bytes =3D pfs->pfs_header.entry_size * sizeof(u32); =20 @@ -654,9 +651,11 @@ static int tpmi_create_device(struct intel_tpmi_info *= tpmi_info, * delete is required on error or on module unload. * feature_vsec_dev and res memory are also freed as part of * device deletion. + * + * "name" must outlive the auxiliary device, as the auxiliary bus + * stores the pointer rather than a copy of the string. */ - return intel_vsec_add_aux(&vsec_dev->auxdev.dev, - feature_vsec_dev, feature_id_name); + return intel_vsec_add_aux(&vsec_dev->auxdev.dev, feature_vsec_dev, name); } =20 static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 2865E53FD2A; Tue, 13 Oct 2026 19:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919795; cv=none; b=LZzXoKsW19WisCSKnB7tKso5Laqg7dhBKfEWtCjMihMzz0Ld4N+/xqkaL/vjJ79kMFKoxj4QLUzpUv2aldzJLVMHWJ5CX+JIt++L27ir4lnjXqUy6yJpAf8/2KAbptM/P6kuJTqsYdjEr1TCLBMgly+cy0ifX3g8zY+4cSW43Tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919795; c=relaxed/simple; bh=nBwY46Hr8XhQplLC+jYrfeYsbLTCkXFa9xpKWrHXq7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQFWXehL5IUCkLALLIa3rzdoOYQWPBiIz9VW23+Hs/nbFYlcLccJeRmiomziu/nP7Gusv9TrMrNOwqLAZTwHEzwID+MHfnZEk5K9TO1y04//7RcjpiFIXXz+9KAkyPSVGTqp0UJmSk6WY79eGc9Hs3CHq+yNixDXsaL0pAl8aeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DU6igb52; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DU6igb52" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919793; x=1823455793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nBwY46Hr8XhQplLC+jYrfeYsbLTCkXFa9xpKWrHXq7E=; b=DU6igb52yb5lKze9jd56h+Z3fc0NXX9b4mJ6dF4Xj6zOT8fvoLIx2TjF oAU+ANTQN3rXuJbAf8/c813YPOiU2dWg8ZgnEiiXLfJyJbekzza0mbJZs rT1NmVg5bGs2hYqSW/sruaUOrCylqTOd7o2/ECVOtwcILp2A8Vgp9rt0T 3kvbF+DUVK0Ambtf37RRttC896dKswwHBNREZygAQYVrTBBeM/zFyR97p QIEQvVDGmXRi8zjflCYmzLDAHsM7N4vFca98t3qNExs2JqOJ0CLEFfFhK au+lHsG2RoGXLco7GaSjjDTcIhVxlmVYOdw4CPLvw4ju8rWB4nN2UG+FY Q==; X-CSE-ConnectionGUID: wzDKcjxBR8e/sU83BjVoWQ== X-CSE-MsgGUID: jJuuS7dgTs2++SSK4Xo4cA== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544111" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544111" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 X-CSE-ConnectionGUID: UMg0eDvaQGyvEjfp2tXx6w== X-CSE-MsgGUID: pHuNue/tTMyY1jxXtK5DKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167658" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/20] platform/x86/intel/vsec: Pass a struct device to intel_vsec_set_mapping() Date: Tue, 13 Oct 2026 12:29:17 -0700 Message-ID: <20261013192935.2243291-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" intel_vsec_set_mapping() takes an intel_vsec_device pointer and only reads the struct device out of it. A caller that has the device but no intel_vsec_device would have to build one just to make this call. Pass the struct device instead. TPMI is the only user of this interface and it is being prepared for enumeration methods other than a PCI VSEC capability, where no intel_vsec_device exists. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec.c | 7 +++---- drivers/platform/x86/intel/vsec_tpmi.c | 2 +- include/linux/intel_vsec.h | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel= /vsec.c index 5ab2215fdd7f..f33eea6e6284 100644 --- a/drivers/platform/x86/intel/vsec.c +++ b/drivers/platform/x86/intel/vsec.c @@ -717,15 +717,14 @@ static int intel_vsec_pci_probe(struct pci_dev *pdev,= const struct pci_device_id return intel_vsec_pci_init(pdev); } =20 -int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info, - struct intel_vsec_device *vsec_dev) +int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info, struct devi= ce *dev) { struct vsec_priv *priv; =20 - if (!dev_is_pci(vsec_dev->dev)) + if (!dev_is_pci(dev)) return -ENODEV; =20 - priv =3D pci_get_drvdata(to_pci_dev(vsec_dev->dev)); + priv =3D pci_get_drvdata(to_pci_dev(dev)); if (!priv) return -EINVAL; =20 diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index 9b2bd0c8cbe2..edeae3fd23a1 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -799,7 +799,7 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) if (ret) return ret; =20 - ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, vsec_dev); + ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, vsec_dev->dev); if (ret) return ret; } diff --git a/include/linux/intel_vsec.h b/include/linux/intel_vsec.h index 843cda8f8644..4d9c9776ca81 100644 --- a/include/linux/intel_vsec.h +++ b/include/linux/intel_vsec.h @@ -221,8 +221,7 @@ static inline struct intel_vsec_device *auxdev_to_ivdev= (struct auxiliary_device #if IS_ENABLED(CONFIG_INTEL_VSEC) int intel_vsec_register(struct device *dev, const struct intel_vsec_platform_info *info); -int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info, - struct intel_vsec_device *vsec_dev); +int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_info, struct devi= ce *dev); struct oobmsm_plat_info *intel_vsec_get_mapping(struct pci_dev *pdev); #else static inline int intel_vsec_register(struct device *dev, @@ -231,7 +230,7 @@ static inline int intel_vsec_register(struct device *de= v, return -ENODEV; } static inline int intel_vsec_set_mapping(struct oobmsm_plat_info *plat_inf= o, - struct intel_vsec_device *vsec_dev) + struct device *dev) { return -ENODEV; } --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 78BB153FD40; Tue, 13 Oct 2026 19:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919797; cv=none; b=e3oizF0Okf1Yh4dQwtPjZk6nF6xi20ZRiIBhxDFhtIcG5CW1oN4kO39iXERdSn01RD8s7giA5ywf9V8/UA5IDBJOYD3Lh+wFyOJ/HPcA7SXyydFQmcQROpArjWLgGOBH7dqo+Pj0shlCgJfMDhdkBqKLDbonogCse3UNaLgYnPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919797; c=relaxed/simple; bh=7bt6GgaH22XHsrurKLDr1PCvL8fb5Dc0kwTEPoHgn60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vd3/5rsyN3JDHPzj7Lg5u7CaKxhgpAsu+nFdpIsqC2oZSrU4GHUd4o3bii8+f751LjBnXTOwX5YmyFhWb+5XHZPWwohiOVRuvFXoJnCXyUW0t8Zv/miLOApq6NB33i/duyzodNCb+Y/P4t0G9Bexjz/i+crToCkgu/ZOmVLrjes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Xe5nHb5o; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Xe5nHb5o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919795; x=1823455795; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7bt6GgaH22XHsrurKLDr1PCvL8fb5Dc0kwTEPoHgn60=; b=Xe5nHb5oOOtiHe3PjvCOf50zY761mIDHtSB8kQ6wNXvIHDVrD4K09cMC 7KbsHHywl+iMqA2BujdE9dKRL541fbLfOJARgD7V/P3W2wn43+9Lf8ZeJ Ig0vomJQGHC18qKZAL3XwrZgkaSeKYDNpsiFewFCA5ro/YQX68zubHO3A F+N+eA+ajYwUzAsGdkBZ7AZSdhaPZHjkIfhDKmQu1dBUaiXmfrekX8WUN YjPGEbyNaAULWQiOx3nrlc9Xarm/t8Ns2ARNUGK2WR5XDuB/yBteMBd0t 6CZiP3YDFEtYlxg/mbb/ZVsClFWYMMW/WRAfZhXAR7jm+ywOLXoSVq4lF A==; X-CSE-ConnectionGUID: fl9TNEoKQTK+r5ZkTswRpA== X-CSE-MsgGUID: 7xfQbbuTQU+gRl1BkFmGEw== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544113" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544113" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 X-CSE-ConnectionGUID: xUUubSxfTASlKmnE9gQAAA== X-CSE-MsgGUID: t5ay1jeOTheH+XjoUXv7mQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167661" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 03/20] platform/x86/intel/tpmi: Remove unused vsec_dev from intel_tpmi_pm_feature Date: Tue, 13 Oct 2026 12:29:18 -0700 Message-ID: <20261013192935.2243291-4-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" The intel_vsec_device pointer stored in every PFS entry is never read back. Remove the field and its assignment. No functional change. Reviewed-by: Andy Shevchenko Reviewed-by: Srinivas Pandruvada Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index edeae3fd23a1..fdca799f7cf9 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -93,14 +93,12 @@ struct intel_tpmi_pfs_entry { * @vsec_offset: Starting MMIO address for this feature in bytes. Essentia= lly * this offset =3D "Address" from VSEC header + PFS Capability * offset for this feature entry. - * @vsec_dev: Pointer to intel_vsec_device structure for this TPMI device * * Represents TPMI instance information for one TPMI ID. */ struct intel_tpmi_pm_feature { struct intel_tpmi_pfs_entry pfs_header; u64 vsec_offset; - struct intel_vsec_device *vsec_dev; }; =20 /** @@ -767,7 +765,6 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) int size, ret; =20 pfs =3D &tpmi_info->tpmi_features[i]; - pfs->vsec_dev =3D vsec_dev; =20 res =3D &vsec_dev->resource[i]; if (!res) --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 071A154145F; Tue, 13 Oct 2026 19:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919798; cv=none; b=JxqwxOxSbDp01YNJJ4YKcY9yzETBDQrPC6uN1tjP5gQ1wV37sCig6a5Iwq5r6djoXJd3biQH1/wjmLot73oeZ2/FZOuVryma2+767QAfiRd7AGvMNGAoQEQhFQkfsawmAs0vBHcrFmewFII+9OgFmmYmjGXUexZr3sORQno3oGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919798; c=relaxed/simple; bh=xP6omJUzOTsdefm8xW7u8ghOXXFftXaatOunE+Cb2U8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gd7Kfms2a51KnxVVTTCGBTQ9ULpoVvS+9dLbT3g+edIxQtOXRZ14J+IZakjJ3KOepSYLhPasYB2GB/1LU0OgOnLsRwTKOrWKFe5zLzJxz/pLPgOkKM8hDayZDYFaSnKG2N62uHluV3tR8vRGfmbc8tG5rGaIGJ4gjaWvu+QJf4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lu28LokD; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lu28LokD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919796; x=1823455796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xP6omJUzOTsdefm8xW7u8ghOXXFftXaatOunE+Cb2U8=; b=lu28LokDtjKzH4D+7CDgvzYrboXXaFvpTxt7Vd8DtIcp/4unNrXoETrS 7fnhSSHwDTvQU99AUohvhQgnxZT+hoM0Im7LMdcfO7FxB9h9PS9yymcBZ /BXyJlCV8jJ6x9Cbs/4ST3y3uKXGksZlS1GYyTTGelhksvnIJsfMbsFjj d/hMKAzdq7buY/xLg6vsJhVMbeHsrDvgfZLYZs1auT2V2ftBE1W7sLExs sogknTEg8fSIfE73SViDpAoV06ZisIfAUXlMuvOhuAQDiLpeZ/ZeTwApn dzOaRGcn3dg3uQ7lhNSBGz9SzpZgj8AWQsI/q4wejc9OvMvx0tJorNqVa g==; X-CSE-ConnectionGUID: LtfbtF0GQl22GXVYCIEXmw== X-CSE-MsgGUID: u5ZoVioZRuCEFSTG+F5cXg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544115" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544115" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 X-CSE-ConnectionGUID: 01SOE0YRRoq/lWRrb9w29A== X-CSE-MsgGUID: C5bxwcs3T9ekLeIC2EHF3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167665" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 04/20] platform/x86/intel/tpmi: Get tpmi_info directly from the parent device Date: Tue, 13 Oct 2026 12:29:19 -0700 Message-ID: <20261013192935.2243291-5-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" tpmi_get_feature_status() and tpmi_get_debugfs_dir() are called by the TPMI feature drivers with their own auxiliary device. Both convert the parent device into an intel_vsec_device and then read the driver data of the auxiliary device it was derived from, which is the parent device they started with. Read the driver data from the parent device directly. Apart from being shorter, this drops an assumption. dev_to_ivdev() is a container_of(), so it only holds while the device the TPMI driver binds to is an auxiliary device created by the Intel VSEC driver. Another enumeration method binds to a different kind of device and the cast would hand out a bogus intel_vsec_device. The driver data is set on that device in either case. The TPMI feature devices are not affected. They remain intel_vsec_device instances allocated by the TPMI driver, since the auxiliary bus is how the feature drivers are reached and not a property of the enumeration. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index fdca799f7cf9..d254dc6a4d0d 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -356,8 +356,7 @@ static int tpmi_read_feature_status(struct intel_tpmi_i= nfo *tpmi_info, int featu int tpmi_get_feature_status(struct auxiliary_device *auxdev, int feature_id, bool *read_blocked, bool *write_blocked) { - struct intel_vsec_device *intel_vsec_dev =3D dev_to_ivdev(auxdev->dev.par= ent); - struct intel_tpmi_info *tpmi_info =3D auxiliary_get_drvdata(&intel_vsec_d= ev->auxdev); + struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); struct tpmi_feature_state feature_state; int ret; =20 @@ -374,8 +373,7 @@ EXPORT_SYMBOL_NS_GPL(tpmi_get_feature_status, "INTEL_TP= MI"); =20 struct dentry *tpmi_get_debugfs_dir(struct auxiliary_device *auxdev) { - struct intel_vsec_device *intel_vsec_dev =3D dev_to_ivdev(auxdev->dev.par= ent); - struct intel_tpmi_info *tpmi_info =3D auxiliary_get_drvdata(&intel_vsec_d= ev->auxdev); + struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); =20 return tpmi_info->dbgfs_dir; } --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 B386853FD3C; Tue, 13 Oct 2026 19:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919802; cv=none; b=c61fORPhzLy4DHa9q4OOCNgHwrFIpoVyPjAi3KoWl0vnwoe2WXsSLF6Cs/m/7fhgVy6U/UEdDCoMeQHBJkeTvIZkfe8gEwr7DcYPDPz+A0NZHUSF2sjcix4BHH5qIBo/wIWKBmPAd74SZEbV60424OnwBOhlGF9Wkj9+E7eHMxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919802; c=relaxed/simple; bh=WyegeQCkEhqSGR+PqPySOEHhsVjJexyrZ8QpsMEGN2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Efz8slOJBY/WkGi3PjQZBj2NoHXPNj206aHWmAthSpCEaX485qx8AUOVXpuzmV5xvvEV9gIvPAlZM64c6yy1q2fucANbPsgExh5c2gxRXkuTKfRUcmTr+ln3YRH7kfkgO+jA0l7YT/Lg73fW/Ncr1kReu+aX/vqkOM/n6pyv4MA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=naIwRLAU; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="naIwRLAU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919796; x=1823455796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WyegeQCkEhqSGR+PqPySOEHhsVjJexyrZ8QpsMEGN2U=; b=naIwRLAULMSQofog3zNvtcUGtcsyjiDa1WacfOK2D7ghmxFp26hknzAE COKDFHn6gW58JjWxMqLuCI8Qe9USlWZionL38KaEO0zRStAI3TmJiYkrQ vfUn3W0jT5N3VBBqMzLQqBUsHHReK+B8MlC1NfO405zBckSOTP8vLjTg5 15YCVfuM7PPQCCJtaGTTGQsRY9B8SsHhHyNYHwcJI1OsB4BVo9j99ckq8 aDhH/0/PVTILxGCO6Je0bhLrbGMUXQX+lr/Zs6uxn9GSU0NVGFo0n2NG7 laklSLsEJSHIftw0vCMEmLu9kFagmcU78vROALh2EWp5Cz9v0PDMjwI/z Q==; X-CSE-ConnectionGUID: Il/YNDYBR6yRUW5UKGae2A== X-CSE-MsgGUID: t87cyYOsQzK1ftfDyN8P0w== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544117" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544117" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:48 -0700 X-CSE-ConnectionGUID: 9Ru/8ky3TeKeepszR4D2dw== X-CSE-MsgGUID: Prn92MRpQ8+Yhn0vK6OzLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167668" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 05/20] platform/x86/intel/tpmi: Keep the feature resources in intel_tpmi_info Date: Tue, 13 Oct 2026 12:29:20 -0700 Message-ID: <20261013192935.2243291-6-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" The PFS walk and tpmi_create_devices() go back to the intel_vsec_device for the MMIO resource array and its count, although the count is already cached in intel_tpmi_info. Cache the resource array as well and use it everywhere. The array belongs to the enumerating device and outlives the TPMI instance, so holding a pointer to it is safe. Fewer places need an intel_vsec_device, which enumeration methods other than PCI VSEC do not have. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index d254dc6a4d0d..b462fd0319e5 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -110,6 +110,7 @@ struct intel_tpmi_pm_feature { * @plat_info: Stores platform info which can be used by the client drive= rs * @tpmi_control_mem: Memory mapped IO for getting control information * @dbgfs_dir: debugfs entry pointer + * @resource: Array of feature_count MMIO resources, one per PFS entry * * Stores the information for all TPMI devices enumerated from a single PC= I device. */ @@ -121,6 +122,7 @@ struct intel_tpmi_info { struct oobmsm_plat_info plat_info; void __iomem *tpmi_control_mem; struct dentry *dbgfs_dir; + struct resource *resource; }; =20 /** @@ -656,10 +658,9 @@ static int tpmi_create_device(struct intel_tpmi_info *= tpmi_info, =20 static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) { - struct intel_vsec_device *vsec_dev =3D tpmi_info->vsec_dev; int ret, i; =20 - for (i =3D 0; i < vsec_dev->num_resources; i++) { + for (i =3D 0; i < tpmi_info->feature_count; i++) { ret =3D tpmi_create_device(tpmi_info, &tpmi_info->tpmi_features[i], tpmi_info->pfs_start); /* @@ -748,15 +749,16 @@ static int intel_vsec_tpmi_init(struct auxiliary_devi= ce *auxdev) =20 tpmi_info->vsec_dev =3D vsec_dev; tpmi_info->feature_count =3D vsec_dev->num_resources; + tpmi_info->resource =3D vsec_dev->resource; tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; =20 - tpmi_info->tpmi_features =3D devm_kcalloc(&auxdev->dev, vsec_dev->num_res= ources, + tpmi_info->tpmi_features =3D devm_kcalloc(&auxdev->dev, tpmi_info->featur= e_count, sizeof(*tpmi_info->tpmi_features), GFP_KERNEL); if (!tpmi_info->tpmi_features) return -ENOMEM; =20 - for (i =3D 0; i < vsec_dev->num_resources; i++) { + for (i =3D 0; i < tpmi_info->feature_count; i++) { struct intel_tpmi_pm_feature *pfs; struct resource *res; u64 res_start; @@ -764,7 +766,7 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) =20 pfs =3D &tpmi_info->tpmi_features[i]; =20 - res =3D &vsec_dev->resource[i]; + res =3D &tpmi_info->resource[i]; if (!res) continue; =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 9FF8F541E4D; Tue, 13 Oct 2026 19:29:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919800; cv=none; b=u2ixcBzslHa5D4x8t+Kvqpg4ZXT655B3EJJdynvj1jnv+qGPUFXsDB1WbR4rgtSebKdyMKBkjDJB57+sQjic+sh1XQIglBX1q+fuwlBKds2oBDjiCqevYxGt4ZmUSNDap5T9ZutV7tJCEPdgPAqpJkC5val4eApVk2hOoBudcv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919800; c=relaxed/simple; bh=/85pcJApOiJt8kQtXJRubP++w6Kanv0+/edmXVRkFIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aWbTobjc5WzRWY7BeMMy+yMDQItNHzBZIu70QaDsI7mvAPIBH18fHcnjcZyq3umoTJu3cxItSasgABhexBhUKyH54XnQ4QXtsajPJ8d5X0QFj/8Ssh6nvqzwWNDs1jwy5hvV0WncbO6lgeknsNtESfYvBBd0faH0gqXZaaG+twY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HGT3mqJ4; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HGT3mqJ4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919797; x=1823455797; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/85pcJApOiJt8kQtXJRubP++w6Kanv0+/edmXVRkFIk=; b=HGT3mqJ4MyuMaodWTRovKlSkGWY/gS9K72+p8GmtChmkXEc5RKt14V7w mwaaN9CDZqdNOJpA32ULaq7Zd7h3HVkzKCmFSNn8MKD2d9l3dOqgeoaQf ZnYBV0h3lLdpLHZi6he41XQR6RCWESc+HscGDvgceH9mwZbb/4/hcRb0v U1O5c/S7pfl2pCKX9RgSfsbBc1McXCWgu6yMTLpmWDUgPJMGM/hvuWXuj 4eRbwkhgBbiBIQ42U+ot2Ej+jpbAe+V2OCaXgfKrKifZL0Kp69pzhQT1B CpSQLEoTmRO0BJunH4Bte+Bb34lSRAzl6JuWf2UzxHP3ZePmmBPNbhWtS Q==; X-CSE-ConnectionGUID: e1A0PZsFRmysumF7HKKpjQ== X-CSE-MsgGUID: RUChPdCkQOOJPRsO5dx6MQ== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544119" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544119" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: ONphwuhPQm2vSKUfDkMEKQ== X-CSE-MsgGUID: 2g4Pb/lDS5O4y7J4DZ7Qwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167673" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 06/20] platform/x86/intel/tpmi: Describe a TPMI instance by its two devices Date: Tue, 13 Oct 2026 12:29:21 -0700 Message-ID: <20261013192935.2243291-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" The intel_vsec_device pointer in intel_tpmi_info is by now only used to reach two devices, the device the TPMI driver is bound to and the device TPMI was enumerated from. Store those two directly and call them tpmi_dev and parent. The devm allocations, the driver data and the TPMI feature devices all hang off tpmi_dev. The parent device names the debugfs directory, is recorded in every TPMI feature device so that the enumerating bus can find those devices again during PCI error recovery, and is the device intel_vsec_set_mapping() registers the mapping for. Both are assigned once during init and used everywhere below it, so intel_tpmi_info no longer refers to an intel_vsec_device. tpmi_to_dev() went away with its only user. There is no functional change, tpmi_dev is &auxdev->dev and parent is vsec_dev->dev, which is what the affected call sites used before. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 29 ++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index b462fd0319e5..f3cd8aa30af0 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -104,25 +104,33 @@ struct intel_tpmi_pm_feature { /** * struct intel_tpmi_info - TPMI information for all IDs in an instance * @tpmi_features: Pointer to a list of TPMI feature instances - * @vsec_dev: Pointer to intel_vsec_device structure for this TPMI device * @feature_count: Number of TPMI of TPMI instances pointed by tpmi_featur= es * @pfs_start: Start of PFS offset for the TPMI instances in this device * @plat_info: Stores platform info which can be used by the client drive= rs * @tpmi_control_mem: Memory mapped IO for getting control information * @dbgfs_dir: debugfs entry pointer * @resource: Array of feature_count MMIO resources, one per PFS entry + * @tpmi_dev: Device this TPMI instance is bound to. It backs the devm + * allocations, holds this structure as its driver data and + * the TPMI feature devices are created under it. + * @parent: Device this TPMI instance was enumerated from. It names + * the debugfs directory and becomes intel_vsec_device::dev + * of every TPMI feature device, so that the enumerating bus + * can find them again, for example during PCI error + * recovery. * * Stores the information for all TPMI devices enumerated from a single PC= I device. */ struct intel_tpmi_info { struct intel_tpmi_pm_feature *tpmi_features; - struct intel_vsec_device *vsec_dev; int feature_count; u64 pfs_start; struct oobmsm_plat_info plat_info; void __iomem *tpmi_control_mem; struct dentry *dbgfs_dir; struct resource *resource; + struct device *tpmi_dev; + struct device *parent; }; =20 /** @@ -534,14 +542,12 @@ static const struct file_operations mem_write_ops =3D= { .release =3D single_release, }; =20 -#define tpmi_to_dev(info) ((info)->vsec_dev->dev) - static void tpmi_dbgfs_register(struct intel_tpmi_info *tpmi_info) { char name[64]; int i; =20 - snprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_to_dev(tpmi_info))); + snprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); tpmi_info->dbgfs_dir =3D debugfs_create_dir(name, NULL); =20 debugfs_create_file("pfs_dump", 0444, tpmi_info->dbgfs_dir, tpmi_info, &t= pmi_pfs_dbg_fops); @@ -570,7 +576,7 @@ static void tpmi_set_control_base(struct auxiliary_devi= ce *auxdev, if (!size) return; =20 - mem =3D devm_ioremap(&auxdev->dev, pfs->vsec_offset, size); + mem =3D devm_ioremap(tpmi_info->tpmi_dev, pfs->vsec_offset, size); if (!mem) return; =20 @@ -602,7 +608,6 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, struct intel_tpmi_pm_feature *pfs, u64 pfs_start) { - struct intel_vsec_device *vsec_dev =3D tpmi_info->vsec_dev; struct intel_vsec_device *feature_vsec_dev; struct tpmi_feature_state feature_state; struct resource *res, *tmp; @@ -639,7 +644,7 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, tmp->flags =3D IORESOURCE_MEM; } =20 - feature_vsec_dev->dev =3D vsec_dev->dev; + feature_vsec_dev->dev =3D tpmi_info->parent; feature_vsec_dev->priv_data =3D &tpmi_info->plat_info; feature_vsec_dev->priv_data_size =3D sizeof(tpmi_info->plat_info); feature_vsec_dev->ida =3D &intel_vsec_tpmi_ida; @@ -653,7 +658,7 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, * "name" must outlive the auxiliary device, as the auxiliary bus * stores the pointer rather than a copy of the string. */ - return intel_vsec_add_aux(&vsec_dev->auxdev.dev, feature_vsec_dev, name); + return intel_vsec_add_aux(tpmi_info->tpmi_dev, feature_vsec_dev, name); } =20 static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) @@ -747,7 +752,8 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) if (!tpmi_info) return -ENOMEM; =20 - tpmi_info->vsec_dev =3D vsec_dev; + tpmi_info->tpmi_dev =3D &auxdev->dev; + tpmi_info->parent =3D vsec_dev->dev; tpmi_info->feature_count =3D vsec_dev->num_resources; tpmi_info->resource =3D vsec_dev->resource; tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; @@ -796,7 +802,8 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) if (ret) return ret; =20 - ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, vsec_dev->dev); + ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, + tpmi_info->parent); if (ret) return ret; } --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 161BB541E61; Tue, 13 Oct 2026 19:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919801; cv=none; b=hImmQGE+Z1Ghf/3vheqi5Z27Pb0AtLRmeQrsCYO82XwXze2lV9fQh7IgLOI4V4KnjdmP2uMTEnQaZNBJawVeCNNoAj9UQBxA8xN6e7fidPymxgo/hoQWTwUdiZOYo1xh+Zdm+KKRxnoiyMiF5ZWtAbcS3eR96Ud6PX78/Zb0qpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919801; c=relaxed/simple; bh=qczTg7GjWnxGdZ8gTIElaBsCzVknAhCBjadcl+ID/oE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9awgHKnZNPQBpocUM4qmUGpOc6rY/j65jNMf0snleq2H0xodOfz33d8yoJkpzAav8RFfN4GHKUJNsI3SKXzjLW0dqFYYK5HSu62DRDmLgQn27tvUNoqjstYQkYKNMpGVm9LZkRx5nM80/bM5Lhlq9ie9Y18Gn1BtbqXwO18MVY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Z03k4UhP; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z03k4UhP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919799; x=1823455799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qczTg7GjWnxGdZ8gTIElaBsCzVknAhCBjadcl+ID/oE=; b=Z03k4UhPpdEOB1P7enu3A/EcYZtD+TPNTCIXYgGFXbuf54oc9hyAFPty XqP5D9W1TVT82fUwUBI7dZwDZvi8IENw2Spcz9OUEx1q8p4ZOqlthP+o/ WbYPzM/nYxWg0Q7Nqf8xhh+aQVSVpgBHGD020kAi3V4xWM45z4XxhLKIb ZPGrgimufS3pbxRMgEJGwT/1m6LD5MWy8lHFm41/3Aj12d2igthZfRYh2 Wdw9CzyQRPzqe4btdMXEqMSBtfimIgHu6DNu3+GhPdQZCwz+CQvOD1+/B o6zTnTrgyJZqVDChXE+zSOdK73nUrD3jcWuOUeElLdskJf3IJEHW6SHl+ A==; X-CSE-ConnectionGUID: 24DAHdORT6GhoPLO3x8o6A== X-CSE-MsgGUID: obqtJhb3ThK0DnQPVXRoRQ== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544122" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544122" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: S5ic9OpzTn6Rry4Dfrk4lw== X-CSE-MsgGUID: r3Jo0HGjTqmKY/HXrDh9Og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167676" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 07/20] platform/x86/intel/tpmi: Drop unused arg from tpmi_set_control_base() Date: Tue, 13 Oct 2026 12:29:22 -0700 Message-ID: <20261013192935.2243291-8-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" tpmi_set_control_base() takes the device for its devm_ioremap() from tpmi_info->tpmi_dev, so the auxiliary device argument is unused. Remove it. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index f3cd8aa30af0..f1dfe2b23c9c 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -565,8 +565,7 @@ static void tpmi_dbgfs_register(struct intel_tpmi_info = *tpmi_info) } } =20 -static void tpmi_set_control_base(struct auxiliary_device *auxdev, - struct intel_tpmi_info *tpmi_info, +static void tpmi_set_control_base(struct intel_tpmi_info *tpmi_info, struct intel_tpmi_pm_feature *pfs) { void __iomem *mem; @@ -809,7 +808,7 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) } =20 if (pfs->pfs_header.tpmi_id =3D=3D TPMI_CONTROL_ID) - tpmi_set_control_base(auxdev, tpmi_info, pfs); + tpmi_set_control_base(tpmi_info, pfs); } =20 tpmi_info->pfs_start =3D pfs_start; --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 6452C541E78; Tue, 13 Oct 2026 19:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919812; cv=none; b=aeUkKSBBX4Wa+fsLpfYtWW9r6qARrwyKugnYYvKRwme3uVup+I5lGPISikS5RgEIYOQCP/GBWW/kqKAVIVSOtu9jKuxk7mYjmzyKEOVNoDUGvC+WbhGMJYalJow4YuWPqf20Ot+ZUefUDo4AolQXUGjpHFQiTB22VklbYPoUQ04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919812; c=relaxed/simple; bh=meu63+OCcj7UxvE6xY3+jisH59b21xOu3ZKtLDkb1Bw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqwVa5Yw+5wN8ViyD263FIMDium/goUbnHvRsk5JvW6hajpqKCvRir/DsKl0kbdCFxJ21arCeGTsAQ9VdFadUyEsRnDQV/F+Z2rGf69rzOfhTKodNX5EWMfK/YHXoIPku7P6TLrD+L94ombtIU8lciJs9KFRqj2DgCx32Z5poYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZaxLcDIo; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZaxLcDIo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919800; x=1823455800; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=meu63+OCcj7UxvE6xY3+jisH59b21xOu3ZKtLDkb1Bw=; b=ZaxLcDIoUMpoEqg2+hlcKKkwVnO5Pap3VfPO3sAGrO5abUIYF6NgcBXJ gjpAcGXnCgAIsNihzYjx2kB72P1mRPsHSjYXzyrMzR91emkH6AjFrV6Fu iuqw3GXwn+yhOfqUm1AfnUFQ1vIFN4SuEmTuC0LIuyeDJOmFURpgJ6ioV 9YxmIvsTFbZ57bAsbkhYncRzFYUtxVbkk9vsV35Hq7vJliAuyyYKmccMK qKJvL+OMVTR4LjFO+cu9ZzJB4uUs7j/RlNQ7E0PtTAY9Z/E5udfyo7Luk KVLqI34ctDymXZP+yMCpNRTGhev+CVzThKuYhAhH9QFXNX23N1GrN+amW A==; X-CSE-ConnectionGUID: Jjji8flIQbyECHWj+jDycQ== X-CSE-MsgGUID: dxkeQFOCTlqgPIlHFyKXgg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544124" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544124" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: bfxS4C4ZRV2ULOnt1pxErw== X-CSE-MsgGUID: bqzn7iFwTS2tgkBcHmTyPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167679" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 08/20] platform/x86/intel/tpmi: Do not assume TPMI is enumerated from PCI Date: Tue, 13 Oct 2026 12:29:23 -0700 Message-ID: <20261013192935.2243291-9-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" The init path converts the enumerating device into a pci_dev without checking and always registers the OOBMSM package to PCI device mapping. That works today because TPMI is only enumerated from a PCI VSEC capability, but ACPI based enumeration is being worked on and the device it enumerates from is not a PCI device. Do both only for a PCI device. The bus number read from the pci_dev is a fallback that tpmi_process_info() overwrites with the value reported by the TPMI_INFO feature, so there is nothing to do without a pci_dev. The mapping stored by intel_vsec_set_mapping() is looked up by pci_dev and cannot be consumed by another enumeration method, and calling it anyway would fail the probe with -ENODEV. While here, stop describing intel_tpmi_info as holding the TPMI devices of one PCI device. No functional change for PCI enumerated TPMI. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index f1dfe2b23c9c..f96b94ba29f8 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -119,7 +119,7 @@ struct intel_tpmi_pm_feature { * can find them again, for example during PCI error * recovery. * - * Stores the information for all TPMI devices enumerated from a single PC= I device. + * Stores the information for all TPMI devices of one TPMI instance. */ struct intel_tpmi_info { struct intel_tpmi_pm_feature *tpmi_features; @@ -742,7 +742,8 @@ static int tpmi_fetch_pfs_header(struct intel_tpmi_pm_f= eature *pfs, u64 start, i static int intel_vsec_tpmi_init(struct auxiliary_device *auxdev) { struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); - struct pci_dev *pci_dev =3D to_pci_dev(vsec_dev->dev); + struct pci_dev *pci_dev =3D dev_is_pci(vsec_dev->dev) ? + to_pci_dev(vsec_dev->dev) : NULL; struct intel_tpmi_info *tpmi_info; u64 pfs_start =3D 0; int ret, i; @@ -755,7 +756,14 @@ static int intel_vsec_tpmi_init(struct auxiliary_devic= e *auxdev) tpmi_info->parent =3D vsec_dev->dev; tpmi_info->feature_count =3D vsec_dev->num_resources; tpmi_info->resource =3D vsec_dev->resource; - tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; + + /* + * Seed the bus number from the enumerating device. It is only a + * fallback, tpmi_process_info() replaces it with the value the + * TPMI_INFO feature reports. + */ + if (pci_dev) + tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; =20 tpmi_info->tpmi_features =3D devm_kcalloc(&auxdev->dev, tpmi_info->featur= e_count, sizeof(*tpmi_info->tpmi_features), @@ -801,10 +809,16 @@ static int intel_vsec_tpmi_init(struct auxiliary_devi= ce *auxdev) if (ret) return ret; =20 - ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, - tpmi_info->parent); - if (ret) - return ret; + /* + * The mapping is looked up by pci_dev, so it is only + * meaningful for PCI enumerated TPMI instances. + */ + if (pci_dev) { + ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, + &pci_dev->dev); + if (ret) + return ret; + } } =20 if (pfs->pfs_header.tpmi_id =3D=3D TPMI_CONTROL_ID) --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 AF678541E60; Tue, 13 Oct 2026 19:30:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919804; cv=none; b=M4KijVhBczVUDM2SmVq1YHf5lai6JZ3/AwLs93pp2Iy+VFHljH4CRosoZmaRZPjTWfrLgCOH1G01VtZikVOL8/Kppi3rH/7ZQY0MqdFYBZG9v1iGY9WjrT17/6mslZPMcz7eMqTAVqiSy5/hQsvJ6PAO8jIzlfajWQcgT+UqvNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919804; c=relaxed/simple; bh=+iCdBjG/0jxqiJt+dlbgWZCqV/vV6THx17hHV0RBLW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cuoAO+4KqhkPrInmqh+obTIe5CO/Y6EZxeJNEbDGuXdtKzNMVzxpx2eMDM38x4gjYd4W8O5bHm5s0+60edyun/oUKz9jnvlp4f7tXjlm1rb5DswIrevXMSF2r57UfnTuje303ZqshrYoeQlDN8QqO+yfweWwaCHNbvMGF2VpNEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lzk+VY/y; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lzk+VY/y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919801; x=1823455801; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+iCdBjG/0jxqiJt+dlbgWZCqV/vV6THx17hHV0RBLW8=; b=lzk+VY/y29YYp0Bf5UhkAdGYhe6LwdWLu5IHkMk6/nEN0hyDoNmH5WOI h9mCo4D1wo6QVgPWaHi44s7Bl6izEZQoCRVz615wgBjSr8W5UdBL8Bj0a BcRuLq3dZnNzb9MxKBY/EwCoxscZunZZYABTnh7pIhxxkShltSrv+zEFV 3R+JGTZ9wZgI3/AzxJonKlaQDLsTnxIUuSNkmaX91HVv0N25Zbmfk/SD9 Z8Wn9nUBkVXjoCTYYHvnD0aAaYJrH2EOgb2UoI4CeM72vHLkerg631wjZ ECdIJsKFoOiYq5rh2VXP3wPZ84GbV9hzPJEwW42Rr3ZZRx0wPbMA+bk0D Q==; X-CSE-ConnectionGUID: qFgLOmY+SV6kxxzLjDkILw== X-CSE-MsgGUID: JJ+IKjVuRkCO1bMkwLMjxA== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544125" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544125" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: piJXs02pSIOHvxz2u/H23w== X-CSE-MsgGUID: RwmKwFUfSyOx5FaFZIrVRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167682" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 09/20] platform/x86/intel/tpmi: Split out enumeration independent init and exit Date: Tue, 13 Oct 2026 12:29:24 -0700 Message-ID: <20261013192935.2243291-10-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" Once the two devices and the MMIO resources are known, the rest of what the init path does is independent of how the TPMI instance was found. Turn that part into intel_tpmi_init(), taking them as arguments, and add intel_tpmi_deinit() for what removal has to undo. The auxiliary bus and intel_vsec_device handling stays in tpmi_probe() and tpmi_remove(). intel_tpmi_info is allocated by the caller instead of by intel_tpmi_init(), so that an enumeration method can embed it in its own state and get back to that with container_of(). The TPMI_CORE_INIT and TPMI_CORE_EXIT notifications now pass the struct device of the TPMI instance instead of its auxiliary device, so that the generic code does not have to know about the auxiliary bus. No in tree notifier callback looks at that argument and one that needs the auxiliary device can use to_auxiliary_dev(). The driver data is set with dev_set_drvdata() on the same device that auxiliary_set_drvdata() used, so tpmi_remove() still finds it. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/vsec_tpmi.c | 48 +++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index f96b94ba29f8..3274a24152ed 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -739,23 +739,18 @@ static int tpmi_fetch_pfs_header(struct intel_tpmi_pm= _feature *pfs, u64 start, i =20 #define TPMI_CAP_OFFSET_UNIT 1024 =20 -static int intel_vsec_tpmi_init(struct auxiliary_device *auxdev) +static int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct devic= e *tpmi_dev, + struct device *parent, struct resource *resource, + int feature_count) { - struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); - struct pci_dev *pci_dev =3D dev_is_pci(vsec_dev->dev) ? - to_pci_dev(vsec_dev->dev) : NULL; - struct intel_tpmi_info *tpmi_info; + struct pci_dev *pci_dev =3D dev_is_pci(parent) ? to_pci_dev(parent) : NUL= L; u64 pfs_start =3D 0; int ret, i; =20 - tpmi_info =3D devm_kzalloc(&auxdev->dev, sizeof(*tpmi_info), GFP_KERNEL); - if (!tpmi_info) - return -ENOMEM; - - tpmi_info->tpmi_dev =3D &auxdev->dev; - tpmi_info->parent =3D vsec_dev->dev; - tpmi_info->feature_count =3D vsec_dev->num_resources; - tpmi_info->resource =3D vsec_dev->resource; + tpmi_info->tpmi_dev =3D tpmi_dev; + tpmi_info->parent =3D parent; + tpmi_info->feature_count =3D feature_count; + tpmi_info->resource =3D resource; =20 /* * Seed the bus number from the enumerating device. It is only a @@ -765,7 +760,7 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) if (pci_dev) tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; =20 - tpmi_info->tpmi_features =3D devm_kcalloc(&auxdev->dev, tpmi_info->featur= e_count, + tpmi_info->tpmi_features =3D devm_kcalloc(tpmi_info->tpmi_dev, tpmi_info-= >feature_count, sizeof(*tpmi_info->tpmi_features), GFP_KERNEL); if (!tpmi_info->tpmi_features) @@ -827,7 +822,7 @@ static int intel_vsec_tpmi_init(struct auxiliary_device= *auxdev) =20 tpmi_info->pfs_start =3D pfs_start; =20 - auxiliary_set_drvdata(auxdev, tpmi_info); + dev_set_drvdata(tpmi_info->tpmi_dev, tpmi_info); =20 /* * Allow debugfs when security policy allows. Everything this debugfs @@ -844,24 +839,37 @@ static int intel_vsec_tpmi_init(struct auxiliary_devi= ce *auxdev) return ret; } =20 - blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_INIT, auxdev); + blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_INIT, tpmi_info= ->tpmi_dev); =20 return 0; } =20 +static void intel_tpmi_deinit(struct intel_tpmi_info *tpmi_info) +{ + blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_EXIT, tpmi_info= ->tpmi_dev); + + debugfs_remove_recursive(tpmi_info->dbgfs_dir); +} + static int tpmi_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id) { - return intel_vsec_tpmi_init(auxdev); + struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); + struct intel_tpmi_info *tpmi_info; + + tpmi_info =3D devm_kzalloc(&auxdev->dev, sizeof(*tpmi_info), GFP_KERNEL); + if (!tpmi_info) + return -ENOMEM; + + return intel_tpmi_init(tpmi_info, &auxdev->dev, vsec_dev->dev, + vsec_dev->resource, vsec_dev->num_resources); } =20 static void tpmi_remove(struct auxiliary_device *auxdev) { struct intel_tpmi_info *tpmi_info =3D auxiliary_get_drvdata(auxdev); =20 - blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_EXIT, auxdev); - - debugfs_remove_recursive(tpmi_info->dbgfs_dir); + intel_tpmi_deinit(tpmi_info); } =20 static const struct auxiliary_device_id tpmi_id_table[] =3D { --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 DD47754280B; Tue, 13 Oct 2026 19:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919811; cv=none; b=WvwAdja7RPcsgGzK7EKD6ILQMha8GOF8YmKeOBJdSWTOiK3GOEd8xP3tbcXSXZCFt5eK/sB8enLdl1FSXfzD7MGPtAjUs/QW416F8OnOcWRT+fUGplTPYPpXpLJmiewoNM6a9WeKYDBeP8ujDoeeq/m+v/8XQWW7a0ynyU/C3YU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919811; c=relaxed/simple; bh=LGeJPr1oQRA36gXAEQWG50gT/05Wsj/V1kRVXyQU0TQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ca8l9vkfNxtAvBtI9sYuTDSe1KOaJHBDJmZaKsPU8HPARXc5hQNYqd2cgJLU7ACrZLjQHNTYwfn1RmTjzo/IukMBkRMlMcFuCrzdeUTzCjL0QTtsQpuDXXeUM8qR87ZhPHK5MzdRvCsiLZMT5V3+1CuD/VwKo4i6LNrXjGBkMAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=H+SfAs3z; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="H+SfAs3z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919802; x=1823455802; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LGeJPr1oQRA36gXAEQWG50gT/05Wsj/V1kRVXyQU0TQ=; b=H+SfAs3zCgH76y1bEXvQyKthFP+9QYF0aPwm670Xv09szqRZyUSgQ6Vc VEDYzSA2cWlamolXsuVDRhFxnFnmNCgwn8lxwOimJQZTsIZ0M26RWBI/l +7GUmopDxCh93TF9tOe0xfnWDGf4dTvMQ8U45wAZ7KUb9ARBSILhhU5gp PN1u3E/m2BQefliglsL0fjDeaaZ0W8CXHcbaa1HBURMKLb9AzwzYDW86J HJGKw2jkJkxj+1nvJ0afxAhNh8DiMvW96L0vWfO9KMolMyuRnmtvFfHLx 3ubAxbjlA3P+8WzSwtPjNrlnaxDyUmEclKb51RYrRvMDD6E2YeYB1Yr8q g==; X-CSE-ConnectionGUID: m2NVxm1WSXC8vkcVnGzZRw== X-CSE-MsgGUID: ujPnJHmuR+qKopx8+tUb0g== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544126" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544126" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: keTbfVZ5QHaVxLKzrWq+vQ== X-CSE-MsgGUID: MbXE7jPwTfSjKpeA0Occpw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167688" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 10/20] platform/x86/intel/tpmi: Split off the PCI VSEC enumeration Date: Tue, 13 Oct 2026 12:29:25 -0700 Message-ID: <20261013192935.2243291-11-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" Everything the TPMI driver does once the PFS table has been located is independent of how the TPMI MMIO region was discovered, from walking the PFS to creating the per feature devices. Only the entry point is VSEC specific and it is now reduced to filling in the arguments of intel_tpmi_init(). Move the enumeration independent code to a new intel-tpmi_common module and leave the auxiliary driver binding to the "intel_vsec.tpmi" device created by the Intel VSEC driver in vsec_tpmi.c. The code is moved as is, apart from a stray blank line and a typo in a comment that are fixed in passing. tpmi_common.h exposes what an enumeration method needs, which is intel_tpmi_init(), intel_tpmi_deinit() and struct intel_tpmi_info. The structure is a complete type because the enumeration method allocates it and is expected to extend it with its own data. The PFS, TPMI_INFO and feature state layouts stay private to tpmi_common.c, only the hardware parsing touches them. CONFIG_INTEL_TPMI_COMMON is a hidden symbol selected by the enumeration method, in the same way as CONFIG_INTEL_TPMI_POWER_DOMAINS. The TPMI client API is now exported by intel-tpmi_common, so the client drivers depend on that module instead of intel-vsec_tpmi. That is what allows a second, non PCI enumeration method to be added later without the client drivers knowing which one is loaded. No functional change. Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- MAINTAINERS | 1 + drivers/platform/x86/intel/Kconfig | 4 + drivers/platform/x86/intel/Makefile | 1 + drivers/platform/x86/intel/tpmi_common.c | 829 ++++++++++++++++++++++ drivers/platform/x86/intel/tpmi_common.h | 52 ++ drivers/platform/x86/intel/vsec_tpmi.c | 836 +---------------------- 6 files changed, 895 insertions(+), 828 deletions(-) create mode 100644 drivers/platform/x86/intel/tpmi_common.c create mode 100644 drivers/platform/x86/intel/tpmi_common.h diff --git a/MAINTAINERS b/MAINTAINERS index 3a19da74d00c..40ea7921ed8b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13522,6 +13522,7 @@ M: Srinivas Pandruvada L: platform-driver-x86@vger.kernel.org S: Maintained F: Documentation/ABI/testing/debugfs-tpmi +F: drivers/platform/x86/intel/tpmi_common.[ch] F: drivers/platform/x86/intel/vsec_tpmi.c F: include/linux/intel_tpmi.h =20 diff --git a/drivers/platform/x86/intel/Kconfig b/drivers/platform/x86/inte= l/Kconfig index 2900407d6095..ea6dc7b50d90 100644 --- a/drivers/platform/x86/intel/Kconfig +++ b/drivers/platform/x86/intel/Kconfig @@ -209,11 +209,15 @@ config INTEL_SMARTCONNECT config INTEL_TPMI_POWER_DOMAINS tristate =20 +config INTEL_TPMI_COMMON + tristate + config INTEL_TPMI tristate "Intel Topology Aware Register and PM Capsule Interface (TPMI)" depends on INTEL_VSEC depends on X86_64 select INTEL_TPMI_POWER_DOMAINS + select INTEL_TPMI_COMMON help The Intel Topology Aware Register and PM Capsule Interface (TPMI), provides enumerable MMIO interface for power management features. diff --git a/drivers/platform/x86/intel/Makefile b/drivers/platform/x86/int= el/Makefile index 138b13756158..d2c63a136e51 100644 --- a/drivers/platform/x86/intel/Makefile +++ b/drivers/platform/x86/intel/Makefile @@ -40,6 +40,7 @@ intel-target-$(CONFIG_INTEL_PUNIT_IPC) +=3D punit_ipc.o # TPMI drivers intel-target-$(CONFIG_INTEL_PLR_TPMI) +=3D plr_tpmi.o intel-target-$(CONFIG_INTEL_TPMI_POWER_DOMAINS) +=3D tpmi_power_domains.o +intel-target-$(CONFIG_INTEL_TPMI_COMMON) +=3D tpmi_common.o intel-target-$(CONFIG_INTEL_TPMI) +=3D vsec_tpmi.o =20 # Intel Uncore drivers diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c new file mode 100644 index 000000000000..0db766309529 --- /dev/null +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -0,0 +1,829 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Enumeration independent part of the Intel TPMI driver + * + * Copyright (c) 2026, Intel Corporation. + * All Rights Reserved. + * + * The TPMI (Topology Aware Register and PM Capsule Interface) provides a + * flexible, extendable and PCIe enumerable MMIO interface for PM features. + * + * For example Intel RAPL (Running Average Power Limit) provides a MMIO + * interface using TPMI. This has advantage over traditional MSR + * (Model Specific Register) interface, where a thread needs to be schedul= ed + * on the target CPU to read or write. Also the RAPL features vary between + * CPU models, and hence lot of model specific code. Here TPMI provides an + * architectural interface by providing hierarchical tables and fields, + * which will not need any model specific implementation. + * + * The TPMI specification defines a PFS (PM Feature Structure) table. + * This table is present in the TPMI MMIO region. Each TPMI PM feature + * has one entry in the PFS with a unique TPMI ID and its access details. + * + * The names of the devices created for the PM features start with the + * "intel_vsec.tpmi-" prefix which is followed by a specific name of the + * given PM feature (for example, "intel_vsec.tpmi-rapl.0"). + * + * The device nodes are create by using interface "intel_vsec_add_aux()" + * provided by the Intel VSEC driver. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tpmi_common.h" + +/** + * struct intel_tpmi_pfs_entry - TPMI PM Feature Structure (PFS) entry + * @tpmi_id: TPMI feature identifier (what the feature is and its data for= mat). + * @num_entries: Number of feature interface instances present in the PFS. + * This represents the maximum number of Power domains in the SoC. + * @entry_size: Interface instance entry size in 32-bit words. + * @cap_offset: Offset from the PM_Features base address to the base of th= e PM VSEC + * register bank in KB. + * @attribute: Feature attribute: 0=3DBIOS. 1=3DOS. 2-3=3DReserved. + * @reserved: Bits for use in the future. + * + * Represents one TPMI feature entry data in the PFS retrieved as is + * from the hardware. + */ +struct intel_tpmi_pfs_entry { + u64 tpmi_id:8; + u64 num_entries:8; + u64 entry_size:16; + u64 cap_offset:16; + u64 attribute:2; + u64 reserved:14; +} __packed; + +/** + * struct intel_tpmi_pm_feature - TPMI PM Feature information for a TPMI ID + * @pfs_header: PFS header retireved from the hardware. + * @vsec_offset: Starting MMIO address for this feature in bytes. Essentia= lly + * this offset =3D "Address" from VSEC header + PFS Capability + * offset for this feature entry. + * + * Represents TPMI instance information for one TPMI ID. + */ +struct intel_tpmi_pm_feature { + struct intel_tpmi_pfs_entry pfs_header; + u64 vsec_offset; +}; + +/** + * struct tpmi_info_header - CPU package ID to PCI device mapping informat= ion + * @fn: PCI function number + * @dev: PCI device number + * @bus: PCI bus number + * @pkg: CPU Package id + * @segment: PCI segment id + * @partition: Package Partition id + * @cdie_mask: Bitmap of compute dies in the current partition + * @reserved: Reserved for future use + * @lock: When set to 1 the register is locked and becomes read-only + * until next reset. Not for use by the OS driver. + * + * The structure to read hardware provided mapping information. + */ +struct tpmi_info_header { + u64 fn:3; + u64 dev:5; + u64 bus:8; + u64 pkg:8; + u64 segment:8; + u64 partition:2; + u64 cdie_mask:16; + u64 reserved:13; + u64 lock:1; +} __packed; + +/** + * struct tpmi_feature_state - Structure to read hardware state of a featu= re + * @enabled: Enable state of a feature, 1: enabled, 0: disabled + * @reserved_1: Reserved for future use + * @write_blocked: Writes are blocked means all write operations are ignor= ed + * @read_blocked: Reads are blocked means will read 0xFFs + * @pcs_select: Interface used by out of band software, not used in OS + * @reserved_2: Reserved for future use + * @id: TPMI ID of the feature + * @reserved_3: Reserved for future use + * @locked: When set to 1, OS can't change this register. + * + * The structure is used to read hardware state of a TPMI feature. This + * information is used for debug and restricting operations for this featu= re. + */ +struct tpmi_feature_state { + u32 enabled:1; + u32 reserved_1:3; + u32 write_blocked:1; + u32 read_blocked:1; + u32 pcs_select:1; + u32 reserved_2:1; + u32 id:8; + u32 reserved_3:15; + u32 locked:1; +} __packed; + +/* + * The size from hardware is in u32 units. This size is from a trusted har= dware, + * but better to verify for pre silicon platforms. Set size to 0, when inv= alid. + */ +#define TPMI_GET_SINGLE_ENTRY_SIZE(pfs) \ +({ \ + pfs->pfs_header.entry_size > SZ_1K ? 0 : pfs->pfs_header.entry_size << 2;= \ +}) + +/* Used during auxbus device creation */ +static DEFINE_IDA(intel_vsec_tpmi_ida); + +static BLOCKING_NOTIFIER_HEAD(tpmi_notify_list); + +int tpmi_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&tpmi_notify_list, nb); +} +EXPORT_SYMBOL_NS_GPL(tpmi_register_notifier, "INTEL_TPMI"); + +int tpmi_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&tpmi_notify_list, nb); +} +EXPORT_SYMBOL_NS_GPL(tpmi_unregister_notifier, "INTEL_TPMI"); + +struct oobmsm_plat_info *tpmi_get_platform_data(struct auxiliary_device *a= uxdev) +{ + struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); + + return vsec_dev->priv_data; +} +EXPORT_SYMBOL_NS_GPL(tpmi_get_platform_data, "INTEL_TPMI"); + +int tpmi_get_resource_count(struct auxiliary_device *auxdev) +{ + struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); + + if (vsec_dev) + return vsec_dev->num_resources; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(tpmi_get_resource_count, "INTEL_TPMI"); + +struct resource *tpmi_get_resource_at_index(struct auxiliary_device *auxde= v, int index) +{ + struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); + + if (vsec_dev && index < vsec_dev->num_resources) + return &vsec_dev->resource[index]; + + return NULL; +} +EXPORT_SYMBOL_NS_GPL(tpmi_get_resource_at_index, "INTEL_TPMI"); + +/* TPMI Control Interface */ + +#define TPMI_CONTROL_STATUS_OFFSET 0x00 +#define TPMI_COMMAND_OFFSET 0x08 +#define TMPI_CONTROL_DATA_VAL_OFFSET 0x0c + +/* + * Spec is calling for max 1 seconds to get ownership at the worst + * case. Read at 10 ms timeouts and repeat up to 1 second. + */ +#define TPMI_CONTROL_TIMEOUT_US (10 * USEC_PER_MSEC) +#define TPMI_CONTROL_TIMEOUT_MAX_US (1 * USEC_PER_SEC) + +#define TPMI_RB_TIMEOUT_US (10 * USEC_PER_MSEC) +#define TPMI_RB_TIMEOUT_MAX_US USEC_PER_SEC + +/* TPMI Control status register defines */ + +#define TPMI_CONTROL_STATUS_RB BIT_ULL(0) + +#define TPMI_CONTROL_STATUS_OWNER GENMASK_ULL(5, 4) +#define TPMI_OWNER_NONE 0 +#define TPMI_OWNER_IN_BAND 1 + +#define TPMI_CONTROL_STATUS_CPL BIT_ULL(6) +#define TPMI_CONTROL_STATUS_RESULT GENMASK_ULL(15, 8) +#define TPMI_CONTROL_STATUS_LEN GENMASK_ULL(31, 16) + +#define TPMI_CMD_PKT_LEN 2 +#define TPMI_CMD_STATUS_SUCCESS 0x40 + +/* TPMI command data registers */ +#define TMPI_CONTROL_DATA_CMD GENMASK_ULL(7, 0) +#define TPMI_CONTROL_DATA_VAL_FEATURE GENMASK_ULL(48, 40) + +/* Command to send via control interface */ +#define TPMI_CONTROL_GET_STATE_CMD 0x10 + +#define TPMI_CONTROL_CMD_MASK GENMASK_ULL(48, 40) + +#define TPMI_CMD_LEN_MASK GENMASK_ULL(18, 16) + +/* Mutex to complete get feature status without interruption */ +static DEFINE_MUTEX(tpmi_dev_lock); + +static int tpmi_wait_for_owner(struct intel_tpmi_info *tpmi_info, u8 owner) +{ + u64 control; + + return readq_poll_timeout(tpmi_info->tpmi_control_mem + TPMI_CONTROL_STAT= US_OFFSET, + control, owner =3D=3D FIELD_GET(TPMI_CONTROL_STATUS_OWNER, control), + TPMI_CONTROL_TIMEOUT_US, TPMI_CONTROL_TIMEOUT_MAX_US); +} + +static int tpmi_read_feature_status(struct intel_tpmi_info *tpmi_info, int= feature_id, + struct tpmi_feature_state *feature_state) +{ + u64 control, data; + int ret; + + if (!tpmi_info->tpmi_control_mem) + return -EFAULT; + + mutex_lock(&tpmi_dev_lock); + + /* Wait for owner bit set to 0 (none) */ + ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_NONE); + if (ret) + goto err_unlock; + + /* set command id to 0x10 for TPMI_GET_STATE */ + data =3D FIELD_PREP(TMPI_CONTROL_DATA_CMD, TPMI_CONTROL_GET_STATE_CMD); + + /* 32 bits for DATA offset and +8 for feature_id field */ + data |=3D FIELD_PREP(TPMI_CONTROL_DATA_VAL_FEATURE, feature_id); + + /* Write at command offset for qword access */ + writeq(data, tpmi_info->tpmi_control_mem + TPMI_COMMAND_OFFSET); + + /* Wait for owner bit set to in-band */ + ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_IN_BAND); + if (ret) + goto err_unlock; + + /* Set Run Busy and packet length of 2 dwords */ + control =3D TPMI_CONTROL_STATUS_RB; + control |=3D FIELD_PREP(TPMI_CONTROL_STATUS_LEN, TPMI_CMD_PKT_LEN); + + /* Write at status offset for qword access */ + writeq(control, tpmi_info->tpmi_control_mem + TPMI_CONTROL_STATUS_OFFSET); + + /* Wait for Run Busy clear */ + ret =3D readq_poll_timeout(tpmi_info->tpmi_control_mem + TPMI_CONTROL_STA= TUS_OFFSET, + control, !(control & TPMI_CONTROL_STATUS_RB), + TPMI_RB_TIMEOUT_US, TPMI_RB_TIMEOUT_MAX_US); + if (ret) + goto done_proc; + + control =3D FIELD_GET(TPMI_CONTROL_STATUS_RESULT, control); + if (control !=3D TPMI_CMD_STATUS_SUCCESS) { + ret =3D -EBUSY; + goto done_proc; + } + + /* Response is ready */ + memcpy_fromio(feature_state, tpmi_info->tpmi_control_mem + TMPI_CONTROL_D= ATA_VAL_OFFSET, + sizeof(*feature_state)); + + ret =3D 0; + +done_proc: + /* Set CPL "completion" bit */ + writeq(TPMI_CONTROL_STATUS_CPL, tpmi_info->tpmi_control_mem + TPMI_CONTRO= L_STATUS_OFFSET); + +err_unlock: + mutex_unlock(&tpmi_dev_lock); + + return ret; +} + +int tpmi_get_feature_status(struct auxiliary_device *auxdev, + int feature_id, bool *read_blocked, bool *write_blocked) +{ + struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); + struct tpmi_feature_state feature_state; + int ret; + + ret =3D tpmi_read_feature_status(tpmi_info, feature_id, &feature_state); + if (ret) + return ret; + + *read_blocked =3D feature_state.read_blocked; + *write_blocked =3D feature_state.write_blocked; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(tpmi_get_feature_status, "INTEL_TPMI"); + +struct dentry *tpmi_get_debugfs_dir(struct auxiliary_device *auxdev) +{ + struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); + + return tpmi_info->dbgfs_dir; +} +EXPORT_SYMBOL_NS_GPL(tpmi_get_debugfs_dir, "INTEL_TPMI"); + +static int tpmi_pfs_dbg_show(struct seq_file *s, void *unused) +{ + struct intel_tpmi_info *tpmi_info =3D s->private; + int locked, disabled, read_blocked, write_blocked; + struct tpmi_feature_state feature_state; + struct intel_tpmi_pm_feature *pfs; + int ret, i; + + seq_printf(s, "tpmi PFS start offset 0x:%llx\n", tpmi_info->pfs_start); + seq_puts(s, "tpmi_id\t\tentries\t\tsize\t\tcap_offset\tattribute\tvsec_of= fset\tlocked\tdisabled\tread_blocked\twrite_blocked\n"); + for (i =3D 0; i < tpmi_info->feature_count; ++i) { + pfs =3D &tpmi_info->tpmi_features[i]; + ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fe= ature_state); + if (ret) { + locked =3D 'U'; + disabled =3D 'U'; + read_blocked =3D 'U'; + write_blocked =3D 'U'; + } else { + disabled =3D feature_state.enabled ? 'N' : 'Y'; + locked =3D feature_state.locked ? 'Y' : 'N'; + read_blocked =3D feature_state.read_blocked ? 'Y' : 'N'; + write_blocked =3D feature_state.write_blocked ? 'Y' : 'N'; + } + seq_printf(s, "0x%02x\t\t0x%02x\t\t0x%04x\t\t0x%04x\t\t0x%02x\t\t0x%016l= lx\t%c\t%c\t\t%c\t\t%c\n", + pfs->pfs_header.tpmi_id, pfs->pfs_header.num_entries, + pfs->pfs_header.entry_size, pfs->pfs_header.cap_offset, + pfs->pfs_header.attribute, pfs->vsec_offset, locked, disabled, + read_blocked, write_blocked); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(tpmi_pfs_dbg); + +#define MEM_DUMP_COLUMN_COUNT 8 + +static int tpmi_mem_dump_show(struct seq_file *s, void *unused) +{ + size_t row_size =3D MEM_DUMP_COLUMN_COUNT * sizeof(u32); + struct intel_tpmi_pm_feature *pfs =3D s->private; + int count, ret =3D 0; + void __iomem *mem; + u32 size; + u64 off; + u8 *buffer; + + size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + if (!size) + return -EIO; + + buffer =3D kmalloc(size, GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + off =3D pfs->vsec_offset; + + mutex_lock(&tpmi_dev_lock); + + for (count =3D 0; count < pfs->pfs_header.num_entries; ++count) { + seq_printf(s, "TPMI Instance:%d offset:0x%llx\n", count, off); + + mem =3D ioremap(off, size); + if (!mem) { + ret =3D -ENOMEM; + break; + } + + memcpy_fromio(buffer, mem, size); + + seq_hex_dump(s, " ", DUMP_PREFIX_OFFSET, row_size, sizeof(u32), buffer, = size, + false); + + iounmap(mem); + + off +=3D size; + } + + mutex_unlock(&tpmi_dev_lock); + + kfree(buffer); + + return ret; +} +DEFINE_SHOW_ATTRIBUTE(tpmi_mem_dump); + +static ssize_t mem_write(struct file *file, const char __user *userbuf, si= ze_t len, loff_t *ppos) +{ + struct seq_file *m =3D file->private_data; + struct intel_tpmi_pm_feature *pfs =3D m->private; + u32 addr, value, punit, size; + u32 num_elems; + void __iomem *mem; + int ret; + + size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + if (!size) + return -EIO; + + u32 *array __free(kfree) =3D NULL; + ret =3D parse_int_array_user(userbuf, len, (int **)&array); + if (ret < 0) + return ret; + + num_elems =3D *array; + if (num_elems !=3D 3) + return -EINVAL; + + punit =3D array[1]; + addr =3D array[2]; + value =3D array[3]; + + if (!IS_ALIGNED(addr, sizeof(u32))) + return -EINVAL; + + if (punit >=3D pfs->pfs_header.num_entries) + return -EINVAL; + + if (addr >=3D size) + return -EINVAL; + + guard(mutex)(&tpmi_dev_lock); + + mem =3D ioremap(pfs->vsec_offset + punit * size, size); + if (!mem) + return -ENOMEM; + + writel(value, mem + addr); + + iounmap(mem); + + return len; +} + +static int mem_write_show(struct seq_file *s, void *unused) +{ + return 0; +} + +static int mem_write_open(struct inode *inode, struct file *file) +{ + return single_open(file, mem_write_show, inode->i_private); +} + +static const struct file_operations mem_write_ops =3D { + .open =3D mem_write_open, + .read =3D seq_read, + .write =3D mem_write, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + +static void tpmi_dbgfs_register(struct intel_tpmi_info *tpmi_info) +{ + char name[64]; + int i; + + snprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); + tpmi_info->dbgfs_dir =3D debugfs_create_dir(name, NULL); + + debugfs_create_file("pfs_dump", 0444, tpmi_info->dbgfs_dir, tpmi_info, &t= pmi_pfs_dbg_fops); + + for (i =3D 0; i < tpmi_info->feature_count; ++i) { + struct intel_tpmi_pm_feature *pfs; + struct dentry *dir; + + pfs =3D &tpmi_info->tpmi_features[i]; + snprintf(name, sizeof(name), "tpmi-id-%02x", pfs->pfs_header.tpmi_id); + dir =3D debugfs_create_dir(name, tpmi_info->dbgfs_dir); + + debugfs_create_file("mem_dump", 0444, dir, pfs, &tpmi_mem_dump_fops); + debugfs_create_file("mem_write", 0644, dir, pfs, &mem_write_ops); + } +} + +static void tpmi_set_control_base(struct intel_tpmi_info *tpmi_info, + struct intel_tpmi_pm_feature *pfs) +{ + void __iomem *mem; + u32 size; + + size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + if (!size) + return; + + mem =3D devm_ioremap(tpmi_info->tpmi_dev, pfs->vsec_offset, size); + if (!mem) + return; + + /* mem is pointing to TPMI CONTROL base */ + tpmi_info->tpmi_control_mem =3D mem; +} + +/* + * The TPMI IDs are sparse, so the unused entries are left NULL and are + * rejected by the caller like any other unsupported feature. + */ +static const char * const intel_tpmi_names[] =3D { + [TPMI_ID_RAPL] =3D "tpmi-rapl", + [TPMI_ID_PEM] =3D "tpmi-pem", + [TPMI_ID_UNCORE] =3D "tpmi-uncore", + [TPMI_ID_SST] =3D "tpmi-sst", + [TPMI_ID_PLR] =3D "tpmi-plr", +}; + +static const char *intel_tpmi_name(enum intel_tpmi_id id) +{ + if (id >=3D ARRAY_SIZE(intel_tpmi_names)) + return NULL; + + return intel_tpmi_names[id]; +} + +static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, + struct intel_tpmi_pm_feature *pfs, + u64 pfs_start) +{ + struct intel_vsec_device *feature_vsec_dev; + struct tpmi_feature_state feature_state; + struct resource *res, *tmp; + const char *name; + int i, ret; + + ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fea= ture_state); + if (ret) + return ret; + + /* + * If not enabled, continue to look at other features in the PFS, so retu= rn -EOPNOTSUPP. + * This will not cause failure of loading of this driver. + */ + if (!feature_state.enabled) + return -EOPNOTSUPP; + + name =3D intel_tpmi_name(pfs->pfs_header.tpmi_id); + if (!name) + return -EOPNOTSUPP; + + feature_vsec_dev =3D kzalloc_flex(*feature_vsec_dev, resource, pfs->pfs_h= eader.num_entries); + if (!feature_vsec_dev) + return -ENOMEM; + + feature_vsec_dev->num_resources =3D pfs->pfs_header.num_entries; + res =3D feature_vsec_dev->resource; + + for (i =3D 0, tmp =3D res; i < pfs->pfs_header.num_entries; i++, tmp++) { + u64 entry_size_bytes =3D pfs->pfs_header.entry_size * sizeof(u32); + + tmp->start =3D pfs->vsec_offset + entry_size_bytes * i; + tmp->end =3D tmp->start + entry_size_bytes - 1; + tmp->flags =3D IORESOURCE_MEM; + } + + feature_vsec_dev->dev =3D tpmi_info->parent; + feature_vsec_dev->priv_data =3D &tpmi_info->plat_info; + feature_vsec_dev->priv_data_size =3D sizeof(tpmi_info->plat_info); + feature_vsec_dev->ida =3D &intel_vsec_tpmi_ida; + + /* + * intel_vsec_add_aux() is resource managed, no explicit + * delete is required on error or on module unload. + * feature_vsec_dev and res memory are also freed as part of + * device deletion. + * + * "name" must outlive the auxiliary device, as the auxiliary bus + * stores the pointer rather than a copy of the string. + */ + return intel_vsec_add_aux(tpmi_info->tpmi_dev, feature_vsec_dev, name); +} + +static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) +{ + int ret, i; + + for (i =3D 0; i < tpmi_info->feature_count; i++) { + ret =3D tpmi_create_device(tpmi_info, &tpmi_info->tpmi_features[i], + tpmi_info->pfs_start); + /* + * Fail, if the supported features fails to create device, + * otherwise, continue. Even if one device failed to create, + * fail the loading of driver. Since intel_vsec_add_aux() + * is resource managed, no clean up is required for the + * successfully created devices. + */ + if (ret && ret !=3D -EOPNOTSUPP) + return ret; + } + + return 0; +} + +#define TPMI_INFO_BUS_INFO_OFFSET 0x08 +#define TPMI_INFO_MAJOR_VERSION 0x00 +#define TPMI_INFO_MINOR_VERSION 0x02 + +static int tpmi_process_info(struct intel_tpmi_info *tpmi_info, + struct intel_tpmi_pm_feature *pfs) +{ + struct tpmi_info_header header; + void __iomem *info_mem; + u64 feature_header; + int ret =3D 0; + + info_mem =3D ioremap(pfs->vsec_offset, pfs->pfs_header.entry_size * sizeo= f(u32)); + if (!info_mem) + return -ENOMEM; + + feature_header =3D readq(info_mem); + if (TPMI_MAJOR_VERSION(feature_header) !=3D TPMI_INFO_MAJOR_VERSION) { + ret =3D -ENODEV; + goto error_info_header; + } + + memcpy_fromio(&header, info_mem + TPMI_INFO_BUS_INFO_OFFSET, sizeof(heade= r)); + + tpmi_info->plat_info.package_id =3D header.pkg; + tpmi_info->plat_info.bus_number =3D header.bus; + tpmi_info->plat_info.device_number =3D header.dev; + tpmi_info->plat_info.function_number =3D header.fn; + + if (TPMI_MINOR_VERSION(feature_header) >=3D TPMI_INFO_MINOR_VERSION) { + tpmi_info->plat_info.cdie_mask =3D header.cdie_mask; + tpmi_info->plat_info.partition =3D header.partition; + tpmi_info->plat_info.segment =3D header.segment; + } + +error_info_header: + iounmap(info_mem); + + return ret; +} + +static int tpmi_fetch_pfs_header(struct intel_tpmi_pm_feature *pfs, u64 st= art, int size) +{ + void __iomem *pfs_mem; + + pfs_mem =3D ioremap(start, size); + if (!pfs_mem) + return -ENOMEM; + + memcpy_fromio(&pfs->pfs_header, pfs_mem, sizeof(pfs->pfs_header)); + + iounmap(pfs_mem); + + return 0; +} + +#define TPMI_CAP_OFFSET_UNIT 1024 + +/** + * intel_tpmi_init() - Bring up a TPMI instance + * @tpmi_info: Caller allocated and zeroed state of the TPMI instance + * @tpmi_dev: Device representing the TPMI instance. Owns the devm + * allocations and parents the TPMI feature devices + * @parent: Device the TPMI instance was enumerated from + * @resource: Array of @feature_count MMIO resources, one per PFS entry + * @feature_count: Number of entries in @resource + * + * Walk the PFS of the TPMI instance described by @resource, register the + * debugfs interface and create a device for each supported PM feature. + * + * Return: 0 on success, negative errno otherwise. + */ +int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct device *tpmi= _dev, + struct device *parent, struct resource *resource, int feature_count) +{ + struct pci_dev *pci_dev =3D dev_is_pci(parent) ? to_pci_dev(parent) : NUL= L; + u64 pfs_start =3D 0; + int ret, i; + + tpmi_info->tpmi_dev =3D tpmi_dev; + tpmi_info->parent =3D parent; + tpmi_info->feature_count =3D feature_count; + tpmi_info->resource =3D resource; + + /* + * Seed the bus number from the enumerating device. It is only a + * fallback, tpmi_process_info() replaces it with the value the + * TPMI_INFO feature reports. + */ + if (pci_dev) + tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; + + tpmi_info->tpmi_features =3D devm_kcalloc(tpmi_info->tpmi_dev, tpmi_info-= >feature_count, + sizeof(*tpmi_info->tpmi_features), + GFP_KERNEL); + if (!tpmi_info->tpmi_features) + return -ENOMEM; + + for (i =3D 0; i < tpmi_info->feature_count; i++) { + struct intel_tpmi_pm_feature *pfs; + struct resource *res; + u64 res_start; + int size, ret; + + pfs =3D &tpmi_info->tpmi_features[i]; + + res =3D &tpmi_info->resource[i]; + if (!res) + continue; + + res_start =3D res->start; + size =3D resource_size(res); + if (size < 0) + continue; + + ret =3D tpmi_fetch_pfs_header(pfs, res_start, size); + if (ret) + continue; + + if (!pfs_start) + pfs_start =3D res_start; + + pfs->vsec_offset =3D pfs_start + pfs->pfs_header.cap_offset * TPMI_CAP_O= FFSET_UNIT; + + /* + * Process TPMI_INFO to get PCI device to CPU package ID. + * Device nodes for TPMI features are not created in this + * for loop. So, the mapping information will be available + * when actual device nodes created outside this + * loop via tpmi_create_devices(). + */ + if (pfs->pfs_header.tpmi_id =3D=3D TPMI_INFO_ID) { + ret =3D tpmi_process_info(tpmi_info, pfs); + if (ret) + return ret; + + /* + * The mapping is looked up by pci_dev, so it is only + * meaningful for PCI enumerated TPMI instances. + */ + if (pci_dev) { + ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, + &pci_dev->dev); + if (ret) + return ret; + } + } + + if (pfs->pfs_header.tpmi_id =3D=3D TPMI_CONTROL_ID) + tpmi_set_control_base(tpmi_info, pfs); + } + + tpmi_info->pfs_start =3D pfs_start; + + dev_set_drvdata(tpmi_info->tpmi_dev, tpmi_info); + + /* + * Allow debugfs when security policy allows. Everything this debugfs + * interface provides, can also be done via /dev/mem access. If + * /dev/mem interface is locked, don't allow debugfs to present any + * information. Also check for CAP_SYS_RAWIO as /dev/mem interface. + */ + if (!security_locked_down(LOCKDOWN_DEV_MEM) && capable(CAP_SYS_RAWIO)) + tpmi_dbgfs_register(tpmi_info); + + ret =3D tpmi_create_devices(tpmi_info); + if (ret) { + debugfs_remove_recursive(tpmi_info->dbgfs_dir); + return ret; + } + + blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_INIT, tpmi_info= ->tpmi_dev); + + return 0; +} +EXPORT_SYMBOL_NS_GPL(intel_tpmi_init, "INTEL_TPMI"); + +/** + * intel_tpmi_deinit() - Tear a TPMI instance down + * @tpmi_info: State of the TPMI instance, as passed to intel_tpmi_init() + * + * The TPMI feature devices and the devm allocations are released by the + * device core when the TPMI device goes away. + */ +void intel_tpmi_deinit(struct intel_tpmi_info *tpmi_info) +{ + blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_EXIT, tpmi_info= ->tpmi_dev); + + debugfs_remove_recursive(tpmi_info->dbgfs_dir); +} +EXPORT_SYMBOL_NS_GPL(intel_tpmi_deinit, "INTEL_TPMI"); + +MODULE_IMPORT_NS("INTEL_VSEC"); +MODULE_DESCRIPTION("Intel TPMI core support"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/intel/tpmi_common.h b/drivers/platform/x8= 6/intel/tpmi_common.h new file mode 100644 index 000000000000..dd4bbe517e1c --- /dev/null +++ b/drivers/platform/x86/intel/tpmi_common.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Intel TPMI core interface for TPMI enumeration methods + * + * Copyright (c) 2026, Intel Corporation. + * All Rights Reserved. + */ + +#ifndef _TPMI_COMMON_H_ +#define _TPMI_COMMON_H_ + +#include + +struct intel_tpmi_pm_feature; + +/** + * struct intel_tpmi_info - TPMI information for all IDs in an instance + * @tpmi_features: Pointer to a list of TPMI feature instances + * @feature_count: Number of TPMI of TPMI instances pointed by tpmi_featur= es + * @pfs_start: Start of PFS offset for the TPMI instances in this device + * @plat_info: Stores platform info which can be used by the client drive= rs + * @tpmi_control_mem: Memory mapped IO for getting control information + * @dbgfs_dir: debugfs entry pointer + * @resource: Array of feature_count MMIO resources, one per PFS entry + * @tpmi_dev: Device this TPMI instance is bound to. It backs the devm + * allocations, holds this structure as its driver data and + * the TPMI feature devices are created under it. + * @parent: Device this TPMI instance was enumerated from. It names + * the debugfs directory and becomes intel_vsec_device::dev + * of every TPMI feature device, so that the enumerating bus + * can find them again, for example during PCI error + * recovery. + * + * Stores the information for all TPMI devices of one TPMI instance. + */ +struct intel_tpmi_info { + struct intel_tpmi_pm_feature *tpmi_features; + int feature_count; + u64 pfs_start; + struct oobmsm_plat_info plat_info; + void __iomem *tpmi_control_mem; + struct dentry *dbgfs_dir; + struct resource *resource; + struct device *tpmi_dev; + struct device *parent; +}; + +int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct device *tpmi= _dev, + struct device *parent, struct resource *resource, int feature_count); +void intel_tpmi_deinit(struct intel_tpmi_info *tpmi_info); + +#endif /* _TPMI_COMMON_H_ */ diff --git a/drivers/platform/x86/intel/vsec_tpmi.c b/drivers/platform/x86/= intel/vsec_tpmi.c index 3274a24152ed..053fe0f58641 100644 --- a/drivers/platform/x86/intel/vsec_tpmi.c +++ b/drivers/platform/x86/intel/vsec_tpmi.c @@ -1,21 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Driver to enumerate TPMI features and create devices + * Enumerate TPMI features from a PCI VSEC structure * * Copyright (c) 2023, Intel Corporation. * All Rights Reserved. * - * The TPMI (Topology Aware Register and PM Capsule Interface) provides a - * flexible, extendable and PCIe enumerable MMIO interface for PM features. - * - * For example Intel RAPL (Running Average Power Limit) provides a MMIO - * interface using TPMI. This has advantage over traditional MSR - * (Model Specific Register) interface, where a thread needs to be schedul= ed - * on the target CPU to read or write. Also the RAPL features vary between - * CPU models, and hence lot of model specific code. Here TPMI provides an - * architectural interface by providing hierarchical tables and fields, - * which will not need any model specific implementation. - * * The TPMI interface uses a PCI VSEC structure to expose the location of * MMIO region. * @@ -29,827 +18,18 @@ * This TPMI driver will bind to the TPMI auxiliary device object created * by the Intel VSEC driver. * - * The TPMI specification defines a PFS (PM Feature Structure) table. - * This table is present in the TPMI MMIO region. The starting address - * of PFS is derived from the tBIR (Bar Indicator Register) and "Address" - * field from the VSEC header. - * - * Each TPMI PM feature has one entry in the PFS with a unique TPMI - * ID and its access details. The TPMI driver creates device nodes - * for the supported PM features. - * - * The names of the devices created by the TPMI driver start with the - * "intel_vsec.tpmi-" prefix which is followed by a specific name of the - * given PM feature (for example, "intel_vsec.tpmi-rapl.0"). - * - * The device nodes are create by using interface "intel_vsec_add_aux()" - * provided by the Intel VSEC driver. + * The starting address of the PFS table in the TPMI MMIO region is derived + * from the tBIR (Bar Indicator Register) and "Address" field from the VSEC + * header by the Intel VSEC driver, which passes the result on as the + * resources of the auxiliary device. Everything that happens from there on + * is enumeration independent and lives in tpmi_common.c. */ =20 -#include -#include #include -#include -#include -#include -#include -#include #include -#include -#include #include -#include -#include -#include -#include -#include - -/** - * struct intel_tpmi_pfs_entry - TPMI PM Feature Structure (PFS) entry - * @tpmi_id: TPMI feature identifier (what the feature is and its data for= mat). - * @num_entries: Number of feature interface instances present in the PFS. - * This represents the maximum number of Power domains in the SoC. - * @entry_size: Interface instance entry size in 32-bit words. - * @cap_offset: Offset from the PM_Features base address to the base of th= e PM VSEC - * register bank in KB. - * @attribute: Feature attribute: 0=3DBIOS. 1=3DOS. 2-3=3DReserved. - * @reserved: Bits for use in the future. - * - * Represents one TPMI feature entry data in the PFS retrieved as is - * from the hardware. - */ -struct intel_tpmi_pfs_entry { - u64 tpmi_id:8; - u64 num_entries:8; - u64 entry_size:16; - u64 cap_offset:16; - u64 attribute:2; - u64 reserved:14; -} __packed; - -/** - * struct intel_tpmi_pm_feature - TPMI PM Feature information for a TPMI ID - * @pfs_header: PFS header retireved from the hardware. - * @vsec_offset: Starting MMIO address for this feature in bytes. Essentia= lly - * this offset =3D "Address" from VSEC header + PFS Capability - * offset for this feature entry. - * - * Represents TPMI instance information for one TPMI ID. - */ -struct intel_tpmi_pm_feature { - struct intel_tpmi_pfs_entry pfs_header; - u64 vsec_offset; -}; - -/** - * struct intel_tpmi_info - TPMI information for all IDs in an instance - * @tpmi_features: Pointer to a list of TPMI feature instances - * @feature_count: Number of TPMI of TPMI instances pointed by tpmi_featur= es - * @pfs_start: Start of PFS offset for the TPMI instances in this device - * @plat_info: Stores platform info which can be used by the client drive= rs - * @tpmi_control_mem: Memory mapped IO for getting control information - * @dbgfs_dir: debugfs entry pointer - * @resource: Array of feature_count MMIO resources, one per PFS entry - * @tpmi_dev: Device this TPMI instance is bound to. It backs the devm - * allocations, holds this structure as its driver data and - * the TPMI feature devices are created under it. - * @parent: Device this TPMI instance was enumerated from. It names - * the debugfs directory and becomes intel_vsec_device::dev - * of every TPMI feature device, so that the enumerating bus - * can find them again, for example during PCI error - * recovery. - * - * Stores the information for all TPMI devices of one TPMI instance. - */ -struct intel_tpmi_info { - struct intel_tpmi_pm_feature *tpmi_features; - int feature_count; - u64 pfs_start; - struct oobmsm_plat_info plat_info; - void __iomem *tpmi_control_mem; - struct dentry *dbgfs_dir; - struct resource *resource; - struct device *tpmi_dev; - struct device *parent; -}; - -/** - * struct tpmi_info_header - CPU package ID to PCI device mapping informat= ion - * @fn: PCI function number - * @dev: PCI device number - * @bus: PCI bus number - * @pkg: CPU Package id - * @segment: PCI segment id - * @partition: Package Partition id - * @cdie_mask: Bitmap of compute dies in the current partition - * @reserved: Reserved for future use - * @lock: When set to 1 the register is locked and becomes read-only - * until next reset. Not for use by the OS driver. - * - * The structure to read hardware provided mapping information. - */ -struct tpmi_info_header { - u64 fn:3; - u64 dev:5; - u64 bus:8; - u64 pkg:8; - u64 segment:8; - u64 partition:2; - u64 cdie_mask:16; - u64 reserved:13; - u64 lock:1; -} __packed; - -/** - * struct tpmi_feature_state - Structure to read hardware state of a featu= re - * @enabled: Enable state of a feature, 1: enabled, 0: disabled - * @reserved_1: Reserved for future use - * @write_blocked: Writes are blocked means all write operations are ignor= ed - * @read_blocked: Reads are blocked means will read 0xFFs - * @pcs_select: Interface used by out of band software, not used in OS - * @reserved_2: Reserved for future use - * @id: TPMI ID of the feature - * @reserved_3: Reserved for future use - * @locked: When set to 1, OS can't change this register. - * - * The structure is used to read hardware state of a TPMI feature. This - * information is used for debug and restricting operations for this featu= re. - */ -struct tpmi_feature_state { - u32 enabled:1; - u32 reserved_1:3; - u32 write_blocked:1; - u32 read_blocked:1; - u32 pcs_select:1; - u32 reserved_2:1; - u32 id:8; - u32 reserved_3:15; - u32 locked:1; -} __packed; - -/* - * The size from hardware is in u32 units. This size is from a trusted har= dware, - * but better to verify for pre silicon platforms. Set size to 0, when inv= alid. - */ -#define TPMI_GET_SINGLE_ENTRY_SIZE(pfs) \ -({ \ - pfs->pfs_header.entry_size > SZ_1K ? 0 : pfs->pfs_header.entry_size << 2;= \ -}) - -/* Used during auxbus device creation */ -static DEFINE_IDA(intel_vsec_tpmi_ida); - -static BLOCKING_NOTIFIER_HEAD(tpmi_notify_list); - -int tpmi_register_notifier(struct notifier_block *nb) -{ - return blocking_notifier_chain_register(&tpmi_notify_list, nb); -} -EXPORT_SYMBOL_NS_GPL(tpmi_register_notifier, "INTEL_TPMI"); - -int tpmi_unregister_notifier(struct notifier_block *nb) -{ - return blocking_notifier_chain_unregister(&tpmi_notify_list, nb); -} -EXPORT_SYMBOL_NS_GPL(tpmi_unregister_notifier, "INTEL_TPMI"); - -struct oobmsm_plat_info *tpmi_get_platform_data(struct auxiliary_device *a= uxdev) -{ - struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); - - return vsec_dev->priv_data; -} -EXPORT_SYMBOL_NS_GPL(tpmi_get_platform_data, "INTEL_TPMI"); - -int tpmi_get_resource_count(struct auxiliary_device *auxdev) -{ - struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); - - if (vsec_dev) - return vsec_dev->num_resources; - - return 0; -} -EXPORT_SYMBOL_NS_GPL(tpmi_get_resource_count, "INTEL_TPMI"); - -struct resource *tpmi_get_resource_at_index(struct auxiliary_device *auxde= v, int index) -{ - struct intel_vsec_device *vsec_dev =3D auxdev_to_ivdev(auxdev); - - if (vsec_dev && index < vsec_dev->num_resources) - return &vsec_dev->resource[index]; - - return NULL; -} -EXPORT_SYMBOL_NS_GPL(tpmi_get_resource_at_index, "INTEL_TPMI"); - -/* TPMI Control Interface */ - -#define TPMI_CONTROL_STATUS_OFFSET 0x00 -#define TPMI_COMMAND_OFFSET 0x08 -#define TMPI_CONTROL_DATA_VAL_OFFSET 0x0c - -/* - * Spec is calling for max 1 seconds to get ownership at the worst - * case. Read at 10 ms timeouts and repeat up to 1 second. - */ -#define TPMI_CONTROL_TIMEOUT_US (10 * USEC_PER_MSEC) -#define TPMI_CONTROL_TIMEOUT_MAX_US (1 * USEC_PER_SEC) - -#define TPMI_RB_TIMEOUT_US (10 * USEC_PER_MSEC) -#define TPMI_RB_TIMEOUT_MAX_US USEC_PER_SEC - -/* TPMI Control status register defines */ - -#define TPMI_CONTROL_STATUS_RB BIT_ULL(0) - -#define TPMI_CONTROL_STATUS_OWNER GENMASK_ULL(5, 4) -#define TPMI_OWNER_NONE 0 -#define TPMI_OWNER_IN_BAND 1 - -#define TPMI_CONTROL_STATUS_CPL BIT_ULL(6) -#define TPMI_CONTROL_STATUS_RESULT GENMASK_ULL(15, 8) -#define TPMI_CONTROL_STATUS_LEN GENMASK_ULL(31, 16) - -#define TPMI_CMD_PKT_LEN 2 -#define TPMI_CMD_STATUS_SUCCESS 0x40 - -/* TPMI command data registers */ -#define TMPI_CONTROL_DATA_CMD GENMASK_ULL(7, 0) -#define TPMI_CONTROL_DATA_VAL_FEATURE GENMASK_ULL(48, 40) - -/* Command to send via control interface */ -#define TPMI_CONTROL_GET_STATE_CMD 0x10 - -#define TPMI_CONTROL_CMD_MASK GENMASK_ULL(48, 40) - -#define TPMI_CMD_LEN_MASK GENMASK_ULL(18, 16) - -/* Mutex to complete get feature status without interruption */ -static DEFINE_MUTEX(tpmi_dev_lock); - -static int tpmi_wait_for_owner(struct intel_tpmi_info *tpmi_info, u8 owner) -{ - u64 control; - - return readq_poll_timeout(tpmi_info->tpmi_control_mem + TPMI_CONTROL_STAT= US_OFFSET, - control, owner =3D=3D FIELD_GET(TPMI_CONTROL_STATUS_OWNER, control), - TPMI_CONTROL_TIMEOUT_US, TPMI_CONTROL_TIMEOUT_MAX_US); -} - -static int tpmi_read_feature_status(struct intel_tpmi_info *tpmi_info, int= feature_id, - struct tpmi_feature_state *feature_state) -{ - u64 control, data; - int ret; - - if (!tpmi_info->tpmi_control_mem) - return -EFAULT; - - mutex_lock(&tpmi_dev_lock); - - /* Wait for owner bit set to 0 (none) */ - ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_NONE); - if (ret) - goto err_unlock; - - /* set command id to 0x10 for TPMI_GET_STATE */ - data =3D FIELD_PREP(TMPI_CONTROL_DATA_CMD, TPMI_CONTROL_GET_STATE_CMD); - - /* 32 bits for DATA offset and +8 for feature_id field */ - data |=3D FIELD_PREP(TPMI_CONTROL_DATA_VAL_FEATURE, feature_id); - - /* Write at command offset for qword access */ - writeq(data, tpmi_info->tpmi_control_mem + TPMI_COMMAND_OFFSET); - - /* Wait for owner bit set to in-band */ - ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_IN_BAND); - if (ret) - goto err_unlock; - - /* Set Run Busy and packet length of 2 dwords */ - control =3D TPMI_CONTROL_STATUS_RB; - control |=3D FIELD_PREP(TPMI_CONTROL_STATUS_LEN, TPMI_CMD_PKT_LEN); - - /* Write at status offset for qword access */ - writeq(control, tpmi_info->tpmi_control_mem + TPMI_CONTROL_STATUS_OFFSET); - - /* Wait for Run Busy clear */ - ret =3D readq_poll_timeout(tpmi_info->tpmi_control_mem + TPMI_CONTROL_STA= TUS_OFFSET, - control, !(control & TPMI_CONTROL_STATUS_RB), - TPMI_RB_TIMEOUT_US, TPMI_RB_TIMEOUT_MAX_US); - if (ret) - goto done_proc; - - control =3D FIELD_GET(TPMI_CONTROL_STATUS_RESULT, control); - if (control !=3D TPMI_CMD_STATUS_SUCCESS) { - ret =3D -EBUSY; - goto done_proc; - } - - /* Response is ready */ - memcpy_fromio(feature_state, tpmi_info->tpmi_control_mem + TMPI_CONTROL_D= ATA_VAL_OFFSET, - sizeof(*feature_state)); - - ret =3D 0; - -done_proc: - /* Set CPL "completion" bit */ - writeq(TPMI_CONTROL_STATUS_CPL, tpmi_info->tpmi_control_mem + TPMI_CONTRO= L_STATUS_OFFSET); - -err_unlock: - mutex_unlock(&tpmi_dev_lock); - - return ret; -} - -int tpmi_get_feature_status(struct auxiliary_device *auxdev, - int feature_id, bool *read_blocked, bool *write_blocked) -{ - struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); - struct tpmi_feature_state feature_state; - int ret; - - ret =3D tpmi_read_feature_status(tpmi_info, feature_id, &feature_state); - if (ret) - return ret; - - *read_blocked =3D feature_state.read_blocked; - *write_blocked =3D feature_state.write_blocked; - - return 0; -} -EXPORT_SYMBOL_NS_GPL(tpmi_get_feature_status, "INTEL_TPMI"); - -struct dentry *tpmi_get_debugfs_dir(struct auxiliary_device *auxdev) -{ - struct intel_tpmi_info *tpmi_info =3D dev_get_drvdata(auxdev->dev.parent); - - return tpmi_info->dbgfs_dir; -} -EXPORT_SYMBOL_NS_GPL(tpmi_get_debugfs_dir, "INTEL_TPMI"); - -static int tpmi_pfs_dbg_show(struct seq_file *s, void *unused) -{ - struct intel_tpmi_info *tpmi_info =3D s->private; - int locked, disabled, read_blocked, write_blocked; - struct tpmi_feature_state feature_state; - struct intel_tpmi_pm_feature *pfs; - int ret, i; - - - seq_printf(s, "tpmi PFS start offset 0x:%llx\n", tpmi_info->pfs_start); - seq_puts(s, "tpmi_id\t\tentries\t\tsize\t\tcap_offset\tattribute\tvsec_of= fset\tlocked\tdisabled\tread_blocked\twrite_blocked\n"); - for (i =3D 0; i < tpmi_info->feature_count; ++i) { - pfs =3D &tpmi_info->tpmi_features[i]; - ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fe= ature_state); - if (ret) { - locked =3D 'U'; - disabled =3D 'U'; - read_blocked =3D 'U'; - write_blocked =3D 'U'; - } else { - disabled =3D feature_state.enabled ? 'N' : 'Y'; - locked =3D feature_state.locked ? 'Y' : 'N'; - read_blocked =3D feature_state.read_blocked ? 'Y' : 'N'; - write_blocked =3D feature_state.write_blocked ? 'Y' : 'N'; - } - seq_printf(s, "0x%02x\t\t0x%02x\t\t0x%04x\t\t0x%04x\t\t0x%02x\t\t0x%016l= lx\t%c\t%c\t\t%c\t\t%c\n", - pfs->pfs_header.tpmi_id, pfs->pfs_header.num_entries, - pfs->pfs_header.entry_size, pfs->pfs_header.cap_offset, - pfs->pfs_header.attribute, pfs->vsec_offset, locked, disabled, - read_blocked, write_blocked); - } - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(tpmi_pfs_dbg); - -#define MEM_DUMP_COLUMN_COUNT 8 - -static int tpmi_mem_dump_show(struct seq_file *s, void *unused) -{ - size_t row_size =3D MEM_DUMP_COLUMN_COUNT * sizeof(u32); - struct intel_tpmi_pm_feature *pfs =3D s->private; - int count, ret =3D 0; - void __iomem *mem; - u32 size; - u64 off; - u8 *buffer; - - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); - if (!size) - return -EIO; - - buffer =3D kmalloc(size, GFP_KERNEL); - if (!buffer) - return -ENOMEM; - - off =3D pfs->vsec_offset; - - mutex_lock(&tpmi_dev_lock); - - for (count =3D 0; count < pfs->pfs_header.num_entries; ++count) { - seq_printf(s, "TPMI Instance:%d offset:0x%llx\n", count, off); - - mem =3D ioremap(off, size); - if (!mem) { - ret =3D -ENOMEM; - break; - } - - memcpy_fromio(buffer, mem, size); - - seq_hex_dump(s, " ", DUMP_PREFIX_OFFSET, row_size, sizeof(u32), buffer, = size, - false); =20 - iounmap(mem); - - off +=3D size; - } - - mutex_unlock(&tpmi_dev_lock); - - kfree(buffer); - - return ret; -} -DEFINE_SHOW_ATTRIBUTE(tpmi_mem_dump); - -static ssize_t mem_write(struct file *file, const char __user *userbuf, si= ze_t len, loff_t *ppos) -{ - struct seq_file *m =3D file->private_data; - struct intel_tpmi_pm_feature *pfs =3D m->private; - u32 addr, value, punit, size; - u32 num_elems; - void __iomem *mem; - int ret; - - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); - if (!size) - return -EIO; - - u32 *array __free(kfree) =3D NULL; - ret =3D parse_int_array_user(userbuf, len, (int **)&array); - if (ret < 0) - return ret; - - num_elems =3D *array; - if (num_elems !=3D 3) - return -EINVAL; - - punit =3D array[1]; - addr =3D array[2]; - value =3D array[3]; - - if (!IS_ALIGNED(addr, sizeof(u32))) - return -EINVAL; - - if (punit >=3D pfs->pfs_header.num_entries) - return -EINVAL; - - if (addr >=3D size) - return -EINVAL; - - guard(mutex)(&tpmi_dev_lock); - - mem =3D ioremap(pfs->vsec_offset + punit * size, size); - if (!mem) - return -ENOMEM; - - writel(value, mem + addr); - - iounmap(mem); - - return len; -} - -static int mem_write_show(struct seq_file *s, void *unused) -{ - return 0; -} - -static int mem_write_open(struct inode *inode, struct file *file) -{ - return single_open(file, mem_write_show, inode->i_private); -} - -static const struct file_operations mem_write_ops =3D { - .open =3D mem_write_open, - .read =3D seq_read, - .write =3D mem_write, - .llseek =3D seq_lseek, - .release =3D single_release, -}; - -static void tpmi_dbgfs_register(struct intel_tpmi_info *tpmi_info) -{ - char name[64]; - int i; - - snprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); - tpmi_info->dbgfs_dir =3D debugfs_create_dir(name, NULL); - - debugfs_create_file("pfs_dump", 0444, tpmi_info->dbgfs_dir, tpmi_info, &t= pmi_pfs_dbg_fops); - - for (i =3D 0; i < tpmi_info->feature_count; ++i) { - struct intel_tpmi_pm_feature *pfs; - struct dentry *dir; - - pfs =3D &tpmi_info->tpmi_features[i]; - snprintf(name, sizeof(name), "tpmi-id-%02x", pfs->pfs_header.tpmi_id); - dir =3D debugfs_create_dir(name, tpmi_info->dbgfs_dir); - - debugfs_create_file("mem_dump", 0444, dir, pfs, &tpmi_mem_dump_fops); - debugfs_create_file("mem_write", 0644, dir, pfs, &mem_write_ops); - } -} - -static void tpmi_set_control_base(struct intel_tpmi_info *tpmi_info, - struct intel_tpmi_pm_feature *pfs) -{ - void __iomem *mem; - u32 size; - - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); - if (!size) - return; - - mem =3D devm_ioremap(tpmi_info->tpmi_dev, pfs->vsec_offset, size); - if (!mem) - return; - - /* mem is pointing to TPMI CONTROL base */ - tpmi_info->tpmi_control_mem =3D mem; -} - -/* - * The TPMI IDs are sparse, so the unused entries are left NULL and are - * rejected by the caller like any other unsupported feature. - */ -static const char * const intel_tpmi_names[] =3D { - [TPMI_ID_RAPL] =3D "tpmi-rapl", - [TPMI_ID_PEM] =3D "tpmi-pem", - [TPMI_ID_UNCORE] =3D "tpmi-uncore", - [TPMI_ID_SST] =3D "tpmi-sst", - [TPMI_ID_PLR] =3D "tpmi-plr", -}; - -static const char *intel_tpmi_name(enum intel_tpmi_id id) -{ - if (id >=3D ARRAY_SIZE(intel_tpmi_names)) - return NULL; - - return intel_tpmi_names[id]; -} - -static int tpmi_create_device(struct intel_tpmi_info *tpmi_info, - struct intel_tpmi_pm_feature *pfs, - u64 pfs_start) -{ - struct intel_vsec_device *feature_vsec_dev; - struct tpmi_feature_state feature_state; - struct resource *res, *tmp; - const char *name; - int i, ret; - - ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fea= ture_state); - if (ret) - return ret; - - /* - * If not enabled, continue to look at other features in the PFS, so retu= rn -EOPNOTSUPP. - * This will not cause failure of loading of this driver. - */ - if (!feature_state.enabled) - return -EOPNOTSUPP; - - name =3D intel_tpmi_name(pfs->pfs_header.tpmi_id); - if (!name) - return -EOPNOTSUPP; - - feature_vsec_dev =3D kzalloc_flex(*feature_vsec_dev, resource, pfs->pfs_h= eader.num_entries); - if (!feature_vsec_dev) - return -ENOMEM; - - feature_vsec_dev->num_resources =3D pfs->pfs_header.num_entries; - res =3D feature_vsec_dev->resource; - - for (i =3D 0, tmp =3D res; i < pfs->pfs_header.num_entries; i++, tmp++) { - u64 entry_size_bytes =3D pfs->pfs_header.entry_size * sizeof(u32); - - tmp->start =3D pfs->vsec_offset + entry_size_bytes * i; - tmp->end =3D tmp->start + entry_size_bytes - 1; - tmp->flags =3D IORESOURCE_MEM; - } - - feature_vsec_dev->dev =3D tpmi_info->parent; - feature_vsec_dev->priv_data =3D &tpmi_info->plat_info; - feature_vsec_dev->priv_data_size =3D sizeof(tpmi_info->plat_info); - feature_vsec_dev->ida =3D &intel_vsec_tpmi_ida; - - /* - * intel_vsec_add_aux() is resource managed, no explicit - * delete is required on error or on module unload. - * feature_vsec_dev and res memory are also freed as part of - * device deletion. - * - * "name" must outlive the auxiliary device, as the auxiliary bus - * stores the pointer rather than a copy of the string. - */ - return intel_vsec_add_aux(tpmi_info->tpmi_dev, feature_vsec_dev, name); -} - -static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) -{ - int ret, i; - - for (i =3D 0; i < tpmi_info->feature_count; i++) { - ret =3D tpmi_create_device(tpmi_info, &tpmi_info->tpmi_features[i], - tpmi_info->pfs_start); - /* - * Fail, if the supported features fails to create device, - * otherwise, continue. Even if one device failed to create, - * fail the loading of driver. Since intel_vsec_add_aux() - * is resource managed, no clean up is required for the - * successfully created devices. - */ - if (ret && ret !=3D -EOPNOTSUPP) - return ret; - } - - return 0; -} - -#define TPMI_INFO_BUS_INFO_OFFSET 0x08 -#define TPMI_INFO_MAJOR_VERSION 0x00 -#define TPMI_INFO_MINOR_VERSION 0x02 - -static int tpmi_process_info(struct intel_tpmi_info *tpmi_info, - struct intel_tpmi_pm_feature *pfs) -{ - struct tpmi_info_header header; - void __iomem *info_mem; - u64 feature_header; - int ret =3D 0; - - info_mem =3D ioremap(pfs->vsec_offset, pfs->pfs_header.entry_size * sizeo= f(u32)); - if (!info_mem) - return -ENOMEM; - - feature_header =3D readq(info_mem); - if (TPMI_MAJOR_VERSION(feature_header) !=3D TPMI_INFO_MAJOR_VERSION) { - ret =3D -ENODEV; - goto error_info_header; - } - - memcpy_fromio(&header, info_mem + TPMI_INFO_BUS_INFO_OFFSET, sizeof(heade= r)); - - tpmi_info->plat_info.package_id =3D header.pkg; - tpmi_info->plat_info.bus_number =3D header.bus; - tpmi_info->plat_info.device_number =3D header.dev; - tpmi_info->plat_info.function_number =3D header.fn; - - if (TPMI_MINOR_VERSION(feature_header) >=3D TPMI_INFO_MINOR_VERSION) { - tpmi_info->plat_info.cdie_mask =3D header.cdie_mask; - tpmi_info->plat_info.partition =3D header.partition; - tpmi_info->plat_info.segment =3D header.segment; - } - -error_info_header: - iounmap(info_mem); - - return ret; -} - -static int tpmi_fetch_pfs_header(struct intel_tpmi_pm_feature *pfs, u64 st= art, int size) -{ - void __iomem *pfs_mem; - - pfs_mem =3D ioremap(start, size); - if (!pfs_mem) - return -ENOMEM; - - memcpy_fromio(&pfs->pfs_header, pfs_mem, sizeof(pfs->pfs_header)); - - iounmap(pfs_mem); - - return 0; -} - -#define TPMI_CAP_OFFSET_UNIT 1024 - -static int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct devic= e *tpmi_dev, - struct device *parent, struct resource *resource, - int feature_count) -{ - struct pci_dev *pci_dev =3D dev_is_pci(parent) ? to_pci_dev(parent) : NUL= L; - u64 pfs_start =3D 0; - int ret, i; - - tpmi_info->tpmi_dev =3D tpmi_dev; - tpmi_info->parent =3D parent; - tpmi_info->feature_count =3D feature_count; - tpmi_info->resource =3D resource; - - /* - * Seed the bus number from the enumerating device. It is only a - * fallback, tpmi_process_info() replaces it with the value the - * TPMI_INFO feature reports. - */ - if (pci_dev) - tpmi_info->plat_info.bus_number =3D pci_dev->bus->number; - - tpmi_info->tpmi_features =3D devm_kcalloc(tpmi_info->tpmi_dev, tpmi_info-= >feature_count, - sizeof(*tpmi_info->tpmi_features), - GFP_KERNEL); - if (!tpmi_info->tpmi_features) - return -ENOMEM; - - for (i =3D 0; i < tpmi_info->feature_count; i++) { - struct intel_tpmi_pm_feature *pfs; - struct resource *res; - u64 res_start; - int size, ret; - - pfs =3D &tpmi_info->tpmi_features[i]; - - res =3D &tpmi_info->resource[i]; - if (!res) - continue; - - res_start =3D res->start; - size =3D resource_size(res); - if (size < 0) - continue; - - ret =3D tpmi_fetch_pfs_header(pfs, res_start, size); - if (ret) - continue; - - if (!pfs_start) - pfs_start =3D res_start; - - pfs->vsec_offset =3D pfs_start + pfs->pfs_header.cap_offset * TPMI_CAP_O= FFSET_UNIT; - - /* - * Process TPMI_INFO to get PCI device to CPU package ID. - * Device nodes for TPMI features are not created in this - * for loop. So, the mapping information will be available - * when actual device nodes created outside this - * loop via tpmi_create_devices(). - */ - if (pfs->pfs_header.tpmi_id =3D=3D TPMI_INFO_ID) { - ret =3D tpmi_process_info(tpmi_info, pfs); - if (ret) - return ret; - - /* - * The mapping is looked up by pci_dev, so it is only - * meaningful for PCI enumerated TPMI instances. - */ - if (pci_dev) { - ret =3D intel_vsec_set_mapping(&tpmi_info->plat_info, - &pci_dev->dev); - if (ret) - return ret; - } - } - - if (pfs->pfs_header.tpmi_id =3D=3D TPMI_CONTROL_ID) - tpmi_set_control_base(tpmi_info, pfs); - } - - tpmi_info->pfs_start =3D pfs_start; - - dev_set_drvdata(tpmi_info->tpmi_dev, tpmi_info); - - /* - * Allow debugfs when security policy allows. Everything this debugfs - * interface provides, can also be done via /dev/mem access. If - * /dev/mem interface is locked, don't allow debugfs to present any - * information. Also check for CAP_SYS_RAWIO as /dev/mem interface. - */ - if (!security_locked_down(LOCKDOWN_DEV_MEM) && capable(CAP_SYS_RAWIO)) - tpmi_dbgfs_register(tpmi_info); - - ret =3D tpmi_create_devices(tpmi_info); - if (ret) { - debugfs_remove_recursive(tpmi_info->dbgfs_dir); - return ret; - } - - blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_INIT, tpmi_info= ->tpmi_dev); - - return 0; -} - -static void intel_tpmi_deinit(struct intel_tpmi_info *tpmi_info) -{ - blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_EXIT, tpmi_info= ->tpmi_dev); - - debugfs_remove_recursive(tpmi_info->dbgfs_dir); -} +#include "tpmi_common.h" =20 static int tpmi_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id) @@ -886,6 +66,6 @@ static struct auxiliary_driver tpmi_aux_driver =3D { =20 module_auxiliary_driver(tpmi_aux_driver); =20 -MODULE_IMPORT_NS("INTEL_VSEC"); +MODULE_IMPORT_NS("INTEL_TPMI"); MODULE_DESCRIPTION("Intel TPMI enumeration module"); MODULE_LICENSE("GPL"); --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 E2254542ED2; Tue, 13 Oct 2026 19:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919807; cv=none; b=cGvuLFJRdq5PEsrdy6wExY9TDAGboPRc6JoHLHfgYcZTqJm8IjxjDuZY/i47wm85YURXItaxvso+qThw4vwmkKB9guItf9B9HVg0yKeHREG21elI6J1S+MhgAZM2intBnWOprKzAmzvNohNeYw3kxpnusMm4KMsEBMpKGEC/ZtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919807; c=relaxed/simple; bh=X4cqXUcmpiZuYqLvTt7lqgHmKdai1YzomAEpVhxlZZs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DDfSzW/owzKIcOEgPYaTFv0TYUp/AMucrjJdR6qJyHoQo3Icxw0dDSC8QUIg5e0yY8UKQ82/gRRiLkqsMUkPPRkR9G9S5NTAMrITXlj8t9pwGQ3odyqxJmOqdvc76i1OYVWweAaqy6CQMazaxNwADayLjNID78jkSfcQ30SUtEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WTk16ub2; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WTk16ub2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919805; x=1823455805; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X4cqXUcmpiZuYqLvTt7lqgHmKdai1YzomAEpVhxlZZs=; b=WTk16ub2kopCBiNjDeKWNpeDz5rKV3VSHmzdAEccLGgU9bJHx9LfBaN4 bO69VKafWVyJ61wK5GcDlvcNJFiwnS5eC5nmTHy1Gly6B02RBKHteOmjl jSsmhsY+OX17DIBcd+dZ9gzwJlqyMyNZKvtKTMu/fmOftoq2rsAkRUYzk EsTvwHB15badMF/pbiKhPtZJvjWv43PfQiD8L8WdNauqML/iTKkN/+9nU QlNVKU2RQFz8ZTXL/SoKwjcENP8yyrWzUzK5b5wDv9FTh5Rf/EnpLKNmw f3k19As9bmQg2PNa9ES6EtGML/eXinNdbHbcz5Fuz16BeV7uOMa85yE9m Q==; X-CSE-ConnectionGUID: UGpsh/TTQv+nbhaTNd85GQ== X-CSE-MsgGUID: +zzZTGhMScytPrJiWmfKFA== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544129" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544129" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: rsndHKHIRF2CCdoGq77fNQ== X-CSE-MsgGUID: Ev4gZliqSQK+1KXlG6P+qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167691" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 11/20] platform/x86/intel/tpmi: Include the headers tpmi_common.c relies on Date: Tue, 13 Oct 2026 12:29:26 -0700 Message-ID: <20261013192935.2243291-12-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable tpmi_common.c uses a number of interfaces whose headers it never includes directly and only gets by chance through other headers: BIT_ULL(), GENMASK_ULL() bits.h __packed compiler_attributes.h EXPORT_SYMBOL_NS_GPL() export.h DEFINE_IDA() idr.h IORESOURCE_MEM ioport.h DEFINE_MUTEX(), mutex_lock() mutex.h seq_printf(), seq_hex_dump() seq_file.h kmalloc(), kzalloc_flex() slab.h USEC_PER_MSEC, USEC_PER_SEC time64.h uXX types.h Include them, so that the file does not break when an unrelated header stops pulling them in. Drop io.h while at it, as iopoll.h already includes it, and sort the block alphabetically: debugfs.h and cleanup.h were the wrong way round. No functional change intended. Suggested-by: Andy Shevchenko Suggested-by: Ilpo J=C3=A4rvinen Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 0db766309529..83362d4bb726 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -32,19 +32,28 @@ #include #include #include -#include +#include #include +#include +#include #include +#include +#include #include #include -#include #include +#include #include +#include #include #include #include +#include #include +#include #include +#include +#include =20 #include "tpmi_common.h" =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 039F0542ED0; Tue, 13 Oct 2026 19:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919809; cv=none; b=NVBjTBh4IuCoUNuS0c3sbPTkQ+rM25//20jwuKPKUZyfKg9WIet1vnAbQjoXECpSISqI6aGs/V2WE1CsMeExmIYi351Tg3KyNZ3F5quQZNUPfX4K6XTGB35Xvq/O3Yp3VRZbF86E+TCHCvz4YP3X98AYQoLhSHRoxnf9CyqA6hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919809; c=relaxed/simple; bh=pGS/xjueNzRwY7nbH4t5291BhysepFipHiXPOhdommg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tCcI7knqq+1I82kpvtU85yO7FB+DUVbgwFl7Y0NA4b6KbMyB7qvUN1YAkVvYiJ/m3rGFwdzDVUJ9cU4iK8849S9ttkbKtx7hCGD/TUiwXiwyv8NUmXd2ZCHdP2sXFmZPYxJErxrFCh9lxqd5mg+SBUlh4Ew5bzbBLZDJonoJA8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gsTtDlp1; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gsTtDlp1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919808; x=1823455808; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pGS/xjueNzRwY7nbH4t5291BhysepFipHiXPOhdommg=; b=gsTtDlp1dU7lzE9nbcj2NY2LMuvO6EVEW03vAxL3sC28Ff8AfN4Wn4Xw jHeJYlAq8j2tAoqvJ/iDdPYWLJQlXgKUEdYcHVpuzhCjx04QEe60P+/B0 HzXnUYVFlPSUi+Ad2zTeRQhVs42+5fWqgZRJlZ/jPCPS7Wy1uRoxJf2n2 7OiOgqapZFhUw+TwlyiA3gnUcemrEm9EOc/PYK8vvbImZFtw781BFqjKw NH+nnGex6Jo6fa6zbpldEmwab5d+5d2B2waV0IaPWrQC8OOFWg0zbrL+8 nY5JSD6flDXwHO+D2PXntSdp1GFmsas1hoCuqW/q1O0OeTNIP6d2gG+1/ A==; X-CSE-ConnectionGUID: dwfDNOK0S8WhGmflIZKI6A== X-CSE-MsgGUID: LFAdgJGPS+qbOdZeyMbjNQ== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544131" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544131" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: fc1Gl+C5QAOzFxaK7NzSqA== X-CSE-MsgGUID: 4o0Hyei6QUq3+uFdEHRVFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167695" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 12/20] platform/x86/intel/tpmi: Turn TPMI_GET_SINGLE_ENTRY_SIZE() into a function Date: Tue, 13 Oct 2026 12:29:27 -0700 Message-ID: <20261013192935.2243291-13-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The macro computing a feature instance size has a few problems. Its comment says the hardware reports the size in u32 units, but the conversion to bytes is spelled as a shift by 2, so the comment and the code have to be read together to see that they agree. Its body is a single conditional expression wrapped in a statement expression that it never needed. And it evaluates its argument twice. Make it a plain static function, tpmi_get_single_entry_size(), which fixes all three: the conversion becomes a multiply by sizeof(u32), there is nothing left to wrap, and the argument is evaluated once and type checked. No functional change intended. Suggested-by: Andy Shevchenko Suggested-by: Ilpo J=C3=A4rvinen Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 83362d4bb726..7f6cd0fb23d7 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -149,13 +149,18 @@ struct tpmi_feature_state { } __packed; =20 /* - * The size from hardware is in u32 units. This size is from a trusted har= dware, - * but better to verify for pre silicon platforms. Set size to 0, when inv= alid. + * Return the size of a single feature interface instance in bytes. The + * hardware reports it in u32 units. The value comes from trusted hardware, + * but is still worth verifying on pre silicon platforms, so return 0 when + * it is out of range. */ -#define TPMI_GET_SINGLE_ENTRY_SIZE(pfs) \ -({ \ - pfs->pfs_header.entry_size > SZ_1K ? 0 : pfs->pfs_header.entry_size << 2;= \ -}) +static u32 tpmi_get_single_entry_size(const struct intel_tpmi_pm_feature *= pfs) +{ + if (pfs->pfs_header.entry_size > SZ_1K) + return 0; + + return pfs->pfs_header.entry_size * sizeof(u32); +} =20 /* Used during auxbus device creation */ static DEFINE_IDA(intel_vsec_tpmi_ida); @@ -397,7 +402,7 @@ static int tpmi_mem_dump_show(struct seq_file *s, void = *unused) u64 off; u8 *buffer; =20 - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size =3D tpmi_get_single_entry_size(pfs); if (!size) return -EIO; =20 @@ -445,7 +450,7 @@ static ssize_t mem_write(struct file *file, const char = __user *userbuf, size_t l void __iomem *mem; int ret; =20 - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size =3D tpmi_get_single_entry_size(pfs); if (!size) return -EIO; =20 @@ -531,7 +536,7 @@ static void tpmi_set_control_base(struct intel_tpmi_inf= o *tpmi_info, void __iomem *mem; u32 size; =20 - size =3D TPMI_GET_SINGLE_ENTRY_SIZE(pfs); + size =3D tpmi_get_single_entry_size(pfs); if (!size) return; =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 096875437CC; Tue, 13 Oct 2026 19:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919811; cv=none; b=dPmfcT6Bw1jjOejtAEQRtBUYUlxGGElKexnItZ8WO9yMSOtgSjPUjPCZQAom3z4jHlAGr9pg4p8NDxkABqu2Mdda+gs1RD1O/C6uOd1qzmhxPSl0BJwwdpC7bctFruce2ZBbI9kLdOAIpTGNQhgSViQQfUiv9MFMmVCWQWckrns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919811; c=relaxed/simple; bh=yT6V2Li5yIQj9solRgGsVP/YWXiUoiFnzPSFblUPFxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AE6cWeHcgW0si1THx97HUuFCqRuSPZjMYoz8toRJx9aOcWoj0iL8IwyROaabwJRweP/26DzNTBzPXnOvbjON8AOAgqxu91ZqN0CeW1e5yrLtWKeVvHA85dGc6AOa6VcpkacL65GmMe+77LtAUHYL1cHXloHQxALOPpqtilros0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hO8wl1VS; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hO8wl1VS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919810; x=1823455810; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yT6V2Li5yIQj9solRgGsVP/YWXiUoiFnzPSFblUPFxs=; b=hO8wl1VSIx3GbkwTeIXzGlLG/DHWTOKQlAme0kZmYRxVewXIey4dWxV+ DxCUhgF4CdfZh8ZsNp2qo7ZC0wgBYKhhCkA7zk3XkooJB8u4sJ77y4QI6 Sa1yi2RaSHannvbIhSxySQ8gKMhvRA12sPsIqsZJ3jQD3UD3RPk6ZvmKd /PgSz+T0APJgo3RTWLpIRPu33nDI/+gyqtr2ph6i1csvPMV6Ks0ZS8wBn xm6MnIhCP+jPN2YUmF+TlRNhjuLM5Wg8LCWAAKwiKAURir2qUae9AVxRo pfo5TX84Kn84f3O/DdMdAtsoTYUU7HG1ewwdwixTC9W1xa5+b7V9wc7U8 g==; X-CSE-ConnectionGUID: yDDLdQERTIywX+ST0I56xQ== X-CSE-MsgGUID: xbJNjCV7TruPg/YM6EkCYg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544133" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544133" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: 7zjHRiMvSfaCFpEpw77EUA== X-CSE-MsgGUID: TPCGtpGFRnmaUDa4U2eIiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167698" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 13/20] platform/x86/intel/tpmi: Use guard() for tpmi_dev_lock in the status read Date: Tue, 13 Oct 2026 12:29:28 -0700 Message-ID: <20261013192935.2243291-14-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable tpmi_read_feature_status() takes tpmi_dev_lock explicitly and unwinds through an err_unlock label, which is what forced the two error paths before the mailbox command is issued to be gotos rather than returns. Take the mutex with guard() and return directly from those two paths. The done_proc label stays, because the paths that reach it have already handed the mailbox to the hardware and still owe it the CPL write before dropping the lock. That is unchanged: the two early failures never wrote CPL before either. No functional change intended. Suggested-by: Andy Shevchenko Suggested-by: Ilpo J=C3=A4rvinen Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 7f6cd0fb23d7..00f27ac0a753 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -272,12 +272,12 @@ static int tpmi_read_feature_status(struct intel_tpmi= _info *tpmi_info, int featu if (!tpmi_info->tpmi_control_mem) return -EFAULT; =20 - mutex_lock(&tpmi_dev_lock); + guard(mutex)(&tpmi_dev_lock); =20 /* Wait for owner bit set to 0 (none) */ ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_NONE); if (ret) - goto err_unlock; + return ret; =20 /* set command id to 0x10 for TPMI_GET_STATE */ data =3D FIELD_PREP(TMPI_CONTROL_DATA_CMD, TPMI_CONTROL_GET_STATE_CMD); @@ -291,7 +291,7 @@ static int tpmi_read_feature_status(struct intel_tpmi_i= nfo *tpmi_info, int featu /* Wait for owner bit set to in-band */ ret =3D tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_IN_BAND); if (ret) - goto err_unlock; + return ret; =20 /* Set Run Busy and packet length of 2 dwords */ control =3D TPMI_CONTROL_STATUS_RB; @@ -323,9 +323,6 @@ static int tpmi_read_feature_status(struct intel_tpmi_i= nfo *tpmi_info, int featu /* Set CPL "completion" bit */ writeq(TPMI_CONTROL_STATUS_CPL, tpmi_info->tpmi_control_mem + TPMI_CONTRO= L_STATUS_OFFSET); =20 -err_unlock: - mutex_unlock(&tpmi_dev_lock); - return ret; } =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 6BDD45437FD; Tue, 13 Oct 2026 19:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; cv=none; b=K2Ga061DyvzQeqKcpNJlrH1IFWn2tNDYxLnQgpZMZ5k3oU9ToqRlU4kNc/OP+6+zxH9Q+LOSCNtUsvUflbH4ORgtTQDiqWGJ+r3YDm6+NdMf3RuprWqqxS62JeqbI5fuCEFcuNh08EYEhHJW+nlyoRtGgGFIjO1xbL2tW75GAQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; c=relaxed/simple; bh=uN/Xb6k5IqC4SamJ+jaoJKYeP2rkiUiEVQKYuO6tsS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eTl0zRoeNH4SskqmoSCAB3Lw5ImCq+XEG8R4zYNCHktLiX2190k8LR2byQ+b+axie1qSojy5SBhozoxuhqpImXp2ERmf2Qam86vv4efkMHuH8R2BeeKx8d5Bj7uH40Du/lvHy5bakqTWIQtkRXhQlPLK9ar34MS/Nbu8qdoI4u4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KccInL9i; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KccInL9i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919811; x=1823455811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uN/Xb6k5IqC4SamJ+jaoJKYeP2rkiUiEVQKYuO6tsS4=; b=KccInL9iVkUwjLrHZL2OPc64iOLaAX9Vp1UyvvzRkDsL/RAbwllyaAVk twF4jzG6uKqJYAhVEoUqs6YibRYXTVc8cclYKfL4iGFL1YPnn7sqVwVsq HzXZ0wUiKudq6mVaHC7vWapBLT91EIeM8ilw5o+AdNRsVXn8oKeNQNibw DeUXAyNdxO1JWWChlTLhdgNZ+ikSN3gDyrVSrM4WBAAHB26hVmMvm/1T1 vDzI1TgYh3XAcD13Kw9mdFloocEiGvSaxVZYGth7o/aRwF9tmS1GIP/aE oChVl42aOWjNniU83dXoM6XuIM7NeGzZHBND+n3ydG54ihKOSNmOCdb+4 Q==; X-CSE-ConnectionGUID: eHZ0HB5fS+aYKuSupJDDoQ== X-CSE-MsgGUID: 5XKyWv3jQQSBGJp3kSzQYw== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544135" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544135" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: tThKqkzYQxqZAltUGJlCpQ== X-CSE-MsgGUID: JGFwqLIvQsaTDbvWrBUDAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167703" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 14/20] platform/x86/intel/tpmi: Use scope based cleanup in the memory dump Date: Tue, 13 Oct 2026 12:29:29 -0700 Message-ID: <20261013192935.2243291-15-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable tpmi_mem_dump_show() frees its dump buffer and drops tpmi_dev_lock by hand at the end of the function, so the ioremap() failure in the middle of the loop cannot just return. It breaks out with an error stashed in ret, which is the only reason ret exists. Attach the buffer to __free(kfree) at its allocation and take the mutex with guard(), then return the error directly from the loop. mem_write() in this file already does both, so this makes the two debugfs paths consistent. No functional change intended. Suggested-by: Ilpo J=C3=A4rvinen Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 00f27ac0a753..5332d30aac6c 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -393,32 +393,29 @@ static int tpmi_mem_dump_show(struct seq_file *s, voi= d *unused) { size_t row_size =3D MEM_DUMP_COLUMN_COUNT * sizeof(u32); struct intel_tpmi_pm_feature *pfs =3D s->private; - int count, ret =3D 0; void __iomem *mem; + int count; u32 size; u64 off; - u8 *buffer; =20 size =3D tpmi_get_single_entry_size(pfs); if (!size) return -EIO; =20 - buffer =3D kmalloc(size, GFP_KERNEL); + u8 *buffer __free(kfree) =3D kmalloc(size, GFP_KERNEL); if (!buffer) return -ENOMEM; =20 off =3D pfs->vsec_offset; =20 - mutex_lock(&tpmi_dev_lock); + guard(mutex)(&tpmi_dev_lock); =20 for (count =3D 0; count < pfs->pfs_header.num_entries; ++count) { seq_printf(s, "TPMI Instance:%d offset:0x%llx\n", count, off); =20 mem =3D ioremap(off, size); - if (!mem) { - ret =3D -ENOMEM; - break; - } + if (!mem) + return -ENOMEM; =20 memcpy_fromio(buffer, mem, size); =20 @@ -430,11 +427,7 @@ static int tpmi_mem_dump_show(struct seq_file *s, void= *unused) off +=3D size; } =20 - mutex_unlock(&tpmi_dev_lock); - - kfree(buffer); - - return ret; + return 0; } DEFINE_SHOW_ATTRIBUTE(tpmi_mem_dump); =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 0EDA454488E; Tue, 13 Oct 2026 19:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; cv=none; b=ht5LuzgDw9Yx0I+zpday1X1KQDaZdSgEOumHOFz6HIPAoui/tZpKs7BYEqhhZ/sGWiBG57Mu2SxZpUjdBEsEEqvj5vinJoNwdY5U+dFdq3Fqpg/Xv/S7VNH4Hq4Tsvyl2KB+n5mFpMCTzYfAeGe2DRcenjPwg0hufSd50tKDuJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; c=relaxed/simple; bh=HTGLRto3nO6S/WMSAAmvf65ADeoe1675DVsbEayoP/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xs+gNMu0ediB7azi/X7DkhZg0Atg2yc1WzJduGUNurtCdTYFRsjOTQffkDQZpJjf4Q0nGtAR+wQ+RSEckCV8fEGyx96DlCj9Vwvr6HJBjhrUwASHton630EHD5e9AEQ50Bs9KPBA61UxRMR/BPd1v2AVAhYbuF1KrUG6Y9Tu8Tc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=W+IgrKlX; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="W+IgrKlX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919812; x=1823455812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HTGLRto3nO6S/WMSAAmvf65ADeoe1675DVsbEayoP/4=; b=W+IgrKlXO53+jgXIhSiUFqIFynaDbJCnkbgq9x9Ud+S4JinuZkbOUfXW gpqyA6F6lnzjvgFzTbBMg0KkrbOpB7XsDp0K0mcOt2kmPYnhNygPSIsQw /QUeacbDql0+vj28gCYali2jyurG3LiyuKvg23MfFWVccpDTDjGXnKDoS s+CP9LvTrbMqb28BZKHzuxGaoxzy3tUf2ZsgxTtfmTRi+Oit5gGIBHstq mETN3Mbw98Gsh+5fDN1Ka0mYKMOgD2UnPzf6dSCApvWsAa2GyzfRLnkVX ftAMf0Vb0CzxiF0dG722NwoszHJiO29W7T5aoC10qOEsd9hOJTLTP7Yp8 Q==; X-CSE-ConnectionGUID: 2+gyQxvPR6+/2H3PkRbJYg== X-CSE-MsgGUID: SnBdbGl+TMWmk0aq6h8png== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544137" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544137" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: Dicckkc6RRmWMPMjGk6j+Q== X-CSE-MsgGUID: d+TSQ/T+Q/G1S9MJTqSJ4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167706" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 15/20] platform/x86/intel/tpmi: Build the TPMI control words in one expression Date: Tue, 13 Oct 2026 12:29:30 -0700 Message-ID: <20261013192935.2243291-16-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" Both mailbox words in tpmi_read_feature_status() are assembled as an assignment followed by an or-assign of a second field, even though neither value is used in between. Build each of them in a single expression, so that a word and the fields it is made of read as one thing. The two comments on the command word described one value between them, so fold them together as well. No functional change intended. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 5332d30aac6c..a91938024d09 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -279,11 +279,12 @@ static int tpmi_read_feature_status(struct intel_tpmi= _info *tpmi_info, int featu if (ret) return ret; =20 - /* set command id to 0x10 for TPMI_GET_STATE */ - data =3D FIELD_PREP(TMPI_CONTROL_DATA_CMD, TPMI_CONTROL_GET_STATE_CMD); - - /* 32 bits for DATA offset and +8 for feature_id field */ - data |=3D FIELD_PREP(TPMI_CONTROL_DATA_VAL_FEATURE, feature_id); + /* + * Set command id to 0x10 for TPMI_GET_STATE, with the feature id 32 + * bits into the DATA offset, +8 for the feature_id field. + */ + data =3D FIELD_PREP(TMPI_CONTROL_DATA_CMD, TPMI_CONTROL_GET_STATE_CMD) | + FIELD_PREP(TPMI_CONTROL_DATA_VAL_FEATURE, feature_id); =20 /* Write at command offset for qword access */ writeq(data, tpmi_info->tpmi_control_mem + TPMI_COMMAND_OFFSET); @@ -294,8 +295,8 @@ static int tpmi_read_feature_status(struct intel_tpmi_i= nfo *tpmi_info, int featu return ret; =20 /* Set Run Busy and packet length of 2 dwords */ - control =3D TPMI_CONTROL_STATUS_RB; - control |=3D FIELD_PREP(TPMI_CONTROL_STATUS_LEN, TPMI_CMD_PKT_LEN); + control =3D TPMI_CONTROL_STATUS_RB | + FIELD_PREP(TPMI_CONTROL_STATUS_LEN, TPMI_CMD_PKT_LEN); =20 /* Write at status offset for qword access */ writeq(control, tpmi_info->tpmi_control_mem + TPMI_CONTROL_STATUS_OFFSET); --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 AFE5254489B; Tue, 13 Oct 2026 19:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; cv=none; b=rzkr2JUOV5WTGiMmByoJjCbIdjIUThsxBHsFTrSZgSF0znQBGFHI2WvSve3WWGvC7o7K4NoKDlIfVLZOFF9R1E89uLjSmChQqdxunn0AU9BCVvUQYNx4XcYUxrKSE+Kmj0c1WHVr/eBtLk4N/FpimooxdEkiXhsq8qfdppw55eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919814; c=relaxed/simple; bh=ClNAeuVqYhJ7bYMachzrgy1uaLJer6p6392akUM6VAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r5ROvZtD3w6NG8xdjYahkGJEytwJ+6qpqnozJmaNqxaHomlFqeyek43d3fsl25WQf+L+5fWje6YznbwjzOGC6ceEGTIow5JKXSA6Sp98r43ppXXDlCoVlFbdDoVO2FtV1eDcdGf9j0bndC1j7mLzxeZLnCVSe9cHpyClSsQJLOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DixSGs8A; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DixSGs8A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919812; x=1823455812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ClNAeuVqYhJ7bYMachzrgy1uaLJer6p6392akUM6VAE=; b=DixSGs8AZa2tXlYV5HGpybjKpfg6JCFGlKXGNxsHu+fDwIrBjrD8RrKM E4ECFXZxvytmuMEA3HywPPgYxWyfqJxDNQOSLqnarOcqiQQsnMy2YI9gp EWeliEZVWAsIib5AV7iGFOJs7PfrWd8pw1jJfiBlRsmn0fiWO0RUzn7D3 bLmHUyIev2ujqAkQwMrHmpBmSWjmiiRZC8Flg4z9HXJJn+MnvmSZOQaYj cflFKxFxbcJtylpmss9jjJ9Lwa4CyfGzA1wDAd+sYU0GCGJnmL/nUfTMm yrTHYzzbti+XlaQ8bHJ0kLDq+ybjSA4lIeSgNk6nSQXC7Fl5AVboH7G6y Q==; X-CSE-ConnectionGUID: V/n9ytzDRy+koiR1U3wrJw== X-CSE-MsgGUID: lWlHdAGHRrqrzQwUEaNeGQ== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544139" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544139" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: 4pViy1OmSXafL/QWbLashw== X-CSE-MsgGUID: /h7iWoV6Ta2zgQZuaVgD2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167710" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 16/20] platform/x86/intel/tpmi: Use DEFINE_SHOW_STORE_ATTRIBUTE() for mem_write Date: Tue, 13 Oct 2026 12:29:31 -0700 Message-ID: <20261013192935.2243291-17-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" The mem_write debugfs file open handler and file_operations are written out by hand, which is what DEFINE_SHOW_STORE_ATTRIBUTE() exists for. Use it, and rename the write callback to mem_write_write() to match the name the macro derives. The other two files in this driver already come from DEFINE_SHOW_ATTRIBUTE(), so this also gives mem_write the .owner =3D THIS_MODULE that the open coded file_operations was missing. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index a91938024d09..b4d361f0ec44 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -432,7 +432,8 @@ static int tpmi_mem_dump_show(struct seq_file *s, void = *unused) } DEFINE_SHOW_ATTRIBUTE(tpmi_mem_dump); =20 -static ssize_t mem_write(struct file *file, const char __user *userbuf, si= ze_t len, loff_t *ppos) +static ssize_t mem_write_write(struct file *file, const char __user *userb= uf, size_t len, + loff_t *ppos) { struct seq_file *m =3D file->private_data; struct intel_tpmi_pm_feature *pfs =3D m->private; @@ -484,19 +485,7 @@ static int mem_write_show(struct seq_file *s, void *un= used) { return 0; } - -static int mem_write_open(struct inode *inode, struct file *file) -{ - return single_open(file, mem_write_show, inode->i_private); -} - -static const struct file_operations mem_write_ops =3D { - .open =3D mem_write_open, - .read =3D seq_read, - .write =3D mem_write, - .llseek =3D seq_lseek, - .release =3D single_release, -}; +DEFINE_SHOW_STORE_ATTRIBUTE(mem_write); =20 static void tpmi_dbgfs_register(struct intel_tpmi_info *tpmi_info) { @@ -517,7 +506,7 @@ static void tpmi_dbgfs_register(struct intel_tpmi_info = *tpmi_info) dir =3D debugfs_create_dir(name, tpmi_info->dbgfs_dir); =20 debugfs_create_file("mem_dump", 0444, dir, pfs, &tpmi_mem_dump_fops); - debugfs_create_file("mem_write", 0644, dir, pfs, &mem_write_ops); + debugfs_create_file("mem_write", 0644, dir, pfs, &mem_write_fops); } } =20 --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 4EF90541E7B; Tue, 13 Oct 2026 19:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919816; cv=none; b=uAMkP1k0yT/DfHdBtJwZPEkAQ67iziYh26RYhfpPe2pf8ovHvbA1zRVh3YPmchUq3HljA2ZCNguDlt0asiKSZPJFe0FUrxfEcAU8LoUEpDqUWBSF1t34t/d3w3+uNoBT5OiPYfGDNCSNpPZGW6porFEgc/glYrwX+PGLdpYUWTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919816; c=relaxed/simple; bh=uitCWUq4bm0g0xsEAHVZ6lolIUGOQ/OkXgKhOS1T5kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F6lMCahJEn4hxa9lpzJa9DWPc0j9IKhaJWb/eoLiPQjH14TwTOEoMVtVk4RLVMDGU9lbUhWn7zZMmd692QWAoW94ulbQI6Y1ZIR9+DQ8162VgXgybKu1LTbfxHK5oU6oOjfop0rnJnz58CT74w2EMnMKonScsT5CzWi7XKYWbys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Vv7wFzWV; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Vv7wFzWV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919814; x=1823455814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uitCWUq4bm0g0xsEAHVZ6lolIUGOQ/OkXgKhOS1T5kw=; b=Vv7wFzWVtrWyXMdL+gwjX0HMmZlZrHJnJzCjNkbITMsDR3vKQMpobzrJ l5n1ugdjNwKgmg+ZrWBX27jAOdvhVxZLRf6AoQZSAeosAxLlZICSgWt1e IDtPQFxyWGpZa8QvV6/+ny29vvwgn3Ag1ptxciQOzgMEw0AczTIiMXXYv +1dNO4RmaQS3pAa4iN4YksExGW5h6ho5/n2szRvSGHmqvZ7CkYwiNkc+F 07uPYS4zJnBybDpv+rg+uZmen8YVg5uMSoKJhaCS/pz7Buuy1olF7s6s6 qbH2wCcX2iWycS0g7LiBFzft3UQ2apkUNPmrxDW38tZUAMRR8XDw9griU w==; X-CSE-ConnectionGUID: PfFs/U7vQ3iNYLiTb2rBLg== X-CSE-MsgGUID: L9bnGyjbSJWU++RXxFYuAA== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544141" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544141" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: DauRAwcxS3Obk7qyU6fa4A== X-CSE-MsgGUID: rgDnocF+QhCp9TnS3M2vtw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167713" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 17/20] platform/x86/intel/tpmi: Use scnprintf() to build the debugfs names Date: Tue, 13 Oct 2026 12:29:32 -0700 Message-ID: <20261013192935.2243291-18-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The kernel has both snprintf() and scnprintf() for formatting into a fixed size buffer. The preference is to settle on scnprintf() and stop adding snprintf() users, so that only one of the two remains in use. Convert the two callers in tpmi_dbgfs_register(). Neither of them looks at the return value, so the difference in what the two functions return does not matter here. No functional change intended. Suggested-by: Ilpo J=C3=A4rvinen Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index b4d361f0ec44..097754365897 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -492,7 +492,7 @@ static void tpmi_dbgfs_register(struct intel_tpmi_info = *tpmi_info) char name[64]; int i; =20 - snprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); + scnprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); tpmi_info->dbgfs_dir =3D debugfs_create_dir(name, NULL); =20 debugfs_create_file("pfs_dump", 0444, tpmi_info->dbgfs_dir, tpmi_info, &t= pmi_pfs_dbg_fops); @@ -502,7 +502,7 @@ static void tpmi_dbgfs_register(struct intel_tpmi_info = *tpmi_info) struct dentry *dir; =20 pfs =3D &tpmi_info->tpmi_features[i]; - snprintf(name, sizeof(name), "tpmi-id-%02x", pfs->pfs_header.tpmi_id); + scnprintf(name, sizeof(name), "tpmi-id-%02x", pfs->pfs_header.tpmi_id); dir =3D debugfs_create_dir(name, tpmi_info->dbgfs_dir); =20 debugfs_create_file("mem_dump", 0444, dir, pfs, &tpmi_mem_dump_fops); --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 BF6BF5448BE; Tue, 13 Oct 2026 19:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919816; cv=none; b=nO5ULmwJPykQr4Y7J+CPTqB33VR/+WpwR9cgt1YUGSDZLiEB0AP8Co1gdlxkDZDv3zhAfDX/F1HuDleigB0FvggD5DC4QK1AuB3lDGf+WVvhhliKpGIG+oqdp4dzJ2ZH5TiJt0oUdnnB0e5FViN8YJqQwsLG1SpcIcPplOef0bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919816; c=relaxed/simple; bh=s0UXAW1jglOMQ0ACum63m+uMDYIGQktW+Os4ylk8wug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KsLl0dpJMuuQxVPq0Q0LikBMCKfYIrwh4AFpDRWimir5i92NdpUHaQOHqeebuJw4ogTdHwdyzQ7ybqjmyLvyH0n0bFh0Bx4smHCBR58CLtCSxV51Fdbv24ITOTPAJ3qfAWyqS+5Hl17J7Ew621APx2wjYF8P0/AyKmuLdlWPbL4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EBjStNx7; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EBjStNx7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919814; x=1823455814; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s0UXAW1jglOMQ0ACum63m+uMDYIGQktW+Os4ylk8wug=; b=EBjStNx7wGZ7A4XrSl5HirNj/Ifb//c6qkdlzSe9pMbCOTPrSR6dWM7e Zl5Q57vDrUjKWzKQAOgrItSezTVE9YBc5Ty7K9D3RgBykOpX5uJeqWLq6 Ly/cY/mLve1WywFjanrWPn0RpkEifjp6Os8ae51DSpQgEcUCyfQju2TOu oUkqoXPMY7M79abJTYUEIGSDedt3zLKTwfEt8kD2yXXdQBpcKVullRn6+ Mq+qs+Z9xejSz4i42uJI58qbr6v1uzdJshUvFy1SwWnMB0eonsrqAGGh0 ryhZNjKys7l1aMcCoH73fUwh6wI83mQIU17F+K7d5+/eapombhAszovRg A==; X-CSE-ConnectionGUID: FNeH6jgIRuC9GjB8jZWGPg== X-CSE-MsgGUID: J9NIXVqzQsCvFzdb0GR0uA== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544143" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544143" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: V7WcJTXdSaCrAXN8Cmy9bA== X-CSE-MsgGUID: X5M6rF0wTCqZamlZgUOQhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167717" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 18/20] platform/x86/intel/tpmi: Use DEFINE_RES_MEM() for the feature resources Date: Tue, 13 Oct 2026 12:29:33 -0700 Message-ID: <20261013192935.2243291-19-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" tpmi_create_device() fills in each feature resource field by field, deriving the end from the start and setting IORESOURCE_MEM by hand. That is what DEFINE_RES_MEM() exists for, so use it. The resources come from kzalloc_flex(), so the fields the macro sets that the open coded version left alone, name and desc, were already zero. No functional change intended. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 097754365897..91d8083fecc0 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -583,9 +583,7 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, for (i =3D 0, tmp =3D res; i < pfs->pfs_header.num_entries; i++, tmp++) { u64 entry_size_bytes =3D pfs->pfs_header.entry_size * sizeof(u32); =20 - tmp->start =3D pfs->vsec_offset + entry_size_bytes * i; - tmp->end =3D tmp->start + entry_size_bytes - 1; - tmp->flags =3D IORESOURCE_MEM; + *tmp =3D DEFINE_RES_MEM(pfs->vsec_offset + entry_size_bytes * i, entry_s= ize_bytes); } =20 feature_vsec_dev->dev =3D tpmi_info->parent; --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 13D27545297; Tue, 13 Oct 2026 19:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919817; cv=none; b=rrI3tLCMVMxR5N1YDHh+QkVkSjLXpynqsGIBBsBiM3EVWxD2Yg9yKBd380yqEd95MvoPTrNFIr/KoW2JnQRD6i6vXJ2XT5wVKrk/Auvb4lx4xFQOadMomHFLh/TC0GQDmdDfTcG4OjfG9TgUBlypBDctiLgxk15QV5xRBlR9tOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919817; c=relaxed/simple; bh=iDhjbgEsBWYrvJ+Q4YWTFHOKu2v3r7lQNFgG42v/7pE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pq84keFnaUn58d70nsfUiawTvA52cFit5xAs7QbZS6EW4jUeko2zWlm//FhgbKww74BoXpEGWF+yUDOG+3DyIse6GzXza2p5wz5JeFxW3qW4Oks7ekIgLegjfeGy5wC7w2nx8lxW5w+Ev1dZpPNRNJhFO1RdF4zsSXolOx3Scrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KvphjD7l; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KvphjD7l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919815; x=1823455815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iDhjbgEsBWYrvJ+Q4YWTFHOKu2v3r7lQNFgG42v/7pE=; b=KvphjD7l+9YrN1xy4J1zvsrYJvkngk79Wm7zKov2AwgtOTyZCLtWdCvq hMosPTSQRKMzbQwcAdTUAufAPbmECMoDT4xkYDg1BvtWcUQ4taBHDW0AR Y0qqlAMM5/REhuA2bs/+S8IVU/FOZwIZMH911/LefyyxN5mjZQKKqalz+ 3uxkreBM6cM0JsSezjComDBmoGvHUB+NrbcaWiEWXH2oBt9FwBuoCd58W QknLxjecipAfvqmjsD2Uxlw2ABBy90eJvU6JnK0IzuYLl9xIkAePeTqrc 3u4MHFslL0Iop/o5iJN+yJuqUjIUc5PJ6juJ4oIlYwXUjH69td8CIuLHf Q==; X-CSE-ConnectionGUID: 83MvThXORjm9SieMqQTOaA== X-CSE-MsgGUID: OV8mZ4aET1GXKtG0iDkicQ== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544145" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544145" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: xYlvpkvQTJy+LyzBynZLPw== X-CSE-MsgGUID: 8r0dmumLRtCoN7q3KZVpqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167720" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 19/20] platform/x86/intel/tpmi: Declare the loop counters in their loops Date: Tue, 13 Oct 2026 12:29:34 -0700 Message-ID: <20261013192935.2243291-20-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@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: quoted-printable Content-Type: text/plain; charset="utf-8" Declare the loop counters in the for statements that use them, so that they are scoped to their loops. In tpmi_create_device() this also replaces the tmp cursor, which moved in step with the counter, with res[i]. While at it, use post-increment in all of them, as the other loops in the file already do. No functional change intended. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 26 +++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 91d8083fecc0..55c8e23dd2ce 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -359,11 +359,11 @@ static int tpmi_pfs_dbg_show(struct seq_file *s, void= *unused) int locked, disabled, read_blocked, write_blocked; struct tpmi_feature_state feature_state; struct intel_tpmi_pm_feature *pfs; - int ret, i; + int ret; =20 seq_printf(s, "tpmi PFS start offset 0x:%llx\n", tpmi_info->pfs_start); seq_puts(s, "tpmi_id\t\tentries\t\tsize\t\tcap_offset\tattribute\tvsec_of= fset\tlocked\tdisabled\tread_blocked\twrite_blocked\n"); - for (i =3D 0; i < tpmi_info->feature_count; ++i) { + for (int i =3D 0; i < tpmi_info->feature_count; i++) { pfs =3D &tpmi_info->tpmi_features[i]; ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fe= ature_state); if (ret) { @@ -395,7 +395,6 @@ static int tpmi_mem_dump_show(struct seq_file *s, void = *unused) size_t row_size =3D MEM_DUMP_COLUMN_COUNT * sizeof(u32); struct intel_tpmi_pm_feature *pfs =3D s->private; void __iomem *mem; - int count; u32 size; u64 off; =20 @@ -411,7 +410,7 @@ static int tpmi_mem_dump_show(struct seq_file *s, void = *unused) =20 guard(mutex)(&tpmi_dev_lock); =20 - for (count =3D 0; count < pfs->pfs_header.num_entries; ++count) { + for (int count =3D 0; count < pfs->pfs_header.num_entries; count++) { seq_printf(s, "TPMI Instance:%d offset:0x%llx\n", count, off); =20 mem =3D ioremap(off, size); @@ -490,14 +489,13 @@ DEFINE_SHOW_STORE_ATTRIBUTE(mem_write); static void tpmi_dbgfs_register(struct intel_tpmi_info *tpmi_info) { char name[64]; - int i; =20 scnprintf(name, sizeof(name), "tpmi-%s", dev_name(tpmi_info->parent)); tpmi_info->dbgfs_dir =3D debugfs_create_dir(name, NULL); =20 debugfs_create_file("pfs_dump", 0444, tpmi_info->dbgfs_dir, tpmi_info, &t= pmi_pfs_dbg_fops); =20 - for (i =3D 0; i < tpmi_info->feature_count; ++i) { + for (int i =3D 0; i < tpmi_info->feature_count; i++) { struct intel_tpmi_pm_feature *pfs; struct dentry *dir; =20 @@ -554,9 +552,9 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, { struct intel_vsec_device *feature_vsec_dev; struct tpmi_feature_state feature_state; - struct resource *res, *tmp; + struct resource *res; const char *name; - int i, ret; + int ret; =20 ret =3D tpmi_read_feature_status(tpmi_info, pfs->pfs_header.tpmi_id, &fea= ture_state); if (ret) @@ -580,10 +578,10 @@ static int tpmi_create_device(struct intel_tpmi_info = *tpmi_info, feature_vsec_dev->num_resources =3D pfs->pfs_header.num_entries; res =3D feature_vsec_dev->resource; =20 - for (i =3D 0, tmp =3D res; i < pfs->pfs_header.num_entries; i++, tmp++) { + for (int i =3D 0; i < pfs->pfs_header.num_entries; i++) { u64 entry_size_bytes =3D pfs->pfs_header.entry_size * sizeof(u32); =20 - *tmp =3D DEFINE_RES_MEM(pfs->vsec_offset + entry_size_bytes * i, entry_s= ize_bytes); + res[i] =3D DEFINE_RES_MEM(pfs->vsec_offset + entry_size_bytes * i, entry= _size_bytes); } =20 feature_vsec_dev->dev =3D tpmi_info->parent; @@ -605,9 +603,9 @@ static int tpmi_create_device(struct intel_tpmi_info *t= pmi_info, =20 static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) { - int ret, i; + int ret; =20 - for (i =3D 0; i < tpmi_info->feature_count; i++) { + for (int i =3D 0; i < tpmi_info->feature_count; i++) { ret =3D tpmi_create_device(tpmi_info, &tpmi_info->tpmi_features[i], tpmi_info->pfs_start); /* @@ -701,7 +699,7 @@ int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, = struct device *tpmi_dev, { struct pci_dev *pci_dev =3D dev_is_pci(parent) ? to_pci_dev(parent) : NUL= L; u64 pfs_start =3D 0; - int ret, i; + int ret; =20 tpmi_info->tpmi_dev =3D tpmi_dev; tpmi_info->parent =3D parent; @@ -722,7 +720,7 @@ int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, = struct device *tpmi_dev, if (!tpmi_info->tpmi_features) return -ENOMEM; =20 - for (i =3D 0; i < tpmi_info->feature_count; i++) { + for (int i =3D 0; i < tpmi_info->feature_count; i++) { struct intel_tpmi_pm_feature *pfs; struct resource *res; u64 res_start; --=20 2.43.0 From nobody Sat Oct 24 13:21:16 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 4973253FD58; Tue, 13 Oct 2026 19:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919818; cv=none; b=c6iXkhMSiufzQKtbre+vSdBPx+35aETzuZvYh9JN2ZYYFm+QvffYmD3rWgp6piaa72cLcv2zILjhGj3nmUMjUeZzjTNe8bGibJd1Xvil0MXlPYbLeXLIC6bumBAC2/s7Rzu/yAcisb4XS6ya7cqK6V9fgoZfDgsvBNmrX1GLZMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919818; c=relaxed/simple; bh=ecmz5smcB2fI+iVz6uagudZ7WzdL9uHLsTbINoBogRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ARde7s7CNqqd7OrnT3l9h59zwoW/+UHh/SwppnI265O/pw87RUUOLYN4innDbmvCCa1sRLoV/gfZG7F5VLTKuwNuwXTE6gvl2pLRTXjnqg0McWuRWlQ3Wi2uxp3f9D5rlatyzmEtoGvu9HLnEioC76I7Av7dI/n9kZ88Q4Vw0NU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=B3Mb1XFK; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="B3Mb1XFK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791919816; x=1823455816; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ecmz5smcB2fI+iVz6uagudZ7WzdL9uHLsTbINoBogRU=; b=B3Mb1XFKcw2jC1jQ8joTkzT2+gUYkv4phvojB4MZp6oWi0uHucJ5yORx 1+OVki25EZp63wKD68wopnDJyUtHNjLZgNE66GVgKJcVb5/CrBaf0ELr9 p094wRAH9lp6W3DOMmQ1AqLWhq8pBjqSWdxF02w0vPVem0DG0KSZ5iDJE wGf94nwoojYpoS6HPQqu7sIb9oEnYGpZbqx66GbKQXrEBBlXhx5BLRFJ4 9v3g94ACa7hZn++J67Q8mMLr+aomzClsAW75WLo2svAfCDwdJIFqm9r0K d2t6cc1LJK2rxjtfIV5RFXY7fI8THT9q4ZVPxvEV+0rfGV7B7xAHvL0mv g==; X-CSE-ConnectionGUID: ByO4kBgOT3GFJs4EjJ89jA== X-CSE-MsgGUID: zbPh8EIPRTi/XoEelAR1yg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="544147" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="544147" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 X-CSE-ConnectionGUID: 43Wnw7EtR6a0TQzflB/lfg== X-CSE-MsgGUID: UyAqLfecQyivNtiPNgDIoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1167723" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 12:29:49 -0700 From: Kuppuswamy Sathyanarayanan To: Srinivas Pandruvada , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , David E Box Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 20/20] platform/x86/intel/tpmi: Describe the device creation policy on the function Date: Tue, 13 Oct 2026 12:29:35 -0700 Message-ID: <20261013192935.2243291-21-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20261013192935.2243291-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The comment explaining the error policy of tpmi_create_devices() sits inside the loop, between the call and the check it describes. Move it above the function, where it describes the policy as a whole. Also split the check into its two cases, skipping unsupported features and failing on any other error, so that each reads on its own. No functional change intended. Suggested-by: Andy Shevchenko Suggested-by: Ilpo J=C3=A4rvinen Reviewed-by: Andy Shevchenko Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/platform/x86/intel/tpmi_common.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/intel/tpmi_common.c b/drivers/platform/x8= 6/intel/tpmi_common.c index 55c8e23dd2ce..b6b811016dfd 100644 --- a/drivers/platform/x86/intel/tpmi_common.c +++ b/drivers/platform/x86/intel/tpmi_common.c @@ -601,6 +601,14 @@ static int tpmi_create_device(struct intel_tpmi_info *= tpmi_info, return intel_vsec_add_aux(tpmi_info->tpmi_dev, feature_vsec_dev, name); } =20 +/* + * Create a device for every feature in the PFS that has one. + * + * A feature that is not supported is reported as -EOPNOTSUPP and skipped. + * Any other error fails the driver load. intel_vsec_add_aux() is resource + * managed, so the devices created before such a failure need no clean up + * here. + */ static int tpmi_create_devices(struct intel_tpmi_info *tpmi_info) { int ret; @@ -608,14 +616,9 @@ static int tpmi_create_devices(struct intel_tpmi_info = *tpmi_info) for (int i =3D 0; i < tpmi_info->feature_count; i++) { ret =3D tpmi_create_device(tpmi_info, &tpmi_info->tpmi_features[i], tpmi_info->pfs_start); - /* - * Fail, if the supported features fails to create device, - * otherwise, continue. Even if one device failed to create, - * fail the loading of driver. Since intel_vsec_add_aux() - * is resource managed, no clean up is required for the - * successfully created devices. - */ - if (ret && ret !=3D -EOPNOTSUPP) + if (ret =3D=3D -EOPNOTSUPP) + continue; + if (ret) return ret; } =20 --=20 2.43.0