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_MINOR_AUTO -1
00035
00036 #ifdef __KERNEL__
00037
00038 #include <nucleus/queue.h>
00039 #include <nucleus/synch.h>
00040 #include <nucleus/thread.h>
00041 #include <linux/types.h>
00042 #include <linux/poll.h>
00043
00044 #define XNPIPE_KERN_CONN 0x1
00045 #define XNPIPE_USER_CONN 0x2
00046 #define XNPIPE_USER_SIGIO 0x4
00047 #define XNPIPE_USER_WREAD 0x8
00048 #define XNPIPE_USER_WREAD_READY 0x10
00049
00050 #define XNPIPE_USER_WMASK \
00051 (XNPIPE_USER_WREAD)
00052
00053 #define XNPIPE_USER_WREADY \
00054 (XNPIPE_USER_WREAD_READY)
00055
00056 typedef struct xnpipe_mh {
00057
00058 xnholder_t link;
00059 unsigned size;
00060 unsigned rdoff;
00061
00062 } xnpipe_mh_t;
00063
00064 static inline xnpipe_mh_t *link2mh (xnholder_t *laddr)
00065 {
00066 return laddr ? ((xnpipe_mh_t *)(((char *)laddr) - (int)(&((xnpipe_mh_t *)0)->link))) : 0;
00067 }
00068
00069 typedef int xnpipe_io_handler(int minor,
00070 struct xnpipe_mh *mh,
00071 int retval,
00072 void *cookie);
00073
00074 typedef int xnpipe_session_handler(int minor,
00075 void *cookie);
00076
00077 typedef void *xnpipe_alloc_handler(int minor,
00078 size_t size,
00079 void *cookie);
00080 typedef struct xnpipe_state {
00081
00082 xnholder_t slink;
00083 xnholder_t alink;
00084 #define link2xnpipe(laddr,link) \
00085 ((struct xnpipe_state *)(((char *)laddr) - (int)(&((struct xnpipe_state *)0)->link)))
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 unsigned int readw;
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,
00125 void *cookie);
00126
00127 int xnpipe_disconnect(int minor);
00128
00129 ssize_t xnpipe_send(int minor,
00130 struct xnpipe_mh *mh,
00131 size_t size,
00132 int flags);
00133
00134 ssize_t xnpipe_mfixup(int minor,
00135 struct xnpipe_mh *mh,
00136 ssize_t size);
00137
00138 ssize_t xnpipe_recv(int minor,
00139 struct xnpipe_mh **pmh,
00140 xnticks_t timeout);
00141
00142 int xnpipe_inquire(int minor);
00143
00144 #ifdef __cplusplus
00145 }
00146 #endif
00147
00148 static inline xnholder_t *xnpipe_m_link(xnpipe_mh_t *mh)
00149 {
00150 return &mh->link;
00151 }
00152
00153 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00154 {
00155 return (char *)(mh + 1);
00156 }
00157
00158 #define xnpipe_m_size(mh) ((mh)->size)
00159
00160 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
00161
00162 #endif
00163
00164 #endif