From a94b4bcde9b88e856d4b6f2bcb9e0e23942a69cc Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Tue, 21 Feb 2017 18:01:12 -0800 Subject: gpu: nvgpu: Abstraction for *sleep, *delay Add abstractions for the following: msleep() udelay() usleep_range() These functions are only a subset of the available Linux delay and sleep functions but this seems to be what we use and what is actually useful for driver development. Bug 1799159 Jira NVGPU-16 Change-Id: I1a25b66314f365432f2f0a5ff1b3a0a5689fc047 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1309087 Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Seema Khowala Reviewed-by: David Martinez Nieto Reviewed-by: Terje Bergstrom Tested-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/linux/timers.c | 52 ++++++++++++++++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/timers.h | 8 +++++ 2 files changed, 60 insertions(+) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/timers.c b/drivers/gpu/nvgpu/common/linux/timers.c index 5c4f0fb1..07eb357a 100644 --- a/drivers/gpu/nvgpu/common/linux/timers.c +++ b/drivers/gpu/nvgpu/common/linux/timers.c @@ -15,6 +15,7 @@ */ #include +#include #include @@ -175,3 +176,54 @@ int nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout) else return time_after(jiffies, (unsigned long)timeout->time); } + +/** + * nvgpu_udelay - Delay for some number of microseconds. + * + * @usecs - Microseconds to wait for. + * + * Wait for at least @usecs microseconds. This is not guaranteed to be perfectly + * accurate. This is normally backed by a busy-loop so this means waits should + * be kept short, below 100us. If longer delays are necessary then + * nvgpu_msleep() should be preferred. + * + * Alternatively, on some platforms, nvgpu_usleep_range() is usable. This + * function will attempt to not use a busy-loop. + */ +void nvgpu_udelay(unsigned int usecs) +{ + udelay(usecs); +} + +/** + * nvgpu_usleep_range - Sleep for a range of microseconds. + * + * @min_us - Minimum wait time. + * @max_us - Maximum wait time. + * + * Wait for some number of microseconds between @min_us and @max_us. This, + * unlike nvgpu_udelay(), will attempt to sleep for the passed number of + * microseconds instead of busy looping. Not all platforms support this, + * and in that case this reduces to nvgpu_udelay(min_us). + * + * Linux note: this is not safe to use in atomic context. If you are in + * atomic context you must use nvgpu_udelay(). + */ +void nvgpu_usleep_range(unsigned int min_us, unsigned int max_us) +{ + usleep_range(min_us, max_us); +} + +/** + * nvgpu_msleep - Sleep for some milliseconds. + * + * @msecs - Sleep for at least this many milliseconds. + * + * Sleep for at least @msecs of milliseconds. For small @msecs (less than 20 ms + * or so) the sleep will be significantly longer due to scheduling overhead and + * mechanics. + */ +void nvgpu_msleep(unsigned int msecs) +{ + msleep(msecs); +} diff --git a/drivers/gpu/nvgpu/include/nvgpu/timers.h b/drivers/gpu/nvgpu/include/nvgpu/timers.h index abf8b736..0aadd0df 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/timers.h +++ b/drivers/gpu/nvgpu/include/nvgpu/timers.h @@ -89,4 +89,12 @@ int nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout); int __nvgpu_timeout_expired_msg(struct nvgpu_timeout *timeout, void *caller, const char *fmt, ...); + +/* + * Waits and delays. + */ +void nvgpu_msleep(unsigned int msecs); +void nvgpu_usleep_range(unsigned int min_us, unsigned int max_us); +void nvgpu_udelay(unsigned int usecs); + #endif -- cgit v1.2.2