]>
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_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
30 * km.m - kernel keyboard/monitor module, procedural interface.
35 #include <sys/kernel.h>
38 #include <dev/ppc/cons.h>
40 #include <sys/systm.h>
42 #include <sys/fcntl.h> /* for kmopen */
43 #include <sys/errno.h>
44 #include <sys/proc.h> /* for kmopen */
45 #include <sys/msgbuf.h>
47 #include <dev/kmreg_com.h>
48 #include <pexpert/pexpert.h>
51 * 'Global' variables, shared only by this file and conf.c.
53 struct tty
*km_tty
[1] = { &cons
};
56 * this works early on, after initialize_screen() but before autoconf (and thus
57 * before we have a kmDevice).
59 int disableConsoleOutput
;
61 static int initialized
= 0;
63 extern void kminit(void);
65 // used by or implemented in the osfmk project
66 extern void cnputcusr(char); // From osfmk
67 extern int cngetc(void); // From osfmk
68 extern void cons_cinput(char ch
); // Used by osfmk
70 static int kmoutput(struct tty
*tp
);
71 static void kmtimeout(struct tty
*tp
);
72 static void kmstart(struct tty
*tp
);
74 extern void KeyboardOpen(void);
79 cons
.t_dev
= makedev(12, 0);
83 * cdevsw interface to km driver.
86 kmopen(dev_t dev
, int flag
, __unused
int devtype
, struct proc
*pp
)
97 tp
= (struct tty
*)&cons
;
98 tp
->t_oproc
= kmstart
;
102 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
103 tp
->t_iflag
= TTYDEF_IFLAG
;
104 tp
->t_oflag
= TTYDEF_OFLAG
;
105 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
106 tp
->t_lflag
= TTYDEF_LFLAG
;
107 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
108 termioschars(&tp
->t_termios
);
110 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
113 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
114 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
118 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
119 * from osfmk/ppc/POWERMAC/video_console.c
125 PE_initialize_console(0, kPETextScreen
);
127 bzero(&video
, sizeof(video
));
128 PE_current_console(&video
);
129 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
130 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
131 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
141 kmclose(__unused dev_t dev
, __unused
int flag
, __unused
int mode
,
142 __unused
struct proc
*p
)
148 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
154 kmread(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
156 register struct tty
*tp
;
159 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
163 kmwrite(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
165 register struct tty
*tp
;
168 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
172 kmioctl( __unused dev_t dev
, u_long cmd
, caddr_t data
, int flag
,
176 struct tty
*tp
= &cons
;
184 wp
= (struct winsize
*)data
;
189 /* Prevent changing of console size --
190 * this ensures that login doesn't revert to the
191 * termcap-defined size
195 /* Bodge in the CLOCAL flag as the km device is always local */
199 register struct termios
*t
= (struct termios
*)data
;
200 t
->c_cflag
|= CLOCAL
;
204 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
207 return ttioctl (tp
, cmd
, data
, flag
, p
);
212 kmputc(__unused dev_t dev
, char c
)
215 if( disableConsoleOutput
)
230 kmgetc(__unused dev_t dev
)
259 * Callouts from linesw.
262 #define KM_LOWAT_DELAY ((ns_time_t)1000)
265 kmstart(struct tty
*tp
)
267 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
269 if (tp
->t_outq
.c_cc
== 0)
271 tp
->t_state
|= TS_BUSY
;
276 (*linesw
[tp
->t_line
].l_start
)(tp
);
281 kmtimeout(struct tty
*tp
)
283 boolean_t funnel_state
;
285 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
287 (void) thread_funnel_set(kernel_flock
, funnel_state
);
292 kmoutput(struct tty
*tp
)
295 * FIXME - to be grokked...copied from m68k km.c.
301 while (tp
->t_outq
.c_cc
> 0) {
302 cc
= ndqb(&tp
->t_outq
, 0);
305 cc
= min(cc
, sizeof buf
);
306 (void) q_to_b(&tp
->t_outq
, (unsigned char *)buf
, cc
);
307 for (cp
= buf
; cp
< &buf
[cc
]; cp
++)
308 kmputc(tp
->t_dev
, *cp
& 0x7f);
310 if (tp
->t_outq
.c_cc
> 0) {
311 timeout((timeout_fcn_t
)kmtimeout
, tp
, hz
);
313 tp
->t_state
&= ~TS_BUSY
;
314 (*linesw
[tp
->t_line
].l_start
)(tp
);
319 void cons_cinput(char ch
)
321 struct tty
*tp
= &cons
;
323 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);