xref: /xnu-11215.81.4/bsd/sys/conf.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1 /*
2  * Copyright (c) 2000-2012 Apple Computer, Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29 /*-
30  * Copyright (c) 1990, 1993
31  *	The Regents of the University of California.  All rights reserved.
32  * (c) UNIX System Laboratories, Inc.
33  * All or some portions of this file are derived from material licensed
34  * to the University of California by American Telephone and Telegraph
35  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36  * the permission of UNIX System Laboratories, Inc.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed by the University of
49  *	California, Berkeley and its contributors.
50  * 4. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *	@(#)conf.h	8.5 (Berkeley) 1/9/95
67  */
68 
69 #ifndef _SYS_CONF_H_
70 #define _SYS_CONF_H_ 1
71 
72 #include <sys/appleapiopts.h>
73 #include <sys/cdefs.h>
74 #include <sys/queue.h>
75 #include <stdint.h>
76 
77 /*
78  * Definitions of device driver entry switches
79  */
80 
81 struct buf;
82 struct proc;
83 struct tty;
84 struct uio;
85 struct vnode;
86 
87 /*
88  * Types for d_type.
89  * These are returned by ioctl FIODTYPE
90  */
91 #define D_TAPE  1
92 #define D_DISK  2
93 #define D_TTY   3
94 
95 #ifdef KERNEL
96 /*
97  * Device switch function types.
98  */
99 typedef int  open_close_fcn_t(dev_t dev, int flags, int devtype,
100     struct proc *p);
101 
102 typedef struct tty *d_devtotty_t(dev_t dev);
103 
104 typedef void strategy_fcn_t(struct buf *bp);
105 typedef int  ioctl_fcn_t(dev_t dev, u_long cmd,
106     caddr_t __sized_by(IOCPARM_LEN(cmd)) data,
107     int fflag, struct proc *p);
108 typedef int  dump_fcn_t(void);     /* parameters vary by architecture */
109 typedef int  psize_fcn_t(dev_t dev);
110 typedef int  read_write_fcn_t(dev_t dev, struct uio *uio, int ioflag);
111 typedef int  stop_fcn_t(struct tty *tp, int rw);
112 typedef int  reset_fcn_t(int uban);
113 typedef int  select_fcn_t(dev_t dev, int which, void * wql, struct proc *p);
114 typedef int  mmap_fcn_t(void);
115 typedef int  rsvd_fcn_t(void);
116 
117 typedef void empty_fcn_t(void);
118 
119 #define d_open_t        open_close_fcn_t
120 #define d_close_t       open_close_fcn_t
121 #define d_read_t        read_write_fcn_t
122 #define d_write_t       read_write_fcn_t
123 #define d_ioctl_t       ioctl_fcn_t
124 #define d_stop_t        stop_fcn_t
125 #define d_reset_t       reset_fcn_t
126 #define d_select_t      select_fcn_t
127 #define d_mmap_t        mmap_fcn_t
128 #define d_strategy_t    strategy_fcn_t
129 
130 
131 __BEGIN_DECLS
132 int             enodev(void);
133 void    enodev_strat(void);
134 __END_DECLS
135 
136 /*
137  * Versions of enodev() pointer, cast to appropriate function type. For use
138  * in empty devsw slots.
139  */
140 #define eno_opcl                ((open_close_fcn_t *)(empty_fcn_t*)&enodev)
141 #define eno_strat               ((strategy_fcn_t *)(empty_fcn_t*)&enodev_strat)
142 #define eno_ioctl               ((ioctl_fcn_t *)(empty_fcn_t*)&enodev)
143 #define eno_dump                ((dump_fcn_t *)(empty_fcn_t*)&enodev)
144 #define eno_psize               ((psize_fcn_t *)(empty_fcn_t*)&enodev)
145 #define eno_rdwrt               ((read_write_fcn_t *)(empty_fcn_t*)&enodev)
146 #define eno_stop                ((stop_fcn_t *)(empty_fcn_t*)&enodev)
147 #define eno_reset               ((reset_fcn_t *)(empty_fcn_t*)&enodev)
148 #define eno_mmap                ((mmap_fcn_t *)(empty_fcn_t*)&enodev)
149 #define eno_select              ((select_fcn_t *)(empty_fcn_t*)&enodev)
150 
151 /* For source backward compatibility only! */
152 #define eno_getc                ((rsvd_fcn_t *)&enodev)
153 #define eno_putc                ((rsvd_fcn_t *)&enodev)
154 
155 /*
156  * Block device switch table
157  */
158 struct bdevsw {
159 	open_close_fcn_t        *d_open;
160 	open_close_fcn_t        *d_close;
161 	strategy_fcn_t          *d_strategy;
162 	ioctl_fcn_t             *d_ioctl;
163 	dump_fcn_t              *d_dump;
164 	psize_fcn_t             *d_psize;
165 	int                     d_type;
166 };
167 
168 
169 d_devtotty_t    nodevtotty;
170 d_write_t       nowrite;
171 
172 #ifdef KERNEL_PRIVATE
173 extern struct bdevsw bdevsw[];
174 extern int (*bootcache_contains_block)(dev_t device, u_int64_t blkno);
175 #endif /* KERNEL_PRIVATE */
176 
177 /*
178  * Contents of empty bdevsw slot.
179  */
180 #define  NO_BDEVICE                                             \
181 	{ eno_opcl,	eno_opcl,	eno_strat, eno_ioctl,   \
182 	  eno_dump,	eno_psize,	0       }
183 
184 
185 /*
186  * Character device switch table
187  */
188 struct cdevsw {
189 	open_close_fcn_t        *d_open;
190 	open_close_fcn_t        *d_close;
191 	read_write_fcn_t        *d_read;
192 	read_write_fcn_t        *d_write;
193 	ioctl_fcn_t             *d_ioctl;
194 	stop_fcn_t              *d_stop;
195 	reset_fcn_t             *d_reset;
196 	struct  tty             **d_ttys;
197 	select_fcn_t            *d_select;
198 	mmap_fcn_t              *d_mmap;
199 	strategy_fcn_t          *d_strategy;
200 	rsvd_fcn_t              *d_reserved_1;
201 	rsvd_fcn_t              *d_reserved_2;
202 	int                     d_type;
203 };
204 
205 #ifdef BSD_KERNEL_PRIVATE
206 
207 extern uint64_t cdevsw_flags[];
208 #define CDEVSW_SELECT_KQUEUE 0x01
209 #define CDEVSW_USE_OFFSET    0x02
210 #define CDEVSW_IS_PTC        0x04
211 #define CDEVSW_IS_PTS        0x08
212 
213 struct thread;
214 #endif /* BSD_KERNEL_PRIVATE */
215 
216 
217 /*
218  * Contents of empty cdevsw slot.
219  */
220 
221 #define  NO_CDEVICE                                                      \
222     {                                                                   \
223 	eno_opcl,	eno_opcl,	eno_rdwrt,	eno_rdwrt,      \
224 	eno_ioctl,	eno_stop,	eno_reset,	0,              \
225 	(select_fcn_t *)(void (*)(void))seltrue,	eno_mmap,       \
226 	eno_strat,	eno_getc,                                       \
227 	eno_putc,	0                                               \
228     }
229 
230 #endif /* KERNEL */
231 
232 #ifdef  KERNEL_PRIVATE
233 typedef int  l_open_t (dev_t dev, struct tty *tp);
234 typedef int  l_close_t(struct tty *tp, int flags);
235 typedef int  l_read_t (struct tty *tp, struct uio *uio, int flag);
236 typedef int  l_write_t(struct tty *tp, struct uio *uio, int flag);
237 typedef int  l_ioctl_t(struct tty *tp, u_long cmd, caddr_t data, int flag,
238     struct proc *p);
239 typedef int  l_rint_t (int c, struct tty *tp);
240 typedef void l_start_t(struct tty *tp);
241 typedef int  l_modem_t(struct tty *tp, int flag);
242 
243 /*
244  * Line discipline switch table
245  */
246 struct linesw {
247 	l_open_t        *l_open;
248 	l_close_t       *l_close;
249 	l_read_t        *l_read;
250 	l_write_t       *l_write;
251 	l_ioctl_t       *l_ioctl;
252 	l_rint_t        *l_rint;
253 	l_start_t       *l_start;
254 	l_modem_t       *l_modem;
255 };
256 
257 
258 extern struct linesw linesw[];
259 extern const int nlinesw;
260 
261 int ldisc_register(int, struct linesw *);
262 void ldisc_deregister(int);
263 #define LDISC_LOAD      -1              /* Loadable line discipline */
264 
265 #endif /* KERNEL_PRIVATE */
266 
267 #ifdef BSD_KERNEL_PRIVATE
268 /*
269  * Swap device table
270  */
271 struct swdevt {
272 	dev_t   sw_dev;
273 	int     sw_flags;
274 	int     sw_nblks;
275 	struct  vnode *sw_vp;
276 };
277 #define SW_FREED        0x01
278 #define SW_SEQUENTIAL   0x02
279 #define sw_freed        sw_flags        /* XXX compat */
280 
281 extern struct swdevt swdevt[];
282 
283 #endif /* BSD_KERNEL_PRIVATE */
284 
285 
286 #ifdef KERNEL
287 /*
288  * ***_free finds free slot;
289  * ***_add adds entries to the devsw table
290  * If int arg is -1; finds a free slot
291  * Returns the major number if successful
292  *  else -1
293  */
294 __BEGIN_DECLS
295 #ifdef KERNEL_PRIVATE
296 extern struct cdevsw cdevsw[];
297 extern int cdevsw_setkqueueok(int, const struct cdevsw*, int);
298 #endif /* KERNEL_PRIVATE */
299 
300 #ifdef BSD_KERNEL_PRIVATE
301 extern void devsw_lock(dev_t, int);
302 extern void devsw_unlock(dev_t, int);
303 #endif /* BSD_KERNEL_PRIVATE */
304 
305 int  bdevsw_isfree(int);
306 int  bdevsw_add(int, const struct bdevsw *);
307 int  bdevsw_remove(int, const struct bdevsw *);
308 int  cdevsw_isfree(int);
309 int  cdevsw_add(int, const struct cdevsw *);
310 int  cdevsw_add_with_bdev(int index, const struct cdevsw * csw, int bdev);
311 int  cdevsw_remove(int, const struct cdevsw *);
312 int  isdisk(dev_t, int);
313 __END_DECLS
314 #endif /* KERNEL */
315 
316 #endif /* _SYS_CONF_H_ */
317