summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/arch_topology.c107
-rw-r--r--drivers/base/auxiliary.c2
-rw-r--r--drivers/base/bus.c8
-rw-r--r--drivers/base/container.c2
-rw-r--r--drivers/base/core.c50
-rw-r--r--drivers/base/cpu.c39
-rw-r--r--drivers/base/dd.c2
-rw-r--r--drivers/base/firmware_loader/sysfs_upload.c1
-rw-r--r--drivers/base/init.c2
-rw-r--r--drivers/base/isa.c2
-rw-r--r--drivers/base/memory.c2
-rw-r--r--drivers/base/node.c20
-rw-r--r--drivers/base/power/Makefile1
-rw-r--r--drivers/base/power/clock_ops.c2
-rw-r--r--drivers/base/power/domain.c3433
-rw-r--r--drivers/base/power/domain_governor.c414
-rw-r--r--drivers/base/power/main.c117
-rw-r--r--drivers/base/power/qos.c2
-rw-r--r--drivers/base/power/runtime.c1
-rw-r--r--drivers/base/property.c66
-rw-r--r--drivers/base/regmap/internal.h1
-rw-r--r--drivers/base/regmap/regcache-maple.c6
-rw-r--r--drivers/base/regmap/regmap-debugfs.c8
-rw-r--r--drivers/base/regmap/regmap-kunit.c61
-rw-r--r--drivers/base/regmap/regmap-ram.c4
-rw-r--r--drivers/base/regmap/regmap-raw-ram.c31
-rw-r--r--drivers/base/regmap/regmap.c2
-rw-r--r--drivers/base/soc.c6
-rw-r--r--drivers/base/swnode.c8
29 files changed, 394 insertions, 4006 deletions
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index b741b5ba82..024b78a0cf 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -19,6 +19,7 @@
#include <linux/init.h>
#include <linux/rcupdate.h>
#include <linux/sched.h>
+#include <linux/units.h>
#define CREATE_TRACE_POINTS
#include <trace/events/thermal_pressure.h>
@@ -26,7 +27,8 @@
static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data);
static struct cpumask scale_freq_counters_mask;
static bool scale_freq_invariant;
-static DEFINE_PER_CPU(u32, freq_factor) = 1;
+DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 1;
+EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref);
static bool supports_scale_freq_counters(const struct cpumask *cpus)
{
@@ -170,9 +172,9 @@ DEFINE_PER_CPU(unsigned long, thermal_pressure);
* operating on stale data when hot-plug is used for some CPUs. The
* @capped_freq reflects the currently allowed max CPUs frequency due to
* thermal capping. It might be also a boost frequency value, which is bigger
- * than the internal 'freq_factor' max frequency. In such case the pressure
- * value should simply be removed, since this is an indication that there is
- * no thermal throttling. The @capped_freq must be provided in kHz.
+ * than the internal 'capacity_freq_ref' max frequency. In such case the
+ * pressure value should simply be removed, since this is an indication that
+ * there is no thermal throttling. The @capped_freq must be provided in kHz.
*/
void topology_update_thermal_pressure(const struct cpumask *cpus,
unsigned long capped_freq)
@@ -183,10 +185,7 @@ void topology_update_thermal_pressure(const struct cpumask *cpus,
cpu = cpumask_first(cpus);
max_capacity = arch_scale_cpu_capacity(cpu);
- max_freq = per_cpu(freq_factor, cpu);
-
- /* Convert to MHz scale which is used in 'freq_factor' */
- capped_freq /= 1000;
+ max_freq = arch_scale_freq_ref(cpu);
/*
* Handle properly the boost frequencies, which should simply clean
@@ -220,20 +219,34 @@ static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
static DEVICE_ATTR_RO(cpu_capacity);
-static int register_cpu_capacity_sysctl(void)
+static int cpu_capacity_sysctl_add(unsigned int cpu)
{
- int i;
- struct device *cpu;
+ struct device *cpu_dev = get_cpu_device(cpu);
- for_each_possible_cpu(i) {
- cpu = get_cpu_device(i);
- if (!cpu) {
- pr_err("%s: too early to get CPU%d device!\n",
- __func__, i);
- continue;
- }
- device_create_file(cpu, &dev_attr_cpu_capacity);
- }
+ if (!cpu_dev)
+ return -ENOENT;
+
+ device_create_file(cpu_dev, &dev_attr_cpu_capacity);
+
+ return 0;
+}
+
+static int cpu_capacity_sysctl_remove(unsigned int cpu)
+{
+ struct device *cpu_dev = get_cpu_device(cpu);
+
+ if (!cpu_dev)
+ return -ENOENT;
+
+ device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
+
+ return 0;
+}
+
+static int register_cpu_capacity_sysctl(void)
+{
+ cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
+ cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
return 0;
}
@@ -279,13 +292,13 @@ void topology_normalize_cpu_scale(void)
capacity_scale = 1;
for_each_possible_cpu(cpu) {
- capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu);
+ capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu);
capacity_scale = max(capacity, capacity_scale);
}
pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale);
for_each_possible_cpu(cpu) {
- capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu);
+ capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu);
capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT,
capacity_scale);
topology_set_cpu_scale(cpu, capacity);
@@ -321,15 +334,15 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
cpu_node, raw_capacity[cpu]);
/*
- * Update freq_factor for calculating early boot cpu capacities.
+ * Update capacity_freq_ref for calculating early boot CPU capacities.
* For non-clk CPU DVFS mechanism, there's no way to get the
* frequency value now, assuming they are running at the same
- * frequency (by keeping the initial freq_factor value).
+ * frequency (by keeping the initial capacity_freq_ref value).
*/
cpu_clk = of_clk_get(cpu_node, 0);
if (!PTR_ERR_OR_ZERO(cpu_clk)) {
- per_cpu(freq_factor, cpu) =
- clk_get_rate(cpu_clk) / 1000;
+ per_cpu(capacity_freq_ref, cpu) =
+ clk_get_rate(cpu_clk) / HZ_PER_KHZ;
clk_put(cpu_clk);
}
} else {
@@ -345,11 +358,16 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
return !ret;
}
+void __weak freq_inv_set_max_ratio(int cpu, u64 max_rate)
+{
+}
+
#ifdef CONFIG_ACPI_CPPC_LIB
#include <acpi/cppc_acpi.h>
void topology_init_cpu_capacity_cppc(void)
{
+ u64 capacity, capacity_scale = 0;
struct cppc_perf_caps perf_caps;
int cpu;
@@ -366,6 +384,10 @@ void topology_init_cpu_capacity_cppc(void)
(perf_caps.highest_perf >= perf_caps.nominal_perf) &&
(perf_caps.highest_perf >= perf_caps.lowest_perf)) {
raw_capacity[cpu] = perf_caps.highest_perf;
+ capacity_scale = max_t(u64, capacity_scale, raw_capacity[cpu]);
+
+ per_cpu(capacity_freq_ref, cpu) = cppc_perf_to_khz(&perf_caps, raw_capacity[cpu]);
+
pr_debug("cpu_capacity: CPU%d cpu_capacity=%u (raw).\n",
cpu, raw_capacity[cpu]);
continue;
@@ -376,7 +398,18 @@ void topology_init_cpu_capacity_cppc(void)
goto exit;
}
- topology_normalize_cpu_scale();
+ for_each_possible_cpu(cpu) {
+ freq_inv_set_max_ratio(cpu,
+ per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ);
+
+ capacity = raw_capacity[cpu];
+ capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT,
+ capacity_scale);
+ topology_set_cpu_scale(cpu, capacity);
+ pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n",
+ cpu, topology_get_cpu_scale(cpu));
+ }
+
schedule_work(&update_topology_flags_work);
pr_debug("cpu_capacity: cpu_capacity initialization done\n");
@@ -398,9 +431,6 @@ init_cpu_capacity_callback(struct notifier_block *nb,
struct cpufreq_policy *policy = data;
int cpu;
- if (!raw_capacity)
- return 0;
-
if (val != CPUFREQ_CREATE_POLICY)
return 0;
@@ -410,13 +440,18 @@ init_cpu_capacity_callback(struct notifier_block *nb,
cpumask_andnot(cpus_to_visit, cpus_to_visit, policy->related_cpus);
- for_each_cpu(cpu, policy->related_cpus)
- per_cpu(freq_factor, cpu) = policy->cpuinfo.max_freq / 1000;
+ for_each_cpu(cpu, policy->related_cpus) {
+ per_cpu(capacity_freq_ref, cpu) = policy->cpuinfo.max_freq;
+ freq_inv_set_max_ratio(cpu,
+ per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ);
+ }
if (cpumask_empty(cpus_to_visit)) {
- topology_normalize_cpu_scale();
- schedule_work(&update_topology_flags_work);
- free_raw_capacity();
+ if (raw_capacity) {
+ topology_normalize_cpu_scale();
+ schedule_work(&update_topology_flags_work);
+ free_raw_capacity();
+ }
pr_debug("cpu_capacity: parsing done\n");
schedule_work(&parsing_done_work);
}
@@ -436,7 +471,7 @@ static int __init register_cpufreq_notifier(void)
* On ACPI-based systems skip registering cpufreq notifier as cpufreq
* information is not needed for cpu capacity initialization.
*/
- if (!acpi_disabled || !raw_capacity)
+ if (!acpi_disabled)
return -EINVAL;
if (!alloc_cpumask_var(&cpus_to_visit, GFP_KERNEL))
diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
index 4d4c2c8d26..d3a2c40c2f 100644
--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -244,7 +244,7 @@ static void auxiliary_bus_shutdown(struct device *dev)
auxdrv->shutdown(auxdev);
}
-static struct bus_type auxiliary_bus_type = {
+static const struct bus_type auxiliary_bus_type = {
.name = "auxiliary",
.probe = auxiliary_bus_probe,
.remove = auxiliary_bus_remove,
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 84a21084d6..daee55c9b2 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -1030,7 +1030,7 @@ static void device_insertion_sort_klist(struct device *a, struct list_head *list
list_move_tail(&a->p->knode_bus.n_node, list);
}
-void bus_sort_breadthfirst(struct bus_type *bus,
+void bus_sort_breadthfirst(const struct bus_type *bus,
int (*compare)(const struct device *a,
const struct device *b))
{
@@ -1194,7 +1194,7 @@ static void system_root_device_release(struct device *dev)
kfree(dev);
}
-static int subsys_register(struct bus_type *subsys,
+static int subsys_register(const struct bus_type *subsys,
const struct attribute_group **groups,
struct kobject *parent_of_root)
{
@@ -1264,7 +1264,7 @@ err_sp:
* directory itself and not some create fake root-device placed in
* /sys/devices/system/<name>.
*/
-int subsys_system_register(struct bus_type *subsys,
+int subsys_system_register(const struct bus_type *subsys,
const struct attribute_group **groups)
{
return subsys_register(subsys, groups, &system_kset->kobj);
@@ -1282,7 +1282,7 @@ EXPORT_SYMBOL_GPL(subsys_system_register);
* There's no restriction on device naming. This is for kernel software
* constructs which need sysfs interface.
*/
-int subsys_virtual_register(struct bus_type *subsys,
+int subsys_virtual_register(const struct bus_type *subsys,
const struct attribute_group **groups)
{
struct kobject *virtual_dir;
diff --git a/drivers/base/container.c b/drivers/base/container.c
index 1ba42d2d35..f40588ebc3 100644
--- a/drivers/base/container.c
+++ b/drivers/base/container.c
@@ -24,7 +24,7 @@ static int container_offline(struct device *dev)
return cdev->offline ? cdev->offline(cdev) : 0;
}
-struct bus_type container_subsys = {
+const struct bus_type container_subsys = {
.name = CONTAINER_BUS_NAME,
.dev_name = CONTAINER_BUS_NAME,
.online = trivial_online,
diff --git a/drivers/base/core.c b/drivers/base/core.c
index f9fb692491..7f39c813ce 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -44,6 +44,7 @@ static bool fw_devlink_is_permissive(void);
static void __fw_devlink_link_to_consumers(struct device *dev);
static bool fw_devlink_drv_reg_done;
static bool fw_devlink_best_effort;
+static struct workqueue_struct *device_link_wq;
/**
* __fwnode_link_add - Create a link between two fwnode_handles.
@@ -125,7 +126,7 @@ static void __fwnode_link_del(struct fwnode_link *link)
*/
static void __fwnode_link_cycle(struct fwnode_link *link)
{
- pr_debug("%pfwf: Relaxing link with %pfwf\n",
+ pr_debug("%pfwf: cycle: depends on %pfwf\n",
link->consumer, link->supplier);
link->flags |= FWLINK_FLAG_CYCLE;
}
@@ -300,7 +301,7 @@ static inline bool device_link_flag_is_sync_state_only(u32 flags)
* Check if @target depends on @dev or any device dependent on it (its child or
* its consumer etc). Return 1 if that is the case or 0 otherwise.
*/
-int device_is_dependent(struct device *dev, void *target)
+static int device_is_dependent(struct device *dev, void *target)
{
struct device_link *link;
int ret;
@@ -532,12 +533,26 @@ static void devlink_dev_release(struct device *dev)
/*
* It may take a while to complete this work because of the SRCU
* synchronization in device_link_release_fn() and if the consumer or
- * supplier devices get deleted when it runs, so put it into the "long"
- * workqueue.
+ * supplier devices get deleted when it runs, so put it into the
+ * dedicated workqueue.
*/
- queue_work(system_long_wq, &link->rm_work);
+ queue_work(device_link_wq, &link->rm_work);
}
+/**
+ * device_link_wait_removal - Wait for ongoing devlink removal jobs to terminate
+ */
+void device_link_wait_removal(void)
+{
+ /*
+ * devlink removal jobs are queued in the dedicated work queue.
+ * To be sure that all removal jobs are terminated, ensure that any
+ * scheduled work has run to completion.
+ */
+ flush_workqueue(device_link_wq);
+}
+EXPORT_SYMBOL_GPL(device_link_wait_removal);
+
static struct class devlink_class = {
.name = "devlink",
.dev_groups = devlink_groups,
@@ -1643,7 +1658,7 @@ static void device_links_purge(struct device *dev)
#define FW_DEVLINK_FLAGS_RPM (FW_DEVLINK_FLAGS_ON | \
DL_FLAG_PM_RUNTIME)
-static u32 fw_devlink_flags = FW_DEVLINK_FLAGS_ON;
+static u32 fw_devlink_flags = FW_DEVLINK_FLAGS_RPM;
static int __init fw_devlink_setup(char *arg)
{
if (!arg)
@@ -1945,6 +1960,7 @@ static bool __fw_devlink_relax_cycles(struct device *con,
/* Termination condition. */
if (sup_dev == con) {
+ pr_debug("----- cycle: start -----\n");
ret = true;
goto out;
}
@@ -1976,8 +1992,11 @@ static bool __fw_devlink_relax_cycles(struct device *con,
else
par_dev = fwnode_get_next_parent_dev(sup_handle);
- if (par_dev && __fw_devlink_relax_cycles(con, par_dev->fwnode))
+ if (par_dev && __fw_devlink_relax_cycles(con, par_dev->fwnode)) {
+ pr_debug("%pfwf: cycle: child of %pfwf\n", sup_handle,
+ par_dev->fwnode);
ret = true;
+ }
if (!sup_dev)
goto out;
@@ -1993,6 +2012,8 @@ static bool __fw_devlink_relax_cycles(struct device *con,
if (__fw_devlink_relax_cycles(con,
dev_link->supplier->fwnode)) {
+ pr_debug("%pfwf: cycle: depends on %pfwf\n", sup_handle,
+ dev_link->supplier->fwnode);
fw_devlink_relax_link(dev_link);
dev_link->flags |= DL_FLAG_CYCLE;
ret = true;
@@ -2072,6 +2093,7 @@ static int fw_devlink_create_devlink(struct device *con,
if (__fw_devlink_relax_cycles(con, sup_handle)) {
__fwnode_link_cycle(link);
flags = fw_devlink_get_flags(link->flags);
+ pr_debug("----- cycle: end -----\n");
dev_info(con, "Fixed dependency cycle(s) with %pfwf\n",
sup_handle);
}
@@ -4091,9 +4113,14 @@ int __init devices_init(void)
sysfs_dev_char_kobj = kobject_create_and_add("char", dev_kobj);
if (!sysfs_dev_char_kobj)
goto char_kobj_err;
+ device_link_wq = alloc_workqueue("device_link_wq", 0, 0);
+ if (!device_link_wq)
+ goto wq_err;
return 0;
+ wq_err:
+ kobject_put(sysfs_dev_char_kobj);
char_kobj_err:
kobject_put(sysfs_dev_block_kobj);
block_kobj_err:
@@ -4951,13 +4978,14 @@ define_dev_printk_level(_dev_info, KERN_INFO);
*
* return dev_err_probe(dev, err, ...);
*
- * Note that it is deemed acceptable to use this function for error
- * prints during probe even if the @err is known to never be -EPROBE_DEFER.
+ * Using this helper in your probe function is totally fine even if @err is
+ * known to never be -EPROBE_DEFER.
* The benefit compared to a normal dev_err() is the standardized format
- * of the error code and the fact that the error code is returned.
+ * of the error code, it being emitted symbolically (i.e. you get "EAGAIN"
+ * instead of "-35") and the fact that the error code is returned which allows
+ * more compact error paths.
*
* Returns @err.
- *
*/
int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
{
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index ef427ee787..0b33e81f9c 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -525,19 +525,42 @@ bool cpu_is_hotpluggable(unsigned int cpu)
EXPORT_SYMBOL_GPL(cpu_is_hotpluggable);
#ifdef CONFIG_GENERIC_CPU_DEVICES
-static DEFINE_PER_CPU(struct cpu, cpu_devices);
-#endif
+DEFINE_PER_CPU(struct cpu, cpu_devices);
+
+bool __weak arch_cpu_is_hotpluggable(int cpu)
+{
+ return false;
+}
+
+int __weak arch_register_cpu(int cpu)
+{
+ struct cpu *c = &per_cpu(cpu_devices, cpu);
+
+ c->hotpluggable = arch_cpu_is_hotpluggable(cpu);
+
+ return register_cpu(c, cpu);
+}
+
+#ifdef CONFIG_HOTPLUG_CPU
+void __weak arch_unregister_cpu(int num)
+{
+ unregister_cpu(&per_cpu(cpu_devices, num));
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+#endif /* CONFIG_GENERIC_CPU_DEVICES */
static void __init cpu_dev_register_generic(void)
{
-#ifdef CONFIG_GENERIC_CPU_DEVICES
- int i;
+ int i, ret;
- for_each_possible_cpu(i) {
- if (register_cpu(&per_cpu(cpu_devices, i), i))
- panic("Failed to register CPU device");
+ if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES))
+ return;
+
+ for_each_present_cpu(i) {
+ ret = arch_register_cpu(i);
+ if (ret)
+ pr_warn("register_cpu %d failed (%d)\n", i, ret);
}
-#endif
}
#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 0c3725c3ee..85152537db 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -313,7 +313,7 @@ static void deferred_probe_timeout_work_func(struct work_struct *work)
mutex_lock(&deferred_probe_mutex);
list_for_each_entry(p, &deferred_probe_pending_list, deferred_probe)
- dev_info(p->device, "deferred probe pending\n");
+ dev_info(p->device, "deferred probe pending: %s", p->deferred_probe_reason ?: "(reason unknown)\n");
mutex_unlock(&deferred_probe_mutex);
fw_devlink_probing_done();
diff --git a/drivers/base/firmware_loader/sysfs_upload.c b/drivers/base/firmware_loader/sysfs_upload.c
index a0af8f5f13..829270067d 100644
--- a/drivers/base/firmware_loader/sysfs_upload.c
+++ b/drivers/base/firmware_loader/sysfs_upload.c
@@ -27,6 +27,7 @@ static const char * const fw_upload_err_str[] = {
[FW_UPLOAD_ERR_INVALID_SIZE] = "invalid-file-size",
[FW_UPLOAD_ERR_RW_ERROR] = "read-write-error",
[FW_UPLOAD_ERR_WEAROUT] = "flash-wearout",
+ [FW_UPLOAD_ERR_FW_INVALID] = "firmware-invalid",
};
static const char *fw_upload_progress(struct device *dev,
diff --git a/drivers/base/init.c b/drivers/base/init.c
index 397eb9880c..c495483512 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -35,8 +35,8 @@ void __init driver_init(void)
of_core_init();
platform_bus_init();
auxiliary_bus_init();
- cpu_dev_init();
memory_dev_init();
node_dev_init();
+ cpu_dev_init();
container_dev_init();
}
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index 675ad31392..e23d0b49a7 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -82,7 +82,7 @@ static int isa_bus_resume(struct device *dev)
return 0;
}
-static struct bus_type isa_bus_type = {
+static const struct bus_type isa_bus_type = {
.name = "isa",
.match = isa_bus_match,
.probe = isa_bus_probe,
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 8a13babd82..14f964a771 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -68,7 +68,7 @@ static inline unsigned long phys_to_block_id(unsigned long phys)
static int memory_subsys_online(struct device *dev);
static int memory_subsys_offline(struct device *dev);
-static struct bus_type memory_subsys = {
+static const struct bus_type memory_subsys = {
.name = MEMORY_CLASS_NAME,
.dev_name = MEMORY_CLASS_NAME,
.online = memory_subsys_online,
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 4d588f4658..a73b0c9a40 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -21,7 +21,7 @@
#include <linux/swap.h>
#include <linux/slab.h>
-static struct bus_type node_subsys = {
+static const struct bus_type node_subsys = {
.name = "node",
.dev_name = "node",
};
@@ -74,14 +74,14 @@ static BIN_ATTR_RO(cpulist, CPULIST_FILE_MAX_BYTES);
* @dev: Device for this memory access class
* @list_node: List element in the node's access list
* @access: The access class rank
- * @hmem_attrs: Heterogeneous memory performance attributes
+ * @coord: Heterogeneous memory performance coordinates
*/
struct node_access_nodes {
struct device dev;
struct list_head list_node;
unsigned int access;
#ifdef CONFIG_HMEM_REPORTING
- struct node_hmem_attrs hmem_attrs;
+ struct access_coordinate coord;
#endif
};
#define to_access_nodes(dev) container_of(dev, struct node_access_nodes, dev)
@@ -126,7 +126,7 @@ static void node_access_release(struct device *dev)
}
static struct node_access_nodes *node_init_node_access(struct node *node,
- unsigned int access)
+ enum access_coordinate_class access)
{
struct node_access_nodes *access_node;
struct device *dev;
@@ -167,7 +167,7 @@ static ssize_t property##_show(struct device *dev, \
char *buf) \
{ \
return sysfs_emit(buf, "%u\n", \
- to_access_nodes(dev)->hmem_attrs.property); \
+ to_access_nodes(dev)->coord.property); \
} \
static DEVICE_ATTR_RO(property)
@@ -187,11 +187,11 @@ static struct attribute *access_attrs[] = {
/**
* node_set_perf_attrs - Set the performance values for given access class
* @nid: Node identifier to be set
- * @hmem_attrs: Heterogeneous memory performance attributes
+ * @coord: Heterogeneous memory performance coordinates
* @access: The access class the for the given attributes
*/
-void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
- unsigned int access)
+void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
+ enum access_coordinate_class access)
{
struct node_access_nodes *c;
struct node *node;
@@ -205,7 +205,7 @@ void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
if (!c)
return;
- c->hmem_attrs = *hmem_attrs;
+ c->coord = *coord;
for (i = 0; access_attrs[i] != NULL; i++) {
if (sysfs_add_file_to_group(&c->dev.kobj, access_attrs[i],
"initiators")) {
@@ -689,7 +689,7 @@ int register_cpu_under_node(unsigned int cpu, unsigned int nid)
*/
int register_memory_node_under_compute_node(unsigned int mem_nid,
unsigned int cpu_nid,
- unsigned int access)
+ enum access_coordinate_class access)
{
struct node *init_node, *targ_node;
struct node_access_nodes *initiator, *target;
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 8fdd0073ee..01f11629d2 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -2,7 +2,6 @@
obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o
obj-$(CONFIG_PM_TRACE_RTC) += trace.o
-obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o
obj-$(CONFIG_HAVE_CLK) += clock_ops.o
obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 4110c19c08..e18ba676cd 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -793,7 +793,7 @@ static int pm_clk_notify(struct notifier_block *nb,
* the remaining members of @clknb should be populated prior to calling this
* routine.
*/
-void pm_clk_add_notifier(struct bus_type *bus,
+void pm_clk_add_notifier(const struct bus_type *bus,
struct pm_clk_notifier_block *clknb)
{
if (!bus || !clknb)
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
deleted file mode 100644
index 011948f02b..0000000000
--- a/drivers/base/power/domain.c
+++ /dev/null
@@ -1,3433 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * drivers/base/power/domain.c - Common code related to device power domains.
- *
- * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
- */
-#define pr_fmt(fmt) "PM: " fmt
-
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/platform_device.h>
-#include <linux/pm_opp.h>
-#include <linux/pm_runtime.h>
-#include <linux/pm_domain.h>
-#include <linux/pm_qos.h>
-#include <linux/pm_clock.h>
-#include <linux/slab.h>
-#include <linux/err.h>
-#include <linux/sched.h>
-#include <linux/suspend.h>
-#include <linux/export.h>
-#include <linux/cpu.h>
-#include <linux/debugfs.h>
-
-#include "power.h"
-
-#define GENPD_RETRY_MAX_MS 250 /* Approximate */
-
-#define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
-({ \
- type (*__routine)(struct device *__d); \
- type __ret = (type)0; \
- \
- __routine = genpd->dev_ops.callback; \
- if (__routine) { \
- __ret = __routine(dev); \
- } \
- __ret; \
-})
-
-static LIST_HEAD(gpd_list);
-static DEFINE_MUTEX(gpd_list_lock);
-
-struct genpd_lock_ops {
- void (*lock)(struct generic_pm_domain *genpd);
- void (*lock_nested)(struct generic_pm_domain *genpd, int depth);
- int (*lock_interruptible)(struct generic_pm_domain *genpd);
- void (*unlock)(struct generic_pm_domain *genpd);
-};
-
-static void genpd_lock_mtx(struct generic_pm_domain *genpd)
-{
- mutex_lock(&genpd->mlock);
-}
-
-static void genpd_lock_nested_mtx(struct generic_pm_domain *genpd,
- int depth)
-{
- mutex_lock_nested(&genpd->mlock, depth);
-}
-
-static int genpd_lock_interruptible_mtx(struct generic_pm_domain *genpd)
-{
- return mutex_lock_interruptible(&genpd->mlock);
-}
-
-static void genpd_unlock_mtx(struct generic_pm_domain *genpd)
-{
- return mutex_unlock(&genpd->mlock);
-}
-
-static const struct genpd_lock_ops genpd_mtx_ops = {
- .lock = genpd_lock_mtx,
- .lock_nested = genpd_lock_nested_mtx,
- .lock_interruptible = genpd_lock_interruptible_mtx,
- .unlock = genpd_unlock_mtx,
-};
-
-static void genpd_lock_spin(struct generic_pm_domain *genpd)
- __acquires(&genpd->slock)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&genpd->slock, flags);
- genpd->lock_flags = flags;
-}
-
-static void genpd_lock_nested_spin(struct generic_pm_domain *genpd,
- int depth)
- __acquires(&genpd->slock)
-{
- unsigned long flags;
-
- spin_lock_irqsave_nested(&genpd->slock, flags, depth);
- genpd->lock_flags = flags;
-}
-
-static int genpd_lock_interruptible_spin(struct generic_pm_domain *genpd)
- __acquires(&genpd->slock)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&genpd->slock, flags);
- genpd->lock_flags = flags;
- return 0;
-}
-
-static void genpd_unlock_spin(struct generic_pm_domain *genpd)
- __releases(&genpd->slock)
-{
- spin_unlock_irqrestore(&genpd->slock, genpd->lock_flags);
-}
-
-static const struct genpd_lock_ops genpd_spin_ops = {
- .lock = genpd_lock_spin,
- .lock_nested = genpd_lock_nested_spin,
- .lock_interruptible = genpd_lock_interruptible_spin,
- .unlock = genpd_unlock_spin,
-};
-
-#define genpd_lock(p) p->lock_ops->lock(p)
-#define genpd_lock_nested(p, d) p->lock_ops->lock_nested(p, d)
-#define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p)
-#define genpd_unlock(p) p->lock_ops->unlock(p)
-
-#define genpd_status_on(genpd) (genpd->status == GENPD_STATE_ON)
-#define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE)
-#define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON)
-#define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP)
-#define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN)
-#define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON)
-#define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
-
-static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
- const struct generic_pm_domain *genpd)
-{
- bool ret;
-
- ret = pm_runtime_is_irq_safe(dev) && !genpd_is_irq_safe(genpd);
-
- /*
- * Warn once if an IRQ safe device is attached to a domain, which
- * callbacks are allowed to sleep. This indicates a suboptimal
- * configuration for PM, but it doesn't matter for an always on domain.
- */
- if (genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd))
- return ret;
-
- if (ret)
- dev_warn_once(dev, "PM domain %s will not be powered off\n",
- genpd->name);
-
- return ret;
-}
-
-static int genpd_runtime_suspend(struct device *dev);
-
-/*
- * Get the generic PM domain for a particular struct device.
- * This validates the struct device pointer, the PM domain pointer,
- * and checks that the PM domain pointer is a real generic PM domain.
- * Any failure results in NULL being returned.
- */
-static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev)
-{
- if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain))
- return NULL;
-
- /* A genpd's always have its ->runtime_suspend() callback assigned. */
- if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend)
- return pd_to_genpd(dev->pm_domain);
-
- return NULL;
-}
-
-/*
- * This should only be used where we are certain that the pm_domain
- * attached to the device is a genpd domain.
- */
-static struct generic_pm_domain *dev_to_genpd(struct device *dev)
-{
- if (IS_ERR_OR_NULL(dev->pm_domain))
- return ERR_PTR(-EINVAL);
-
- return pd_to_genpd(dev->pm_domain);
-}
-
-static int genpd_stop_dev(const struct generic_pm_domain *genpd,
- struct device *dev)
-{
- return GENPD_DEV_CALLBACK(genpd, int, stop, dev);
-}
-
-static int genpd_start_dev(const struct generic_pm_domain *genpd,
- struct device *dev)
-{
- return GENPD_DEV_CALLBACK(genpd, int, start, dev);
-}
-
-static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
-{
- bool ret = false;
-
- if (!WARN_ON(atomic_read(&genpd->sd_count) == 0))
- ret = !!atomic_dec_and_test(&genpd->sd_count);
-
- return ret;
-}
-
-static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
-{
- atomic_inc(&genpd->sd_count);
- smp_mb__after_atomic();
-}
-
-#ifdef CONFIG_DEBUG_FS
-static struct dentry *genpd_debugfs_dir;
-
-static void genpd_debug_add(struct generic_pm_domain *genpd);
-
-static void genpd_debug_remove(struct generic_pm_domain *genpd)
-{
- if (!genpd_debugfs_dir)
- return;
-
- debugfs_lookup_and_remove(genpd->name, genpd_debugfs_dir);
-}
-
-static void genpd_update_accounting(struct generic_pm_domain *genpd)
-{
- u64 delta, now;
-
- now = ktime_get_mono_fast_ns();
- if (now <= genpd->accounting_time)
- return;
-
- delta = now - genpd->accounting_time;
-
- /*
- * If genpd->status is active, it means we are just
- * out of off and so update the idle time and vice
- * versa.
- */
- if (genpd->status == GENPD_STATE_ON)
- genpd->states[genpd->state_idx].idle_time += delta;
- else
- genpd->on_time += delta;
-
- genpd->accounting_time = now;
-}
-#else
-static inline void genpd_debug_add(struct generic_pm_domain *genpd) {}
-static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {}
-static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {}
-#endif
-
-static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd,
- unsigned int state)
-{
- struct generic_pm_domain_data *pd_data;
- struct pm_domain_data *pdd;
- struct gpd_link *link;
-
- /* New requested state is same as Max requested state */
- if (state == genpd->performance_state)
- return state;
-
- /* New requested state is higher than Max requested state */
- if (state > genpd->performance_state)
- return state;
-
- /* Traverse all devices within the domain */
- list_for_each_entry(pdd, &genpd->dev_list, list_node) {
- pd_data = to_gpd_data(pdd);
-
- if (pd_data->performance_state > state)
- state = pd_data->performance_state;
- }
-
- /*
- * Traverse all sub-domains within the domain. This can be
- * done without any additional locking as the link->performance_state
- * field is protected by the parent genpd->lock, which is already taken.
- *
- * Also note that link->performance_state (subdomain's performance state
- * requirement to parent domain) is different from
- * link->child->performance_state (current performance state requirement
- * of the devices/sub-domains of the subdomain) and so can have a
- * different value.
- *
- * Note that we also take vote from powered-off sub-domains into account
- * as the same is done for devices right now.
- */
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- if (link->performance_state > state)
- state = link->performance_state;
- }
-
- return state;
-}
-
-static int genpd_xlate_performance_state(struct generic_pm_domain *genpd,
- struct generic_pm_domain *parent,
- unsigned int pstate)
-{
- if (!parent->set_performance_state)
- return pstate;
-
- return dev_pm_opp_xlate_performance_state(genpd->opp_table,
- parent->opp_table,
- pstate);
-}
-
-static int _genpd_set_performance_state(struct generic_pm_domain *genpd,
- unsigned int state, int depth)
-{
- struct generic_pm_domain *parent;
- struct gpd_link *link;
- int parent_state, ret;
-
- if (state == genpd->performance_state)
- return 0;
-
- /* Propagate to parents of genpd */
- list_for_each_entry(link, &genpd->child_links, child_node) {
- parent = link->parent;
-
- /* Find parent's performance state */
- ret = genpd_xlate_performance_state(genpd, parent, state);
- if (unlikely(ret < 0))
- goto err;
-
- parent_state = ret;
-
- genpd_lock_nested(parent, depth + 1);
-
- link->prev_performance_state = link->performance_state;
- link->performance_state = parent_state;
- parent_state = _genpd_reeval_performance_state(parent,
- parent_state);
- ret = _genpd_set_performance_state(parent, parent_state, depth + 1);
- if (ret)
- link->performance_state = link->prev_performance_state;
-
- genpd_unlock(parent);
-
- if (ret)
- goto err;
- }
-
- if (genpd->set_performance_state) {
- ret = genpd->set_performance_state(genpd, state);
- if (ret)
- goto err;
- }
-
- genpd->performance_state = state;
- return 0;
-
-err:
- /* Encountered an error, lets rollback */
- list_for_each_entry_continue_reverse(link, &genpd->child_links,
- child_node) {
- parent = link->parent;
-
- genpd_lock_nested(parent, depth + 1);
-
- parent_state = link->prev_performance_state;
- link->performance_state = parent_state;
-
- parent_state = _genpd_reeval_performance_state(parent,
- parent_state);
- if (_genpd_set_performance_state(parent, parent_state, depth + 1)) {
- pr_err("%s: Failed to roll back to %d performance state\n",
- parent->name, parent_state);
- }
-
- genpd_unlock(parent);
- }
-
- return ret;
-}
-
-static int genpd_set_performance_state(struct device *dev, unsigned int state)
-{
- struct generic_pm_domain *genpd = dev_to_genpd(dev);
- struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
- unsigned int prev_state;
- int ret;
-
- prev_state = gpd_data->performance_state;
- if (prev_state == state)
- return 0;
-
- gpd_data->performance_state = state;
- state = _genpd_reeval_performance_state(genpd, state);
-
- ret = _genpd_set_performance_state(genpd, state, 0);
- if (ret)
- gpd_data->performance_state = prev_state;
-
- return ret;
-}
-
-static int genpd_drop_performance_state(struct device *dev)
-{
- unsigned int prev_state = dev_gpd_data(dev)->performance_state;
-
- if (!genpd_set_performance_state(dev, 0))
- return prev_state;
-
- return 0;
-}
-
-static void genpd_restore_performance_state(struct device *dev,
- unsigned int state)
-{
- if (state)
- genpd_set_performance_state(dev, state);
-}
-
-static int genpd_dev_pm_set_performance_state(struct device *dev,
- unsigned int state)
-{
- struct generic_pm_domain *genpd = dev_to_genpd(dev);
- int ret = 0;
-
- genpd_lock(genpd);
- if (pm_runtime_suspended(dev)) {
- dev_gpd_data(dev)->rpm_pstate = state;
- } else {
- ret = genpd_set_performance_state(dev, state);
- if (!ret)
- dev_gpd_data(dev)->rpm_pstate = 0;
- }
- genpd_unlock(genpd);
-
- return ret;
-}
-
-/**
- * dev_pm_genpd_set_performance_state- Set performance state of device's power
- * domain.
- *
- * @dev: Device for which the performance-state needs to be set.
- * @state: Target performance state of the device. This can be set as 0 when the
- * device doesn't have any performance state constraints left (And so
- * the device wouldn't participate anymore to find the target
- * performance state of the genpd).
- *
- * It is assumed that the users guarantee that the genpd wouldn't be detached
- * while this routine is getting called.
- *
- * Returns 0 on success and negative error values on failures.
- */
-int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state)
-{
- struct generic_pm_domain *genpd;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return -ENODEV;
-
- if (WARN_ON(!dev->power.subsys_data ||
- !dev->power.subsys_data->domain_data))
- return -EINVAL;
-
- return genpd_dev_pm_set_performance_state(dev, state);
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_set_performance_state);
-
-/**
- * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup.
- *
- * @dev: Device to handle
- * @next: impending interrupt/wakeup for the device
- *
- *
- * Allow devices to inform of the next wakeup. It's assumed that the users
- * guarantee that the genpd wouldn't be detached while this routine is getting
- * called. Additionally, it's also assumed that @dev isn't runtime suspended
- * (RPM_SUSPENDED)."
- * Although devices are expected to update the next_wakeup after the end of
- * their usecase as well, it is possible the devices themselves may not know
- * about that, so stale @next will be ignored when powering off the domain.
- */
-void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next)
-{
- struct generic_pm_domain *genpd;
- struct gpd_timing_data *td;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return;
-
- td = to_gpd_data(dev->power.subsys_data->domain_data)->td;
- if (td)
- td->next_wakeup = next;
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_set_next_wakeup);
-
-/**
- * dev_pm_genpd_get_next_hrtimer - Return the next_hrtimer for the genpd
- * @dev: A device that is attached to the genpd.
- *
- * This routine should typically be called for a device, at the point of when a
- * GENPD_NOTIFY_PRE_OFF notification has been sent for it.
- *
- * Returns the aggregated value of the genpd's next hrtimer or KTIME_MAX if no
- * valid value have been set.
- */
-ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev)
-{
- struct generic_pm_domain *genpd;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return KTIME_MAX;
-
- if (genpd->gd)
- return genpd->gd->next_hrtimer;
-
- return KTIME_MAX;
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_get_next_hrtimer);
-
-/*
- * dev_pm_genpd_synced_poweroff - Next power off should be synchronous
- *
- * @dev: A device that is attached to the genpd.
- *
- * Allows a consumer of the genpd to notify the provider that the next power off
- * should be synchronous.
- *
- * It is assumed that the users guarantee that the genpd wouldn't be detached
- * while this routine is getting called.
- */
-void dev_pm_genpd_synced_poweroff(struct device *dev)
-{
- struct generic_pm_domain *genpd;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return;
-
- genpd_lock(genpd);
- genpd->synced_poweroff = true;
- genpd_unlock(genpd);
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_synced_poweroff);
-
-static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed)
-{
- unsigned int state_idx = genpd->state_idx;
- ktime_t time_start;
- s64 elapsed_ns;
- int ret;
-
- /* Notify consumers that we are about to power on. */
- ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
- GENPD_NOTIFY_PRE_ON,
- GENPD_NOTIFY_OFF, NULL);
- ret = notifier_to_errno(ret);
- if (ret)
- return ret;
-
- if (!genpd->power_on)
- goto out;
-
- timed = timed && genpd->gd && !genpd->states[state_idx].fwnode;
- if (!timed) {
- ret = genpd->power_on(genpd);
- if (ret)
- goto err;
-
- goto out;
- }
-
- time_start = ktime_get();
- ret = genpd->power_on(genpd);
- if (ret)
- goto err;
-
- elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
- if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns)
- goto out;
-
- genpd->states[state_idx].power_on_latency_ns = elapsed_ns;
- genpd->gd->max_off_time_changed = true;
- pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
- genpd->name, "on", elapsed_ns);
-
-out:
- raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL);
- genpd->synced_poweroff = false;
- return 0;
-err:
- raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF,
- NULL);
- return ret;
-}
-
-static int _genpd_power_off(struct generic_pm_domain *genpd, bool timed)
-{
- unsigned int state_idx = genpd->state_idx;
- ktime_t time_start;
- s64 elapsed_ns;
- int ret;
-
- /* Notify consumers that we are about to power off. */
- ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
- GENPD_NOTIFY_PRE_OFF,
- GENPD_NOTIFY_ON, NULL);
- ret = notifier_to_errno(ret);
- if (ret)
- return ret;
-
- if (!genpd->power_off)
- goto out;
-
- timed = timed && genpd->gd && !genpd->states[state_idx].fwnode;
- if (!timed) {
- ret = genpd->power_off(genpd);
- if (ret)
- goto busy;
-
- goto out;
- }
-
- time_start = ktime_get();
- ret = genpd->power_off(genpd);
- if (ret)
- goto busy;
-
- elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
- if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns)
- goto out;
-
- genpd->states[state_idx].power_off_latency_ns = elapsed_ns;
- genpd->gd->max_off_time_changed = true;
- pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
- genpd->name, "off", elapsed_ns);
-
-out:
- raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF,
- NULL);
- return 0;
-busy:
- raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL);
- return ret;
-}
-
-/**
- * genpd_queue_power_off_work - Queue up the execution of genpd_power_off().
- * @genpd: PM domain to power off.
- *
- * Queue up the execution of genpd_power_off() unless it's already been done
- * before.
- */
-static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
-{
- queue_work(pm_wq, &genpd->power_off_work);
-}
-
-/**
- * genpd_power_off - Remove power from a given PM domain.
- * @genpd: PM domain to power down.
- * @one_dev_on: If invoked from genpd's ->runtime_suspend|resume() callback, the
- * RPM status of the releated device is in an intermediate state, not yet turned
- * into RPM_SUSPENDED. This means genpd_power_off() must allow one device to not
- * be RPM_SUSPENDED, while it tries to power off the PM domain.
- * @depth: nesting count for lockdep.
- *
- * If all of the @genpd's devices have been suspended and all of its subdomains
- * have been powered down, remove power from @genpd.
- */
-static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
- unsigned int depth)
-{
- struct pm_domain_data *pdd;
- struct gpd_link *link;
- unsigned int not_suspended = 0;
- int ret;
-
- /*
- * Do not try to power off the domain in the following situations:
- * (1) The domain is already in the "power off" state.
- * (2) System suspend is in progress.
- */
- if (!genpd_status_on(genpd) || genpd->prepared_count > 0)
- return 0;
-
- /*
- * Abort power off for the PM domain in the following situations:
- * (1) The domain is configured as always on.
- * (2) When the domain has a subdomain being powered on.
- */
- if (genpd_is_always_on(genpd) ||
- genpd_is_rpm_always_on(genpd) ||
- atomic_read(&genpd->sd_count) > 0)
- return -EBUSY;
-
- /*
- * The children must be in their deepest (powered-off) states to allow
- * the parent to be powered off. Note that, there's no need for
- * additional locking, as powering on a child, requires the parent's
- * lock to be acquired first.
- */
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- struct generic_pm_domain *child = link->child;
- if (child->state_idx < child->state_count - 1)
- return -EBUSY;
- }
-
- list_for_each_entry(pdd, &genpd->dev_list, list_node) {
- /*
- * Do not allow PM domain to be powered off, when an IRQ safe
- * device is part of a non-IRQ safe domain.
- */
- if (!pm_runtime_suspended(pdd->dev) ||
- irq_safe_dev_in_sleep_domain(pdd->dev, genpd))
- not_suspended++;
- }
-
- if (not_suspended > 1 || (not_suspended == 1 && !one_dev_on))
- return -EBUSY;
-
- if (genpd->gov && genpd->gov->power_down_ok) {
- if (!genpd->gov->power_down_ok(&genpd->domain))
- return -EAGAIN;
- }
-
- /* Default to shallowest state. */
- if (!genpd->gov)
- genpd->state_idx = 0;
-
- /* Don't power off, if a child domain is waiting to power on. */
- if (atomic_read(&genpd->sd_count) > 0)
- return -EBUSY;
-
- ret = _genpd_power_off(genpd, true);
- if (ret) {
- genpd->states[genpd->state_idx].rejected++;
- return ret;
- }
-
- genpd->status = GENPD_STATE_OFF;
- genpd_update_accounting(genpd);
- genpd->states[genpd->state_idx].usage++;
-
- list_for_each_entry(link, &genpd->child_links, child_node) {
- genpd_sd_counter_dec(link->parent);
- genpd_lock_nested(link->parent, depth + 1);
- genpd_power_off(link->parent, false, depth + 1);
- genpd_unlock(link->parent);
- }
-
- return 0;
-}
-
-/**
- * genpd_power_on - Restore power to a given PM domain and its parents.
- * @genpd: PM domain to power up.
- * @depth: nesting count for lockdep.
- *
- * Restore power to @genpd and all of its parents so that it is possible to
- * resume a device belonging to it.
- */
-static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth)
-{
- struct gpd_link *link;
- int ret = 0;
-
- if (genpd_status_on(genpd))
- return 0;
-
- /*
- * The list is guaranteed not to change while the loop below is being
- * executed, unless one of the parents' .power_on() callbacks fiddles
- * with it.
- */
- list_for_each_entry(link, &genpd->child_links, child_node) {
- struct generic_pm_domain *parent = link->parent;
-
- genpd_sd_counter_inc(parent);
-
- genpd_lock_nested(parent, depth + 1);
- ret = genpd_power_on(parent, depth + 1);
- genpd_unlock(parent);
-
- if (ret) {
- genpd_sd_counter_dec(parent);
- goto err;
- }
- }
-
- ret = _genpd_power_on(genpd, true);
- if (ret)
- goto err;
-
- genpd->status = GENPD_STATE_ON;
- genpd_update_accounting(genpd);
-
- return 0;
-
- err:
- list_for_each_entry_continue_reverse(link,
- &genpd->child_links,
- child_node) {
- genpd_sd_counter_dec(link->parent);
- genpd_lock_nested(link->parent, depth + 1);
- genpd_power_off(link->parent, false, depth + 1);
- genpd_unlock(link->parent);
- }
-
- return ret;
-}
-
-static int genpd_dev_pm_start(struct device *dev)
-{
- struct generic_pm_domain *genpd = dev_to_genpd(dev);
-
- return genpd_start_dev(genpd, dev);
-}
-
-static int genpd_dev_pm_qos_notifier(struct notifier_block *nb,
- unsigned long val, void *ptr)
-{
- struct generic_pm_domain_data *gpd_data;
- struct device *dev;
-
- gpd_data = container_of(nb, struct generic_pm_domain_data, nb);
- dev = gpd_data->base.dev;
-
- for (;;) {
- struct generic_pm_domain *genpd = ERR_PTR(-ENODATA);
- struct pm_domain_data *pdd;
- struct gpd_timing_data *td;
-
- spin_lock_irq(&dev->power.lock);
-
- pdd = dev->power.subsys_data ?
- dev->power.subsys_data->domain_data : NULL;
- if (pdd) {
- td = to_gpd_data(pdd)->td;
- if (td) {
- td->constraint_changed = true;
- genpd = dev_to_genpd(dev);
- }
- }
-
- spin_unlock_irq(&dev->power.lock);
-
- if (!IS_ERR(genpd)) {
- genpd_lock(genpd);
- genpd->gd->max_off_time_changed = true;
- genpd_unlock(genpd);
- }
-
- dev = dev->parent;
- if (!dev || dev->power.ignore_children)
- break;
- }
-
- return NOTIFY_DONE;
-}
-
-/**
- * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
- * @work: Work structure used for scheduling the execution of this function.
- */
-static void genpd_power_off_work_fn(struct work_struct *work)
-{
- struct generic_pm_domain *genpd;
-
- genpd = container_of(work, struct generic_pm_domain, power_off_work);
-
- genpd_lock(genpd);
- genpd_power_off(genpd, false, 0);
- genpd_unlock(genpd);
-}
-
-/**
- * __genpd_runtime_suspend - walk the hierarchy of ->runtime_suspend() callbacks
- * @dev: Device to handle.
- */
-static int __genpd_runtime_suspend(struct device *dev)
-{
- int (*cb)(struct device *__dev);
-
- if (dev->type && dev->type->pm)
- cb = dev->type->pm->runtime_suspend;
- else if (dev->class && dev->class->pm)
- cb = dev->class->pm->runtime_suspend;
- else if (dev->bus && dev->bus->pm)
- cb = dev->bus->pm->runtime_suspend;
- else
- cb = NULL;
-
- if (!cb && dev->driver && dev->driver->pm)
- cb = dev->driver->pm->runtime_suspend;
-
- return cb ? cb(dev) : 0;
-}
-
-/**
- * __genpd_runtime_resume - walk the hierarchy of ->runtime_resume() callbacks
- * @dev: Device to handle.
- */
-static int __genpd_runtime_resume(struct device *dev)
-{
- int (*cb)(struct device *__dev);
-
- if (dev->type && dev->type->pm)
- cb = dev->type->pm->runtime_resume;
- else if (dev->class && dev->class->pm)
- cb = dev->class->pm->runtime_resume;
- else if (dev->bus && dev->bus->pm)
- cb = dev->bus->pm->runtime_resume;
- else
- cb = NULL;
-
- if (!cb && dev->driver && dev->driver->pm)
- cb = dev->driver->pm->runtime_resume;
-
- return cb ? cb(dev) : 0;
-}
-
-/**
- * genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
- * @dev: Device to suspend.
- *
- * Carry out a runtime suspend of a device under the assumption that its
- * pm_domain field points to the domain member of an object of type
- * struct generic_pm_domain representing a PM domain consisting of I/O devices.
- */
-static int genpd_runtime_suspend(struct device *dev)
-{
- struct generic_pm_domain *genpd;
- bool (*suspend_ok)(struct device *__dev);
- struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
- struct gpd_timing_data *td = gpd_data->td;
- bool runtime_pm = pm_runtime_enabled(dev);
- ktime_t time_start = 0;
- s64 elapsed_ns;
- int ret;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return -EINVAL;
-
- /*
- * A runtime PM centric subsystem/driver may re-use the runtime PM
- * callbacks for other purposes than runtime PM. In those scenarios
- * runtime PM is disabled. Under these circumstances, we shall skip
- * validating/measuring the PM QoS latency.
- */
- suspend_ok = genpd->gov ? genpd->gov->suspend_ok : NULL;
- if (runtime_pm && suspend_ok && !suspend_ok(dev))
- return -EBUSY;
-
- /* Measure suspend latency. */
- if (td && runtime_pm)
- time_start = ktime_get();
-
- ret = __genpd_runtime_suspend(dev);
- if (ret)
- return ret;
-
- ret = genpd_stop_dev(genpd, dev);
- if (ret) {
- __genpd_runtime_resume(dev);
- return ret;
- }
-
- /* Update suspend latency value if the measured time exceeds it. */
- if (td && runtime_pm) {
- elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
- if (elapsed_ns > td->suspend_latency_ns) {
- td->suspend_latency_ns = elapsed_ns;
- dev_dbg(dev, "suspend latency exceeded, %lld ns\n",
- elapsed_ns);
- genpd->gd->max_off_time_changed = true;
- td->constraint_changed = true;
- }
- }
-
- /*
- * If power.irq_safe is set, this routine may be run with
- * IRQs disabled, so suspend only if the PM domain also is irq_safe.
- */
- if (irq_safe_dev_in_sleep_domain(dev, genpd))
- return 0;
-
- genpd_lock(genpd);
- genpd_power_off(genpd, true, 0);
- gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
- genpd_unlock(genpd);
-
- return 0;
-}
-
-/**
- * genpd_runtime_resume - Resume a device belonging to I/O PM domain.
- * @dev: Device to resume.
- *
- * Carry out a runtime resume of a device under the assumption that its
- * pm_domain field points to the domain member of an object of type
- * struct generic_pm_domain representing a PM domain consisting of I/O devices.
- */
-static int genpd_runtime_resume(struct device *dev)
-{
- struct generic_pm_domain *genpd;
- struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev);
- struct gpd_timing_data *td = gpd_data->td;
- bool timed = td && pm_runtime_enabled(dev);
- ktime_t time_start = 0;
- s64 elapsed_ns;
- int ret;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return -EINVAL;
-
- /*
- * As we don't power off a non IRQ safe domain, which holds
- * an IRQ safe device, we don't need to restore power to it.
- */
- if (irq_safe_dev_in_sleep_domain(dev, genpd))
- goto out;
-
- genpd_lock(genpd);
- genpd_restore_performance_state(dev, gpd_data->rpm_pstate);
- ret = genpd_power_on(genpd, 0);
- genpd_unlock(genpd);
-
- if (ret)
- return ret;
-
- out:
- /* Measure resume latency. */
- if (timed)
- time_start = ktime_get();
-
- ret = genpd_start_dev(genpd, dev);
- if (ret)
- goto err_poweroff;
-
- ret = __genpd_runtime_resume(dev);
- if (ret)
- goto err_stop;
-
- /* Update resume latency value if the measured time exceeds it. */
- if (timed) {
- elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
- if (elapsed_ns > td->resume_latency_ns) {
- td->resume_latency_ns = elapsed_ns;
- dev_dbg(dev, "resume latency exceeded, %lld ns\n",
- elapsed_ns);
- genpd->gd->max_off_time_changed = true;
- td->constraint_changed = true;
- }
- }
-
- return 0;
-
-err_stop:
- genpd_stop_dev(genpd, dev);
-err_poweroff:
- if (!pm_runtime_is_irq_safe(dev) || genpd_is_irq_safe(genpd)) {
- genpd_lock(genpd);
- genpd_power_off(genpd, true, 0);
- gpd_data->rpm_pstate = genpd_drop_performance_state(dev);
- genpd_unlock(genpd);
- }
-
- return ret;
-}
-
-static bool pd_ignore_unused;
-static int __init pd_ignore_unused_setup(char *__unused)
-{
- pd_ignore_unused = true;
- return 1;
-}
-__setup("pd_ignore_unused", pd_ignore_unused_setup);
-
-/**
- * genpd_power_off_unused - Power off all PM domains with no devices in use.
- */
-static int __init genpd_power_off_unused(void)
-{
- struct generic_pm_domain *genpd;
-
- if (pd_ignore_unused) {
- pr_warn("genpd: Not disabling unused power domains\n");
- return 0;
- }
-
- mutex_lock(&gpd_list_lock);
-
- list_for_each_entry(genpd, &gpd_list, gpd_list_node)
- genpd_queue_power_off_work(genpd);
-
- mutex_unlock(&gpd_list_lock);
-
- return 0;
-}
-late_initcall_sync(genpd_power_off_unused);
-
-#ifdef CONFIG_PM_SLEEP
-
-/**
- * genpd_sync_power_off - Synchronously power off a PM domain and its parents.
- * @genpd: PM domain to power off, if possible.
- * @use_lock: use the lock.
- * @depth: nesting count for lockdep.
- *
- * Check if the given PM domain can be powered off (during system suspend or
- * hibernation) and do that if so. Also, in that case propagate to its parents.
- *
- * This function is only called in "noirq" and "syscore" stages of system power
- * transitions. The "noirq" callbacks may be executed asynchronously, thus in
- * these cases the lock must be held.
- */
-static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock,
- unsigned int depth)
-{
- struct gpd_link *link;
-
- if (!genpd_status_on(genpd) || genpd_is_always_on(genpd))
- return;
-
- if (genpd->suspended_count != genpd->device_count
- || atomic_read(&genpd->sd_count) > 0)
- return;
-
- /* Check that the children are in their deepest (powered-off) state. */
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- struct generic_pm_domain *child = link->child;
- if (child->state_idx < child->state_count - 1)
- return;
- }
-
- /* Choose the deepest state when suspending */
- genpd->state_idx = genpd->state_count - 1;
- if (_genpd_power_off(genpd, false))
- return;
-
- genpd->status = GENPD_STATE_OFF;
-
- list_for_each_entry(link, &genpd->child_links, child_node) {
- genpd_sd_counter_dec(link->parent);
-
- if (use_lock)
- genpd_lock_nested(link->parent, depth + 1);
-
- genpd_sync_power_off(link->parent, use_lock, depth + 1);
-
- if (use_lock)
- genpd_unlock(link->parent);
- }
-}
-
-/**
- * genpd_sync_power_on - Synchronously power on a PM domain and its parents.
- * @genpd: PM domain to power on.
- * @use_lock: use the lock.
- * @depth: nesting count for lockdep.
- *
- * This function is only called in "noirq" and "syscore" stages of system power
- * transitions. The "noirq" callbacks may be executed asynchronously, thus in
- * these cases the lock must be held.
- */
-static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock,
- unsigned int depth)
-{
- struct gpd_link *link;
-
- if (genpd_status_on(genpd))
- return;
-
- list_for_each_entry(link, &genpd->child_links, child_node) {
- genpd_sd_counter_inc(link->parent);
-
- if (use_lock)
- genpd_lock_nested(link->parent, depth + 1);
-
- genpd_sync_power_on(link->parent, use_lock, depth + 1);
-
- if (use_lock)
- genpd_unlock(link->parent);
- }
-
- _genpd_power_on(genpd, false);
- genpd->status = GENPD_STATE_ON;
-}
-
-/**
- * genpd_prepare - Start power transition of a device in a PM domain.
- * @dev: Device to start the transition of.
- *
- * Start a power transition of a device (during a system-wide power transition)
- * under the assumption that its pm_domain field points to the domain member of
- * an object of type struct generic_pm_domain representing a PM domain
- * consisting of I/O devices.
- */
-static int genpd_prepare(struct device *dev)
-{
- struct generic_pm_domain *genpd;
- int ret;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return -EINVAL;
-
- genpd_lock(genpd);
-
- if (genpd->prepared_count++ == 0)
- genpd->suspended_count = 0;
-
- genpd_unlock(genpd);
-
- ret = pm_generic_prepare(dev);
- if (ret < 0) {
- genpd_lock(genpd);
-
- genpd->prepared_count--;
-
- genpd_unlock(genpd);
- }
-
- /* Never return 1, as genpd don't cope with the direct_complete path. */
- return ret >= 0 ? 0 : ret;
-}
-
-/**
- * genpd_finish_suspend - Completion of suspend or hibernation of device in an
- * I/O pm domain.
- * @dev: Device to suspend.
- * @suspend_noirq: Generic suspend_noirq callback.
- * @resume_noirq: Generic resume_noirq callback.
- *
- * Stop the device and remove power from the domain if all devices in it have
- * been stopped.
- */
-static int genpd_finish_suspend(struct device *dev,
- int (*suspend_noirq)(struct device *dev),
- int (*resume_noirq)(struct device *dev))
-{
- struct generic_pm_domain *genpd;
- int ret = 0;
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return -EINVAL;
-
- ret = suspend_noirq(dev);
- if (ret)
- return ret;
-
- if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
- return 0;
-
- if (genpd->dev_ops.stop && genpd->dev_ops.start &&
- !pm_runtime_status_suspended(dev)) {
- ret = genpd_stop_dev(genpd, dev);
- if (ret) {
- resume_noirq(dev);
- return ret;
- }
- }
-
- genpd_lock(genpd);
- genpd->suspended_count++;
- genpd_sync_power_off(genpd, true, 0);
- genpd_unlock(genpd);
-
- return 0;
-}
-
-/**
- * genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain.
- * @dev: Device to suspend.
- *
- * Stop the device and remove power from the domain if all devices in it have
- * been stopped.
- */
-static int genpd_suspend_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_suspend(dev,
- pm_generic_suspend_noirq,
- pm_generic_resume_noirq);
-}
-
-/**
- * genpd_finish_resume - Completion of resume of device in an I/O PM domain.
- * @dev: Device to resume.
- * @resume_noirq: Generic resume_noirq callback.
- *
- * Restore power to the device's PM domain, if necessary, and start the device.
- */
-static int genpd_finish_resume(struct device *dev,
- int (*resume_noirq)(struct device *dev))
-{
- struct generic_pm_domain *genpd;
- int ret;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return -EINVAL;
-
- if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd))
- return resume_noirq(dev);
-
- genpd_lock(genpd);
- genpd_sync_power_on(genpd, true, 0);
- genpd->suspended_count--;
- genpd_unlock(genpd);
-
- if (genpd->dev_ops.stop && genpd->dev_ops.start &&
- !pm_runtime_status_suspended(dev)) {
- ret = genpd_start_dev(genpd, dev);
- if (ret)
- return ret;
- }
-
- return pm_generic_resume_noirq(dev);
-}
-
-/**
- * genpd_resume_noirq - Start of resume of device in an I/O PM domain.
- * @dev: Device to resume.
- *
- * Restore power to the device's PM domain, if necessary, and start the device.
- */
-static int genpd_resume_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_resume(dev, pm_generic_resume_noirq);
-}
-
-/**
- * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain.
- * @dev: Device to freeze.
- *
- * Carry out a late freeze of a device under the assumption that its
- * pm_domain field points to the domain member of an object of type
- * struct generic_pm_domain representing a power domain consisting of I/O
- * devices.
- */
-static int genpd_freeze_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_suspend(dev,
- pm_generic_freeze_noirq,
- pm_generic_thaw_noirq);
-}
-
-/**
- * genpd_thaw_noirq - Early thaw of device in an I/O PM domain.
- * @dev: Device to thaw.
- *
- * Start the device, unless power has been removed from the domain already
- * before the system transition.
- */
-static int genpd_thaw_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_resume(dev, pm_generic_thaw_noirq);
-}
-
-/**
- * genpd_poweroff_noirq - Completion of hibernation of device in an
- * I/O PM domain.
- * @dev: Device to poweroff.
- *
- * Stop the device and remove power from the domain if all devices in it have
- * been stopped.
- */
-static int genpd_poweroff_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_suspend(dev,
- pm_generic_poweroff_noirq,
- pm_generic_restore_noirq);
-}
-
-/**
- * genpd_restore_noirq - Start of restore of device in an I/O PM domain.
- * @dev: Device to resume.
- *
- * Make sure the domain will be in the same power state as before the
- * hibernation the system is resuming from and start the device if necessary.
- */
-static int genpd_restore_noirq(struct device *dev)
-{
- dev_dbg(dev, "%s()\n", __func__);
-
- return genpd_finish_resume(dev, pm_generic_restore_noirq);
-}
-
-/**
- * genpd_complete - Complete power transition of a device in a power domain.
- * @dev: Device to complete the transition of.
- *
- * Complete a power transition of a device (during a system-wide power
- * transition) under the assumption that its pm_domain field points to the
- * domain member of an object of type struct generic_pm_domain representing
- * a power domain consisting of I/O devices.
- */
-static void genpd_complete(struct device *dev)
-{
- struct generic_pm_domain *genpd;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- genpd = dev_to_genpd(dev);
- if (IS_ERR(genpd))
- return;
-
- pm_generic_complete(dev);
-
- genpd_lock(genpd);
-
- genpd->prepared_count--;
- if (!genpd->prepared_count)
- genpd_queue_power_off_work(genpd);
-
- genpd_unlock(genpd);
-}
-
-static void genpd_switch_state(struct device *dev, bool suspend)
-{
- struct generic_pm_domain *genpd;
- bool use_lock;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return;
-
- use_lock = genpd_is_irq_safe(genpd);
-
- if (use_lock)
- genpd_lock(genpd);
-
- if (suspend) {
- genpd->suspended_count++;
- genpd_sync_power_off(genpd, use_lock, 0);
- } else {
- genpd_sync_power_on(genpd, use_lock, 0);
- genpd->suspended_count--;
- }
-
- if (use_lock)
- genpd_unlock(genpd);
-}
-
-/**
- * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev
- * @dev: The device that is attached to the genpd, that can be suspended.
- *
- * This routine should typically be called for a device that needs to be
- * suspended during the syscore suspend phase. It may also be called during
- * suspend-to-idle to suspend a corresponding CPU device that is attached to a
- * genpd.
- */
-void dev_pm_genpd_suspend(struct device *dev)
-{
- genpd_switch_state(dev, true);
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_suspend);
-
-/**
- * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev
- * @dev: The device that is attached to the genpd, which needs to be resumed.
- *
- * This routine should typically be called for a device that needs to be resumed
- * during the syscore resume phase. It may also be called during suspend-to-idle
- * to resume a corresponding CPU device that is attached to a genpd.
- */
-void dev_pm_genpd_resume(struct device *dev)
-{
- genpd_switch_state(dev, false);
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_resume);
-
-#else /* !CONFIG_PM_SLEEP */
-
-#define genpd_prepare NULL
-#define genpd_suspend_noirq NULL
-#define genpd_resume_noirq NULL
-#define genpd_freeze_noirq NULL
-#define genpd_thaw_noirq NULL
-#define genpd_poweroff_noirq NULL
-#define genpd_restore_noirq NULL
-#define genpd_complete NULL
-
-#endif /* CONFIG_PM_SLEEP */
-
-static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
- bool has_governor)
-{
- struct generic_pm_domain_data *gpd_data;
- struct gpd_timing_data *td;
- int ret;
-
- ret = dev_pm_get_subsys_data(dev);
- if (ret)
- return ERR_PTR(ret);
-
- gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
- if (!gpd_data) {
- ret = -ENOMEM;
- goto err_put;
- }
-
- gpd_data->base.dev = dev;
- gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier;
-
- /* Allocate data used by a governor. */
- if (has_governor) {
- td = kzalloc(sizeof(*td), GFP_KERNEL);
- if (!td) {
- ret = -ENOMEM;
- goto err_free;
- }
-
- td->constraint_changed = true;
- td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
- td->next_wakeup = KTIME_MAX;
- gpd_data->td = td;
- }
-
- spin_lock_irq(&dev->power.lock);
-
- if (dev->power.subsys_data->domain_data)
- ret = -EINVAL;
- else
- dev->power.subsys_data->domain_data = &gpd_data->base;
-
- spin_unlock_irq(&dev->power.lock);
-
- if (ret)
- goto err_free;
-
- return gpd_data;
-
- err_free:
- kfree(gpd_data->td);
- kfree(gpd_data);
- err_put:
- dev_pm_put_subsys_data(dev);
- return ERR_PTR(ret);
-}
-
-static void genpd_free_dev_data(struct device *dev,
- struct generic_pm_domain_data *gpd_data)
-{
- spin_lock_irq(&dev->power.lock);
-
- dev->power.subsys_data->domain_data = NULL;
-
- spin_unlock_irq(&dev->power.lock);
-
- kfree(gpd_data->td);
- kfree(gpd_data);
- dev_pm_put_subsys_data(dev);
-}
-
-static void genpd_update_cpumask(struct generic_pm_domain *genpd,
- int cpu, bool set, unsigned int depth)
-{
- struct gpd_link *link;
-
- if (!genpd_is_cpu_domain(genpd))
- return;
-
- list_for_each_entry(link, &genpd->child_links, child_node) {
- struct generic_pm_domain *parent = link->parent;
-
- genpd_lock_nested(parent, depth + 1);
- genpd_update_cpumask(parent, cpu, set, depth + 1);
- genpd_unlock(parent);
- }
-
- if (set)
- cpumask_set_cpu(cpu, genpd->cpus);
- else
- cpumask_clear_cpu(cpu, genpd->cpus);
-}
-
-static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu)
-{
- if (cpu >= 0)
- genpd_update_cpumask(genpd, cpu, true, 0);
-}
-
-static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu)
-{
- if (cpu >= 0)
- genpd_update_cpumask(genpd, cpu, false, 0);
-}
-
-static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev)
-{
- int cpu;
-
- if (!genpd_is_cpu_domain(genpd))
- return -1;
-
- for_each_possible_cpu(cpu) {
- if (get_cpu_device(cpu) == dev)
- return cpu;
- }
-
- return -1;
-}
-
-static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
- struct device *base_dev)
-{
- struct genpd_governor_data *gd = genpd->gd;
- struct generic_pm_domain_data *gpd_data;
- int ret;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- gpd_data = genpd_alloc_dev_data(dev, gd);
- if (IS_ERR(gpd_data))
- return PTR_ERR(gpd_data);
-
- gpd_data->cpu = genpd_get_cpu(genpd, base_dev);
-
- ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
- if (ret)
- goto out;
-
- genpd_lock(genpd);
-
- genpd_set_cpumask(genpd, gpd_data->cpu);
- dev_pm_domain_set(dev, &genpd->domain);
-
- genpd->device_count++;
- if (gd)
- gd->max_off_time_changed = true;
-
- list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
-
- genpd_unlock(genpd);
- out:
- if (ret)
- genpd_free_dev_data(dev, gpd_data);
- else
- dev_pm_qos_add_notifier(dev, &gpd_data->nb,
- DEV_PM_QOS_RESUME_LATENCY);
-
- return ret;
-}
-
-/**
- * pm_genpd_add_device - Add a device to an I/O PM domain.
- * @genpd: PM domain to add the device to.
- * @dev: Device to be added.
- */
-int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
-{
- int ret;
-
- if (!genpd || !dev)
- return -EINVAL;
-
- mutex_lock(&gpd_list_lock);
- ret = genpd_add_device(genpd, dev, dev);
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_add_device);
-
-static int genpd_remove_device(struct generic_pm_domain *genpd,
- struct device *dev)
-{
- struct generic_pm_domain_data *gpd_data;
- struct pm_domain_data *pdd;
- int ret = 0;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- pdd = dev->power.subsys_data->domain_data;
- gpd_data = to_gpd_data(pdd);
- dev_pm_qos_remove_notifier(dev, &gpd_data->nb,
- DEV_PM_QOS_RESUME_LATENCY);
-
- genpd_lock(genpd);
-
- if (genpd->prepared_count > 0) {
- ret = -EAGAIN;
- goto out;
- }
-
- genpd->device_count--;
- if (genpd->gd)
- genpd->gd->max_off_time_changed = true;
-
- genpd_clear_cpumask(genpd, gpd_data->cpu);
- dev_pm_domain_set(dev, NULL);
-
- list_del_init(&pdd->list_node);
-
- genpd_unlock(genpd);
-
- if (genpd->detach_dev)
- genpd->detach_dev(genpd, dev);
-
- genpd_free_dev_data(dev, gpd_data);
-
- return 0;
-
- out:
- genpd_unlock(genpd);
- dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY);
-
- return ret;
-}
-
-/**
- * pm_genpd_remove_device - Remove a device from an I/O PM domain.
- * @dev: Device to be removed.
- */
-int pm_genpd_remove_device(struct device *dev)
-{
- struct generic_pm_domain *genpd = dev_to_genpd_safe(dev);
-
- if (!genpd)
- return -EINVAL;
-
- return genpd_remove_device(genpd, dev);
-}
-EXPORT_SYMBOL_GPL(pm_genpd_remove_device);
-
-/**
- * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev
- *
- * @dev: Device that should be associated with the notifier
- * @nb: The notifier block to register
- *
- * Users may call this function to add a genpd power on/off notifier for an
- * attached @dev. Only one notifier per device is allowed. The notifier is
- * sent when genpd is powering on/off the PM domain.
- *
- * It is assumed that the user guarantee that the genpd wouldn't be detached
- * while this routine is getting called.
- *
- * Returns 0 on success and negative error values on failures.
- */
-int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb)
-{
- struct generic_pm_domain *genpd;
- struct generic_pm_domain_data *gpd_data;
- int ret;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return -ENODEV;
-
- if (WARN_ON(!dev->power.subsys_data ||
- !dev->power.subsys_data->domain_data))
- return -EINVAL;
-
- gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
- if (gpd_data->power_nb)
- return -EEXIST;
-
- genpd_lock(genpd);
- ret = raw_notifier_chain_register(&genpd->power_notifiers, nb);
- genpd_unlock(genpd);
-
- if (ret) {
- dev_warn(dev, "failed to add notifier for PM domain %s\n",
- genpd->name);
- return ret;
- }
-
- gpd_data->power_nb = nb;
- return 0;
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_add_notifier);
-
-/**
- * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev
- *
- * @dev: Device that is associated with the notifier
- *
- * Users may call this function to remove a genpd power on/off notifier for an
- * attached @dev.
- *
- * It is assumed that the user guarantee that the genpd wouldn't be detached
- * while this routine is getting called.
- *
- * Returns 0 on success and negative error values on failures.
- */
-int dev_pm_genpd_remove_notifier(struct device *dev)
-{
- struct generic_pm_domain *genpd;
- struct generic_pm_domain_data *gpd_data;
- int ret;
-
- genpd = dev_to_genpd_safe(dev);
- if (!genpd)
- return -ENODEV;
-
- if (WARN_ON(!dev->power.subsys_data ||
- !dev->power.subsys_data->domain_data))
- return -EINVAL;
-
- gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
- if (!gpd_data->power_nb)
- return -ENODEV;
-
- genpd_lock(genpd);
- ret = raw_notifier_chain_unregister(&genpd->power_notifiers,
- gpd_data->power_nb);
- genpd_unlock(genpd);
-
- if (ret) {
- dev_warn(dev, "failed to remove notifier for PM domain %s\n",
- genpd->name);
- return ret;
- }
-
- gpd_data->power_nb = NULL;
- return 0;
-}
-EXPORT_SYMBOL_GPL(dev_pm_genpd_remove_notifier);
-
-static int genpd_add_subdomain(struct generic_pm_domain *genpd,
- struct generic_pm_domain *subdomain)
-{
- struct gpd_link *link, *itr;
- int ret = 0;
-
- if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)
- || genpd == subdomain)
- return -EINVAL;
-
- /*
- * If the domain can be powered on/off in an IRQ safe
- * context, ensure that the subdomain can also be
- * powered on/off in that context.
- */
- if (!genpd_is_irq_safe(genpd) && genpd_is_irq_safe(subdomain)) {
- WARN(1, "Parent %s of subdomain %s must be IRQ safe\n",
- genpd->name, subdomain->name);
- return -EINVAL;
- }
-
- link = kzalloc(sizeof(*link), GFP_KERNEL);
- if (!link)
- return -ENOMEM;
-
- genpd_lock(subdomain);
- genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING);
-
- if (!genpd_status_on(genpd) && genpd_status_on(subdomain)) {
- ret = -EINVAL;
- goto out;
- }
-
- list_for_each_entry(itr, &genpd->parent_links, parent_node) {
- if (itr->child == subdomain && itr->parent == genpd) {
- ret = -EINVAL;
- goto out;
- }
- }
-
- link->parent = genpd;
- list_add_tail(&link->parent_node, &genpd->parent_links);
- link->child = subdomain;
- list_add_tail(&link->child_node, &subdomain->child_links);
- if (genpd_status_on(subdomain))
- genpd_sd_counter_inc(genpd);
-
- out:
- genpd_unlock(genpd);
- genpd_unlock(subdomain);
- if (ret)
- kfree(link);
- return ret;
-}
-
-/**
- * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
- * @genpd: Leader PM domain to add the subdomain to.
- * @subdomain: Subdomain to be added.
- */
-int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
- struct generic_pm_domain *subdomain)
-{
- int ret;
-
- mutex_lock(&gpd_list_lock);
- ret = genpd_add_subdomain(genpd, subdomain);
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_add_subdomain);
-
-/**
- * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
- * @genpd: Leader PM domain to remove the subdomain from.
- * @subdomain: Subdomain to be removed.
- */
-int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
- struct generic_pm_domain *subdomain)
-{
- struct gpd_link *l, *link;
- int ret = -EINVAL;
-
- if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
- return -EINVAL;
-
- genpd_lock(subdomain);
- genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING);
-
- if (!list_empty(&subdomain->parent_links) || subdomain->device_count) {
- pr_warn("%s: unable to remove subdomain %s\n",
- genpd->name, subdomain->name);
- ret = -EBUSY;
- goto out;
- }
-
- list_for_each_entry_safe(link, l, &genpd->parent_links, parent_node) {
- if (link->child != subdomain)
- continue;
-
- list_del(&link->parent_node);
- list_del(&link->child_node);
- kfree(link);
- if (genpd_status_on(subdomain))
- genpd_sd_counter_dec(genpd);
-
- ret = 0;
- break;
- }
-
-out:
- genpd_unlock(genpd);
- genpd_unlock(subdomain);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain);
-
-static void genpd_free_default_power_state(struct genpd_power_state *states,
- unsigned int state_count)
-{
- kfree(states);
-}
-
-static int genpd_set_default_power_state(struct generic_pm_domain *genpd)
-{
- struct genpd_power_state *state;
-
- state = kzalloc(sizeof(*state), GFP_KERNEL);
- if (!state)
- return -ENOMEM;
-
- genpd->states = state;
- genpd->state_count = 1;
- genpd->free_states = genpd_free_default_power_state;
-
- return 0;
-}
-
-static int genpd_alloc_data(struct generic_pm_domain *genpd)
-{
- struct genpd_governor_data *gd = NULL;
- int ret;
-
- if (genpd_is_cpu_domain(genpd) &&
- !zalloc_cpumask_var(&genpd->cpus, GFP_KERNEL))
- return -ENOMEM;
-
- if (genpd->gov) {
- gd = kzalloc(sizeof(*gd), GFP_KERNEL);
- if (!gd) {
- ret = -ENOMEM;
- goto free;
- }
-
- gd->max_off_time_ns = -1;
- gd->max_off_time_changed = true;
- gd->next_wakeup = KTIME_MAX;
- gd->next_hrtimer = KTIME_MAX;
- }
-
- /* Use only one "off" state if there were no states declared */
- if (genpd->state_count == 0) {
- ret = genpd_set_default_power_state(genpd);
- if (ret)
- goto free;
- }
-
- genpd->gd = gd;
- return 0;
-
-free:
- if (genpd_is_cpu_domain(genpd))
- free_cpumask_var(genpd->cpus);
- kfree(gd);
- return ret;
-}
-
-static void genpd_free_data(struct generic_pm_domain *genpd)
-{
- if (genpd_is_cpu_domain(genpd))
- free_cpumask_var(genpd->cpus);
- if (genpd->free_states)
- genpd->free_states(genpd->states, genpd->state_count);
- kfree(genpd->gd);
-}
-
-static void genpd_lock_init(struct generic_pm_domain *genpd)
-{
- if (genpd->flags & GENPD_FLAG_IRQ_SAFE) {
- spin_lock_init(&genpd->slock);
- genpd->lock_ops = &genpd_spin_ops;
- } else {
- mutex_init(&genpd->mlock);
- genpd->lock_ops = &genpd_mtx_ops;
- }
-}
-
-/**
- * pm_genpd_init - Initialize a generic I/O PM domain object.
- * @genpd: PM domain object to initialize.
- * @gov: PM domain governor to associate with the domain (may be NULL).
- * @is_off: Initial value of the domain's power_is_off field.
- *
- * Returns 0 on successful initialization, else a negative error code.
- */
-int pm_genpd_init(struct generic_pm_domain *genpd,
- struct dev_power_governor *gov, bool is_off)
-{
- int ret;
-
- if (IS_ERR_OR_NULL(genpd))
- return -EINVAL;
-
- INIT_LIST_HEAD(&genpd->parent_links);
- INIT_LIST_HEAD(&genpd->child_links);
- INIT_LIST_HEAD(&genpd->dev_list);
- RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers);
- genpd_lock_init(genpd);
- genpd->gov = gov;
- INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
- atomic_set(&genpd->sd_count, 0);
- genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
- genpd->device_count = 0;
- genpd->provider = NULL;
- genpd->has_provider = false;
- genpd->accounting_time = ktime_get_mono_fast_ns();
- genpd->domain.ops.runtime_suspend = genpd_runtime_suspend;
- genpd->domain.ops.runtime_resume = genpd_runtime_resume;
- genpd->domain.ops.prepare = genpd_prepare;
- genpd->domain.ops.suspend_noirq = genpd_suspend_noirq;
- genpd->domain.ops.resume_noirq = genpd_resume_noirq;
- genpd->domain.ops.freeze_noirq = genpd_freeze_noirq;
- genpd->domain.ops.thaw_noirq = genpd_thaw_noirq;
- genpd->domain.ops.poweroff_noirq = genpd_poweroff_noirq;
- genpd->domain.ops.restore_noirq = genpd_restore_noirq;
- genpd->domain.ops.complete = genpd_complete;
- genpd->domain.start = genpd_dev_pm_start;
- genpd->domain.set_performance_state = genpd_dev_pm_set_performance_state;
-
- if (genpd->flags & GENPD_FLAG_PM_CLK) {
- genpd->dev_ops.stop = pm_clk_suspend;
- genpd->dev_ops.start = pm_clk_resume;
- }
-
- /* The always-on governor works better with the corresponding flag. */
- if (gov == &pm_domain_always_on_gov)
- genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON;
-
- /* Always-on domains must be powered on at initialization. */
- if ((genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd)) &&
- !genpd_status_on(genpd)) {
- pr_err("always-on PM domain %s is not on\n", genpd->name);
- return -EINVAL;
- }
-
- /* Multiple states but no governor doesn't make sense. */
- if (!gov && genpd->state_count > 1)
- pr_warn("%s: no governor for states\n", genpd->name);
-
- ret = genpd_alloc_data(genpd);
- if (ret)
- return ret;
-
- device_initialize(&genpd->dev);
- dev_set_name(&genpd->dev, "%s", genpd->name);
-
- mutex_lock(&gpd_list_lock);
- list_add(&genpd->gpd_list_node, &gpd_list);
- mutex_unlock(&gpd_list_lock);
- genpd_debug_add(genpd);
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_init);
-
-static int genpd_remove(struct generic_pm_domain *genpd)
-{
- struct gpd_link *l, *link;
-
- if (IS_ERR_OR_NULL(genpd))
- return -EINVAL;
-
- genpd_lock(genpd);
-
- if (genpd->has_provider) {
- genpd_unlock(genpd);
- pr_err("Provider present, unable to remove %s\n", genpd->name);
- return -EBUSY;
- }
-
- if (!list_empty(&genpd->parent_links) || genpd->device_count) {
- genpd_unlock(genpd);
- pr_err("%s: unable to remove %s\n", __func__, genpd->name);
- return -EBUSY;
- }
-
- list_for_each_entry_safe(link, l, &genpd->child_links, child_node) {
- list_del(&link->parent_node);
- list_del(&link->child_node);
- kfree(link);
- }
-
- list_del(&genpd->gpd_list_node);
- genpd_unlock(genpd);
- genpd_debug_remove(genpd);
- cancel_work_sync(&genpd->power_off_work);
- genpd_free_data(genpd);
-
- pr_debug("%s: removed %s\n", __func__, genpd->name);
-
- return 0;
-}
-
-/**
- * pm_genpd_remove - Remove a generic I/O PM domain
- * @genpd: Pointer to PM domain that is to be removed.
- *
- * To remove the PM domain, this function:
- * - Removes the PM domain as a subdomain to any parent domains,
- * if it was added.
- * - Removes the PM domain from the list of registered PM domains.
- *
- * The PM domain will only be removed, if the associated provider has
- * been removed, it is not a parent to any other PM domain and has no
- * devices associated with it.
- */
-int pm_genpd_remove(struct generic_pm_domain *genpd)
-{
- int ret;
-
- mutex_lock(&gpd_list_lock);
- ret = genpd_remove(genpd);
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_remove);
-
-#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
-
-/*
- * Device Tree based PM domain providers.
- *
- * The code below implements generic device tree based PM domain providers that
- * bind device tree nodes with generic PM domains registered in the system.
- *
- * Any driver that registers generic PM domains and needs to support binding of
- * devices to these domains is supposed to register a PM domain provider, which
- * maps a PM domain specifier retrieved from the device tree to a PM domain.
- *
- * Two simple mapping functions have been provided for convenience:
- * - genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
- * - genpd_xlate_onecell() for mapping of multiple PM domains per node by
- * index.
- */
-
-/**
- * struct of_genpd_provider - PM domain provider registration structure
- * @link: Entry in global list of PM domain providers
- * @node: Pointer to device tree node of PM domain provider
- * @xlate: Provider-specific xlate callback mapping a set of specifier cells
- * into a PM domain.
- * @data: context pointer to be passed into @xlate callback
- */
-struct of_genpd_provider {
- struct list_head link;
- struct device_node *node;
- genpd_xlate_t xlate;
- void *data;
-};
-
-/* List of registered PM domain providers. */
-static LIST_HEAD(of_genpd_providers);
-/* Mutex to protect the list above. */
-static DEFINE_MUTEX(of_genpd_mutex);
-
-/**
- * genpd_xlate_simple() - Xlate function for direct node-domain mapping
- * @genpdspec: OF phandle args to map into a PM domain
- * @data: xlate function private data - pointer to struct generic_pm_domain
- *
- * This is a generic xlate function that can be used to model PM domains that
- * have their own device tree nodes. The private data of xlate function needs
- * to be a valid pointer to struct generic_pm_domain.
- */
-static struct generic_pm_domain *genpd_xlate_simple(
- struct of_phandle_args *genpdspec,
- void *data)
-{
- return data;
-}
-
-/**
- * genpd_xlate_onecell() - Xlate function using a single index.
- * @genpdspec: OF phandle args to map into a PM domain
- * @data: xlate function private data - pointer to struct genpd_onecell_data
- *
- * This is a generic xlate function that can be used to model simple PM domain
- * controllers that have one device tree node and provide multiple PM domains.
- * A single cell is used as an index into an array of PM domains specified in
- * the genpd_onecell_data struct when registering the provider.
- */
-static struct generic_pm_domain *genpd_xlate_onecell(
- struct of_phandle_args *genpdspec,
- void *data)
-{
- struct genpd_onecell_data *genpd_data = data;
- unsigned int idx = genpdspec->args[0];
-
- if (genpdspec->args_count != 1)
- return ERR_PTR(-EINVAL);
-
- if (idx >= genpd_data->num_domains) {
- pr_err("%s: invalid domain index %u\n", __func__, idx);
- return ERR_PTR(-EINVAL);
- }
-
- if (!genpd_data->domains[idx])
- return ERR_PTR(-ENOENT);
-
- return genpd_data->domains[idx];
-}
-
-/**
- * genpd_add_provider() - Register a PM domain provider for a node
- * @np: Device node pointer associated with the PM domain provider.
- * @xlate: Callback for decoding PM domain from phandle arguments.
- * @data: Context pointer for @xlate callback.
- */
-static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
- void *data)
-{
- struct of_genpd_provider *cp;
-
- cp = kzalloc(sizeof(*cp), GFP_KERNEL);
- if (!cp)
- return -ENOMEM;
-
- cp->node = of_node_get(np);
- cp->data = data;
- cp->xlate = xlate;
- fwnode_dev_initialized(&np->fwnode, true);
-
- mutex_lock(&of_genpd_mutex);
- list_add(&cp->link, &of_genpd_providers);
- mutex_unlock(&of_genpd_mutex);
- pr_debug("Added domain provider from %pOF\n", np);
-
- return 0;
-}
-
-static bool genpd_present(const struct generic_pm_domain *genpd)
-{
- bool ret = false;
- const struct generic_pm_domain *gpd;
-
- mutex_lock(&gpd_list_lock);
- list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
- if (gpd == genpd) {
- ret = true;
- break;
- }
- }
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-
-/**
- * of_genpd_add_provider_simple() - Register a simple PM domain provider
- * @np: Device node pointer associated with the PM domain provider.
- * @genpd: Pointer to PM domain associated with the PM domain provider.
- */
-int of_genpd_add_provider_simple(struct device_node *np,
- struct generic_pm_domain *genpd)
-{
- int ret;
-
- if (!np || !genpd)
- return -EINVAL;
-
- if (!genpd_present(genpd))
- return -EINVAL;
-
- genpd->dev.of_node = np;
-
- /* Parse genpd OPP table */
- if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
- ret = dev_pm_opp_of_add_table(&genpd->dev);
- if (ret)
- return dev_err_probe(&genpd->dev, ret, "Failed to add OPP table\n");
-
- /*
- * Save table for faster processing while setting performance
- * state.
- */
- genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev);
- WARN_ON(IS_ERR(genpd->opp_table));
- }
-
- ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
- if (ret) {
- if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
- dev_pm_opp_put_opp_table(genpd->opp_table);
- dev_pm_opp_of_remove_table(&genpd->dev);
- }
-
- return ret;
- }
-
- genpd->provider = &np->fwnode;
- genpd->has_provider = true;
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
-
-/**
- * of_genpd_add_provider_onecell() - Register a onecell PM domain provider
- * @np: Device node pointer associated with the PM domain provider.
- * @data: Pointer to the data associated with the PM domain provider.
- */
-int of_genpd_add_provider_onecell(struct device_node *np,
- struct genpd_onecell_data *data)
-{
- struct generic_pm_domain *genpd;
- unsigned int i;
- int ret = -EINVAL;
-
- if (!np || !data)
- return -EINVAL;
-
- if (!data->xlate)
- data->xlate = genpd_xlate_onecell;
-
- for (i = 0; i < data->num_domains; i++) {
- genpd = data->domains[i];
-
- if (!genpd)
- continue;
- if (!genpd_present(genpd))
- goto error;
-
- genpd->dev.of_node = np;
-
- /* Parse genpd OPP table */
- if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
- ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i);
- if (ret) {
- dev_err_probe(&genpd->dev, ret,
- "Failed to add OPP table for index %d\n", i);
- goto error;
- }
-
- /*
- * Save table for faster processing while setting
- * performance state.
- */
- genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev);
- WARN_ON(IS_ERR(genpd->opp_table));
- }
-
- genpd->provider = &np->fwnode;
- genpd->has_provider = true;
- }
-
- ret = genpd_add_provider(np, data->xlate, data);
- if (ret < 0)
- goto error;
-
- return 0;
-
-error:
- while (i--) {
- genpd = data->domains[i];
-
- if (!genpd)
- continue;
-
- genpd->provider = NULL;
- genpd->has_provider = false;
-
- if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
- dev_pm_opp_put_opp_table(genpd->opp_table);
- dev_pm_opp_of_remove_table(&genpd->dev);
- }
- }
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(of_genpd_add_provider_onecell);
-
-/**
- * of_genpd_del_provider() - Remove a previously registered PM domain provider
- * @np: Device node pointer associated with the PM domain provider
- */
-void of_genpd_del_provider(struct device_node *np)
-{
- struct of_genpd_provider *cp, *tmp;
- struct generic_pm_domain *gpd;
-
- mutex_lock(&gpd_list_lock);
- mutex_lock(&of_genpd_mutex);
- list_for_each_entry_safe(cp, tmp, &of_genpd_providers, link) {
- if (cp->node == np) {
- /*
- * For each PM domain associated with the
- * provider, set the 'has_provider' to false
- * so that the PM domain can be safely removed.
- */
- list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
- if (gpd->provider == &np->fwnode) {
- gpd->has_provider = false;
-
- if (genpd_is_opp_table_fw(gpd) || !gpd->set_performance_state)
- continue;
-
- dev_pm_opp_put_opp_table(gpd->opp_table);
- dev_pm_opp_of_remove_table(&gpd->dev);
- }
- }
-
- fwnode_dev_initialized(&cp->node->fwnode, false);
- list_del(&cp->link);
- of_node_put(cp->node);
- kfree(cp);
- break;
- }
- }
- mutex_unlock(&of_genpd_mutex);
- mutex_unlock(&gpd_list_lock);
-}
-EXPORT_SYMBOL_GPL(of_genpd_del_provider);
-
-/**
- * genpd_get_from_provider() - Look-up PM domain
- * @genpdspec: OF phandle args to use for look-up
- *
- * Looks for a PM domain provider under the node specified by @genpdspec and if
- * found, uses xlate function of the provider to map phandle args to a PM
- * domain.
- *
- * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
- * on failure.
- */
-static struct generic_pm_domain *genpd_get_from_provider(
- struct of_phandle_args *genpdspec)
-{
- struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
- struct of_genpd_provider *provider;
-
- if (!genpdspec)
- return ERR_PTR(-EINVAL);
-
- mutex_lock(&of_genpd_mutex);
-
- /* Check if we have such a provider in our array */
- list_for_each_entry(provider, &of_genpd_providers, link) {
- if (provider->node == genpdspec->np)
- genpd = provider->xlate(genpdspec, provider->data);
- if (!IS_ERR(genpd))
- break;
- }
-
- mutex_unlock(&of_genpd_mutex);
-
- return genpd;
-}
-
-/**
- * of_genpd_add_device() - Add a device to an I/O PM domain
- * @genpdspec: OF phandle args to use for look-up PM domain
- * @dev: Device to be added.
- *
- * Looks-up an I/O PM domain based upon phandle args provided and adds
- * the device to the PM domain. Returns a negative error code on failure.
- */
-int of_genpd_add_device(struct of_phandle_args *genpdspec, struct device *dev)
-{
- struct generic_pm_domain *genpd;
- int ret;
-
- if (!dev)
- return -EINVAL;
-
- mutex_lock(&gpd_list_lock);
-
- genpd = genpd_get_from_provider(genpdspec);
- if (IS_ERR(genpd)) {
- ret = PTR_ERR(genpd);
- goto out;
- }
-
- ret = genpd_add_device(genpd, dev, dev);
-
-out:
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(of_genpd_add_device);
-
-/**
- * of_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
- * @parent_spec: OF phandle args to use for parent PM domain look-up
- * @subdomain_spec: OF phandle args to use for subdomain look-up
- *
- * Looks-up a parent PM domain and subdomain based upon phandle args
- * provided and adds the subdomain to the parent PM domain. Returns a
- * negative error code on failure.
- */
-int of_genpd_add_subdomain(struct of_phandle_args *parent_spec,
- struct of_phandle_args *subdomain_spec)
-{
- struct generic_pm_domain *parent, *subdomain;
- int ret;
-
- mutex_lock(&gpd_list_lock);
-
- parent = genpd_get_from_provider(parent_spec);
- if (IS_ERR(parent)) {
- ret = PTR_ERR(parent);
- goto out;
- }
-
- subdomain = genpd_get_from_provider(subdomain_spec);
- if (IS_ERR(subdomain)) {
- ret = PTR_ERR(subdomain);
- goto out;
- }
-
- ret = genpd_add_subdomain(parent, subdomain);
-
-out:
- mutex_unlock(&gpd_list_lock);
-
- return ret == -ENOENT ? -EPROBE_DEFER : ret;
-}
-EXPORT_SYMBOL_GPL(of_genpd_add_subdomain);
-
-/**
- * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
- * @parent_spec: OF phandle args to use for parent PM domain look-up
- * @subdomain_spec: OF phandle args to use for subdomain look-up
- *
- * Looks-up a parent PM domain and subdomain based upon phandle args
- * provided and removes the subdomain from the parent PM domain. Returns a
- * negative error code on failure.
- */
-int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec,
- struct of_phandle_args *subdomain_spec)
-{
- struct generic_pm_domain *parent, *subdomain;
- int ret;
-
- mutex_lock(&gpd_list_lock);
-
- parent = genpd_get_from_provider(parent_spec);
- if (IS_ERR(parent)) {
- ret = PTR_ERR(parent);
- goto out;
- }
-
- subdomain = genpd_get_from_provider(subdomain_spec);
- if (IS_ERR(subdomain)) {
- ret = PTR_ERR(subdomain);
- goto out;
- }
-
- ret = pm_genpd_remove_subdomain(parent, subdomain);
-
-out:
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-EXPORT_SYMBOL_GPL(of_genpd_remove_subdomain);
-
-/**
- * of_genpd_remove_last - Remove the last PM domain registered for a provider
- * @np: Pointer to device node associated with provider
- *
- * Find the last PM domain that was added by a particular provider and
- * remove this PM domain from the list of PM domains. The provider is
- * identified by the 'provider' device structure that is passed. The PM
- * domain will only be removed, if the provider associated with domain
- * has been removed.
- *
- * Returns a valid pointer to struct generic_pm_domain on success or
- * ERR_PTR() on failure.
- */
-struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
-{
- struct generic_pm_domain *gpd, *tmp, *genpd = ERR_PTR(-ENOENT);
- int ret;
-
- if (IS_ERR_OR_NULL(np))
- return ERR_PTR(-EINVAL);
-
- mutex_lock(&gpd_list_lock);
- list_for_each_entry_safe(gpd, tmp, &gpd_list, gpd_list_node) {
- if (gpd->provider == &np->fwnode) {
- ret = genpd_remove(gpd);
- genpd = ret ? ERR_PTR(ret) : gpd;
- break;
- }
- }
- mutex_unlock(&gpd_list_lock);
-
- return genpd;
-}
-EXPORT_SYMBOL_GPL(of_genpd_remove_last);
-
-static void genpd_release_dev(struct device *dev)
-{
- of_node_put(dev->of_node);
- kfree(dev);
-}
-
-static struct bus_type genpd_bus_type = {
- .name = "genpd",
-};
-
-/**
- * genpd_dev_pm_detach - Detach a device from its PM domain.
- * @dev: Device to detach.
- * @power_off: Currently not used
- *
- * Try to locate a corresponding generic PM domain, which the device was
- * attached to previously. If such is found, the device is detached from it.
- */
-static void genpd_dev_pm_detach(struct device *dev, bool power_off)
-{
- struct generic_pm_domain *pd;
- unsigned int i;
- int ret = 0;
-
- pd = dev_to_genpd(dev);
- if (IS_ERR(pd))
- return;
-
- dev_dbg(dev, "removing from PM domain %s\n", pd->name);
-
- /* Drop the default performance state */
- if (dev_gpd_data(dev)->default_pstate) {
- dev_pm_genpd_set_performance_state(dev, 0);
- dev_gpd_data(dev)->default_pstate = 0;
- }
-
- for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) {
- ret = genpd_remove_device(pd, dev);
- if (ret != -EAGAIN)
- break;
-
- mdelay(i);
- cond_resched();
- }
-
- if (ret < 0) {
- dev_err(dev, "failed to remove from PM domain %s: %d",
- pd->name, ret);
- return;
- }
-
- /* Check if PM domain can be powered off after removing this device. */
- genpd_queue_power_off_work(pd);
-
- /* Unregister the device if it was created by genpd. */
- if (dev->bus == &genpd_bus_type)
- device_unregister(dev);
-}
-
-static void genpd_dev_pm_sync(struct device *dev)
-{
- struct generic_pm_domain *pd;
-
- pd = dev_to_genpd(dev);
- if (IS_ERR(pd))
- return;
-
- genpd_queue_power_off_work(pd);
-}
-
-static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
- unsigned int index, bool power_on)
-{
- struct of_phandle_args pd_args;
- struct generic_pm_domain *pd;
- int pstate;
- int ret;
-
- ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
- "#power-domain-cells", index, &pd_args);
- if (ret < 0)
- return ret;
-
- mutex_lock(&gpd_list_lock);
- pd = genpd_get_from_provider(&pd_args);
- of_node_put(pd_args.np);
- if (IS_ERR(pd)) {
- mutex_unlock(&gpd_list_lock);
- dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
- __func__, PTR_ERR(pd));
- return driver_deferred_probe_check_state(base_dev);
- }
-
- dev_dbg(dev, "adding to PM domain %s\n", pd->name);
-
- ret = genpd_add_device(pd, dev, base_dev);
- mutex_unlock(&gpd_list_lock);
-
- if (ret < 0)
- return dev_err_probe(dev, ret, "failed to add to PM domain %s\n", pd->name);
-
- dev->pm_domain->detach = genpd_dev_pm_detach;
- dev->pm_domain->sync = genpd_dev_pm_sync;
-
- /* Set the default performance state */
- pstate = of_get_required_opp_performance_state(dev->of_node, index);
- if (pstate < 0 && pstate != -ENODEV && pstate != -EOPNOTSUPP) {
- ret = pstate;
- goto err;
- } else if (pstate > 0) {
- ret = dev_pm_genpd_set_performance_state(dev, pstate);
- if (ret)
- goto err;
- dev_gpd_data(dev)->default_pstate = pstate;
- }
-
- if (power_on) {
- genpd_lock(pd);
- ret = genpd_power_on(pd, 0);
- genpd_unlock(pd);
- }
-
- if (ret) {
- /* Drop the default performance state */
- if (dev_gpd_data(dev)->default_pstate) {
- dev_pm_genpd_set_performance_state(dev, 0);
- dev_gpd_data(dev)->default_pstate = 0;
- }
-
- genpd_remove_device(pd, dev);
- return -EPROBE_DEFER;
- }
-
- return 1;
-
-err:
- dev_err(dev, "failed to set required performance state for power-domain %s: %d\n",
- pd->name, ret);
- genpd_remove_device(pd, dev);
- return ret;
-}
-
-/**
- * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
- * @dev: Device to attach.
- *
- * Parse device's OF node to find a PM domain specifier. If such is found,
- * attaches the device to retrieved pm_domain ops.
- *
- * Returns 1 on successfully attached PM domain, 0 when the device don't need a
- * PM domain or when multiple power-domains exists for it, else a negative error
- * code. Note that if a power-domain exists for the device, but it cannot be
- * found or turned on, then return -EPROBE_DEFER to ensure that the device is
- * not probed and to re-try again later.
- */
-int genpd_dev_pm_attach(struct device *dev)
-{
- if (!dev->of_node)
- return 0;
-
- /*
- * Devices with multiple PM domains must be attached separately, as we
- * can only attach one PM domain per device.
- */
- if (of_count_phandle_with_args(dev->of_node, "power-domains",
- "#power-domain-cells") != 1)
- return 0;
-
- return __genpd_dev_pm_attach(dev, dev, 0, true);
-}
-EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
-
-/**
- * genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
- * @dev: The device used to lookup the PM domain.
- * @index: The index of the PM domain.
- *
- * Parse device's OF node to find a PM domain specifier at the provided @index.
- * If such is found, creates a virtual device and attaches it to the retrieved
- * pm_domain ops. To deal with detaching of the virtual device, the ->detach()
- * callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach().
- *
- * Returns the created virtual device if successfully attached PM domain, NULL
- * when the device don't need a PM domain, else an ERR_PTR() in case of
- * failures. If a power-domain exists for the device, but cannot be found or
- * turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device
- * is not probed and to re-try again later.
- */
-struct device *genpd_dev_pm_attach_by_id(struct device *dev,
- unsigned int index)
-{
- struct device *virt_dev;
- int num_domains;
- int ret;
-
- if (!dev->of_node)
- return NULL;
-
- /* Verify that the index is within a valid range. */
- num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
- "#power-domain-cells");
- if (index >= num_domains)
- return NULL;
-
- /* Allocate and register device on the genpd bus. */
- virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL);
- if (!virt_dev)
- return ERR_PTR(-ENOMEM);
-
- dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
- virt_dev->bus = &genpd_bus_type;
- virt_dev->release = genpd_release_dev;
- virt_dev->of_node = of_node_get(dev->of_node);
-
- ret = device_register(virt_dev);
- if (ret) {
- put_device(virt_dev);
- return ERR_PTR(ret);
- }
-
- /* Try to attach the device to the PM domain at the specified index. */
- ret = __genpd_dev_pm_attach(virt_dev, dev, index, false);
- if (ret < 1) {
- device_unregister(virt_dev);
- return ret ? ERR_PTR(ret) : NULL;
- }
-
- pm_runtime_enable(virt_dev);
- genpd_queue_power_off_work(dev_to_genpd(virt_dev));
-
- return virt_dev;
-}
-EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);
-
-/**
- * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains.
- * @dev: The device used to lookup the PM domain.
- * @name: The name of the PM domain.
- *
- * Parse device's OF node to find a PM domain specifier using the
- * power-domain-names DT property. For further description see
- * genpd_dev_pm_attach_by_id().
- */
-struct device *genpd_dev_pm_attach_by_name(struct device *dev, const char *name)
-{
- int index;
-
- if (!dev->of_node)
- return NULL;
-
- index = of_property_match_string(dev->of_node, "power-domain-names",
- name);
- if (index < 0)
- return NULL;
-
- return genpd_dev_pm_attach_by_id(dev, index);
-}
-
-static const struct of_device_id idle_state_match[] = {
- { .compatible = "domain-idle-state", },
- { }
-};
-
-static int genpd_parse_state(struct genpd_power_state *genpd_state,
- struct device_node *state_node)
-{
- int err;
- u32 residency;
- u32 entry_latency, exit_latency;
-
- err = of_property_read_u32(state_node, "entry-latency-us",
- &entry_latency);
- if (err) {
- pr_debug(" * %pOF missing entry-latency-us property\n",
- state_node);
- return -EINVAL;
- }
-
- err = of_property_read_u32(state_node, "exit-latency-us",
- &exit_latency);
- if (err) {
- pr_debug(" * %pOF missing exit-latency-us property\n",
- state_node);
- return -EINVAL;
- }
-
- err = of_property_read_u32(state_node, "min-residency-us", &residency);
- if (!err)
- genpd_state->residency_ns = 1000LL * residency;
-
- genpd_state->power_on_latency_ns = 1000LL * exit_latency;
- genpd_state->power_off_latency_ns = 1000LL * entry_latency;
- genpd_state->fwnode = &state_node->fwnode;
-
- return 0;
-}
-
-static int genpd_iterate_idle_states(struct device_node *dn,
- struct genpd_power_state *states)
-{
- int ret;
- struct of_phandle_iterator it;
- struct device_node *np;
- int i = 0;
-
- ret = of_count_phandle_with_args(dn, "domain-idle-states", NULL);
- if (ret <= 0)
- return ret == -ENOENT ? 0 : ret;
-
- /* Loop over the phandles until all the requested entry is found */
- of_for_each_phandle(&it, ret, dn, "domain-idle-states", NULL, 0) {
- np = it.node;
- if (!of_match_node(idle_state_match, np))
- continue;
-
- if (!of_device_is_available(np))
- continue;
-
- if (states) {
- ret = genpd_parse_state(&states[i], np);
- if (ret) {
- pr_err("Parsing idle state node %pOF failed with err %d\n",
- np, ret);
- of_node_put(np);
- return ret;
- }
- }
- i++;
- }
-
- return i;
-}
-
-/**
- * of_genpd_parse_idle_states: Return array of idle states for the genpd.
- *
- * @dn: The genpd device node
- * @states: The pointer to which the state array will be saved.
- * @n: The count of elements in the array returned from this function.
- *
- * Returns the device states parsed from the OF node. The memory for the states
- * is allocated by this function and is the responsibility of the caller to
- * free the memory after use. If any or zero compatible domain idle states is
- * found it returns 0 and in case of errors, a negative error code is returned.
- */
-int of_genpd_parse_idle_states(struct device_node *dn,
- struct genpd_power_state **states, int *n)
-{
- struct genpd_power_state *st;
- int ret;
-
- ret = genpd_iterate_idle_states(dn, NULL);
- if (ret < 0)
- return ret;
-
- if (!ret) {
- *states = NULL;
- *n = 0;
- return 0;
- }
-
- st = kcalloc(ret, sizeof(*st), GFP_KERNEL);
- if (!st)
- return -ENOMEM;
-
- ret = genpd_iterate_idle_states(dn, st);
- if (ret <= 0) {
- kfree(st);
- return ret < 0 ? ret : -EINVAL;
- }
-
- *states = st;
- *n = ret;
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
-
-/**
- * pm_genpd_opp_to_performance_state - Gets performance state of the genpd from its OPP node.
- *
- * @genpd_dev: Genpd's device for which the performance-state needs to be found.
- * @opp: struct dev_pm_opp of the OPP for which we need to find performance
- * state.
- *
- * Returns performance state encoded in the OPP of the genpd. This calls
- * platform specific genpd->opp_to_performance_state() callback to translate
- * power domain OPP to performance state.
- *
- * Returns performance state on success and 0 on failure.
- */
-unsigned int pm_genpd_opp_to_performance_state(struct device *genpd_dev,
- struct dev_pm_opp *opp)
-{
- struct generic_pm_domain *genpd = NULL;
- int state;
-
- genpd = container_of(genpd_dev, struct generic_pm_domain, dev);
-
- if (unlikely(!genpd->opp_to_performance_state))
- return 0;
-
- genpd_lock(genpd);
- state = genpd->opp_to_performance_state(genpd, opp);
- genpd_unlock(genpd);
-
- return state;
-}
-EXPORT_SYMBOL_GPL(pm_genpd_opp_to_performance_state);
-
-static int __init genpd_bus_init(void)
-{
- return bus_register(&genpd_bus_type);
-}
-core_initcall(genpd_bus_init);
-
-#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
-
-
-/*** debugfs support ***/
-
-#ifdef CONFIG_DEBUG_FS
-/*
- * TODO: This function is a slightly modified version of rtpm_status_show
- * from sysfs.c, so generalize it.
- */
-static void rtpm_status_str(struct seq_file *s, struct device *dev)
-{
- static const char * const status_lookup[] = {
- [RPM_ACTIVE] = "active",
- [RPM_RESUMING] = "resuming",
- [RPM_SUSPENDED] = "suspended",
- [RPM_SUSPENDING] = "suspending"
- };
- const char *p = "";
-
- if (dev->power.runtime_error)
- p = "error";
- else if (dev->power.disable_depth)
- p = "unsupported";
- else if (dev->power.runtime_status < ARRAY_SIZE(status_lookup))
- p = status_lookup[dev->power.runtime_status];
- else
- WARN_ON(1);
-
- seq_printf(s, "%-25s ", p);
-}
-
-static void perf_status_str(struct seq_file *s, struct device *dev)
-{
- struct generic_pm_domain_data *gpd_data;
-
- gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
- seq_put_decimal_ull(s, "", gpd_data->performance_state);
-}
-
-static int genpd_summary_one(struct seq_file *s,
- struct generic_pm_domain *genpd)
-{
- static const char * const status_lookup[] = {
- [GENPD_STATE_ON] = "on",
- [GENPD_STATE_OFF] = "off"
- };
- struct pm_domain_data *pm_data;
- const char *kobj_path;
- struct gpd_link *link;
- char state[16];
- int ret;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup)))
- goto exit;
- if (!genpd_status_on(genpd))
- snprintf(state, sizeof(state), "%s-%u",
- status_lookup[genpd->status], genpd->state_idx);
- else
- snprintf(state, sizeof(state), "%s",
- status_lookup[genpd->status]);
- seq_printf(s, "%-30s %-50s %u", genpd->name, state, genpd->performance_state);
-
- /*
- * Modifications on the list require holding locks on both
- * parent and child, so we are safe.
- * Also genpd->name is immutable.
- */
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- if (list_is_first(&link->parent_node, &genpd->parent_links))
- seq_printf(s, "\n%48s", " ");
- seq_printf(s, "%s", link->child->name);
- if (!list_is_last(&link->parent_node, &genpd->parent_links))
- seq_puts(s, ", ");
- }
-
- list_for_each_entry(pm_data, &genpd->dev_list, list_node) {
- kobj_path = kobject_get_path(&pm_data->dev->kobj,
- genpd_is_irq_safe(genpd) ?
- GFP_ATOMIC : GFP_KERNEL);
- if (kobj_path == NULL)
- continue;
-
- seq_printf(s, "\n %-50s ", kobj_path);
- rtpm_status_str(s, pm_data->dev);
- perf_status_str(s, pm_data->dev);
- kfree(kobj_path);
- }
-
- seq_puts(s, "\n");
-exit:
- genpd_unlock(genpd);
-
- return 0;
-}
-
-static int summary_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd;
- int ret = 0;
-
- seq_puts(s, "domain status children performance\n");
- seq_puts(s, " /device runtime status\n");
- seq_puts(s, "----------------------------------------------------------------------------------------------\n");
-
- ret = mutex_lock_interruptible(&gpd_list_lock);
- if (ret)
- return -ERESTARTSYS;
-
- list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
- ret = genpd_summary_one(s, genpd);
- if (ret)
- break;
- }
- mutex_unlock(&gpd_list_lock);
-
- return ret;
-}
-
-static int status_show(struct seq_file *s, void *data)
-{
- static const char * const status_lookup[] = {
- [GENPD_STATE_ON] = "on",
- [GENPD_STATE_OFF] = "off"
- };
-
- struct generic_pm_domain *genpd = s->private;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- if (WARN_ON_ONCE(genpd->status >= ARRAY_SIZE(status_lookup)))
- goto exit;
-
- if (genpd->status == GENPD_STATE_OFF)
- seq_printf(s, "%s-%u\n", status_lookup[genpd->status],
- genpd->state_idx);
- else
- seq_printf(s, "%s\n", status_lookup[genpd->status]);
-exit:
- genpd_unlock(genpd);
- return ret;
-}
-
-static int sub_domains_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
- struct gpd_link *link;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- list_for_each_entry(link, &genpd->parent_links, parent_node)
- seq_printf(s, "%s\n", link->child->name);
-
- genpd_unlock(genpd);
- return ret;
-}
-
-static int idle_states_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
- u64 now, delta, idle_time = 0;
- unsigned int i;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- seq_puts(s, "State Time Spent(ms) Usage Rejected\n");
-
- for (i = 0; i < genpd->state_count; i++) {
- idle_time += genpd->states[i].idle_time;
-
- if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
- now = ktime_get_mono_fast_ns();
- if (now > genpd->accounting_time) {
- delta = now - genpd->accounting_time;
- idle_time += delta;
- }
- }
-
- do_div(idle_time, NSEC_PER_MSEC);
- seq_printf(s, "S%-13i %-14llu %-14llu %llu\n", i, idle_time,
- genpd->states[i].usage, genpd->states[i].rejected);
- }
-
- genpd_unlock(genpd);
- return ret;
-}
-
-static int active_time_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
- u64 now, on_time, delta = 0;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- if (genpd->status == GENPD_STATE_ON) {
- now = ktime_get_mono_fast_ns();
- if (now > genpd->accounting_time)
- delta = now - genpd->accounting_time;
- }
-
- on_time = genpd->on_time + delta;
- do_div(on_time, NSEC_PER_MSEC);
- seq_printf(s, "%llu ms\n", on_time);
-
- genpd_unlock(genpd);
- return ret;
-}
-
-static int total_idle_time_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
- u64 now, delta, total = 0;
- unsigned int i;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- for (i = 0; i < genpd->state_count; i++) {
- total += genpd->states[i].idle_time;
-
- if (genpd->status == GENPD_STATE_OFF && genpd->state_idx == i) {
- now = ktime_get_mono_fast_ns();
- if (now > genpd->accounting_time) {
- delta = now - genpd->accounting_time;
- total += delta;
- }
- }
- }
-
- do_div(total, NSEC_PER_MSEC);
- seq_printf(s, "%llu ms\n", total);
-
- genpd_unlock(genpd);
- return ret;
-}
-
-
-static int devices_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
- struct pm_domain_data *pm_data;
- const char *kobj_path;
- int ret = 0;
-
- ret = genpd_lock_interruptible(genpd);
- if (ret)
- return -ERESTARTSYS;
-
- list_for_each_entry(pm_data, &genpd->dev_list, list_node) {
- kobj_path = kobject_get_path(&pm_data->dev->kobj,
- genpd_is_irq_safe(genpd) ?
- GFP_ATOMIC : GFP_KERNEL);
- if (kobj_path == NULL)
- continue;
-
- seq_printf(s, "%s\n", kobj_path);
- kfree(kobj_path);
- }
-
- genpd_unlock(genpd);
- return ret;
-}
-
-static int perf_state_show(struct seq_file *s, void *data)
-{
- struct generic_pm_domain *genpd = s->private;
-
- if (genpd_lock_interruptible(genpd))
- return -ERESTARTSYS;
-
- seq_printf(s, "%u\n", genpd->performance_state);
-
- genpd_unlock(genpd);
- return 0;
-}
-
-DEFINE_SHOW_ATTRIBUTE(summary);
-DEFINE_SHOW_ATTRIBUTE(status);
-DEFINE_SHOW_ATTRIBUTE(sub_domains);
-DEFINE_SHOW_ATTRIBUTE(idle_states);
-DEFINE_SHOW_ATTRIBUTE(active_time);
-DEFINE_SHOW_ATTRIBUTE(total_idle_time);
-DEFINE_SHOW_ATTRIBUTE(devices);
-DEFINE_SHOW_ATTRIBUTE(perf_state);
-
-static void genpd_debug_add(struct generic_pm_domain *genpd)
-{
- struct dentry *d;
-
- if (!genpd_debugfs_dir)
- return;
-
- d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);
-
- debugfs_create_file("current_state", 0444,
- d, genpd, &status_fops);
- debugfs_create_file("sub_domains", 0444,
- d, genpd, &sub_domains_fops);
- debugfs_create_file("idle_states", 0444,
- d, genpd, &idle_states_fops);
- debugfs_create_file("active_time", 0444,
- d, genpd, &active_time_fops);
- debugfs_create_file("total_idle_time", 0444,
- d, genpd, &total_idle_time_fops);
- debugfs_create_file("devices", 0444,
- d, genpd, &devices_fops);
- if (genpd->set_performance_state)
- debugfs_create_file("perf_state", 0444,
- d, genpd, &perf_state_fops);
-}
-
-static int __init genpd_debug_init(void)
-{
- struct generic_pm_domain *genpd;
-
- genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);
-
- debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
- NULL, &summary_fops);
-
- list_for_each_entry(genpd, &gpd_list, gpd_list_node)
- genpd_debug_add(genpd);
-
- return 0;
-}
-late_initcall(genpd_debug_init);
-
-static void __exit genpd_debug_exit(void)
-{
- debugfs_remove_recursive(genpd_debugfs_dir);
-}
-__exitcall(genpd_debug_exit);
-#endif /* CONFIG_DEBUG_FS */
diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c
deleted file mode 100644
index cc2c3a5a6d..0000000000
--- a/drivers/base/power/domain_governor.c
+++ /dev/null
@@ -1,414 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * drivers/base/power/domain_governor.c - Governors for device PM domains.
- *
- * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
- */
-#include <linux/kernel.h>
-#include <linux/pm_domain.h>
-#include <linux/pm_qos.h>
-#include <linux/hrtimer.h>
-#include <linux/cpuidle.h>
-#include <linux/cpumask.h>
-#include <linux/ktime.h>
-
-static int dev_update_qos_constraint(struct device *dev, void *data)
-{
- s64 *constraint_ns_p = data;
- s64 constraint_ns;
-
- if (dev->power.subsys_data && dev->power.subsys_data->domain_data) {
- struct gpd_timing_data *td = dev_gpd_data(dev)->td;
-
- /*
- * Only take suspend-time QoS constraints of devices into
- * account, because constraints updated after the device has
- * been suspended are not guaranteed to be taken into account
- * anyway. In order for them to take effect, the device has to
- * be resumed and suspended again.
- */
- constraint_ns = td ? td->effective_constraint_ns :
- PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
- } else {
- /*
- * The child is not in a domain and there's no info on its
- * suspend/resume latencies, so assume them to be negligible and
- * take its current PM QoS constraint (that's the only thing
- * known at this point anyway).
- */
- constraint_ns = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY);
- constraint_ns *= NSEC_PER_USEC;
- }
-
- if (constraint_ns < *constraint_ns_p)
- *constraint_ns_p = constraint_ns;
-
- return 0;
-}
-
-/**
- * default_suspend_ok - Default PM domain governor routine to suspend devices.
- * @dev: Device to check.
- */
-static bool default_suspend_ok(struct device *dev)
-{
- struct gpd_timing_data *td = dev_gpd_data(dev)->td;
- unsigned long flags;
- s64 constraint_ns;
-
- dev_dbg(dev, "%s()\n", __func__);
-
- spin_lock_irqsave(&dev->power.lock, flags);
-
- if (!td->constraint_changed) {
- bool ret = td->cached_suspend_ok;
-
- spin_unlock_irqrestore(&dev->power.lock, flags);
- return ret;
- }
- td->constraint_changed = false;
- td->cached_suspend_ok = false;
- td->effective_constraint_ns = 0;
- constraint_ns = __dev_pm_qos_resume_latency(dev);
-
- spin_unlock_irqrestore(&dev->power.lock, flags);
-
- if (constraint_ns == 0)
- return false;
-
- constraint_ns *= NSEC_PER_USEC;
- /*
- * We can walk the children without any additional locking, because
- * they all have been suspended at this point and their
- * effective_constraint_ns fields won't be modified in parallel with us.
- */
- if (!dev->power.ignore_children)
- device_for_each_child(dev, &constraint_ns,
- dev_update_qos_constraint);
-
- if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS) {
- /* "No restriction", so the device is allowed to suspend. */
- td->effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS;
- td->cached_suspend_ok = true;
- } else if (constraint_ns == 0) {
- /*
- * This triggers if one of the children that don't belong to a
- * domain has a zero PM QoS constraint and it's better not to
- * suspend then. effective_constraint_ns is zero already and
- * cached_suspend_ok is false, so bail out.
- */
- return false;
- } else {
- constraint_ns -= td->suspend_latency_ns +
- td->resume_latency_ns;
- /*
- * effective_constraint_ns is zero already and cached_suspend_ok
- * is false, so if the computed value is not positive, return
- * right away.
- */
- if (constraint_ns <= 0)
- return false;
-
- td->effective_constraint_ns = constraint_ns;
- td->cached_suspend_ok = true;
- }
-
- /*
- * The children have been suspended already, so we don't need to take
- * their suspend latencies into account here.
- */
- return td->cached_suspend_ok;
-}
-
-static void update_domain_next_wakeup(struct generic_pm_domain *genpd, ktime_t now)
-{
- ktime_t domain_wakeup = KTIME_MAX;
- ktime_t next_wakeup;
- struct pm_domain_data *pdd;
- struct gpd_link *link;
-
- if (!(genpd->flags & GENPD_FLAG_MIN_RESIDENCY))
- return;
-
- /*
- * Devices that have a predictable wakeup pattern, may specify
- * their next wakeup. Let's find the next wakeup from all the
- * devices attached to this domain and from all the sub-domains.
- * It is possible that component's a next wakeup may have become
- * stale when we read that here. We will ignore to ensure the domain
- * is able to enter its optimal idle state.
- */
- list_for_each_entry(pdd, &genpd->dev_list, list_node) {
- next_wakeup = to_gpd_data(pdd)->td->next_wakeup;
- if (next_wakeup != KTIME_MAX && !ktime_before(next_wakeup, now))
- if (ktime_before(next_wakeup, domain_wakeup))
- domain_wakeup = next_wakeup;
- }
-
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- struct genpd_governor_data *cgd = link->child->gd;
-
- next_wakeup = cgd ? cgd->next_wakeup : KTIME_MAX;
- if (next_wakeup != KTIME_MAX && !ktime_before(next_wakeup, now))
- if (ktime_before(next_wakeup, domain_wakeup))
- domain_wakeup = next_wakeup;
- }
-
- genpd->gd->next_wakeup = domain_wakeup;
-}
-
-static bool next_wakeup_allows_state(struct generic_pm_domain *genpd,
- unsigned int state, ktime_t now)
-{
- ktime_t domain_wakeup = genpd->gd->next_wakeup;
- s64 idle_time_ns, min_sleep_ns;
-
- min_sleep_ns = genpd->states[state].power_off_latency_ns +
- genpd->states[state].residency_ns;
-
- idle_time_ns = ktime_to_ns(ktime_sub(domain_wakeup, now));
-
- return idle_time_ns >= min_sleep_ns;
-}
-
-static bool __default_power_down_ok(struct dev_pm_domain *pd,
- unsigned int state)
-{
- struct generic_pm_domain *genpd = pd_to_genpd(pd);
- struct gpd_link *link;
- struct pm_domain_data *pdd;
- s64 min_off_time_ns;
- s64 off_on_time_ns;
-
- off_on_time_ns = genpd->states[state].power_off_latency_ns +
- genpd->states[state].power_on_latency_ns;
-
- min_off_time_ns = -1;
- /*
- * Check if subdomains can be off for enough time.
- *
- * All subdomains have been powered off already at this point.
- */
- list_for_each_entry(link, &genpd->parent_links, parent_node) {
- struct genpd_governor_data *cgd = link->child->gd;
-
- s64 sd_max_off_ns = cgd ? cgd->max_off_time_ns : -1;
-
- if (sd_max_off_ns < 0)
- continue;
-
- /*
- * Check if the subdomain is allowed to be off long enough for
- * the current domain to turn off and on (that's how much time
- * it will have to wait worst case).
- */
- if (sd_max_off_ns <= off_on_time_ns)
- return false;
-
- if (min_off_time_ns > sd_max_off_ns || min_off_time_ns < 0)
- min_off_time_ns = sd_max_off_ns;
- }
-
- /*
- * Check if the devices in the domain can be off enough time.
- */
- list_for_each_entry(pdd, &genpd->dev_list, list_node) {
- struct gpd_timing_data *td;
- s64 constraint_ns;
-
- /*
- * Check if the device is allowed to be off long enough for the
- * domain to turn off and on (that's how much time it will
- * have to wait worst case).
- */
- td = to_gpd_data(pdd)->td;
- constraint_ns = td->effective_constraint_ns;
- /*
- * Zero means "no suspend at all" and this runs only when all
- * devices in the domain are suspended, so it must be positive.
- */
- if (constraint_ns == PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS)
- continue;
-
- if (constraint_ns <= off_on_time_ns)
- return false;
-
- if (min_off_time_ns > constraint_ns || min_off_time_ns < 0)
- min_off_time_ns = constraint_ns;
- }
-
- /*
- * If the computed minimum device off time is negative, there are no
- * latency constraints, so the domain can spend arbitrary time in the
- * "off" state.
- */
- if (min_off_time_ns < 0)
- return true;
-
- /*
- * The difference between the computed minimum subdomain or device off
- * time and the time needed to turn the domain on is the maximum
- * theoretical time this domain can spend in the "off" state.
- */
- genpd->gd->max_off_time_ns = min_off_time_ns -
- genpd->states[state].power_on_latency_ns;
- return true;
-}
-
-/**
- * _default_power_down_ok - Default generic PM domain power off governor routine.
- * @pd: PM domain to check.
- * @now: current ktime.
- *
- * This routine must be executed under the PM domain's lock.
- */
-static bool _default_power_down_ok(struct dev_pm_domain *pd, ktime_t now)
-{
- struct generic_pm_domain *genpd = pd_to_genpd(pd);
- struct genpd_governor_data *gd = genpd->gd;
- int state_idx = genpd->state_count - 1;
- struct gpd_link *link;
-
- /*
- * Find the next wakeup from devices that can determine their own wakeup
- * to find when the domain would wakeup and do it for every device down
- * the hierarchy. It is not worth while to sleep if the state's residency
- * cannot be met.
- */
- update_domain_next_wakeup(genpd, now);
- if ((genpd->flags & GENPD_FLAG_MIN_RESIDENCY) && (gd->next_wakeup != KTIME_MAX)) {
- /* Let's find out the deepest domain idle state, the devices prefer */
- while (state_idx >= 0) {
- if (next_wakeup_allows_state(genpd, state_idx, now)) {
- gd->max_off_time_changed = true;
- break;
- }
- state_idx--;
- }
-
- if (state_idx < 0) {
- state_idx = 0;
- gd->cached_power_down_ok = false;
- goto done;
- }
- }
-
- if (!gd->max_off_time_changed) {
- genpd->state_idx = gd->cached_power_down_state_idx;
- return gd->cached_power_down_ok;
- }
-
- /*
- * We have to invalidate the cached results for the parents, so
- * use the observation that default_power_down_ok() is not
- * going to be called for any parent until this instance
- * returns.
- */
- list_for_each_entry(link, &genpd->child_links, child_node) {
- struct genpd_governor_data *pgd = link->parent->gd;
-
- if (pgd)
- pgd->max_off_time_changed = true;
- }
-
- gd->max_off_time_ns = -1;
- gd->max_off_time_changed = false;
- gd->cached_power_down_ok = true;
-
- /*
- * Find a state to power down to, starting from the state
- * determined by the next wakeup.
- */
- while (!__default_power_down_ok(pd, state_idx)) {
- if (state_idx == 0) {
- gd->cached_power_down_ok = false;
- break;
- }
- state_idx--;
- }
-
-done:
- genpd->state_idx = state_idx;
- gd->cached_power_down_state_idx = genpd->state_idx;
- return gd->cached_power_down_ok;
-}
-
-static bool default_power_down_ok(struct dev_pm_domain *pd)
-{
- return _default_power_down_ok(pd, ktime_get());
-}
-
-#ifdef CONFIG_CPU_IDLE
-static bool cpu_power_down_ok(struct dev_pm_domain *pd)
-{
- struct generic_pm_domain *genpd = pd_to_genpd(pd);
- struct cpuidle_device *dev;
- ktime_t domain_wakeup, next_hrtimer;
- ktime_t now = ktime_get();
- s64 idle_duration_ns;
- int cpu, i;
-
- /* Validate dev PM QoS constraints. */
- if (!_default_power_down_ok(pd, now))
- return false;
-
- if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN))
- return true;
-
- /*
- * Find the next wakeup for any of the online CPUs within the PM domain
- * and its subdomains. Note, we only need the genpd->cpus, as it already
- * contains a mask of all CPUs from subdomains.
- */
- domain_wakeup = ktime_set(KTIME_SEC_MAX, 0);
- for_each_cpu_and(cpu, genpd->cpus, cpu_online_mask) {
- dev = per_cpu(cpuidle_devices, cpu);
- if (dev) {
- next_hrtimer = READ_ONCE(dev->next_hrtimer);
- if (ktime_before(next_hrtimer, domain_wakeup))
- domain_wakeup = next_hrtimer;
- }
- }
-
- /* The minimum idle duration is from now - until the next wakeup. */
- idle_duration_ns = ktime_to_ns(ktime_sub(domain_wakeup, now));
- if (idle_duration_ns <= 0)
- return false;
-
- /* Store the next domain_wakeup to allow consumers to use it. */
- genpd->gd->next_hrtimer = domain_wakeup;
-
- /*
- * Find the deepest idle state that has its residency value satisfied
- * and by also taking into account the power off latency for the state.
- * Start at the state picked by the dev PM QoS constraint validation.
- */
- i = genpd->state_idx;
- do {
- if (idle_duration_ns >= (genpd->states[i].residency_ns +
- genpd->states[i].power_off_latency_ns)) {
- genpd->state_idx = i;
- return true;
- }
- } while (--i >= 0);
-
- return false;
-}
-
-struct dev_power_governor pm_domain_cpu_gov = {
- .suspend_ok = default_suspend_ok,
- .power_down_ok = cpu_power_down_ok,
-};
-#endif
-
-struct dev_power_governor simple_qos_governor = {
- .suspend_ok = default_suspend_ok,
- .power_down_ok = default_power_down_ok,
-};
-
-/**
- * pm_genpd_gov_always_on - A governor implementing an always-on policy
- */
-struct dev_power_governor pm_domain_always_on_gov = {
- .suspend_ok = default_suspend_ok,
-};
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 9c5a5f4dba..fadcd0379d 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -579,7 +579,7 @@ bool dev_pm_skip_resume(struct device *dev)
}
/**
- * __device_resume_noirq - Execute a "noirq resume" callback for given device.
+ * device_resume_noirq - Execute a "noirq resume" callback for given device.
* @dev: Device to handle.
* @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously.
@@ -587,7 +587,7 @@ bool dev_pm_skip_resume(struct device *dev)
* The driver of @dev will not receive interrupts while this function is being
* executed.
*/
-static void __device_resume_noirq(struct device *dev, pm_message_t state, bool async)
+static void device_resume_noirq(struct device *dev, pm_message_t state, bool async)
{
pm_callback_t callback = NULL;
const char *info = NULL;
@@ -674,16 +674,22 @@ static bool dpm_async_fn(struct device *dev, async_func_t func)
{
reinit_completion(&dev->power.completion);
- if (!is_async(dev))
- return false;
-
- get_device(dev);
+ if (is_async(dev)) {
+ dev->power.async_in_progress = true;
- if (async_schedule_dev_nocall(func, dev))
- return true;
+ get_device(dev);
- put_device(dev);
+ if (async_schedule_dev_nocall(func, dev))
+ return true;
+ put_device(dev);
+ }
+ /*
+ * Because async_schedule_dev_nocall() above has returned false or it
+ * has not been called at all, func() is not running and it is safe to
+ * update the async_in_progress flag without extra synchronization.
+ */
+ dev->power.async_in_progress = false;
return false;
}
@@ -691,18 +697,10 @@ static void async_resume_noirq(void *data, async_cookie_t cookie)
{
struct device *dev = data;
- __device_resume_noirq(dev, pm_transition, true);
+ device_resume_noirq(dev, pm_transition, true);
put_device(dev);
}
-static void device_resume_noirq(struct device *dev)
-{
- if (dpm_async_fn(dev, async_resume_noirq))
- return;
-
- __device_resume_noirq(dev, pm_transition, false);
-}
-
static void dpm_noirq_resume_devices(pm_message_t state)
{
struct device *dev;
@@ -712,18 +710,28 @@ static void dpm_noirq_resume_devices(pm_message_t state)
mutex_lock(&dpm_list_mtx);
pm_transition = state;
+ /*
+ * Trigger the resume of "async" devices upfront so they don't have to
+ * wait for the "non-async" ones they don't depend on.
+ */
+ list_for_each_entry(dev, &dpm_noirq_list, power.entry)
+ dpm_async_fn(dev, async_resume_noirq);
+
while (!list_empty(&dpm_noirq_list)) {
dev = to_device(dpm_noirq_list.next);
- get_device(dev);
list_move_tail(&dev->power.entry, &dpm_late_early_list);
- mutex_unlock(&dpm_list_mtx);
+ if (!dev->power.async_in_progress) {
+ get_device(dev);
- device_resume_noirq(dev);
+ mutex_unlock(&dpm_list_mtx);
- put_device(dev);
+ device_resume_noirq(dev, state, false);
- mutex_lock(&dpm_list_mtx);
+ put_device(dev);
+
+ mutex_lock(&dpm_list_mtx);
+ }
}
mutex_unlock(&dpm_list_mtx);
async_synchronize_full();
@@ -747,14 +755,14 @@ void dpm_resume_noirq(pm_message_t state)
}
/**
- * __device_resume_early - Execute an "early resume" callback for given device.
+ * device_resume_early - Execute an "early resume" callback for given device.
* @dev: Device to handle.
* @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously.
*
* Runtime PM is disabled for @dev while this function is being executed.
*/
-static void __device_resume_early(struct device *dev, pm_message_t state, bool async)
+static void device_resume_early(struct device *dev, pm_message_t state, bool async)
{
pm_callback_t callback = NULL;
const char *info = NULL;
@@ -820,18 +828,10 @@ static void async_resume_early(void *data, async_cookie_t cookie)
{
struct device *dev = data;
- __device_resume_early(dev, pm_transition, true);
+ device_resume_early(dev, pm_transition, true);
put_device(dev);
}
-static void device_resume_early(struct device *dev)
-{
- if (dpm_async_fn(dev, async_resume_early))
- return;
-
- __device_resume_early(dev, pm_transition, false);
-}
-
/**
* dpm_resume_early - Execute "early resume" callbacks for all devices.
* @state: PM transition of the system being carried out.
@@ -845,18 +845,28 @@ void dpm_resume_early(pm_message_t state)
mutex_lock(&dpm_list_mtx);
pm_transition = state;
+ /*
+ * Trigger the resume of "async" devices upfront so they don't have to
+ * wait for the "non-async" ones they don't depend on.
+ */
+ list_for_each_entry(dev, &dpm_late_early_list, power.entry)
+ dpm_async_fn(dev, async_resume_early);
+
while (!list_empty(&dpm_late_early_list)) {
dev = to_device(dpm_late_early_list.next);
- get_device(dev);
list_move_tail(&dev->power.entry, &dpm_suspended_list);
- mutex_unlock(&dpm_list_mtx);
+ if (!dev->power.async_in_progress) {
+ get_device(dev);
- device_resume_early(dev);
+ mutex_unlock(&dpm_list_mtx);
- put_device(dev);
+ device_resume_early(dev, state, false);
- mutex_lock(&dpm_list_mtx);
+ put_device(dev);
+
+ mutex_lock(&dpm_list_mtx);
+ }
}
mutex_unlock(&dpm_list_mtx);
async_synchronize_full();
@@ -876,12 +886,12 @@ void dpm_resume_start(pm_message_t state)
EXPORT_SYMBOL_GPL(dpm_resume_start);
/**
- * __device_resume - Execute "resume" callbacks for given device.
+ * device_resume - Execute "resume" callbacks for given device.
* @dev: Device to handle.
* @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously.
*/
-static void __device_resume(struct device *dev, pm_message_t state, bool async)
+static void device_resume(struct device *dev, pm_message_t state, bool async)
{
pm_callback_t callback = NULL;
const char *info = NULL;
@@ -975,18 +985,10 @@ static void async_resume(void *data, async_cookie_t cookie)
{
struct device *dev = data;
- __device_resume(dev, pm_transition, true);
+ device_resume(dev, pm_transition, true);
put_device(dev);
}
-static void device_resume(struct device *dev)
-{
- if (dpm_async_fn(dev, async_resume))
- return;
-
- __device_resume(dev, pm_transition, false);
-}
-
/**
* dpm_resume - Execute "resume" callbacks for non-sysdev devices.
* @state: PM transition of the system being carried out.
@@ -1006,16 +1008,25 @@ void dpm_resume(pm_message_t state)
pm_transition = state;
async_error = 0;
+ /*
+ * Trigger the resume of "async" devices upfront so they don't have to
+ * wait for the "non-async" ones they don't depend on.
+ */
+ list_for_each_entry(dev, &dpm_suspended_list, power.entry)
+ dpm_async_fn(dev, async_resume);
+
while (!list_empty(&dpm_suspended_list)) {
dev = to_device(dpm_suspended_list.next);
get_device(dev);
- mutex_unlock(&dpm_list_mtx);
+ if (!dev->power.async_in_progress) {
+ mutex_unlock(&dpm_list_mtx);
- device_resume(dev);
+ device_resume(dev, state, false);
- mutex_lock(&dpm_list_mtx);
+ mutex_lock(&dpm_list_mtx);
+ }
if (!list_empty(&dev->power.entry))
list_move_tail(&dev->power.entry, &dpm_prepared_list);
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index 8e93167f17..bd77f6734f 100644
--- a/drivers/base/power/qos.c
+++ b/drivers/base/power/qos.c
@@ -201,7 +201,7 @@ static int dev_pm_qos_constraints_allocate(struct device *dev)
if (!qos)
return -ENOMEM;
- n = kzalloc(3 * sizeof(*n), GFP_KERNEL);
+ n = kcalloc(3, sizeof(*n), GFP_KERNEL);
if (!n) {
kfree(qos);
return -ENOMEM;
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 4545669cb9..05793c9fbb 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -11,6 +11,7 @@
#include <linux/export.h>
#include <linux/pm_runtime.h>
#include <linux/pm_wakeirq.h>
+#include <linux/rculist.h>
#include <trace/events/rpm.h>
#include "../base.h"
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 8c40abed78..a1b01ab420 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -473,7 +473,7 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
const char **values;
int nval, ret;
- nval = fwnode_property_read_string_array(fwnode, propname, NULL, 0);
+ nval = fwnode_property_string_array_count(fwnode, propname);
if (nval < 0)
return nval;
@@ -499,6 +499,41 @@ out_free:
EXPORT_SYMBOL_GPL(fwnode_property_match_string);
/**
+ * fwnode_property_match_property_string - find a property string value in an array and return index
+ * @fwnode: Firmware node to get the property of
+ * @propname: Name of the property holding the string value
+ * @array: String array to search in
+ * @n: Size of the @array
+ *
+ * Find a property string value in a given @array and if it is found return
+ * the index back.
+ *
+ * Return: index, starting from %0, if the string value was found in the @array (success),
+ * %-ENOENT when the string value was not found in the @array,
+ * %-EINVAL if given arguments are not valid,
+ * %-ENODATA if the property does not have a value,
+ * %-EPROTO or %-EILSEQ if the property is not a string,
+ * %-ENXIO if no suitable firmware interface is present.
+ */
+int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
+ const char *propname, const char * const *array, size_t n)
+{
+ const char *string;
+ int ret;
+
+ ret = fwnode_property_read_string(fwnode, propname, &string);
+ if (ret)
+ return ret;
+
+ ret = match_string(array, n, string);
+ if (ret < 0)
+ ret = -ENOENT;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(fwnode_property_match_property_string);
+
+/**
* fwnode_property_get_reference_args() - Find a reference with arguments
* @fwnode: Firmware node where to look for the reference
* @prop: The name of the property
@@ -508,6 +543,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_string);
* @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL.
* @index: Index of the reference, from zero onwards.
* @args: Result structure with reference and integer arguments.
+ * May be NULL.
*
* Obtain a reference based on a named property in an fwnode, with
* integer arguments.
@@ -595,6 +631,34 @@ const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
}
/**
+ * fwnode_name_eq - Return true if node name is equal
+ * @fwnode: The firmware node
+ * @name: The name to which to compare the node name
+ *
+ * Compare the name provided as an argument to the name of the node, stopping
+ * the comparison at either NUL or '@' character, whichever comes first. This
+ * function is generally used for comparing node names while ignoring the
+ * possible unit address of the node.
+ *
+ * Return: true if the node name matches with the name provided in the @name
+ * argument, false otherwise.
+ */
+bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name)
+{
+ const char *node_name;
+ ptrdiff_t len;
+
+ node_name = fwnode_get_name(fwnode);
+ if (!node_name)
+ return false;
+
+ len = strchrnul(node_name, '@') - node_name;
+
+ return str_has_prefix(node_name, name) == len;
+}
+EXPORT_SYMBOL_GPL(fwnode_name_eq);
+
+/**
* fwnode_get_parent - Return parent firwmare node
* @fwnode: Firmware whose parent is retrieved
*
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 9a9ea514c2..583dd5d7d4 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -318,6 +318,7 @@ struct regmap_ram_data {
bool *read;
bool *written;
enum regmap_endian reg_endian;
+ bool (*noinc_reg)(struct regmap_ram_data *data, unsigned int reg);
};
/*
diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
index 41edd6a430..55999a50cc 100644
--- a/drivers/base/regmap/regcache-maple.c
+++ b/drivers/base/regmap/regcache-maple.c
@@ -112,7 +112,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
unsigned long *entry, *lower, *upper;
unsigned long lower_index, lower_last;
unsigned long upper_index, upper_last;
- int ret;
+ int ret = 0;
lower = NULL;
upper = NULL;
@@ -145,7 +145,7 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
upper_index = max + 1;
upper_last = mas.last;
- upper = kmemdup(&entry[max + 1],
+ upper = kmemdup(&entry[max - mas.index + 1],
((mas.last - max) *
sizeof(unsigned long)),
map->alloc_flags);
@@ -244,7 +244,7 @@ static int regcache_maple_sync(struct regmap *map, unsigned int min,
unsigned long lmin = min;
unsigned long lmax = max;
unsigned int r, v, sync_start;
- int ret;
+ int ret = 0;
bool sync_needed = false;
map->cache_bypass = true;
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index bdd80b73c3..fb84cda92a 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -226,8 +226,8 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
if (*ppos < 0 || !count)
return -EINVAL;
- if (count > (PAGE_SIZE << MAX_ORDER))
- count = PAGE_SIZE << MAX_ORDER;
+ if (count > (PAGE_SIZE << MAX_PAGE_ORDER))
+ count = PAGE_SIZE << MAX_PAGE_ORDER;
buf = kmalloc(count, GFP_KERNEL);
if (!buf)
@@ -373,8 +373,8 @@ static ssize_t regmap_reg_ranges_read_file(struct file *file,
if (*ppos < 0 || !count)
return -EINVAL;
- if (count > (PAGE_SIZE << MAX_ORDER))
- count = PAGE_SIZE << MAX_ORDER;
+ if (count > (PAGE_SIZE << MAX_PAGE_ORDER))
+ count = PAGE_SIZE << MAX_PAGE_ORDER;
buf = kmalloc(count, GFP_KERNEL);
if (!buf)
diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c
index 4c9e38ead5..0d957c5f1b 100644
--- a/drivers/base/regmap/regmap-kunit.c
+++ b/drivers/base/regmap/regmap-kunit.c
@@ -1203,6 +1203,66 @@ static void raw_write(struct kunit *test)
regmap_exit(map);
}
+static bool reg_zero(struct device *dev, unsigned int reg)
+{
+ return reg == 0;
+}
+
+static bool ram_reg_zero(struct regmap_ram_data *data, unsigned int reg)
+{
+ return reg == 0;
+}
+
+static void raw_noinc_write(struct kunit *test)
+{
+ struct raw_test_types *t = (struct raw_test_types *)test->param_value;
+ struct regmap *map;
+ struct regmap_config config;
+ struct regmap_ram_data *data;
+ unsigned int val;
+ u16 val_test, val_last;
+ u16 val_array[BLOCK_TEST_SIZE];
+
+ config = raw_regmap_config;
+ config.volatile_reg = reg_zero;
+ config.writeable_noinc_reg = reg_zero;
+ config.readable_noinc_reg = reg_zero;
+
+ map = gen_raw_regmap(&config, t, &data);
+ KUNIT_ASSERT_FALSE(test, IS_ERR(map));
+ if (IS_ERR(map))
+ return;
+
+ data->noinc_reg = ram_reg_zero;
+
+ get_random_bytes(&val_array, sizeof(val_array));
+
+ if (config.val_format_endian == REGMAP_ENDIAN_BIG) {
+ val_test = be16_to_cpu(val_array[1]) + 100;
+ val_last = be16_to_cpu(val_array[BLOCK_TEST_SIZE - 1]);
+ } else {
+ val_test = le16_to_cpu(val_array[1]) + 100;
+ val_last = le16_to_cpu(val_array[BLOCK_TEST_SIZE - 1]);
+ }
+
+ /* Put some data into the register following the noinc register */
+ KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 1, val_test));
+
+ /* Write some data to the noinc register */
+ KUNIT_EXPECT_EQ(test, 0, regmap_noinc_write(map, 0, val_array,
+ sizeof(val_array)));
+
+ /* We should read back the last value written */
+ KUNIT_EXPECT_EQ(test, 0, regmap_read(map, 0, &val));
+ KUNIT_ASSERT_EQ(test, val_last, val);
+
+ /* Make sure we didn't touch the register after the noinc register */
+ KUNIT_EXPECT_EQ(test, 0, regmap_read(map, 1, &val));
+ KUNIT_ASSERT_EQ(test, val_test, val);
+
+ regmap_exit(map);
+}
+
static void raw_sync(struct kunit *test)
{
struct raw_test_types *t = (struct raw_test_types *)test->param_value;
@@ -1306,6 +1366,7 @@ static struct kunit_case regmap_test_cases[] = {
KUNIT_CASE_PARAM(raw_read_defaults, raw_test_types_gen_params),
KUNIT_CASE_PARAM(raw_write_read_single, raw_test_types_gen_params),
KUNIT_CASE_PARAM(raw_write, raw_test_types_gen_params),
+ KUNIT_CASE_PARAM(raw_noinc_write, raw_test_types_gen_params),
KUNIT_CASE_PARAM(raw_sync, raw_test_cache_types_gen_params),
{}
};
diff --git a/drivers/base/regmap/regmap-ram.c b/drivers/base/regmap/regmap-ram.c
index 85f34a5dee..192d6b131d 100644
--- a/drivers/base/regmap/regmap-ram.c
+++ b/drivers/base/regmap/regmap-ram.c
@@ -65,12 +65,12 @@ struct regmap *__regmap_init_ram(const struct regmap_config *config,
return ERR_PTR(-EINVAL);
}
- data->read = kcalloc(sizeof(bool), config->max_register + 1,
+ data->read = kcalloc(config->max_register + 1, sizeof(bool),
GFP_KERNEL);
if (!data->read)
return ERR_PTR(-ENOMEM);
- data->written = kcalloc(sizeof(bool), config->max_register + 1,
+ data->written = kcalloc(config->max_register + 1, sizeof(bool),
GFP_KERNEL);
if (!data->written)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/base/regmap/regmap-raw-ram.c b/drivers/base/regmap/regmap-raw-ram.c
index c9b800885f..93ae07b503 100644
--- a/drivers/base/regmap/regmap-raw-ram.c
+++ b/drivers/base/regmap/regmap-raw-ram.c
@@ -41,10 +41,15 @@ static int regmap_raw_ram_gather_write(void *context,
return -EINVAL;
r = decode_reg(data->reg_endian, reg);
- memcpy(&our_buf[r], val, val_len);
-
- for (i = 0; i < val_len / 2; i++)
- data->written[r + i] = true;
+ if (data->noinc_reg && data->noinc_reg(data, r)) {
+ memcpy(&our_buf[r], val + val_len - 2, 2);
+ data->written[r] = true;
+ } else {
+ memcpy(&our_buf[r], val, val_len);
+
+ for (i = 0; i < val_len / 2; i++)
+ data->written[r + i] = true;
+ }
return 0;
}
@@ -70,10 +75,16 @@ static int regmap_raw_ram_read(void *context,
return -EINVAL;
r = decode_reg(data->reg_endian, reg);
- memcpy(val, &our_buf[r], val_len);
-
- for (i = 0; i < val_len / 2; i++)
- data->read[r + i] = true;
+ if (data->noinc_reg && data->noinc_reg(data, r)) {
+ for (i = 0; i < val_len; i += 2)
+ memcpy(val + i, &our_buf[r], 2);
+ data->read[r] = true;
+ } else {
+ memcpy(val, &our_buf[r], val_len);
+
+ for (i = 0; i < val_len / 2; i++)
+ data->read[r + i] = true;
+ }
return 0;
}
@@ -111,12 +122,12 @@ struct regmap *__regmap_init_raw_ram(const struct regmap_config *config,
return ERR_PTR(-EINVAL);
}
- data->read = kcalloc(sizeof(bool), config->max_register + 1,
+ data->read = kcalloc(config->max_register + 1, sizeof(bool),
GFP_KERNEL);
if (!data->read)
return ERR_PTR(-ENOMEM);
- data->written = kcalloc(sizeof(bool), config->max_register + 1,
+ data->written = kcalloc(config->max_register + 1, sizeof(bool),
GFP_KERNEL);
if (!data->written)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ea61577471..6db77d8e45 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2136,7 +2136,7 @@ static int regmap_noinc_readwrite(struct regmap *map, unsigned int reg,
}
/**
- * regmap_noinc_write(): Write data from a register without incrementing the
+ * regmap_noinc_write(): Write data to a register without incrementing the
* register number
*
* @map: Register map to write to
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 8dec5228fd..282c38aece 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -28,7 +28,7 @@ struct soc_device {
int soc_dev_num;
};
-static struct bus_type soc_bus_type = {
+static const struct bus_type soc_bus_type = {
.name = "soc",
};
static bool soc_bus_registered;
@@ -106,7 +106,7 @@ static void soc_release(struct device *dev)
{
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
- ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
+ ida_free(&soc_ida, soc_dev->soc_dev_num);
kfree(soc_dev->dev.groups);
kfree(soc_dev);
}
@@ -155,7 +155,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
soc_attr_groups[1] = soc_dev_attr->custom_attr_group;
/* Fetch a unique (reclaimable) SOC ID. */
- ret = ida_simple_get(&soc_ida, 0, 0, GFP_KERNEL);
+ ret = ida_alloc(&soc_ida, GFP_KERNEL);
if (ret < 0)
goto out3;
soc_dev->soc_dev_num = ret;
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 079bd14bde..36512fb75a 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -750,10 +750,10 @@ static void software_node_release(struct kobject *kobj)
struct swnode *swnode = kobj_to_swnode(kobj);
if (swnode->parent) {
- ida_simple_remove(&swnode->parent->child_ids, swnode->id);
+ ida_free(&swnode->parent->child_ids, swnode->id);
list_del(&swnode->entry);
} else {
- ida_simple_remove(&swnode_root_ids, swnode->id);
+ ida_free(&swnode_root_ids, swnode->id);
}
if (swnode->allocated)
@@ -779,8 +779,8 @@ swnode_register(const struct software_node *node, struct swnode *parent,
if (!swnode)
return ERR_PTR(-ENOMEM);
- ret = ida_simple_get(parent ? &parent->child_ids : &swnode_root_ids,
- 0, 0, GFP_KERNEL);
+ ret = ida_alloc(parent ? &parent->child_ids : &swnode_root_ids,
+ GFP_KERNEL);
if (ret < 0) {
kfree(swnode);
return ERR_PTR(ret);