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_FLUSH _IO(XNPIPE_IOCTL_BASE,1)
00029 #define XNPIPEIOC_SETSIG _IO(XNPIPE_IOCTL_BASE,2)
00030
00031 #define XNPIPE_NORMAL 0x0
00032 #define XNPIPE_URGENT 0x1
00033
00034 #define XNPIPE_IFLUSH 0x1
00035 #define XNPIPE_OFLUSH 0x2
00036
00037 #define XNPIPE_MINOR_AUTO -1
00038
00039 #ifdef __KERNEL__
00040
00041 #include <nucleus/queue.h>
00042 #include <nucleus/synch.h>
00043 #include <nucleus/thread.h>
00044 #include <linux/types.h>
00045 #include <linux/poll.h>
00046
00047 #define XNPIPE_KERN_CONN 0x1
00048 #define XNPIPE_USER_CONN 0x2
00049 #define XNPIPE_USER_SIGIO 0x4
00050 #define XNPIPE_USER_WREAD 0x8
00051 #define XNPIPE_USER_WREAD_READY 0x10
00052 #define XNPIPE_USER_WSYNC 0x20
00053 #define XNPIPE_USER_WSYNC_READY 0x40
00054
00055 #define XNPIPE_USER_ALL_WAIT \
00056 (XNPIPE_USER_WREAD|XNPIPE_USER_WSYNC)
00057
00058 #define XNPIPE_USER_ALL_READY \
00059 (XNPIPE_USER_WREAD_READY|XNPIPE_USER_WSYNC_READY)
00060
00061 typedef struct xnpipe_mh {
00062
00063 xnholder_t link;
00064 unsigned size;
00065 unsigned rdoff;
00066
00067 } xnpipe_mh_t;
00068
00069 static inline xnpipe_mh_t *link2mh(xnholder_t *ln)
00070 {
00071 return ln ? container_of(ln, xnpipe_mh_t, link) : NULL;
00072 }
00073
00074 typedef int xnpipe_io_handler (int minor,
00075 struct xnpipe_mh *mh, int retval, void *cookie);
00076
00077 typedef int xnpipe_session_handler (int minor, void *cookie);
00078
00079 typedef void *xnpipe_alloc_handler (int minor, size_t size, void *cookie);
00080
00081 typedef struct xnpipe_state {
00082
00083 xnholder_t slink;
00084 xnholder_t alink;
00085 #define link2xnpipe(ln, fld) container_of(ln, xnpipe_state_t, fld)
00086
00087 xnqueue_t inq;
00088 xnqueue_t outq;
00089 xnpipe_io_handler *output_handler;
00090 xnpipe_io_handler *input_handler;
00091 xnpipe_alloc_handler *alloc_handler;
00092 xnsynch_t synchbase;
00093 void *cookie;
00094
00095
00096 xnflags_t status;
00097 struct fasync_struct *asyncq;
00098 wait_queue_head_t readq;
00099 wait_queue_head_t syncq;
00100 size_t ionrd;
00101
00102 } xnpipe_state_t;
00103
00104 extern xnpipe_state_t xnpipe_states[];
00105
00106 #define xnminor_from_state(s) (s - xnpipe_states)
00107
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #endif
00111
00112 int xnpipe_mount(void);
00113
00114 void xnpipe_umount(void);
00115
00116
00117
00118 void xnpipe_setup(xnpipe_session_handler *open_handler,
00119 xnpipe_session_handler *close_handler);
00120
00121 int xnpipe_connect(int minor,
00122 xnpipe_io_handler *output_handler,
00123 xnpipe_io_handler *input_handler,
00124 xnpipe_alloc_handler *alloc_handler, void *cookie);
00125
00126 int xnpipe_disconnect(int minor);
00127
00128 ssize_t xnpipe_send(int minor,
00129 struct xnpipe_mh *mh, size_t size, int flags);
00130
00131 ssize_t xnpipe_mfixup(int minor, struct xnpipe_mh *mh, ssize_t size);
00132
00133 ssize_t xnpipe_recv(int minor,
00134 struct xnpipe_mh **pmh, xnticks_t timeout);
00135
00136 int xnpipe_inquire(int minor);
00137
00138 int xnpipe_flush(int minor, int mode);
00139
00140 #ifdef __cplusplus
00141 }
00142 #endif
00143
00144 static inline xnholder_t *xnpipe_m_link(xnpipe_mh_t *mh)
00145 {
00146 return &mh->link;
00147 }
00148
00149 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00150 {
00151 return (char *)(mh + 1);
00152 }
00153
00154 #define xnpipe_m_size(mh) ((mh)->size)
00155
00156 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
00157
00158 #endif
00159
00160 #endif