1 /* $NetBSD: itecons.c,v 1.8 2009/10/26 19:16:55 cegger Exp $ */
3 /* $OpenBSD: itecons.c,v 1.6 1999/04/20 20:01:02 mickey Exp $ */
6 * Copyright (c) 1998-2004 Michael Shalayeff
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 * Copyright 1996 1995 by Open Software Foundation, Inc.
34 * Permission to use, copy, modify, and distribute this software and
35 * its documentation for any purpose and without fee is hereby granted,
36 * provided that the above copyright notice appears in all copies and
37 * that both the copyright notice and this permission notice appear in
38 * supporting documentation.
40 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
41 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42 * FOR A PARTICULAR PURPOSE.
44 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
45 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
47 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
48 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54 #include <sys/param.h>
55 #include <sys/disklabel.h>
56 #include <machine/pdc.h>
57 #include <machine/iomod.h>
62 iodcio_t cniodc
; /* console IODC entry point */
63 iodcio_t kyiodc
; /* keyboard IODC entry point */
64 pz_device_t
*cons_pzdev
, *kbd_pzdev
;
70 char cnbuf
[IODC_MINIOSIZ
] __attribute__ ((aligned (IODC_MINIOSIZ
)));
71 int kycode
[IODC_MAXSIZE
/sizeof(int)];
75 cnspeed(dev_t dev
, int sp
)
82 ite_probe(struct consdev
*cn
)
84 cniodc
= (iodcio_t
)PAGE0
->mem_free
;
85 cons_pzdev
= &PAGE0
->mem_cons
;
86 kbd_pzdev
= &PAGE0
->mem_kbd
;
88 if ((*pdc
) (PDC_IODC
, PDC_IODC_READ
, pdcbuf
, cons_pzdev
->pz_hpa
,
89 IODC_INIT
, cniodc
, IODC_MAXSIZE
) < 0 ||
90 (*cniodc
)(cons_pzdev
->pz_hpa
,
91 (cons_pzdev
->pz_hpa
==PAGE0
->mem_boot
.pz_hpa
)?
92 IODC_INIT_DEV
: IODC_INIT_ALL
, cons_pzdev
->pz_spa
,
93 cons_pzdev
->pz_layers
, pdcbuf
, 0,0,0,0) < 0 ||
94 (*pdc
) (PDC_IODC
, PDC_IODC_READ
, pdcbuf
, cons_pzdev
->pz_hpa
,
95 IODC_IO
, cniodc
, IODC_MAXSIZE
) < 0) {
96 /* morse code with the LED's?!! */
97 cons_pzdev
->pz_iodc_io
= kbd_pzdev
->pz_iodc_io
= NULL
;
99 cn
->cn_pri
= CN_INTERNAL
;
100 cn
->cn_dev
= makedev(0, 0);
105 ite_init(struct consdev
*cn
)
108 * If the keyboard is separate from the console output device,
109 * we load the keyboard code at `kycode'.
111 * N.B. In this case, since the keyboard code is part of the
112 * boot code, it will be overwritten when we load a kernel.
114 if (cons_pzdev
->pz_class
!= PCL_DUPLEX
||
115 kbd_pzdev
->pz_class
== PCL_KEYBD
) {
117 kyiodc
= (iodcio_t
)kycode
;
119 if ((*pdc
) (PDC_IODC
, PDC_IODC_READ
, pdcbuf
, kbd_pzdev
->pz_hpa
,
120 IODC_INIT
, kyiodc
, IODC_MAXSIZE
) < 0 ||
121 (*kyiodc
)(kbd_pzdev
->pz_hpa
,
122 (kbd_pzdev
->pz_hpa
== PAGE0
->mem_boot
.pz_hpa
||
123 kbd_pzdev
->pz_hpa
== cons_pzdev
->pz_hpa
)?
124 IODC_INIT_DEV
: IODC_INIT_ALL
, kbd_pzdev
->pz_spa
,
125 kbd_pzdev
->pz_layers
, pdcbuf
, 0, 0, 0, 0) < 0 ||
126 (*pdc
) (PDC_IODC
, PDC_IODC_READ
, pdcbuf
, kbd_pzdev
->pz_hpa
,
127 IODC_IO
, kyiodc
, IODC_MAXSIZE
))
132 memcpy((char *)&PAGE0
->mem_kbd
, (char *)&PAGE0
->mem_cons
,
133 sizeof(struct pz_device
));
136 cons_pzdev
->pz_iodc_io
= cniodc
;
137 kbd_pzdev
->pz_iodc_io
= kyiodc
;
140 printf("ite_init: no kbd\n");
145 ite_putc(dev_t dev
, int c
)
152 (*cniodc
)(cons_pzdev
->pz_hpa
, IODC_IO_CONSOUT
, cons_pzdev
->pz_spa
,
153 cons_pzdev
->pz_layers
, pdcbuf
, 0, cnbuf
, 1, 0);
157 * since i don't know how to 'just check the char available'
158 * i store the key into the stash removing on read op later;
163 static int stash
= 0;
178 err
= (*kyiodc
)(kbd_pzdev
->pz_hpa
, IODC_IO_CONSIN
,
179 kbd_pzdev
->pz_spa
, kbd_pzdev
->pz_layers
,
180 pdcbuf
, 0, cnbuf
, 1, 0);
184 if (debug
&& err
< 0)
185 printf("KBD input error: %d", err
);
188 /* if we are doing ischar() report immidiatelly */
189 if (!i
-- && (dev
& 0x80) && l
== 0) {
192 printf("ite_getc(0x%x): no char %d(%x)\n",
201 printf("KBD input got too much (%d)\n", l
);
204 printf("kbd: \'%c\' (0x%x)\n", c
, c
);
213 ite_pollc(dev_t dev
, int on
)