dd9c8f76c58febcbec5d270703bca7a3c8f019e3
[openwrt/openwrt.git] / target / linux / ubicom32 / files / arch / ubicom32 / include / asm / ubicom32ring.h
1 /*
2 * arch/ubicom32/include/asm/ubicom32ring.h
3 * Userspace I/O platform driver for Ubicom32 ring buffers
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _ASM_UBICOM32_UBICOM32RING_H
25 #define _ASM_UBICOM32_UBICOM32RING_H
26
27 #define UIO_UBICOM32RING_REG_VERSION 2
28
29 struct uio_ubicom32ring_desc {
30 volatile unsigned int head;
31 volatile unsigned int tail;
32 unsigned int entries;
33 volatile unsigned int ring[0];
34 };
35
36 struct uio_ubicom32ring_regs {
37 unsigned int version;
38
39 /*
40 * Magic type used to identify the ring set. Each driver will
41 * have a different magic value.
42 */
43 unsigned int magic;
44
45 /*
46 * Registers defined by the driver
47 */
48 unsigned int regs_size;
49 void *regs;
50
51 /*
52 * The locations of the rings
53 *
54 * DO NOT ADD ANYTHING BELOW THIS LINE
55 */
56 unsigned int num_rings;
57 struct uio_ubicom32ring_desc *rings[0];
58 };
59
60 /*
61 * ringtio_ring_flush
62 */
63 static inline void ringtio_ring_flush(struct uio_ubicom32ring_desc *rd)
64 {
65 rd->head = rd->tail = 0;
66 }
67
68 /*
69 * ringtio_ring_get
70 */
71 static inline int ringtio_ring_get(struct uio_ubicom32ring_desc *rd, void **val)
72 {
73 if (rd->head == rd->tail) {
74 return 0;
75 }
76
77 *val = (void *)rd->ring[rd->head++];
78 if (rd->head == rd->entries) {
79 rd->head = 0;
80 }
81 return 1;
82 }
83
84 /*
85 * ringtio_ring_put
86 */
87 static inline int ringtio_ring_put(struct uio_ubicom32ring_desc *rd, void *val)
88 {
89 unsigned int newtail = rd->tail + 1;
90 if (newtail == rd->entries) {
91 newtail = 0;
92 }
93
94 if (newtail == rd->head) {
95 return 0;
96 }
97
98 rd->ring[rd->tail] = (unsigned int)val;
99 rd->tail = newtail;
100 return 1;
101 }
102
103 #endif /* _ASM_UBICOM32_UBICOM32RING_H */