00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _XENO_NUCLEUS_PIPE_H
00021 #define _XENO_NUCLEUS_PIPE_H
00022
00023 #define XNPIPE_NDEVS CONFIG_XENO_OPT_PIPE_NRDEV
00024 #define XNPIPE_DEV_MAJOR 150
00025
00026 #define XNPIPE_IOCTL_BASE 'p'
00027 #define XNPIPEIOC_GET_NRDEV _IOW(XNPIPE_IOCTL_BASE, 0, int)
00028 #define XNPIPEIOC_IFLUSH _IO(XNPIPE_IOCTL_BASE,1)
00029 #define XNPIPEIOC_OFLUSH _IO(XNPIPE_IOCTL_BASE,2)
00030 #define XNPIPEIOC_FLUSH XNPIPEIOC_OFLUSH
00031 #define XNPIPEIOC_SETSIG _IO(XNPIPE_IOCTL_BASE,3)
00032
00033 #define XNPIPE_NORMAL 0x0
00034 #define XNPIPE_URGENT 0x1
00035
00036 #define XNPIPE_IFLUSH 0x1
00037 #define XNPIPE_OFLUSH 0x2
00038
00039 #define XNPIPE_MINOR_AUTO -1
00040
00041 #ifdef __KERNEL__
00042
00043 #include <nucleus/queue.h>
00044 #include <nucleus/synch.h>
00045 #include <nucleus/thread.h>
00046 #include <linux/types.h>
00047 #include <linux/poll.h>
00048
00049 #define XNPIPE_KERN_CONN 0x1
00050 #define XNPIPE_KERN_LCLOSE 0x2
00051 #define XNPIPE_USER_CONN 0x4
00052 #define XNPIPE_USER_SIGIO 0x8
00053 #define XNPIPE_USER_WREAD 0x10
00054 #define XNPIPE_USER_WREAD_READY 0x20
00055 #define XNPIPE_USER_WSYNC 0x40
00056 #define XNPIPE_USER_WSYNC_READY 0x80
00057
00058 #define XNPIPE_USER_ALL_WAIT \
00059 (XNPIPE_USER_WREAD|XNPIPE_USER_WSYNC)
00060
00061 #define XNPIPE_USER_ALL_READY \
00062 (XNPIPE_USER_WREAD_READY|XNPIPE_USER_WSYNC_READY)
00063
00064 typedef struct xnpipe_mh {
00065
00066 struct xnholder link;
00067 unsigned size;
00068 unsigned rdoff;
00069
00070 } xnpipe_mh_t;
00071
00072 static inline xnpipe_mh_t *link2mh(struct xnholder *ln)
00073 {
00074 return ln ? container_of(ln, xnpipe_mh_t, link) : NULL;
00075 }
00076
00077 struct xnpipe_state;
00078
00079 struct xnpipe_operations {
00080 void (*output)(struct xnpipe_mh *mh, void *xstate);
00081 int (*input)(struct xnpipe_mh *mh, int retval, void *xstate);
00082 void *(*alloc_ibuf)(size_t size, void *xstate);
00083 void (*free_ibuf)(void *buf, void *xstate);
00084 void (*free_obuf)(void *buf, void *xstate);
00085 void (*release)(void *xstate);
00086 };
00087
00088 struct xnpipe_state {
00089
00090 struct xnholder slink;
00091 struct xnholder alink;
00092 #define link2xnpipe(ln, fld) container_of(ln, struct xnpipe_state, fld)
00093
00094 struct xnqueue inq;
00095 struct xnqueue outq;
00096 struct xnsynch synchbase;
00097 struct xnpipe_operations ops;
00098 void *xstate;
00099
00100
00101 xnflags_t status;
00102 struct fasync_struct *asyncq;
00103 wait_queue_head_t readq;
00104 wait_queue_head_t syncq;
00105 int wcount;
00106 size_t ionrd;
00107
00108 };
00109
00110 extern struct xnpipe_state xnpipe_states[];
00111
00112 #define xnminor_from_state(s) (s - xnpipe_states)
00113
00114 #ifdef __cplusplus
00115 extern "C" {
00116 #endif
00117
00118 int xnpipe_mount(void);
00119
00120 void xnpipe_umount(void);
00121
00122
00123
00124 int xnpipe_connect(int minor,
00125 struct xnpipe_operations *ops, void *xstate);
00126
00127 int xnpipe_disconnect(int minor);
00128
00129 ssize_t xnpipe_send(int minor,
00130 struct xnpipe_mh *mh, size_t size, int flags);
00131
00132 ssize_t xnpipe_mfixup(int minor, struct xnpipe_mh *mh, ssize_t size);
00133
00134 ssize_t xnpipe_recv(int minor,
00135 struct xnpipe_mh **pmh, xnticks_t timeout);
00136
00137 int xnpipe_flush(int minor, int mode);
00138
00139 #ifdef __cplusplus
00140 }
00141 #endif
00142
00143 static inline struct xnholder *xnpipe_m_link(xnpipe_mh_t *mh)
00144 {
00145 return &mh->link;
00146 }
00147
00148 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00149 {
00150 return (char *)(mh + 1);
00151 }
00152
00153 #define xnpipe_m_size(mh) ((mh)->size)
00154
00155 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
00156
00157 #endif
00158
00159 #endif