From ae16d918a316eb60407be875de416efb373a652f Mon Sep 17 00:00:00 2001 From: yokota Date: Mon, 11 Jan 1999 03:18:56 +0000 Subject: The first stage of console driver reorganization: activate new keyboard and video card drivers. Because of the changes, you are required to update your kernel configuration file now! The files in sys/dev/syscons are still i386-specific (but less so than before), and won't compile for alpha and PC98 yet. syscons still directly accesses the video card registers here and there; this will be rectified in the later stages. --- sys/i386/isa/pcvt/pcvt_drv.c | 162 +++++++++++++++++++++++++++++-------------- 1 file changed, 111 insertions(+), 51 deletions(-) (limited to 'sys/i386/isa/pcvt/pcvt_drv.c') diff --git a/sys/i386/isa/pcvt/pcvt_drv.c b/sys/i386/isa/pcvt/pcvt_drv.c index 26c02f3..c4ed5a1 100644 --- a/sys/i386/isa/pcvt/pcvt_drv.c +++ b/sys/i386/isa/pcvt/pcvt_drv.c @@ -114,6 +114,11 @@ static void vgapelinit(void); /* read initial VGA DAC palette */ static int pcvt_xmode_set(int on, struct proc *p); /* initialize for X mode */ #endif /* XSERVER && !PCVT_USL_VT_COMPAT */ +#ifdef _DEV_KBD_KBDREG_H_ +static void detect_kbd(void *arg); +static kbd_callback_func_t pcevent; +#endif + static cn_probe_t pccnprobe; static cn_init_t pccninit; static cn_getc_t pccngetc; @@ -161,17 +166,19 @@ pcprobe(struct isa_device *dev) #endif /* PCVT_NETBSD > 9 */ #endif /* PCVT_NETBSD > 100 */ { -#ifdef _I386_ISA_KBDIO_H_ - kbdc = kbdc_open(IO_KBD); +#ifdef _DEV_KBD_KBDREG_H_ + int i; - if(kbdc == NULL) + kbd = NULL; + kbd_configure(KB_CONF_PROBE_ONLY); + i = kbd_allocate("*", -1, (void *)&kbd, pcevent, (void *)dev->id_unit); + if ((i < 0) || ((kbd = kbd_get_keyboard(i)) == NULL)) { reset_keyboard = 0; - return 1; + return (-1); } - reset_keyboard = 1; /* it's now safe to do kbd reset */ -#endif /* _I386_ISA_KBDIO_H_ */ +#endif /* _DEV_KBD_KBDREG_H_ */ kbd_code_init(); @@ -179,7 +186,9 @@ pcprobe(struct isa_device *dev) ((struct isa_attach_args *)aux)->ia_iosize = 16; return 1; #else -#if PCVT_NETBSD || PCVT_FREEBSD +#ifdef _DEV_KBD_KBDREG_H_ + return (-1); +#elif PCVT_NETBSD || PCVT_FREEBSD return (16); #else return 1; @@ -207,6 +216,11 @@ pcattach(struct isa_device *dev) vt_coldmalloc(); /* allocate memory for screens */ +#ifdef _DEV_KBD_KBDREG_H_ + if (kbd == NULL) + timeout(detect_kbd, (void *)dev->id_unit, hz*2); +#endif /* _DEV_KBD_KBDREG_H_ */ + #if PCVT_NETBSD || PCVT_FREEBSD #if PCVT_NETBSD > 9 @@ -849,6 +863,50 @@ pcvt_timeout(void *arg) } #endif +#ifdef _DEV_KBD_KBDREG_H_ +static void +detect_kbd(void *arg) +{ + int unit = (int)arg; + int i; + + if (kbd != NULL) + return; + i = kbd_allocate("*", -1, (void *)&kbd, pcevent, (void *)unit); + if (i >= 0) + kbd = kbd_get_keyboard(i); + if (kbd != NULL) + { + reset_keyboard = 1; /* ok to reset the keyboard */ + kbd_code_init(); + return; + } + reset_keyboard = 0; + timeout(detect_kbd, (void *)unit, hz*2); +} + +int +pcevent(keyboard_t *thiskbd, int event, void *arg) +{ + int unit = (int)arg; + + if (thiskbd != kbd) + return EINVAL; /* shouldn't happen */ + + switch (event) { + case KBDIO_KEYINPUT: + pcrint(unit); + return 0; + case KBDIO_UNLOADING: + kbd = NULL; + kbd_release(thiskbd, (void *)&kbd); + timeout(detect_kbd, (void *)unit, hz*4); + return 0; + default: + return EINVAL; + } +} +#endif /* _DEV_KBD_KBDREG_H_ */ void pcrint(int unit) @@ -862,7 +920,7 @@ pcrint(int unit) int s; # endif -# ifdef _I386_ISA_KBDIO_H_ +# ifdef _DEV_KBD_KBDREG_H_ int c; # endif @@ -870,25 +928,6 @@ pcrint(int unit) u_char *cp; #endif /* PCVT_KBD_FIFO */ - /* - * in case the keyboard was not plugged in while booting, kbdc - * was set to NULL at that time. When a keyboard IRQ occurs and - * kbdc is NULL, the keyboard was probably reconnected to the - * keyboard controller and we have to initialize the keyboard. - */ - - if(kbdc == NULL) - { - kbdc = kbdc_open(IO_KBD); - if(kbdc == NULL) - { - reset_keyboard = 0; - return; - } - reset_keyboard = 1; - kbd_code_init(); - } - #if PCVT_SCREENSAVER pcvt_scrnsv_reset(); #endif /* PCVT_SCREENSAVER */ @@ -900,7 +939,7 @@ pcrint(int unit) return; } -# ifndef _I386_ISA_KBDIO_H_ +# ifndef _DEV_KBD_KBDREG_H_ while (inb(CONTROLLER_CTRL) & STATUS_OUTPBF) /* check 8042 buffer */ { ret = 1; /* got something */ @@ -909,11 +948,11 @@ pcrint(int unit) dt = inb(CONTROLLER_DATA); /* get it 8042 data */ # else - while ((c = read_kbd_data_no_wait(kbdc)) != -1) + while ((c = (*kbdsw[kbd->kb_index]->read)(kbd, FALSE)) != -1) { ret = 1; /* got something */ dt = c; -# endif /* _I386_ISA_KBDIO_H_ */ +# endif /* _DEV_KBD_KBDREG_H_ */ if (pcvt_kbd_count >= PCVT_KBD_FIFO_SZ) /* fifo overflow ? */ { @@ -1131,32 +1170,40 @@ int pccnprobe(struct consdev *cp) { struct isa_device *dvp; + int i; + + /* + * Take control if we are the highest priority enabled display device. + */ + dvp = find_display(); + if (dvp == NULL || dvp->id_driver != &vtdriver) { + cp->cn_pri = CN_DEAD; + return; + } + +#ifdef _DEV_KBD_KBDREG_H_ + kbd = NULL; + kbd_configure(KB_CONF_PROBE_ONLY); + i = kbd_allocate("*", -1, (void *)&kbd, pcevent, (void *)dvp->id_unit); + if (i >= 0) + kbd = kbd_get_keyboard(i); -#ifdef _I386_ISA_KBDIO_H_ - kbdc = kbdc_open(IO_KBD); /* * Don't reset the keyboard via `kbdio' just yet. * The system clock has not been calibrated... */ reset_keyboard = 0; + #if PCVT_SCANSET == 2 /* * Turn off scancode translation early so that UserConfig * and DDB can read the keyboard. */ - empty_both_buffers(kbdc, 10); - set_controller_command_byte(kbdc, KBD_TRANSLATION, 0); + empty_both_buffers(*(KBDC *)kbd->kb_data, 10); + set_controller_command_byte(*(KBDC *)kbd->kb_data, KBD_TRANSLATION, 0); #endif /* PCVT_SCANSET == 2 */ -#endif /* _I386_ISA_KBDIO_H_ */ - /* - * Take control if we are the highest priority enabled display device. - */ - dvp = find_display(); - if (dvp == NULL || dvp->id_driver != &vtdriver) { - cp->cn_pri = CN_DEAD; - return; - } +#endif /* _DEV_KBD_KBDREG_H_ */ /* initialize required fields */ @@ -1254,7 +1301,13 @@ pccngetc(Dev_t dev) s = spltty(); /* block pcrint while we poll */ kbd_polling = 1; +#ifdef _DEV_KBD_KBDREG_H_ + (*kbdsw[kbd->kb_index]->enable)(kbd); +#endif cp = sgetc(0); +#ifdef _DEV_KBD_KBDREG_H_ + (*kbdsw[kbd->kb_index]->disable)(kbd); +#endif kbd_polling = 0; splx(s); c = *cp++; @@ -1281,7 +1334,13 @@ pccncheckc(Dev_t dev) char *cp; int x = spltty(); kbd_polling = 1; +#ifdef _DEV_KBD_KBDREG_H_ + (*kbdsw[kbd->kb_index]->enable)(kbd); +#endif cp = sgetc(1); +#ifdef _DEV_KBD_KBDREG_H_ + (*kbdsw[kbd->kb_index]->disable)(kbd); +#endif kbd_polling = 0; splx(x); return (cp == NULL ? -1 : *cp); @@ -1520,7 +1579,7 @@ pcvt_xmode_set(int on, struct proc *p) vsp->Crtat = vsp->Memory; /* operate in memory now */ -#ifndef _I386_ISA_KBDIO_H_ +#ifndef _DEV_KBD_KBDREG_H_ #if PCVT_SCANSET == 2 /* put keyboard to return ancient PC scan codes */ @@ -1534,15 +1593,15 @@ pcvt_xmode_set(int on, struct proc *p) #endif /* PCVT_USEKBDSEC */ #endif /* PCVT_SCANSET == 2 */ -#else /* _I386_ISA_KBDIO_H_ */ +#else /* _DEV_KBD_KBDREG_H_ */ #if PCVT_SCANSET == 2 /* put keyboard to return ancient PC scan codes */ - set_controller_command_byte(kbdc, + set_controller_command_byte(*(KBDC *)kbd->kb_data, KBD_TRANSLATION, KBD_TRANSLATION); #endif /* PCVT_SCANSET == 2 */ -#endif /* !_I386_ISA_KBDIO_H_ */ +#endif /* !_DEV_KBD_KBDREG_H_ */ #if PCVT_NETBSD > 9 fp->tf_eflags |= PSL_IOPL; @@ -1579,7 +1638,7 @@ pcvt_xmode_set(int on, struct proc *p) pcvt_set_scrnsv_tmo(saved_scrnsv_tmo); #endif /* PCVT_SCREENSAVER */ -#ifndef _I386_ISA_KBDIO_H_ +#ifndef _DEV_KBD_KBDREG_H_ #if PCVT_SCANSET == 2 kbc_8042cmd(CONTR_WRITE); @@ -1592,13 +1651,14 @@ pcvt_xmode_set(int on, struct proc *p) #endif /* PCVT_USEKBDSEC */ #endif /* PCVT_SCANSET == 2 */ -#else /* _I386_ISA_KBDIO_H_ */ +#else /* _DEV_KBD_KBDREG_H_ */ #if PCVT_SCANSET == 2 - set_controller_command_byte(kbdc, KBD_TRANSLATION, 0); + set_controller_command_byte(*(KBDC *)kbd->kb_data, + KBD_TRANSLATION, 0); #endif /* PCVT_SCANSET == 2 */ -#endif /* !_I386_ISA_KBDIO_H_ */ +#endif /* !_DEV_KBD_KBDREG_H_ */ if(adaptor_type == MDA_ADAPTOR) { -- cgit v1.1