mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c
drm_timeout_abs_to_jiffies() began as a static helper inside the syncobj wait implementation and was later exported in place, so that it could be called by multiple drivers (e.g. panfrost, lima, tegra and accel drivers). All of them reach it through drm_utils.h. Give it a file of its own, so that timeout conversion helpers have a home, which will be useful when we add new timeout handlers. Also create a drm_timeout.h header to host all timeout-related helpers. The function was moved to the new file as it is, including the use of "signed long" as the return type. Note that the return and parameters types should be reconsidered in the future to better represent the non-negative nature of a timeout. No functional change. Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patch.msgid.link/20260915-drm-timeout-helpers-v3-1-f2ae987d861f@igalia.com Signed-off-by: Maíra Canal <mcanal@igalia.com>
This commit is contained in:
parent
37b346eab2
commit
ae72b9c39d
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
#include <drm/drm_drv.h>
|
||||
#include <drm/drm_ioctl.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_gem.h>
|
||||
#include <drm/drm_accel.h>
|
||||
#include <drm/drm_managed.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
#include <drm/ethosu_accel.h>
|
||||
|
||||
#include "ethosu_drv.h"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <drm/drm_cache.h>
|
||||
#include <drm/drm_debugfs.h>
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
#include "ivpu_drv.h"
|
||||
#include "ivpu_fw.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <drm/drm_device.h>
|
||||
#include <drm/drm_print.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
#include <drm/rocket_accel.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/iommu.h>
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ drm-y := \
|
|||
drm_rect.o \
|
||||
drm_syncobj.o \
|
||||
drm_sysfs.o \
|
||||
drm_timeout.o \
|
||||
drm_trace_points.o \
|
||||
drm_vblank.o \
|
||||
drm_vblank_work.o \
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@
|
|||
#include <drm/drm_gem.h>
|
||||
#include <drm/drm_print.h>
|
||||
#include <drm/drm_syncobj.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
#include "drm_internal.h"
|
||||
|
||||
|
|
@ -1193,39 +1193,6 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
|
|||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
|
||||
*
|
||||
* @timeout_nsec: timeout nsec component in ns, 0 for poll
|
||||
*
|
||||
* Calculate the timeout in jiffies from an absolute time in sec/nsec.
|
||||
*/
|
||||
signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
|
||||
{
|
||||
ktime_t abs_timeout, now;
|
||||
u64 timeout_ns, timeout_jiffies64;
|
||||
|
||||
/* make 0 timeout means poll - absolute 0 doesn't seem valid */
|
||||
if (timeout_nsec == 0)
|
||||
return 0;
|
||||
|
||||
abs_timeout = ns_to_ktime(timeout_nsec);
|
||||
now = ktime_get();
|
||||
|
||||
if (!ktime_after(abs_timeout, now))
|
||||
return 0;
|
||||
|
||||
timeout_ns = ktime_to_ns(ktime_sub(abs_timeout, now));
|
||||
|
||||
timeout_jiffies64 = nsecs_to_jiffies64(timeout_ns);
|
||||
/* clamp timeout to avoid infinite timeout */
|
||||
if (timeout_jiffies64 >= MAX_SCHEDULE_TIMEOUT - 1)
|
||||
return MAX_SCHEDULE_TIMEOUT - 1;
|
||||
|
||||
return timeout_jiffies64 + 1;
|
||||
}
|
||||
EXPORT_SYMBOL(drm_timeout_abs_to_jiffies);
|
||||
|
||||
static int drm_syncobj_array_wait(struct drm_device *dev,
|
||||
struct drm_file *file_private,
|
||||
struct drm_syncobj_wait *wait,
|
||||
|
|
|
|||
50
drivers/gpu/drm/drm_timeout.c
Normal file
50
drivers/gpu/drm/drm_timeout.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
/*
|
||||
* Timeout conversion helpers for wait ioctls.
|
||||
*
|
||||
* Copyright 2017 Red Hat
|
||||
* Copyright 2016 Advanced Micro Devices, Inc.
|
||||
*/
|
||||
|
||||
#include <linux/export.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/ktime.h>
|
||||
#include <linux/sched.h>
|
||||
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
/**
|
||||
* drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
|
||||
* @timeout_nsec: timeout nsec component in ns, 0 for poll
|
||||
*
|
||||
* Calculate the timeout in jiffies from an absolute time in ns. The result is
|
||||
* clamped to MAX_SCHEDULE_TIMEOUT - 1 to avoid infinite timeouts.
|
||||
*
|
||||
* Returns:
|
||||
* The number of jiffies until the given timeout, or the upper limit.
|
||||
*/
|
||||
signed long drm_timeout_abs_to_jiffies(s64 timeout_nsec)
|
||||
{
|
||||
ktime_t abs_timeout, now;
|
||||
u64 timeout_ns, timeout_jiffies64;
|
||||
|
||||
/* make 0 timeout means poll - absolute 0 doesn't seem valid */
|
||||
if (timeout_nsec == 0)
|
||||
return 0;
|
||||
|
||||
abs_timeout = ns_to_ktime(timeout_nsec);
|
||||
now = ktime_get();
|
||||
|
||||
if (!ktime_after(abs_timeout, now))
|
||||
return 0;
|
||||
|
||||
timeout_ns = ktime_to_ns(ktime_sub(abs_timeout, now));
|
||||
|
||||
timeout_jiffies64 = nsecs_to_jiffies64(timeout_ns);
|
||||
/* clamp timeout to avoid infinite timeout */
|
||||
if (timeout_jiffies64 >= MAX_SCHEDULE_TIMEOUT - 1)
|
||||
return MAX_SCHEDULE_TIMEOUT - 1;
|
||||
|
||||
return timeout_jiffies64 + 1;
|
||||
}
|
||||
EXPORT_SYMBOL(drm_timeout_abs_to_jiffies);
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_syncobj.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
#include <drm/lima_drm.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#include <drm/drm_ioctl.h>
|
||||
#include <drm/drm_print.h>
|
||||
#include <drm/drm_syncobj.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
#include "panfrost_device.h"
|
||||
#include "panfrost_drv.h"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <drm/drm_drv.h>
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
|
||||
#include "drm.h"
|
||||
#include "uapi.h"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <drm/drm_device.h>
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_utils.h>
|
||||
#include <drm/drm_timeout.h>
|
||||
#include <uapi/drm/xe_drm.h>
|
||||
|
||||
#include "xe_device.h"
|
||||
|
|
|
|||
16
include/drm/drm_timeout.h
Normal file
16
include/drm/drm_timeout.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Function prototypes for timeout conversion helpers for wait ioctls.
|
||||
*
|
||||
* Copyright 2017 Red Hat
|
||||
* Copyright 2016 Advanced Micro Devices, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __DRM_TIMEOUT_H__
|
||||
#define __DRM_TIMEOUT_H__
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
signed long drm_timeout_abs_to_jiffies(s64 timeout_nsec);
|
||||
|
||||
#endif
|
||||
|
|
@ -25,6 +25,4 @@ struct drm_panel_backlight_quirk {
|
|||
const struct drm_panel_backlight_quirk *
|
||||
drm_get_panel_backlight_quirk(const struct drm_edid *edid);
|
||||
|
||||
signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user