From nobody Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 845903314C3; Tue, 22 Sep 2026 18:33:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101999; cv=none; b=L55fuFDdBPwaTQzBj4E+ru+TnGosDfTqGol93mXjnSMpiwaED7XSSW+7nqZekkh0Lp+5/FQV895h1BjSlSWMAgBV1TGql7gmTcZSbPJnOebdWUu7qyNGT5kfmGmjRAhFvn8nNLDMiNrV0+YvrePFRugQwk3vWRA0XJeZxmvKNmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101999; c=relaxed/simple; bh=Z+45j+E2SIXO1krqnxt+Ax1Palf6Th7eSTMIXrJXia8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k8M+G3zuY33NfFFHNVcYefUEXc2N8T5ZgMWzeKUuYW/kA+anVYBRQo54q/vsQnoH/f76c9q8PG9qso7Pw72u8RBGTVDKpRyKJp2JPlQZb+IkLzU0FjrifE5XpPjdR0sRgKdwDCb6KdOPcoH2xL7HdFVOo4N35iRpad9akPC2jJ8= 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=gRhe9Cix; arc=none smtp.client-ip=192.198.163.12 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="gRhe9Cix" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790101996; x=1821637996; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z+45j+E2SIXO1krqnxt+Ax1Palf6Th7eSTMIXrJXia8=; b=gRhe9CixpNDRin0tBJDfnsQkMC3FWnclhp6hnjrVsFQKyroNfJeO+0T2 nKQ4JI5levHMNe8DJBz7rJYTrt+8IMG/U1eo7+AXWIMv4pXg/SsIpugBs 7b744j8DUoBcMo5Ql4PJh9BvYOfo/wq819EtLEN2g6HOJrvYdkrGnku1L lBPNe26PZcFXK2OKeLcMW1IoP4dXldN8JHiRaSq4o5suFqC0zqo1fnhxM Y5HTJ+Rm4m2+gbobrq8tdCmOPSbwVO7FZYsyQFc+iPqJMXTn7mVeqB7Uy xQ/Y8+XhzWUrtgePzSL/Tu8WDg3YM8wQC4ADxolGPQEg8ZY7rF1IaChCQ w==; X-CSE-ConnectionGUID: Le/twPKFRGiz3ESSeDAGdg== X-CSE-MsgGUID: toHjARsYTkSLA7gAx80EKQ== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564883" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564883" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:14 -0700 X-CSE-ConnectionGUID: zKC5gF8ZQHWZmd9Y2RELuw== X-CSE-MsgGUID: 7Rb0vajQSki81H/jpvUImg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827957" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:14 -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 v1 01/10] platform/x86/intel/tpmi: Use static strings for the feature device names Date: Tue, 22 Sep 2026 11:33:02 -0700 Message-ID: <20260922183311.3783010-2-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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. Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko Reviewed-by: Srinivas Pandruvada --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 D5E303BB9EB; Tue, 22 Sep 2026 18:33:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101998; cv=none; b=tZtptHEOb3AmqKtQgl1phZRqFwcjdj0UTSF+vOPDyafmKQF7Ttl1rDBf/yZWkgaM84tQZcPVR2c3rvSRCgNIQTpEMdfXTQYlq4r0RNiaa84KcSEcbJocYXj0U9x4HnrILYNuYOn1g612zgjE8BfAYpI+W83LB6XbUj771Co8YLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101998; c=relaxed/simple; bh=43iCEcdNrqESVqvh7iTNwHAKsvTYeK4i01c/nab3iwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5ls9UAuMv/Oc/obCNlMYmYTZoQ6YoM9s3p/onaZ6ppoqfilnZv4a9v9NflKfk0y6LjhEf0zvPxbNE4QYi9Y6ifcpuEn/GYJxf1GWb2nyR8XFTXZCZiodyWItvAPOnBCf9eob/fdj1YoBeRLBuCxaDBlGZqwyAopspnvc0G/pQc= 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=U3LiTDkg; arc=none smtp.client-ip=192.198.163.12 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="U3LiTDkg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790101997; x=1821637997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=43iCEcdNrqESVqvh7iTNwHAKsvTYeK4i01c/nab3iwQ=; b=U3LiTDkgiLWXaPQlr8PwF8YqIBeKMzerNi6ERbnl+N4Jd37XQY63t2VE T0xhRlhW2Om2gmfWheliAMN5rTJG6bTB/aLUvdUXpnFGZVBUoB+hVxTTY EETaqflwE2/iR479KHLkMUXWVMN8Iypd93O+TjMmnpd1Fxms3HP+Mq/AL +M2Bqtw6maI25rk14O8UhhY/xEU70RKw5NPDFp+4tDlcQGNZgwLx/PsuA EPtp838vgnC1cRv+6i1uI3u8aYiXMsuzYvKTgVPgOJKX643xpaqeJSs0w fxHC+z/0M0ISgl9VhragayS8IenfxDw87aPl6ku1bZrjfEwSZwC5P9w3U g==; X-CSE-ConnectionGUID: OG2AUDnETL6KWyhcK3Pasw== X-CSE-MsgGUID: 5XMx7DsQRGWRcw33w5MI+w== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564886" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564886" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -0700 X-CSE-ConnectionGUID: hRgt/1Y9TqGmXTVb2pQtMA== X-CSE-MsgGUID: YXwyEFIkQSK1gY0L/gwVXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827961" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:14 -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 v1 02/10] platform/x86/intel/vsec: Pass a struct device to intel_vsec_set_mapping() Date: Tue, 22 Sep 2026 11:33:03 -0700 Message-ID: <20260922183311.3783010-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 3BB0E3EFFA9; Tue, 22 Sep 2026 18:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101998; cv=none; b=g+8BdA2ZKXrPWf+chs7vqYwrrs8T4a35Hm6SIdMjQk1ITwGoX+k87PxVvShdDjROeuN+fhB82pbYs9FJsCyPiwaon0XaTJLa3mLLcN3KLG+bGsZQFgNxrR4no7V/UQ7Ghrj/uxFCRWVjBZqS8OLrDVfaxHPcZW9RXAN8edm+Eik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790101998; c=relaxed/simple; bh=1YKJlmNEPCE2F3n+VhEhSB9oLunKLzhg22mwoRQ9ck4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SDYWwSqqpQ5h7LhLxysS3NIbh59fUy4F6BbjtP+Iz2occU2lVOTc3K12uAmOLMljWjplGDwRt6/GwJk73MxNXSAnmY0dLl7GyMK0CUGtBZzoo5eZ+OiPcyTLXkQ4VL93PtGcSneCrxZb4kp4ZsD7s8dPQDuyUDLp64pH8OnLK4A= 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=jw0DWSfq; arc=none smtp.client-ip=192.198.163.12 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="jw0DWSfq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790101997; x=1821637997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1YKJlmNEPCE2F3n+VhEhSB9oLunKLzhg22mwoRQ9ck4=; b=jw0DWSfqJx3S3+k7g6ev/eRowj4Rpn+wykHVMNYVxZEi3kDsrf3qY+5z lre4MY4iMSUj5VGuLhBpS68F6Eg2NfsGrWjvA8it0enyYLXvoHbmkAO8o IQO2vVS51yryNl1OVTDZyIbA2ItkkeJ8Grc6H4dk2kWqusbbLu4OwjWCn jHhTIzidhonceL+WdQYQ2oVZ/bqM3pbdDD68UWfzQnS9W3tkPdyR7g2q7 Ug83Yk0UTw6YXWTibliAB25aASFLSo/DKHbbnzSd+uankpUWHs5qAc1kw qkk3BAnlpLdHboh4Y6YO1iF23bALm2afSXxhW0yD/XkLGg/ISFuHOC416 w==; X-CSE-ConnectionGUID: dJXlvRxJSEWuJLZt3wT3ww== X-CSE-MsgGUID: 6Qkzt37ZRuKZxGSehDluRg== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564888" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564888" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -0700 X-CSE-ConnectionGUID: qBmUHQIdT/GiByPIpNcVVQ== X-CSE-MsgGUID: VLOg46PzS1iNVaYE3mTaRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827970" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:14 -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 v1 03/10] platform/x86/intel/tpmi: Remove unused vsec_dev from intel_tpmi_pm_feature Date: Tue, 22 Sep 2026 11:33:04 -0700 Message-ID: <20260922183311.3783010-4-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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. Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko Reviewed-by: Srinivas Pandruvada --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 B355448F004; Tue, 22 Sep 2026 18:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102000; cv=none; b=K9VA4a4LAExS21t718G5P6gzFnxGx4MtAR5gQNFX2Atei7G+NiQF6xIDS29xxhLxP7ZWuPzF5XyTl5QPq1nBs6lD2i0/5KoV0tYp7wYXYZBHEFcbNaX8bA4SK1VgCQ+IgL40EVwKUohT6pSWqQIs0Sf6bwcbkx/KM0e4gSiw7p4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102000; c=relaxed/simple; bh=LsLeqxYQgAybD6QcrWkUIw8mwMKm+WxkfDNLAHefl0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qp7To4+aX3uB/l03Se55IsIhNAZcXUMaJcMWLdasrhCzuzIavM3kmfnM2M1tp8g+7g208SBDmjz+dGWRVZ3kZxAoh2KaOLZ8XmDoFeUlQfm2l5shNsNFOkb5GpamW3MniYUx9qkmPwiH7wfjG3+kOfuYJ7RDmZtcgEWjqg87Zi4= 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=OAsQfy4m; arc=none smtp.client-ip=192.198.163.12 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="OAsQfy4m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790101999; x=1821637999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LsLeqxYQgAybD6QcrWkUIw8mwMKm+WxkfDNLAHefl0c=; b=OAsQfy4mMTsAsn/YLk6IU/4JDcs0KiSmWn5c2ZuQed69NeG2ytJPWeyM ayfEaj7r8O/HRzcXqDcHMkKF+x5IXztxW2nYY/KNtsDh98eVPa8gmxgc+ +LjeuL7/XqVbAHrCK0keA/gmFRCZDzC0rZhoEw9aU5A1iXrX/zFwXjjf0 K9T+Oyvd9pKS6CyuI6lSE6QqbeJ4TG3kDFiDKpBMHcxQJn3wxaub1WOWU quvFkD3ztb29v3zHEOYrqepDDPEmXtzMBWyiUTsZk+/l6lZMJD5oEdEHR oR8RLRkNS76Vr9RaREijuRGHMns/xVdlZD9t01DI4wNyl50ijtGmcaReH w==; X-CSE-ConnectionGUID: sLDiNNvZRE+NruV0U90cPA== X-CSE-MsgGUID: ZEoFh/r+S3i7MrfRyIJEIw== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564892" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564892" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -0700 X-CSE-ConnectionGUID: ohGRwNeHR+CwXnK5R8frYg== X-CSE-MsgGUID: d6dslco4QvuLKPCv5hrqFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827974" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -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 v1 04/10] platform/x86/intel/tpmi: Get tpmi_info directly from the parent device Date: Tue, 22 Sep 2026 11:33:05 -0700 Message-ID: <20260922183311.3783010-5-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 EA89C490C07; Tue, 22 Sep 2026 18:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102000; cv=none; b=Q39Y5cr/QvRJXzjBmyq8AApAuZWrvqgV0jbZKg04Dt41kCyUVuPoMGkUrkR8KGnZEJyj4aAtUTA2CJTbjqnIZa2kDn/46y6S24CWchEdJO59bgP7X+GjvoxT2lQ+ivuRBH7OSsJpWp7tUFFFVK3SX7CDseIlo/sY3Y/7kbnVcj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102000; c=relaxed/simple; bh=5+J9lJ3AvqQV2FjVBib/zG4wwMZuAyNQEHlOEjfss7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tJv/Z00Tb18eNYsJY/xRLf1iL/XjyrqvuDwN551wbVWWRlVJQri6jrYi0W/LH1c0/Wbiu0dRD/O+Hw4NaemVVONcqj/827I+PVpTX5z8wrDwwoe2Qbw8BcCcsicckaOEb8LnO5WM+4HvfxULTG9tQYYb1HaBvcYndkrnzCz4HlQ= 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=YAPUl133; arc=none smtp.client-ip=192.198.163.12 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="YAPUl133" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790101999; x=1821637999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5+J9lJ3AvqQV2FjVBib/zG4wwMZuAyNQEHlOEjfss7c=; b=YAPUl133QZGy9if9XMhplmVp/fk54B5swgaqP/GpxmRVoqE4d8gMiWMn TvMg6g7Ea8wcQ0PI20Bh1b/fxrvsG5TA6gFsHkps+VaR/hT5mBLEwWfk5 JoVO6FQwhQ/DNehtwGKniKjr9CcCx/uAW+uxX4mnKSN9cMUVElHow4/7A H/+wXqSVk0+xz8ybkFFsXd/weyJWQAMs2muJWm2johfEXRBeNL/W2rcQZ r3K9z1YxahL5S44T+tWofFfCVpjHO0UrNl82fC99F1ti4i/MZb2wcGLYG hmlHf//MziQ1H8zflrXsmuGpgGTIA5VdJSXuvcDyxCzGHIQN0NsWv4yB+ g==; X-CSE-ConnectionGUID: 49H2twEdSQuG8QDhqfKLdQ== X-CSE-MsgGUID: a/C99d6uSGOERqxyuoLNRQ== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564893" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564893" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -0700 X-CSE-ConnectionGUID: cGSl0ieZRoKiRVP+XqRoDQ== X-CSE-MsgGUID: JtvMqAmYSv2E4gPteQMYdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827978" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -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 v1 05/10] platform/x86/intel/tpmi: Keep the feature resources in intel_tpmi_info Date: Tue, 22 Sep 2026 11:33:06 -0700 Message-ID: <20260922183311.3783010-6-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 8E511485508; Tue, 22 Sep 2026 18:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102003; cv=none; b=VlV//na3/KMgD6wtgjFsdGtnU7qp/tba4SUWI/AqXBeH5/R2802ncp2JiuNMqivDOntGunaFAHcAZtCAjvxbDCyagHmZmUJCGV9YChR2fU35N/KTFCvcEBKnrxjBrOK0fOLlWakAlmdg5vviFtlRfC43eKHwehYcSvUFAfMq3GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102003; c=relaxed/simple; bh=yqnHQFFgG9HGV9s3Z+hWtHclzLx1oyNWvpKhmIRKOEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZE7CltqxB5wycL+J62yN6MezFhSmu2eIvIKmVBcHl0cWkob9Y8c0nUc/PgE8/dc3KfAFFrRFGe9JsR2bG6ERqmK6/cCgyrpCoHkxXPxiUrG4f3Y/snlHG9bsDIk4GwZVGLMS8m5sG6JNdBlUbmBxFc8GHBGfVyiJaTSBiNKZ9DA= 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=Gp3cOVJR; arc=none smtp.client-ip=192.198.163.12 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="Gp3cOVJR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790102000; x=1821638000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yqnHQFFgG9HGV9s3Z+hWtHclzLx1oyNWvpKhmIRKOEY=; b=Gp3cOVJRZXCLY4iHIDiGa8Rk83ok30blcRI/za5RsG+c7ERE7ak/WCDn WONIjutriBMJ63AAIE3v1yw57ZBDQKy8eTH8X1on6chDlrnHexaB89xcT UIqwfvAPmPpFWMatq296jdubcdLk2A+0KbFxdwPdUZnrgE52lOA/55j7Z IrKnsuEbxO+gXWvF+8ukNsX7/EHrI6+i2glt5YyKBJZZtSUfLxn6YoQyG ZCj09pEMBTZkroXdt6lVkC8QqJ4LgWqcHeIrMm7gPMbufvBqdWEZ42twc 8gy/y05qmsAisj7hsuI8RrIIUErevrJWPJYLe+COmfOrJ/n7rytK55V8H A==; X-CSE-ConnectionGUID: fXitUszeSyqwgjpoq5OX3g== X-CSE-MsgGUID: 1Qyfrw6iQQefgNN9xknXmg== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564895" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564895" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -0700 X-CSE-ConnectionGUID: eIT8MmkoRJyTtX8HEuGUeA== X-CSE-MsgGUID: sr9/g0XASNKbnTMXCY7ESw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827982" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -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 v1 06/10] platform/x86/intel/tpmi: Describe a TPMI instance by its two devices Date: Tue, 22 Sep 2026 11:33:07 -0700 Message-ID: <20260922183311.3783010-7-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 EF12B4915AF; Tue, 22 Sep 2026 18:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102001; cv=none; b=sdtV8XQvXMCJM2xHbK3vfwwrRu4mLkbpuAgOX3Ah6qz7mT99pezJfYCm/5FYgrgmWguxkwty/1azkE7Cs77xyIecX2oVJm4rPKEu5xIY/2yfUoYjozW2b0zyR4aDuJJWM9riatrsu8xrR5wHRwrHdXqRj/yTkWmkFcvbZ6lTgDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102001; c=relaxed/simple; bh=TKLJqwOdfqdczTZY63mKSLHqDkP1wnzAjiDjiaAxGBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSVCYanveoY6dAb1SyvilT378R8jhdsaCIPH9fz70PyUGNhbpFXMxshyS/z9ukT4o2R7yFaywbpRJEk3b6rThx5c6qKQW9r2op4JP342Ixit97YXssGkemMMhHWyyXdAdIdvCOPaEoZ2PNtHSTgHFjilo/3tYUdcWWc9Y41FwKk= 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=Hjosn7EI; arc=none smtp.client-ip=192.198.163.12 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="Hjosn7EI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790102000; x=1821638000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TKLJqwOdfqdczTZY63mKSLHqDkP1wnzAjiDjiaAxGBc=; b=Hjosn7EIm2RRZpSECkkEo9TWu99EXCV4SIUWoflmUhaOX5EH5JHVXbPO 342ORCaZWm0/HYtDJvAW6O+hU65xtopPIg6HoO8b29+9jwpT3qGyzlCVC RFi35ZbFu8LHhULAicdKdURwrC9AzqLL71pLyO1ghMbceEE7vxupIzC15 6C0WWt7ANNINKxj4H04ahTzibQKPD2wQHHxjq43MzQYW7Wy1PhwC08BE4 x/Z0zpnFD5yne7di8YTQosvY2julh1qdwcJjXsUnv+drdY3/p/HlGiAZs ibebjqyHUw/2Zzld1fB2URGvicS4yC0XZTQ6AvZVstKCJItHyj4vt+HH0 A==; X-CSE-ConnectionGUID: neujAO7jRuinZ6/BwMJ7EA== X-CSE-MsgGUID: SGWsfOngQYWHzX5HzRCAOw== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564897" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564897" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -0700 X-CSE-ConnectionGUID: B0lNkeUbRPywwyFbxzT6nw== X-CSE-MsgGUID: vEBiotfzQEOySuYus6PpnQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827990" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -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 v1 07/10] platform/x86/intel/tpmi: Drop unused arg from tpmi_set_control_base() Date: Tue, 22 Sep 2026 11:33:08 -0700 Message-ID: <20260922183311.3783010-8-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 D9FA9494809; Tue, 22 Sep 2026 18:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102002; cv=none; b=o5Cw26fjRqczwB157J4a3XTBiY/Z3aEXJzOsucsex/enlZ85hy3nJd9SvY2Ly/ML0yBL6YHQr9BMOTVDSKqNi7ztjVko1DkBpiigwZYLnHzrtpTFOTIp5w86CZH+OwvCSKnpqOc2yJyYsLiRibfbAL9c5Hw9KU+IF1sp967mrT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102002; c=relaxed/simple; bh=XNY5cqhovtfO0VevlMS7pV1QbAxZrJbMrLg0DPVdyog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G/aQ0ce3ccqKuiB2pWNZ0PNnGPD/52Tkx3Z7P6MePC1YWqzREPiu2B5InHB0OEQLm4Xkpu9E/DF4OPVjIoEg9NmNvrzOREINvlpn6suG6Y6vOnOglZqihylUg+uvJTC6AzqBiv/Ixurj+WnL8pSLt0oQWB78fU3gY9IdK1kciaQ= 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=l4i3Q9ze; arc=none smtp.client-ip=192.198.163.12 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="l4i3Q9ze" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790102001; x=1821638001; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XNY5cqhovtfO0VevlMS7pV1QbAxZrJbMrLg0DPVdyog=; b=l4i3Q9zeD8g2oGPw1OT5XYJ6hZQZbTQab47G4uuIBUfif7HMMQIZzT5c UMqlHPkOtNS1BMBgg91LzgECOdLobZOHHJW5yILozNNzXBSaFejRRczYL qDbueoTRRYV4alLGEI4RcQpAXs37xEg+PaOEsZ08YngYTo/YFHZOja7VS e1I9OxrzEt/cbPg5/2X++e5azyvMq/kyU7TEtFp74vufSqAdGVg6ikTpk lku7QXZOYX/+7ak70pdqSYRhy16/OtlvfQpHcaCsxomGBaAJlaomZ2ahO tmmPr5m6WZzlJmdCiOFn4rPDmN8XMwOrMqcSM/ymchY2vW6xfrJtYVOzD w==; X-CSE-ConnectionGUID: WPO/fqW2SS6ihX4ZWZMacw== X-CSE-MsgGUID: STRgjMI5ROmZ8HtOzoJtSw== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564899" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564899" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -0700 X-CSE-ConnectionGUID: TqY4/thwQF66/iwRK7buhw== X-CSE-MsgGUID: eDPVsGvaTe6MUxSlW2EIcQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827993" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:15 -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 v1 08/10] platform/x86/intel/tpmi: Do not assume TPMI is enumerated from PCI Date: Tue, 22 Sep 2026 11:33:09 -0700 Message-ID: <20260922183311.3783010-9-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 DE7FE496D28; Tue, 22 Sep 2026 18:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102003; cv=none; b=dwH7Q3X+6gD0XAb8xhdl2GQqErOkjGXZ4awLbuLiPddrz5VgIvAS1DtqTuj2Ehd670WT8vTvDjf4npvYMdl47d5KwlMA3oYITRPLPnaFMbr3SPlbhGY6XcbSCwzJDi72u6rce/yXMEVy+BdxVeYAT92YQ6CQh6SGmmnPCBdtZYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102003; c=relaxed/simple; bh=yuNyo/2MR7p6Nj40k7IruL1gpNaVM6knfhPXm5uIzDo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWY5P1Ix5xCuBClbC5KIyWzpAgqpNnLeAsAdo6Jh+dwPBZplsxorH+jSlbAMXg/zlgKxS0Y81CuMMe0pvtodmiZ7ythlkR2LFawh7Rdx6xZVtpjDh04QRE2Kb3Aa4ZakWsETflfCyQJv/N0WF5WixLb8kJ0nSFkxet25amEMomU= 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=dslpWEZt; arc=none smtp.client-ip=192.198.163.12 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="dslpWEZt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790102002; x=1821638002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yuNyo/2MR7p6Nj40k7IruL1gpNaVM6knfhPXm5uIzDo=; b=dslpWEZtyYfJYpXYb6KXk7brFWdefeVueVu86+HpX/NdSWQke/yuJEU5 GkSTYfnEXappGnCIfygHk3qxwcF2WEghaqv6V5jjv10Ad2hHVAzWu8Jpy wgvamg338lmlR4kHM8PMSQqqT53jn43bbH89cDnNjn+XZOUbWrZ6uqoRE IvkmSzZ6LmeVIbCfzp6TwweSjqEJ6XX0AV4H70LL7Xiwda0puAG/M7WCN I+HhsJ1TA3PBm9FsydJxUK1DI3LauOJPNsbTgihnH3d0sT7qPsdQ5v1dk c2oWBsm3Hx73jrN1ZMUS+rJroUyRje5DAeCqJQhEUyZ8axXXDeDQyVfkQ g==; X-CSE-ConnectionGUID: IHuiZZgQQpeAkMmMiAKskg== X-CSE-MsgGUID: v3dsYHmpT76/lYp7hCIbnQ== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564901" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564901" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -0700 X-CSE-ConnectionGUID: ZCb/zok+RBahobyBh924VA== X-CSE-MsgGUID: ECbhDH1gQ02s18amAlxO3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271827997" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -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 v1 09/10] platform/x86/intel/tpmi: Split out enumeration independent init and exit Date: Tue, 22 Sep 2026 11:33:10 -0700 Message-ID: <20260922183311.3783010-10-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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 Thu Sep 24 15:11:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 A73C4499F25; Tue, 22 Sep 2026 18:33:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102007; cv=none; b=FD76Nz3B449GQLWc9VMyD94LzEGLvSLPNJKJFLrrVdx1qsV9LL2snnUI4qOUfsicchYHq9VQm59wD+NUeiMlf51e3OOZrOgTHh3bfME57BKprooDsOIuStyBTIoded8HUdyZtDkdkVIDiXFAGwXiTLqxu056LAycBkNEzUclogM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790102007; c=relaxed/simple; bh=ed4aqXqEP+CGPOgR0mxhP5zimDUjg1WcYDhJ9CUCauA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aZ5XAD/K+NrH+DhYFHJCy4SJZEYp1xPhMBC9F7iWGct2uIVIcVAmt/ewtQzpcxTgAemKSZgTnYwL6CBG7fJD7T1I5wHe0jUoNOEnHDIuXRgFlyC0z7xSmKsoNVhl14kVdaXdNFPOt7dwHeZ3TQQ2sktpNZIZWuD1i0kr8UFkibk= 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=ZKReQ4HM; arc=none smtp.client-ip=192.198.163.12 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="ZKReQ4HM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790102003; x=1821638003; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ed4aqXqEP+CGPOgR0mxhP5zimDUjg1WcYDhJ9CUCauA=; b=ZKReQ4HMgA35B/PbNC79c+TrR+m3yt2gtvZbBy2ZL0v5+IZ0Lmz71R/c kG72vJw1eJAH9BXk0Mtf1TSq3VEytg6C6bys14P0CrsDwj96JqmkQYAjc OjiYp+Lpm8Mj1XiDA2hT6kEvrnQMH3uQ1j5uC6AJ7QcixbzCE/tl50Mqq /etYjskJ4GfzdKKDevK0rTghOyTS5rrRNRaj4UTs/+jl2lbQpG2WvsvyN xA1adtS6M95fE2DOdRZ4ZEjO4vm5WFX4VrR4bP88D/+sBtNdFes9Uecsm H8DuddjmoOTXDFg2R3If59z2iMd2+5p2P16ve8OV25Vf8zLMOHvDiTtDy g==; X-CSE-ConnectionGUID: jBKUlEsKSgKlAjiDEvlu0Q== X-CSE-MsgGUID: kXLscX/OTnOVUx3U+DU2aA== X-IronPort-AV: E=McAfee;i="6800,10657,11913"; a="94564904" X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="94564904" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -0700 X-CSE-ConnectionGUID: xewXtiIkQeqtM72SPjgnUA== X-CSE-MsgGUID: ChAEOUr2S2m8Yh5vLYA1Ig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,117,1787036400"; d="scan'208";a="271828006" Received: from skuppusw-desk2.jf.intel.com ([10.165.154.101]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2026 11:33:16 -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 v1 10/10] platform/x86/intel/tpmi: Split off the PCI VSEC enumeration Date: Tue, 22 Sep 2026 11:33:11 -0700 Message-ID: <20260922183311.3783010-11-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260922183311.3783010-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20260922183311.3783010-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 Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko --- 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