Split getsockopt() and setsockopt().
[dragonfly.git] / sys / sys / device.h
1 /*
2  * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $DragonFly: src/sys/sys/device.h,v 1.1 2003/07/22 17:03:34 dillon Exp $
27  */
28
29 #ifndef _SYS_DEVICE_H_
30 #define _SYS_DEVICE_H_
31
32 #ifndef _SYS_MSGPORT_H_
33 #include <sys/msgport.h>
34 #endif
35
36 /*
37  * This structure is at the base of every CDEVSW port message
38  */
39 struct cdevmsg  {
40     lwkt_msg    msg;
41     dev_t       dev;
42     struct cdevsw *csw;
43 };
44
45 /*
46  * int d_open(dev_t dev, int oflags, int devtype, thread_t td)
47  */
48 struct cdevmsg_open {
49     struct cdevmsg msg;
50     int         oflags;
51     int         devtype;
52     struct thread *td;
53 };
54
55 /*
56  * int d_close(dev_t dev, int fflag, int devtype, thread_t td)
57  */
58 struct cdevmsg_close {
59     struct cdevmsg msg;
60     int         fflag;
61     int         devtype;
62     struct thread *td;
63 };
64
65 /*
66  * void d_strategy(struct buf *bp)
67  */
68 struct cdevmsg_strategy {
69     struct cdevmsg msg;
70     struct buf  *bp;
71 };
72
73 /*
74  * int d_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td)
75  */
76 struct cdevmsg_ioctl {
77     struct cdevmsg msg;
78     u_long      cmd;
79     caddr_t     data;
80     int         fflag;
81     struct thread *td;
82 };
83
84 /*
85  * void d_dump(dev_t dev)
86  */
87 struct cdevmsg_dump {
88     struct cdevmsg msg;
89 };
90
91 /*
92  * int d_psize(dev_t dev)
93  */
94 struct cdevmsg_psize {
95     struct cdevmsg msg;
96     int         result;
97 };
98
99 /*
100  * int d_read(dev_t dev, struct uio *uio, int ioflag)
101  */
102 struct cdevmsg_read {
103     struct cdevmsg msg;
104     struct uio  *uio;
105     int         ioflag;
106 };
107
108 /*
109  * int d_write(dev_t dev, struct uio *uio, int ioflag)
110  */
111 struct cdevmsg_write {
112     struct cdevmsg msg;
113     struct uio  *uio;
114     int         ioflag;
115 };
116
117 /*
118  * int d_poll(dev_t dev, int events, thread_t td)
119  */
120 struct cdevmsg_poll {
121     struct cdevmsg msg;
122     int         events;
123     struct thread *td;
124 };
125
126 /*
127  * int d_kqfilter(dev_t dev, struct knote *kn)
128  */
129 struct cdevmsg_kqfilter {
130     struct cdevmsg msg;
131     struct knote *kn;
132     int         result;
133 };
134
135 /*
136  * int d_mmap(dev_t dev, vm_offset_t offset, int nprot)
137  */
138 struct cdevmsg_mmap {
139     struct cdevmsg msg;
140     vm_offset_t offset;
141     int         nprot;
142     int         result; /* page number */
143 };
144
145 union cdevallmsg {
146     struct lwkt_msg             am_lmsg;
147     struct cdevmsg              am_msg;
148     struct cdevmsg_open         am_open;
149     struct cdevmsg_close        am_close;
150     struct cdevmsg_strategy     am_strategy;
151     struct cdevmsg_ioctl        am_ioctl;
152     struct cdevmsg_dump         am_dump;
153     struct cdevmsg_psize        am_psize;
154     struct cdevmsg_read         am_read;
155     struct cdevmsg_write        am_write;
156     struct cdevmsg_poll         am_poll;
157     struct cdevmsg_kqfilter     am_kqfilter;
158     struct cdevmsg_mmap         am_mmap;
159 };
160
161 typedef union cdevallmsg *cdevallmsg_t;
162 typedef struct cdevmsg          *cdevmsg_t;
163 typedef struct cdevmsg_open     *cdevmsg_open_t;
164 typedef struct cdevmsg_close    *cdevmsg_close_t;
165 typedef struct cdevmsg_strategy *cdevmsg_strategy_t;
166 typedef struct cdevmsg_ioctl    *cdevmsg_ioctl_t;
167 typedef struct cdevmsg_dump     *cdevmsg_dump_t;
168 typedef struct cdevmsg_psize    *cdevmsg_psize_t;
169 typedef struct cdevmsg_read     *cdevmsg_read_t;
170 typedef struct cdevmsg_write    *cdevmsg_write_t;
171 typedef struct cdevmsg_poll     *cdevmsg_poll_t;
172 typedef struct cdevmsg_kqfilter *cdevmsg_kqfilter_t;
173 typedef struct cdevmsg_mmap     *cdevmsg_mmap_t;
174
175 #define CDEV_CMD_OPEN           (MSG_CMD_CDEV|0x0001)
176 #define CDEV_CMD_CLOSE          (MSG_CMD_CDEV|0x0002)
177 #define CDEV_CMD_STRATEGY       (MSG_CMD_CDEV|0x0003)
178 #define CDEV_CMD_IOCTL          (MSG_CMD_CDEV|0x0004)
179 #define CDEV_CMD_DUMP           (MSG_CMD_CDEV|0x0005)
180 #define CDEV_CMD_PSIZE          (MSG_CMD_CDEV|0x0006)
181 #define CDEV_CMD_READ           (MSG_CMD_CDEV|0x0007)
182 #define CDEV_CMD_WRITE          (MSG_CMD_CDEV|0x0008)
183 #define CDEV_CMD_POLL           (MSG_CMD_CDEV|0x0009)
184 #define CDEV_CMD_KQFILTER       (MSG_CMD_CDEV|0x000A)
185 #define CDEV_CMD_MMAP           (MSG_CMD_CDEV|0x000B)
186
187 #ifdef _KERNEL
188
189 struct disk;
190
191 const char *dev_dname(dev_t dev);
192 struct lwkt_port *dev_dport(dev_t dev);
193 int dev_dflags(dev_t dev);
194 int dev_dmaj(dev_t dev);
195 int dev_dopen(dev_t dev, int oflags, int devtype, struct thread *td);
196 int dev_dclose(dev_t dev, int fflag, int devtype, struct thread *td);
197 void dev_dstrategy(dev_t dev, struct buf *bp);
198 int dev_dioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td);
199 int dev_ddump(dev_t dev);
200 int dev_dpsize(dev_t dev);
201 int dev_dread(dev_t dev, struct uio *uio, int ioflag);
202 int dev_dwrite(dev_t dev, struct uio *uio, int ioflag);
203 int dev_dpoll(dev_t dev, int events, struct thread *td);
204 int dev_dkqfilter(dev_t dev, struct knote *kn);
205 int dev_dmmap(dev_t dev, vm_offset_t offset, int nprot);
206
207 int dev_port_dopen(lwkt_port_t port, dev_t dev, int oflags, int devtype, struct thread *td);
208 int dev_port_dclose(lwkt_port_t port, dev_t dev, int fflag, int devtype, struct thread *td);
209 void dev_port_dstrategy(lwkt_port_t port, dev_t dev, struct buf *bp);
210 int dev_port_dioctl(lwkt_port_t port, dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td);
211 int dev_port_ddump(lwkt_port_t port, dev_t dev);
212 int dev_port_dpsize(lwkt_port_t port, dev_t dev);
213 int dev_port_dread(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag);
214 int dev_port_dwrite(lwkt_port_t port, dev_t dev, struct uio *uio, int ioflag);
215 int dev_port_dpoll(lwkt_port_t port, dev_t dev, int events, struct thread *td);
216 int dev_port_dkqfilter(lwkt_port_t port, dev_t dev, struct knote *kn);
217 int dev_port_dmmap(lwkt_port_t port, dev_t dev, vm_offset_t offset, int nprot);
218
219 #endif
220
221 #endif
222