From 1e05d21cdd005b91bfe7df21692f0ce6c5eaa929 Mon Sep 17 00:00:00 2001 From: jkim Date: Fri, 25 Sep 2009 19:49:07 +0000 Subject: - Use x86bios_offset() instead of BIOS_PADDRTOVADDR() macro.[1] - Clear all registers before calling real mode interrupt handlers as we did for dpms and vesa and re-enable the function as it should be fixed by this. - Tidy up register access. For example, when we call INT 0x15, AH=0xc0, we used to initialize AX=0xc000 to clear AL at the same time but it is very confusing. We don't have to do this any more because we are explicitly clearing all registers now. - Check size of system configuration table although it is almost always 8. This is to make sure we are not reading some random low physical memory. Hopefully it is just zero in that case. :-) - Fix some style nits and add more comments. Submitted by: paradox (ddkprog yahoo com)[1] --- sys/dev/atkbdc/atkbd.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/sys/dev/atkbdc/atkbd.c b/sys/dev/atkbdc/atkbd.c index beaee1e..6fc2a1f 100644 --- a/sys/dev/atkbdc/atkbd.c +++ b/sys/dev/atkbdc/atkbd.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include -#if 0 +#if defined(__i386__) || defined(__amd64__) #include #include #include @@ -1089,32 +1089,41 @@ atkbd_shutdown_final(void *v) static int get_typematic(keyboard_t *kbd) { -#if 0 +#if defined(__i386__) || defined(__amd64__) /* * Only some systems allow us to retrieve the keyboard repeat * rate previously set via the BIOS... */ x86regs_t regs; - vm_offset_t p; + uint8_t *p; - regs.R_AX = 0xc000; + /* Is BIOS system configuration table supported? */ + bzero(®s, sizeof(regs)); + regs.R_AH = 0xc0; x86bios_intr(®s, 0x15); - if ((regs.R_EFLG & PSL_C) || regs.R_AH) - return ENODEV; - p = BIOS_PADDRTOVADDR((regs.R_ES << 4) + regs.R_BX); - if ((readb(p + 6) & 0x40) == 0) /* int 16, function 0x09 supported? */ - return ENODEV; - regs.R_AX = 0x0900; + if ((regs.R_FLG & PSL_C) || regs.R_AH) + return (ENODEV); + + /* Is int 16, function 0x09 supported? */ + p = x86bios_offset((regs.R_ES << 4) + regs.R_BX); + if (readw(p) < 5 || (readb(p + 6) & 0x40) == 0) + return (ENODEV); + + /* Is int 16, function 0x0306 supported? */ + bzero(®s, sizeof(regs)); + regs.R_AH = 0x09; x86bios_intr(®s, 0x16); - if ((regs.R_AL & 0x08) == 0) /* int 16, function 0x0306 supported? */ - return ENODEV; + if ((regs.R_AL & 0x08) == 0) + return (ENODEV); + + bzero(®s, sizeof(regs)); regs.R_AX = 0x0306; x86bios_intr(®s, 0x16); kbd->kb_delay1 = typematic_delay(regs.R_BH << 5); kbd->kb_delay2 = typematic_rate(regs.R_BL); - return 0; + return (0); #else - return ENODEV; + return (ENODEV); #endif /* __i386__ || __amd64__ */ } -- cgit v1.1