History

Merge branches 'pm-core' and 'pm-runtime'

Merge runtime PM framework updates and a core power management code fix for 6.18-rc1: - Make pm_runtime_put*() family of functions return 1 when the given device is already suspended which is consistent with the documentation (Brian Norris) - Add basic kunit tests for runtime PM API contracts and update return values in kerneldoc coments for the runtime PM API (Brian Norris, Dan Carpenter) - Add auto-cleanup macros for runtime PM "resume and get" and "get without resume" operations, use one of them in the PCI core and drop the existing "free" macro introduced for similar purpose, but somewhat cumbersome to use (Rafael Wysocki) - Make the core power management code avoid waiting on device links marked as SYNC_STATE_ONLY which is consistent with the handling of those device links elsewhere (Pin-yen Lin) * pm-core: PM: sleep: Do not wait on SYNC_STATE_ONLY device links * pm-runtime: PM: runtime: Fix error checking for kunit_device_register() PM: runtime: Introduce one more usage counter guard PM: runtime: Drop DEFINE_FREE() for pm_runtime_put() PCI/sysfs: Use runtime PM guard macro for auto-cleanup PM: runtime: Add auto-cleanup macros for "resume and get" operations PM: runtime: Update kerneldoc return codes PM: runtime: Make put{,_sync}() return 1 when already suspended PM: runtime: Add basic kunit tests for API contracts

Rafael J. Wysocki committed 1 year ago

Commit 05f084d3 parents 9910531 632d310 92158fa9 files · +343 −41Browse files

Unified · Split

9 files
  1. drivers/base/Kconfig +6 −0
  2. drivers/base/base.h +1 −0
  3. drivers/base/core.c +1 −1
  4. drivers/base/power/Makefile +1 −0
  5. drivers/base/power/main.c +4 −2
  6. drivers/base/power/runtime-test.c +253 −0
  7. drivers/base/power/runtime.c +5 −0
  8. drivers/pci/pci-sysfs.c +3 −2
  9. include/linux/pm_runtime.h +69 −36
