Index: apm.c =================================================================== RCS file: /home/ncvs/src/sys/i386/apm/apm.c,v retrieving revision 1.115 diff -u -r1.115 apm.c --- apm.c 2000/07/19 06:32:00 1.115 +++ apm.c 2000/07/27 20:09:14 @@ -103,9 +103,11 @@ static int apm_suspend_delay = 1; static int apm_standby_delay = 1; +static int apm_debug = 0; SYSCTL_INT(_machdep, OID_AUTO, apm_suspend_delay, CTLFLAG_RW, &apm_suspend_delay, 1, ""); SYSCTL_INT(_machdep, OID_AUTO, apm_standby_delay, CTLFLAG_RW, &apm_standby_delay, 1, ""); +SYSCTL_INT(_debug, OID_AUTO, apm_debug, CTLFLAG_RW, &apm_debug, 0, ""); /* * return 0 if the function successfull, @@ -120,10 +122,10 @@ u_int apm_func = sc->bios.r.eax & 0xff; if (!apm_check_function_supported(sc->intversion, apm_func)) { -#ifdef APM_DEBUG - printf("apm_bioscall: function 0x%x is not supported in v%d.%d\n", - apm_func, sc->majorversion, sc->minorversion); -#endif + if (apm_debug) { + printf("apm_bioscall: function 0x%x is not supported in v%d.%d\n", + apm_func, sc->majorversion, sc->minorversion); + } return (-1); } @@ -269,12 +271,21 @@ sc->bios.r.ebx = PMDV_DISP0; sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND; sc->bios.r.edx = 0; - if (apm_bioscall()) { - printf("Display off failure: errcode = %d\n", - 0xff & (sc->bios.r.eax >> 8)); - return 1; + if (apm_bioscall() == 0) { + return 0; } - return 0; + + /* If failed, then try to blank all display devices instead. */ + sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE; + sc->bios.r.ebx = 0x01ff; /* all display devices */ + sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND; + sc->bios.r.edx = 0; + if (apm_bioscall() == 0) { + return 0; + } + printf("Display off failure: errcode = %d\n", + 0xff & (sc->bios.r.eax >> 8)); + return 1; } /* @@ -309,9 +320,9 @@ int s; struct apmhook *p, *prev; -#ifdef APM_DEBUG - printf("Add hook \"%s\"\n", ah->ah_name); -#endif + if (apm_debug) { + printf("Add hook \"%s\"\n", ah->ah_name); + } s = splhigh(); if (ah == NULL) @@ -362,9 +373,9 @@ struct apmhook *p; for (p = list; p != NULL; p = p->ah_next) { -#ifdef APM_DEBUG - printf("Execute APM hook \"%s.\"\n", p->ah_name); -#endif + if (apm_debug) { + printf("Execute APM hook \"%s.\"\n", p->ah_name); + } if ((*(p->ah_fun))(p->ah_arg)) printf("Warning: APM hook \"%s\" failed", p->ah_name); } @@ -537,9 +548,9 @@ sc->bios.r.edx = 0; if (apm_bioscall()) { -#ifdef APM_DEBUG - printf("apm_lastreq_rejected: failed\n"); -#endif + if (apm_debug) { + printf("apm_lastreq_rejected: failed\n"); + } return 1; } apm_op_inprog = 0; @@ -725,9 +736,9 @@ { struct apm_softc *sc = &apm_softc; -#ifdef APM_DEBUG - printf("called apm_event_enable()\n"); -#endif + if (apm_debug) { + printf("called apm_event_enable()\n"); + } if (sc->initialized) { sc->active = 1; apm_timeout(sc); @@ -740,9 +751,9 @@ { struct apm_softc *sc = &apm_softc; -#ifdef APM_DEBUG - printf("called apm_event_disable()\n"); -#endif + if (apm_debug) { + printf("called apm_event_disable()\n"); + } if (sc->initialized) { untimeout(apm_timeout, NULL, apm_timeout_ch); sc->active = 0; @@ -903,12 +914,11 @@ int apm_event; struct apm_softc *sc = &apm_softc; -#ifdef APM_DEBUG -# define OPMEV_DEBUGMESSAGE(symbol) case symbol: \ - printf("Received APM Event: " #symbol "\n"); -#else -# define OPMEV_DEBUGMESSAGE(symbol) case symbol: -#endif +#define OPMEV_DEBUGMESSAGE(symbol) case symbol: \ + if (apm_debug) { \ + printf("Received APM Event: " #symbol "\n"); \ + } + do { apm_event = apm_getevent(); switch (apm_event) { @@ -1013,18 +1023,19 @@ /* Always call HLT in idle loop */ sc->always_halt_cpu = 1; - /* print bootstrap messages */ -#ifdef APM_DEBUG - printf("apm: APM BIOS version %04x\n", apm_version); - printf("apm: Code16 0x%08x, Data 0x%08x\n", - sc->bios.seg.code16.base, sc->bios.seg.data.base); - printf("apm: Code entry 0x%08x, Idling CPU %s, Management %s\n", - sc->bios.entry, is_enabled(sc->slow_idle_cpu), - is_enabled(!sc->disabled)); - printf("apm: CS_limit=0x%x, DS_limit=0x%x\n", - sc->bios.seg.code16.limit, sc->bios.seg.data.limit); -#endif /* APM_DEBUG */ + getenv_int("debug.apm_debug", &apm_debug); + /* print bootstrap messages */ + if (apm_debug) { + printf("apm: APM BIOS version %04lx\n", apm_version); + printf("apm: Code16 0x%08x, Data 0x%08x\n", + sc->bios.seg.code16.base, sc->bios.seg.data.base); + printf("apm: Code entry 0x%08x, Idling CPU %s, Management %s\n", + sc->bios.entry, is_enabled(sc->slow_idle_cpu), + is_enabled(!sc->disabled)); + printf("apm: CS_limit=0x%x, DS_limit=0x%x\n", + sc->bios.seg.code16.limit, sc->bios.seg.data.limit); + } /* * In one test, apm bios version was 1.02; an attempt to register * a 1.04 driver resulted in a 1.00 connection! Registering a @@ -1041,38 +1052,36 @@ sc->intversion = INTVERSION(sc->majorversion, sc->minorversion); -#ifdef APM_DEBUG - if (sc->intversion >= INTVERSION(1, 1)) - printf("apm: Engaged control %s\n", is_enabled(!sc->disengaged)); -#endif - - printf("apm: found APM BIOS v%ld.%ld, connected at v%d.%d\n", + if (apm_debug) { + if (sc->intversion >= INTVERSION(1, 1)) + printf("apm: Engaged control %s\n", is_enabled(!sc->disengaged)); + } + device_printf(dev, "found APM BIOS v%ld.%ld, connected at v%d.%d\n", ((apm_version & 0xf000) >> 12) * 10 + ((apm_version & 0x0f00) >> 8), ((apm_version & 0x00f0) >> 4) * 10 + ((apm_version & 0x000f) >> 0), sc->majorversion, sc->minorversion); -#ifdef APM_DEBUG - printf("apm: Slow Idling CPU %s\n", is_enabled(sc->slow_idle_cpu)); -#endif - + if (apm_debug) { + printf("apm: Slow Idling CPU %s\n", is_enabled(sc->slow_idle_cpu)); + } /* enable power management */ if (sc->disabled) { if (apm_enable_disable_pm(1)) { -#ifdef APM_DEBUG - printf("apm: *Warning* enable function failed! [%x]\n", - (sc->bios.r.eax >> 8) & 0xff); -#endif + if (apm_debug) { + printf("apm: *Warning* enable function failed! [%x]\n", + (sc->bios.r.eax >> 8) & 0xff); + } } } /* engage power managment (APM 1.1 or later) */ if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) { if (apm_engage_disengage_pm(1)) { -#ifdef APM_DEBUG - printf("apm: *Warning* engage function failed err=[%x]", - (sc->bios.r.eax >> 8) & 0xff); - printf(" (Docked or using external power?).\n"); -#endif + if (apm_debug) { + printf("apm: *Warning* engage function failed err=[%x]", + (sc->bios.r.eax >> 8) & 0xff); + printf(" (Docked or using external power?).\n"); + } } } @@ -1164,9 +1173,9 @@ if (!sc->initialized) return (ENXIO); -#ifdef APM_DEBUG - printf("APM ioctl: cmd = 0x%x\n", cmd); -#endif + if (apm_debug) { + printf("APM ioctl: cmd = 0x%lx\n", cmd); + } switch (cmd) { case APMIO_SUSPEND: if (!(flag & FWRITE)) @@ -1330,9 +1339,9 @@ enabled = 0; } sc->event_filter[event_type] = enabled; -#ifdef APM_DEBUG - printf("apmwrite: event 0x%x %s\n", event_type, is_enabled(enabled)); -#endif + if (apm_debug) { + printf("apmwrite: event 0x%x %s\n", event_type, is_enabled(enabled)); + } return uio->uio_resid; }