• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *	  Filename: vp9_mem_list.h
3  *	   Version: 0.01alpha
4  * Description: Video engine driver memory list management.
5  *	   License: GPLv2
6  *
7  *		Author	: yangcaoyuan <yangcaoyuan@allwinnertech.com>
8  *		Date	: 2017/04/04
9  */
10 
11 #ifndef _VE_MEM__LIST_H
12 #define _VE_MEM__LIST_H
13 
14 #define ion_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
15 
16 #define aw_container_of(aw_ptr, type, member) ({ \
17 const typeof(((type *)0)->member)*__mptr = (aw_ptr); \
18 (type *)((char *)__mptr - ion_offsetof(type, member)); })
19 
aw_prefetch(const void * x)20 static inline void aw_prefetch(const void *x) {(void)x; }
aw_prefetchw(const void * x)21 static inline void aw_prefetchw(const void *x) {(void)x; }
22 
23 #define AW_LIST_LOCATION1  ((void *) 0x00100100)
24 #define AW_LIST_LOCATION2  ((void *) 0x00200200)
25 
26 struct aw_mem_list_head {
27 struct aw_mem_list_head *aw_next, *aw_prev;
28 };
29 
30 #define AW_MEM_LIST_HEAD_INIT(aw_name) { &(aw_name), &(aw_name) }
31 
32 #define VE_LIST_HEAD(aw_name) \
33 struct aw_mem_list_head aw_name = AW_MEM_LIST_HEAD_INIT(aw_name)
34 
35 #define AW_MEM_INIT_LIST_HEAD(aw_ptr) do { \
36 (aw_ptr)->aw_next = (aw_ptr); (aw_ptr)->aw_prev = (aw_ptr); \
37 } while (0)
38 
39 /*
40  * Insert a new entry between two known consecutive entries.
41  *
42  * This is only for internal list manipulation where we know
43  * the aw_prev/aw_next entries already!
44  */
__aw_list_add(struct aw_mem_list_head * newList,struct aw_mem_list_head * aw_prev,struct aw_mem_list_head * aw_next)45 static inline void __aw_list_add(struct aw_mem_list_head *newList,
46 	  struct aw_mem_list_head *aw_prev,
47 	  struct aw_mem_list_head *aw_next)
48 {
49 	aw_next->aw_prev = newList;
50 	newList->aw_next = aw_next;
51 	newList->aw_prev = aw_prev;
52 	aw_prev->aw_next = newList;
53 }
54 
55 /**
56  * list_add - add a new entry
57  * @new: new entry to be added
58  * @head: list head to add it after
59  *
60  * Insert a new entry after the specified head.
61  * This is good for implementing stacks.
62  */
aw_mem_list_add(struct aw_mem_list_head * newList,struct aw_mem_list_head * head)63 static inline void aw_mem_list_add(struct aw_mem_list_head *newList,
64 										struct aw_mem_list_head *head)
65 {
66 	__aw_list_add(newList, head, head->aw_next);
67 }
68 
69 /**
70  * aw_mem_list_add_tail - add a new entry
71  * @new: new entry to be added
72  * @head: list head to add it before
73  *
74  * Insert a new entry before the specified head.
75  * This is useful for implementing queues.
76  */
aw_mem_list_add_tail(struct aw_mem_list_head * newList,struct aw_mem_list_head * head)77 static inline void aw_mem_list_add_tail(struct aw_mem_list_head *newList,
78 		 struct aw_mem_list_head *head)
79 {
80 	__aw_list_add(newList, head->aw_prev, head);
81 }
82 
__aw_mem_list_del(struct aw_mem_list_head * aw_prev,struct aw_mem_list_head * aw_next)83 static inline void __aw_mem_list_del(struct aw_mem_list_head *aw_prev,
84 		struct aw_mem_list_head *aw_next)
85 {
86 	aw_next->aw_prev = aw_prev;
87 	aw_prev->aw_next = aw_next;
88 }
89 
aw_mem_list_del(struct aw_mem_list_head * entry)90 static inline void aw_mem_list_del(struct aw_mem_list_head *entry)
91 {
92 	__aw_mem_list_del(entry->aw_prev, entry->aw_next);
93 	entry->aw_next = AW_LIST_LOCATION1;
94 	entry->aw_prev = AW_LIST_LOCATION2;
95 }
96 
97 #define aw_mem_list_entry(aw_ptr, type, member) aw_container_of(aw_ptr, type, member)
98 
99 #define aw_mem_list_for_each_safe(aw_pos, aw_n, aw_head) \
100 for (aw_pos = (aw_head)->aw_next, aw_n = aw_pos->aw_next; aw_pos != (aw_head); \
101 aw_pos = aw_n, aw_n = aw_pos->aw_next)
102 
103 #define aw_mem_list_for_each_entry(aw_pos, aw_head, member) \
104 for (aw_pos = aw_mem_list_entry((aw_head)->aw_next, typeof(*aw_pos), member); \
105 	aw_prefetch(aw_pos->member.aw_next), &aw_pos->member != (aw_head);  \
106 	aw_pos = aw_mem_list_entry(aw_pos->member.aw_next, typeof(*aw_pos), member))
107 
108 #endif
109