xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_osk_wait_queue.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2012-2014, 2016-2017 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 	wait_queue_head_t wait_queue;
25 };
26 
_mali_osk_wait_queue_init(void)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 
_mali_osk_wait_queue_wait_event(_mali_osk_wait_queue_t * queue,mali_bool (* condition)(void *),void * data)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 
_mali_osk_wait_queue_wait_event_timeout(_mali_osk_wait_queue_t * queue,mali_bool (* condition)(void *),void * data,u32 timeout)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 
_mali_osk_wait_queue_wake_up(_mali_osk_wait_queue_t * queue)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 
_mali_osk_wait_queue_term(_mali_osk_wait_queue_t * queue)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 }
79