Lines Matching refs:wf
13 static void rpm_get(struct intel_wakeref *wf) in rpm_get() argument
15 wf->wakeref = intel_runtime_pm_get(&wf->i915->runtime_pm); in rpm_get()
18 static void rpm_put(struct intel_wakeref *wf) in rpm_put() argument
20 intel_wakeref_t wakeref = fetch_and_zero(&wf->wakeref); in rpm_put()
22 intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref); in rpm_put()
26 int __intel_wakeref_get_first(struct intel_wakeref *wf) in __intel_wakeref_get_first() argument
34 mutex_lock_nested(&wf->mutex, SINGLE_DEPTH_NESTING); in __intel_wakeref_get_first()
35 if (!atomic_read(&wf->count)) { in __intel_wakeref_get_first()
38 rpm_get(wf); in __intel_wakeref_get_first()
40 err = wf->ops->get(wf); in __intel_wakeref_get_first()
42 rpm_put(wf); in __intel_wakeref_get_first()
43 mutex_unlock(&wf->mutex); in __intel_wakeref_get_first()
49 atomic_inc(&wf->count); in __intel_wakeref_get_first()
50 mutex_unlock(&wf->mutex); in __intel_wakeref_get_first()
52 INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0); in __intel_wakeref_get_first()
56 static void ____intel_wakeref_put_last(struct intel_wakeref *wf) in ____intel_wakeref_put_last() argument
58 INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0); in ____intel_wakeref_put_last()
59 if (unlikely(!atomic_dec_and_test(&wf->count))) in ____intel_wakeref_put_last()
63 if (likely(!wf->ops->put(wf))) { in ____intel_wakeref_put_last()
64 rpm_put(wf); in ____intel_wakeref_put_last()
65 wake_up_var(&wf->wakeref); in ____intel_wakeref_put_last()
69 mutex_unlock(&wf->mutex); in ____intel_wakeref_put_last()
72 void __intel_wakeref_put_last(struct intel_wakeref *wf, unsigned long flags) in __intel_wakeref_put_last() argument
74 INTEL_WAKEREF_BUG_ON(delayed_work_pending(&wf->work)); in __intel_wakeref_put_last()
77 if (flags & INTEL_WAKEREF_PUT_ASYNC || !mutex_trylock(&wf->mutex)) { in __intel_wakeref_put_last()
78 mod_delayed_work(wf->i915->unordered_wq, &wf->work, in __intel_wakeref_put_last()
83 ____intel_wakeref_put_last(wf); in __intel_wakeref_put_last()
88 struct intel_wakeref *wf = container_of(wrk, typeof(*wf), work.work); in __intel_wakeref_put_work() local
90 if (atomic_add_unless(&wf->count, -1, 1)) in __intel_wakeref_put_work()
93 mutex_lock(&wf->mutex); in __intel_wakeref_put_work()
94 ____intel_wakeref_put_last(wf); in __intel_wakeref_put_work()
97 void __intel_wakeref_init(struct intel_wakeref *wf, in __intel_wakeref_init() argument
102 wf->i915 = i915; in __intel_wakeref_init()
103 wf->ops = ops; in __intel_wakeref_init()
105 __mutex_init(&wf->mutex, "wakeref.mutex", &key->mutex); in __intel_wakeref_init()
106 atomic_set(&wf->count, 0); in __intel_wakeref_init()
107 wf->wakeref = 0; in __intel_wakeref_init()
109 INIT_DELAYED_WORK(&wf->work, __intel_wakeref_put_work); in __intel_wakeref_init()
110 lockdep_init_map(&wf->work.work.lockdep_map, in __intel_wakeref_init()
114 int intel_wakeref_wait_for_idle(struct intel_wakeref *wf) in intel_wakeref_wait_for_idle() argument
120 err = wait_var_event_killable(&wf->wakeref, in intel_wakeref_wait_for_idle()
121 !intel_wakeref_is_active(wf)); in intel_wakeref_wait_for_idle()
125 intel_wakeref_unlock_wait(wf); in intel_wakeref_wait_for_idle()
131 struct intel_wakeref_auto *wf = from_timer(wf, t, timer); in wakeref_auto_timeout() local
135 if (!refcount_dec_and_lock_irqsave(&wf->count, &wf->lock, &flags)) in wakeref_auto_timeout()
138 wakeref = fetch_and_zero(&wf->wakeref); in wakeref_auto_timeout()
139 spin_unlock_irqrestore(&wf->lock, flags); in wakeref_auto_timeout()
141 intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref); in wakeref_auto_timeout()
144 void intel_wakeref_auto_init(struct intel_wakeref_auto *wf, in intel_wakeref_auto_init() argument
147 spin_lock_init(&wf->lock); in intel_wakeref_auto_init()
148 timer_setup(&wf->timer, wakeref_auto_timeout, 0); in intel_wakeref_auto_init()
149 refcount_set(&wf->count, 0); in intel_wakeref_auto_init()
150 wf->wakeref = 0; in intel_wakeref_auto_init()
151 wf->i915 = i915; in intel_wakeref_auto_init()
154 void intel_wakeref_auto(struct intel_wakeref_auto *wf, unsigned long timeout) in intel_wakeref_auto() argument
159 if (del_timer_sync(&wf->timer)) in intel_wakeref_auto()
160 wakeref_auto_timeout(&wf->timer); in intel_wakeref_auto()
165 assert_rpm_wakelock_held(&wf->i915->runtime_pm); in intel_wakeref_auto()
167 if (!refcount_inc_not_zero(&wf->count)) { in intel_wakeref_auto()
168 spin_lock_irqsave(&wf->lock, flags); in intel_wakeref_auto()
169 if (!refcount_inc_not_zero(&wf->count)) { in intel_wakeref_auto()
170 INTEL_WAKEREF_BUG_ON(wf->wakeref); in intel_wakeref_auto()
171 wf->wakeref = in intel_wakeref_auto()
172 intel_runtime_pm_get_if_in_use(&wf->i915->runtime_pm); in intel_wakeref_auto()
173 refcount_set(&wf->count, 1); in intel_wakeref_auto()
175 spin_unlock_irqrestore(&wf->lock, flags); in intel_wakeref_auto()
183 if (mod_timer(&wf->timer, jiffies + timeout)) in intel_wakeref_auto()
184 wakeref_auto_timeout(&wf->timer); in intel_wakeref_auto()
187 void intel_wakeref_auto_fini(struct intel_wakeref_auto *wf) in intel_wakeref_auto_fini() argument
189 intel_wakeref_auto(wf, 0); in intel_wakeref_auto_fini()
190 INTEL_WAKEREF_BUG_ON(wf->wakeref); in intel_wakeref_auto_fini()