mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-23 01:31:30 +03:00
- dce-os-worker.c/.h module exposes functionality which allows
DCE KMD clients to wait/signal events.
- The current abstraction of this module has following drawbacks
which this change attempts to address:
* Name: dce-os-worker is a misnomer
- Rename to dce-wait-cond.c/.h and make it a dce-kmd core file.
- Rename functions accordingly.
* dce-os-worker module initializes data structures from tegra_dce
which makes it ineligible for re-use.
- dce-client-ipc can re-use this module as it uses exact
same functionality.
- But this module is tied with DCE-KMD core such that it has
functions that operate on fixed known inputs.
- dce_os_work_cond_sw_resource_init/deinit()
Inits/Deinits most but not all condition var resources
from tegra_dce. Eg. dce-client-ipc resources
are not initialized.
- Move this function to new core file:dce-waiters.c
- All other functions require msg_id as input and can only
operate on DCE_WAIT* resources making it ineligible
to be used by other clients like dce-client-ipc.
- Refactor these fucntions to operate on
individual wait conditions so that all DCE-KMD
core modules can reuse them.
- Additionally, this change will also remove unused functions
and macros from dce-os-cond.c/.h
- dce-client-ipc will also switch to use dce-wait-cond interface
for client ipc waits.
- Make dce-os-cond.h a common file and move OS specific impl
to dce-os-cond-internal.h
JIRA TDS-16581
Change-Id: Ie8c6ec724e48cde66917fab4aa43e7da464ef8fb
Signed-off-by: anupamg <anupamg@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3258562
Reviewed-by: Vinod Gopalakrishnakurup <vinodg@nvidia.com>
Reviewed-by: Arun Swain <arswain@nvidia.com>
157 lines
4.2 KiB
C
157 lines
4.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* SPDX-FileCopyrightText: Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
*/
|
|
|
|
#include <dce-os-cond.h>
|
|
#include <dce-wait-cond.h>
|
|
#include <dce-os-utils.h>
|
|
#include <dce-os-log.h>
|
|
#include <dce.h>
|
|
|
|
/*
|
|
* dce_wait_cond_wait_interruptible : Wait for a given condition
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to init.
|
|
* @reset : Boolean input to indicate if to reset condition.
|
|
* If reset is set to true, clear wait->complete as soon as we exit from wait (consume wake).
|
|
* Client can use this, if they want the next dce_wait_cond_wait_interruptible call to
|
|
* not see the old wait->complete state.
|
|
* @timeout_ms : Wait timeout in ms. 0 for no timeout.
|
|
*
|
|
* Return : 0 if successful, -ETIMEOUT on timeout, -ERESTARTSYS on interrupt.
|
|
* -EINVAL if invalid input args.
|
|
*
|
|
* Note: Since multiple clients wait on a broadcast event, the user is responsible
|
|
* to reset the condition only when all clients have consumed the call.
|
|
*/
|
|
int dce_wait_cond_wait_interruptible(struct tegra_dce *d, struct dce_wait_cond *wait,
|
|
bool reset, u32 timeout_ms)
|
|
{
|
|
int ret = 0;
|
|
|
|
DCE_WARN_ON_NULL(d);
|
|
|
|
if (timeout_ms == 0) {
|
|
ret = DCE_OS_COND_WAIT_INTERRUPTIBLE(&wait->cond_wait,
|
|
dce_os_atomic_read(&wait->complete) == 1);
|
|
} else {
|
|
ret = DCE_OS_COND_WAIT_INTERRUPTIBLE_TIMEOUT(&wait->cond_wait,
|
|
dce_os_atomic_read(&wait->complete) == 1,
|
|
timeout_ms);
|
|
/**
|
|
* DCE_OS_COND_WAIT_INTERRUPTIBLE_TIMEOUT returns remaining jiffies
|
|
* if condition was evaluated to true before timeout.
|
|
* Set return value to SUCCESS in this case.
|
|
*/
|
|
if (ret > 0)
|
|
ret = 0;
|
|
}
|
|
|
|
/* Skip reset if interrupted by a signal or any other error. */
|
|
if ((ret == 0) && reset)
|
|
dce_os_atomic_set(&wait->complete, 0);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* dce_wait_cond_signal_interruptible : Wakeup waiting task on given condition
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to init.
|
|
*
|
|
* Return : void
|
|
*/
|
|
void dce_wait_cond_signal_interruptible(struct tegra_dce *d, struct dce_wait_cond *wait)
|
|
{
|
|
DCE_WARN_ON_NULL(d);
|
|
|
|
/*
|
|
* Set wait->complete to "1", so if the wait is called even after
|
|
* "dce_os_cond_signal_interruptible", it'll see the complete variable
|
|
* as "1" and exit the wait immediately.
|
|
*/
|
|
dce_os_atomic_set(&wait->complete, 1);
|
|
dce_os_cond_signal_interruptible(&wait->cond_wait);
|
|
}
|
|
|
|
/*
|
|
* dce_wait_cond_reset : reset condition wait variable to zero
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to init.
|
|
*
|
|
* Return : void
|
|
*/
|
|
void dce_wait_cond_reset(struct tegra_dce *d, struct dce_wait_cond *wait)
|
|
{
|
|
DCE_WARN_ON_NULL(d);
|
|
|
|
dce_os_atomic_set(&wait->complete, 0);
|
|
}
|
|
|
|
/**
|
|
* dce_wait_cond_init : Init DCE OS wait condition
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to init.
|
|
*
|
|
* Return : 0 if successful else error code
|
|
*/
|
|
int dce_wait_cond_init(struct tegra_dce *d, struct dce_wait_cond *wait)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (dce_os_cond_init(&wait->cond_wait)) {
|
|
dce_os_err(d, "dce boot wait condition init failed");
|
|
ret = -1;
|
|
goto fail;
|
|
}
|
|
|
|
dce_os_atomic_set(&wait->complete, 0);
|
|
|
|
fail:
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* dce_wait_cond_deinit : de-init dce workqueues related resources
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to init.
|
|
*
|
|
* Return : void
|
|
*/
|
|
void dce_wait_cond_deinit(struct tegra_dce *d, struct dce_wait_cond *wait)
|
|
{
|
|
DCE_WARN_ON_NULL(d);
|
|
|
|
dce_os_atomic_set(&wait->complete, 0);
|
|
dce_os_cond_destroy(&wait->cond_wait);
|
|
}
|
|
|
|
/**
|
|
* dce_wait_cond_broadcast_interruptible - Signal all waiters of a condition
|
|
* variable
|
|
*
|
|
* @d : Pointer to tegra_dce struct.
|
|
* @wait : DCE OS wait condition to signal.
|
|
*
|
|
* Wake up all waiters for a condition variable.
|
|
*
|
|
* The waiters are using an interruptible wait.
|
|
*/
|
|
void dce_wait_cond_broadcast_interruptible(struct tegra_dce *d, struct dce_wait_cond *wait)
|
|
{
|
|
DCE_WARN_ON_NULL(d);
|
|
/*
|
|
* Set wait->complete to "1", so if the wait is called even after
|
|
* "dce_wait_cond_broadcast_interruptible", it'll see the complete variable
|
|
* as "1" and exit the wait immediately.
|
|
*/
|
|
dce_os_atomic_set(&wait->complete, 1);
|
|
dce_os_cond_broadcast_interruptible(&wait->cond_wait);
|
|
}
|