.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * drivers/base/power/domain.c - Common code related to device power domains. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp. |
---|
5 | | - * |
---|
6 | | - * This file is released under the GPLv2. |
---|
7 | 6 | */ |
---|
| 7 | +#define pr_fmt(fmt) "PM: " fmt |
---|
8 | 8 | |
---|
9 | 9 | #include <linux/delay.h> |
---|
10 | 10 | #include <linux/kernel.h> |
---|
.. | .. |
---|
20 | 20 | #include <linux/sched.h> |
---|
21 | 21 | #include <linux/suspend.h> |
---|
22 | 22 | #include <linux/export.h> |
---|
| 23 | +#include <linux/cpu.h> |
---|
| 24 | +#include <linux/debugfs.h> |
---|
23 | 25 | |
---|
24 | 26 | #include "power.h" |
---|
25 | 27 | |
---|
.. | .. |
---|
122 | 124 | #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p) |
---|
123 | 125 | #define genpd_unlock(p) p->lock_ops->unlock(p) |
---|
124 | 126 | |
---|
125 | | -#define genpd_status_on(genpd) (genpd->status == GPD_STATE_ACTIVE) |
---|
| 127 | +#define genpd_status_on(genpd) (genpd->status == GENPD_STATE_ON) |
---|
126 | 128 | #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) |
---|
127 | 129 | #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON) |
---|
128 | 130 | #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP) |
---|
| 131 | +#define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN) |
---|
| 132 | +#define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON) |
---|
129 | 133 | |
---|
130 | 134 | static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, |
---|
131 | 135 | const struct generic_pm_domain *genpd) |
---|
.. | .. |
---|
146 | 150 | return ret; |
---|
147 | 151 | } |
---|
148 | 152 | |
---|
| 153 | +static int genpd_runtime_suspend(struct device *dev); |
---|
| 154 | + |
---|
149 | 155 | /* |
---|
150 | 156 | * Get the generic PM domain for a particular struct device. |
---|
151 | 157 | * This validates the struct device pointer, the PM domain pointer, |
---|
152 | 158 | * and checks that the PM domain pointer is a real generic PM domain. |
---|
153 | 159 | * Any failure results in NULL being returned. |
---|
154 | 160 | */ |
---|
155 | | -static struct generic_pm_domain *genpd_lookup_dev(struct device *dev) |
---|
| 161 | +static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev) |
---|
156 | 162 | { |
---|
157 | | - struct generic_pm_domain *genpd = NULL, *gpd; |
---|
158 | | - |
---|
159 | 163 | if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain)) |
---|
160 | 164 | return NULL; |
---|
161 | 165 | |
---|
162 | | - mutex_lock(&gpd_list_lock); |
---|
163 | | - list_for_each_entry(gpd, &gpd_list, gpd_list_node) { |
---|
164 | | - if (&gpd->domain == dev->pm_domain) { |
---|
165 | | - genpd = gpd; |
---|
166 | | - break; |
---|
167 | | - } |
---|
168 | | - } |
---|
169 | | - mutex_unlock(&gpd_list_lock); |
---|
| 166 | + /* A genpd's always have its ->runtime_suspend() callback assigned. */ |
---|
| 167 | + if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend) |
---|
| 168 | + return pd_to_genpd(dev->pm_domain); |
---|
170 | 169 | |
---|
171 | | - return genpd; |
---|
| 170 | + return NULL; |
---|
172 | 171 | } |
---|
173 | 172 | |
---|
174 | 173 | /* |
---|
.. | .. |
---|
212 | 211 | } |
---|
213 | 212 | |
---|
214 | 213 | #ifdef CONFIG_DEBUG_FS |
---|
| 214 | +static struct dentry *genpd_debugfs_dir; |
---|
| 215 | + |
---|
| 216 | +static void genpd_debug_add(struct generic_pm_domain *genpd); |
---|
| 217 | + |
---|
| 218 | +static void genpd_debug_remove(struct generic_pm_domain *genpd) |
---|
| 219 | +{ |
---|
| 220 | + struct dentry *d; |
---|
| 221 | + |
---|
| 222 | + if (!genpd_debugfs_dir) |
---|
| 223 | + return; |
---|
| 224 | + |
---|
| 225 | + d = debugfs_lookup(genpd->name, genpd_debugfs_dir); |
---|
| 226 | + debugfs_remove(d); |
---|
| 227 | +} |
---|
| 228 | + |
---|
215 | 229 | static void genpd_update_accounting(struct generic_pm_domain *genpd) |
---|
216 | 230 | { |
---|
217 | 231 | ktime_t delta, now; |
---|
.. | .. |
---|
224 | 238 | * out of off and so update the idle time and vice |
---|
225 | 239 | * versa. |
---|
226 | 240 | */ |
---|
227 | | - if (genpd->status == GPD_STATE_ACTIVE) { |
---|
| 241 | + if (genpd->status == GENPD_STATE_ON) { |
---|
228 | 242 | int state_idx = genpd->state_idx; |
---|
229 | 243 | |
---|
230 | 244 | genpd->states[state_idx].idle_time = |
---|
.. | .. |
---|
236 | 250 | genpd->accounting_time = now; |
---|
237 | 251 | } |
---|
238 | 252 | #else |
---|
| 253 | +static inline void genpd_debug_add(struct generic_pm_domain *genpd) {} |
---|
| 254 | +static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {} |
---|
239 | 255 | static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {} |
---|
240 | 256 | #endif |
---|
| 257 | + |
---|
| 258 | +static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, |
---|
| 259 | + unsigned int state) |
---|
| 260 | +{ |
---|
| 261 | + struct generic_pm_domain_data *pd_data; |
---|
| 262 | + struct pm_domain_data *pdd; |
---|
| 263 | + struct gpd_link *link; |
---|
| 264 | + |
---|
| 265 | + /* New requested state is same as Max requested state */ |
---|
| 266 | + if (state == genpd->performance_state) |
---|
| 267 | + return state; |
---|
| 268 | + |
---|
| 269 | + /* New requested state is higher than Max requested state */ |
---|
| 270 | + if (state > genpd->performance_state) |
---|
| 271 | + return state; |
---|
| 272 | + |
---|
| 273 | + /* Traverse all devices within the domain */ |
---|
| 274 | + list_for_each_entry(pdd, &genpd->dev_list, list_node) { |
---|
| 275 | + pd_data = to_gpd_data(pdd); |
---|
| 276 | + |
---|
| 277 | + if (pd_data->performance_state > state) |
---|
| 278 | + state = pd_data->performance_state; |
---|
| 279 | + } |
---|
| 280 | + |
---|
| 281 | + /* |
---|
| 282 | + * Traverse all sub-domains within the domain. This can be |
---|
| 283 | + * done without any additional locking as the link->performance_state |
---|
| 284 | + * field is protected by the parent genpd->lock, which is already taken. |
---|
| 285 | + * |
---|
| 286 | + * Also note that link->performance_state (subdomain's performance state |
---|
| 287 | + * requirement to parent domain) is different from |
---|
| 288 | + * link->child->performance_state (current performance state requirement |
---|
| 289 | + * of the devices/sub-domains of the subdomain) and so can have a |
---|
| 290 | + * different value. |
---|
| 291 | + * |
---|
| 292 | + * Note that we also take vote from powered-off sub-domains into account |
---|
| 293 | + * as the same is done for devices right now. |
---|
| 294 | + */ |
---|
| 295 | + list_for_each_entry(link, &genpd->parent_links, parent_node) { |
---|
| 296 | + if (link->performance_state > state) |
---|
| 297 | + state = link->performance_state; |
---|
| 298 | + } |
---|
| 299 | + |
---|
| 300 | + return state; |
---|
| 301 | +} |
---|
| 302 | + |
---|
| 303 | +static int _genpd_set_performance_state(struct generic_pm_domain *genpd, |
---|
| 304 | + unsigned int state, int depth) |
---|
| 305 | +{ |
---|
| 306 | + struct generic_pm_domain *parent; |
---|
| 307 | + struct gpd_link *link; |
---|
| 308 | + int parent_state, ret; |
---|
| 309 | + |
---|
| 310 | + if (state == genpd->performance_state) |
---|
| 311 | + return 0; |
---|
| 312 | + |
---|
| 313 | + /* Propagate to parents of genpd */ |
---|
| 314 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 315 | + parent = link->parent; |
---|
| 316 | + |
---|
| 317 | + if (!parent->set_performance_state) |
---|
| 318 | + continue; |
---|
| 319 | + |
---|
| 320 | + /* Find parent's performance state */ |
---|
| 321 | + ret = dev_pm_opp_xlate_performance_state(genpd->opp_table, |
---|
| 322 | + parent->opp_table, |
---|
| 323 | + state); |
---|
| 324 | + if (unlikely(ret < 0)) |
---|
| 325 | + goto err; |
---|
| 326 | + |
---|
| 327 | + parent_state = ret; |
---|
| 328 | + |
---|
| 329 | + genpd_lock_nested(parent, depth + 1); |
---|
| 330 | + |
---|
| 331 | + link->prev_performance_state = link->performance_state; |
---|
| 332 | + link->performance_state = parent_state; |
---|
| 333 | + parent_state = _genpd_reeval_performance_state(parent, |
---|
| 334 | + parent_state); |
---|
| 335 | + ret = _genpd_set_performance_state(parent, parent_state, depth + 1); |
---|
| 336 | + if (ret) |
---|
| 337 | + link->performance_state = link->prev_performance_state; |
---|
| 338 | + |
---|
| 339 | + genpd_unlock(parent); |
---|
| 340 | + |
---|
| 341 | + if (ret) |
---|
| 342 | + goto err; |
---|
| 343 | + } |
---|
| 344 | + |
---|
| 345 | + ret = genpd->set_performance_state(genpd, state); |
---|
| 346 | + if (ret) |
---|
| 347 | + goto err; |
---|
| 348 | + |
---|
| 349 | + genpd->performance_state = state; |
---|
| 350 | + return 0; |
---|
| 351 | + |
---|
| 352 | +err: |
---|
| 353 | + /* Encountered an error, lets rollback */ |
---|
| 354 | + list_for_each_entry_continue_reverse(link, &genpd->child_links, |
---|
| 355 | + child_node) { |
---|
| 356 | + parent = link->parent; |
---|
| 357 | + |
---|
| 358 | + if (!parent->set_performance_state) |
---|
| 359 | + continue; |
---|
| 360 | + |
---|
| 361 | + genpd_lock_nested(parent, depth + 1); |
---|
| 362 | + |
---|
| 363 | + parent_state = link->prev_performance_state; |
---|
| 364 | + link->performance_state = parent_state; |
---|
| 365 | + |
---|
| 366 | + parent_state = _genpd_reeval_performance_state(parent, |
---|
| 367 | + parent_state); |
---|
| 368 | + if (_genpd_set_performance_state(parent, parent_state, depth + 1)) { |
---|
| 369 | + pr_err("%s: Failed to roll back to %d performance state\n", |
---|
| 370 | + parent->name, parent_state); |
---|
| 371 | + } |
---|
| 372 | + |
---|
| 373 | + genpd_unlock(parent); |
---|
| 374 | + } |
---|
| 375 | + |
---|
| 376 | + return ret; |
---|
| 377 | +} |
---|
241 | 378 | |
---|
242 | 379 | /** |
---|
243 | 380 | * dev_pm_genpd_set_performance_state- Set performance state of device's power |
---|
.. | .. |
---|
257 | 394 | int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) |
---|
258 | 395 | { |
---|
259 | 396 | struct generic_pm_domain *genpd; |
---|
260 | | - struct generic_pm_domain_data *gpd_data, *pd_data; |
---|
261 | | - struct pm_domain_data *pdd; |
---|
| 397 | + struct generic_pm_domain_data *gpd_data; |
---|
262 | 398 | unsigned int prev; |
---|
263 | | - int ret = 0; |
---|
| 399 | + int ret; |
---|
264 | 400 | |
---|
265 | | - genpd = dev_to_genpd(dev); |
---|
266 | | - if (IS_ERR(genpd)) |
---|
| 401 | + genpd = dev_to_genpd_safe(dev); |
---|
| 402 | + if (!genpd) |
---|
267 | 403 | return -ENODEV; |
---|
268 | 404 | |
---|
269 | 405 | if (unlikely(!genpd->set_performance_state)) |
---|
270 | 406 | return -EINVAL; |
---|
271 | 407 | |
---|
272 | | - if (unlikely(!dev->power.subsys_data || |
---|
273 | | - !dev->power.subsys_data->domain_data)) { |
---|
274 | | - WARN_ON(1); |
---|
| 408 | + if (WARN_ON(!dev->power.subsys_data || |
---|
| 409 | + !dev->power.subsys_data->domain_data)) |
---|
275 | 410 | return -EINVAL; |
---|
276 | | - } |
---|
277 | 411 | |
---|
278 | 412 | genpd_lock(genpd); |
---|
279 | 413 | |
---|
.. | .. |
---|
281 | 415 | prev = gpd_data->performance_state; |
---|
282 | 416 | gpd_data->performance_state = state; |
---|
283 | 417 | |
---|
284 | | - /* New requested state is same as Max requested state */ |
---|
285 | | - if (state == genpd->performance_state) |
---|
286 | | - goto unlock; |
---|
| 418 | + state = _genpd_reeval_performance_state(genpd, state); |
---|
| 419 | + ret = _genpd_set_performance_state(genpd, state, 0); |
---|
| 420 | + if (ret) |
---|
| 421 | + gpd_data->performance_state = prev; |
---|
287 | 422 | |
---|
288 | | - /* New requested state is higher than Max requested state */ |
---|
289 | | - if (state > genpd->performance_state) |
---|
290 | | - goto update_state; |
---|
291 | | - |
---|
292 | | - /* Traverse all devices within the domain */ |
---|
293 | | - list_for_each_entry(pdd, &genpd->dev_list, list_node) { |
---|
294 | | - pd_data = to_gpd_data(pdd); |
---|
295 | | - |
---|
296 | | - if (pd_data->performance_state > state) |
---|
297 | | - state = pd_data->performance_state; |
---|
298 | | - } |
---|
299 | | - |
---|
300 | | - if (state == genpd->performance_state) |
---|
301 | | - goto unlock; |
---|
302 | | - |
---|
303 | | - /* |
---|
304 | | - * We aren't propagating performance state changes of a subdomain to its |
---|
305 | | - * masters as we don't have hardware that needs it. Over that, the |
---|
306 | | - * performance states of subdomain and its masters may not have |
---|
307 | | - * one-to-one mapping and would require additional information. We can |
---|
308 | | - * get back to this once we have hardware that needs it. For that |
---|
309 | | - * reason, we don't have to consider performance state of the subdomains |
---|
310 | | - * of genpd here. |
---|
311 | | - */ |
---|
312 | | - |
---|
313 | | -update_state: |
---|
314 | | - if (genpd_status_on(genpd)) { |
---|
315 | | - ret = genpd->set_performance_state(genpd, state); |
---|
316 | | - if (ret) { |
---|
317 | | - gpd_data->performance_state = prev; |
---|
318 | | - goto unlock; |
---|
319 | | - } |
---|
320 | | - } |
---|
321 | | - |
---|
322 | | - genpd->performance_state = state; |
---|
323 | | - |
---|
324 | | -unlock: |
---|
325 | 423 | genpd_unlock(genpd); |
---|
326 | 424 | |
---|
327 | 425 | return ret; |
---|
328 | 426 | } |
---|
329 | 427 | EXPORT_SYMBOL_GPL(dev_pm_genpd_set_performance_state); |
---|
| 428 | + |
---|
| 429 | +/** |
---|
| 430 | + * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup. |
---|
| 431 | + * |
---|
| 432 | + * @dev: Device to handle |
---|
| 433 | + * @next: impending interrupt/wakeup for the device |
---|
| 434 | + * |
---|
| 435 | + * |
---|
| 436 | + * Allow devices to inform of the next wakeup. It's assumed that the users |
---|
| 437 | + * guarantee that the genpd wouldn't be detached while this routine is getting |
---|
| 438 | + * called. Additionally, it's also assumed that @dev isn't runtime suspended |
---|
| 439 | + * (RPM_SUSPENDED)." |
---|
| 440 | + * Although devices are expected to update the next_wakeup after the end of |
---|
| 441 | + * their usecase as well, it is possible the devices themselves may not know |
---|
| 442 | + * about that, so stale @next will be ignored when powering off the domain. |
---|
| 443 | + */ |
---|
| 444 | +void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) |
---|
| 445 | +{ |
---|
| 446 | + struct generic_pm_domain_data *gpd_data; |
---|
| 447 | + struct generic_pm_domain *genpd; |
---|
| 448 | + |
---|
| 449 | + genpd = dev_to_genpd_safe(dev); |
---|
| 450 | + if (!genpd) |
---|
| 451 | + return; |
---|
| 452 | + |
---|
| 453 | + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); |
---|
| 454 | + gpd_data->next_wakeup = next; |
---|
| 455 | +} |
---|
| 456 | +EXPORT_SYMBOL_GPL(dev_pm_genpd_set_next_wakeup); |
---|
330 | 457 | |
---|
331 | 458 | static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) |
---|
332 | 459 | { |
---|
.. | .. |
---|
335 | 462 | s64 elapsed_ns; |
---|
336 | 463 | int ret; |
---|
337 | 464 | |
---|
338 | | - if (!genpd->power_on) |
---|
339 | | - return 0; |
---|
| 465 | + /* Notify consumers that we are about to power on. */ |
---|
| 466 | + ret = raw_notifier_call_chain_robust(&genpd->power_notifiers, |
---|
| 467 | + GENPD_NOTIFY_PRE_ON, |
---|
| 468 | + GENPD_NOTIFY_OFF, NULL); |
---|
| 469 | + ret = notifier_to_errno(ret); |
---|
| 470 | + if (ret) |
---|
| 471 | + return ret; |
---|
340 | 472 | |
---|
341 | | - if (!timed) |
---|
342 | | - return genpd->power_on(genpd); |
---|
| 473 | + if (!genpd->power_on) |
---|
| 474 | + goto out; |
---|
| 475 | + |
---|
| 476 | + if (!timed) { |
---|
| 477 | + ret = genpd->power_on(genpd); |
---|
| 478 | + if (ret) |
---|
| 479 | + goto err; |
---|
| 480 | + |
---|
| 481 | + goto out; |
---|
| 482 | + } |
---|
343 | 483 | |
---|
344 | 484 | time_start = ktime_get(); |
---|
345 | 485 | ret = genpd->power_on(genpd); |
---|
346 | 486 | if (ret) |
---|
347 | | - return ret; |
---|
| 487 | + goto err; |
---|
348 | 488 | |
---|
349 | 489 | elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); |
---|
350 | | - |
---|
351 | | - if (unlikely(genpd->set_performance_state)) { |
---|
352 | | - ret = genpd->set_performance_state(genpd, genpd->performance_state); |
---|
353 | | - if (ret) { |
---|
354 | | - pr_warn("%s: Failed to set performance state %d (%d)\n", |
---|
355 | | - genpd->name, genpd->performance_state, ret); |
---|
356 | | - } |
---|
357 | | - } |
---|
358 | | - |
---|
359 | 490 | if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns) |
---|
360 | | - return ret; |
---|
| 491 | + goto out; |
---|
361 | 492 | |
---|
362 | 493 | genpd->states[state_idx].power_on_latency_ns = elapsed_ns; |
---|
363 | 494 | genpd->max_off_time_changed = true; |
---|
364 | 495 | pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n", |
---|
365 | 496 | genpd->name, "on", elapsed_ns); |
---|
366 | 497 | |
---|
| 498 | +out: |
---|
| 499 | + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL); |
---|
| 500 | + return 0; |
---|
| 501 | +err: |
---|
| 502 | + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF, |
---|
| 503 | + NULL); |
---|
367 | 504 | return ret; |
---|
368 | 505 | } |
---|
369 | 506 | |
---|
.. | .. |
---|
374 | 511 | s64 elapsed_ns; |
---|
375 | 512 | int ret; |
---|
376 | 513 | |
---|
377 | | - if (!genpd->power_off) |
---|
378 | | - return 0; |
---|
| 514 | + /* Notify consumers that we are about to power off. */ |
---|
| 515 | + ret = raw_notifier_call_chain_robust(&genpd->power_notifiers, |
---|
| 516 | + GENPD_NOTIFY_PRE_OFF, |
---|
| 517 | + GENPD_NOTIFY_ON, NULL); |
---|
| 518 | + ret = notifier_to_errno(ret); |
---|
| 519 | + if (ret) |
---|
| 520 | + return ret; |
---|
379 | 521 | |
---|
380 | | - if (!timed) |
---|
381 | | - return genpd->power_off(genpd); |
---|
| 522 | + if (!genpd->power_off) |
---|
| 523 | + goto out; |
---|
| 524 | + |
---|
| 525 | + if (!timed) { |
---|
| 526 | + ret = genpd->power_off(genpd); |
---|
| 527 | + if (ret) |
---|
| 528 | + goto busy; |
---|
| 529 | + |
---|
| 530 | + goto out; |
---|
| 531 | + } |
---|
382 | 532 | |
---|
383 | 533 | time_start = ktime_get(); |
---|
384 | 534 | ret = genpd->power_off(genpd); |
---|
385 | | - if (ret == -EBUSY) |
---|
386 | | - return ret; |
---|
| 535 | + if (ret) |
---|
| 536 | + goto busy; |
---|
387 | 537 | |
---|
388 | 538 | elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); |
---|
389 | 539 | if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns) |
---|
390 | | - return ret; |
---|
| 540 | + goto out; |
---|
391 | 541 | |
---|
392 | 542 | genpd->states[state_idx].power_off_latency_ns = elapsed_ns; |
---|
393 | 543 | genpd->max_off_time_changed = true; |
---|
394 | 544 | pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n", |
---|
395 | 545 | genpd->name, "off", elapsed_ns); |
---|
396 | 546 | |
---|
| 547 | +out: |
---|
| 548 | + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_OFF, |
---|
| 549 | + NULL); |
---|
| 550 | + return 0; |
---|
| 551 | +busy: |
---|
| 552 | + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_NOTIFY_ON, NULL); |
---|
397 | 553 | return ret; |
---|
398 | 554 | } |
---|
399 | 555 | |
---|
.. | .. |
---|
426 | 582 | struct pm_domain_data *pdd; |
---|
427 | 583 | struct gpd_link *link; |
---|
428 | 584 | unsigned int not_suspended = 0; |
---|
| 585 | + int ret; |
---|
429 | 586 | |
---|
430 | 587 | /* |
---|
431 | 588 | * Do not try to power off the domain in the following situations: |
---|
.. | .. |
---|
440 | 597 | * (1) The domain is configured as always on. |
---|
441 | 598 | * (2) When the domain has a subdomain being powered on. |
---|
442 | 599 | */ |
---|
443 | | - if (genpd_is_always_on(genpd) || atomic_read(&genpd->sd_count) > 0) |
---|
| 600 | + if (genpd_is_always_on(genpd) || |
---|
| 601 | + genpd_is_rpm_always_on(genpd) || |
---|
| 602 | + atomic_read(&genpd->sd_count) > 0) |
---|
444 | 603 | return -EBUSY; |
---|
445 | 604 | |
---|
446 | 605 | list_for_each_entry(pdd, &genpd->dev_list, list_node) { |
---|
.. | .. |
---|
471 | 630 | if (!genpd->gov) |
---|
472 | 631 | genpd->state_idx = 0; |
---|
473 | 632 | |
---|
474 | | - if (genpd->power_off) { |
---|
475 | | - int ret; |
---|
| 633 | + /* Don't power off, if a child domain is waiting to power on. */ |
---|
| 634 | + if (atomic_read(&genpd->sd_count) > 0) |
---|
| 635 | + return -EBUSY; |
---|
476 | 636 | |
---|
477 | | - if (atomic_read(&genpd->sd_count) > 0) |
---|
478 | | - return -EBUSY; |
---|
479 | | - |
---|
480 | | - /* |
---|
481 | | - * If sd_count > 0 at this point, one of the subdomains hasn't |
---|
482 | | - * managed to call genpd_power_on() for the master yet after |
---|
483 | | - * incrementing it. In that case genpd_power_on() will wait |
---|
484 | | - * for us to drop the lock, so we can call .power_off() and let |
---|
485 | | - * the genpd_power_on() restore power for us (this shouldn't |
---|
486 | | - * happen very often). |
---|
487 | | - */ |
---|
488 | | - ret = _genpd_power_off(genpd, true); |
---|
489 | | - if (ret) |
---|
490 | | - return ret; |
---|
| 637 | + ret = _genpd_power_off(genpd, true); |
---|
| 638 | + if (ret) { |
---|
| 639 | + genpd->states[genpd->state_idx].rejected++; |
---|
| 640 | + return ret; |
---|
491 | 641 | } |
---|
492 | 642 | |
---|
493 | | - genpd->status = GPD_STATE_POWER_OFF; |
---|
| 643 | + genpd->status = GENPD_STATE_OFF; |
---|
494 | 644 | genpd_update_accounting(genpd); |
---|
| 645 | + genpd->states[genpd->state_idx].usage++; |
---|
495 | 646 | |
---|
496 | | - list_for_each_entry(link, &genpd->slave_links, slave_node) { |
---|
497 | | - genpd_sd_counter_dec(link->master); |
---|
498 | | - genpd_lock_nested(link->master, depth + 1); |
---|
499 | | - genpd_power_off(link->master, false, depth + 1); |
---|
500 | | - genpd_unlock(link->master); |
---|
| 647 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 648 | + genpd_sd_counter_dec(link->parent); |
---|
| 649 | + genpd_lock_nested(link->parent, depth + 1); |
---|
| 650 | + genpd_power_off(link->parent, false, depth + 1); |
---|
| 651 | + genpd_unlock(link->parent); |
---|
501 | 652 | } |
---|
502 | 653 | |
---|
503 | 654 | return 0; |
---|
504 | 655 | } |
---|
505 | 656 | |
---|
506 | 657 | /** |
---|
507 | | - * genpd_power_on - Restore power to a given PM domain and its masters. |
---|
| 658 | + * genpd_power_on - Restore power to a given PM domain and its parents. |
---|
508 | 659 | * @genpd: PM domain to power up. |
---|
509 | 660 | * @depth: nesting count for lockdep. |
---|
510 | 661 | * |
---|
511 | | - * Restore power to @genpd and all of its masters so that it is possible to |
---|
| 662 | + * Restore power to @genpd and all of its parents so that it is possible to |
---|
512 | 663 | * resume a device belonging to it. |
---|
513 | 664 | */ |
---|
514 | 665 | static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) |
---|
.. | .. |
---|
521 | 672 | |
---|
522 | 673 | /* |
---|
523 | 674 | * The list is guaranteed not to change while the loop below is being |
---|
524 | | - * executed, unless one of the masters' .power_on() callbacks fiddles |
---|
| 675 | + * executed, unless one of the parents' .power_on() callbacks fiddles |
---|
525 | 676 | * with it. |
---|
526 | 677 | */ |
---|
527 | | - list_for_each_entry(link, &genpd->slave_links, slave_node) { |
---|
528 | | - struct generic_pm_domain *master = link->master; |
---|
| 678 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 679 | + struct generic_pm_domain *parent = link->parent; |
---|
529 | 680 | |
---|
530 | | - genpd_sd_counter_inc(master); |
---|
| 681 | + genpd_sd_counter_inc(parent); |
---|
531 | 682 | |
---|
532 | | - genpd_lock_nested(master, depth + 1); |
---|
533 | | - ret = genpd_power_on(master, depth + 1); |
---|
534 | | - genpd_unlock(master); |
---|
| 683 | + genpd_lock_nested(parent, depth + 1); |
---|
| 684 | + ret = genpd_power_on(parent, depth + 1); |
---|
| 685 | + genpd_unlock(parent); |
---|
535 | 686 | |
---|
536 | 687 | if (ret) { |
---|
537 | | - genpd_sd_counter_dec(master); |
---|
| 688 | + genpd_sd_counter_dec(parent); |
---|
538 | 689 | goto err; |
---|
539 | 690 | } |
---|
540 | 691 | } |
---|
.. | .. |
---|
543 | 694 | if (ret) |
---|
544 | 695 | goto err; |
---|
545 | 696 | |
---|
546 | | - genpd->status = GPD_STATE_ACTIVE; |
---|
| 697 | + genpd->status = GENPD_STATE_ON; |
---|
547 | 698 | genpd_update_accounting(genpd); |
---|
548 | 699 | |
---|
549 | 700 | return 0; |
---|
550 | 701 | |
---|
551 | 702 | err: |
---|
552 | 703 | list_for_each_entry_continue_reverse(link, |
---|
553 | | - &genpd->slave_links, |
---|
554 | | - slave_node) { |
---|
555 | | - genpd_sd_counter_dec(link->master); |
---|
556 | | - genpd_lock_nested(link->master, depth + 1); |
---|
557 | | - genpd_power_off(link->master, false, depth + 1); |
---|
558 | | - genpd_unlock(link->master); |
---|
| 704 | + &genpd->child_links, |
---|
| 705 | + child_node) { |
---|
| 706 | + genpd_sd_counter_dec(link->parent); |
---|
| 707 | + genpd_lock_nested(link->parent, depth + 1); |
---|
| 708 | + genpd_power_off(link->parent, false, depth + 1); |
---|
| 709 | + genpd_unlock(link->parent); |
---|
559 | 710 | } |
---|
560 | 711 | |
---|
561 | 712 | return ret; |
---|
| 713 | +} |
---|
| 714 | + |
---|
| 715 | +static int genpd_dev_pm_start(struct device *dev) |
---|
| 716 | +{ |
---|
| 717 | + struct generic_pm_domain *genpd = dev_to_genpd(dev); |
---|
| 718 | + |
---|
| 719 | + return genpd_start_dev(genpd, dev); |
---|
562 | 720 | } |
---|
563 | 721 | |
---|
564 | 722 | static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, |
---|
.. | .. |
---|
849 | 1007 | } |
---|
850 | 1008 | late_initcall(genpd_power_off_unused); |
---|
851 | 1009 | |
---|
852 | | -#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_GENERIC_DOMAINS_OF) |
---|
853 | | - |
---|
854 | | -static bool genpd_present(const struct generic_pm_domain *genpd) |
---|
855 | | -{ |
---|
856 | | - const struct generic_pm_domain *gpd; |
---|
857 | | - |
---|
858 | | - if (IS_ERR_OR_NULL(genpd)) |
---|
859 | | - return false; |
---|
860 | | - |
---|
861 | | - list_for_each_entry(gpd, &gpd_list, gpd_list_node) |
---|
862 | | - if (gpd == genpd) |
---|
863 | | - return true; |
---|
864 | | - |
---|
865 | | - return false; |
---|
866 | | -} |
---|
867 | | - |
---|
868 | | -#endif |
---|
869 | | - |
---|
870 | 1010 | #ifdef CONFIG_PM_SLEEP |
---|
871 | 1011 | |
---|
872 | 1012 | /** |
---|
873 | | - * genpd_sync_power_off - Synchronously power off a PM domain and its masters. |
---|
| 1013 | + * genpd_sync_power_off - Synchronously power off a PM domain and its parents. |
---|
874 | 1014 | * @genpd: PM domain to power off, if possible. |
---|
875 | 1015 | * @use_lock: use the lock. |
---|
876 | 1016 | * @depth: nesting count for lockdep. |
---|
877 | 1017 | * |
---|
878 | 1018 | * Check if the given PM domain can be powered off (during system suspend or |
---|
879 | | - * hibernation) and do that if so. Also, in that case propagate to its masters. |
---|
| 1019 | + * hibernation) and do that if so. Also, in that case propagate to its parents. |
---|
880 | 1020 | * |
---|
881 | 1021 | * This function is only called in "noirq" and "syscore" stages of system power |
---|
882 | 1022 | * transitions. The "noirq" callbacks may be executed asynchronously, thus in |
---|
.. | .. |
---|
899 | 1039 | if (_genpd_power_off(genpd, false)) |
---|
900 | 1040 | return; |
---|
901 | 1041 | |
---|
902 | | - genpd->status = GPD_STATE_POWER_OFF; |
---|
| 1042 | + genpd->status = GENPD_STATE_OFF; |
---|
903 | 1043 | |
---|
904 | | - list_for_each_entry(link, &genpd->slave_links, slave_node) { |
---|
905 | | - genpd_sd_counter_dec(link->master); |
---|
| 1044 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 1045 | + genpd_sd_counter_dec(link->parent); |
---|
906 | 1046 | |
---|
907 | 1047 | if (use_lock) |
---|
908 | | - genpd_lock_nested(link->master, depth + 1); |
---|
| 1048 | + genpd_lock_nested(link->parent, depth + 1); |
---|
909 | 1049 | |
---|
910 | | - genpd_sync_power_off(link->master, use_lock, depth + 1); |
---|
| 1050 | + genpd_sync_power_off(link->parent, use_lock, depth + 1); |
---|
911 | 1051 | |
---|
912 | 1052 | if (use_lock) |
---|
913 | | - genpd_unlock(link->master); |
---|
| 1053 | + genpd_unlock(link->parent); |
---|
914 | 1054 | } |
---|
915 | 1055 | } |
---|
916 | 1056 | |
---|
917 | 1057 | /** |
---|
918 | | - * genpd_sync_power_on - Synchronously power on a PM domain and its masters. |
---|
| 1058 | + * genpd_sync_power_on - Synchronously power on a PM domain and its parents. |
---|
919 | 1059 | * @genpd: PM domain to power on. |
---|
920 | 1060 | * @use_lock: use the lock. |
---|
921 | 1061 | * @depth: nesting count for lockdep. |
---|
.. | .. |
---|
932 | 1072 | if (genpd_status_on(genpd)) |
---|
933 | 1073 | return; |
---|
934 | 1074 | |
---|
935 | | - list_for_each_entry(link, &genpd->slave_links, slave_node) { |
---|
936 | | - genpd_sd_counter_inc(link->master); |
---|
| 1075 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 1076 | + genpd_sd_counter_inc(link->parent); |
---|
937 | 1077 | |
---|
938 | 1078 | if (use_lock) |
---|
939 | | - genpd_lock_nested(link->master, depth + 1); |
---|
| 1079 | + genpd_lock_nested(link->parent, depth + 1); |
---|
940 | 1080 | |
---|
941 | | - genpd_sync_power_on(link->master, use_lock, depth + 1); |
---|
| 1081 | + genpd_sync_power_on(link->parent, use_lock, depth + 1); |
---|
942 | 1082 | |
---|
943 | 1083 | if (use_lock) |
---|
944 | | - genpd_unlock(link->master); |
---|
| 1084 | + genpd_unlock(link->parent); |
---|
945 | 1085 | } |
---|
946 | 1086 | |
---|
947 | 1087 | _genpd_power_on(genpd, false); |
---|
948 | | - |
---|
949 | | - genpd->status = GPD_STATE_ACTIVE; |
---|
| 1088 | + genpd->status = GENPD_STATE_ON; |
---|
950 | 1089 | } |
---|
951 | 1090 | |
---|
952 | 1091 | /** |
---|
.. | .. |
---|
1007 | 1146 | |
---|
1008 | 1147 | genpd_lock(genpd); |
---|
1009 | 1148 | |
---|
1010 | | - if (genpd->prepared_count++ == 0) { |
---|
| 1149 | + if (genpd->prepared_count++ == 0) |
---|
1011 | 1150 | genpd->suspended_count = 0; |
---|
1012 | | - genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF; |
---|
1013 | | - } |
---|
1014 | 1151 | |
---|
1015 | 1152 | genpd_unlock(genpd); |
---|
1016 | 1153 | |
---|
.. | .. |
---|
1052 | 1189 | if (ret) |
---|
1053 | 1190 | return ret; |
---|
1054 | 1191 | |
---|
1055 | | - if (genpd->suspend_power_off || |
---|
1056 | | - (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))) |
---|
| 1192 | + if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd)) |
---|
1057 | 1193 | return 0; |
---|
1058 | 1194 | |
---|
1059 | 1195 | if (genpd->dev_ops.stop && genpd->dev_ops.start && |
---|
.. | .. |
---|
1107 | 1243 | if (IS_ERR(genpd)) |
---|
1108 | 1244 | return -EINVAL; |
---|
1109 | 1245 | |
---|
1110 | | - if (genpd->suspend_power_off || |
---|
1111 | | - (dev->power.wakeup_path && genpd_is_active_wakeup(genpd))) |
---|
| 1246 | + if (dev->power.wakeup_path && genpd_is_active_wakeup(genpd)) |
---|
1112 | 1247 | return pm_generic_resume_noirq(dev); |
---|
1113 | 1248 | |
---|
1114 | 1249 | genpd_lock(genpd); |
---|
.. | .. |
---|
1223 | 1358 | * first time for the given domain in the present cycle. |
---|
1224 | 1359 | */ |
---|
1225 | 1360 | genpd_lock(genpd); |
---|
1226 | | - if (genpd->suspended_count++ == 0) |
---|
| 1361 | + if (genpd->suspended_count++ == 0) { |
---|
1227 | 1362 | /* |
---|
1228 | 1363 | * The boot kernel might put the domain into arbitrary state, |
---|
1229 | 1364 | * so make it appear as powered off to genpd_sync_power_on(), |
---|
1230 | 1365 | * so that it tries to power it on in case it was really off. |
---|
1231 | 1366 | */ |
---|
1232 | | - genpd->status = GPD_STATE_POWER_OFF; |
---|
| 1367 | + genpd->status = GENPD_STATE_OFF; |
---|
| 1368 | + } |
---|
1233 | 1369 | |
---|
1234 | 1370 | genpd_sync_power_on(genpd, true, 0); |
---|
1235 | 1371 | genpd_unlock(genpd); |
---|
.. | .. |
---|
1274 | 1410 | genpd_unlock(genpd); |
---|
1275 | 1411 | } |
---|
1276 | 1412 | |
---|
1277 | | -/** |
---|
1278 | | - * genpd_syscore_switch - Switch power during system core suspend or resume. |
---|
1279 | | - * @dev: Device that normally is marked as "always on" to switch power for. |
---|
1280 | | - * |
---|
1281 | | - * This routine may only be called during the system core (syscore) suspend or |
---|
1282 | | - * resume phase for devices whose "always on" flags are set. |
---|
1283 | | - */ |
---|
1284 | | -static void genpd_syscore_switch(struct device *dev, bool suspend) |
---|
| 1413 | +static void genpd_switch_state(struct device *dev, bool suspend) |
---|
1285 | 1414 | { |
---|
1286 | 1415 | struct generic_pm_domain *genpd; |
---|
| 1416 | + bool use_lock; |
---|
1287 | 1417 | |
---|
1288 | | - genpd = dev_to_genpd(dev); |
---|
1289 | | - if (!genpd_present(genpd)) |
---|
| 1418 | + genpd = dev_to_genpd_safe(dev); |
---|
| 1419 | + if (!genpd) |
---|
1290 | 1420 | return; |
---|
| 1421 | + |
---|
| 1422 | + use_lock = genpd_is_irq_safe(genpd); |
---|
| 1423 | + |
---|
| 1424 | + if (use_lock) |
---|
| 1425 | + genpd_lock(genpd); |
---|
1291 | 1426 | |
---|
1292 | 1427 | if (suspend) { |
---|
1293 | 1428 | genpd->suspended_count++; |
---|
1294 | | - genpd_sync_power_off(genpd, false, 0); |
---|
| 1429 | + genpd_sync_power_off(genpd, use_lock, 0); |
---|
1295 | 1430 | } else { |
---|
1296 | | - genpd_sync_power_on(genpd, false, 0); |
---|
| 1431 | + genpd_sync_power_on(genpd, use_lock, 0); |
---|
1297 | 1432 | genpd->suspended_count--; |
---|
1298 | 1433 | } |
---|
| 1434 | + |
---|
| 1435 | + if (use_lock) |
---|
| 1436 | + genpd_unlock(genpd); |
---|
1299 | 1437 | } |
---|
1300 | 1438 | |
---|
1301 | | -void pm_genpd_syscore_poweroff(struct device *dev) |
---|
| 1439 | +/** |
---|
| 1440 | + * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev |
---|
| 1441 | + * @dev: The device that is attached to the genpd, that can be suspended. |
---|
| 1442 | + * |
---|
| 1443 | + * This routine should typically be called for a device that needs to be |
---|
| 1444 | + * suspended during the syscore suspend phase. It may also be called during |
---|
| 1445 | + * suspend-to-idle to suspend a corresponding CPU device that is attached to a |
---|
| 1446 | + * genpd. |
---|
| 1447 | + */ |
---|
| 1448 | +void dev_pm_genpd_suspend(struct device *dev) |
---|
1302 | 1449 | { |
---|
1303 | | - genpd_syscore_switch(dev, true); |
---|
| 1450 | + genpd_switch_state(dev, true); |
---|
1304 | 1451 | } |
---|
1305 | | -EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweroff); |
---|
| 1452 | +EXPORT_SYMBOL_GPL(dev_pm_genpd_suspend); |
---|
1306 | 1453 | |
---|
1307 | | -void pm_genpd_syscore_poweron(struct device *dev) |
---|
| 1454 | +/** |
---|
| 1455 | + * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev |
---|
| 1456 | + * @dev: The device that is attached to the genpd, which needs to be resumed. |
---|
| 1457 | + * |
---|
| 1458 | + * This routine should typically be called for a device that needs to be resumed |
---|
| 1459 | + * during the syscore resume phase. It may also be called during suspend-to-idle |
---|
| 1460 | + * to resume a corresponding CPU device that is attached to a genpd. |
---|
| 1461 | + */ |
---|
| 1462 | +void dev_pm_genpd_resume(struct device *dev) |
---|
1308 | 1463 | { |
---|
1309 | | - genpd_syscore_switch(dev, false); |
---|
| 1464 | + genpd_switch_state(dev, false); |
---|
1310 | 1465 | } |
---|
1311 | | -EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron); |
---|
| 1466 | +EXPORT_SYMBOL_GPL(dev_pm_genpd_resume); |
---|
1312 | 1467 | |
---|
1313 | 1468 | #else /* !CONFIG_PM_SLEEP */ |
---|
1314 | 1469 | |
---|
.. | .. |
---|
1323 | 1478 | |
---|
1324 | 1479 | #endif /* CONFIG_PM_SLEEP */ |
---|
1325 | 1480 | |
---|
1326 | | -static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, |
---|
1327 | | - struct gpd_timing_data *td) |
---|
| 1481 | +static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev) |
---|
1328 | 1482 | { |
---|
1329 | 1483 | struct generic_pm_domain_data *gpd_data; |
---|
1330 | 1484 | int ret; |
---|
.. | .. |
---|
1339 | 1493 | goto err_put; |
---|
1340 | 1494 | } |
---|
1341 | 1495 | |
---|
1342 | | - if (td) |
---|
1343 | | - gpd_data->td = *td; |
---|
1344 | | - |
---|
1345 | 1496 | gpd_data->base.dev = dev; |
---|
1346 | 1497 | gpd_data->td.constraint_changed = true; |
---|
1347 | 1498 | gpd_data->td.effective_constraint_ns = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS; |
---|
1348 | 1499 | gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; |
---|
| 1500 | + gpd_data->next_wakeup = KTIME_MAX; |
---|
1349 | 1501 | |
---|
1350 | 1502 | spin_lock_irq(&dev->power.lock); |
---|
1351 | 1503 | |
---|
.. | .. |
---|
1381 | 1533 | dev_pm_put_subsys_data(dev); |
---|
1382 | 1534 | } |
---|
1383 | 1535 | |
---|
| 1536 | +static void genpd_update_cpumask(struct generic_pm_domain *genpd, |
---|
| 1537 | + int cpu, bool set, unsigned int depth) |
---|
| 1538 | +{ |
---|
| 1539 | + struct gpd_link *link; |
---|
| 1540 | + |
---|
| 1541 | + if (!genpd_is_cpu_domain(genpd)) |
---|
| 1542 | + return; |
---|
| 1543 | + |
---|
| 1544 | + list_for_each_entry(link, &genpd->child_links, child_node) { |
---|
| 1545 | + struct generic_pm_domain *parent = link->parent; |
---|
| 1546 | + |
---|
| 1547 | + genpd_lock_nested(parent, depth + 1); |
---|
| 1548 | + genpd_update_cpumask(parent, cpu, set, depth + 1); |
---|
| 1549 | + genpd_unlock(parent); |
---|
| 1550 | + } |
---|
| 1551 | + |
---|
| 1552 | + if (set) |
---|
| 1553 | + cpumask_set_cpu(cpu, genpd->cpus); |
---|
| 1554 | + else |
---|
| 1555 | + cpumask_clear_cpu(cpu, genpd->cpus); |
---|
| 1556 | +} |
---|
| 1557 | + |
---|
| 1558 | +static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu) |
---|
| 1559 | +{ |
---|
| 1560 | + if (cpu >= 0) |
---|
| 1561 | + genpd_update_cpumask(genpd, cpu, true, 0); |
---|
| 1562 | +} |
---|
| 1563 | + |
---|
| 1564 | +static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu) |
---|
| 1565 | +{ |
---|
| 1566 | + if (cpu >= 0) |
---|
| 1567 | + genpd_update_cpumask(genpd, cpu, false, 0); |
---|
| 1568 | +} |
---|
| 1569 | + |
---|
| 1570 | +static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev) |
---|
| 1571 | +{ |
---|
| 1572 | + int cpu; |
---|
| 1573 | + |
---|
| 1574 | + if (!genpd_is_cpu_domain(genpd)) |
---|
| 1575 | + return -1; |
---|
| 1576 | + |
---|
| 1577 | + for_each_possible_cpu(cpu) { |
---|
| 1578 | + if (get_cpu_device(cpu) == dev) |
---|
| 1579 | + return cpu; |
---|
| 1580 | + } |
---|
| 1581 | + |
---|
| 1582 | + return -1; |
---|
| 1583 | +} |
---|
| 1584 | + |
---|
1384 | 1585 | static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, |
---|
1385 | | - struct gpd_timing_data *td) |
---|
| 1586 | + struct device *base_dev) |
---|
1386 | 1587 | { |
---|
1387 | 1588 | struct generic_pm_domain_data *gpd_data; |
---|
1388 | 1589 | int ret; |
---|
.. | .. |
---|
1392 | 1593 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) |
---|
1393 | 1594 | return -EINVAL; |
---|
1394 | 1595 | |
---|
1395 | | - gpd_data = genpd_alloc_dev_data(dev, td); |
---|
| 1596 | + gpd_data = genpd_alloc_dev_data(dev); |
---|
1396 | 1597 | if (IS_ERR(gpd_data)) |
---|
1397 | 1598 | return PTR_ERR(gpd_data); |
---|
| 1599 | + |
---|
| 1600 | + gpd_data->cpu = genpd_get_cpu(genpd, base_dev); |
---|
1398 | 1601 | |
---|
1399 | 1602 | ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; |
---|
1400 | 1603 | if (ret) |
---|
.. | .. |
---|
1402 | 1605 | |
---|
1403 | 1606 | genpd_lock(genpd); |
---|
1404 | 1607 | |
---|
| 1608 | + genpd_set_cpumask(genpd, gpd_data->cpu); |
---|
1405 | 1609 | dev_pm_domain_set(dev, &genpd->domain); |
---|
1406 | 1610 | |
---|
1407 | 1611 | genpd->device_count++; |
---|
.. | .. |
---|
1414 | 1618 | if (ret) |
---|
1415 | 1619 | genpd_free_dev_data(dev, gpd_data); |
---|
1416 | 1620 | else |
---|
1417 | | - dev_pm_qos_add_notifier(dev, &gpd_data->nb); |
---|
| 1621 | + dev_pm_qos_add_notifier(dev, &gpd_data->nb, |
---|
| 1622 | + DEV_PM_QOS_RESUME_LATENCY); |
---|
1418 | 1623 | |
---|
1419 | 1624 | return ret; |
---|
1420 | 1625 | } |
---|
.. | .. |
---|
1429 | 1634 | int ret; |
---|
1430 | 1635 | |
---|
1431 | 1636 | mutex_lock(&gpd_list_lock); |
---|
1432 | | - ret = genpd_add_device(genpd, dev, NULL); |
---|
| 1637 | + ret = genpd_add_device(genpd, dev, dev); |
---|
1433 | 1638 | mutex_unlock(&gpd_list_lock); |
---|
1434 | 1639 | |
---|
1435 | 1640 | return ret; |
---|
.. | .. |
---|
1447 | 1652 | |
---|
1448 | 1653 | pdd = dev->power.subsys_data->domain_data; |
---|
1449 | 1654 | gpd_data = to_gpd_data(pdd); |
---|
1450 | | - dev_pm_qos_remove_notifier(dev, &gpd_data->nb); |
---|
| 1655 | + dev_pm_qos_remove_notifier(dev, &gpd_data->nb, |
---|
| 1656 | + DEV_PM_QOS_RESUME_LATENCY); |
---|
1451 | 1657 | |
---|
1452 | 1658 | genpd_lock(genpd); |
---|
1453 | 1659 | |
---|
.. | .. |
---|
1459 | 1665 | genpd->device_count--; |
---|
1460 | 1666 | genpd->max_off_time_changed = true; |
---|
1461 | 1667 | |
---|
| 1668 | + genpd_clear_cpumask(genpd, gpd_data->cpu); |
---|
1462 | 1669 | dev_pm_domain_set(dev, NULL); |
---|
1463 | 1670 | |
---|
1464 | 1671 | list_del_init(&pdd->list_node); |
---|
.. | .. |
---|
1474 | 1681 | |
---|
1475 | 1682 | out: |
---|
1476 | 1683 | genpd_unlock(genpd); |
---|
1477 | | - dev_pm_qos_add_notifier(dev, &gpd_data->nb); |
---|
| 1684 | + dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); |
---|
1478 | 1685 | |
---|
1479 | 1686 | return ret; |
---|
1480 | 1687 | } |
---|
.. | .. |
---|
1485 | 1692 | */ |
---|
1486 | 1693 | int pm_genpd_remove_device(struct device *dev) |
---|
1487 | 1694 | { |
---|
1488 | | - struct generic_pm_domain *genpd = genpd_lookup_dev(dev); |
---|
| 1695 | + struct generic_pm_domain *genpd = dev_to_genpd_safe(dev); |
---|
1489 | 1696 | |
---|
1490 | 1697 | if (!genpd) |
---|
1491 | 1698 | return -EINVAL; |
---|
.. | .. |
---|
1493 | 1700 | return genpd_remove_device(genpd, dev); |
---|
1494 | 1701 | } |
---|
1495 | 1702 | EXPORT_SYMBOL_GPL(pm_genpd_remove_device); |
---|
| 1703 | + |
---|
| 1704 | +/** |
---|
| 1705 | + * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev |
---|
| 1706 | + * |
---|
| 1707 | + * @dev: Device that should be associated with the notifier |
---|
| 1708 | + * @nb: The notifier block to register |
---|
| 1709 | + * |
---|
| 1710 | + * Users may call this function to add a genpd power on/off notifier for an |
---|
| 1711 | + * attached @dev. Only one notifier per device is allowed. The notifier is |
---|
| 1712 | + * sent when genpd is powering on/off the PM domain. |
---|
| 1713 | + * |
---|
| 1714 | + * It is assumed that the user guarantee that the genpd wouldn't be detached |
---|
| 1715 | + * while this routine is getting called. |
---|
| 1716 | + * |
---|
| 1717 | + * Returns 0 on success and negative error values on failures. |
---|
| 1718 | + */ |
---|
| 1719 | +int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb) |
---|
| 1720 | +{ |
---|
| 1721 | + struct generic_pm_domain *genpd; |
---|
| 1722 | + struct generic_pm_domain_data *gpd_data; |
---|
| 1723 | + int ret; |
---|
| 1724 | + |
---|
| 1725 | + genpd = dev_to_genpd_safe(dev); |
---|
| 1726 | + if (!genpd) |
---|
| 1727 | + return -ENODEV; |
---|
| 1728 | + |
---|
| 1729 | + if (WARN_ON(!dev->power.subsys_data || |
---|
| 1730 | + !dev->power.subsys_data->domain_data)) |
---|
| 1731 | + return -EINVAL; |
---|
| 1732 | + |
---|
| 1733 | + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); |
---|
| 1734 | + if (gpd_data->power_nb) |
---|
| 1735 | + return -EEXIST; |
---|
| 1736 | + |
---|
| 1737 | + genpd_lock(genpd); |
---|
| 1738 | + ret = raw_notifier_chain_register(&genpd->power_notifiers, nb); |
---|
| 1739 | + genpd_unlock(genpd); |
---|
| 1740 | + |
---|
| 1741 | + if (ret) { |
---|
| 1742 | + dev_warn(dev, "failed to add notifier for PM domain %s\n", |
---|
| 1743 | + genpd->name); |
---|
| 1744 | + return ret; |
---|
| 1745 | + } |
---|
| 1746 | + |
---|
| 1747 | + gpd_data->power_nb = nb; |
---|
| 1748 | + return 0; |
---|
| 1749 | +} |
---|
| 1750 | +EXPORT_SYMBOL_GPL(dev_pm_genpd_add_notifier); |
---|
| 1751 | + |
---|
| 1752 | +/** |
---|
| 1753 | + * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev |
---|
| 1754 | + * |
---|
| 1755 | + * @dev: Device that is associated with the notifier |
---|
| 1756 | + * |
---|
| 1757 | + * Users may call this function to remove a genpd power on/off notifier for an |
---|
| 1758 | + * attached @dev. |
---|
| 1759 | + * |
---|
| 1760 | + * It is assumed that the user guarantee that the genpd wouldn't be detached |
---|
| 1761 | + * while this routine is getting called. |
---|
| 1762 | + * |
---|
| 1763 | + * Returns 0 on success and negative error values on failures. |
---|
| 1764 | + */ |
---|
| 1765 | +int dev_pm_genpd_remove_notifier(struct device *dev) |
---|
| 1766 | +{ |
---|
| 1767 | + struct generic_pm_domain *genpd; |
---|
| 1768 | + struct generic_pm_domain_data *gpd_data; |
---|
| 1769 | + int ret; |
---|
| 1770 | + |
---|
| 1771 | + genpd = dev_to_genpd_safe(dev); |
---|
| 1772 | + if (!genpd) |
---|
| 1773 | + return -ENODEV; |
---|
| 1774 | + |
---|
| 1775 | + if (WARN_ON(!dev->power.subsys_data || |
---|
| 1776 | + !dev->power.subsys_data->domain_data)) |
---|
| 1777 | + return -EINVAL; |
---|
| 1778 | + |
---|
| 1779 | + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); |
---|
| 1780 | + if (!gpd_data->power_nb) |
---|
| 1781 | + return -ENODEV; |
---|
| 1782 | + |
---|
| 1783 | + genpd_lock(genpd); |
---|
| 1784 | + ret = raw_notifier_chain_unregister(&genpd->power_notifiers, |
---|
| 1785 | + gpd_data->power_nb); |
---|
| 1786 | + genpd_unlock(genpd); |
---|
| 1787 | + |
---|
| 1788 | + if (ret) { |
---|
| 1789 | + dev_warn(dev, "failed to remove notifier for PM domain %s\n", |
---|
| 1790 | + genpd->name); |
---|
| 1791 | + return ret; |
---|
| 1792 | + } |
---|
| 1793 | + |
---|
| 1794 | + gpd_data->power_nb = NULL; |
---|
| 1795 | + return 0; |
---|
| 1796 | +} |
---|
| 1797 | +EXPORT_SYMBOL_GPL(dev_pm_genpd_remove_notifier); |
---|
1496 | 1798 | |
---|
1497 | 1799 | static int genpd_add_subdomain(struct generic_pm_domain *genpd, |
---|
1498 | 1800 | struct generic_pm_domain *subdomain) |
---|
.. | .. |
---|
1527 | 1829 | goto out; |
---|
1528 | 1830 | } |
---|
1529 | 1831 | |
---|
1530 | | - list_for_each_entry(itr, &genpd->master_links, master_node) { |
---|
1531 | | - if (itr->slave == subdomain && itr->master == genpd) { |
---|
| 1832 | + list_for_each_entry(itr, &genpd->parent_links, parent_node) { |
---|
| 1833 | + if (itr->child == subdomain && itr->parent == genpd) { |
---|
1532 | 1834 | ret = -EINVAL; |
---|
1533 | 1835 | goto out; |
---|
1534 | 1836 | } |
---|
1535 | 1837 | } |
---|
1536 | 1838 | |
---|
1537 | | - link->master = genpd; |
---|
1538 | | - list_add_tail(&link->master_node, &genpd->master_links); |
---|
1539 | | - link->slave = subdomain; |
---|
1540 | | - list_add_tail(&link->slave_node, &subdomain->slave_links); |
---|
| 1839 | + link->parent = genpd; |
---|
| 1840 | + list_add_tail(&link->parent_node, &genpd->parent_links); |
---|
| 1841 | + link->child = subdomain; |
---|
| 1842 | + list_add_tail(&link->child_node, &subdomain->child_links); |
---|
1541 | 1843 | if (genpd_status_on(subdomain)) |
---|
1542 | 1844 | genpd_sd_counter_inc(genpd); |
---|
1543 | 1845 | |
---|
.. | .. |
---|
1551 | 1853 | |
---|
1552 | 1854 | /** |
---|
1553 | 1855 | * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain. |
---|
1554 | | - * @genpd: Master PM domain to add the subdomain to. |
---|
| 1856 | + * @genpd: Leader PM domain to add the subdomain to. |
---|
1555 | 1857 | * @subdomain: Subdomain to be added. |
---|
1556 | 1858 | */ |
---|
1557 | 1859 | int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
---|
.. | .. |
---|
1569 | 1871 | |
---|
1570 | 1872 | /** |
---|
1571 | 1873 | * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. |
---|
1572 | | - * @genpd: Master PM domain to remove the subdomain from. |
---|
| 1874 | + * @genpd: Leader PM domain to remove the subdomain from. |
---|
1573 | 1875 | * @subdomain: Subdomain to be removed. |
---|
1574 | 1876 | */ |
---|
1575 | 1877 | int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
---|
.. | .. |
---|
1584 | 1886 | genpd_lock(subdomain); |
---|
1585 | 1887 | genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING); |
---|
1586 | 1888 | |
---|
1587 | | - if (!list_empty(&subdomain->master_links) || subdomain->device_count) { |
---|
1588 | | - pr_warn("%s: unable to remove subdomain %s\n", genpd->name, |
---|
1589 | | - subdomain->name); |
---|
| 1889 | + if (!list_empty(&subdomain->parent_links) || subdomain->device_count) { |
---|
| 1890 | + pr_warn("%s: unable to remove subdomain %s\n", |
---|
| 1891 | + genpd->name, subdomain->name); |
---|
1590 | 1892 | ret = -EBUSY; |
---|
1591 | 1893 | goto out; |
---|
1592 | 1894 | } |
---|
1593 | 1895 | |
---|
1594 | | - list_for_each_entry_safe(link, l, &genpd->master_links, master_node) { |
---|
1595 | | - if (link->slave != subdomain) |
---|
| 1896 | + list_for_each_entry_safe(link, l, &genpd->parent_links, parent_node) { |
---|
| 1897 | + if (link->child != subdomain) |
---|
1596 | 1898 | continue; |
---|
1597 | 1899 | |
---|
1598 | | - list_del(&link->master_node); |
---|
1599 | | - list_del(&link->slave_node); |
---|
| 1900 | + list_del(&link->parent_node); |
---|
| 1901 | + list_del(&link->child_node); |
---|
1600 | 1902 | kfree(link); |
---|
1601 | 1903 | if (genpd_status_on(subdomain)) |
---|
1602 | 1904 | genpd_sd_counter_dec(genpd); |
---|
.. | .. |
---|
1613 | 1915 | } |
---|
1614 | 1916 | EXPORT_SYMBOL_GPL(pm_genpd_remove_subdomain); |
---|
1615 | 1917 | |
---|
| 1918 | +static void genpd_free_default_power_state(struct genpd_power_state *states, |
---|
| 1919 | + unsigned int state_count) |
---|
| 1920 | +{ |
---|
| 1921 | + kfree(states); |
---|
| 1922 | +} |
---|
| 1923 | + |
---|
1616 | 1924 | static int genpd_set_default_power_state(struct generic_pm_domain *genpd) |
---|
1617 | 1925 | { |
---|
1618 | 1926 | struct genpd_power_state *state; |
---|
.. | .. |
---|
1623 | 1931 | |
---|
1624 | 1932 | genpd->states = state; |
---|
1625 | 1933 | genpd->state_count = 1; |
---|
1626 | | - genpd->free = state; |
---|
| 1934 | + genpd->free_states = genpd_free_default_power_state; |
---|
1627 | 1935 | |
---|
1628 | 1936 | return 0; |
---|
1629 | 1937 | } |
---|
.. | .. |
---|
1655 | 1963 | if (IS_ERR_OR_NULL(genpd)) |
---|
1656 | 1964 | return -EINVAL; |
---|
1657 | 1965 | |
---|
1658 | | - INIT_LIST_HEAD(&genpd->master_links); |
---|
1659 | | - INIT_LIST_HEAD(&genpd->slave_links); |
---|
| 1966 | + INIT_LIST_HEAD(&genpd->parent_links); |
---|
| 1967 | + INIT_LIST_HEAD(&genpd->child_links); |
---|
1660 | 1968 | INIT_LIST_HEAD(&genpd->dev_list); |
---|
| 1969 | + RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers); |
---|
1661 | 1970 | genpd_lock_init(genpd); |
---|
1662 | 1971 | genpd->gov = gov; |
---|
1663 | 1972 | INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); |
---|
1664 | 1973 | atomic_set(&genpd->sd_count, 0); |
---|
1665 | | - genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; |
---|
| 1974 | + genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON; |
---|
1666 | 1975 | genpd->device_count = 0; |
---|
1667 | 1976 | genpd->max_off_time_ns = -1; |
---|
1668 | 1977 | genpd->max_off_time_changed = true; |
---|
| 1978 | + genpd->next_wakeup = KTIME_MAX; |
---|
1669 | 1979 | genpd->provider = NULL; |
---|
1670 | 1980 | genpd->has_provider = false; |
---|
1671 | 1981 | genpd->accounting_time = ktime_get(); |
---|
.. | .. |
---|
1679 | 1989 | genpd->domain.ops.poweroff_noirq = genpd_poweroff_noirq; |
---|
1680 | 1990 | genpd->domain.ops.restore_noirq = genpd_restore_noirq; |
---|
1681 | 1991 | genpd->domain.ops.complete = genpd_complete; |
---|
| 1992 | + genpd->domain.start = genpd_dev_pm_start; |
---|
1682 | 1993 | |
---|
1683 | 1994 | if (genpd->flags & GENPD_FLAG_PM_CLK) { |
---|
1684 | 1995 | genpd->dev_ops.stop = pm_clk_suspend; |
---|
.. | .. |
---|
1686 | 1997 | } |
---|
1687 | 1998 | |
---|
1688 | 1999 | /* Always-on domains must be powered on at initialization. */ |
---|
1689 | | - if (genpd_is_always_on(genpd) && !genpd_status_on(genpd)) |
---|
| 2000 | + if ((genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd)) && |
---|
| 2001 | + !genpd_status_on(genpd)) |
---|
1690 | 2002 | return -EINVAL; |
---|
| 2003 | + |
---|
| 2004 | + if (genpd_is_cpu_domain(genpd) && |
---|
| 2005 | + !zalloc_cpumask_var(&genpd->cpus, GFP_KERNEL)) |
---|
| 2006 | + return -ENOMEM; |
---|
1691 | 2007 | |
---|
1692 | 2008 | /* Use only one "off" state if there were no states declared */ |
---|
1693 | 2009 | if (genpd->state_count == 0) { |
---|
1694 | 2010 | ret = genpd_set_default_power_state(genpd); |
---|
1695 | | - if (ret) |
---|
| 2011 | + if (ret) { |
---|
| 2012 | + if (genpd_is_cpu_domain(genpd)) |
---|
| 2013 | + free_cpumask_var(genpd->cpus); |
---|
1696 | 2014 | return ret; |
---|
1697 | | - } else if (!gov) { |
---|
1698 | | - pr_warn("%s : no governor for states\n", genpd->name); |
---|
| 2015 | + } |
---|
| 2016 | + } else if (!gov && genpd->state_count > 1) { |
---|
| 2017 | + pr_warn("%s: no governor for states\n", genpd->name); |
---|
1699 | 2018 | } |
---|
1700 | 2019 | |
---|
1701 | 2020 | device_initialize(&genpd->dev); |
---|
.. | .. |
---|
1703 | 2022 | |
---|
1704 | 2023 | mutex_lock(&gpd_list_lock); |
---|
1705 | 2024 | list_add(&genpd->gpd_list_node, &gpd_list); |
---|
| 2025 | + genpd_debug_add(genpd); |
---|
1706 | 2026 | mutex_unlock(&gpd_list_lock); |
---|
1707 | 2027 | |
---|
1708 | 2028 | return 0; |
---|
.. | .. |
---|
1724 | 2044 | return -EBUSY; |
---|
1725 | 2045 | } |
---|
1726 | 2046 | |
---|
1727 | | - if (!list_empty(&genpd->master_links) || genpd->device_count) { |
---|
| 2047 | + if (!list_empty(&genpd->parent_links) || genpd->device_count) { |
---|
1728 | 2048 | genpd_unlock(genpd); |
---|
1729 | 2049 | pr_err("%s: unable to remove %s\n", __func__, genpd->name); |
---|
1730 | 2050 | return -EBUSY; |
---|
1731 | 2051 | } |
---|
1732 | 2052 | |
---|
1733 | | - list_for_each_entry_safe(link, l, &genpd->slave_links, slave_node) { |
---|
1734 | | - list_del(&link->master_node); |
---|
1735 | | - list_del(&link->slave_node); |
---|
| 2053 | + list_for_each_entry_safe(link, l, &genpd->child_links, child_node) { |
---|
| 2054 | + list_del(&link->parent_node); |
---|
| 2055 | + list_del(&link->child_node); |
---|
1736 | 2056 | kfree(link); |
---|
1737 | 2057 | } |
---|
1738 | 2058 | |
---|
1739 | 2059 | list_del(&genpd->gpd_list_node); |
---|
1740 | 2060 | genpd_unlock(genpd); |
---|
| 2061 | + genpd_debug_remove(genpd); |
---|
1741 | 2062 | cancel_work_sync(&genpd->power_off_work); |
---|
1742 | | - kfree(genpd->free); |
---|
| 2063 | + if (genpd_is_cpu_domain(genpd)) |
---|
| 2064 | + free_cpumask_var(genpd->cpus); |
---|
| 2065 | + if (genpd->free_states) |
---|
| 2066 | + genpd->free_states(genpd->states, genpd->state_count); |
---|
| 2067 | + |
---|
1743 | 2068 | pr_debug("%s: removed %s\n", __func__, genpd->name); |
---|
1744 | 2069 | |
---|
1745 | 2070 | return 0; |
---|
.. | .. |
---|
1873 | 2198 | cp->node = of_node_get(np); |
---|
1874 | 2199 | cp->data = data; |
---|
1875 | 2200 | cp->xlate = xlate; |
---|
| 2201 | + fwnode_dev_initialized(&np->fwnode, true); |
---|
1876 | 2202 | |
---|
1877 | 2203 | mutex_lock(&of_genpd_mutex); |
---|
1878 | 2204 | list_add(&cp->link, &of_genpd_providers); |
---|
.. | .. |
---|
1880 | 2206 | pr_debug("Added domain provider from %pOF\n", np); |
---|
1881 | 2207 | |
---|
1882 | 2208 | return 0; |
---|
| 2209 | +} |
---|
| 2210 | + |
---|
| 2211 | +static bool genpd_present(const struct generic_pm_domain *genpd) |
---|
| 2212 | +{ |
---|
| 2213 | + const struct generic_pm_domain *gpd; |
---|
| 2214 | + |
---|
| 2215 | + list_for_each_entry(gpd, &gpd_list, gpd_list_node) |
---|
| 2216 | + if (gpd == genpd) |
---|
| 2217 | + return true; |
---|
| 2218 | + return false; |
---|
1883 | 2219 | } |
---|
1884 | 2220 | |
---|
1885 | 2221 | /** |
---|
.. | .. |
---|
1906 | 2242 | if (genpd->set_performance_state) { |
---|
1907 | 2243 | ret = dev_pm_opp_of_add_table(&genpd->dev); |
---|
1908 | 2244 | if (ret) { |
---|
1909 | | - dev_err(&genpd->dev, "Failed to add OPP table: %d\n", |
---|
1910 | | - ret); |
---|
| 2245 | + if (ret != -EPROBE_DEFER) |
---|
| 2246 | + dev_err(&genpd->dev, "Failed to add OPP table: %d\n", |
---|
| 2247 | + ret); |
---|
1911 | 2248 | goto unlock; |
---|
1912 | 2249 | } |
---|
| 2250 | + |
---|
| 2251 | + /* |
---|
| 2252 | + * Save table for faster processing while setting performance |
---|
| 2253 | + * state. |
---|
| 2254 | + */ |
---|
| 2255 | + genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev); |
---|
| 2256 | + WARN_ON(IS_ERR(genpd->opp_table)); |
---|
1913 | 2257 | } |
---|
1914 | 2258 | |
---|
1915 | 2259 | ret = genpd_add_provider(np, genpd_xlate_simple, genpd); |
---|
1916 | 2260 | if (ret) { |
---|
1917 | | - if (genpd->set_performance_state) |
---|
| 2261 | + if (genpd->set_performance_state) { |
---|
| 2262 | + dev_pm_opp_put_opp_table(genpd->opp_table); |
---|
1918 | 2263 | dev_pm_opp_of_remove_table(&genpd->dev); |
---|
| 2264 | + } |
---|
1919 | 2265 | |
---|
1920 | 2266 | goto unlock; |
---|
1921 | 2267 | } |
---|
.. | .. |
---|
1964 | 2310 | if (genpd->set_performance_state) { |
---|
1965 | 2311 | ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i); |
---|
1966 | 2312 | if (ret) { |
---|
1967 | | - dev_err(&genpd->dev, "Failed to add OPP table for index %d: %d\n", |
---|
1968 | | - i, ret); |
---|
| 2313 | + if (ret != -EPROBE_DEFER) |
---|
| 2314 | + dev_err(&genpd->dev, "Failed to add OPP table for index %d: %d\n", |
---|
| 2315 | + i, ret); |
---|
1969 | 2316 | goto error; |
---|
1970 | 2317 | } |
---|
| 2318 | + |
---|
| 2319 | + /* |
---|
| 2320 | + * Save table for faster processing while setting |
---|
| 2321 | + * performance state. |
---|
| 2322 | + */ |
---|
| 2323 | + genpd->opp_table = dev_pm_opp_get_opp_table_indexed(&genpd->dev, i); |
---|
| 2324 | + WARN_ON(IS_ERR(genpd->opp_table)); |
---|
1971 | 2325 | } |
---|
1972 | 2326 | |
---|
1973 | 2327 | genpd->provider = &np->fwnode; |
---|
.. | .. |
---|
1992 | 2346 | genpd->provider = NULL; |
---|
1993 | 2347 | genpd->has_provider = false; |
---|
1994 | 2348 | |
---|
1995 | | - if (genpd->set_performance_state) |
---|
| 2349 | + if (genpd->set_performance_state) { |
---|
| 2350 | + dev_pm_opp_put_opp_table(genpd->opp_table); |
---|
1996 | 2351 | dev_pm_opp_of_remove_table(&genpd->dev); |
---|
| 2352 | + } |
---|
1997 | 2353 | } |
---|
1998 | 2354 | |
---|
1999 | 2355 | mutex_unlock(&gpd_list_lock); |
---|
.. | .. |
---|
2027 | 2383 | if (!gpd->set_performance_state) |
---|
2028 | 2384 | continue; |
---|
2029 | 2385 | |
---|
| 2386 | + dev_pm_opp_put_opp_table(gpd->opp_table); |
---|
2030 | 2387 | dev_pm_opp_of_remove_table(&gpd->dev); |
---|
2031 | 2388 | } |
---|
2032 | 2389 | } |
---|
2033 | 2390 | |
---|
| 2391 | + fwnode_dev_initialized(&cp->node->fwnode, false); |
---|
2034 | 2392 | list_del(&cp->link); |
---|
2035 | 2393 | of_node_put(cp->node); |
---|
2036 | 2394 | kfree(cp); |
---|
.. | .. |
---|
2098 | 2456 | goto out; |
---|
2099 | 2457 | } |
---|
2100 | 2458 | |
---|
2101 | | - ret = genpd_add_device(genpd, dev, NULL); |
---|
| 2459 | + ret = genpd_add_device(genpd, dev, dev); |
---|
2102 | 2460 | |
---|
2103 | 2461 | out: |
---|
2104 | 2462 | mutex_unlock(&gpd_list_lock); |
---|
.. | .. |
---|
2146 | 2504 | EXPORT_SYMBOL_GPL(of_genpd_add_subdomain); |
---|
2147 | 2505 | |
---|
2148 | 2506 | /** |
---|
| 2507 | + * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. |
---|
| 2508 | + * @parent_spec: OF phandle args to use for parent PM domain look-up |
---|
| 2509 | + * @subdomain_spec: OF phandle args to use for subdomain look-up |
---|
| 2510 | + * |
---|
| 2511 | + * Looks-up a parent PM domain and subdomain based upon phandle args |
---|
| 2512 | + * provided and removes the subdomain from the parent PM domain. Returns a |
---|
| 2513 | + * negative error code on failure. |
---|
| 2514 | + */ |
---|
| 2515 | +int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, |
---|
| 2516 | + struct of_phandle_args *subdomain_spec) |
---|
| 2517 | +{ |
---|
| 2518 | + struct generic_pm_domain *parent, *subdomain; |
---|
| 2519 | + int ret; |
---|
| 2520 | + |
---|
| 2521 | + mutex_lock(&gpd_list_lock); |
---|
| 2522 | + |
---|
| 2523 | + parent = genpd_get_from_provider(parent_spec); |
---|
| 2524 | + if (IS_ERR(parent)) { |
---|
| 2525 | + ret = PTR_ERR(parent); |
---|
| 2526 | + goto out; |
---|
| 2527 | + } |
---|
| 2528 | + |
---|
| 2529 | + subdomain = genpd_get_from_provider(subdomain_spec); |
---|
| 2530 | + if (IS_ERR(subdomain)) { |
---|
| 2531 | + ret = PTR_ERR(subdomain); |
---|
| 2532 | + goto out; |
---|
| 2533 | + } |
---|
| 2534 | + |
---|
| 2535 | + ret = pm_genpd_remove_subdomain(parent, subdomain); |
---|
| 2536 | + |
---|
| 2537 | +out: |
---|
| 2538 | + mutex_unlock(&gpd_list_lock); |
---|
| 2539 | + |
---|
| 2540 | + return ret; |
---|
| 2541 | +} |
---|
| 2542 | +EXPORT_SYMBOL_GPL(of_genpd_remove_subdomain); |
---|
| 2543 | + |
---|
| 2544 | +/** |
---|
2149 | 2545 | * of_genpd_remove_last - Remove the last PM domain registered for a provider |
---|
2150 | 2546 | * @provider: Pointer to device structure associated with provider |
---|
2151 | 2547 | * |
---|
.. | .. |
---|
2182 | 2578 | |
---|
2183 | 2579 | static void genpd_release_dev(struct device *dev) |
---|
2184 | 2580 | { |
---|
| 2581 | + of_node_put(dev->of_node); |
---|
2185 | 2582 | kfree(dev); |
---|
2186 | 2583 | } |
---|
2187 | 2584 | |
---|
.. | .. |
---|
2243 | 2640 | genpd_queue_power_off_work(pd); |
---|
2244 | 2641 | } |
---|
2245 | 2642 | |
---|
2246 | | -static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np, |
---|
| 2643 | +static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, |
---|
2247 | 2644 | unsigned int index, bool power_on) |
---|
2248 | 2645 | { |
---|
2249 | 2646 | struct of_phandle_args pd_args; |
---|
2250 | 2647 | struct generic_pm_domain *pd; |
---|
2251 | 2648 | int ret; |
---|
2252 | 2649 | |
---|
2253 | | - ret = of_parse_phandle_with_args(np, "power-domains", |
---|
| 2650 | + ret = of_parse_phandle_with_args(dev->of_node, "power-domains", |
---|
2254 | 2651 | "#power-domain-cells", index, &pd_args); |
---|
2255 | 2652 | if (ret < 0) |
---|
2256 | 2653 | return ret; |
---|
.. | .. |
---|
2262 | 2659 | mutex_unlock(&gpd_list_lock); |
---|
2263 | 2660 | dev_dbg(dev, "%s() failed to find PM domain: %ld\n", |
---|
2264 | 2661 | __func__, PTR_ERR(pd)); |
---|
2265 | | - return driver_deferred_probe_check_state(dev); |
---|
| 2662 | + return driver_deferred_probe_check_state(base_dev); |
---|
2266 | 2663 | } |
---|
2267 | 2664 | |
---|
2268 | 2665 | dev_dbg(dev, "adding to PM domain %s\n", pd->name); |
---|
2269 | 2666 | |
---|
2270 | | - ret = genpd_add_device(pd, dev, NULL); |
---|
| 2667 | + ret = genpd_add_device(pd, dev, base_dev); |
---|
2271 | 2668 | mutex_unlock(&gpd_list_lock); |
---|
2272 | 2669 | |
---|
2273 | 2670 | if (ret < 0) { |
---|
.. | .. |
---|
2318 | 2715 | "#power-domain-cells") != 1) |
---|
2319 | 2716 | return 0; |
---|
2320 | 2717 | |
---|
2321 | | - return __genpd_dev_pm_attach(dev, dev->of_node, 0, true); |
---|
| 2718 | + return __genpd_dev_pm_attach(dev, dev, 0, true); |
---|
2322 | 2719 | } |
---|
2323 | 2720 | EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); |
---|
2324 | 2721 | |
---|
.. | .. |
---|
2341 | 2738 | struct device *genpd_dev_pm_attach_by_id(struct device *dev, |
---|
2342 | 2739 | unsigned int index) |
---|
2343 | 2740 | { |
---|
2344 | | - struct device *genpd_dev; |
---|
| 2741 | + struct device *virt_dev; |
---|
2345 | 2742 | int num_domains; |
---|
2346 | 2743 | int ret; |
---|
2347 | 2744 | |
---|
2348 | 2745 | if (!dev->of_node) |
---|
2349 | 2746 | return NULL; |
---|
2350 | 2747 | |
---|
2351 | | - /* Deal only with devices using multiple PM domains. */ |
---|
| 2748 | + /* Verify that the index is within a valid range. */ |
---|
2352 | 2749 | num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", |
---|
2353 | 2750 | "#power-domain-cells"); |
---|
2354 | | - if (num_domains < 2 || index >= num_domains) |
---|
| 2751 | + if (index >= num_domains) |
---|
2355 | 2752 | return NULL; |
---|
2356 | 2753 | |
---|
2357 | 2754 | /* Allocate and register device on the genpd bus. */ |
---|
2358 | | - genpd_dev = kzalloc(sizeof(*genpd_dev), GFP_KERNEL); |
---|
2359 | | - if (!genpd_dev) |
---|
| 2755 | + virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL); |
---|
| 2756 | + if (!virt_dev) |
---|
2360 | 2757 | return ERR_PTR(-ENOMEM); |
---|
2361 | 2758 | |
---|
2362 | | - dev_set_name(genpd_dev, "genpd:%u:%s", index, dev_name(dev)); |
---|
2363 | | - genpd_dev->bus = &genpd_bus_type; |
---|
2364 | | - genpd_dev->release = genpd_release_dev; |
---|
| 2759 | + dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev)); |
---|
| 2760 | + virt_dev->bus = &genpd_bus_type; |
---|
| 2761 | + virt_dev->release = genpd_release_dev; |
---|
| 2762 | + virt_dev->of_node = of_node_get(dev->of_node); |
---|
2365 | 2763 | |
---|
2366 | | - ret = device_register(genpd_dev); |
---|
| 2764 | + ret = device_register(virt_dev); |
---|
2367 | 2765 | if (ret) { |
---|
2368 | | - kfree(genpd_dev); |
---|
| 2766 | + put_device(virt_dev); |
---|
2369 | 2767 | return ERR_PTR(ret); |
---|
2370 | 2768 | } |
---|
2371 | 2769 | |
---|
2372 | 2770 | /* Try to attach the device to the PM domain at the specified index. */ |
---|
2373 | | - ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index, false); |
---|
| 2771 | + ret = __genpd_dev_pm_attach(virt_dev, dev, index, false); |
---|
2374 | 2772 | if (ret < 1) { |
---|
2375 | | - device_unregister(genpd_dev); |
---|
| 2773 | + device_unregister(virt_dev); |
---|
2376 | 2774 | return ret ? ERR_PTR(ret) : NULL; |
---|
2377 | 2775 | } |
---|
2378 | 2776 | |
---|
2379 | | - pm_runtime_enable(genpd_dev); |
---|
2380 | | - genpd_queue_power_off_work(dev_to_genpd(genpd_dev)); |
---|
| 2777 | + pm_runtime_enable(virt_dev); |
---|
| 2778 | + genpd_queue_power_off_work(dev_to_genpd(virt_dev)); |
---|
2381 | 2779 | |
---|
2382 | | - return genpd_dev; |
---|
| 2780 | + return virt_dev; |
---|
2383 | 2781 | } |
---|
2384 | 2782 | EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id); |
---|
2385 | 2783 | |
---|
.. | .. |
---|
2392 | 2790 | * power-domain-names DT property. For further description see |
---|
2393 | 2791 | * genpd_dev_pm_attach_by_id(). |
---|
2394 | 2792 | */ |
---|
2395 | | -struct device *genpd_dev_pm_attach_by_name(struct device *dev, char *name) |
---|
| 2793 | +struct device *genpd_dev_pm_attach_by_name(struct device *dev, const char *name) |
---|
2396 | 2794 | { |
---|
2397 | 2795 | int index; |
---|
2398 | 2796 | |
---|
.. | .. |
---|
2423 | 2821 | &entry_latency); |
---|
2424 | 2822 | if (err) { |
---|
2425 | 2823 | pr_debug(" * %pOF missing entry-latency-us property\n", |
---|
2426 | | - state_node); |
---|
| 2824 | + state_node); |
---|
2427 | 2825 | return -EINVAL; |
---|
2428 | 2826 | } |
---|
2429 | 2827 | |
---|
.. | .. |
---|
2431 | 2829 | &exit_latency); |
---|
2432 | 2830 | if (err) { |
---|
2433 | 2831 | pr_debug(" * %pOF missing exit-latency-us property\n", |
---|
2434 | | - state_node); |
---|
| 2832 | + state_node); |
---|
2435 | 2833 | return -EINVAL; |
---|
2436 | 2834 | } |
---|
2437 | 2835 | |
---|
2438 | 2836 | err = of_property_read_u32(state_node, "min-residency-us", &residency); |
---|
2439 | 2837 | if (!err) |
---|
2440 | | - genpd_state->residency_ns = 1000 * residency; |
---|
| 2838 | + genpd_state->residency_ns = 1000LL * residency; |
---|
2441 | 2839 | |
---|
2442 | | - genpd_state->power_on_latency_ns = 1000 * exit_latency; |
---|
2443 | | - genpd_state->power_off_latency_ns = 1000 * entry_latency; |
---|
| 2840 | + genpd_state->power_on_latency_ns = 1000LL * exit_latency; |
---|
| 2841 | + genpd_state->power_off_latency_ns = 1000LL * entry_latency; |
---|
2444 | 2842 | genpd_state->fwnode = &state_node->fwnode; |
---|
2445 | 2843 | |
---|
2446 | 2844 | return 0; |
---|
.. | .. |
---|
2456 | 2854 | |
---|
2457 | 2855 | ret = of_count_phandle_with_args(dn, "domain-idle-states", NULL); |
---|
2458 | 2856 | if (ret <= 0) |
---|
2459 | | - return ret; |
---|
| 2857 | + return ret == -ENOENT ? 0 : ret; |
---|
2460 | 2858 | |
---|
2461 | 2859 | /* Loop over the phandles until all the requested entry is found */ |
---|
2462 | 2860 | of_for_each_phandle(&it, ret, dn, "domain-idle-states", NULL, 0) { |
---|
2463 | 2861 | np = it.node; |
---|
2464 | 2862 | if (!of_match_node(idle_state_match, np)) |
---|
2465 | 2863 | continue; |
---|
| 2864 | + |
---|
| 2865 | + if (!of_device_is_available(np)) |
---|
| 2866 | + continue; |
---|
| 2867 | + |
---|
2466 | 2868 | if (states) { |
---|
2467 | 2869 | ret = genpd_parse_state(&states[i], np); |
---|
2468 | 2870 | if (ret) { |
---|
.. | .. |
---|
2487 | 2889 | * |
---|
2488 | 2890 | * Returns the device states parsed from the OF node. The memory for the states |
---|
2489 | 2891 | * is allocated by this function and is the responsibility of the caller to |
---|
2490 | | - * free the memory after use. If no domain idle states is found it returns |
---|
2491 | | - * -EINVAL and in case of errors, a negative error code. |
---|
| 2892 | + * free the memory after use. If any or zero compatible domain idle states is |
---|
| 2893 | + * found it returns 0 and in case of errors, a negative error code is returned. |
---|
2492 | 2894 | */ |
---|
2493 | 2895 | int of_genpd_parse_idle_states(struct device_node *dn, |
---|
2494 | 2896 | struct genpd_power_state **states, int *n) |
---|
.. | .. |
---|
2497 | 2899 | int ret; |
---|
2498 | 2900 | |
---|
2499 | 2901 | ret = genpd_iterate_idle_states(dn, NULL); |
---|
2500 | | - if (ret <= 0) |
---|
2501 | | - return ret < 0 ? ret : -EINVAL; |
---|
| 2902 | + if (ret < 0) |
---|
| 2903 | + return ret; |
---|
| 2904 | + |
---|
| 2905 | + if (!ret) { |
---|
| 2906 | + *states = NULL; |
---|
| 2907 | + *n = 0; |
---|
| 2908 | + return 0; |
---|
| 2909 | + } |
---|
2502 | 2910 | |
---|
2503 | 2911 | st = kcalloc(ret, sizeof(*st), GFP_KERNEL); |
---|
2504 | 2912 | if (!st) |
---|
.. | .. |
---|
2518 | 2926 | EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); |
---|
2519 | 2927 | |
---|
2520 | 2928 | /** |
---|
2521 | | - * of_genpd_opp_to_performance_state- Gets performance state of device's |
---|
2522 | | - * power domain corresponding to a DT node's "required-opps" property. |
---|
| 2929 | + * pm_genpd_opp_to_performance_state - Gets performance state of the genpd from its OPP node. |
---|
2523 | 2930 | * |
---|
2524 | | - * @dev: Device for which the performance-state needs to be found. |
---|
2525 | | - * @np: DT node where the "required-opps" property is present. This can be |
---|
2526 | | - * the device node itself (if it doesn't have an OPP table) or a node |
---|
2527 | | - * within the OPP table of a device (if device has an OPP table). |
---|
| 2931 | + * @genpd_dev: Genpd's device for which the performance-state needs to be found. |
---|
| 2932 | + * @opp: struct dev_pm_opp of the OPP for which we need to find performance |
---|
| 2933 | + * state. |
---|
2528 | 2934 | * |
---|
2529 | | - * Returns performance state corresponding to the "required-opps" property of |
---|
2530 | | - * a DT node. This calls platform specific genpd->opp_to_performance_state() |
---|
2531 | | - * callback to translate power domain OPP to performance state. |
---|
| 2935 | + * Returns performance state encoded in the OPP of the genpd. This calls |
---|
| 2936 | + * platform specific genpd->opp_to_performance_state() callback to translate |
---|
| 2937 | + * power domain OPP to performance state. |
---|
2532 | 2938 | * |
---|
2533 | 2939 | * Returns performance state on success and 0 on failure. |
---|
2534 | 2940 | */ |
---|
2535 | | -unsigned int of_genpd_opp_to_performance_state(struct device *dev, |
---|
2536 | | - struct device_node *np) |
---|
| 2941 | +unsigned int pm_genpd_opp_to_performance_state(struct device *genpd_dev, |
---|
| 2942 | + struct dev_pm_opp *opp) |
---|
2537 | 2943 | { |
---|
2538 | | - struct generic_pm_domain *genpd; |
---|
2539 | | - struct dev_pm_opp *opp; |
---|
2540 | | - int state = 0; |
---|
| 2944 | + struct generic_pm_domain *genpd = NULL; |
---|
| 2945 | + int state; |
---|
2541 | 2946 | |
---|
2542 | | - genpd = dev_to_genpd(dev); |
---|
2543 | | - if (IS_ERR(genpd)) |
---|
2544 | | - return 0; |
---|
| 2947 | + genpd = container_of(genpd_dev, struct generic_pm_domain, dev); |
---|
2545 | 2948 | |
---|
2546 | | - if (unlikely(!genpd->set_performance_state)) |
---|
| 2949 | + if (unlikely(!genpd->opp_to_performance_state)) |
---|
2547 | 2950 | return 0; |
---|
2548 | 2951 | |
---|
2549 | 2952 | genpd_lock(genpd); |
---|
2550 | | - |
---|
2551 | | - opp = of_dev_pm_opp_find_required_opp(&genpd->dev, np); |
---|
2552 | | - if (IS_ERR(opp)) { |
---|
2553 | | - dev_err(dev, "Failed to find required OPP: %ld\n", |
---|
2554 | | - PTR_ERR(opp)); |
---|
2555 | | - goto unlock; |
---|
2556 | | - } |
---|
2557 | | - |
---|
2558 | 2953 | state = genpd->opp_to_performance_state(genpd, opp); |
---|
2559 | | - dev_pm_opp_put(opp); |
---|
2560 | | - |
---|
2561 | | -unlock: |
---|
2562 | 2954 | genpd_unlock(genpd); |
---|
2563 | 2955 | |
---|
2564 | 2956 | return state; |
---|
2565 | 2957 | } |
---|
2566 | | -EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state); |
---|
| 2958 | +EXPORT_SYMBOL_GPL(pm_genpd_opp_to_performance_state); |
---|
2567 | 2959 | |
---|
2568 | 2960 | static int __init genpd_bus_init(void) |
---|
2569 | 2961 | { |
---|
.. | .. |
---|
2577 | 2969 | /*** debugfs support ***/ |
---|
2578 | 2970 | |
---|
2579 | 2971 | #ifdef CONFIG_DEBUG_FS |
---|
2580 | | -#include <linux/pm.h> |
---|
2581 | | -#include <linux/device.h> |
---|
2582 | | -#include <linux/debugfs.h> |
---|
2583 | | -#include <linux/seq_file.h> |
---|
2584 | | -#include <linux/init.h> |
---|
2585 | | -#include <linux/kobject.h> |
---|
2586 | | -static struct dentry *genpd_debugfs_dir; |
---|
2587 | | - |
---|
2588 | 2972 | /* |
---|
2589 | 2973 | * TODO: This function is a slightly modified version of rtpm_status_show |
---|
2590 | 2974 | * from sysfs.c, so generalize it. |
---|
.. | .. |
---|
2615 | 2999 | struct generic_pm_domain *genpd) |
---|
2616 | 3000 | { |
---|
2617 | 3001 | static const char * const status_lookup[] = { |
---|
2618 | | - [GPD_STATE_ACTIVE] = "on", |
---|
2619 | | - [GPD_STATE_POWER_OFF] = "off" |
---|
| 3002 | + [GENPD_STATE_ON] = "on", |
---|
| 3003 | + [GENPD_STATE_OFF] = "off" |
---|
2620 | 3004 | }; |
---|
2621 | 3005 | struct pm_domain_data *pm_data; |
---|
2622 | 3006 | const char *kobj_path; |
---|
.. | .. |
---|
2640 | 3024 | |
---|
2641 | 3025 | /* |
---|
2642 | 3026 | * Modifications on the list require holding locks on both |
---|
2643 | | - * master and slave, so we are safe. |
---|
| 3027 | + * parent and child, so we are safe. |
---|
2644 | 3028 | * Also genpd->name is immutable. |
---|
2645 | 3029 | */ |
---|
2646 | | - list_for_each_entry(link, &genpd->master_links, master_node) { |
---|
2647 | | - seq_printf(s, "%s", link->slave->name); |
---|
2648 | | - if (!list_is_last(&link->master_node, &genpd->master_links)) |
---|
| 3030 | + list_for_each_entry(link, &genpd->parent_links, parent_node) { |
---|
| 3031 | + seq_printf(s, "%s", link->child->name); |
---|
| 3032 | + if (!list_is_last(&link->parent_node, &genpd->parent_links)) |
---|
2649 | 3033 | seq_puts(s, ", "); |
---|
2650 | 3034 | } |
---|
2651 | 3035 | |
---|
.. | .. |
---|
2668 | 3052 | return 0; |
---|
2669 | 3053 | } |
---|
2670 | 3054 | |
---|
2671 | | -static int genpd_summary_show(struct seq_file *s, void *data) |
---|
| 3055 | +static int summary_show(struct seq_file *s, void *data) |
---|
2672 | 3056 | { |
---|
2673 | 3057 | struct generic_pm_domain *genpd; |
---|
2674 | 3058 | int ret = 0; |
---|
2675 | 3059 | |
---|
2676 | | - seq_puts(s, "domain status slaves\n"); |
---|
| 3060 | + seq_puts(s, "domain status children\n"); |
---|
2677 | 3061 | seq_puts(s, " /device runtime status\n"); |
---|
2678 | 3062 | seq_puts(s, "----------------------------------------------------------------------\n"); |
---|
2679 | 3063 | |
---|
.. | .. |
---|
2691 | 3075 | return ret; |
---|
2692 | 3076 | } |
---|
2693 | 3077 | |
---|
2694 | | -static int genpd_status_show(struct seq_file *s, void *data) |
---|
| 3078 | +static int status_show(struct seq_file *s, void *data) |
---|
2695 | 3079 | { |
---|
2696 | 3080 | static const char * const status_lookup[] = { |
---|
2697 | | - [GPD_STATE_ACTIVE] = "on", |
---|
2698 | | - [GPD_STATE_POWER_OFF] = "off" |
---|
| 3081 | + [GENPD_STATE_ON] = "on", |
---|
| 3082 | + [GENPD_STATE_OFF] = "off" |
---|
2699 | 3083 | }; |
---|
2700 | 3084 | |
---|
2701 | 3085 | struct generic_pm_domain *genpd = s->private; |
---|
.. | .. |
---|
2708 | 3092 | if (WARN_ON_ONCE(genpd->status >= ARRAY_SIZE(status_lookup))) |
---|
2709 | 3093 | goto exit; |
---|
2710 | 3094 | |
---|
2711 | | - if (genpd->status == GPD_STATE_POWER_OFF) |
---|
| 3095 | + if (genpd->status == GENPD_STATE_OFF) |
---|
2712 | 3096 | seq_printf(s, "%s-%u\n", status_lookup[genpd->status], |
---|
2713 | 3097 | genpd->state_idx); |
---|
2714 | 3098 | else |
---|
.. | .. |
---|
2718 | 3102 | return ret; |
---|
2719 | 3103 | } |
---|
2720 | 3104 | |
---|
2721 | | -static int genpd_sub_domains_show(struct seq_file *s, void *data) |
---|
| 3105 | +static int sub_domains_show(struct seq_file *s, void *data) |
---|
2722 | 3106 | { |
---|
2723 | 3107 | struct generic_pm_domain *genpd = s->private; |
---|
2724 | 3108 | struct gpd_link *link; |
---|
.. | .. |
---|
2728 | 3112 | if (ret) |
---|
2729 | 3113 | return -ERESTARTSYS; |
---|
2730 | 3114 | |
---|
2731 | | - list_for_each_entry(link, &genpd->master_links, master_node) |
---|
2732 | | - seq_printf(s, "%s\n", link->slave->name); |
---|
| 3115 | + list_for_each_entry(link, &genpd->parent_links, parent_node) |
---|
| 3116 | + seq_printf(s, "%s\n", link->child->name); |
---|
2733 | 3117 | |
---|
2734 | 3118 | genpd_unlock(genpd); |
---|
2735 | 3119 | return ret; |
---|
2736 | 3120 | } |
---|
2737 | 3121 | |
---|
2738 | | -static int genpd_idle_states_show(struct seq_file *s, void *data) |
---|
| 3122 | +static int idle_states_show(struct seq_file *s, void *data) |
---|
2739 | 3123 | { |
---|
2740 | 3124 | struct generic_pm_domain *genpd = s->private; |
---|
2741 | 3125 | unsigned int i; |
---|
.. | .. |
---|
2745 | 3129 | if (ret) |
---|
2746 | 3130 | return -ERESTARTSYS; |
---|
2747 | 3131 | |
---|
2748 | | - seq_puts(s, "State Time Spent(ms)\n"); |
---|
| 3132 | + seq_puts(s, "State Time Spent(ms) Usage Rejected\n"); |
---|
2749 | 3133 | |
---|
2750 | 3134 | for (i = 0; i < genpd->state_count; i++) { |
---|
2751 | 3135 | ktime_t delta = 0; |
---|
2752 | 3136 | s64 msecs; |
---|
2753 | 3137 | |
---|
2754 | | - if ((genpd->status == GPD_STATE_POWER_OFF) && |
---|
| 3138 | + if ((genpd->status == GENPD_STATE_OFF) && |
---|
2755 | 3139 | (genpd->state_idx == i)) |
---|
2756 | 3140 | delta = ktime_sub(ktime_get(), genpd->accounting_time); |
---|
2757 | 3141 | |
---|
2758 | 3142 | msecs = ktime_to_ms( |
---|
2759 | 3143 | ktime_add(genpd->states[i].idle_time, delta)); |
---|
2760 | | - seq_printf(s, "S%-13i %lld\n", i, msecs); |
---|
| 3144 | + seq_printf(s, "S%-13i %-14lld %-14llu %llu\n", i, msecs, |
---|
| 3145 | + genpd->states[i].usage, genpd->states[i].rejected); |
---|
2761 | 3146 | } |
---|
2762 | 3147 | |
---|
2763 | 3148 | genpd_unlock(genpd); |
---|
2764 | 3149 | return ret; |
---|
2765 | 3150 | } |
---|
2766 | 3151 | |
---|
2767 | | -static int genpd_active_time_show(struct seq_file *s, void *data) |
---|
| 3152 | +static int active_time_show(struct seq_file *s, void *data) |
---|
2768 | 3153 | { |
---|
2769 | 3154 | struct generic_pm_domain *genpd = s->private; |
---|
2770 | 3155 | ktime_t delta = 0; |
---|
.. | .. |
---|
2774 | 3159 | if (ret) |
---|
2775 | 3160 | return -ERESTARTSYS; |
---|
2776 | 3161 | |
---|
2777 | | - if (genpd->status == GPD_STATE_ACTIVE) |
---|
| 3162 | + if (genpd->status == GENPD_STATE_ON) |
---|
2778 | 3163 | delta = ktime_sub(ktime_get(), genpd->accounting_time); |
---|
2779 | 3164 | |
---|
2780 | 3165 | seq_printf(s, "%lld ms\n", ktime_to_ms( |
---|
.. | .. |
---|
2784 | 3169 | return ret; |
---|
2785 | 3170 | } |
---|
2786 | 3171 | |
---|
2787 | | -static int genpd_total_idle_time_show(struct seq_file *s, void *data) |
---|
| 3172 | +static int total_idle_time_show(struct seq_file *s, void *data) |
---|
2788 | 3173 | { |
---|
2789 | 3174 | struct generic_pm_domain *genpd = s->private; |
---|
2790 | 3175 | ktime_t delta = 0, total = 0; |
---|
.. | .. |
---|
2797 | 3182 | |
---|
2798 | 3183 | for (i = 0; i < genpd->state_count; i++) { |
---|
2799 | 3184 | |
---|
2800 | | - if ((genpd->status == GPD_STATE_POWER_OFF) && |
---|
| 3185 | + if ((genpd->status == GENPD_STATE_OFF) && |
---|
2801 | 3186 | (genpd->state_idx == i)) |
---|
2802 | 3187 | delta = ktime_sub(ktime_get(), genpd->accounting_time); |
---|
2803 | 3188 | |
---|
.. | .. |
---|
2812 | 3197 | } |
---|
2813 | 3198 | |
---|
2814 | 3199 | |
---|
2815 | | -static int genpd_devices_show(struct seq_file *s, void *data) |
---|
| 3200 | +static int devices_show(struct seq_file *s, void *data) |
---|
2816 | 3201 | { |
---|
2817 | 3202 | struct generic_pm_domain *genpd = s->private; |
---|
2818 | 3203 | struct pm_domain_data *pm_data; |
---|
.. | .. |
---|
2838 | 3223 | return ret; |
---|
2839 | 3224 | } |
---|
2840 | 3225 | |
---|
2841 | | -static int genpd_perf_state_show(struct seq_file *s, void *data) |
---|
| 3226 | +static int perf_state_show(struct seq_file *s, void *data) |
---|
2842 | 3227 | { |
---|
2843 | 3228 | struct generic_pm_domain *genpd = s->private; |
---|
2844 | 3229 | |
---|
.. | .. |
---|
2851 | 3236 | return 0; |
---|
2852 | 3237 | } |
---|
2853 | 3238 | |
---|
2854 | | -#define define_genpd_open_function(name) \ |
---|
2855 | | -static int genpd_##name##_open(struct inode *inode, struct file *file) \ |
---|
2856 | | -{ \ |
---|
2857 | | - return single_open(file, genpd_##name##_show, inode->i_private); \ |
---|
| 3239 | +DEFINE_SHOW_ATTRIBUTE(summary); |
---|
| 3240 | +DEFINE_SHOW_ATTRIBUTE(status); |
---|
| 3241 | +DEFINE_SHOW_ATTRIBUTE(sub_domains); |
---|
| 3242 | +DEFINE_SHOW_ATTRIBUTE(idle_states); |
---|
| 3243 | +DEFINE_SHOW_ATTRIBUTE(active_time); |
---|
| 3244 | +DEFINE_SHOW_ATTRIBUTE(total_idle_time); |
---|
| 3245 | +DEFINE_SHOW_ATTRIBUTE(devices); |
---|
| 3246 | +DEFINE_SHOW_ATTRIBUTE(perf_state); |
---|
| 3247 | + |
---|
| 3248 | +static void genpd_debug_add(struct generic_pm_domain *genpd) |
---|
| 3249 | +{ |
---|
| 3250 | + struct dentry *d; |
---|
| 3251 | + |
---|
| 3252 | + if (!genpd_debugfs_dir) |
---|
| 3253 | + return; |
---|
| 3254 | + |
---|
| 3255 | + d = debugfs_create_dir(genpd->name, genpd_debugfs_dir); |
---|
| 3256 | + |
---|
| 3257 | + debugfs_create_file("current_state", 0444, |
---|
| 3258 | + d, genpd, &status_fops); |
---|
| 3259 | + debugfs_create_file("sub_domains", 0444, |
---|
| 3260 | + d, genpd, &sub_domains_fops); |
---|
| 3261 | + debugfs_create_file("idle_states", 0444, |
---|
| 3262 | + d, genpd, &idle_states_fops); |
---|
| 3263 | + debugfs_create_file("active_time", 0444, |
---|
| 3264 | + d, genpd, &active_time_fops); |
---|
| 3265 | + debugfs_create_file("total_idle_time", 0444, |
---|
| 3266 | + d, genpd, &total_idle_time_fops); |
---|
| 3267 | + debugfs_create_file("devices", 0444, |
---|
| 3268 | + d, genpd, &devices_fops); |
---|
| 3269 | + if (genpd->set_performance_state) |
---|
| 3270 | + debugfs_create_file("perf_state", 0444, |
---|
| 3271 | + d, genpd, &perf_state_fops); |
---|
2858 | 3272 | } |
---|
2859 | | - |
---|
2860 | | -define_genpd_open_function(summary); |
---|
2861 | | -define_genpd_open_function(status); |
---|
2862 | | -define_genpd_open_function(sub_domains); |
---|
2863 | | -define_genpd_open_function(idle_states); |
---|
2864 | | -define_genpd_open_function(active_time); |
---|
2865 | | -define_genpd_open_function(total_idle_time); |
---|
2866 | | -define_genpd_open_function(devices); |
---|
2867 | | -define_genpd_open_function(perf_state); |
---|
2868 | | - |
---|
2869 | | -#define define_genpd_debugfs_fops(name) \ |
---|
2870 | | -static const struct file_operations genpd_##name##_fops = { \ |
---|
2871 | | - .open = genpd_##name##_open, \ |
---|
2872 | | - .read = seq_read, \ |
---|
2873 | | - .llseek = seq_lseek, \ |
---|
2874 | | - .release = single_release, \ |
---|
2875 | | -} |
---|
2876 | | - |
---|
2877 | | -define_genpd_debugfs_fops(summary); |
---|
2878 | | -define_genpd_debugfs_fops(status); |
---|
2879 | | -define_genpd_debugfs_fops(sub_domains); |
---|
2880 | | -define_genpd_debugfs_fops(idle_states); |
---|
2881 | | -define_genpd_debugfs_fops(active_time); |
---|
2882 | | -define_genpd_debugfs_fops(total_idle_time); |
---|
2883 | | -define_genpd_debugfs_fops(devices); |
---|
2884 | | -define_genpd_debugfs_fops(perf_state); |
---|
2885 | 3273 | |
---|
2886 | 3274 | static int __init genpd_debug_init(void) |
---|
2887 | 3275 | { |
---|
2888 | | - struct dentry *d; |
---|
2889 | 3276 | struct generic_pm_domain *genpd; |
---|
2890 | 3277 | |
---|
2891 | 3278 | genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL); |
---|
2892 | 3279 | |
---|
2893 | | - if (!genpd_debugfs_dir) |
---|
2894 | | - return -ENOMEM; |
---|
| 3280 | + debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir, |
---|
| 3281 | + NULL, &summary_fops); |
---|
2895 | 3282 | |
---|
2896 | | - d = debugfs_create_file("pm_genpd_summary", S_IRUGO, |
---|
2897 | | - genpd_debugfs_dir, NULL, &genpd_summary_fops); |
---|
2898 | | - if (!d) |
---|
2899 | | - return -ENOMEM; |
---|
2900 | | - |
---|
2901 | | - list_for_each_entry(genpd, &gpd_list, gpd_list_node) { |
---|
2902 | | - d = debugfs_create_dir(genpd->name, genpd_debugfs_dir); |
---|
2903 | | - if (!d) |
---|
2904 | | - return -ENOMEM; |
---|
2905 | | - |
---|
2906 | | - debugfs_create_file("current_state", 0444, |
---|
2907 | | - d, genpd, &genpd_status_fops); |
---|
2908 | | - debugfs_create_file("sub_domains", 0444, |
---|
2909 | | - d, genpd, &genpd_sub_domains_fops); |
---|
2910 | | - debugfs_create_file("idle_states", 0444, |
---|
2911 | | - d, genpd, &genpd_idle_states_fops); |
---|
2912 | | - debugfs_create_file("active_time", 0444, |
---|
2913 | | - d, genpd, &genpd_active_time_fops); |
---|
2914 | | - debugfs_create_file("total_idle_time", 0444, |
---|
2915 | | - d, genpd, &genpd_total_idle_time_fops); |
---|
2916 | | - debugfs_create_file("devices", 0444, |
---|
2917 | | - d, genpd, &genpd_devices_fops); |
---|
2918 | | - if (genpd->set_performance_state) |
---|
2919 | | - debugfs_create_file("perf_state", 0444, |
---|
2920 | | - d, genpd, &genpd_perf_state_fops); |
---|
2921 | | - } |
---|
| 3283 | + list_for_each_entry(genpd, &gpd_list, gpd_list_node) |
---|
| 3284 | + genpd_debug_add(genpd); |
---|
2922 | 3285 | |
---|
2923 | 3286 | return 0; |
---|
2924 | 3287 | } |
---|