]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/dsp/dspgateway/ipbuf.h
REMOVE OMAP LEGACY CODE: Reset mach-omap1/board-*.c files to mainline
[linux-2.6-omap-h63xx.git] / drivers / dsp / dspgateway / ipbuf.h
1 /*
2  * This file is part of OMAP DSP driver (DSP Gateway version 3.3.1)
3  *
4  * Copyright (C) 2002-2006 Nokia Corporation. All rights reserved.
5  *
6  * Contact: Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #ifndef __PLAT_OMAP_DSP_IPBUF_H
25 #define __PLAT_OMAP_DSP_IPBUF_H
26
27 struct ipbuf {
28         u16 c;                  /* count */
29         u16 next;               /* link */
30         u16 la;                 /* lock owner (ARM side) */
31         u16 sa;                 /* sync word (ARM->DSP) */
32         u16 ld;                 /* lock owner (DSP side) */
33         u16 sd;                 /* sync word (DSP->ARM) */
34         unsigned char d[0];     /* data */
35 };
36
37 struct ipbuf_p {
38         u16 c;          /* count */
39         u16 s;          /* sync word */
40         u16 al;         /* data address lower */
41         u16 ah;         /* data address upper */
42 };
43
44 #define IPBUF_SYS_DLEN  31
45
46 struct ipbuf_sys {
47         u16 s;                  /* sync word */
48         u16 d[IPBUF_SYS_DLEN];  /* data */
49 };
50
51 struct ipbcfg {
52         u16 ln;
53         u16 lsz;
54         void *base;
55         u16 bsycnt;
56         unsigned long cnt_full; /* count of IPBFULL error */
57 };
58
59 struct ipbuf_head {
60         u16 bid;
61         struct ipbuf *p;
62 };
63
64 extern struct ipbcfg ipbcfg;
65 extern struct ipbuf_sys *ipbuf_sys_da, *ipbuf_sys_ad;
66
67 #define ipb_bsycnt_inc(ipbcfg)  atomic_inc((atomic_t *)&((ipbcfg)->bsycnt))
68 #define ipb_bsycnt_dec(ipbcfg)  atomic_dec((atomic_t *)&((ipbcfg)->bsycnt))
69
70 #define dsp_mem_enable_ipbuf()  dsp_mem_enable(ipbcfg.base)
71 #define dsp_mem_disable_ipbuf() dsp_mem_disable(ipbcfg.base)
72
73 struct ipblink {
74         spinlock_t lock;
75         u16 top;
76         u16 tail;
77 };
78
79 #define IPBLINK_INIT {                          \
80                 .lock = SPIN_LOCK_UNLOCKED,     \
81                 .top  = BID_NULL,               \
82                 .tail = BID_NULL,               \
83         }
84
85 #define INIT_IPBLINK(link)                      \
86         do {                                    \
87                 spin_lock_init(&(link)->lock);  \
88                 (link)->top  = BID_NULL;        \
89                 (link)->tail = BID_NULL;        \
90         } while(0)
91
92 #define RESET_IPBLINK(link)                     \
93         do {                                    \
94                 (link)->top  = BID_NULL;        \
95                 (link)->tail = BID_NULL;        \
96         } while(0)
97
98 #define ipblink_empty(link)     ((link)->top == BID_NULL)
99
100 static inline void __ipblink_del_top(struct ipblink *link)
101 {
102         struct ipbuf_head *ipb_h = bid_to_ipbuf(link->top);
103
104         if ((link->top = ipb_h->p->next) == BID_NULL)
105                 link->tail = BID_NULL;
106         else
107                 ipb_h->p->next = BID_NULL;
108 }
109
110 static inline void ipblink_del_top(struct ipblink *link)
111 {
112         spin_lock(&link->lock);
113         __ipblink_del_top(link);
114         spin_unlock(&link->lock);
115 }
116
117 static inline void __ipblink_add_tail(struct ipblink *link, u16 bid)
118 {
119         if (ipblink_empty(link))
120                 link->top = bid;
121         else
122                 bid_to_ipbuf(link->tail)->p->next = bid;
123         link->tail = bid;
124 }
125
126 static inline void ipblink_add_tail(struct ipblink *link, u16 bid)
127 {
128         spin_lock(&link->lock);
129         __ipblink_add_tail(link, bid);
130         spin_unlock(&link->lock);
131 }
132
133 static inline void __ipblink_flush(struct ipblink *link)
134 {
135         u16 bid;
136
137         while (!ipblink_empty(link)) {
138                 bid = link->top;
139                 __ipblink_del_top(link);
140                 unuse_ipbuf(bid_to_ipbuf(bid));
141         }
142 }
143
144 static inline void ipblink_flush(struct ipblink *link)
145 {
146         spin_lock(&link->lock);
147         __ipblink_flush(link);
148         spin_unlock(&link->lock);
149 }
150
151 static inline void __ipblink_add_pvt(struct ipblink *link)
152 {
153         link->top  = BID_PVT;
154         link->tail = BID_PVT;
155 }
156
157 static inline void ipblink_add_pvt(struct ipblink *link)
158 {
159         spin_lock(&link->lock);
160         __ipblink_add_pvt(link);
161         spin_unlock(&link->lock);
162 }
163
164 static inline void __ipblink_del_pvt(struct ipblink *link)
165 {
166         link->top  = BID_NULL;
167         link->tail = BID_NULL;
168 }
169
170 static inline void ipblink_del_pvt(struct ipblink *link)
171 {
172         spin_lock(&link->lock);
173         __ipblink_del_pvt(link);
174         spin_unlock(&link->lock);
175 }
176
177 static inline void __ipblink_flush_pvt(struct ipblink *link)
178 {
179         if (!ipblink_empty(link))
180                 ipblink_del_pvt(link);
181 }
182
183 static inline void ipblink_flush_pvt(struct ipblink *link)
184 {
185         spin_lock(&link->lock);
186         __ipblink_flush_pvt(link);
187         spin_unlock(&link->lock);
188 }
189
190 #define ipblink_for_each(bid, link) \
191         for (bid = (link)->top; bid != BID_NULL; bid = bid_to_ipbuf(bid)->p->next)
192
193 #endif /* __PLAT_OMAP_DSP_IPBUF_H */