-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the call queue handling logic off to a new file to allow for its use in other translation units cleanly. Signed-off-by: Hernan Gatta <[email protected]> Acked-by: Etienne Carriere <[email protected]> [etienne: picked commit from linaro-swg/linux#72] Signed-off-by: Etienne Carriere <[email protected]> Change-Id: Ifbd281a8be32921d8273ba8683c53d5b19334b66
- Loading branch information
1 parent
0cca4d0
commit 2aa2627
Showing
4 changed files
with
100 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (c) 2015, Linaro Limited | ||
*/ | ||
|
||
#include "optee_private.h" | ||
|
||
void optee_cq_wait_init(struct optee_call_queue *cq, | ||
struct optee_call_waiter *w) | ||
{ | ||
/* | ||
* We're preparing to make a call to secure world. In case we can't | ||
* allocate a thread in secure world we'll end up waiting in | ||
* optee_cq_wait_for_completion(). | ||
* | ||
* Normally if there's no contention in secure world the call will | ||
* complete and we can cleanup directly with optee_cq_wait_final(). | ||
*/ | ||
mutex_lock(&cq->mutex); | ||
|
||
/* | ||
* We add ourselves to the queue, but we don't wait. This | ||
* guarantees that we don't lose a completion if secure world | ||
* returns busy and another thread just exited and try to complete | ||
* someone. | ||
*/ | ||
init_completion(&w->c); | ||
list_add_tail(&w->list_node, &cq->waiters); | ||
|
||
mutex_unlock(&cq->mutex); | ||
} | ||
|
||
void optee_cq_wait_for_completion(struct optee_call_queue *cq, | ||
struct optee_call_waiter *w) | ||
{ | ||
wait_for_completion(&w->c); | ||
|
||
mutex_lock(&cq->mutex); | ||
|
||
/* Move to end of list to get out of the way for other waiters */ | ||
list_del(&w->list_node); | ||
reinit_completion(&w->c); | ||
list_add_tail(&w->list_node, &cq->waiters); | ||
|
||
mutex_unlock(&cq->mutex); | ||
} | ||
|
||
void optee_cq_complete_one(struct optee_call_queue *cq) | ||
{ | ||
struct optee_call_waiter *w; | ||
|
||
list_for_each_entry(w, &cq->waiters, list_node) { | ||
if (!completion_done(&w->c)) { | ||
complete(&w->c); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void optee_cq_wait_final(struct optee_call_queue *cq, | ||
struct optee_call_waiter *w) | ||
{ | ||
/* | ||
* We're done with the call to secure world. The thread in secure | ||
* world that was used for this call is now available for some | ||
* other task to use. | ||
*/ | ||
mutex_lock(&cq->mutex); | ||
|
||
/* Get out of the list */ | ||
list_del(&w->list_node); | ||
|
||
/* Wake up one eventual waiting task */ | ||
optee_cq_complete_one(cq); | ||
|
||
/* | ||
* If we're completed we've got a completion from another task that | ||
* was just done with its call to secure world. Since yet another | ||
* thread now is available in secure world wake up another eventual | ||
* waiting task. | ||
*/ | ||
if (completion_done(&w->c)) | ||
optee_cq_complete_one(cq); | ||
|
||
mutex_unlock(&cq->mutex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters