Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/*	$NetBSD: list.h,v 1.32 2021/12/19 11:39:24 riastradh Exp $	*/

/*-
 * Copyright (c) 2013 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Taylor R. Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Notes on porting:
 *
 * - LIST_HEAD(x) means a declaration `struct list_head x =
 *   LIST_HEAD_INIT(x)' in Linux, but something else in NetBSD.
 *   Replace by the expansion.
 */

#ifndef _LINUX_LIST_H_
#define _LINUX_LIST_H_

#include <sys/null.h>
#include <sys/pslist.h>
#include <sys/queue.h>

#include <linux/kernel.h>
#include <linux/types.h>

#define	POISON_INUSE	0x5a	/* XXX */

/*
 * Doubly-linked lists.  Type defined in <linux/types.h>.
 */

#define	LIST_HEAD_INIT(name)	{ .prev = &(name), .next = &(name) }

#define	LINUX_LIST_HEAD(name)	struct list_head name = LIST_HEAD_INIT(name)

static inline void
INIT_LIST_HEAD(struct list_head *head)
{
	head->prev = head;
	head->next = head;
}

static inline struct list_head *
list_first(const struct list_head *head)
{
	return head->next;
}

static inline struct list_head *
list_last(const struct list_head *head)
{
	return head->prev;
}

static inline struct list_head *
list_next(const struct list_head *node)
{
	return node->next;
}

static inline struct list_head *
list_prev(const struct list_head *node)
{
	return node->prev;
}

static inline int
list_empty(const struct list_head *head)
{
	return (head->next == head);
}

static inline int
list_is_singular(const struct list_head *head)
{

	if (list_empty(head))
		return false;
	if (head->next != head->prev)
		return false;
	return true;
}

static inline bool
list_is_first(const struct list_head *entry, const struct list_head *head)
{
	return head == entry->prev;
}

static inline bool
list_is_last(const struct list_head *entry, const struct list_head *head)
{
	return head == entry->next;
}

static inline void
__list_add_between(struct list_head *prev, struct list_head *node,
    struct list_head *next)
{
	prev->next = node;
	node->prev = prev;
	node->next = next;
	next->prev = node;
}

static inline void
list_add(struct list_head *node, struct list_head *head)
{
	__list_add_between(head, node, head->next);
}

static inline void
list_add_rcu(struct list_head *node, struct list_head *head)
{
	struct list_head *next = head->next;

	/* Initialize the new node first.  */
	node->next = next;
	node->prev = head;

	/* Now publish it.  */
	atomic_store_release(&head->next, node);

	/* Fix up back pointers, not protected by RCU.  */
	next->prev = node;
}

static inline void
list_add_tail(struct list_head *node, struct list_head *head)
{
	__list_add_between(head->prev, node, head);
}

static inline void
__list_del_entry(struct list_head *entry)
{
	entry->prev->next = entry->next;
	entry->next->prev = entry->prev;
}

static inline void
list_del(struct list_head *entry)
{
	__list_del_entry(entry);
	entry->next = (void *)(uintptr_t)1;
	entry->prev = (void *)(uintptr_t)2;
}

static inline void
__list_splice_between(struct list_head *prev, const struct list_head *list,
    struct list_head *next)
{
	struct list_head *first = list->next;
	struct list_head *last = list->prev;

	first->prev = prev;
	prev->next = first;

	last->next = next;
	next->prev = last;
}

static inline void
list_splice(const struct list_head *list, struct list_head *head)
{
	if (!list_empty(list))
		__list_splice_between(head, list, head->next);
}

static inline void
list_splice_init(struct list_head *list, struct list_head *head)
{
	if (!list_empty(list)) {
		__list_splice_between(head, list, head->next);
		INIT_LIST_HEAD(list);
	}
}

static inline void
list_splice_tail(const struct list_head *list, struct list_head *head)
{
	if (!list_empty(list))
		__list_splice_between(head->prev, list, head);
}

static inline void
list_splice_tail_init(struct list_head *list, struct list_head *head)
{
	if (!list_empty(list)) {
		__list_splice_between(head->prev, list, head);
		INIT_LIST_HEAD(list);
	}
}

static inline void
list_move(struct list_head *node, struct list_head *head)
{
	list_del(node);
	list_add(node, head);
}

static inline void
list_move_tail(struct list_head *node, struct list_head *head)
{
	list_del(node);
	list_add_tail(node, head);
}

static inline void
list_bulk_move_tail(struct list_head *head, struct list_head *first,
    struct list_head *last)
{

