140b326eeSChris Wilson /*
240b326eeSChris Wilson * Copyright © 2016 Intel Corporation
340b326eeSChris Wilson *
440b326eeSChris Wilson * Permission is hereby granted, free of charge, to any person obtaining a
540b326eeSChris Wilson * copy of this software and associated documentation files (the "Software"),
640b326eeSChris Wilson * to deal in the Software without restriction, including without limitation
740b326eeSChris Wilson * the rights to use, copy, modify, merge, publish, distribute, sublicense,
840b326eeSChris Wilson * and/or sell copies of the Software, and to permit persons to whom the
940b326eeSChris Wilson * Software is furnished to do so, subject to the following conditions:
1040b326eeSChris Wilson *
1140b326eeSChris Wilson * The above copyright notice and this permission notice (including the next
1240b326eeSChris Wilson * paragraph) shall be included in all copies or substantial portions of the
1340b326eeSChris Wilson * Software.
1440b326eeSChris Wilson *
1540b326eeSChris Wilson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1640b326eeSChris Wilson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1740b326eeSChris Wilson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1840b326eeSChris Wilson * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1940b326eeSChris Wilson * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2040b326eeSChris Wilson * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2140b326eeSChris Wilson * IN THE SOFTWARE.
2240b326eeSChris Wilson *
2340b326eeSChris Wilson */
2440b326eeSChris Wilson
2540b326eeSChris Wilson #ifndef __I915_UTILS_H
2640b326eeSChris Wilson #define __I915_UTILS_H
2740b326eeSChris Wilson
28cb363304SJani Nikula #include <linux/list.h>
29976b55f0SChris Wilson #include <linux/overflow.h>
30b30ed4ccSJani Nikula #include <linux/sched.h>
31ff9fbe7cSLucas De Marchi #include <linux/string_helpers.h>
32cb363304SJani Nikula #include <linux/types.h>
33cb363304SJani Nikula #include <linux/workqueue.h>
34348332e0SChristoph Hellwig #include <linux/sched/clock.h>
35c900a670SCasey Bowman
36c900a670SCasey Bowman #ifdef CONFIG_X86
37a7f46d5bSTvrtko Ursulin #include <asm/hypervisor.h>
38c900a670SCasey Bowman #endif
39cb363304SJani Nikula
40358c855cSJani Nikula struct drm_i915_private;
413a7a92abSChris Wilson struct timer_list;
42358c855cSJani Nikula
43f8e9325fSJani Nikula #define FDO_BUG_URL "https://drm.pages.freedesktop.org/intel-docs/how-to-file-i915-bugs.html"
4417f5d579SLyude Paul
4557bdff48SLucas De Marchi #define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
4657bdff48SLucas De Marchi __stringify(x), (long)(x))
47f0d66153SMichal Wajdeczko
48358c855cSJani Nikula #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
49358c855cSJani Nikula
50dd6e38dfSJanusz Krzysztofik int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
51358c855cSJani Nikula const char *func, int line);
52dd6e38dfSJanusz Krzysztofik #define i915_inject_probe_error(_i915, _err) \
53dd6e38dfSJanusz Krzysztofik __i915_inject_probe_error((_i915), (_err), __func__, __LINE__)
54358c855cSJani Nikula bool i915_error_injected(void);
55358c855cSJani Nikula
56358c855cSJani Nikula #else
57358c855cSJani Nikula
58b58a8813SMichal Wajdeczko #define i915_inject_probe_error(i915, e) ({ BUILD_BUG_ON_INVALID(i915); 0; })
59358c855cSJani Nikula #define i915_error_injected() false
60358c855cSJani Nikula
61358c855cSJani Nikula #endif
62358c855cSJani Nikula
63dd6e38dfSJanusz Krzysztofik #define i915_inject_probe_failure(i915) i915_inject_probe_error((i915), -ENODEV)
64358c855cSJani Nikula
65*372f244bSJani Nikula #define i915_probe_error(i915, fmt, ...) ({ \
66*372f244bSJani Nikula if (i915_error_injected()) \
67*372f244bSJani Nikula drm_dbg(&(i915)->drm, fmt, ##__VA_ARGS__); \
68*372f244bSJani Nikula else \
69*372f244bSJani Nikula drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
70*372f244bSJani Nikula })
71358c855cSJani Nikula
7240b326eeSChris Wilson #define range_overflows(start, size, max) ({ \
7340b326eeSChris Wilson typeof(start) start__ = (start); \
7440b326eeSChris Wilson typeof(size) size__ = (size); \
7540b326eeSChris Wilson typeof(max) max__ = (max); \
7640b326eeSChris Wilson (void)(&start__ == &size__); \
7740b326eeSChris Wilson (void)(&start__ == &max__); \
78520f8350SMatthew Auld start__ >= max__ || size__ > max__ - start__; \
7940b326eeSChris Wilson })
8040b326eeSChris Wilson
8140b326eeSChris Wilson #define range_overflows_t(type, start, size, max) \
8240b326eeSChris Wilson range_overflows((type)(start), (type)(size), (type)(max))
8340b326eeSChris Wilson
84520f8350SMatthew Auld #define range_overflows_end(start, size, max) ({ \
85520f8350SMatthew Auld typeof(start) start__ = (start); \
86520f8350SMatthew Auld typeof(size) size__ = (size); \
87520f8350SMatthew Auld typeof(max) max__ = (max); \
88520f8350SMatthew Auld (void)(&start__ == &size__); \
89520f8350SMatthew Auld (void)(&start__ == &max__); \
90520f8350SMatthew Auld start__ > max__ || size__ > max__ - start__; \
91520f8350SMatthew Auld })
92520f8350SMatthew Auld
93520f8350SMatthew Auld #define range_overflows_end_t(type, start, size, max) \
94520f8350SMatthew Auld range_overflows_end((type)(start), (type)(size), (type)(max))
95520f8350SMatthew Auld
960ce81788SChris Wilson #define ptr_mask_bits(ptr, n) ({ \
97b7163936SChris Wilson unsigned long __v = (unsigned long)(ptr); \
980ce81788SChris Wilson (typeof(ptr))(__v & -BIT(n)); \
99b7163936SChris Wilson })
100b7163936SChris Wilson
1010ce81788SChris Wilson #define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
1020ce81788SChris Wilson
1030ce81788SChris Wilson #define ptr_unpack_bits(ptr, bits, n) ({ \
104b7163936SChris Wilson unsigned long __v = (unsigned long)(ptr); \
1050ce81788SChris Wilson *(bits) = __v & (BIT(n) - 1); \
1060ce81788SChris Wilson (typeof(ptr))(__v & -BIT(n)); \
107b7163936SChris Wilson })
108b7163936SChris Wilson
1092d751415STvrtko Ursulin #define ptr_pack_bits(ptr, bits, n) ({ \
1102d751415STvrtko Ursulin unsigned long __bits = (bits); \
1112d751415STvrtko Ursulin GEM_BUG_ON(__bits & -BIT(n)); \
1122d751415STvrtko Ursulin ((typeof(ptr))((unsigned long)(ptr) | __bits)); \
1132d751415STvrtko Ursulin })
114b7163936SChris Wilson
115df403069SChris Wilson #define ptr_dec(ptr) ({ \
116df403069SChris Wilson unsigned long __v = (unsigned long)(ptr); \
117df403069SChris Wilson (typeof(ptr))(__v - 1); \
118df403069SChris Wilson })
11922b7a426SChris Wilson
120df403069SChris Wilson #define ptr_inc(ptr) ({ \
121df403069SChris Wilson unsigned long __v = (unsigned long)(ptr); \
122df403069SChris Wilson (typeof(ptr))(__v + 1); \
123df403069SChris Wilson })
12422b7a426SChris Wilson
1250ce81788SChris Wilson #define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
1260ce81788SChris Wilson #define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
1270ce81788SChris Wilson #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
1280ce81788SChris Wilson #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
1290ce81788SChris Wilson
130b7163936SChris Wilson #define fetch_and_zero(ptr) ({ \
131b7163936SChris Wilson typeof(*ptr) __T = *(ptr); \
132b7163936SChris Wilson *(ptr) = (typeof(*ptr))0; \
133b7163936SChris Wilson __T; \
134b7163936SChris Wilson })
135b7163936SChris Wilson
ptrdiff(const void * a,const void * b)136d6e9c965SMichal Wajdeczko static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
137d6e9c965SMichal Wajdeczko {
138d6e9c965SMichal Wajdeczko return a - b;
139d6e9c965SMichal Wajdeczko }
140d6e9c965SMichal Wajdeczko
1419d1305efSChris Wilson /*
1429d1305efSChris Wilson * container_of_user: Extract the superclass from a pointer to a member.
1439d1305efSChris Wilson *
1449d1305efSChris Wilson * Exactly like container_of() with the exception that it plays nicely
1459d1305efSChris Wilson * with sparse for __user @ptr.
1469d1305efSChris Wilson */
1479d1305efSChris Wilson #define container_of_user(ptr, type, member) ({ \
1489d1305efSChris Wilson void __user *__mptr = (void __user *)(ptr); \
14989270d00SAndrzej Hajda BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
1509d1305efSChris Wilson !__same_type(*(ptr), void), \
1519d1305efSChris Wilson "pointer type mismatch in container_of()"); \
1529d1305efSChris Wilson ((type __user *)(__mptr - offsetof(type, member))); })
1539d1305efSChris Wilson
1549d1305efSChris Wilson /*
1559d1305efSChris Wilson * check_user_mbz: Check that a user value exists and is zero
1569d1305efSChris Wilson *
1579d1305efSChris Wilson * Frequently in our uABI we reserve space for future extensions, and
1589d1305efSChris Wilson * two ensure that userspace is prepared we enforce that space must
1599d1305efSChris Wilson * be zero. (Then any future extension can safely assume a default value
1609d1305efSChris Wilson * of 0.)
1619d1305efSChris Wilson *
1629d1305efSChris Wilson * check_user_mbz() combines checking that the user pointer is accessible
1639d1305efSChris Wilson * and that the contained value is zero.
1649d1305efSChris Wilson *
1659d1305efSChris Wilson * Returns: -EFAULT if not accessible, -EINVAL if !zero, or 0 on success.
1669d1305efSChris Wilson */
1679d1305efSChris Wilson #define check_user_mbz(U) ({ \
1689d1305efSChris Wilson typeof(*(U)) mbz__; \
1699d1305efSChris Wilson get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0; \
1709d1305efSChris Wilson })
1719d1305efSChris Wilson
1724ff4b44cSChris Wilson #define u64_to_ptr(T, x) ({ \
1734ff4b44cSChris Wilson typecheck(u64, x); \
1744ff4b44cSChris Wilson (T *)(uintptr_t)(x); \
1754ff4b44cSChris Wilson })
1764ff4b44cSChris Wilson
17716586fcdSMichal Wajdeczko #define __mask_next_bit(mask) ({ \
17816586fcdSMichal Wajdeczko int __idx = ffs(mask) - 1; \
17916586fcdSMichal Wajdeczko mask &= ~BIT(__idx); \
18016586fcdSMichal Wajdeczko __idx; \
18116586fcdSMichal Wajdeczko })
18216586fcdSMichal Wajdeczko
is_power_of_2_u64(u64 n)1832920516bSMatthew Auld static inline bool is_power_of_2_u64(u64 n)
1842920516bSMatthew Auld {
1852920516bSMatthew Auld return (n != 0 && ((n & (n - 1)) == 0));
1862920516bSMatthew Auld }
1872920516bSMatthew Auld
__list_del_many(struct list_head * head,struct list_head * first)1886c067579SChris Wilson static inline void __list_del_many(struct list_head *head,
1896c067579SChris Wilson struct list_head *first)
1906c067579SChris Wilson {
1916c067579SChris Wilson first->prev = head;
1926c067579SChris Wilson WRITE_ONCE(head->next, first);
1936c067579SChris Wilson }
1946c067579SChris Wilson
list_is_last_rcu(const struct list_head * list,const struct list_head * head)195875c3b4bSChris Wilson static inline int list_is_last_rcu(const struct list_head *list,
196875c3b4bSChris Wilson const struct list_head *head)
197875c3b4bSChris Wilson {
198875c3b4bSChris Wilson return READ_ONCE(list->next) == head;
199875c3b4bSChris Wilson }
200875c3b4bSChris Wilson
msecs_to_jiffies_timeout(const unsigned int m)201b30ed4ccSJani Nikula static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
202b30ed4ccSJani Nikula {
203b30ed4ccSJani Nikula unsigned long j = msecs_to_jiffies(m);
204b30ed4ccSJani Nikula
205b30ed4ccSJani Nikula return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
206b30ed4ccSJani Nikula }
207b30ed4ccSJani Nikula
208b30ed4ccSJani Nikula /*
209b30ed4ccSJani Nikula * If you need to wait X milliseconds between events A and B, but event B
210b30ed4ccSJani Nikula * doesn't happen exactly after event A, you record the timestamp (jiffies) of
211b30ed4ccSJani Nikula * when event A happened, then just before event B you call this function and
212b30ed4ccSJani Nikula * pass the timestamp as the first argument, and X as the second argument.
213b30ed4ccSJani Nikula */
214b30ed4ccSJani Nikula static inline void
wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies,int to_wait_ms)215b30ed4ccSJani Nikula wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
216b30ed4ccSJani Nikula {
217b30ed4ccSJani Nikula unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
218b30ed4ccSJani Nikula
219b30ed4ccSJani Nikula /*
220b30ed4ccSJani Nikula * Don't re-read the value of "jiffies" every time since it may change
221b30ed4ccSJani Nikula * behind our back and break the math.
222b30ed4ccSJani Nikula */
223b30ed4ccSJani Nikula tmp_jiffies = jiffies;
224b30ed4ccSJani Nikula target_jiffies = timestamp_jiffies +
225b30ed4ccSJani Nikula msecs_to_jiffies_timeout(to_wait_ms);
226b30ed4ccSJani Nikula
227b30ed4ccSJani Nikula if (time_after(target_jiffies, tmp_jiffies)) {
228b30ed4ccSJani Nikula remaining_jiffies = target_jiffies - tmp_jiffies;
229b30ed4ccSJani Nikula while (remaining_jiffies)
230b30ed4ccSJani Nikula remaining_jiffies =
231b30ed4ccSJani Nikula schedule_timeout_uninterruptible(remaining_jiffies);
232b30ed4ccSJani Nikula }
233b30ed4ccSJani Nikula }
234b30ed4ccSJani Nikula
235144c3f7bSJani Nikula /*
236b30ed4ccSJani Nikula * __wait_for - magic wait macro
237b30ed4ccSJani Nikula *
238b30ed4ccSJani Nikula * Macro to help avoid open coding check/wait/timeout patterns. Note that it's
239b30ed4ccSJani Nikula * important that we check the condition again after having timed out, since the
240b30ed4ccSJani Nikula * timeout could be due to preemption or similar and we've never had a chance to
241b30ed4ccSJani Nikula * check the condition before the timeout.
242b30ed4ccSJani Nikula */
243b30ed4ccSJani Nikula #define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
244b30ed4ccSJani Nikula const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
245b30ed4ccSJani Nikula long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
246b30ed4ccSJani Nikula int ret__; \
247b30ed4ccSJani Nikula might_sleep(); \
248b30ed4ccSJani Nikula for (;;) { \
249b30ed4ccSJani Nikula const bool expired__ = ktime_after(ktime_get_raw(), end__); \
250b30ed4ccSJani Nikula OP; \
251b30ed4ccSJani Nikula /* Guarantee COND check prior to timeout */ \
252b30ed4ccSJani Nikula barrier(); \
253b30ed4ccSJani Nikula if (COND) { \
254b30ed4ccSJani Nikula ret__ = 0; \
255b30ed4ccSJani Nikula break; \
256b30ed4ccSJani Nikula } \
257b30ed4ccSJani Nikula if (expired__) { \
258b30ed4ccSJani Nikula ret__ = -ETIMEDOUT; \
259b30ed4ccSJani Nikula break; \
260b30ed4ccSJani Nikula } \
261b30ed4ccSJani Nikula usleep_range(wait__, wait__ * 2); \
262b30ed4ccSJani Nikula if (wait__ < (Wmax)) \
263b30ed4ccSJani Nikula wait__ <<= 1; \
264b30ed4ccSJani Nikula } \
265b30ed4ccSJani Nikula ret__; \
266b30ed4ccSJani Nikula })
267b30ed4ccSJani Nikula
268b30ed4ccSJani Nikula #define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
269b30ed4ccSJani Nikula (Wmax))
270b30ed4ccSJani Nikula #define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000)
271b30ed4ccSJani Nikula
272b30ed4ccSJani Nikula /* If CONFIG_PREEMPT_COUNT is disabled, in_atomic() always reports false. */
273b30ed4ccSJani Nikula #if defined(CONFIG_DRM_I915_DEBUG) && defined(CONFIG_PREEMPT_COUNT)
274b30ed4ccSJani Nikula # define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) WARN_ON_ONCE((ATOMIC) && !in_atomic())
275b30ed4ccSJani Nikula #else
276b30ed4ccSJani Nikula # define _WAIT_FOR_ATOMIC_CHECK(ATOMIC) do { } while (0)
277b30ed4ccSJani Nikula #endif
278b30ed4ccSJani Nikula
279b30ed4ccSJani Nikula #define _wait_for_atomic(COND, US, ATOMIC) \
280b30ed4ccSJani Nikula ({ \
281b30ed4ccSJani Nikula int cpu, ret, timeout = (US) * 1000; \
282b30ed4ccSJani Nikula u64 base; \
283b30ed4ccSJani Nikula _WAIT_FOR_ATOMIC_CHECK(ATOMIC); \
284b30ed4ccSJani Nikula if (!(ATOMIC)) { \
285b30ed4ccSJani Nikula preempt_disable(); \
286b30ed4ccSJani Nikula cpu = smp_processor_id(); \
287b30ed4ccSJani Nikula } \
288b30ed4ccSJani Nikula base = local_clock(); \
289b30ed4ccSJani Nikula for (;;) { \
290b30ed4ccSJani Nikula u64 now = local_clock(); \
291b30ed4ccSJani Nikula if (!(ATOMIC)) \
292b30ed4ccSJani Nikula preempt_enable(); \
293b30ed4ccSJani Nikula /* Guarantee COND check prior to timeout */ \
294b30ed4ccSJani Nikula barrier(); \
295b30ed4ccSJani Nikula if (COND) { \
296b30ed4ccSJani Nikula ret = 0; \
297b30ed4ccSJani Nikula break; \
298b30ed4ccSJani Nikula } \
299b30ed4ccSJani Nikula if (now - base >= timeout) { \
300b30ed4ccSJani Nikula ret = -ETIMEDOUT; \
301b30ed4ccSJani Nikula break; \
302b30ed4ccSJani Nikula } \
303b30ed4ccSJani Nikula cpu_relax(); \
304b30ed4ccSJani Nikula if (!(ATOMIC)) { \
305b30ed4ccSJani Nikula preempt_disable(); \
306b30ed4ccSJani Nikula if (unlikely(cpu != smp_processor_id())) { \
307b30ed4ccSJani Nikula timeout -= now - base; \
308b30ed4ccSJani Nikula cpu = smp_processor_id(); \
309b30ed4ccSJani Nikula base = local_clock(); \
310b30ed4ccSJani Nikula } \
311b30ed4ccSJani Nikula } \
312b30ed4ccSJani Nikula } \
313b30ed4ccSJani Nikula ret; \
314b30ed4ccSJani Nikula })
315b30ed4ccSJani Nikula
316b30ed4ccSJani Nikula #define wait_for_us(COND, US) \
317b30ed4ccSJani Nikula ({ \
318b30ed4ccSJani Nikula int ret__; \
319b30ed4ccSJani Nikula BUILD_BUG_ON(!__builtin_constant_p(US)); \
320b30ed4ccSJani Nikula if ((US) > 10) \
321b30ed4ccSJani Nikula ret__ = _wait_for((COND), (US), 10, 10); \
322b30ed4ccSJani Nikula else \
323b30ed4ccSJani Nikula ret__ = _wait_for_atomic((COND), (US), 0); \
324b30ed4ccSJani Nikula ret__; \
325b30ed4ccSJani Nikula })
326b30ed4ccSJani Nikula
327b30ed4ccSJani Nikula #define wait_for_atomic_us(COND, US) \
328b30ed4ccSJani Nikula ({ \
329b30ed4ccSJani Nikula BUILD_BUG_ON(!__builtin_constant_p(US)); \
330b30ed4ccSJani Nikula BUILD_BUG_ON((US) > 50000); \
331b30ed4ccSJani Nikula _wait_for_atomic((COND), (US), 1); \
332b30ed4ccSJani Nikula })
333b30ed4ccSJani Nikula
334b30ed4ccSJani Nikula #define wait_for_atomic(COND, MS) wait_for_atomic_us((COND), (MS) * 1000)
335b30ed4ccSJani Nikula
336b30ed4ccSJani Nikula #define KHz(x) (1000 * (x))
337b30ed4ccSJani Nikula #define MHz(x) KHz(1000 * (x))
338b30ed4ccSJani Nikula
33965706203SMichał Winiarski void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint);
__add_taint_for_CI(unsigned int taint)34065706203SMichał Winiarski static inline void __add_taint_for_CI(unsigned int taint)
341e3adffe8SJani Nikula {
342e3adffe8SJani Nikula /*
343e3adffe8SJani Nikula * The system is "ok", just about surviving for the user, but
344e3adffe8SJani Nikula * CI results are now unreliable as the HW is very suspect.
345e3adffe8SJani Nikula * CI checks the taint state after every test and will reboot
346e3adffe8SJani Nikula * the machine if the kernel is tainted.
347e3adffe8SJani Nikula */
348e3adffe8SJani Nikula add_taint(taint, LOCKDEP_STILL_OK);
349e3adffe8SJani Nikula }
350e3adffe8SJani Nikula
3513a7a92abSChris Wilson void cancel_timer(struct timer_list *t);
3523a7a92abSChris Wilson void set_timer_ms(struct timer_list *t, unsigned long timeout);
3533a7a92abSChris Wilson
timer_active(const struct timer_list * t)354c185a16eSChris Wilson static inline bool timer_active(const struct timer_list *t)
355c185a16eSChris Wilson {
356c185a16eSChris Wilson return READ_ONCE(t->expires);
357c185a16eSChris Wilson }
358c185a16eSChris Wilson
timer_expired(const struct timer_list * t)3593a7a92abSChris Wilson static inline bool timer_expired(const struct timer_list *t)
3603a7a92abSChris Wilson {
361c185a16eSChris Wilson return timer_active(t) && !timer_pending(t);
3623a7a92abSChris Wilson }
3633a7a92abSChris Wilson
i915_run_as_guest(void)364a7f46d5bSTvrtko Ursulin static inline bool i915_run_as_guest(void)
365a7f46d5bSTvrtko Ursulin {
366c900a670SCasey Bowman #if IS_ENABLED(CONFIG_X86)
367a7f46d5bSTvrtko Ursulin return !hypervisor_is_type(X86_HYPER_NATIVE);
368c900a670SCasey Bowman #else
369c900a670SCasey Bowman /* Not supported yet */
370c900a670SCasey Bowman return false;
371c900a670SCasey Bowman #endif
372a7f46d5bSTvrtko Ursulin }
373a7f46d5bSTvrtko Ursulin
374a7f46d5bSTvrtko Ursulin bool i915_vtd_active(struct drm_i915_private *i915);
375a7f46d5bSTvrtko Ursulin
376c08c3641SVille Syrjälä bool i915_direct_stolen_access(struct drm_i915_private *i915);
377c08c3641SVille Syrjälä
37840b326eeSChris Wilson #endif /* !__I915_UTILS_H */
379