Skip to content

Commit 4614e0c

Browse files
committed
Merge branches 'pm-cpu', 'pm-cpuidle' and 'pm-domains'
* pm-cpu: kernel/cpu_pm: fix cpu_cluster_pm_exit comment * pm-cpuidle: cpuidle/coupled: Add sanity check for safe_state_index * pm-domains: staging: board: Migrate away from __pm_genpd_name_add_device() PM / Domains: Ensure subdomain is not in use before removing PM / Domains: Try power off masters in error path of __pm_genpd_poweron()
4 parents 3e66c4b + 21dd33b + abceaa9 + f33b774 commit 4614e0c

File tree

7 files changed

+94
-16
lines changed

7 files changed

+94
-16
lines changed

drivers/base/power/domain.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool timed)
212212
return ret;
213213
}
214214

215+
/**
216+
* genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff().
217+
* @genpd: PM domait to power off.
218+
*
219+
* Queue up the execution of pm_genpd_poweroff() unless it's already been done
220+
* before.
221+
*/
222+
static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
223+
{
224+
queue_work(pm_wq, &genpd->power_off_work);
225+
}
226+
215227
/**
216228
* __pm_genpd_poweron - Restore power to a given PM domain and its masters.
217229
* @genpd: PM domain to power up.
@@ -259,8 +271,12 @@ static int __pm_genpd_poweron(struct generic_pm_domain *genpd)
259271
return 0;
260272

261273
err:
262-
list_for_each_entry_continue_reverse(link, &genpd->slave_links, slave_node)
274+
list_for_each_entry_continue_reverse(link,
275+
&genpd->slave_links,
276+
slave_node) {
263277
genpd_sd_counter_dec(link->master);
278+
genpd_queue_power_off_work(link->master);
279+
}
264280

265281
return ret;
266282
}
@@ -348,18 +364,6 @@ static int genpd_dev_pm_qos_notifier(struct notifier_block *nb,
348364
return NOTIFY_DONE;
349365
}
350366

351-
/**
352-
* genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff().
353-
* @genpd: PM domait to power off.
354-
*
355-
* Queue up the execution of pm_genpd_poweroff() unless it's already been done
356-
* before.
357-
*/
358-
static void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
359-
{
360-
queue_work(pm_wq, &genpd->power_off_work);
361-
}
362-
363367
/**
364368
* pm_genpd_poweroff - Remove power from a given PM domain.
365369
* @genpd: PM domain to power down.
@@ -1469,6 +1473,13 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
14691473

14701474
mutex_lock(&genpd->lock);
14711475

1476+
if (!list_empty(&subdomain->slave_links) || subdomain->device_count) {
1477+
pr_warn("%s: unable to remove subdomain %s\n", genpd->name,
1478+
subdomain->name);
1479+
ret = -EBUSY;
1480+
goto out;
1481+
}
1482+
14721483
list_for_each_entry(link, &genpd->master_links, master_node) {
14731484
if (link->slave != subdomain)
14741485
continue;
@@ -1487,6 +1498,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
14871498
break;
14881499
}
14891500

1501+
out:
14901502
mutex_unlock(&genpd->lock);
14911503

14921504
return ret;

drivers/cpuidle/coupled.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state)
186186
return drv->states[state].flags & CPUIDLE_FLAG_COUPLED;
187187
}
188188

189+
/**
190+
* cpuidle_coupled_state_verify - check if the coupled states are correctly set.
191+
* @drv: struct cpuidle_driver for the platform
192+
*
193+
* Returns 0 for valid state values, a negative error code otherwise:
194+
* * -EINVAL if any coupled state(safe_state_index) is wrongly set.
195+
*/
196+
int cpuidle_coupled_state_verify(struct cpuidle_driver *drv)
197+
{
198+
int i;
199+
200+
for (i = drv->state_count - 1; i >= 0; i--) {
201+
if (cpuidle_state_is_coupled(drv, i) &&
202+
(drv->safe_state_index == i ||
203+
drv->safe_state_index < 0 ||
204+
drv->safe_state_index >= drv->state_count))
205+
return -EINVAL;
206+
}
207+
208+
return 0;
209+
}
210+
189211
/**
190212
* cpuidle_coupled_set_ready - mark a cpu as ready
191213
* @coupled: the struct coupled that contains the current cpu

drivers/cpuidle/cpuidle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern void cpuidle_remove_sysfs(struct cpuidle_device *dev);
3535

3636
#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
3737
bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state);
38+
int cpuidle_coupled_state_verify(struct cpuidle_driver *drv);
3839
int cpuidle_enter_state_coupled(struct cpuidle_device *dev,
3940
struct cpuidle_driver *drv, int next_state);
4041
int cpuidle_coupled_register_device(struct cpuidle_device *dev);
@@ -46,6 +47,11 @@ bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state)
4647
return false;
4748
}
4849

50+
static inline int cpuidle_coupled_state_verify(struct cpuidle_driver *drv)
51+
{
52+
return 0;
53+
}
54+
4955
static inline int cpuidle_enter_state_coupled(struct cpuidle_device *dev,
5056
struct cpuidle_driver *drv, int next_state)
5157
{

drivers/cpuidle/driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
227227
if (!drv || !drv->state_count)
228228
return -EINVAL;
229229

230+
ret = cpuidle_coupled_state_verify(drv);
231+
if (ret)
232+
return ret;
233+
230234
if (cpuidle_disabled())
231235
return -ENODEV;
232236

drivers/staging/board/armadillo800eva.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static const struct board_staging_dev armadillo800eva_devices[] __initconst = {
9191
.pdev = &lcdc0_device,
9292
.clocks = lcdc0_clocks,
9393
.nclocks = ARRAY_SIZE(lcdc0_clocks),
94-
.domain = "a4lc",
94+
.domain = "/system-controller@e6180000/pm-domains/c5/a4lc@1"
9595
},
9696
};
9797

drivers/staging/board/board.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,40 @@ int __init board_staging_register_clock(const struct board_staging_clk *bsc)
135135
return error;
136136
}
137137

138+
#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
139+
static int board_staging_add_dev_domain(struct platform_device *pdev,
140+
const char *domain)
141+
{
142+
struct of_phandle_args pd_args;
143+
struct generic_pm_domain *pd;
144+
struct device_node *np;
145+
146+
np = of_find_node_by_path(domain);
147+
if (!np) {
148+
pr_err("Cannot find domain node %s\n", domain);
149+
return -ENOENT;
150+
}
151+
152+
pd_args.np = np;
153+
pd_args.args_count = 0;
154+
pd = of_genpd_get_from_provider(&pd_args);
155+
if (IS_ERR(pd)) {
156+
pr_err("Cannot find genpd %s (%ld)\n", domain, PTR_ERR(pd));
157+
return PTR_ERR(pd);
158+
159+
}
160+
pr_debug("Found genpd %s for device %s\n", pd->name, pdev->name);
161+
162+
return pm_genpd_add_device(pd, &pdev->dev);
163+
}
164+
#else
165+
static inline int board_staging_add_dev_domain(struct platform_device *pdev,
166+
const char *domain)
167+
{
168+
return 0;
169+
}
170+
#endif
171+
138172
int __init board_staging_register_device(const struct board_staging_dev *dev)
139173
{
140174
struct platform_device *pdev = dev->pdev;
@@ -161,7 +195,7 @@ int __init board_staging_register_device(const struct board_staging_dev *dev)
161195
}
162196

163197
if (dev->domain)
164-
__pm_genpd_name_add_device(dev->domain, &pdev->dev, NULL);
198+
board_staging_add_dev_domain(pdev, dev->domain);
165199

166200
return error;
167201
}

kernel/cpu_pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
180180
* low power state that may have caused some blocks in the same power domain
181181
* to reset.
182182
*
183-
* Must be called after cpu_pm_exit has been called on all cpus in the power
183+
* Must be called after cpu_cluster_pm_enter has been called for the power
184184
* domain, and before cpu_pm_exit has been called on any cpu in the power
185185
* domain. Notified drivers can include VFP co-processor, interrupt controller
186186
* and its PM extensions, local CPU timers context save/restore which

0 commit comments

Comments
 (0)