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