00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _xenomai_dbridge_h
00021 #define _xenomai_dbridge_h
00022
00023 #undef DBRIDGE_DEBUG
00024
00025 #define DBRIDGE_WAIT 0x0
00026 #define DBRIDGE_NOWAIT 0x1
00027
00028 #define DBRIDGE_NORMAL 0x0
00029 #define DBRIDGE_URGENT 0x1
00030
00031 #define DBRIDGE_RTK_CONN 0x1
00032 #define DBRIDGE_USR_CONN 0x2
00033 #define DBRIDGE_USR_WOPEN 0x4
00034 #define DBRIDGE_USR_WSEND 0x8
00035 #define DBRIDGE_USR_WPOLL 0x10
00036 #define DBRIDGE_USR_SIGIO 0x20
00037 #define DBRIDGE_USR_ONWAIT 0x40
00038
00039 #define DBRIDGE_USR_WMASK \
00040 (DBRIDGE_USR_WOPEN|DBRIDGE_USR_WSEND|DBRIDGE_USR_WPOLL)
00041
00042 #define DBRIDGE_MQ_NDEVS 8
00043 #define DBRIDGE_EV_NDEVS 8
00044 #define DBRIDGE_NDEVS (DBRIDGE_MQ_NDEVS + DBRIDGE_EV_NDEVS + 1)
00045 #define DBRIDGE_MAJOR 150
00046
00047 #define XIOCURTMODE 0xfbfb
00048
00049 #ifdef __KERNEL__
00050
00051 #include <xenomai/queue.h>
00052 #include <xenomai/synch.h>
00053 #include <xenomai/thread.h>
00054 #include <linux/types.h>
00055 #include <linux/poll.h>
00056
00057 typedef struct dbridge_mh {
00058
00059 xnholder_t link;
00060 #define link2mh(laddr) \
00061 (laddr ? ((dbridge_mh_t *)(((char *)laddr) - (int)(&((dbridge_mh_t *)0)->link))) : 0)
00062 unsigned size;
00063
00064 } dbridge_mh_t;
00065
00066 typedef int dbridge_io_handler(int minor,
00067 struct dbridge_mh *mh,
00068 int onerror,
00069 void *cookie);
00070
00071 typedef int dbridge_session_handler(int minor,
00072 void *cookie);
00073
00074 typedef void *dbridge_alloc_handler(int minor,
00075 size_t size,
00076 void *cookie);
00077 struct _dbridge_state;
00078
00079 typedef struct _dbridge_ops {
00080
00081 int (*open)(struct _dbridge_state *state,
00082 struct inode *inode,
00083 struct file *file);
00084
00085 int (*close)(struct _dbridge_state *state,
00086 struct inode *inode,
00087 struct file *file);
00088
00089 ssize_t (*read)(struct _dbridge_state *state,
00090 struct file *file,
00091 char *buf,
00092 size_t count,
00093 loff_t *ppos);
00094
00095 ssize_t (*write)(struct _dbridge_state *state,
00096 struct file *file,
00097 const char *buf,
00098 size_t count,
00099 loff_t *ppos);
00100
00101 int (*ioctl)(struct _dbridge_state *state,
00102 struct inode *inode,
00103 struct file *file,
00104 unsigned cmd,
00105 unsigned long arg);
00106
00107 int (*fasync)(struct _dbridge_state *state,
00108 int fd,
00109 struct file *file,
00110 int on);
00111
00112 unsigned (*poll)(struct _dbridge_state *state,
00113 struct file *file,
00114 poll_table *pt);
00115 } dbridge_ops_t;
00116
00117 typedef struct _dbridge_state {
00118
00119 dbridge_ops_t *ops;
00120 xnholder_t slink;
00121 xnholder_t alink;
00122 #define link2dbs(laddr,link) \
00123 ((struct _dbridge_state *)(((char *)laddr) - (int)(&((struct _dbridge_state *)0)->link)))
00124
00125 union {
00126 struct {
00127 xnqueue_t inq;
00128 xnqueue_t outq;
00129 dbridge_io_handler *o_handler;
00130 dbridge_io_handler *i_handler;
00131 dbridge_alloc_handler *alloc_handler;
00132 xnsynch_t synchbase;
00133 void *cookie;
00134 } mq;
00135
00136 struct {
00137 unsigned long events;
00138 xnsynch_t synchbase;
00139 } ev;
00140 } u;
00141
00142
00143 int status;
00144 struct semaphore open_sem;
00145 struct semaphore send_sem;
00146 struct semaphore event_sem;
00147 struct semaphore *wchan;
00148 struct fasync_struct *asyncq;
00149 wait_queue_head_t pollq;
00150
00151 } dbridge_state_t;
00152
00153 extern dbridge_state_t dbridge_states[];
00154
00155 #define minor_from_state(s) (s - dbridge_states)
00156
00157 static inline void dbridge_schedule_request (void) {
00158 extern unsigned dbridge_wakeup_srq;
00159 rt_pend_linux_srq(dbridge_wakeup_srq);
00160 }
00161
00162 #ifdef __cplusplus
00163 extern "C" {
00164 #endif
00165
00166 void dbridge_enqueue_wait(dbridge_state_t *state,
00167 struct semaphore *wchan,
00168 int flags);
00169
00170 void dbridge_dequeue_wait(dbridge_state_t *state,
00171 int flags);
00172
00173
00174
00175 void dbridge_msetup(dbridge_session_handler *open_handler,
00176 dbridge_session_handler *close_handler);
00177
00178 int dbridge_mconnect(int minor,
00179 dbridge_io_handler *o_handler,
00180 dbridge_io_handler *i_handler,
00181 dbridge_alloc_handler *alloc_handler,
00182 void *cookie);
00183
00184 int dbridge_mdisconnect(int minor);
00185
00186 ssize_t dbridge_msend(int minor,
00187 struct dbridge_mh *mh,
00188 size_t size,
00189 int flags);
00190
00191 ssize_t dbridge_mrecv(int minor,
00192 struct dbridge_mh **pmh,
00193 xntime_t timeout);
00194
00195 int dbridge_minquire(int minor);
00196
00197 #ifdef __cplusplus
00198 }
00199 #endif
00200
00201 static inline xnholder_t *dbridge_m_link(dbridge_mh_t *mh) {
00202 return &mh->link;
00203 }
00204
00205 #else
00206
00207 typedef struct dbridge_mh {
00208
00209 char __opaque[8];
00210 unsigned size;
00211
00212 } dbridge_mh_t;
00213
00214 #endif
00215
00216 static inline char *dbridge_m_data(dbridge_mh_t *mh) {
00217 return (char *)(mh + 1);
00218 }
00219
00220 #define dbridge_m_size(mh) ((mh)->size)
00221
00222 #endif