Index: apm.c =================================================================== RCS file: /u3/cvsroot/src/sys/arch/i386/i386/apm.c,v retrieving revision 1.66 diff -c -r1.66 apm.c *** apm.c 1997/01/18 14:30:23 1.66 --- apm.c 1997/03/02 17:40:40 *************** *** 291,296 **** --- 291,297 ---- int apm_suspends = 0; int apm_battlow = 0; int apm_damn_fool_bios = 0; + int apm_op_inprog = 0; STATIC void apm_get_powstate(dev) *************** *** 319,324 **** --- 320,329 ---- static int apm_evindex = 0; + /* + * return 0 if the user will notice and handle the event, + * return 1 if the kernel driver should do so. + */ STATIC int apm_record_event(sc, event_type) struct apm_softc *sc; *************** *** 350,388 **** switch(regs->bx) { case APM_USER_STANDBY_REQ: ! DPRINTF(("user wants STANDBY--fat chance\n")); ! (void) apm_set_powstate(APM_DEV_ALLDEVS, APM_LASTREQ_REJECTED); apm_powmgt_enable(1); /* in case BIOS hates being spurned */ ! #ifndef APM_NO_STANDBY if (apm_record_event(sc, regs->bx)) apm_userstandbys++; #endif break; case APM_STANDBY_REQ: DPRINTF(("standby requested\n")); if (apm_standbys || apm_suspends) DPRINTF(("damn fool BIOS did not wait for answer\n")); ! #ifndef APM_NO_STANDBY ! if (apm_record_event(sc, regs->bx)) { ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_INPROG); apm_standbys++; ! } else #endif - { - (void) apm_set_powstate(APM_DEV_ALLDEVS, - APM_LASTREQ_REJECTED); - /* in case BIOS hates being spurned */ - apm_powmgt_enable(1); - } break; case APM_USER_SUSPEND_REQ: ! DPRINTF(("user wants suspend--fat chance!\n")); ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_REJECTED); ! apm_powmgt_enable(1); /* in case BIOS hates being spurned */ if (apm_record_event(sc, regs->bx)) apm_suspends++; break; case APM_SUSPEND_REQ: DPRINTF(("suspend requested\n")); --- 355,396 ---- switch(regs->bx) { case APM_USER_STANDBY_REQ: ! DPRINTF(("user standby requested\n")); ! #ifdef APM_NO_STANDBY ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_REJECTED); apm_powmgt_enable(1); /* in case BIOS hates being spurned */ ! #else if (apm_record_event(sc, regs->bx)) apm_userstandbys++; + apm_op_inprog++; + (void) apm_set_powstate(APM_DEV_ALLDEVS, + APM_LASTREQ_INPROG); #endif break; case APM_STANDBY_REQ: DPRINTF(("standby requested\n")); if (apm_standbys || apm_suspends) DPRINTF(("damn fool BIOS did not wait for answer\n")); ! #ifdef APM_NO_STANDBY ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_REJECTED); ! apm_powmgt_enable(1); /* in case BIOS hates being spurned */ ! #else ! if (apm_record_event(sc, regs->bx)) apm_standbys++; ! apm_op_inprog++; ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_INPROG); #endif break; case APM_USER_SUSPEND_REQ: ! DPRINTF(("user wants suspend\n")); if (apm_record_event(sc, regs->bx)) apm_suspends++; + apm_op_inprog++; + (void) apm_set_powstate(APM_DEV_ALLDEVS, + APM_LASTREQ_INPROG); break; case APM_SUSPEND_REQ: DPRINTF(("suspend requested\n")); *************** *** 391,406 **** /* just give up the fight */ apm_damn_fool_bios = 1; } ! if (apm_record_event(sc, regs->bx)) { ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_INPROG); apm_suspends++; ! } else { ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_REJECTED); ! /* in case BIOS hates being spurned */ ! apm_powmgt_enable(1); ! } break; case APM_POWER_CHANGE: DPRINTF(("power status change\n")); --- 399,409 ---- /* just give up the fight */ apm_damn_fool_bios = 1; } ! if (apm_record_event(sc, regs->bx)) apm_suspends++; ! apm_op_inprog++; ! (void) apm_set_powstate(APM_DEV_ALLDEVS, ! APM_LASTREQ_INPROG); break; case APM_POWER_CHANGE: DPRINTF(("power status change\n")); *************** *** 416,422 **** apm_record_event(sc, regs->bx); break; case APM_CRIT_RESUME: ! DPRINTF(("system resumed without us!\n")); inittodr(time.tv_sec); apm_record_event(sc, regs->bx); break; --- 419,425 ---- apm_record_event(sc, regs->bx); break; case APM_CRIT_RESUME: ! DPRINTF(("resume from critical system suspend!\n")); inittodr(time.tv_sec); apm_record_event(sc, regs->bx); break; *************** *** 459,472 **** struct apmregs regs; struct apm_softc *sc = arg; ! while (apm_get_event(®s) == 0 && !apm_damn_fool_bios) { apm_event_handle(sc, ®s); ! }; if (APM_ERR_CODE(®s) != APM_ERR_NOEVENTS) apm_perror("get event", ®s); if (apm_suspends) { apm_suspend(); } else if (apm_standbys || apm_userstandbys) { apm_standby(); } apm_suspends = apm_standbys = apm_battlow = apm_userstandbys = 0; --- 462,484 ---- struct apmregs regs; struct apm_softc *sc = arg; ! /* ! * tell the BIOS we're working on it, if asked to do a ! * suspend/standby ! */ ! if (apm_op_inprog) ! apm_set_powstate(APM_DEV_ALLDEVS, APM_LASTREQ_INPROG); ! ! while (apm_get_event(®s) == 0 && !apm_damn_fool_bios) apm_event_handle(sc, ®s); ! if (APM_ERR_CODE(®s) != APM_ERR_NOEVENTS) apm_perror("get event", ®s); if (apm_suspends) { + apm_op_inprog = 0; apm_suspend(); } else if (apm_standbys || apm_userstandbys) { + apm_op_inprog = 0; apm_standby(); } apm_suspends = apm_standbys = apm_battlow = apm_userstandbys = 0; *************** *** 946,955 **** /* * enable power management if it's disabled. */ ! /* XXX some bogus APM BIOSes don't set the disabled bit in ! the connect state, yet still complain about the functions ! being disabled when other calls are made. sigh. */ ! /* if (apminfo.apm_detail & APM_BIOS_PM_DISABLED) */ apm_powmgt_enable(1); /* * Engage cooperative power mgt (we get to do it) --- 958,964 ---- /* * enable power management if it's disabled. */ ! if (apminfo.apm_detail & APM_BIOS_PM_DISABLED) apm_powmgt_enable(1); /* * Engage cooperative power mgt (we get to do it)