]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/arm/cons.c
xnu-6153.61.1.tar.gz
[apple/xnu.git] / bsd / dev / arm / cons.c
CommitLineData
5ba3f43e
A
1/*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 */
4/*
5 * Copyright (c) 1987, 1988 NeXT, Inc.
0a7de745 6 *
5ba3f43e 7 * HISTORY 7-Jan-93 Mac Gillon (mgillon) at NeXT Integrated POSIX support
0a7de745 8 *
5ba3f43e
A
9 * 12-Aug-87 John Seamons (jks) at NeXT Ported to NeXT.
10 */
11
12/*
13 * Indirect driver for console.
14 */
15#include <sys/param.h>
16#include <sys/systm.h>
17#include <sys/conf.h>
18#include <sys/ioctl.h>
19#include <sys/tty.h>
20#include <sys/proc.h>
21#include <sys/uio.h>
22
0a7de745 23struct tty *constty; /* current console device */
5ba3f43e
A
24
25/*
26 * The km driver supplied the default console device for the systems
27 * (usually a raw frame buffer driver, but potentially a serial driver).
28 */
29extern struct tty *km_tty[1];
30
31/*
32 * cdevsw[] entries for the console device driver
33 */
34int cnopen(__unused dev_t dev, int flag, int devtype, proc_t pp);
35int cnclose(__unused dev_t dev, int flag, int mode, proc_t pp);
36int cnread(__unused dev_t dev, struct uio *uio, int ioflag);
37int cnwrite(__unused dev_t dev, struct uio *uio, int ioflag);
38int cnioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flg, proc_t p);
39int cnselect(__unused dev_t dev, int flag, void * wql, proc_t p);
40
41static dev_t
42cndev(void)
43{
0a7de745 44 if (constty) {
5ba3f43e 45 return constty->t_dev;
0a7de745 46 } else {
5ba3f43e 47 return km_tty[0]->t_dev;
0a7de745 48 }
5ba3f43e
A
49}
50
51int
52cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp)
53{
54 dev = cndev();
0a7de745 55 return (*cdevsw[major(dev)].d_open)(dev, flag, devtype, pp);
5ba3f43e
A
56}
57
58
59int
60cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp)
61{
62 dev = cndev();
0a7de745 63 return (*cdevsw[major(dev)].d_close)(dev, flag, mode, pp);
5ba3f43e
A
64}
65
66
67int
68cnread(__unused dev_t dev, struct uio *uio, int ioflag)
69{
70 dev = cndev();
0a7de745 71 return (*cdevsw[major(dev)].d_read)(dev, uio, ioflag);
5ba3f43e
A
72}
73
74
75int
76cnwrite(__unused dev_t dev, struct uio *uio, int ioflag)
77{
78 dev = cndev();
0a7de745 79 return (*cdevsw[major(dev)].d_write)(dev, uio, ioflag);
5ba3f43e
A
80}
81
82
83int
84cnioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
85{
86 dev = cndev();
87
88 /*
89 * XXX This check prevents the cons.c code from being shared between
90 * XXX all architectures; it is probably not needed on ARM, either,
91 * XXX but I have no test platforms or ability to run a kernel.
92 *
93 * Superuser can always use this to wrest control of console
94 * output from the "virtual" console.
95 */
96 if ((unsigned) cmd == TIOCCONS && constty) {
97 int error = proc_suser(p);
0a7de745
A
98 if (error) {
99 return error;
100 }
5ba3f43e 101 constty = NULL;
0a7de745 102 return 0;
5ba3f43e 103 }
0a7de745 104 return (*cdevsw[major(dev)].d_ioctl)(dev, cmd, addr, flag, p);
5ba3f43e
A
105}
106
107
108int
109cnselect(__unused dev_t dev, int flag, void *wql, struct proc *p)
110{
111 dev = cndev();
0a7de745 112 return (*cdevsw[major(dev)].d_select)(dev, flag, wql, p);
5ba3f43e 113}