tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / linux / mali_osk_wait_queue.c
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 {
25     wait_queue_head_t wait_queue;
26 };
27
28 _mali_osk_wait_queue_t* _mali_osk_wait_queue_init( void )
29 {
30     _mali_osk_wait_queue_t* ret = NULL;
31
32     ret = kmalloc(sizeof(_mali_osk_wait_queue_t), GFP_KERNEL);
33
34     if (NULL == ret)
35     {
36         return ret;
37     }
38
39     init_waitqueue_head(&ret->wait_queue);
40     MALI_DEBUG_ASSERT(!waitqueue_active(&ret->wait_queue));
41
42     return ret;
43 }
44
45 void _mali_osk_wait_queue_wait_event( _mali_osk_wait_queue_t *queue, mali_bool (*condition)(void) )
46 {
47     MALI_DEBUG_ASSERT_POINTER( queue );
48     MALI_DEBUG_PRINT(6, ("Adding to wait queue %p\n", queue));
49     wait_event(queue->wait_queue, condition());
50 }
51
52 void _mali_osk_wait_queue_wake_up( _mali_osk_wait_queue_t *queue )
53 {
54     MALI_DEBUG_ASSERT_POINTER( queue );
55
56     /* if queue is empty, don't attempt to wake up its elements */
57     if (!waitqueue_active(&queue->wait_queue)) return;
58
59     MALI_DEBUG_PRINT(6, ("Waking up elements in wait queue %p ....\n", queue));
60
61     wake_up_all(&queue->wait_queue);
62
63     MALI_DEBUG_PRINT(6, ("... elements in wait queue %p woken up\n", queue));
64 }
65
66 void _mali_osk_wait_queue_term( _mali_osk_wait_queue_t *queue )
67 {
68         /* Parameter validation  */
69         MALI_DEBUG_ASSERT_POINTER( queue );
70
71         /* Linux requires no explicit termination of wait queues */
72     kfree(queue);
73 }