x86: unmask CPUID levels on Intel CPUs
[linux-2.6/mini2440.git] / drivers / staging / meilhaus / meslist.c
blob7e8b66c05f7e62635d448757a861cce21b5aeb0c
1 /**
2 * @file me_slist.c
4 * @brief Implements the subdevice list class.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 */
9 /*
10 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "meerror.h"
28 #include "medefines.h"
30 #include "meslist.h"
31 #include "medebug.h"
33 int me_slist_query_number_subdevices(struct me_slist *slist, int *number)
35 PDEBUG_LOCKS("called.\n");
36 *number = slist->n;
37 return ME_ERRNO_SUCCESS;
40 unsigned int me_slist_get_number_subdevices(struct me_slist *slist)
42 PDEBUG_LOCKS("called.\n");
43 return slist->n;
46 me_subdevice_t *me_slist_get_subdevice(struct me_slist * slist,
47 unsigned int index)
50 struct list_head *pos;
51 me_subdevice_t *subdevice = NULL;
52 unsigned int i = 0;
54 PDEBUG_LOCKS("called.\n");
56 if (index >= slist->n) {
57 PERROR("Index out of range.\n");
58 return NULL;
61 list_for_each(pos, &slist->head) {
62 if (i == index) {
63 subdevice = list_entry(pos, me_subdevice_t, list);
64 break;
67 ++i;
70 return subdevice;
73 int me_slist_get_subdevice_by_type(struct me_slist *slist,
74 unsigned int start_subdevice,
75 int type, int subtype, int *subdevice)
77 me_subdevice_t *pos;
78 int s_type, s_subtype;
79 unsigned int index = 0;
81 PDEBUG_LOCKS("called.\n");
83 if (start_subdevice >= slist->n) {
84 PERROR("Start index out of range.\n");
85 return ME_ERRNO_NOMORE_SUBDEVICE_TYPE;
88 list_for_each_entry(pos, &slist->head, list) {
89 if (index < start_subdevice) { // Go forward to start subdevice.
90 ++index;
91 continue;
94 pos->me_subdevice_query_subdevice_type(pos,
95 &s_type, &s_subtype);
97 if (subtype == ME_SUBTYPE_ANY) {
98 if (s_type == type)
99 break;
100 } else {
101 if ((s_type == type) && (s_subtype == subtype))
102 break;
105 ++index;
108 if (index >= slist->n) {
109 return ME_ERRNO_NOMORE_SUBDEVICE_TYPE;
112 *subdevice = index;
114 return ME_ERRNO_SUCCESS;
117 void me_slist_add_subdevice_tail(struct me_slist *slist,
118 me_subdevice_t * subdevice)
120 PDEBUG_LOCKS("called.\n");
122 list_add_tail(&subdevice->list, &slist->head);
123 ++slist->n;
126 me_subdevice_t *me_slist_del_subdevice_tail(struct me_slist *slist)
129 struct list_head *last;
130 me_subdevice_t *subdevice;
132 PDEBUG_LOCKS("called.\n");
134 if (list_empty(&slist->head))
135 return NULL;
137 last = slist->head.prev;
139 subdevice = list_entry(last, me_subdevice_t, list);
141 list_del(last);
143 --slist->n;
145 return subdevice;
148 int me_slist_init(me_slist_t * slist)
150 PDEBUG_LOCKS("called.\n");
152 INIT_LIST_HEAD(&slist->head);
153 slist->n = 0;
154 return 0;
157 void me_slist_deinit(me_slist_t * slist)
160 struct list_head *s;
161 me_subdevice_t *subdevice;
163 PDEBUG_LOCKS("called.\n");
165 while (!list_empty(&slist->head)) {
166 s = slist->head.next;
167 list_del(s);
168 subdevice = list_entry(s, me_subdevice_t, list);
169 subdevice->me_subdevice_destructor(subdevice);
172 slist->n = 0;