1 /*===============================================================================================*
2 * *
3 * MMMMMMMM MMMMMMM MMMMMMM MMMMMMMM MMMMMMMM MM MM MMMMMMMMMMMMM *
4 * MMM MMM MMM MMM MM MM . MM MMM MM *
5 * MMM MMM MMM MMM MM MM MM MMM MM. *
6 * MMM MMM MMM MMM MM . MM MM MMM MMMM *
7 * MMM MMM MMM MMM MM MMMM MMM MM *
8 * MMMMMMMMMMMM MMM MMM MM MMMM MMMMMMMMMMM *
9 * MMM MMM MMM MMM MM MMMM MMM . *
10 * MMM MMM MMM MMM MM . MM MMM MM *
11 * MMM MMM MMM MMM . MM MMMM MMM MMMM *
12 * MMM MMM MM MM MM MM. MMM MM *
13 * MMM MMM . MM MM. MMMM MM MMM MM *
14 * MMMMMMMM MMMMMMM MM. MMMMM MM MMMM MMMMMMMMMMMMM. *
15 * *
16 *================================================================================================
17 *
18 * usb host module
19 *
20 * Copyright(C), 2006-2008, SoftWinners Co., Ltd.
21 * All Rights Reserved
22 *
23 * File Name :
24 *
25 * Author : GLHuang(HoLiGun)
26 *
27 * Version : 1.0
28 *
29 * Date : 2008.06.12
30 *
31 * Description :
32 * 对list_head的extention
33 * History :
34 *================================================================================================
35 */
36
37 #include "usb_os_platform.h"
38
39 #include "usb_list.h"
40 #include "list_head_ext.h"
41 #include <hal_osal.h>
42
43 hal_spinlock_t list_lock;
44 //从list_header_input中删除某个node
45 //return : 0 //表示找到了改node,且成功删除了
46 //对list的操作有critical保护
47 /*
48 ********************************************************************************
49 * list_head_ext_remov_node_from_list
50 * Description:
51 * 从list_header_input队列中删除值为node_data的node
52 *
53 * Arguments:
54 * node_data : input. 用来寻找node
55 * list_header_input : input. 队列的头
56 * Return value:
57 * 0 : success
58 * !0 : fail
59 * note:
60 * 多个线程可能同时操作这个list, 所以要进临界区关总中断。
61 * 注意 : 这样做可能会影响系统性能
62 *********************************************************************************
63 */
list_head_ext_remov_node_from_list(void * node_data,struct usb_list_head * list_header_input)64 int list_head_ext_remov_node_from_list(void *node_data,
65 struct usb_list_head *list_header_input)
66 {
67 struct usb_list_head *list_start = NULL;
68 struct usb_list_head *list_now = NULL;
69 struct usb_list_head *list_next = NULL;
70 __u32 sr = 0;
71
72 /* check input */
73 if (node_data == NULL || list_header_input == NULL)
74 {
75 hal_log_err("ERR : list_head_ext_remov_node_from_list() input == NULL");
76 return -1;
77 }
78
79 /* list must not empty */
80 if (usb_list_empty(list_header_input))
81 {
82 hal_log_err("ERR : list_head_ext_remov_node_from_list() func_drv->dev_list is empty");
83 return -1 ;
84 }
85
86 //USB_OS_ENTER_CRITICAL(sr);
87 /* 遍历整个list, 寻找要删除的node, 并且删除它 */
88 list_start = list_header_input;
89 list_now = list_start->next;
90
91 while (list_start != list_now)
92 {
93 list_next = list_now->next;
94
95 if (list_now->data == node_data)
96 {
97 list_now->data = NULL;
98 list_head_unlink_and_del(list_now);
99 list_now = NULL;
100 //USB_OS_EXIT_CRITICAL(sr);
101 return 0;
102 }
103
104 list_now = list_next;
105 }
106
107 //USB_OS_EXIT_CRITICAL(sr);
108 return -1;
109 }
110
111
112 /*
113 ********************************************************************************
114 * list_node_exist
115 * Description:
116 * 判断list中是否存在值为data的node
117 *
118 * Arguments:
119 * node_data : input.
120 * list_header_input : input.
121 * Return value:
122 * 0 : success
123 * !0 : fail
124 * note:
125 *
126 *********************************************************************************
127 */
list_node_exist(void * data,struct usb_list_head * list_head)128 s32 list_node_exist(void *data, struct usb_list_head *list_head)
129 {
130 struct usb_list_head *list_start = NULL;
131 struct usb_list_head *list_now = NULL;
132 __u32 cup_sr = 0;
133
134 /* check input */
135 if (data == NULL || list_head == NULL)
136 {
137 hal_log_err("ERR : list_node_exist: input == NULL");
138 return -1;
139 }
140
141 //USB_OS_ENTER_CRITICAL(cup_sr);
142 hal_spin_lock(&list_lock);
143 /* 遍历整个list, 寻找值为data的node */
144 list_start = list_head;
145 list_now = list_start->next;
146
147 while (list_now != list_start)
148 {
149 if (list_now->data == data)
150 {
151 //USB_OS_EXIT_CRITICAL(cup_sr);
152 hal_spin_unlock(&list_lock);
153 return 0;
154 }
155
156 list_now = list_now->next;
157 }
158
159 //USB_OS_EXIT_CRITICAL(cup_sr);
160 hal_spin_unlock(&list_lock);
161 return -1;
162 }
163
164 /*
165 *****************************************************************************
166 * del_node_from_list
167 *
168 * Description:
169 * 遍历整个list, 删除带有data内容的所有node
170 * Arguments:
171 *
172 * Returns:
173 *
174 * note:
175 *
176 *
177 *****************************************************************************
178 */
list_del_node_by_data(void * data,struct usb_list_head * list)179 s32 list_del_node_by_data(void *data, struct usb_list_head *list)
180 {
181 struct usb_list_head *list_now = NULL;
182 struct usb_list_head *list_next = NULL;
183 u32 is_find = 0;
184 __u32 cup_sr = 0;
185
186 if (data == NULL || list == NULL)
187 {
188 hal_log_err("ERR: list_del_node_by_data: input == NULL");
189 return -1;
190 }
191
192 if (usb_list_empty(list))
193 {
194 hal_log_err("ERR: list_del_node_by_data: list is already empty");
195 return -1;
196 }
197
198 //USB_OS_ENTER_CRITICAL(cup_sr);
199 hal_spin_lock(&list_lock);
200 list_now = list->next;
201 list_next = NULL;
202
203 //遇到链表头就退出
204 while (list_now != list)
205 {
206 list_next = list_now->next;
207
208 //--<1>--找到req就将其从链表中删除
209 if (list_now->data == data)
210 {
211 /* 将其从链表中取出来 */
212 usb_list_del_init(list_now);
213 /* 释放list结构 */
214 _usb_list_head_free(list_now);
215 list_now = NULL;
216 is_find = 1;
217 }
218
219 list_now = list_next;
220 }
221
222 //USB_OS_EXIT_CRITICAL(cup_sr);
223 hal_spin_unlock(&list_lock);
224
225 if (is_find)
226 {
227 return 0;
228 }
229 else
230 {
231 //hal_log_err("ERR: list_del_node_by_data: del failed");
232 return -1;
233 }
234 }
235
236 /*
237 *****************************************************************************
238 * list_destroy_whole_list
239 *
240 * Description:
241 * 删除 list 里所有的node, 并且释放其资源
242 * Arguments:
243 *
244 * Returns:
245 *
246 * note:
247 *
248 *
249 *****************************************************************************
250 */
list_destroy_whole_list(struct usb_list_head * list)251 s32 list_destroy_whole_list(struct usb_list_head *list)
252 {
253 struct usb_list_head *list_now = NULL;
254 struct usb_list_head *list_next = NULL;
255 __u32 cup_sr = 0;
256
257 if (list == NULL)
258 {
259 hal_log_err("ERR: input == NULL");
260 return -1;
261 }
262
263 if (usb_list_empty(list))
264 {
265 hal_log_err("ERR: list is already empty");
266 return -1;
267 }
268
269 //USB_OS_ENTER_CRITICAL(cup_sr);
270 hal_spin_lock(&list_lock);
271 list_now = list->next;
272 list_next = NULL;
273
274 //遇到链表头就退出
275 while (list_now != list)
276 {
277 //--<1>--预先取得下一个node
278 list_next = list_now->next;
279 //--<2>--删除当前node, 并且释放其资源
280 usb_list_del_init(list_now);
281 _usb_list_head_free(list_now);
282 list_now = NULL;
283 //--<3>--取得下一个node
284 list_now = list_next;
285 }
286
287 //USB_OS_EXIT_CRITICAL(cup_sr);
288 hal_spin_unlock(&list_lock);
289 return 0;
290 }
291
292
293
294
295