[PATCH v2 09/19] platform/x86/intel/tpmi: Split out enumeration independent init and exit

From: Kuppuswamy Sathyanarayanan

Date: Thu Sep 24 2026 - 14:32:47 EST


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 <srinivas.pandruvada@xxxxxxxxxxxxxxx>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@xxxxxxxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
---
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

#define TPMI_CAP_OFFSET_UNIT 1024

-static int intel_vsec_tpmi_init(struct auxiliary_device *auxdev)
+static int intel_tpmi_init(struct intel_tpmi_info *tpmi_info, struct device *tpmi_dev,
+ struct device *parent, struct resource *resource,
+ int feature_count)
{
- struct intel_vsec_device *vsec_dev = auxdev_to_ivdev(auxdev);
- struct pci_dev *pci_dev = dev_is_pci(vsec_dev->dev) ?
- to_pci_dev(vsec_dev->dev) : NULL;
- struct intel_tpmi_info *tpmi_info;
+ struct pci_dev *pci_dev = dev_is_pci(parent) ? to_pci_dev(parent) : NULL;
u64 pfs_start = 0;
int ret, i;

- tpmi_info = devm_kzalloc(&auxdev->dev, sizeof(*tpmi_info), GFP_KERNEL);
- if (!tpmi_info)
- return -ENOMEM;
-
- tpmi_info->tpmi_dev = &auxdev->dev;
- tpmi_info->parent = vsec_dev->dev;
- tpmi_info->feature_count = vsec_dev->num_resources;
- tpmi_info->resource = vsec_dev->resource;
+ tpmi_info->tpmi_dev = tpmi_dev;
+ tpmi_info->parent = parent;
+ tpmi_info->feature_count = feature_count;
+ tpmi_info->resource = resource;

/*
* 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 = pci_dev->bus->number;

- tpmi_info->tpmi_features = devm_kcalloc(&auxdev->dev, tpmi_info->feature_count,
+ tpmi_info->tpmi_features = 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)

tpmi_info->pfs_start = pfs_start;

- auxiliary_set_drvdata(auxdev, tpmi_info);
+ dev_set_drvdata(tpmi_info->tpmi_dev, tpmi_info);

/*
* Allow debugfs when security policy allows. Everything this debugfs
@@ -844,24 +839,37 @@ static int intel_vsec_tpmi_init(struct auxiliary_device *auxdev)
return ret;
}

- 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);

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);
+}
+
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 = auxdev_to_ivdev(auxdev);
+ struct intel_tpmi_info *tpmi_info;
+
+ tpmi_info = 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);
}

static void tpmi_remove(struct auxiliary_device *auxdev)
{
struct intel_tpmi_info *tpmi_info = auxiliary_get_drvdata(auxdev);

- blocking_notifier_call_chain(&tpmi_notify_list, TPMI_CORE_EXIT, auxdev);
-
- debugfs_remove_recursive(tpmi_info->dbgfs_dir);
+ intel_tpmi_deinit(tpmi_info);
}

static const struct auxiliary_device_id tpmi_id_table[] = {
--
2.43.0