Xenomai  3.0.8
pipe.h
1 /*
2  * 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 #ifndef _COBALT_KERNEL_PIPE_H
20 #define _COBALT_KERNEL_PIPE_H
21 
22 #include <linux/types.h>
23 #include <linux/poll.h>
24 #include <cobalt/kernel/synch.h>
25 #include <cobalt/kernel/thread.h>
26 #include <cobalt/uapi/kernel/pipe.h>
27 
28 #define XNPIPE_NDEVS CONFIG_XENO_OPT_PIPE_NRDEV
29 #define XNPIPE_DEV_MAJOR 150
30 
31 #define XNPIPE_KERN_CONN 0x1
32 #define XNPIPE_KERN_LCLOSE 0x2
33 #define XNPIPE_USER_CONN 0x4
34 #define XNPIPE_USER_SIGIO 0x8
35 #define XNPIPE_USER_WREAD 0x10
36 #define XNPIPE_USER_WREAD_READY 0x20
37 #define XNPIPE_USER_WSYNC 0x40
38 #define XNPIPE_USER_WSYNC_READY 0x80
39 #define XNPIPE_USER_LCONN 0x100
40 
41 #define XNPIPE_USER_ALL_WAIT \
42 (XNPIPE_USER_WREAD|XNPIPE_USER_WSYNC)
43 
44 #define XNPIPE_USER_ALL_READY \
45 (XNPIPE_USER_WREAD_READY|XNPIPE_USER_WSYNC_READY)
46 
47 struct xnpipe_mh {
48  size_t size;
49  size_t rdoff;
50  struct list_head link;
51 };
52 
53 struct xnpipe_state;
54 
55 struct xnpipe_operations {
56  void (*output)(struct xnpipe_mh *mh, void *xstate);
57  int (*input)(struct xnpipe_mh *mh, int retval, void *xstate);
58  void *(*alloc_ibuf)(size_t size, void *xstate);
59  void (*free_ibuf)(void *buf, void *xstate);
60  void (*free_obuf)(void *buf, void *xstate);
61  void (*release)(void *xstate);
62 };
63 
64 struct xnpipe_state {
65  struct list_head slink; /* Link on sleep queue */
66  struct list_head alink; /* Link on async queue */
67 
68  struct list_head inq; /* From user-space to kernel */
69  int nrinq;
70  struct list_head outq; /* From kernel to user-space */
71  int nroutq;
72  struct xnsynch synchbase;
73  struct xnpipe_operations ops;
74  void *xstate; /* Extra state managed by caller */
75 
76  /* Linux kernel part */
77  unsigned long status;
78  struct fasync_struct *asyncq;
79  wait_queue_head_t readq; /* open/read/poll waiters */
80  wait_queue_head_t syncq; /* sync waiters */
81  int wcount; /* number of waiters on this minor */
82  size_t ionrd;
83 };
84 
85 extern struct xnpipe_state xnpipe_states[];
86 
87 #define xnminor_from_state(s) (s - xnpipe_states)
88 
89 #ifdef CONFIG_XENO_OPT_PIPE
90 int xnpipe_mount(void);
91 void xnpipe_umount(void);
92 #else /* !CONFIG_XENO_OPT_PIPE */
93 static inline int xnpipe_mount(void) { return 0; }
94 static inline void xnpipe_umount(void) { }
95 #endif /* !CONFIG_XENO_OPT_PIPE */
96 
97 /* Entry points of the kernel interface. */
98 
99 int xnpipe_connect(int minor,
100  struct xnpipe_operations *ops, void *xstate);
101 
102 int xnpipe_disconnect(int minor);
103 
104 ssize_t xnpipe_send(int minor,
105  struct xnpipe_mh *mh, size_t size, int flags);
106 
107 ssize_t xnpipe_mfixup(int minor, struct xnpipe_mh *mh, ssize_t size);
108 
109 ssize_t xnpipe_recv(int minor,
110  struct xnpipe_mh **pmh, xnticks_t timeout);
111 
112 int xnpipe_flush(int minor, int mode);
113 
114 int xnpipe_pollstate(int minor, unsigned int *mask_r);
115 
116 static inline unsigned int __xnpipe_pollstate(int minor)
117 {
118  struct xnpipe_state *state = xnpipe_states + minor;
119  unsigned int mask = POLLOUT;
120 
121  if (!list_empty(&state->inq))
122  mask |= POLLIN;
123 
124  return mask;
125 }
126 
127 static inline char *xnpipe_m_data(struct xnpipe_mh *mh)
128 {
129  return (char *)(mh + 1);
130 }
131 
132 #define xnpipe_m_size(mh) ((mh)->size)
133 
134 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
135 
136 #endif /* !_COBALT_KERNEL_PIPE_H */