apm.c (64615) | apm.c (65865) |
---|---|
1/* 2 * APM (Advanced Power Management) BIOS Device Driver 3 * 4 * Copyright (c) 1994 UKAI, Fumitoshi. 5 * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org> 6 * Copyright (c) 1996 Nate Williams <nate@FreeBSD.org> 7 * Copyright (c) 1997 Poul-Henning Kamp <phk@FreeBSD.org> 8 * 9 * This software may be used, modified, copied, and distributed, in 10 * both source and binary form provided that the above copyright and 11 * these terms are retained. Under no circumstances is the author 12 * responsible for the proper functioning of this software, nor does 13 * the author assume any responsibility for damages incurred with its 14 * use. 15 * 16 * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) 17 * | 1/* 2 * APM (Advanced Power Management) BIOS Device Driver 3 * 4 * Copyright (c) 1994 UKAI, Fumitoshi. 5 * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org> 6 * Copyright (c) 1996 Nate Williams <nate@FreeBSD.org> 7 * Copyright (c) 1997 Poul-Henning Kamp <phk@FreeBSD.org> 8 * 9 * This software may be used, modified, copied, and distributed, in 10 * both source and binary form provided that the above copyright and 11 * these terms are retained. Under no circumstances is the author 12 * responsible for the proper functioning of this software, nor does 13 * the author assume any responsibility for damages incurred with its 14 * use. 15 * 16 * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) 17 * |
18 * $FreeBSD: head/sys/i386/bios/apm.c 64615 2000-08-13 17:05:27Z ume $ | 18 * $FreeBSD: head/sys/i386/bios/apm.c 65865 2000-09-14 22:34:57Z iwasaki $ |
19 */ 20 21#include <sys/param.h> 22#include <sys/systm.h> 23#include <sys/eventhandler.h> 24#include <sys/conf.h> 25#include <sys/kernel.h> 26#include <sys/time.h> --- 370 unchanged lines hidden (view full) --- 397apm_hook_disestablish(int apmh, struct apmhook *ah) 398{ 399 if (apmh < 0 || apmh >= NAPM_HOOK) 400 return; 401 402 apm_del_hook(&hook[apmh], ah); 403} 404 | 19 */ 20 21#include <sys/param.h> 22#include <sys/systm.h> 23#include <sys/eventhandler.h> 24#include <sys/conf.h> 25#include <sys/kernel.h> 26#include <sys/time.h> --- 370 unchanged lines hidden (view full) --- 397apm_hook_disestablish(int apmh, struct apmhook *ah) 398{ 399 if (apmh < 0 || apmh >= NAPM_HOOK) 400 return; 401 402 apm_del_hook(&hook[apmh], ah); 403} 404 |
405 406static struct timeval suspend_time; 407static struct timeval diff_time; 408 409static int 410apm_default_resume(void *arg) 411{ 412 int pl; 413 u_int second, minute, hour; 414 struct timeval resume_time, tmp_time; 415 416 /* modified for adjkerntz */ 417 pl = splsoftclock(); 418 i8254_restore(); /* restore timer_freq and hz */ 419 inittodr(0); /* adjust time to RTC */ 420 microtime(&resume_time); 421 getmicrotime(&tmp_time); 422 timevaladd(&tmp_time, &diff_time); 423 424#ifdef FIXME 425 /* XXX THIS DOESN'T WORK!!! */ 426 time = tmp_time; 427#endif 428 429#ifdef APM_FIXUP_CALLTODO 430 /* Calculate the delta time suspended */ 431 timevalsub(&resume_time, &suspend_time); 432 /* Fixup the calltodo list with the delta time. */ 433 adjust_timeout_calltodo(&resume_time); 434#endif /* APM_FIXUP_CALLTODOK */ 435 splx(pl); 436#ifndef APM_FIXUP_CALLTODO 437 second = resume_time.tv_sec - suspend_time.tv_sec; 438#else /* APM_FIXUP_CALLTODO */ 439 /* 440 * We've already calculated resume_time to be the delta between 441 * the suspend and the resume. 442 */ 443 second = resume_time.tv_sec; 444#endif /* APM_FIXUP_CALLTODO */ 445 hour = second / 3600; 446 second %= 3600; 447 minute = second / 60; 448 second %= 60; 449 log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n", 450 hour, minute, second); 451 return 0; 452} 453 454static int 455apm_default_suspend(void *arg) 456{ 457 int pl; 458 459 pl = splsoftclock(); 460 microtime(&diff_time); 461 inittodr(0); 462 microtime(&suspend_time); 463 timevalsub(&diff_time, &suspend_time); 464 splx(pl); 465 return 0; 466} 467 | |
468static int apm_record_event __P((struct apm_softc *, u_int)); 469static void apm_processevent(void); 470 471static u_int apm_op_inprog = 0; 472 473static void 474apm_do_suspend(void) 475{ --- 8 unchanged lines hidden (view full) --- 484 485 if (sc->initialized) { 486 error = DEVICE_SUSPEND(root_bus); 487 if (error) { 488 DEVICE_RESUME(root_bus); 489 } else { 490 apm_execute_hook(hook[APM_HOOK_SUSPEND]); 491 if (apm_suspend_system(PMST_SUSPEND) == 0) { | 405static int apm_record_event __P((struct apm_softc *, u_int)); 406static void apm_processevent(void); 407 408static u_int apm_op_inprog = 0; 409 410static void 411apm_do_suspend(void) 412{ --- 8 unchanged lines hidden (view full) --- 421 422 if (sc->initialized) { 423 error = DEVICE_SUSPEND(root_bus); 424 if (error) { 425 DEVICE_RESUME(root_bus); 426 } else { 427 apm_execute_hook(hook[APM_HOOK_SUSPEND]); 428 if (apm_suspend_system(PMST_SUSPEND) == 0) { |
429 sc->suspending = 1; |
|
492 apm_processevent(); 493 } else { 494 /* Failure, 'resume' the system again */ 495 apm_execute_hook(hook[APM_HOOK_RESUME]); 496 DEVICE_RESUME(root_bus); 497 } 498 } 499 } --- 10 unchanged lines hidden (view full) --- 510 apm_op_inprog = 0; 511 sc->standbys = sc->standby_countdown = 0; 512 513 if (sc->initialized) { 514 /* 515 * As far as standby, we don't need to execute 516 * all of suspend hooks. 517 */ | 430 apm_processevent(); 431 } else { 432 /* Failure, 'resume' the system again */ 433 apm_execute_hook(hook[APM_HOOK_RESUME]); 434 DEVICE_RESUME(root_bus); 435 } 436 } 437 } --- 10 unchanged lines hidden (view full) --- 448 apm_op_inprog = 0; 449 sc->standbys = sc->standby_countdown = 0; 450 451 if (sc->initialized) { 452 /* 453 * As far as standby, we don't need to execute 454 * all of suspend hooks. 455 */ |
518 apm_default_suspend(&apm_softc); | |
519 if (apm_suspend_system(PMST_STANDBY) == 0) 520 apm_processevent(); 521 } 522} 523 524static void 525apm_lastreq_notify(void) 526{ --- 68 unchanged lines hidden (view full) --- 595void 596apm_resume(void) 597{ 598 struct apm_softc *sc = &apm_softc; 599 600 if (!sc) 601 return; 602 | 456 if (apm_suspend_system(PMST_STANDBY) == 0) 457 apm_processevent(); 458 } 459} 460 461static void 462apm_lastreq_notify(void) 463{ --- 68 unchanged lines hidden (view full) --- 532void 533apm_resume(void) 534{ 535 struct apm_softc *sc = &apm_softc; 536 537 if (!sc) 538 return; 539 |
540 if (sc->suspending == 0) 541 return; 542 543 sc->suspending = 0; |
|
603 if (sc->initialized) { 604 apm_execute_hook(hook[APM_HOOK_RESUME]); 605 DEVICE_RESUME(root_bus); 606 } 607} 608 609 610/* get power status per battery */ --- 371 unchanged lines hidden (view full) --- 982 apm_resume(); 983 break; 984 OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME); 985 apm_record_event(sc, apm_event); 986 apm_resume(); 987 break; 988 OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME); 989 apm_record_event(sc, apm_event); | 544 if (sc->initialized) { 545 apm_execute_hook(hook[APM_HOOK_RESUME]); 546 DEVICE_RESUME(root_bus); 547 } 548} 549 550 551/* get power status per battery */ --- 371 unchanged lines hidden (view full) --- 923 apm_resume(); 924 break; 925 OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME); 926 apm_record_event(sc, apm_event); 927 apm_resume(); 928 break; 929 OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME); 930 apm_record_event(sc, apm_event); |
990 apm_resume(); | |
991 break; 992 OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW); 993 if (apm_record_event(sc, apm_event)) { 994 apm_battery_low(); 995 apm_suspend(PMST_SUSPEND); 996 } 997 break; 998 OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE); --- 91 unchanged lines hidden (view full) --- 1090 if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) { 1091 if (apm_engage_disengage_pm(1)) { 1092 APM_DPRINT("apm: *Warning* engage function failed err=[%x]", 1093 (sc->bios.r.eax >> 8) & 0xff); 1094 APM_DPRINT(" (Docked or using external power?).\n"); 1095 } 1096 } 1097 | 931 break; 932 OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW); 933 if (apm_record_event(sc, apm_event)) { 934 apm_battery_low(); 935 apm_suspend(PMST_SUSPEND); 936 } 937 break; 938 OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE); --- 91 unchanged lines hidden (view full) --- 1030 if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) { 1031 if (apm_engage_disengage_pm(1)) { 1032 APM_DPRINT("apm: *Warning* engage function failed err=[%x]", 1033 (sc->bios.r.eax >> 8) & 0xff); 1034 APM_DPRINT(" (Docked or using external power?).\n"); 1035 } 1036 } 1037 |
1098 /* default suspend hook */ 1099 sc->sc_suspend.ah_fun = apm_default_suspend; 1100 sc->sc_suspend.ah_arg = sc; 1101 sc->sc_suspend.ah_name = "default suspend"; 1102 sc->sc_suspend.ah_order = APM_MAX_ORDER; 1103 1104 /* default resume hook */ 1105 sc->sc_resume.ah_fun = apm_default_resume; 1106 sc->sc_resume.ah_arg = sc; 1107 sc->sc_resume.ah_name = "default resume"; 1108 sc->sc_resume.ah_order = APM_MIN_ORDER; 1109 1110 apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend); 1111 apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume); 1112 | |
1113 /* Power the system off using APM */ 1114 EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL, 1115 SHUTDOWN_PRI_LAST); 1116 1117 sc->initialized = 1; | 1038 /* Power the system off using APM */ 1039 EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL, 1040 SHUTDOWN_PRI_LAST); 1041 1042 sc->initialized = 1; |
1043 sc->suspending = 0; |
|
1118 1119 make_dev(&apm_cdevsw, 0, 0, 5, 0660, "apm"); 1120 make_dev(&apm_cdevsw, 8, 0, 5, 0660, "apmctl"); 1121 return 0; 1122} 1123 1124static int 1125apmopen(dev_t dev, int flag, int fmt, struct proc *p) --- 268 unchanged lines hidden --- | 1044 1045 make_dev(&apm_cdevsw, 0, 0, 5, 0660, "apm"); 1046 make_dev(&apm_cdevsw, 8, 0, 5, 0660, "apmctl"); 1047 return 0; 1048} 1049 1050static int 1051apmopen(dev_t dev, int flag, int fmt, struct proc *p) --- 268 unchanged lines hidden --- |