Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* |
2 | * This confidential and proprietary software may be used only as | |
3 | * authorised by a licensing agreement from ARM Limited | |
4 | * (C) COPYRIGHT 2012-2013 ARM Limited | |
5 | * ALL RIGHTS RESERVED | |
6 | * The entire notice above must be reproduced on all authorised | |
7 | * copies and copies may only be made to the extent permitted | |
8 | * by a licensing agreement from ARM Limited. | |
9 | */ | |
10 | ||
11 | /** | |
12 | * @file mali_osk_wait_queue.c | |
13 | * Implemenation of the OS abstraction layer for the kernel device driver | |
14 | */ | |
15 | ||
16 | #include <linux/wait.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/sched.h> | |
19 | ||
20 | #include "mali_osk.h" | |
21 | #include "mali_kernel_common.h" | |
22 | ||
23 | struct _mali_osk_wait_queue_t_struct { | |
24 | wait_queue_head_t wait_queue; | |
25 | }; | |
26 | ||
27 | _mali_osk_wait_queue_t* _mali_osk_wait_queue_init( void ) | |
28 | { | |
29 | _mali_osk_wait_queue_t* ret = NULL; | |
30 | ||
31 | ret = kmalloc(sizeof(_mali_osk_wait_queue_t), GFP_KERNEL); | |
32 | ||
33 | if (NULL == ret) { | |
34 | return ret; | |
35 | } | |
36 | ||
37 | init_waitqueue_head(&ret->wait_queue); | |
38 | MALI_DEBUG_ASSERT(!waitqueue_active(&ret->wait_queue)); | |
39 | ||
40 | return ret; | |
41 | } | |
42 | ||
43 | void _mali_osk_wait_queue_wait_event( _mali_osk_wait_queue_t *queue, mali_bool (*condition)(void *), void *data ) | |
44 | { | |
45 | MALI_DEBUG_ASSERT_POINTER( queue ); | |
46 | MALI_DEBUG_PRINT(6, ("Adding to wait queue %p\n", queue)); | |
47 | wait_event(queue->wait_queue, condition(data)); | |
48 | } | |
49 | ||
50 | void _mali_osk_wait_queue_wait_event_timeout( _mali_osk_wait_queue_t *queue, mali_bool (*condition)(void *), void *data, u32 timeout ) | |
51 | { | |
52 | MALI_DEBUG_ASSERT_POINTER( queue ); | |
53 | MALI_DEBUG_PRINT(6, ("Adding to wait queue %p\n", queue)); | |
54 | wait_event_timeout(queue->wait_queue, condition(data), _mali_osk_time_mstoticks(timeout)); | |
55 | } | |
56 | ||
57 | void _mali_osk_wait_queue_wake_up( _mali_osk_wait_queue_t *queue ) | |
58 | { | |
59 | MALI_DEBUG_ASSERT_POINTER( queue ); | |
60 | ||
61 | /* if queue is empty, don't attempt to wake up its elements */ | |
62 | if (!waitqueue_active(&queue->wait_queue)) return; | |
63 | ||
64 | MALI_DEBUG_PRINT(6, ("Waking up elements in wait queue %p ....\n", queue)); | |
65 | ||
66 | wake_up_all(&queue->wait_queue); | |
67 | ||
68 | MALI_DEBUG_PRINT(6, ("... elements in wait queue %p woken up\n", queue)); | |
69 | } | |
70 | ||
71 | void _mali_osk_wait_queue_term( _mali_osk_wait_queue_t *queue ) | |
72 | { | |
73 | /* Parameter validation */ | |
74 | MALI_DEBUG_ASSERT_POINTER( queue ); | |
75 | ||
76 | /* Linux requires no explicit termination of wait queues */ | |
77 | kfree(queue); | |
78 | } |