1 /*
2 * Filename: ve_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 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program;
21 *
22 */
23 #ifndef _VE_MEM__LIST_H
24 #define _VE_MEM__LIST_H
25
26 #define ion_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
27
28 #define aw_container_of(aw_ptr, type, member) ({ \
29 const typeof(((type *)0)->member)*__mptr = (aw_ptr); \
30 (type *)((char *)__mptr - ion_offsetof(type, member)); })
31
aw_prefetch(const void * x)32 static inline void aw_prefetch(const void *x) {(void)x; }
aw_prefetchw(const void * x)33 static inline void aw_prefetchw(const void *x) {(void)x; }
34
35 #define AW_LIST_LOCATION1 ((void *) 0x00100100)
36 #define AW_LIST_LOCATION2 ((void *) 0x00200200)
37
38 struct aw_mem_list_head {
39 struct aw_mem_list_head *aw_next, *aw_prev;
40 };
41
42 #define AW_MEM_LIST_HEAD_INIT(aw_name) { &(aw_name), &(aw_name) }
43
44 #define VE_LIST_HEAD(aw_name) \
45 struct aw_mem_list_head aw_name = AW_MEM_LIST_HEAD_INIT(aw_name)
46
47 #define AW_MEM_INIT_LIST_HEAD(aw_ptr) do { \
48 (aw_ptr)->aw_next = (aw_ptr); (aw_ptr)->aw_prev = (aw_ptr); \
49 } while (0)
50
51 /*
52 * Insert a new entry between two known consecutive entries.
53 *
54 * This is only for internal list manipulation where we know
55 * the aw_prev/aw_next entries already!
56 */
__aw_list_add(struct aw_mem_list_head * newList,struct aw_mem_list_head * aw_prev,struct aw_mem_list_head * aw_next)57 static inline void __aw_list_add(struct aw_mem_list_head *newList,
58 struct aw_mem_list_head *aw_prev,
59 struct aw_mem_list_head *aw_next)
60 {
61 aw_next->aw_prev = newList;
62 newList->aw_next = aw_next;
63 newList->aw_prev = aw_prev;
64 aw_prev->aw_next = newList;
65 }
66
67 /**
68 * list_add - add a new entry
69 * @new: new entry to be added
70 * @head: list head to add it after
71 *
72 * Insert a new entry after the specified head.
73 * This is good for implementing stacks.
74 */
aw_mem_list_add(struct aw_mem_list_head * newList,struct aw_mem_list_head * head)75 static inline void aw_mem_list_add(struct aw_mem_list_head *newList,
76 struct aw_mem_list_head *head)
77 {
78 __aw_list_add(newList, head, head->aw_next);
79 }
80
81 /**
82 * aw_mem_list_add_tail - add a new entry
83 * @new: new entry to be added
84 * @head: list head to add it before
85 *
86 * Insert a new entry before the specified head.
87 * This is useful for implementing queues.
88 */
aw_mem_list_add_tail(struct aw_mem_list_head * newList,struct aw_mem_list_head * head)89 static inline void aw_mem_list_add_tail(struct aw_mem_list_head *newList,
90 struct aw_mem_list_head *head)
91 {
92 __aw_list_add(newList, head->aw_prev, head);
93 }
94
__aw_mem_list_del(struct aw_mem_list_head * aw_prev,struct aw_mem_list_head * aw_next)95 static inline void __aw_mem_list_del(struct aw_mem_list_head *aw_prev,
96 struct aw_mem_list_head *aw_next)
97 {
98 aw_next->aw_prev = aw_prev;
99 aw_prev->aw_next = aw_next;
100 }
101
aw_mem_list_del(struct aw_mem_list_head * entry)102 static inline void aw_mem_list_del(struct aw_mem_list_head *entry)
103 {
104 __aw_mem_list_del(entry->aw_prev, entry->aw_next);
105 entry->aw_next = AW_LIST_LOCATION1;
106 entry->aw_prev = AW_LIST_LOCATION2;
107 }
108
109 #define aw_mem_list_entry(aw_ptr, type, member) aw_container_of(aw_ptr, type, member)
110
111 #define aw_mem_list_for_each_safe(aw_pos, aw_n, aw_head) \
112 for (aw_pos = (aw_head)->aw_next, aw_n = aw_pos->aw_next; aw_pos != (aw_head); \
113 aw_pos = aw_n, aw_n = aw_pos->aw_next)
114
115 #define aw_mem_list_for_each_entry(aw_pos, aw_head, member) \
116 for (aw_pos = aw_mem_list_entry((aw_head)->aw_next, typeof(*aw_pos), member); \
117 aw_prefetch(aw_pos->member.aw_next), &aw_pos->member != (aw_head); \
118 aw_pos = aw_mem_list_entry(aw_pos->member.aw_next, typeof(*aw_pos), member))
119
120 #endif
121