	first->prev->next = last->next;
	last->next->prev = first->prev;

	head->prev->next = first;
	first->prev = head->prev;

	last->next = head;
	head->prev = last;
}

static inline void
list_replace(struct list_head *old, struct list_head *new)
{
	new->prev = old->prev;
	old->prev->next = new;
	new->next = old->next;
	old->next->prev = new;
}

static inline void
list_replace_init(struct list_head *old, struct list_head *new)
{
	list_replace(old, new);
	INIT_LIST_HEAD(old);
}

static inline void
list_del_init(struct list_head *node)
{
	list_del(node);
	INIT_LIST_HEAD(node);
}

#define	list_entry(PTR, TYPE, FIELD)	container_of(PTR, TYPE, FIELD)
#define	list_first_entry(PTR, TYPE, FIELD)				\
	list_entry(list_first((PTR)), TYPE, FIELD)
#define	list_first_entry_or_null(PTR, TYPE, FIELD)			\
	(list_empty((PTR)) ? NULL : list_entry(list_first((PTR)), TYPE, FIELD))
#define	list_last_entry(PTR, TYPE, FIELD)				\
	list_entry(list_last((PTR)), TYPE, FIELD)
#define	list_next_entry(ENTRY, FIELD)					\
	list_entry(list_next(&(ENTRY)->FIELD), typeof(*(ENTRY)), FIELD)
#define	list_prev_entry(ENTRY, FIELD)					\
	list_entry(list_prev(&(ENTRY)->FIELD), typeof(*(ENTRY)), FIELD)

#define	list_for_each(VAR, HEAD)					\
	for ((VAR) = list_first((HEAD));				\
		(VAR) != (HEAD);					\
		(VAR) = list_next((VAR)))

#define	list_for_each_prev(VAR, HEAD)					\
	for ((VAR) = list_last((HEAD));					\
		(VAR) != (HEAD);					\
		(VAR) = list_prev((VAR)))

#define	list_for_each_safe(VAR, NEXT, HEAD)				\
	for ((VAR) = list_first((HEAD));				\
		((VAR) != (HEAD)) && ((NEXT) = list_next((VAR)), 1);	\
		(VAR) = (NEXT))

#define	list_safe_reset_next(VAR, NEXT, FIELD)				\
	(NEXT) = list_next_entry(VAR, FIELD)

#define	list_for_each_entry(VAR, HEAD, FIELD)				\
	for ((VAR) = list_entry(list_first((HEAD)), typeof(*(VAR)), FIELD); \
		&(VAR)->FIELD != (HEAD);				\
		(VAR) = list_entry(list_next(&(VAR)->FIELD), typeof(*(VAR)), \
		    FIELD))

#define	list_for_each_entry_safe(VAR, NEXT, HEAD, FIELD)		\
	for ((VAR) = list_entry(list_first((HEAD)), typeof(*(VAR)), FIELD); \
		(&(VAR)->FIELD != (HEAD)) &&				\
		    ((NEXT) = list_entry(list_next(&(VAR)->FIELD),	\
			typeof(*(VAR)), FIELD), 1);			\
		(VAR) = (NEXT))

#define	list_for_each_entry_safe_reverse(VAR, NEXT, HEAD, FIELD)	\
	for ((VAR) = list_entry(list_last((HEAD)), typeof(*(VAR)), FIELD); \
		(&(VAR)->FIELD != (HEAD)) &&				\
		    ((NEXT) = list_entry(list_prev(&(VAR)->FIELD),	\
		        typeof(*(VAR)), FIELD), 1);			\
		(VAR) = (NEXT))

#define	list_for_each_entry_reverse(VAR, HEAD, FIELD)			\
	for ((VAR) = list_entry(list_last((HEAD)), typeof(*(VAR)), FIELD); \
		&(VAR)->FIELD != (HEAD);				\
		(VAR) = list_entry(list_prev(&(VAR)->FIELD), typeof(*(VAR)), \
		    FIELD))

#define	list_for_each_entry_continue(VAR, HEAD, FIELD)			\
	for ((VAR) = list_next_entry((VAR), FIELD);			\
		&(VAR)->FIELD != (HEAD);				\
		(VAR) = list_next_entry((VAR), FIELD))

#define	list_for_each_entry_continue_reverse(VAR, HEAD, FIELD)		\
	for ((VAR) = list_prev_entry((VAR), FIELD);			\
		&(VAR)->FIELD != (HEAD);				\
		(VAR) = list_prev_entry((VAR), FIELD))

