]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/km.c
1de1c32577d46e37fcb924083882fbb40af8fcbf
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
32 * km.m - kernel keyboard/monitor module, procedural interface.
37 #include <sys/kernel.h>
40 #include <dev/ppc/cons.h>
42 #include <sys/systm.h>
44 #include <sys/fcntl.h> /* for kmopen */
45 #include <sys/errno.h>
46 #include <sys/proc.h> /* for kmopen */
47 #include <sys/msgbuf.h>
49 #include <dev/kmreg_com.h>
50 #include <pexpert/pexpert.h>
53 * 'Global' variables, shared only by this file and conf.c.
55 struct tty
*km_tty
[1] = { &cons
};
58 * this works early on, after initialize_screen() but before autoconf (and thus
59 * before we have a kmDevice).
61 int disableConsoleOutput
;
63 static int initialized
= 0;
65 // Function prototypes
66 extern d_open_t kmopen
;
67 extern d_close_t kmclose
;
68 extern d_read_t kmread
;
69 extern d_write_t kmwrite
;
70 extern d_ioctl_t kmioctl
;
71 extern d_getc_t kmgetc
;
72 extern d_putc_t kmputc
;
74 extern void kminit(void);
76 // used by or implemented in the osfmk project
77 extern void cnputcusr(char); // From osfmk
78 extern int cngetc(void); // From osfmk
79 extern void cons_cinput(char ch
); // Used by osfmk
81 static int kmoutput(struct tty
*tp
);
82 static void kmtimeout(struct tty
*tp
);
83 static void kmstart(struct tty
*tp
);
85 extern void KeyboardOpen(void);
90 cons
.t_dev
= makedev(12, 0);
94 * cdevsw interface to km driver.
97 kmopen(dev_t dev
, int flag
, __unused
int devtype
, struct proc
*pp
)
108 tp
= (struct tty
*)&cons
;
109 tp
->t_oproc
= kmstart
;
113 if ( !(tp
->t_state
& TS_ISOPEN
) ) {
114 tp
->t_iflag
= TTYDEF_IFLAG
;
115 tp
->t_oflag
= TTYDEF_OFLAG
;
116 tp
->t_cflag
= (CREAD
| CS8
| CLOCAL
);
117 tp
->t_lflag
= TTYDEF_LFLAG
;
118 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
119 termioschars(&tp
->t_termios
);
121 } else if ((tp
->t_state
& TS_XCLUDE
) && proc_suser(pp
))
124 tp
->t_state
|= TS_CARR_ON
; /* lie and say carrier exists and is on. */
125 ret
= ((*linesw
[tp
->t_line
].l_open
)(dev
, tp
));
129 /* Magic numbers. These are CHARWIDTH and CHARHEIGHT
130 * from osfmk/ppc/POWERMAC/video_console.c
136 PE_initialize_console(0, kPETextScreen
);
138 bzero(&video
, sizeof(video
));
139 PE_current_console(&video
);
140 if( video
.v_width
!= 0 && video
.v_height
!= 0 ) {
141 wp
->ws_col
= video
.v_width
/ wp
->ws_xpixel
;
142 wp
->ws_row
= video
.v_height
/ wp
->ws_ypixel
;
152 kmclose(__unused dev_t dev
, __unused
int flag
, __unused
int mode
,
153 __unused
struct proc
*p
)
159 (*linesw
[tp
->t_line
].l_close
)(tp
,flag
);
165 kmread(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
167 register struct tty
*tp
;
170 return ((*linesw
[tp
->t_line
].l_read
)(tp
, uio
, ioflag
));
174 kmwrite(__unused dev_t dev
, struct uio
*uio
, int ioflag
)
176 register struct tty
*tp
;
179 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, ioflag
));
183 kmioctl( __unused dev_t dev
, u_long cmd
, caddr_t data
, int flag
,
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
);
218 return ttioctl (tp
, cmd
, data
, flag
, p
);
223 kmputc(__unused dev_t dev
, char c
)
226 if( disableConsoleOutput
)
241 kmgetc(__unused dev_t dev
)
270 * Callouts from linesw.
273 #define KM_LOWAT_DELAY ((ns_time_t)1000)
276 kmstart(struct tty
*tp
)
278 if (tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))
280 if (tp
->t_outq
.c_cc
== 0)
282 tp
->t_state
|= TS_BUSY
;
287 (*linesw
[tp
->t_line
].l_start
)(tp
);
292 kmtimeout(struct tty
*tp
)
294 boolean_t funnel_state
;
296 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
298 (void) thread_funnel_set(kernel_flock
, funnel_state
);
303 kmoutput(struct tty
*tp
)
306 * FIXME - to be grokked...copied from m68k km.c.
312 while (tp
->t_outq
.c_cc
> 0) {
313 cc
= ndqb(&tp
->t_outq
, 0);
316 cc
= min(cc
, sizeof buf
);
317 (void) q_to_b(&tp
->t_outq
, buf
, cc
);
318 for (cp
= buf
; cp
< &buf
[cc
]; cp
++)
319 kmputc(tp
->t_dev
, *cp
& 0x7f);
321 if (tp
->t_outq
.c_cc
> 0) {
322 timeout((timeout_fcn_t
)kmtimeout
, tp
, hz
);
324 tp
->t_state
&= ~TS_BUSY
;
325 (*linesw
[tp
->t_line
].l_start
)(tp
);
330 void cons_cinput(char ch
)
332 struct tty
*tp
= &cons
;
334 (*linesw
[tp
->t_line
].l_rint
) (ch
, tp
);