]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/km.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
27 * km.m - kernel keyboard/monitor module, procedural interface.
32 #include <sys/param.h>
35 #include <dev/ppc/cons.h>
37 #include <sys/systm.h>
39 #include <sys/fcntl.h> /* for kmopen */
40 #include <sys/errno.h>
41 #include <sys/proc.h> /* for kmopen */
42 #include <sys/msgbuf.h>
44 #include <dev/kmreg_com.h>
45 #include <pexpert/pexpert.h>
48 * 'Global' variables, shared only by this file and conf.c.
50 extern struct tty cons
;
51 struct tty
*km_tty
[1] = { &cons
};
54 * this works early on, after initialize_screen() but before autoconf (and thus
55 * before we have a kmDevice).
57 int disableConsoleOutput
;
60 * 'Global' variables, shared only by this file and kmDevice.m.
64 static int kmoutput(struct tty
*tp
);
65 static void kmtimeout(struct tty
*tp
);
66 static void kmstart(struct tty
*tp
);
68 extern void KeyboardOpen(void);
72 cons
.t_dev
= makedev(12, 0);
76 * cdevsw interface to km driver.
95 tp
= (struct tty
*)&cons
;
96 tp
->t_oproc
= kmstart
;
100 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
101 tp
->t_iflag
= TTYDEF_IFLAG
;
102 tp
->t_oflag
= TTYDEF_OFLAG
;
103 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
104 tp
->t_lflag
= TTYDEF_LFLAG
;
105 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
106 termioschars(&tp
->t_termios
);
108 } else if ((tp
->t_state
& TS_XCLUDE
) && pp
->p_ucred
->cr_uid
!= 0)
111 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
112 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
116 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
117 * from osfmk/ppc/POWERMAC/video_console.c
123 PE_initialize_console(0, kPETextScreen
);
125 bzero(&video
, sizeof(video
));
126 PE_current_console(&video
);
127 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
128 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
129 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
149 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
160 register struct tty
*tp
;
163 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
172 register struct tty
*tp
;
175 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
187 struct tty
*tp
= &cons
;
195 wp
= (struct winsize
*)data
;
200 /* Prevent changing of console size --
201 * this ensures that login doesn't revert to the
202 * termcap-defined size
206 /* Bodge in the CLOCAL flag as the km device is always local */
210 register struct termios
*t
= (struct termios
*)data
;
211 t
->c_cflag
|= CLOCAL
;
215 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
219 error
= ttioctl (tp
, cmd
, data
, flag
, p
);
234 if( disableConsoleOutput
)
277 * Callouts from linesw.
280 #define KM_LOWAT_DELAY ((ns_time_t)1000)
287 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
289 if (tp
->t_outq
.c_cc
== 0)
291 tp
->t_state
|= TS_BUSY
;
292 if (tp
->t_outq
.c_cc
> tp
->t_lowat
) {
304 timeout(kmtimeout
, tp
, hz
);
314 kmtimeout( struct tty
*tp
)
316 boolean_t funnel_state
;
318 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
320 (void) thread_funnel_set(kernel_flock
, funnel_state
);
329 * FIXME - to be grokked...copied from m68k km.c.
337 while (tp
->t_outq
.c_cc
> 0) {
338 cc
= ndqb(&tp
->t_outq
, 0);
341 cc
= min(cc
, sizeof buf
);
342 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
343 for (cp
= buf
; cp
< &buf
[cc
]; cp
++) {
347 if (tp
->t_outq
.c_cc
> 0) {
348 timeout(kmtimeout
, tp
, hz
);
350 tp
->t_state
&= ~TS_BUSY
;
357 struct tty
*tp
= &cons
;
358 boolean_t funnel_state
;
361 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);