mirror of
https://github.com/torvalds/linux.git
synced 2024-11-28 23:21:31 +00:00
eb5555d422
On unloading of the scmi_perf_domain module got the below splat, when in
the DT provided to the system under test the '#power-domain-cells' property
was missing. Indeed, this particular setup causes the probe to bail out
early without giving any error, which leads to the ->remove() callback gets
to run too, but without all the expected initialized structures in place.
Add a check and bail out early on remove too.
Call trace:
scmi_perf_domain_remove+0x28/0x70 [scmi_perf_domain]
scmi_dev_remove+0x28/0x40 [scmi_core]
device_remove+0x54/0x90
device_release_driver_internal+0x1dc/0x240
driver_detach+0x58/0xa8
bus_remove_driver+0x78/0x108
driver_unregister+0x38/0x70
scmi_driver_unregister+0x28/0x180 [scmi_core]
scmi_perf_domain_driver_exit+0x18/0xb78 [scmi_perf_domain]
__arm64_sys_delete_module+0x1a8/0x2c0
invoke_syscall+0x50/0x128
el0_svc_common.constprop.0+0x48/0xf0
do_el0_svc+0x24/0x38
el0_svc+0x34/0xb8
el0t_64_sync_handler+0x100/0x130
el0t_64_sync+0x190/0x198
Code: a90153f3 f9403c14 f9414800 955f8a05 (b9400a80)
---[ end trace 0000000000000000 ]---
Fixes: 2af23ceb86
("pmdomain: arm: Add the SCMI performance domain")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240125191756.868860-1-cristian.marussi@arm.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
188 lines
4.5 KiB
C
188 lines
4.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* SCMI performance domain support.
|
|
*
|
|
* Copyright (C) 2023 Linaro Ltd.
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pm_domain.h>
|
|
#include <linux/pm_opp.h>
|
|
#include <linux/scmi_protocol.h>
|
|
#include <linux/slab.h>
|
|
|
|
struct scmi_perf_domain {
|
|
struct generic_pm_domain genpd;
|
|
const struct scmi_perf_proto_ops *perf_ops;
|
|
const struct scmi_protocol_handle *ph;
|
|
const struct scmi_perf_domain_info *info;
|
|
u32 domain_id;
|
|
};
|
|
|
|
#define to_scmi_pd(pd) container_of(pd, struct scmi_perf_domain, genpd)
|
|
|
|
static int
|
|
scmi_pd_set_perf_state(struct generic_pm_domain *genpd, unsigned int state)
|
|
{
|
|
struct scmi_perf_domain *pd = to_scmi_pd(genpd);
|
|
int ret;
|
|
|
|
if (!pd->info->set_perf)
|
|
return 0;
|
|
|
|
if (!state)
|
|
return -EINVAL;
|
|
|
|
ret = pd->perf_ops->level_set(pd->ph, pd->domain_id, state, false);
|
|
if (ret)
|
|
dev_warn(&genpd->dev, "Failed with %d when trying to set %d perf level",
|
|
ret, state);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int
|
|
scmi_pd_attach_dev(struct generic_pm_domain *genpd, struct device *dev)
|
|
{
|
|
struct scmi_perf_domain *pd = to_scmi_pd(genpd);
|
|
int ret;
|
|
|
|
/*
|
|
* Allow the device to be attached, but don't add the OPP table unless
|
|
* the performance level can be changed.
|
|
*/
|
|
if (!pd->info->set_perf)
|
|
return 0;
|
|
|
|
ret = pd->perf_ops->device_opps_add(pd->ph, dev, pd->domain_id);
|
|
if (ret)
|
|
dev_warn(dev, "failed to add OPPs for the device\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void
|
|
scmi_pd_detach_dev(struct generic_pm_domain *genpd, struct device *dev)
|
|
{
|
|
struct scmi_perf_domain *pd = to_scmi_pd(genpd);
|
|
|
|
if (!pd->info->set_perf)
|
|
return;
|
|
|
|
dev_pm_opp_remove_all_dynamic(dev);
|
|
}
|
|
|
|
static int scmi_perf_domain_probe(struct scmi_device *sdev)
|
|
{
|
|
struct device *dev = &sdev->dev;
|
|
const struct scmi_handle *handle = sdev->handle;
|
|
const struct scmi_perf_proto_ops *perf_ops;
|
|
struct scmi_protocol_handle *ph;
|
|
struct scmi_perf_domain *scmi_pd;
|
|
struct genpd_onecell_data *scmi_pd_data;
|
|
struct generic_pm_domain **domains;
|
|
int num_domains, i, ret = 0;
|
|
|
|
if (!handle)
|
|
return -ENODEV;
|
|
|
|
/* The OF node must specify us as a power-domain provider. */
|
|
if (!of_find_property(dev->of_node, "#power-domain-cells", NULL))
|
|
return 0;
|
|
|
|
perf_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PERF, &ph);
|
|
if (IS_ERR(perf_ops))
|
|
return PTR_ERR(perf_ops);
|
|
|
|
num_domains = perf_ops->num_domains_get(ph);
|
|
if (num_domains < 0) {
|
|
dev_warn(dev, "Failed with %d when getting num perf domains\n",
|
|
num_domains);
|
|
return num_domains;
|
|
} else if (!num_domains) {
|
|
return 0;
|
|
}
|
|
|
|
scmi_pd = devm_kcalloc(dev, num_domains, sizeof(*scmi_pd), GFP_KERNEL);
|
|
if (!scmi_pd)
|
|
return -ENOMEM;
|
|
|
|
scmi_pd_data = devm_kzalloc(dev, sizeof(*scmi_pd_data), GFP_KERNEL);
|
|
if (!scmi_pd_data)
|
|
return -ENOMEM;
|
|
|
|
domains = devm_kcalloc(dev, num_domains, sizeof(*domains), GFP_KERNEL);
|
|
if (!domains)
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < num_domains; i++, scmi_pd++) {
|
|
scmi_pd->info = perf_ops->info_get(ph, i);
|
|
|
|
scmi_pd->domain_id = i;
|
|
scmi_pd->perf_ops = perf_ops;
|
|
scmi_pd->ph = ph;
|
|
scmi_pd->genpd.name = scmi_pd->info->name;
|
|
scmi_pd->genpd.flags = GENPD_FLAG_ALWAYS_ON |
|
|
GENPD_FLAG_OPP_TABLE_FW;
|
|
scmi_pd->genpd.set_performance_state = scmi_pd_set_perf_state;
|
|
scmi_pd->genpd.attach_dev = scmi_pd_attach_dev;
|
|
scmi_pd->genpd.detach_dev = scmi_pd_detach_dev;
|
|
|
|
ret = pm_genpd_init(&scmi_pd->genpd, NULL, false);
|
|
if (ret)
|
|
goto err;
|
|
|
|
domains[i] = &scmi_pd->genpd;
|
|
}
|
|
|
|
scmi_pd_data->domains = domains;
|
|
scmi_pd_data->num_domains = num_domains;
|
|
|
|
ret = of_genpd_add_provider_onecell(dev->of_node, scmi_pd_data);
|
|
if (ret)
|
|
goto err;
|
|
|
|
dev_set_drvdata(dev, scmi_pd_data);
|
|
dev_info(dev, "Initialized %d performance domains", num_domains);
|
|
return 0;
|
|
err:
|
|
for (i--; i >= 0; i--)
|
|
pm_genpd_remove(domains[i]);
|
|
return ret;
|
|
}
|
|
|
|
static void scmi_perf_domain_remove(struct scmi_device *sdev)
|
|
{
|
|
struct device *dev = &sdev->dev;
|
|
struct genpd_onecell_data *scmi_pd_data = dev_get_drvdata(dev);
|
|
int i;
|
|
|
|
if (!scmi_pd_data)
|
|
return;
|
|
|
|
of_genpd_del_provider(dev->of_node);
|
|
|
|
for (i = 0; i < scmi_pd_data->num_domains; i++)
|
|
pm_genpd_remove(scmi_pd_data->domains[i]);
|
|
}
|
|
|
|
static const struct scmi_device_id scmi_id_table[] = {
|
|
{ SCMI_PROTOCOL_PERF, "perf" },
|
|
{ },
|
|
};
|
|
MODULE_DEVICE_TABLE(scmi, scmi_id_table);
|
|
|
|
static struct scmi_driver scmi_perf_domain_driver = {
|
|
.name = "scmi-perf-domain",
|
|
.probe = scmi_perf_domain_probe,
|
|
.remove = scmi_perf_domain_remove,
|
|
.id_table = scmi_id_table,
|
|
};
|
|
module_scmi_driver(scmi_perf_domain_driver);
|
|
|
|
MODULE_AUTHOR("Ulf Hansson <ulf.hansson@linaro.org>");
|
|
MODULE_DESCRIPTION("ARM SCMI perf domain driver");
|
|
MODULE_LICENSE("GPL v2");
|