Xenomai API  2.6.5
pipe.h
1 /*
2  * @note Copyright (C) 2001,2002,2003 Philippe Gerum.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA
7  * 02139, USA; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * Xenomai is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _XENO_NUCLEUS_PIPE_H
21 #define _XENO_NUCLEUS_PIPE_H
22 
23 #define XNPIPE_NDEVS CONFIG_XENO_OPT_PIPE_NRDEV
24 #define XNPIPE_DEV_MAJOR 150
25 
26 #define XNPIPE_IOCTL_BASE 'p'
27 #define XNPIPEIOC_GET_NRDEV _IOW(XNPIPE_IOCTL_BASE, 0, int)
28 #define XNPIPEIOC_IFLUSH _IO(XNPIPE_IOCTL_BASE,1)
29 #define XNPIPEIOC_OFLUSH _IO(XNPIPE_IOCTL_BASE,2)
30 #define XNPIPEIOC_FLUSH XNPIPEIOC_OFLUSH
31 #define XNPIPEIOC_SETSIG _IO(XNPIPE_IOCTL_BASE,3)
32 
33 #define XNPIPE_NORMAL 0x0
34 #define XNPIPE_URGENT 0x1
35 
36 #define XNPIPE_IFLUSH 0x1
37 #define XNPIPE_OFLUSH 0x2
38 
39 #define XNPIPE_MINOR_AUTO -1
40 
41 #ifdef __KERNEL__
42 
43 #include <nucleus/queue.h>
44 #include <nucleus/synch.h>
45 #include <nucleus/thread.h>
46 #include <linux/types.h>
47 #include <linux/poll.h>
48 
49 #define XNPIPE_KERN_CONN 0x1
50 #define XNPIPE_KERN_LCLOSE 0x2
51 #define XNPIPE_USER_CONN 0x4
52 #define XNPIPE_USER_SIGIO 0x8
53 #define XNPIPE_USER_WREAD 0x10
54 #define XNPIPE_USER_WREAD_READY 0x20
55 #define XNPIPE_USER_WSYNC 0x40
56 #define XNPIPE_USER_WSYNC_READY 0x80
57 
58 #define XNPIPE_USER_ALL_WAIT \
59 (XNPIPE_USER_WREAD|XNPIPE_USER_WSYNC)
60 
61 #define XNPIPE_USER_ALL_READY \
62 (XNPIPE_USER_WREAD_READY|XNPIPE_USER_WSYNC_READY)
63 
64 typedef struct xnpipe_mh {
65 
66  struct xnholder link;
67  unsigned size;
68  unsigned rdoff;
69 
70 } xnpipe_mh_t;
71 
72 static inline xnpipe_mh_t *link2mh(struct xnholder *ln)
73 {
74  return ln ? container_of(ln, xnpipe_mh_t, link) : NULL;
75 }
76 
77 struct xnpipe_state;
78 
79 struct xnpipe_operations {
80  void (*output)(struct xnpipe_mh *mh, void *xstate);
81  int (*input)(struct xnpipe_mh *mh, int retval, void *xstate);
82  void *(*alloc_ibuf)(size_t size, void *xstate);
83  void (*free_ibuf)(void *buf, void *xstate);
84  void (*free_obuf)(void *buf, void *xstate);
85  void (*release)(void *xstate);
86 };
87 
88 struct xnpipe_state {
89 
90  struct xnholder slink; /* Link on sleep queue */
91  struct xnholder alink; /* Link on async queue */
92 #define link2xnpipe(ln, fld) container_of(ln, struct xnpipe_state, fld)
93 
94  struct xnqueue inq; /* From user-space to kernel */
95  struct xnqueue outq; /* From kernel to user-space */
96  struct xnsynch synchbase;
97  struct xnpipe_operations ops;
98  void *xstate; /* Extra state managed by caller */
99 
100  /* Linux kernel part */
101  xnflags_t status;
102  struct fasync_struct *asyncq;
103  wait_queue_head_t readq; /* open/read/poll waiters */
104  wait_queue_head_t syncq; /* sync waiters */
105  int wcount; /* number of waiters on this minor */
106  size_t ionrd;
107 
108 };
109 
110 extern struct xnpipe_state xnpipe_states[];
111 
112 #define xnminor_from_state(s) (s - xnpipe_states)
113 
114 #ifdef __cplusplus
115 extern "C" {
116 #endif /* __cplusplus */
117 
118 int xnpipe_mount(void);
119 
120 void xnpipe_umount(void);
121 
122 /* Entry points of the kernel interface. */
123 
124 int xnpipe_connect(int minor,
125  struct xnpipe_operations *ops, void *xstate);
126 
127 int xnpipe_disconnect(int minor);
128 
129 ssize_t xnpipe_send(int minor,
130  struct xnpipe_mh *mh, size_t size, int flags);
131 
132 ssize_t xnpipe_mfixup(int minor, struct xnpipe_mh *mh, ssize_t size);
133 
134 ssize_t xnpipe_recv(int minor,
135  struct xnpipe_mh **pmh, xnticks_t timeout);
136 
137 int xnpipe_flush(int minor, int mode);
138 
139 #ifdef __cplusplus
140 }
141 #endif /* __cplusplus */
142 
143 static inline struct xnholder *xnpipe_m_link(xnpipe_mh_t *mh)
144 {
145  return &mh->link;
146 }
147 
148 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
149 {
150  return (char *)(mh + 1);
151 }
152 
153 #define xnpipe_m_size(mh) ((mh)->size)
154 
155 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
156 
157 #endif /* __KERNEL__ */
158 
159 #endif /* !_XENO_NUCLEUS_PIPE_H */