]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/arm64/conf.c
xnu-6153.61.1.tar.gz
[apple/xnu.git] / bsd / dev / arm64 / conf.c
CommitLineData
5ba3f43e
A
1/*
2 * Copyright (c) 2000-2017 Apple Inc. All rights reserved.
3 */
4/*
5 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
6 * Copyright (c) 1993 NeXT Computer, Inc.
7 *
8 * UNIX Device switch tables.
9 *
10 * HISTORY
11 *
12 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
13 * enabled file descriptor pseudo-device.
14 * 18 June 1993 ? at NeXT
15 * Cleaned up a lot of stuff in this file.
16 */
17
18#include <sys/param.h>
19#include <sys/systm.h>
20#include <sys/ioctl.h>
21#include <sys/tty.h>
22#include <sys/conf.h>
23
24/* Prototypes that should be elsewhere: */
25extern dev_t chrtoblk(dev_t dev);
26extern int chrtoblk_set(int cdev, int bdev);
27
28struct bdevsw bdevsw[] =
29{
30 /*
31 * For block devices, every other block of 8 slots is reserved to Apple.
32 * The other slots are available for the user. This way we can both
33 * add new entries without running into each other. Be sure to fill in
34 * Apple's 8 reserved slots when you jump over us -- we'll do the same
35 * for you.
36 */
37
38 /* 0 - 7 are reserved to Apple */
39
0a7de745
A
40 NO_BDEVICE, /* 0 */
41 NO_BDEVICE, /* 1 */
42 NO_BDEVICE, /* 2 */
43 NO_BDEVICE, /* 3 */
44 NO_BDEVICE, /* 4 */
45 NO_BDEVICE, /* 5 */
46 NO_BDEVICE, /* 6 */
47 NO_BDEVICE, /* 7 */
5ba3f43e
A
48
49 /* 8 - 15 are reserved to the user */
0a7de745
A
50 NO_BDEVICE, /* 8 */
51 NO_BDEVICE, /* 9 */
52 NO_BDEVICE, /* 10 */
53 NO_BDEVICE, /* 11 */
54 NO_BDEVICE, /* 12 */
55 NO_BDEVICE, /* 13 */
56 NO_BDEVICE, /* 14 */
57 NO_BDEVICE, /* 15 */
5ba3f43e
A
58
59 /* 16 - 23 are reserved to Apple */
0a7de745
A
60 NO_BDEVICE, /* 16 */
61 NO_BDEVICE, /* 17 */
62 NO_BDEVICE, /* 18 */
63 NO_BDEVICE, /* 18 */
64 NO_BDEVICE, /* 20 */
65 NO_BDEVICE, /* 21 */
66 NO_BDEVICE, /* 22 */
67 NO_BDEVICE, /* 23 */
5ba3f43e
A
68};
69
70const int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
71
72extern struct tty *km_tty[];
73extern d_open_t cnopen;
74extern d_close_t cnclose;
75extern d_read_t cnread;
76extern d_write_t cnwrite;
77extern d_ioctl_t cnioctl;
78extern d_select_t cnselect;
79extern d_open_t kmopen;
80extern d_close_t kmclose;
81extern d_read_t kmread;
82extern d_write_t kmwrite;
83extern d_ioctl_t kmioctl;
84extern d_open_t sgopen;
85extern d_close_t sgclose;
86extern d_ioctl_t sgioctl;
87
88#if NVOL > 0
89extern d_open_t volopen;
90extern d_close_t volclose;
91extern d_ioctl_t volioctl;
92#else
0a7de745
A
93#define volopen eno_opcl
94#define volclose eno_opcl
95#define volioctl eno_ioctl
5ba3f43e
A
96#endif
97
98extern d_open_t cttyopen;
99extern d_read_t cttyread;
100extern d_write_t cttywrite;
101extern d_ioctl_t cttyioctl;
102extern d_select_t cttyselect;
103
104extern d_read_t mmread;
105extern d_write_t mmwrite;
106extern d_ioctl_t mmioctl;
0a7de745
A
107#define mmselect (select_fcn_t *)seltrue
108#define mmmmap eno_mmap
5ba3f43e
A
109
110#include <pty.h>
111#if NPTY > 0
112extern d_open_t ptsopen;
113extern d_close_t ptsclose;
114extern d_read_t ptsread;
115extern d_write_t ptswrite;
116extern d_select_t ptsselect;
117extern d_stop_t ptsstop;
118extern d_open_t ptcopen;
119extern d_close_t ptcclose;
120extern d_read_t ptcread;
121extern d_write_t ptcwrite;
122extern d_select_t ptcselect;
123extern d_ioctl_t ptyioctl;
124#else
0a7de745
A
125#define ptsopen eno_opcl
126#define ptsclose eno_opcl
127#define ptsread eno_rdwrt
128#define ptswrite eno_rdwrt
129#define ptsstop nulldev
5ba3f43e 130
0a7de745
A
131#define ptcopen eno_opcl
132#define ptcclose eno_opcl
133#define ptcread eno_rdwrt
134#define ptcwrite eno_rdwrt
135#define ptcselect eno_select
136#define ptyioctl eno_ioctl
5ba3f43e
A
137#endif
138
139extern d_open_t logopen;
140extern d_close_t logclose;
141extern d_read_t logread;
142extern d_ioctl_t logioctl;
143extern d_select_t logselect;
144
145extern d_open_t oslog_streamopen;
146extern d_close_t oslog_streamclose;
147extern d_read_t oslog_streamread;
148extern d_ioctl_t oslog_streamioctl;
149extern d_select_t oslog_streamselect;
150
151
152extern d_open_t oslogopen;
153extern d_close_t oslogclose;
154extern d_ioctl_t oslogioctl;
155extern d_select_t oslogselect;
156
0a7de745
A
157#define nullopen (d_open_t *)&nulldev
158#define nullclose (d_close_t *)&nulldev
159#define nullread (d_read_t *)&nulldev
160#define nullwrite (d_write_t *)&nulldev
161#define nullioctl (d_ioctl_t *)&nulldev
162#define nullselect (d_select_t *)&nulldev
163#define nullstop (d_stop_t *)&nulldev
164#define nullreset (d_reset_t *)&nulldev
5ba3f43e
A
165
166struct cdevsw cdevsw[] = {
167 /*
168 * To add character devices to this table dynamically, use cdevsw_add.
169 */
170
171 [0] = {
172 cnopen, cnclose, cnread, cnwrite,
173 cnioctl, nullstop, nullreset, 0, cnselect,
174 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
175 },
176 [1] = NO_CDEVICE,
177 [2] = {
178 cttyopen, nullclose, cttyread, cttywrite,
179 cttyioctl, nullstop, nullreset, 0, cttyselect,
180 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
181 },
182 [3] = {
183 nullopen, nullclose, mmread, mmwrite,
184 mmioctl, nullstop, nullreset, 0, mmselect,
185 mmmmap, eno_strat, eno_getc, eno_putc, D_DISK
186 },
187 [PTC_MAJOR] = {
188 ptsopen, ptsclose, ptsread, ptswrite,
189 ptyioctl, ptsstop, nullreset, 0, ptsselect,
190 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
191 },
192 [PTS_MAJOR] = {
193 ptcopen, ptcclose, ptcread, ptcwrite,
194 ptyioctl, nullstop, nullreset, 0, ptcselect,
195 eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY
196 },
197 [6] = {
198 logopen, logclose, logread, eno_rdwrt,
199 logioctl, eno_stop, nullreset, 0, logselect,
200 eno_mmap, eno_strat, eno_getc, eno_putc, 0
201 },
202 [7] = {
203 oslogopen, oslogclose, eno_rdwrt, eno_rdwrt,
204 oslogioctl, eno_stop, nullreset, 0, oslogselect,
205 eno_mmap, eno_strat, eno_getc, eno_putc, 0
206 },
207 [8] = {
208 oslog_streamopen, oslog_streamclose, oslog_streamread, eno_rdwrt,
209 oslog_streamioctl, eno_stop, nullreset, 0, oslog_streamselect,
210 eno_mmap, eno_strat, eno_getc, eno_putc, 0
211 },
212 [9 ... 11] = NO_CDEVICE,
213 [12] = {
214 kmopen, kmclose, kmread, kmwrite,
215 kmioctl, nullstop, nullreset, km_tty, ttselect,
216 eno_mmap, eno_strat, eno_getc, eno_putc, 0
217 },
cb323159 218 [13 ... 42] = NO_CDEVICE,
5ba3f43e
A
219};
220const int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
221
222uint64_t cdevsw_flags[sizeof(cdevsw) / sizeof(cdevsw[0])];
223
0a7de745 224#include <sys/vnode.h> /* for VCHR and VBLK */
5ba3f43e
A
225/*
226 * return true if a disk
227 */
228int
229isdisk(dev_t dev, int type)
230{
231 dev_t maj = major(dev);
232
233 switch (type) {
234 case VCHR:
cb323159 235 maj = chrtoblk(dev);
5ba3f43e
A
236 if (maj == NODEV) {
237 break;
238 }
0a7de745 239 /* FALL THROUGH */
5ba3f43e
A
240 case VBLK:
241 if (bdevsw[maj].d_type == D_DISK) {
0a7de745 242 return 1;
5ba3f43e
A
243 }
244 break;
245 }
0a7de745 246 return 0;
5ba3f43e
A
247}
248
cb323159 249static int chrtoblktab[] = {[0 ... nchrdev] = NODEV };
5ba3f43e
A
250
251/*
252 * convert chr dev to blk dev
253 */
254dev_t
255chrtoblk(dev_t dev)
256{
257 int blkmaj;
258
0a7de745
A
259 if (major(dev) >= nchrdev) {
260 return NODEV;
261 }
5ba3f43e 262 blkmaj = chrtoblktab[major(dev)];
0a7de745
A
263 if (blkmaj == NODEV) {
264 return NODEV;
265 }
266 return makedev(blkmaj, minor(dev));
5ba3f43e
A
267}
268
269int
270chrtoblk_set(int cdev, int bdev)
271{
0a7de745
A
272 if (cdev >= nchrdev) {
273 return -1;
274 }
275 if (bdev != NODEV && bdev >= nblkdev) {
276 return -1;
277 }
5ba3f43e
A
278 chrtoblktab[cdev] = bdev;
279 return 0;
280}