]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/arm/km.c
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
5 * Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
7 * km.m - kernel keyboard/monitor module, procedural interface.
11 #include <sys/param.h>
14 #include <machine/cons.h>
16 #include <sys/systm.h>
18 #include <sys/fcntl.h> /* for kmopen */
19 #include <sys/errno.h>
20 #include <sys/proc.h> /* for kmopen */
21 #include <sys/msgbuf.h>
23 #include <dev/kmreg_com.h>
24 #include <pexpert/pexpert.h>
25 #include <console/serial_protos.h>
29 extern void cnputcusr(char);
30 extern void cnputsusr(char *, int);
31 extern int cngetc(void);
35 void cons_cinput(char ch
);
38 * 'Global' variables, shared only by this file and conf.c.
40 struct tty
*km_tty
[1] = { 0 };
43 * this works early on, after initialize_screen() but before autoconf (and thus
44 * before we have a kmDevice).
46 int disableConsoleOutput
;
49 * 'Global' variables, shared only by this file and kmDevice.m.
53 static int kmoutput(struct tty
* tp
);
54 static void kmstart(struct tty
* tp
);
56 extern void KeyboardOpen(void);
61 km_tty
[0] = ttymalloc();
62 km_tty
[0]->t_dev
= makedev(12, 0);
67 * cdevsw interface to km driver.
70 kmopen(dev_t dev
, int flag
, __unused
int devtype
, proc_t pp
)
85 tp
->t_oproc
= kmstart
;
89 if (!(tp
->t_state
& TS_ISOPEN
)) {
90 tp
->t_iflag
= TTYDEF_IFLAG
;
91 tp
->t_oflag
= TTYDEF_OFLAG
;
92 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
93 tp
->t_lflag
= TTYDEF_LFLAG
;
94 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
95 termioschars(&tp
->t_termios
);
97 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
)) {
102 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is
104 ret
= ((*linesw
[tp
->t_line
].l_open
) (dev
, tp
));
109 * Magic numbers. These are CHARWIDTH and CHARHEIGHT from
110 * pexpert/i386/video_console.c
115 tty_unlock(tp
); /* XXX race window */
118 PE_initialize_console(0, kPETextScreen
);
120 bzero(&video
, sizeof(video
));
121 PE_current_console(&video
);
125 if (serialmode
& SERIALMODE_OUTPUT
) {
128 } else if (video
.v_width
!= 0 && video
.v_height
!= 0) {
129 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
130 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
144 kmclose(dev_t dev
, int flag
, __unused
int mode
, __unused proc_t p
)
147 struct tty
*tp
= km_tty
[minor(dev
)];
150 ret
= (*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
158 kmread(dev_t dev
, struct uio
* uio
, int ioflag
)
161 struct tty
*tp
= km_tty
[minor(dev
)];
164 ret
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
);
171 kmwrite(dev_t dev
, struct uio
* uio
, int ioflag
)
174 struct tty
*tp
= km_tty
[minor(dev
)];
177 ret
= (*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
);
184 kmioctl(dev_t dev
, u_long cmd
, caddr_t data
, int flag
, proc_t p
)
187 struct tty
*tp
= km_tty
[minor(dev
)];
194 wp
= (struct winsize
*) data
;
200 * Prevent changing of console size -- this ensures that
201 * login doesn't revert to the termcap-defined size
206 /* Bodge in the CLOCAL flag as the km device is always local */
211 struct termios32
*t
= (struct termios32
*)data
;
212 t
->c_cflag
|= CLOCAL
;
220 struct user_termios
*t
= (struct user_termios
*)data
;
221 t
->c_cflag
|= CLOCAL
;
226 error
= (*linesw
[tp
->t_line
].l_ioctl
) (tp
, cmd
, data
, flag
, p
);
229 error
= ttioctl_locked(tp
, cmd
, data
, flag
, p
);
242 * Output a character to the serial console driver via cnputcusr(),
243 * which is exported by that driver.
245 * Locks: Assumes tp in the calling tty driver code is locked on
246 * entry, remains locked on exit
248 * Notes: Called from kmoutput(); giving the locking output
249 * assumptions here, this routine should be static (and
250 * inlined, given there is only one call site).
253 kmputc(__unused dev_t dev
, char c
)
255 if(!disableConsoleOutput
&& initialized
) {
267 * Callouts from linesw.
270 #define KM_LOWAT_DELAY ((ns_time_t)1000)
273 * t_oproc for this driver; called from within the line discipline
275 * Locks: Assumes tp is locked on entry, remains locked on exit
278 kmstart(struct tty
*tp
)
280 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
282 if (tp
->t_outq
.c_cc
== 0)
284 tp
->t_state
|= TS_BUSY
;
285 if (tp
->t_outq
.c_cc
> tp
->t_lowat
) {
296 timeout(kmtimeout
, tp
, hz
);
304 (*linesw
[tp
->t_line
].l_start
) (tp
);
309 * One-shot output retry timeout from kmoutput(); re-calls kmoutput() at
310 * intervals until the output queue for the tty is empty, at which point
311 * the timeout is not rescheduled by kmoutput()
313 * This function must take the tty_lock() around the kmoutput() call; it
314 * ignores the return value.
319 struct tty
*tp
= (struct tty
*)arg
;
329 * Locks: Assumes tp is locked on entry, remains locked on exit
331 * Notes: Called from kmstart() and kmtimeout(); kmtimeout() is a
332 * timer initiated by this routine to deal with pending
333 * output not yet flushed (output is flushed at a maximum
334 * of sizeof(buf) charatcers at a time before dropping into
338 kmoutput(struct tty
* tp
)
340 unsigned char buf
[80]; /* buffer; limits output per call */
344 /* While there is data available to be output... */
345 while (tp
->t_outq
.c_cc
> 0) {
346 cc
= ndqb(&tp
->t_outq
, 0);
350 * attempt to output as many characters as are available,
351 * up to the available transfer buffer size.
353 cc
= min(cc
, sizeof(buf
));
354 /* copy the output queue contents to the buffer */
355 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
356 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
357 /* output the buffer one charatcer at a time */
361 cnputsusr((char *)buf
, cc
);
363 kmputc(tp
->t_dev
, *buf
);
367 * XXX This is likely not necessary, as the tty output queue is not
368 * XXX writeable while we hold the tty_lock().
370 if (tp
->t_outq
.c_cc
> 0) {
371 timeout(kmtimeout
, tp
, hz
);
373 tp
->t_state
&= ~TS_BUSY
;
374 /* Start the output processing for the line discipline */
375 (*linesw
[tp
->t_line
].l_start
) (tp
);
384 * Driver character input from the polled mode serial console driver calls
385 * this routine to input a character from the serial driver into the tty
386 * line discipline specific input processing receiv interrupt routine,
389 * Locks: Assumes that the tty_lock() is NOT held on the tp, so a
390 * serial driver should NOT call this function as a result
391 * of being called from a function which already holds the
392 * lock; ECHOE will be handled at the line discipline, if
393 * output echo processing is going to occur.
398 struct tty
*tp
= km_tty
[0]; /* XXX */
401 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);