Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / sys / device.h
CommitLineData
335dda38 1/*
8c10bfcf
MD
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 *
335dda38
MD
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
8c10bfcf 10 *
335dda38
MD
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
8c10bfcf
MD
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
335dda38 32 * SUCH DAMAGE.
8c10bfcf 33 *
b13267a5 34 * $DragonFly: src/sys/sys/device.h,v 1.7 2006/09/10 01:26:40 dillon Exp $
335dda38
MD
35 */
36
37#ifndef _SYS_DEVICE_H_
38#define _SYS_DEVICE_H_
39
1bd40720
MD
40#ifndef _SYS_TYPES_H_
41#include <sys/types.h>
42#endif
fef8985e
MD
43#ifndef _SYS_SYSLINK_H_
44#include <sys/syslink.h>
335dda38
MD
45#endif
46
b13267a5
MD
47struct cdev;
48
335dda38 49/*
fef8985e 50 * This structure is at the base of every device args structure
335dda38 51 */
fef8985e
MD
52struct dev_generic_args {
53 struct syslink_desc *a_desc;
b13267a5 54 struct cdev *a_dev;
335dda38
MD
55};
56
fef8985e
MD
57typedef struct dev_generic_args dev_default_args;
58
335dda38 59/*
b13267a5 60 * int d_open(cdev_t dev, int oflags, int devtype, struct ucred *cred)
335dda38 61 */
fef8985e
MD
62struct dev_open_args {
63 struct dev_generic_args a_head;
64 int a_oflags;
65 int a_devtype;
66 struct ucred *a_cred;
335dda38
MD
67};
68
69/*
b13267a5 70 * int d_close(cdev_t dev, int fflag, int devtype)
335dda38 71 */
fef8985e
MD
72struct dev_close_args {
73 struct dev_generic_args a_head;
74 int a_fflag;
75 int a_devtype;
335dda38
MD
76};
77
78/*
b13267a5 79 * int d_read(cdev_t dev, struct uio *uio, int ioflag)
335dda38 80 */
fef8985e
MD
81struct dev_read_args {
82 struct dev_generic_args a_head;
83 struct uio *a_uio;
84 int a_ioflag;
335dda38
MD
85};
86
87/*
b13267a5 88 * int d_write(cdev_t dev, struct uio *uio, int ioflag)
335dda38 89 */
fef8985e
MD
90struct dev_write_args {
91 struct dev_generic_args a_head;
92 struct uio *a_uio;
93 int a_ioflag;
335dda38
MD
94};
95
96/*
b13267a5 97 * int d_ioctl(cdev_t dev, u_long cmd, caddr_t data, int fflag,
fef8985e 98 * struct ucred *cred)
335dda38 99 */
fef8985e
MD
100struct dev_ioctl_args {
101 struct dev_generic_args a_head;
102 u_long a_cmd;
103 caddr_t a_data;
104 int a_fflag;
105 struct ucred *a_cred;
335dda38
MD
106};
107
108/*
b13267a5 109 * int d_poll(cdev_t dev, int events)
335dda38 110 */
fef8985e
MD
111struct dev_poll_args {
112 struct dev_generic_args a_head;
113 int a_events;
335dda38
MD
114};
115
116/*
b13267a5 117 * int d_mmap(cdev_t dev, vm_offset_t offset, int nprot)
335dda38 118 */
fef8985e
MD
119struct dev_mmap_args {
120 struct dev_generic_args a_head;
121 vm_offset_t a_offset;
122 int a_nprot;
123 int a_result; /* page number */
335dda38
MD
124};
125
126/*
b13267a5 127 * void d_strategy(cdev_t dev, struct bio *bio)
335dda38 128 */
fef8985e
MD
129struct dev_strategy_args {
130 struct dev_generic_args a_head;
131 struct bio *a_bio;
335dda38
MD
132};
133
134/*
b13267a5 135 * void d_dump(cdev_t dev)
335dda38 136 */
fef8985e
MD
137struct dev_dump_args {
138 struct dev_generic_args a_head;
139 u_int a_count;
140 u_int a_blkno;
141 u_int a_secsize;
142};
143
144/*
b13267a5 145 * int d_psize(cdev_t dev)
fef8985e
MD
146 */
147struct dev_psize_args {
148 struct dev_generic_args a_head;
149 int a_result;
335dda38
MD
150};
151
152/*
b13267a5 153 * int d_kqfilter(cdev_t dev, struct knote *kn)
335dda38 154 */
fef8985e
MD
155struct dev_kqfilter_args {
156 struct dev_generic_args a_head;
157 struct knote *a_kn;
158 int a_result;
159};
160
161struct dev_clone_args {
162 struct dev_generic_args a_head;
335dda38
MD
163};
164
165/*
fef8985e
MD
166 * Typedefs to help drivers declare the driver routines and such
167 */
168typedef int d_default_t (struct dev_generic_args *ap);
169typedef int d_open_t (struct dev_open_args *ap);
170typedef int d_close_t (struct dev_close_args *ap);
171typedef int d_read_t (struct dev_read_args *ap);
172typedef int d_write_t (struct dev_write_args *ap);
173typedef int d_ioctl_t (struct dev_ioctl_args *ap);
174typedef int d_poll_t (struct dev_poll_args *ap);
175typedef int d_mmap_t (struct dev_mmap_args *ap);
176typedef int d_strategy_t (struct dev_strategy_args *ap);
177typedef int d_dump_t (struct dev_dump_args *ap);
178typedef int d_psize_t (struct dev_psize_args *ap);
179typedef int d_kqfilter_t (struct dev_kqfilter_args *ap);
180typedef int d_clone_t (struct dev_clone_args *ap);
181
182/*
183 * Character device switch table.
184 *
185 * NOTE: positions are hard coded for static structure initialization.
186 */
187struct dev_ops {
188 struct {
189 const char *name; /* base name, e.g. 'da' */
190 int maj; /* major device number */
191 u_int flags; /* D_XXX flags */
192 void *data; /* custom driver data */
193 int refs; /* ref count */
194 } head;
195
196#define dev_ops_first_field d_default
197 d_default_t *d_default;
198 d_open_t *d_open;
199 d_close_t *d_close;
200 d_read_t *d_read;
201 d_write_t *d_write;
202 d_ioctl_t *d_ioctl;
203 d_poll_t *d_poll;
204 d_mmap_t *d_mmap;
205 d_strategy_t *d_strategy;
206 d_dump_t *d_dump;
207 d_psize_t *d_psize;
208 d_kqfilter_t *d_kqfilter;
209 d_clone_t *d_clone; /* clone from base dev_ops */
210#define dev_ops_last_field d_clone
211};
212
213/*
214 * Types for d_flags.
335dda38 215 */
fef8985e
MD
216#define D_TAPE 0x0001
217#define D_DISK 0x0002
218#define D_TTY 0x0004
219#define D_MEM 0x0008
220
221#define D_TYPEMASK 0xffff
222
223/*
224 * Flags for d_flags.
225 */
226#define D_MEMDISK 0x00010000 /* memory type disk */
227#define D_NAGGED 0x00020000 /* nagged about missing make_dev() */
228#define D_CANFREE 0x00040000 /* can free blocks */
229#define D_TRACKCLOSE 0x00080000 /* track all closes */
230#define D_MASTER 0x00100000 /* used by pty/tty code */
231#define D_KQFILTER 0x00200000 /* has kqfilter entry */
232
233/*
234 * A union of all possible argument structures.
235 */
236union dev_args_union {
237 struct dev_generic_args du_head;
238 struct dev_open_args du_open;
239 struct dev_close_args du_close;
240 struct dev_read_args du_read;
241 struct dev_write_args du_write;
242 struct dev_ioctl_args du_ioctl;
243 struct dev_poll_args du_poll;
244 struct dev_mmap_args du_mmap;
245 struct dev_strategy_args du_strategy;
246 struct dev_dump_args du_dump;
247 struct dev_psize_args du_psize;
248 struct dev_kqfilter_args du_kqfilter;
249 struct dev_clone_args du_clone;
250};
251
252/*
253 * Linking structure for mask/match registration
254 */
255struct dev_ops_link {
256 struct dev_ops_link *next;
257 u_int mask;
258 u_int match;
259 struct dev_ops *ops;
260};
335dda38
MD
261
262#ifdef _KERNEL
263
fef8985e
MD
264extern struct dev_ops dead_dev_ops;
265
335dda38
MD
266struct disk;
267
b13267a5
MD
268int dev_dopen(cdev_t dev, int oflags, int devtype, struct ucred *cred);
269int dev_dclose(cdev_t dev, int fflag, int devtype);
270void dev_dstrategy(cdev_t dev, struct bio *bio);
271void dev_dstrategy_chain(cdev_t dev, struct bio *bio);
272int dev_dioctl(cdev_t dev, u_long cmd, caddr_t data, int fflag,
fef8985e 273 struct ucred *cred);
b13267a5
MD
274int dev_ddump(cdev_t dev);
275int dev_dpsize(cdev_t dev);
276int dev_dread(cdev_t dev, struct uio *uio, int ioflag);
277int dev_dwrite(cdev_t dev, struct uio *uio, int ioflag);
278int dev_dpoll(cdev_t dev, int events);
279int dev_dkqfilter(cdev_t dev, struct knote *kn);
280int dev_dmmap(cdev_t dev, vm_offset_t offset, int nprot);
281int dev_dclone(cdev_t dev);
282
283const char *dev_dname(cdev_t dev);
284int dev_dmaj(cdev_t dev);
285int dev_dflags(cdev_t dev);
fef8985e
MD
286int dev_doperate(struct dev_generic_args *ap);
287int dev_doperate_ops(struct dev_ops *, struct dev_generic_args *ap);
288
289d_default_t nodefault;
290d_open_t noopen;
291d_close_t noclose;
292d_read_t noread;
293d_write_t nowrite;
294d_ioctl_t noioctl;
295d_poll_t nopoll;
296d_mmap_t nommap;
297d_strategy_t nostrategy;
298d_dump_t nodump;
299d_psize_t nopsize;
300d_kqfilter_t nokqfilter;
301d_clone_t noclone;
302
303d_open_t nullopen;
304d_close_t nullclose;
305
306extern struct syslink_desc dev_default_desc;
307extern struct syslink_desc dev_open_desc;
308extern struct syslink_desc dev_close_desc;
309extern struct syslink_desc dev_read_desc;
310extern struct syslink_desc dev_write_desc;
311extern struct syslink_desc dev_ioctl_desc;
312extern struct syslink_desc dev_dump_desc;
313extern struct syslink_desc dev_psize_desc;
314extern struct syslink_desc dev_poll_desc;
315extern struct syslink_desc dev_mmap_desc;
316extern struct syslink_desc dev_strategu_desc;
317extern struct syslink_desc dev_kqfilter_desc;
318extern struct syslink_desc dev_clone_desc;
319
320void compile_dev_ops(struct dev_ops *);
321int dev_ops_add(struct dev_ops *, u_int mask, u_int match);
322int dev_ops_remove(struct dev_ops *, u_int mask, u_int match);
323void dev_ops_release(struct dev_ops *);
b13267a5 324struct dev_ops *dev_ops_add_override(cdev_t, struct dev_ops *, u_int, u_int);
fef8985e 325
b13267a5
MD
326struct dev_ops *dev_ops_intercept(cdev_t, struct dev_ops *);
327void dev_ops_restore(cdev_t, struct dev_ops *);
fef8985e
MD
328struct dev_ops *dev_ops_get(int x, int y);
329
330void destroy_all_devs(struct dev_ops *, u_int mask, u_int match);
b13267a5 331cdev_t make_dev(struct dev_ops *ops, int minor, uid_t uid, gid_t gid,
fef8985e 332 int perms, const char *fmt, ...) __printflike(6, 7);
b13267a5 333cdev_t make_adhoc_dev (struct dev_ops *ops, int minor);
335dda38 334
335dda38
MD
335#endif
336
337#endif
338