xref: /dragonfly/sys/sys/device.h (revision 1ab20d67)
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.2 2004/05/19 22:53:02 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 };
43 
44 /*
45  * int d_open(dev_t dev, int oflags, int devtype, thread_t td)
46  */
47 struct cdevmsg_open {
48     struct cdevmsg msg;
49     int		oflags;
50     int		devtype;
51     struct thread *td;
52 };
53 
54 /*
55  * int d_close(dev_t dev, int fflag, int devtype, thread_t td)
56  */
57 struct cdevmsg_close {
58     struct cdevmsg msg;
59     int		fflag;
60     int		devtype;
61     struct thread *td;
62 };
63 
64 /*
65  * void d_strategy(struct buf *bp)
66  */
67 struct cdevmsg_strategy {
68     struct cdevmsg msg;
69     struct buf	*bp;
70 };
71 
72 /*
73  * int d_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, thread_t td)
74  */
75 struct cdevmsg_ioctl {
76     struct cdevmsg msg;
77     u_long	cmd;
78     caddr_t	data;
79     int		fflag;
80     struct thread *td;
81 };
82 
83 /*
84  * void d_dump(dev_t dev)
85  */
86 struct cdevmsg_dump {
87     struct cdevmsg msg;
88     u_int count;
89     u_int blkno;
90     u_int secsize;
91 };
92 
93 /*
94  * int d_psize(dev_t dev)
95  */
96 struct cdevmsg_psize {
97     struct cdevmsg msg;
98     int		result;
99 };
100 
101 /*
102  * int d_read(dev_t dev, struct uio *uio, int ioflag)
103  */
104 struct cdevmsg_read {
105     struct cdevmsg msg;
106     struct uio 	*uio;
107     int		ioflag;
108 };
109 
110 /*
111  * int d_write(dev_t dev, struct uio *uio, int ioflag)
112  */
113 struct cdevmsg_write {
114     struct cdevmsg msg;
115     struct uio 	*uio;
116     int		ioflag;
117 };
118 
119 /*
120  * int d_poll(dev_t dev, int events, thread_t td)
121  */
122 struct cdevmsg_poll {
123     struct cdevmsg msg;
124     int		events;
125     struct thread *td;
126 };
127 
128 /*
129  * int d_kqfilter(dev_t dev, struct knote *kn)
130  */
131 struct cdevmsg_kqfilter {
132     struct cdevmsg msg;
133     struct knote *kn;
134     int		result;
135 };
136 
137 /*
138  * int d_mmap(dev_t dev, vm_offset_t offset, int nprot)
139  */
140 struct cdevmsg_mmap {
141     struct cdevmsg msg;
142     vm_offset_t	offset;
143     int		nprot;
144     int		result;	/* page number */
145 };
146 
147 union cdevallmsg {
148     struct lwkt_msg		am_lmsg;
149     struct cdevmsg 		am_msg;
150     struct cdevmsg_open		am_open;
151     struct cdevmsg_close	am_close;
152     struct cdevmsg_strategy	am_strategy;
153     struct cdevmsg_ioctl	am_ioctl;
154     struct cdevmsg_dump		am_dump;
155     struct cdevmsg_psize	am_psize;
156     struct cdevmsg_read		am_read;
157     struct cdevmsg_write	am_write;
158     struct cdevmsg_poll		am_poll;
159     struct cdevmsg_kqfilter	am_kqfilter;
160     struct cdevmsg_mmap		am_mmap;
161 };
162 
163 typedef union cdevallmsg *cdevallmsg_t;
164 typedef struct cdevmsg		*cdevmsg_t;
165 typedef struct cdevmsg_open	*cdevmsg_open_t;
166 typedef struct cdevmsg_close	*cdevmsg_close_t;
167 typedef struct cdevmsg_strategy	*cdevmsg_strategy_t;
168 typedef struct cdevmsg_ioctl	*cdevmsg_ioctl_t;
169 typedef struct cdevmsg_dump	*cdevmsg_dump_t;
170 typedef struct cdevmsg_psize	*cdevmsg_psize_t;
171 typedef struct cdevmsg_read	*cdevmsg_read_t;
172 typedef struct cdevmsg_write	*cdevmsg_write_t;
173 typedef struct cdevmsg_poll	*cdevmsg_poll_t;
174 typedef struct cdevmsg_kqfilter	*cdevmsg_kqfilter_t;
175 typedef struct cdevmsg_mmap	*cdevmsg_mmap_t;
176 
177 #define CDEV_CMD_OPEN		(MSG_CMD_CDEV|0x0001)
178 #define CDEV_CMD_CLOSE		(MSG_CMD_CDEV|0x0002)
179 #define CDEV_CMD_STRATEGY	(MSG_CMD_CDEV|0x0003)
180 #define CDEV_CMD_IOCTL		(MSG_CMD_CDEV|0x0004)
181 #define CDEV_CMD_DUMP		(MSG_CMD_CDEV|0x0005)
182 #define CDEV_CMD_PSIZE		(MSG_CMD_CDEV|0x0006)
183 #define CDEV_CMD_READ		(MSG_CMD_CDEV|0x0007)
184 #define CDEV_CMD_WRITE		(MSG_CMD_CDEV|0x0008)
185 #define CDEV_CMD_POLL		(MSG_CMD_CDEV|0x0009)
186 #define CDEV_CMD_KQFILTER	(MSG_CMD_CDEV|0x000A)
187 #define CDEV_CMD_MMAP		(MSG_CMD_CDEV|0x000B)
188 
189 #ifdef _KERNEL
190 
191 struct disk;
192 
193 const char *dev_dname(dev_t dev);
194 struct lwkt_port *dev_dport(dev_t dev);
195 int dev_dflags(dev_t dev);
196 int dev_dmaj(dev_t dev);
197 int dev_dopen(dev_t dev, int oflags, int devtype, struct thread *td);
198 int dev_dclose(dev_t dev, int fflag, int devtype, struct thread *td);
199 void dev_dstrategy(dev_t dev, struct buf *bp);
200 int dev_dioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td);
201 int dev_ddump(dev_t dev);
202 int dev_dpsize(dev_t dev);
203 int dev_dread(dev_t dev, struct uio *uio, int ioflag);
204 int dev_dwrite(dev_t dev, struct uio *uio, int ioflag);
205 int dev_dpoll(dev_t dev, int events, struct thread *td);
206 int dev_dkqfilter(dev_t dev, struct knote *kn);
207 int dev_dmmap(dev_t dev, vm_offset_t offset, int nprot);
208 
209 #endif
210 
211 #endif
212 
213