DEV messaging stage 2/4: In this stage all DEV commands are now being
[dragonfly.git] / sys / sys / msgport.h
1 /*
2  * SYS/MSGPORT.H
3  *
4  *      Implements LWKT messages and ports.
5  * 
6  * $DragonFly: src/sys/sys/msgport.h,v 1.2 2003/07/22 17:03:34 dillon Exp $
7  */
8
9 #ifndef _SYS_MSGPORT_H_
10 #define _SYS_MSGPORT_H_
11
12 #ifndef _SYS_QUEUE_H_
13 #include <sys/queue.h>          /* TAILQ_* macros */
14 #endif
15
16 struct lwkt_msg;
17 struct lwkt_port;
18 struct thread;
19
20 typedef struct lwkt_msg         *lwkt_msg_t;
21 typedef struct lwkt_port        *lwkt_port_t;
22
23 typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue;
24
25 /*
26  * The standard message and port structure for communications between
27  * threads.  See kern/lwkt_msgport.c for documentation on how messages and
28  * ports work.
29  */
30 typedef struct lwkt_msg {
31     TAILQ_ENTRY(lwkt_msg) ms_node;      /* link node (not always used) */
32     lwkt_port_t ms_target_port;         /* only used in certain situations */
33     lwkt_port_t ms_reply_port;          /* asynch replies returned here */
34     int         ms_abortreq;            /* set asynchronously */
35     int         ms_cmd;
36     int         ms_flags;
37     int         ms_error;
38 } lwkt_msg;
39
40 #define MSGF_DONE       0x0001          /* asynch message is complete */
41 #define MSGF_REPLY      0x0002          /* asynch message has been returned */
42 #define MSGF_QUEUED     0x0004          /* message has been queued sanitychk */
43 #define MSGF_ASYNC      0x0008          /* sync/async hint */
44
45 #define MSG_CMD_CDEV    0x00010000
46 #define MSG_CMD_VFS     0x00020000
47 #define MSG_CMD_SYSCALL 0x00030000
48 #define MSG_SUBCMD_MASK 0x0000FFFF
49
50 typedef struct lwkt_port {
51     lwkt_msg_queue      mp_msgq;
52     int                 mp_flags;
53     struct thread       *mp_td;
54     int                 (*mp_beginmsg)(lwkt_port_t port, lwkt_msg_t msg);
55     void                (*mp_abortmsg)(lwkt_port_t port, lwkt_msg_t msg);
56     void                (*mp_returnmsg)(lwkt_port_t port, lwkt_msg_t msg);
57 } lwkt_port;
58
59 #define MSGPORTF_WAITING        0x0001
60
61 #ifdef _KERNEL
62
63 extern void lwkt_init_port(lwkt_port_t port, struct thread *td);
64 extern void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg);
65 extern int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg);
66 extern int lwkt_waitmsg(lwkt_msg_t msg);
67 extern void lwkt_replyport(lwkt_port_t port, lwkt_msg_t msg);
68 extern void lwkt_abortport(lwkt_port_t port, lwkt_msg_t msg);
69 extern int lwkt_putport(lwkt_port_t port, lwkt_msg_t msg);
70 extern void *lwkt_getport(lwkt_port_t port);
71 extern void *lwkt_waitport(lwkt_port_t port);
72
73 #endif
74
75 #endif