-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkcl_wait.c
133 lines (115 loc) · 4.03 KB
/
kcl_wait.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/****************************************************************************
* *
* Copyright 1999-2005 ATI Technologies Inc., Markham, Ontario, CANADA. *
* All Rights Reserved. *
* *
* Your use and or redistribution of this software in source and \ or *
* binary form, with or without modification, is subject to: (i) your *
* ongoing acceptance of and compliance with the terms and conditions of *
* the ATI Technologies Inc. software End User License Agreement; and (ii) *
* your inclusion of this notice in any version of this software that you *
* use or redistribute. A copy of the ATI Technologies Inc. software End *
* User License Agreement is included with this software and is also *
* available by contacting ATI Technologies Inc. at http://www.ati.com *
* *
****************************************************************************/
/** \brief KCL WAIT interface implementation
*
* CONVENTIONS
*
* Public symbols:
* - prefixed with KCL_WAIT
* - are not static
* - declared in the corresponding header
*
* Private symbols:
* - prefixed with kcl
* - are static
* - not declared in the corresponding header
*
*/
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
#include <generated/autoconf.h>
#else
#include <linux/autoconf.h>
#endif
#include <linux/wait.h>
#include <linux/highmem.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include "kcl_config.h"
#include "kcl_wait.h"
/** \brief Create wait object, init it and add to the kernel queue
** \param object_handle [in] Object handle
** \return Kernel wait handle on success, 0 otherwise
*/
KCL_WAIT_Handle ATI_API_CALL KCL_WAIT_Add(KCL_WAIT_ObjectHandle object_handle)
{
wait_queue_t* wait_handle = kmalloc(sizeof(wait_queue_t), GFP_KERNEL);
if (!wait_handle)
{
return 0;
}
init_waitqueue_entry(wait_handle, current);
add_wait_queue((wait_queue_head_t*)object_handle, wait_handle);
return (KCL_WAIT_Handle)wait_handle;
}
/** \brief Create wait object, init it and add to the kernel queue
** \param object_handle [in] Object handle
** \return Kernel wait handle on success, 0 otherwise
*/
KCL_WAIT_Handle ATI_API_CALL KCL_WAIT_Add_Exclusive(KCL_WAIT_ObjectHandle object_handle)
{
wait_queue_t* wait_handle = kmalloc(sizeof(wait_queue_t), GFP_KERNEL);
if (!wait_handle)
{
return 0;
}
init_waitqueue_entry(wait_handle, current);
add_wait_queue_exclusive((wait_queue_head_t*)object_handle, wait_handle);
return (KCL_WAIT_Handle)wait_handle;
}
/** \brief Remove wait object from the kernel queue and destroy it
** \param wait_handle [in] Kernel wait handle
** \param object_handle [in] Object handle
*/
void ATI_API_CALL KCL_WAIT_Remove(KCL_WAIT_Handle wait_handle,
KCL_WAIT_ObjectHandle object_handle)
{
remove_wait_queue((wait_queue_head_t*)object_handle,
(wait_queue_t*)wait_handle);
if (wait_handle)
{
kfree(wait_handle);
}
}
/** \brief Send wake up signal to the wait object
** \param object_handle [in] Object handle
*/
void ATI_API_CALL KCL_WAIT_Wakeup(KCL_WAIT_ObjectHandle object_handle)
{
wake_up_interruptible((wait_queue_head_t*)object_handle);
}
/** \brief Create and init user wait object
** \return Object handle
*/
KCL_WAIT_ObjectHandle ATI_API_CALL KCL_WAIT_CreateObject(void)
{
wait_queue_head_t* wait_object = kmalloc(sizeof(wait_queue_head_t), GFP_ATOMIC);
if (wait_object)
{
init_waitqueue_head(wait_object);
}
return (KCL_WAIT_ObjectHandle)wait_object;
}
/** \brief Destroy user wait object
** \return Object handle
*/
void ATI_API_CALL KCL_WAIT_RemoveObject(KCL_WAIT_ObjectHandle wait_object)
{
if (wait_object)
{
kfree(wait_object);
}
}