#define	list_for_each_entry_from(VAR, HEAD, FIELD)			\
	for (;								\
		(&(VAR)->FIELD != (HEAD));				\
		(VAR) = list_next_entry((VAR), FIELD))

#define	list_for_each_entry_from_reverse(VAR, HEAD, FIELD)		\
	for (;								\
		(&(VAR)->FIELD != (HEAD));				\
		(VAR) = list_prev_entry((VAR), FIELD))

#define	list_for_each_entry_safe_from(VAR, NEXT, HEAD, FIELD)		\
	for (;								\
		(&(VAR)->FIELD != (HEAD)) &&				\
		    ((NEXT) = list_next_entry((VAR), FIELD));		\
		(VAR) = (NEXT))

/*
 * `H'ead-only/`H'ash-table doubly-linked lists.
 */

#define	hlist_head	pslist_head
#define	hlist_node	pslist_entry

#define	HLIST_HEAD_INIT	PSLIST_INITIALIZER
#define	INIT_HLIST_HEAD	PSLIST_INIT
#define	hlist_empty(h)	(pslist_writer_first(h) == NULL)
#define	hlist_first	pslist_writer_first
#define	hlist_next	pslist_writer_next

static inline void
hlist_add_head(struct hlist_node *node, struct hlist_head *head)
{

	pslist_entry_init(node);
	pslist_writer_insert_head(head, node);
}

static inline void
hlist_del(struct hlist_node *node)
{

	pslist_writer_remove(node);
	/* XXX abstraction violation */
	node->ple_prevp = _PSLIST_POISON;
}

static inline void
hlist_del_init(struct hlist_node *node)
{

	/* XXX abstraction violation */
	if (node->ple_prevp != NULL)
		pslist_writer_remove(node);
}

#define	hlist_entry(PTR, TYPE, FIELD)	container_of(PTR, TYPE, FIELD)
#define	hlist_for_each(VAR, HEAD)					      \
	for ((VAR) = hlist_first(HEAD); (VAR) != NULL; (VAR) = hlist_next(VAR))
#define	hlist_for_each_safe(VAR, NEXT, HEAD)				      \
	for ((VAR) = hlist_first(HEAD);					      \
		(VAR) != NULL && ((NEXT) = hlist_next(HEAD), 1);	      \
		(VAR) = (NEXT))
#define	hlist_for_each_entry(VAR, HEAD, FIELD)				      \
	for ((VAR) = (hlist_first(HEAD) == NULL ? NULL :		      \
			hlist_entry(hlist_first(HEAD), typeof(*(VAR)),	      \
			    FIELD));					      \
		(VAR) != NULL;						      \
		(VAR) = (hlist_next(&(VAR)->FIELD) == NULL ? NULL :	      \
			hlist_entry(hlist_next(&(VAR)->FIELD), typeof(*(VAR)),\
			    FIELD)))

#define	hlist_for_each_entry_safe(VAR, NEXT, HEAD, FIELD)		      \
	for ((VAR) = (hlist_first(HEAD) == NULL ? NULL :		      \
			hlist_entry(hlist_first(HEAD), typeof(*(VAR)),	      \
			    FIELD));					      \
		((VAR) != NULL &&					      \
		    ((NEXT) = hlist_next(&(VAR)->FIELD), 1));		      \
	        (VAR) = hlist_entry((NEXT), typeof(*(VAR)), FIELD))

static inline void
hlist_add_behind_rcu(struct hlist_node *node, struct hlist_node *prev)
{

	pslist_entry_init(node);
	pslist_writer_insert_after(prev, node);
}

static inline void
hlist_add_head_rcu(struct hlist_node *node, struct hlist_head *head)
{

	pslist_entry_init(node);
	pslist_writer_insert_head(head, node);
}

#define	hlist_del_init_rcu	hlist_del_init /* no special needs */

#define	hlist_first_rcu		pslist_reader_first
#define	hlist_next_rcu		pslist_reader_next

#define	hlist_for_each_entry_rcu(VAR, HEAD, FIELD)			      \
	for ((VAR) = (hlist_first_rcu(HEAD) == NULL ? NULL :		      \
			hlist_entry(hlist_first_rcu(HEAD), typeof(*(VAR)),    \
			    FIELD));					      \
		(VAR) != NULL;						      \
		(VAR) = (hlist_next_rcu(&(VAR)->FIELD) == NULL ? NULL :	      \
			hlist_entry(hlist_next_rcu(&(VAR)->FIELD),	      \
			    typeof(*(VAR)), FIELD)))

#endif  /* _LINUX_LIST_H_ */