]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
24 * km.m - kernel keyboard/monitor module, procedural interface.
29 #include <sys/kernel.h>
32 #include <dev/ppc/cons.h>
34 #include <sys/systm.h>
36 #include <sys/fcntl.h> /* for kmopen */
37 #include <sys/errno.h>
38 #include <sys/proc.h> /* for kmopen */
39 #include <sys/msgbuf.h>
41 #include <dev/kmreg_com.h>
42 #include <pexpert/pexpert.h>
45 * 'Global' variables, shared only by this file and conf.c.
47 struct tty
*km_tty
[1] = { &cons
};
50 * this works early on, after initialize_screen() but before autoconf (and thus
51 * before we have a kmDevice).
53 int disableConsoleOutput
;
55 static int initialized
= 0;
57 // Function prototypes
58 extern d_open_t kmopen
;
59 extern d_close_t kmclose
;
60 extern d_read_t kmread
;
61 extern d_write_t kmwrite
;
62 extern d_ioctl_t kmioctl
;
63 extern d_getc_t kmgetc
;
64 extern d_putc_t kmputc
;
66 extern void kminit(void);
68 // used by or implemented in the osfmk project
69 extern void cnputcusr(char); // From osfmk
70 extern int cngetc(void); // From osfmk
71 extern void cons_cinput(char ch
); // Used by osfmk
73 static int kmoutput(struct tty
*tp
);
74 static void kmtimeout(struct tty
*tp
);
75 static void kmstart(struct tty
*tp
);
77 extern void KeyboardOpen(void);
82 cons
.t_dev
= makedev(12, 0);
86 * cdevsw interface to km driver.
89 kmopen(dev_t dev
, int flag
, __unused
int devtype
, struct proc
*pp
)
100 tp
= (struct tty
*)&cons
;
101 tp
->t_oproc
= kmstart
;
105 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
106 tp
->t_iflag
= TTYDEF_IFLAG
;
107 tp
->t_oflag
= TTYDEF_OFLAG
;
108 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
109 tp
->t_lflag
= TTYDEF_LFLAG
;
110 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
111 termioschars(&tp
->t_termios
);
113 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
116 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
117 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
121 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
122 * from osfmk/ppc/POWERMAC/video_console.c
128 PE_initialize_console(0, kPETextScreen
);
130 bzero(&video
, sizeof(video
));
131 PE_current_console(&video
);
132 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
133 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
134 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
144 kmclose(__unused dev_t dev
, __unused
int flag
, __unused
int mode
,
145 __unused
struct proc
*p
)
151 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
157 kmread(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
159 register struct tty
*tp
;
162 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
166 kmwrite(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
168 register struct tty
*tp
;
171 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
175 kmioctl( __unused dev_t dev
, u_long cmd
, caddr_t data
, int flag
,
179 struct tty
*tp
= &cons
;
187 wp
= (struct winsize
*)data
;
192 /* Prevent changing of console size --
193 * this ensures that login doesn't revert to the
194 * termcap-defined size
198 /* Bodge in the CLOCAL flag as the km device is always local */
202 register struct termios
*t
= (struct termios
*)data
;
203 t
->c_cflag
|= CLOCAL
;
207 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
210 return ttioctl (tp
, cmd
, data
, flag
, p
);
215 kmputc(__unused dev_t dev
, char c
)
218 if( disableConsoleOutput
)
233 kmgetc(__unused dev_t dev
)
262 * Callouts from linesw.
265 #define KM_LOWAT_DELAY ((ns_time_t)1000)
268 kmstart(struct tty
*tp
)
270 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
272 if (tp
->t_outq
.c_cc
== 0)
274 tp
->t_state
|= TS_BUSY
;
279 (*linesw
[tp
->t_line
].l_start
)(tp
);
284 kmtimeout(struct tty
*tp
)
286 boolean_t funnel_state
;
288 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
290 (void) thread_funnel_set(kernel_flock
, funnel_state
);
295 kmoutput(struct tty
*tp
)
298 * FIXME - to be grokked...copied from m68k km.c.
304 while (tp
->t_outq
.c_cc
> 0) {
305 cc
= ndqb(&tp
->t_outq
, 0);
308 cc
= min(cc
, sizeof buf
);
309 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
310 for (cp
= buf
; cp
< &buf
[cc
]; cp
++)
311 kmputc(tp
->t_dev
, *cp
& 0x7f);
313 if (tp
->t_outq
.c_cc
> 0) {
314 timeout((timeout_fcn_t
)kmtimeout
, tp
, hz
);
316 tp
->t_state
&= ~TS_BUSY
;
317 (*linesw
[tp
->t_line
].l_start
)(tp
);
322 void cons_cinput(char ch
)
324 struct tty
*tp
= &cons
;
326 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);