drivers/base/Kconfig+6−0
@@ -167,6 +167,12 @@ config PM_QOS_KUNIT_TEST · 166 unmodified lines
167 depends on KUNIT=y167 depends on KUNIT=y
168 default KUNIT_ALL_TESTS168 default KUNIT_ALL_TESTS
169 169
170config PM_RUNTIME_KUNIT_TEST
171 tristate "KUnit Tests for runtime PM" if !KUNIT_ALL_TESTS
172 depends on KUNIT
173 depends on PM
174 default KUNIT_ALL_TESTS
175
170config HMEM_REPORTING176config HMEM_REPORTING
171 bool177 bool
172 default n178 default n
drivers/base/base.h+1−0
@@ -248,6 +248,7 @@ void device_links_driver_cleanup(struct device *dev); · 247 unmodified lines
248void device_links_no_driver(struct device *dev);248void device_links_no_driver(struct device *dev);
249bool device_links_busy(struct device *dev);249bool device_links_busy(struct device *dev);
250void device_links_unbind_consumers(struct device *dev);250void device_links_unbind_consumers(struct device *dev);
251bool device_link_flag_is_sync_state_only(u32 flags);
251void fw_devlink_drivers_done(void);252void fw_devlink_drivers_done(void);
252void fw_devlink_probing_done(void);253void fw_devlink_probing_done(void);
253 254
drivers/base/core.c+1−1
@@ -287,7 +287,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target) · 286 unmodified lines
287#define DL_MARKER_FLAGS (DL_FLAG_INFERRED | \287#define DL_MARKER_FLAGS (DL_FLAG_INFERRED | \
288 DL_FLAG_CYCLE | \288 DL_FLAG_CYCLE | \
289 DL_FLAG_MANAGED)289 DL_FLAG_MANAGED)
290static inline bool device_link_flag_is_sync_state_only(u32 flags)290bool device_link_flag_is_sync_state_only(u32 flags)
291{291{
292 return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;292 return (flags & ~DL_MARKER_FLAGS) == DL_FLAG_SYNC_STATE_ONLY;
293}293}
drivers/base/power/Makefile+1−0
@@ -4,5 +4,6 @@ obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o · 3 unmodified lines
4obj-$(CONFIG_PM_TRACE_RTC) += trace.o4obj-$(CONFIG_PM_TRACE_RTC) += trace.o
5obj-$(CONFIG_HAVE_CLK) += clock_ops.o5obj-$(CONFIG_HAVE_CLK) += clock_ops.o
6obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o6obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o
7obj-$(CONFIG_PM_RUNTIME_KUNIT_TEST) += runtime-test.o
7 8
8ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG9ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/main.c+4−2
@@ -278,7 +278,8 @@ static void dpm_wait_for_suppliers(struct device *dev, bool async) · 277 unmodified lines
278 * walking.278 * walking.
279 */279 */
280 dev_for_each_link_to_supplier(link, dev)280 dev_for_each_link_to_supplier(link, dev)
281 if (READ_ONCE(link->status) != DL_STATE_DORMANT)281 if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
282 !device_link_flag_is_sync_state_only(link->flags))
282 dpm_wait(link->supplier, async);283 dpm_wait(link->supplier, async);
283 284
284 device_links_read_unlock(idx);285 device_links_read_unlock(idx);
@@ -335,7 +336,8 @@ static void dpm_wait_for_consumers(struct device *dev, bool async) · 50 unmodified lines
335 * unregistration).336 * unregistration).
336 */337 */
337 dev_for_each_link_to_consumer(link, dev)338 dev_for_each_link_to_consumer(link, dev)
338 if (READ_ONCE(link->status) != DL_STATE_DORMANT)339 if (READ_ONCE(link->status) != DL_STATE_DORMANT &&
340 !device_link_flag_is_sync_state_only(link->flags))
339 dpm_wait(link->consumer, async);341 dpm_wait(link->consumer, async);
340 342
341 device_links_read_unlock(idx);343 device_links_read_unlock(idx);
drivers/base/power/runtime-test.c+253−0
@@ -0,0 +1,253 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2025 Google, Inc.
4 */
5
6#include <linux/cleanup.h>
7#include <linux/pm_runtime.h>
8#include <kunit/device.h>
9#include <kunit/test.h>
10
11#define DEVICE_NAME "pm_runtime_test_device"
12
13static void pm_runtime_depth_test(struct kunit *test)
14{
15 struct device *dev = kunit_device_register(test, DEVICE_NAME);
16
17 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
18
19 pm_runtime_enable(dev);
20
21 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
22 KUNIT_EXPECT_EQ(test, 0, pm_runtime_get_sync(dev));
23 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
24 KUNIT_EXPECT_EQ(test, 1, pm_runtime_get_sync(dev)); /* "already active" */
25 KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync(dev));
26 KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync(dev));
27 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
28}
29
30/* Test pm_runtime_put() and friends when already suspended. */
31static void pm_runtime_already_suspended_test(struct kunit *test)
32{
33 struct device *dev = kunit_device_register(test, DEVICE_NAME);
34
35 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
36
37 pm_runtime_enable(dev);
38 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
39
40 pm_runtime_get_noresume(dev);
41 KUNIT_EXPECT_EQ(test, 0, pm_runtime_barrier(dev)); /* no wakeup needed */
42 pm_runtime_put(dev);
43
44 pm_runtime_get_noresume(dev);
45 KUNIT_EXPECT_EQ(test, 1, pm_runtime_put_sync(dev));
46
47 KUNIT_EXPECT_EQ(test, 1, pm_runtime_suspend(dev));
48 KUNIT_EXPECT_EQ(test, 1, pm_runtime_autosuspend(dev));
49 KUNIT_EXPECT_EQ(test, 1, pm_request_autosuspend(dev));
50
51 pm_runtime_get_noresume(dev);
52 KUNIT_EXPECT_EQ(test, 1, pm_runtime_put_sync_autosuspend(dev));
53
54 pm_runtime_get_noresume(dev);
55 pm_runtime_put_autosuspend(dev);
56
57 /* Grab 2 refcounts */
58 pm_runtime_get_noresume(dev);
59 pm_runtime_get_noresume(dev);
60 /* The first put() sees usage_count 1 */
61 KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync_autosuspend(dev));
62 /* The second put() sees usage_count 0 but tells us "already suspended". */
63 KUNIT_EXPECT_EQ(test, 1, pm_runtime_put_sync_autosuspend(dev));
64
65 /* Should have remained suspended the whole time. */
66 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
67}
68
69static void pm_runtime_idle_test(struct kunit *test)
70{
71 struct device *dev = kunit_device_register(test, DEVICE_NAME);
72
73 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
74
75 pm_runtime_enable(dev);
76
77 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
78 KUNIT_EXPECT_EQ(test, 0, pm_runtime_get_sync(dev));
79 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
80 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_idle(dev));
81 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
82 pm_runtime_put_noidle(dev);
83 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
84 KUNIT_EXPECT_EQ(test, 0, pm_runtime_idle(dev));
85 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
86 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_idle(dev));
87 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_request_idle(dev));
88}
89
90static void pm_runtime_disabled_test(struct kunit *test)
91{
92 struct device *dev = kunit_device_register(test, DEVICE_NAME);
93
94 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
95
96 /* Never called pm_runtime_enable() */
97 KUNIT_EXPECT_FALSE(test, pm_runtime_enabled(dev));
98
99 /* "disabled" is treated as "active" */
100 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
101 KUNIT_EXPECT_FALSE(test, pm_runtime_suspended(dev));
102
103 /*
104 * Note: these "fail", but they still acquire/release refcounts, so
105 * keep them balanced.
106 */
107 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_get(dev));
108 pm_runtime_put(dev);
109
110 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_get_sync(dev));
111 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_put_sync(dev));
112
113 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_get(dev));
114 pm_runtime_put_autosuspend(dev);
115
116 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_resume_and_get(dev));
117 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_idle(dev));
118 KUNIT_EXPECT_EQ(test, -EACCES, pm_request_idle(dev));
119 KUNIT_EXPECT_EQ(test, -EACCES, pm_request_resume(dev));
120 KUNIT_EXPECT_EQ(test, -EACCES, pm_request_autosuspend(dev));
121 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_suspend(dev));
122 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_resume(dev));
123 KUNIT_EXPECT_EQ(test, -EACCES, pm_runtime_autosuspend(dev));
124
125 /* Still disabled */
126 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
127 KUNIT_EXPECT_FALSE(test, pm_runtime_enabled(dev));
128}
129
130static void pm_runtime_error_test(struct kunit *test)
131{
132 struct device *dev = kunit_device_register(test, DEVICE_NAME);
133
134 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
135
136 pm_runtime_enable(dev);
137 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
138
139 /* Fake a .runtime_resume() error */
140 dev->power.runtime_error = -EIO;
141
142 /*
143 * Note: these "fail", but they still acquire/release refcounts, so
144 * keep them balanced.
145 */
146 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_get(dev));
147 pm_runtime_put(dev);
148
149 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_get_sync(dev));
150 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_put_sync(dev));
151
152 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_get(dev));
153 pm_runtime_put_autosuspend(dev);
154
155 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_get(dev));
156 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_put_sync_autosuspend(dev));
157
158 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_resume_and_get(dev));
159 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_idle(dev));
160 KUNIT_EXPECT_EQ(test, -EINVAL, pm_request_idle(dev));
161 KUNIT_EXPECT_EQ(test, -EINVAL, pm_request_resume(dev));
162 KUNIT_EXPECT_EQ(test, -EINVAL, pm_request_autosuspend(dev));
163 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_suspend(dev));
164 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_resume(dev));
165 KUNIT_EXPECT_EQ(test, -EINVAL, pm_runtime_autosuspend(dev));
166
167 /* Error is still pending */
168 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
169 KUNIT_EXPECT_EQ(test, -EIO, dev->power.runtime_error);
170 /* Clear error */
171 KUNIT_EXPECT_EQ(test, 0, pm_runtime_set_suspended(dev));
172 KUNIT_EXPECT_EQ(test, 0, dev->power.runtime_error);
173 /* Still suspended */
174 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
175
176 KUNIT_EXPECT_EQ(test, 0, pm_runtime_get(dev));
177 KUNIT_EXPECT_EQ(test, 1, pm_runtime_barrier(dev)); /* resume was pending */
178 pm_runtime_put(dev);
179 pm_runtime_suspend(dev); /* flush the put(), to suspend */
180 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
181
182 KUNIT_EXPECT_EQ(test, 0, pm_runtime_get_sync(dev));
183 KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync(dev));
184
185 KUNIT_EXPECT_EQ(test, 0, pm_runtime_get_sync(dev));
186 pm_runtime_put_autosuspend(dev);
187
188 KUNIT_EXPECT_EQ(test, 0, pm_runtime_resume_and_get(dev));
189
190 /*
191 * The following should all return -EAGAIN (usage is non-zero) or 1
192 * (already resumed).
193 */
194 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_idle(dev));
195 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_request_idle(dev));
196 KUNIT_EXPECT_EQ(test, 1, pm_request_resume(dev));
197 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_request_autosuspend(dev));
198 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_suspend(dev));
199 KUNIT_EXPECT_EQ(test, 1, pm_runtime_resume(dev));
200 KUNIT_EXPECT_EQ(test, -EAGAIN, pm_runtime_autosuspend(dev));
201
202 KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync(dev));
203
204 /* Suspended again */
205 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
206}
207
208/*
209 * Explore a typical probe() sequence in which a device marks itself powered,
210 * but doesn't hold any runtime PM reference, so it suspends as soon as it goes
211 * idle.
212 */
213static void pm_runtime_probe_active_test(struct kunit *test)
214{
215 struct device *dev = kunit_device_register(test, DEVICE_NAME);
216
217 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
218
219 KUNIT_EXPECT_TRUE(test, pm_runtime_status_suspended(dev));
220
221 KUNIT_EXPECT_EQ(test, 0, pm_runtime_set_active(dev));
222 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
223
224 pm_runtime_enable(dev);
225 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
226
227 /* Nothing to flush. We stay active. */
228 KUNIT_EXPECT_EQ(test, 0, pm_runtime_barrier(dev));
229 KUNIT_EXPECT_TRUE(test, pm_runtime_active(dev));
230
231 /* Ask for idle? Now we suspend. */
232 KUNIT_EXPECT_EQ(test, 0, pm_runtime_idle(dev));
233 KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
234}
235
236static struct kunit_case pm_runtime_test_cases[] = {
237 KUNIT_CASE(pm_runtime_depth_test),
238 KUNIT_CASE(pm_runtime_already_suspended_test),
239 KUNIT_CASE(pm_runtime_idle_test),
240 KUNIT_CASE(pm_runtime_disabled_test),
241 KUNIT_CASE(pm_runtime_error_test),
242 KUNIT_CASE(pm_runtime_probe_active_test),
243 {}
244};
245
246static struct kunit_suite pm_runtime_test_suite = {
247 .name = "pm_runtime_test_cases",
248 .test_cases = pm_runtime_test_cases,
249};
250
251kunit_test_suite(pm_runtime_test_suite);
252MODULE_DESCRIPTION("Runtime power management unit test suite");
253MODULE_LICENSE("GPL");
drivers/base/power/runtime.c+5−0
@@ -498,6 +498,9 @@ static int rpm_idle(struct device *dev, int rpmflags) · 497 unmodified lines
498 if (retval < 0)498 if (retval < 0)
499 ; /* Conditions are wrong. */499 ; /* Conditions are wrong. */
500 500
501 else if ((rpmflags & RPM_GET_PUT) && retval == 1)
502 ; /* put() is allowed in RPM_SUSPENDED */
503
501 /* Idle notifications are allowed only in the RPM_ACTIVE state. */504 /* Idle notifications are allowed only in the RPM_ACTIVE state. */
502 else if (dev->power.runtime_status != RPM_ACTIVE)505 else if (dev->power.runtime_status != RPM_ACTIVE)
503 retval = -EAGAIN;506 retval = -EAGAIN;
@@ -796,6 +799,8 @@ static int rpm_resume(struct device *dev, int rpmflags) · 292 unmodified lines
796 if (dev->power.runtime_status == RPM_ACTIVE &&799 if (dev->power.runtime_status == RPM_ACTIVE &&
797 dev->power.last_status == RPM_ACTIVE)800 dev->power.last_status == RPM_ACTIVE)
798 retval = 1;801 retval = 1;
802 else if (rpmflags & RPM_TRANSPARENT)
803 goto out;
799 else804 else
800 retval = -EACCES;805 retval = -EACCES;
801 }806 }
drivers/pci/pci-sysfs.c+3−2
@@ -1475,8 +1475,9 @@ static ssize_t reset_method_store(struct device *dev, · 1474 unmodified lines
1475 return count;1475 return count;
1476 }1476 }
1477 1477
1478 pm_runtime_get_sync(dev);1478 ACQUIRE(pm_runtime_active_try, pm)(dev);
1479 struct device *pmdev __free(pm_runtime_put) = dev;1479 if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
1480 return -ENXIO;
1480 1481
1481 if (sysfs_streq(buf, "default")) {1482 if (sysfs_streq(buf, "default")) {
1482 pci_init_reset_methods(pdev);1483 pci_init_reset_methods(pdev);
include/linux/pm_runtime.h+69−36
@@ -21,6 +21,7 @@ · 20 unmodified lines
21#define RPM_GET_PUT 0x04 /* Increment/decrement the21#define RPM_GET_PUT 0x04 /* Increment/decrement the
22 usage_count */22 usage_count */
23#define RPM_AUTO 0x08 /* Use autosuspend_delay */23#define RPM_AUTO 0x08 /* Use autosuspend_delay */
24#define RPM_TRANSPARENT 0x10 /* Succeed if runtime PM is disabled */
24 25
25/*26/*
26 * Use this for defining a set of PM operations to be used in all situations27 * Use this for defining a set of PM operations to be used in all situations
@@ -350,13 +351,12 @@ static inline int pm_runtime_force_resume(struct device *dev) { return -ENXIO; } · 323 unmodified lines
350 * * 0: Success.351 * * 0: Success.
351 * * -EINVAL: Runtime PM error.352 * * -EINVAL: Runtime PM error.
352 * * -EACCES: Runtime PM disabled.353 * * -EACCES: Runtime PM disabled.
353 * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing354 * * -EAGAIN: Runtime PM usage counter non-zero, Runtime PM status change
354 * or device not in %RPM_ACTIVE state.355 * ongoing or device not in %RPM_ACTIVE state.
355 * * -EBUSY: Runtime PM child_count non-zero.356 * * -EBUSY: Runtime PM child_count non-zero.
356 * * -EPERM: Device PM QoS resume latency 0.357 * * -EPERM: Device PM QoS resume latency 0.
357 * * -EINPROGRESS: Suspend already in progress.358 * * -EINPROGRESS: Suspend already in progress.
358 * * -ENOSYS: CONFIG_PM not enabled.359 * * -ENOSYS: CONFIG_PM not enabled.
359 * * 1: Device already suspended.
360 * Other values and conditions for the above values are possible as returned by360 * Other values and conditions for the above values are possible as returned by
361 * Runtime PM idle and suspend callbacks.361 * Runtime PM idle and suspend callbacks.
362 */362 */
@@ -370,14 +370,15 @@ static inline int pm_runtime_idle(struct device *dev) · 7 unmodified lines
370 * @dev: Target device.370 * @dev: Target device.
371 *371 *
372 * Return:372 * Return:
373 * * 1: Success; device was already suspended.
373 * * 0: Success.374 * * 0: Success.
374 * * -EINVAL: Runtime PM error.375 * * -EINVAL: Runtime PM error.
375 * * -EACCES: Runtime PM disabled.376 * * -EACCES: Runtime PM disabled.
376 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.377 * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change
378 * ongoing.
377 * * -EBUSY: Runtime PM child_count non-zero.379 * * -EBUSY: Runtime PM child_count non-zero.
378 * * -EPERM: Device PM QoS resume latency 0.380 * * -EPERM: Device PM QoS resume latency 0.
379 * * -ENOSYS: CONFIG_PM not enabled.381 * * -ENOSYS: CONFIG_PM not enabled.
380 * * 1: Device already suspended.
381 * Other values and conditions for the above values are possible as returned by382 * Other values and conditions for the above values are possible as returned by
382 * Runtime PM suspend callbacks.383 * Runtime PM suspend callbacks.
383 */384 */
@@ -396,14 +397,15 @@ static inline int pm_runtime_suspend(struct device *dev) · 12 unmodified lines
396 * engaging its "idle check" callback.397 * engaging its "idle check" callback.
397 *398 *
398 * Return:399 * Return:
400 * * 1: Success; device was already suspended.
399 * * 0: Success.401 * * 0: Success.
400 * * -EINVAL: Runtime PM error.402 * * -EINVAL: Runtime PM error.
401 * * -EACCES: Runtime PM disabled.403 * * -EACCES: Runtime PM disabled.
402 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.404 * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change
405 * ongoing.
403 * * -EBUSY: Runtime PM child_count non-zero.406 * * -EBUSY: Runtime PM child_count non-zero.
404 * * -EPERM: Device PM QoS resume latency 0.407 * * -EPERM: Device PM QoS resume latency 0.
405 * * -ENOSYS: CONFIG_PM not enabled.408 * * -ENOSYS: CONFIG_PM not enabled.
406 * * 1: Device already suspended.
407 * Other values and conditions for the above values are possible as returned by409 * Other values and conditions for the above values are possible as returned by
408 * Runtime PM suspend callbacks.410 * Runtime PM suspend callbacks.
409 */411 */
@@ -433,13 +435,12 @@ static inline int pm_runtime_resume(struct device *dev) · 23 unmodified lines
433 * * 0: Success.435 * * 0: Success.
434 * * -EINVAL: Runtime PM error.436 * * -EINVAL: Runtime PM error.
435 * * -EACCES: Runtime PM disabled.437 * * -EACCES: Runtime PM disabled.
436 * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing438 * * -EAGAIN: Runtime PM usage counter non-zero, Runtime PM status change
437 * or device not in %RPM_ACTIVE state.439 * ongoing or device not in %RPM_ACTIVE state.
438 * * -EBUSY: Runtime PM child_count non-zero.440 * * -EBUSY: Runtime PM child_count non-zero.
439 * * -EPERM: Device PM QoS resume latency 0.441 * * -EPERM: Device PM QoS resume latency 0.
440 * * -EINPROGRESS: Suspend already in progress.442 * * -EINPROGRESS: Suspend already in progress.
441 * * -ENOSYS: CONFIG_PM not enabled.443 * * -ENOSYS: CONFIG_PM not enabled.
442 * * 1: Device already suspended.
443 */444 */
444static inline int pm_request_idle(struct device *dev)445static inline int pm_request_idle(struct device *dev)
445{446{
@@ -464,15 +465,16 @@ static inline int pm_request_resume(struct device *dev) · 18 unmodified lines
464 * equivalent pm_runtime_autosuspend() for @dev asynchronously.465 * equivalent pm_runtime_autosuspend() for @dev asynchronously.
465 *466 *
466 * Return:467 * Return:
468 * * 1: Success; device was already suspended.
467 * * 0: Success.469 * * 0: Success.
468 * * -EINVAL: Runtime PM error.470 * * -EINVAL: Runtime PM error.
469 * * -EACCES: Runtime PM disabled.471 * * -EACCES: Runtime PM disabled.
470 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.472 * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change
473 * ongoing.
471 * * -EBUSY: Runtime PM child_count non-zero.474 * * -EBUSY: Runtime PM child_count non-zero.
472 * * -EPERM: Device PM QoS resume latency 0.475 * * -EPERM: Device PM QoS resume latency 0.
473 * * -EINPROGRESS: Suspend already in progress.476 * * -EINPROGRESS: Suspend already in progress.
474 * * -ENOSYS: CONFIG_PM not enabled.477 * * -ENOSYS: CONFIG_PM not enabled.
475 * * 1: Device already suspended.
476 */478 */
477static inline int pm_request_autosuspend(struct device *dev)479static inline int pm_request_autosuspend(struct device *dev)
478{480{
@@ -511,6 +513,19 @@ static inline int pm_runtime_get_sync(struct device *dev) · 32 unmodified lines
511 return __pm_runtime_resume(dev, RPM_GET_PUT);513 return __pm_runtime_resume(dev, RPM_GET_PUT);
512}514}
513 515
516static inline int pm_runtime_get_active(struct device *dev, int rpmflags)
517{
518 int ret;
519
520 ret = __pm_runtime_resume(dev, RPM_GET_PUT | rpmflags);
521 if (ret < 0) {
522 pm_runtime_put_noidle(dev);
523 return ret;
524 }
525
526 return 0;
527}
528
514/**529/**
515 * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it.530 * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it.
516 * @dev: Target device.531 * @dev: Target device.
@@ -521,15 +536,7 @@ static inline int pm_runtime_get_sync(struct device *dev) · 4 unmodified lines
521 */536 */
522static inline int pm_runtime_resume_and_get(struct device *dev)537static inline int pm_runtime_resume_and_get(struct device *dev)
523{538{
524 int ret;539 return pm_runtime_get_active(dev, 0);
525
526 ret = __pm_runtime_resume(dev, RPM_GET_PUT);
527 if (ret < 0) {
528 pm_runtime_put_noidle(dev);
529 return ret;
530 }
531
532 return 0;
533}540}
534 541
535/**542/**
@@ -540,23 +547,22 @@ static inline int pm_runtime_resume_and_get(struct device *dev) · 4 unmodified lines
540 * equal to 0, queue up a work item for @dev like in pm_request_idle().547 * equal to 0, queue up a work item for @dev like in pm_request_idle().
541 *548 *
542 * Return:549 * Return:
550 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
543 * * 0: Success.551 * * 0: Success.
544 * * -EINVAL: Runtime PM error.552 * * -EINVAL: Runtime PM error.
545 * * -EACCES: Runtime PM disabled.553 * * -EACCES: Runtime PM disabled.
546 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.554 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
555 * change ongoing.
547 * * -EBUSY: Runtime PM child_count non-zero.556 * * -EBUSY: Runtime PM child_count non-zero.
548 * * -EPERM: Device PM QoS resume latency 0.557 * * -EPERM: Device PM QoS resume latency 0.
549 * * -EINPROGRESS: Suspend already in progress.558 * * -EINPROGRESS: Suspend already in progress.
550 * * -ENOSYS: CONFIG_PM not enabled.559 * * -ENOSYS: CONFIG_PM not enabled.
551 * * 1: Device already suspended.
552 */560 */
553static inline int pm_runtime_put(struct device *dev)561static inline int pm_runtime_put(struct device *dev)
554{562{
555 return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);563 return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
556}564}
557 565
558DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
559
560/**566/**
561 * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.567 * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
562 * @dev: Target device.568 * @dev: Target device.
@@ -565,15 +571,16 @@ DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T)) · 2 unmodified lines
565 * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().571 * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
566 *572 *
567 * Return:573 * Return:
574 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
568 * * 0: Success.575 * * 0: Success.
569 * * -EINVAL: Runtime PM error.576 * * -EINVAL: Runtime PM error.
570 * * -EACCES: Runtime PM disabled.577 * * -EACCES: Runtime PM disabled.
571 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.578 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
579 * change ongoing.
572 * * -EBUSY: Runtime PM child_count non-zero.580 * * -EBUSY: Runtime PM child_count non-zero.
573 * * -EPERM: Device PM QoS resume latency 0.581 * * -EPERM: Device PM QoS resume latency 0.
574 * * -EINPROGRESS: Suspend already in progress.582 * * -EINPROGRESS: Suspend already in progress.
575 * * -ENOSYS: CONFIG_PM not enabled.583 * * -ENOSYS: CONFIG_PM not enabled.
576 * * 1: Device already suspended.
577 */584 */
578static inline int __pm_runtime_put_autosuspend(struct device *dev)585static inline int __pm_runtime_put_autosuspend(struct device *dev)
579{586{
@@ -590,15 +597,16 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev) · 10 unmodified lines
590 * in pm_request_autosuspend().597 * in pm_request_autosuspend().
591 *598 *
592 * Return:599 * Return:
600 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
593 * * 0: Success.601 * * 0: Success.
594 * * -EINVAL: Runtime PM error.602 * * -EINVAL: Runtime PM error.
595 * * -EACCES: Runtime PM disabled.603 * * -EACCES: Runtime PM disabled.
596 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.604 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
605 * change ongoing.
597 * * -EBUSY: Runtime PM child_count non-zero.606 * * -EBUSY: Runtime PM child_count non-zero.
598 * * -EPERM: Device PM QoS resume latency 0.607 * * -EPERM: Device PM QoS resume latency 0.
599 * * -EINPROGRESS: Suspend already in progress.608 * * -EINPROGRESS: Suspend already in progress.
600 * * -ENOSYS: CONFIG_PM not enabled.609 * * -ENOSYS: CONFIG_PM not enabled.
601 * * 1: Device already suspended.
602 */610 */
603static inline int pm_runtime_put_autosuspend(struct device *dev)611static inline int pm_runtime_put_autosuspend(struct device *dev)
604{612{
@@ -606,6 +614,29 @@ static inline int pm_runtime_put_autosuspend(struct device *dev) · 1 unmodified line
606 return __pm_runtime_put_autosuspend(dev);614 return __pm_runtime_put_autosuspend(dev);
607}615}
608 616
617DEFINE_GUARD(pm_runtime_noresume, struct device *,
618 pm_runtime_get_noresume(_T), pm_runtime_put_noidle(_T));
619
620DEFINE_GUARD(pm_runtime_active, struct device *,
621 pm_runtime_get_sync(_T), pm_runtime_put(_T));
622DEFINE_GUARD(pm_runtime_active_auto, struct device *,
623 pm_runtime_get_sync(_T), pm_runtime_put_autosuspend(_T));
624/*
625 * Use the following guards with ACQUIRE()/ACQUIRE_ERR().
626 *
627 * The difference between the "_try" and "_try_enabled" variants is that the
628 * former do not produce an error when runtime PM is disabled for the given
629 * device.
630 */
631DEFINE_GUARD_COND(pm_runtime_active, _try,
632 pm_runtime_get_active(_T, RPM_TRANSPARENT))
633DEFINE_GUARD_COND(pm_runtime_active, _try_enabled,
634 pm_runtime_resume_and_get(_T))
635DEFINE_GUARD_COND(pm_runtime_active_auto, _try,
636 pm_runtime_get_active(_T, RPM_TRANSPARENT))
637DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled,
638 pm_runtime_resume_and_get(_T))
639
609/**640/**
610 * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.641 * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0.
611 * @dev: Target device.642 * @dev: Target device.
@@ -619,14 +650,15 @@ static inline int pm_runtime_put_autosuspend(struct device *dev) · 7 unmodified lines
619 * if it returns an error code.650 * if it returns an error code.
620 *651 *
621 * Return:652 * Return:
653 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
622 * * 0: Success.654 * * 0: Success.
623 * * -EINVAL: Runtime PM error.655 * * -EINVAL: Runtime PM error.
624 * * -EACCES: Runtime PM disabled.656 * * -EACCES: Runtime PM disabled.
625 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.657 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
658 * change ongoing.
626 * * -EBUSY: Runtime PM child_count non-zero.659 * * -EBUSY: Runtime PM child_count non-zero.
627 * * -EPERM: Device PM QoS resume latency 0.660 * * -EPERM: Device PM QoS resume latency 0.
628 * * -ENOSYS: CONFIG_PM not enabled.661 * * -ENOSYS: CONFIG_PM not enabled.
629 * * 1: Device already suspended.
630 * Other values and conditions for the above values are possible as returned by662 * Other values and conditions for the above values are possible as returned by
631 * Runtime PM suspend callbacks.663 * Runtime PM suspend callbacks.
632 */664 */
@@ -646,15 +678,15 @@ static inline int pm_runtime_put_sync(struct device *dev) · 13 unmodified lines
646 * if it returns an error code.678 * if it returns an error code.
647 *679 *
648 * Return:680 * Return:
681 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
649 * * 0: Success.682 * * 0: Success.
650 * * -EINVAL: Runtime PM error.683 * * -EINVAL: Runtime PM error.
651 * * -EACCES: Runtime PM disabled.684 * * -EACCES: Runtime PM disabled.
652 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.685 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
653 * * -EAGAIN: usage_count non-zero or Runtime PM status change ongoing.686 * change ongoing.
654 * * -EBUSY: Runtime PM child_count non-zero.687 * * -EBUSY: Runtime PM child_count non-zero.
655 * * -EPERM: Device PM QoS resume latency 0.688 * * -EPERM: Device PM QoS resume latency 0.
656 * * -ENOSYS: CONFIG_PM not enabled.689 * * -ENOSYS: CONFIG_PM not enabled.
657 * * 1: Device already suspended.
658 * Other values and conditions for the above values are possible as returned by690 * Other values and conditions for the above values are possible as returned by
659 * Runtime PM suspend callbacks.691 * Runtime PM suspend callbacks.
660 */692 */
@@ -677,15 +709,16 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev) · 16 unmodified lines
677 * if it returns an error code.709 * if it returns an error code.
678 *710 *
679 * Return:711 * Return:
712 * * 1: Success. Usage counter dropped to zero, but device was already suspended.
680 * * 0: Success.713 * * 0: Success.
681 * * -EINVAL: Runtime PM error.714 * * -EINVAL: Runtime PM error.
682 * * -EACCES: Runtime PM disabled.715 * * -EACCES: Runtime PM disabled.
683 * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.716 * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status
717 * change ongoing.
684 * * -EBUSY: Runtime PM child_count non-zero.718 * * -EBUSY: Runtime PM child_count non-zero.
685 * * -EPERM: Device PM QoS resume latency 0.719 * * -EPERM: Device PM QoS resume latency 0.
686 * * -EINPROGRESS: Suspend already in progress.720 * * -EINPROGRESS: Suspend already in progress.
687 * * -ENOSYS: CONFIG_PM not enabled.721 * * -ENOSYS: CONFIG_PM not enabled.
688 * * 1: Device already suspended.
689 * Other values and conditions for the above values are possible as returned by722 * Other values and conditions for the above values are possible as returned by
690 * Runtime PM suspend callbacks.723 * Runtime PM suspend callbacks.
691 */724 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t