2 * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved.
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.
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.
12 * @file mali_osk_wait_queue.c
13 * Implemenation of the OS abstraction layer for the kernel device driver
16 #include <linux/wait.h>
17 #include <linux/slab.h>
18 #include <linux/sched.h>
21 #include "mali_kernel_common.h"
23 struct _mali_osk_wait_queue_t_struct {
24 wait_queue_head_t wait_queue;
27 _mali_osk_wait_queue_t *_mali_osk_wait_queue_init(void)
29 _mali_osk_wait_queue_t *ret = NULL;
31 ret = kmalloc(sizeof(_mali_osk_wait_queue_t), GFP_KERNEL);
37 init_waitqueue_head(&ret->wait_queue);
38 MALI_DEBUG_ASSERT(!waitqueue_active(&ret->wait_queue));
43 void _mali_osk_wait_queue_wait_event(_mali_osk_wait_queue_t *queue, mali_bool(*condition)(void *), void *data)
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));
50 void _mali_osk_wait_queue_wait_event_timeout(_mali_osk_wait_queue_t *queue, mali_bool(*condition)(void *), void *data, u32 timeout)
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));
57 void _mali_osk_wait_queue_wake_up(_mali_osk_wait_queue_t *queue)
59 MALI_DEBUG_ASSERT_POINTER(queue);
61 /* if queue is empty, don't attempt to wake up its elements */
62 if (!waitqueue_active(&queue->wait_queue)) return;
64 MALI_DEBUG_PRINT(6, ("Waking up elements in wait queue %p ....\n", queue));
66 wake_up_all(&queue->wait_queue);
68 MALI_DEBUG_PRINT(6, ("... elements in wait queue %p woken up\n", queue));
71 void _mali_osk_wait_queue_term(_mali_osk_wait_queue_t *queue)
73 /* Parameter validation */
74 MALI_DEBUG_ASSERT_POINTER(queue);
76 /* Linux requires no explicit termination of wait queues */