xref: /linux/drivers/gpu/drm/xe/xe_sleep.h (revision 94a2ceb1906d2bcbf2c6afbc5ede400eea3872c8)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2026 Intel Corporation
4  */
5 
6 #ifndef _XE_SLEEP_H_
7 #define _XE_SLEEP_H_
8 
9 #include <linux/delay.h>
10 #include <linux/math64.h>
11 
12 /**
13  * xe_sleep_relaxed_ms() - Sleep for an approximate time.
14  * @delay_ms: time in msec to sleep
15  *
16  * For smaller timeouts, sleep with 0.5ms accuracy.
17  */
18 static inline void xe_sleep_relaxed_ms(unsigned int delay_ms)
19 {
20 	unsigned long min_us, max_us;
21 
22 	if (!delay_ms)
23 		return;
24 
25 	if (delay_ms > 20) {
26 		msleep(delay_ms);
27 		return;
28 	}
29 
30 	min_us = mul_u32_u32(delay_ms, 1000);
31 	max_us = min_us + 500;
32 
33 	usleep_range(min_us, max_us);
34 }
35 
36 #endif
37