1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 #ifndef _DRVLIST_H
79 #define _DRVLIST_H
80
81 #include "MsTypes.h"
82
83 /* list structure definition */
84 struct list_head {
85 struct list_head *next;
86 struct list_head *prev;
87 };
88
89 #define DECLARE_LIST(mylist) \
90 struct list_head mylist = { &(mylist), &(mylist) }
91
92 /**
93 * @brief Initial list structure data member
94 *
95 * @param pInitList pointer of the list to be initialized.
96 *
97 * @return None
98 */
ms_list_init(struct list_head * pInitList)99 static __inline__ void ms_list_init (struct list_head *pInitList)
100 {
101 pInitList->next = pInitList;
102 pInitList->prev = pInitList;
103 }
104
105 /**
106 * @brief Insert list after the specified list
107 *
108 * @param pNew New list to be added.
109 *
110 * @param pInsert_after_it Insert list after this list.
111 *
112 * @return None
113 */
ms_insert_list_after(struct list_head * pNew,struct list_head * pInsert_after_it)114 static __inline__ void ms_insert_list_after( struct list_head *pNew, struct list_head *pInsert_after_it )
115 {
116 struct list_head *next;
117 next = pInsert_after_it->next;
118 pInsert_after_it->next = pNew;
119 pNew->next = next;
120 pNew->prev = pInsert_after_it;
121 next->prev = pNew;
122 }
123
124 /**
125 * @brief check if is empty list
126 *
127 * @param pList list to be checked.
128 *
129 * @return boolean
130 */
ms_is_empty_list(struct list_head * pList)131 static __inline__ int ms_is_empty_list( struct list_head *pList )
132 {
133 if (pList == pList->next)
134 return TRUE;
135 else
136 return FALSE;
137 }
138
139 /**
140 * @brief Insert list before the specified list
141 *
142 * @param pNew New list to be added.
143 *
144 * @param pInsert_before_it Insert list before this list.
145 *
146 * @return None
147 */
ms_insert_list_before(struct list_head * pNew,struct list_head * pInsert_before_it)148 static __inline__ void ms_insert_list_before( struct list_head *pNew, struct list_head *pInsert_before_it )
149 {
150 struct list_head *prev;
151 prev = pInsert_before_it->prev;
152 pNew->prev = prev;
153 pNew->next = pInsert_before_it;
154 pInsert_before_it->prev = pNew;
155 prev->next = pNew;
156 }
157
158 /**
159 * @brief Remove current entry from list
160 *
161 * @param pNew Current entry to be removed.
162 *
163 * @return None
164 */
ms_list_remove(struct list_head * pList)165 static __inline__ void ms_list_remove( struct list_head *pList )
166 {
167 pList->prev->next = pList->next;
168 pList->next->prev = pList->prev;
169 }
170
171 /**
172 * @brief Remove current entry from list and initial the entry
173 *
174 * @param pEntry Current entry to be removed.
175 *
176 * @return None
177 */
ms_list_remove_and_init(struct list_head * pEntry)178 static __inline__ void ms_list_remove_and_init(struct list_head *pEntry)
179 {
180 ms_list_remove(pEntry);
181 ms_list_init(pEntry);
182 }
183
184 /**
185 * @brief Join lists.
186 *
187 * @param pList The list to be added.
188 *
189 * @param pHead The place
190 *
191 * @return None
192 */
ms_list_join(struct list_head * pList,struct list_head * pHead)193 static __inline__ void ms_list_join(struct list_head *pList, struct list_head *pHead)
194 {
195 struct list_head *pFirst = pList->next;
196 struct list_head *pLast = pList->prev;
197 struct list_head *pNext = pHead->next;
198
199 pFirst->prev = pHead;
200 pHead->next = pFirst;
201
202 pLast->next = pNext;
203 pNext->prev = pLast;
204 }
205
206 /**
207 * @brief cast a member item to the container structure.
208 *
209 * @param _item_ member item pointer.
210 *
211 * @param _struct_ The type definition of the container structure
212 *
213 * @param _member_ The name of the _item_ in the structure _struct_
214 *
215 * @return the container structure pointer
216 */
217 #define entry_to_container( _item_, _struct_, _member_ ) \
218 ((_struct_ *)((char *)(_item_)-(char *)(offsetof(_struct_,_member_))))
219
220 #define list_for_loop( _item_, _list_ ) \
221 for ( (_item_)=(_list_)->next; (_item_)!=(_list_); (_item_)=(_item_)->next )
222
223 #define list_for_each_entry(_list_, _head_, _item_) \
224 for ((_list_) = entry_to_container((_head_)->next, typeof(*_list_), _item_); \
225 &((_list_)->_item_) != (_head_); \
226 (_list_) = entry_to_container((_list_)->_item_.next, typeof(*_list_), _item_))
227
228 #define list_for_loop_ex(_item_, _temp_, _list_) \
229 for (_item_=(_list_)->next, _temp_=_item_->next; _item_!=(_list_); _item_=_temp_, _temp_=_item_->next)
230
231 #if 0
232 #define list_for_each_prev(_item_, _list_) \
233 or (_item_ = (_list_)->prev; _item_ != (_list_); _item_ = _item_->prev)
234 #endif
235
236 #define INIT_LIST_HEAD( _list_ ) ms_list_init( _list_)
237 #define list_add( _newlist_, _list_add_after_ ) ms_insert_list_after( _newlist_, _list_add_after_ )
238 #define list_empty( _list_ ) ms_is_empty_list( _list_)
239 #define list_add_tail( _newlist_, _list_add_before_ ) ms_insert_list_before( _newlist_, _list_add_before_ )
240 #define list_del( _list_ ) ms_list_remove( _list_)
241 #define list_del_init( _list_ ) ms_list_remove_and_init( _list_)
242 #define __list_splice( _list_, _head_ ) ms_list_join( _list_, _head_ )
243 #define list_entry( _list_, _struct_, _member_ ) entry_to_container( _list_, _struct_, _member_ )
244 #define list_for_each_safe(_item_, _temp_, _list_) list_for_loop_ex(_item_, _temp_, _list_)
245 #define list_for_each( _item_, _list_ ) list_for_loop( _item_, _list_ )
246
247 #endif
248
249
250