DEVFS - remove dev_ops_add(), dev_ops_get(), and get_dev()
[dragonfly.git] / sys / platform / pc32 / apm / apm.c
CommitLineData
984263bc
MD
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: src/sys/i386/apm/apm.c,v 1.114.2.5 2002/11/02 04:41:50 iwasaki Exp $
26be20a0 19 * $DragonFly: src/sys/platform/pc32/apm/apm.c,v 1.21 2006/12/23 00:27:03 swildner Exp $
984263bc
MD
20 */
21
22#include <sys/param.h>
23#include <sys/systm.h>
24#include <sys/eventhandler.h>
25#include <sys/conf.h>
fef8985e 26#include <sys/device.h>
984263bc
MD
27#include <sys/kernel.h>
28#include <sys/time.h>
29#include <sys/reboot.h>
30#include <sys/bus.h>
9183fa5b 31#include <sys/selinfo.h>
984263bc
MD
32#include <sys/poll.h>
33#include <sys/fcntl.h>
984263bc
MD
34#include <sys/uio.h>
35#include <sys/signalvar.h>
36#include <sys/sysctl.h>
37#include <machine/apm_bios.h>
38#include <machine/segments.h>
39#include <machine/clock.h>
40#include <vm/vm.h>
41#include <vm/vm_param.h>
42#include <vm/pmap.h>
43#include <sys/syslog.h>
9acd5bbb 44#include <sys/thread2.h>
984263bc
MD
45
46#include <machine/pc/bios.h>
47#include <machine/vm86.h>
48
a9295349 49#include <machine_base/apm/apm.h>
984263bc
MD
50
51/* Used by the apm_saver screen saver module */
3ae0cd58 52int apm_display (int newstate);
984263bc
MD
53struct apm_softc apm_softc;
54
3ae0cd58 55static void apm_resume (void);
984263bc 56static int apm_bioscall(void);
3ae0cd58 57static int apm_check_function_supported (u_int version, u_int func);
984263bc
MD
58
59static u_long apm_version;
60
61int apm_evindex;
62
63#define SCFLAG_ONORMAL 0x0000001
64#define SCFLAG_OCTL 0x0000002
65#define SCFLAG_OPEN (SCFLAG_ONORMAL|SCFLAG_OCTL)
66
67#define APMDEV(dev) (minor(dev)&0x0f)
68#define APMDEV_NORMAL 0
69#define APMDEV_CTL 8
70
71static struct apmhook *hook[NAPM_HOOK]; /* XXX */
72
73#define is_enabled(foo) ((foo) ? "enabled" : "disabled")
74
75/* Map version number to integer (keeps ordering of version numbers) */
76#define INTVERSION(major, minor) ((major)*100 + (minor))
77
b02bbab0 78static struct callout apm_timeout_ch;
984263bc
MD
79
80static timeout_t apm_timeout;
81static d_open_t apmopen;
82static d_close_t apmclose;
83static d_write_t apmwrite;
84static d_ioctl_t apmioctl;
85static d_poll_t apmpoll;
86
87#define CDEV_MAJOR 39
fef8985e
MD
88static struct dev_ops apm_ops = {
89 { "apm", CDEV_MAJOR, 0 },
90 .d_open = apmopen,
91 .d_close = apmclose,
92 .d_write = apmwrite,
93 .d_ioctl = apmioctl,
94 .d_poll = apmpoll,
984263bc
MD
95};
96
97static int apm_suspend_delay = 1;
98static int apm_standby_delay = 1;
99static int apm_debug = 0;
100
101#define APM_DPRINT(args...) do { \
102 if (apm_debug) { \
26be20a0 103 kprintf(args); \
984263bc
MD
104 } \
105} while (0)
106
107SYSCTL_INT(_machdep, OID_AUTO, apm_suspend_delay, CTLFLAG_RW, &apm_suspend_delay, 1, "");
108SYSCTL_INT(_machdep, OID_AUTO, apm_standby_delay, CTLFLAG_RW, &apm_standby_delay, 1, "");
109SYSCTL_INT(_debug, OID_AUTO, apm_debug, CTLFLAG_RW, &apm_debug, 0, "");
110
111/*
112 * return 0 if the function successfull,
113 * return 1 if the function unsuccessfull,
114 * return -1 if the function unsupported.
115 */
116static int
117apm_bioscall(void)
118{
119 struct apm_softc *sc = &apm_softc;
71f385dc 120 int error = 0;
984263bc
MD
121 u_int apm_func = sc->bios.r.eax & 0xff;
122
123 if (!apm_check_function_supported(sc->intversion, apm_func)) {
124 APM_DPRINT("apm_bioscall: function 0x%x is not supported in v%d.%d\n",
125 apm_func, sc->majorversion, sc->minorversion);
126 return (-1);
127 }
128
129 sc->bios_busy = 1;
130 if (sc->connectmode == APM_PROT32CONNECT) {
131 set_bios_selectors(&sc->bios.seg,
132 BIOSCODE_FLAG | BIOSDATA_FLAG);
71f385dc 133 error = bios32(&sc->bios.r,
984263bc
MD
134 sc->bios.entry, GSEL(GBIOSCODE32_SEL, SEL_KPL));
135 } else {
71f385dc 136 error = bios16(&sc->bios, NULL);
984263bc
MD
137 }
138 sc->bios_busy = 0;
71f385dc 139 return (error);
984263bc
MD
140}
141
142/* check whether APM function is supported (1) or not (0). */
143static int
144apm_check_function_supported(u_int version, u_int func)
145{
146 /* except driver version */
147 if (func == APM_DRVVERSION) {
148 return (1);
149 }
150
151 switch (version) {
152 case INTVERSION(1, 0):
153 if (func > APM_GETPMEVENT) {
154 return (0); /* not supported */
155 }
156 break;
157 case INTVERSION(1, 1):
158 if (func > APM_ENGAGEDISENGAGEPM &&
159 func < APM_OEMFUNC) {
160 return (0); /* not supported */
161 }
162 break;
163 case INTVERSION(1, 2):
164 break;
165 }
166
167 return (1); /* supported */
168}
169
170/* enable/disable power management */
171static int
172apm_enable_disable_pm(int enable)
173{
174 struct apm_softc *sc = &apm_softc;
175
176 sc->bios.r.eax = (APM_BIOS << 8) | APM_ENABLEDISABLEPM;
177
178 if (sc->intversion >= INTVERSION(1, 1))
179 sc->bios.r.ebx = PMDV_ALLDEV;
180 else
181 sc->bios.r.ebx = 0xffff; /* APM version 1.0 only */
182 sc->bios.r.ecx = enable;
183 sc->bios.r.edx = 0;
184 return (apm_bioscall());
185}
186
187/* register driver version (APM 1.1 or later) */
188static int
189apm_driver_version(int version)
190{
191 struct apm_softc *sc = &apm_softc;
192
193 sc->bios.r.eax = (APM_BIOS << 8) | APM_DRVVERSION;
194 sc->bios.r.ebx = 0x0;
195 sc->bios.r.ecx = version;
196 sc->bios.r.edx = 0;
197
198 if (apm_bioscall() == 0 && sc->bios.r.eax == version)
199 return (0);
200
201 /* Some old BIOSes don't return the connection version in %ax. */
202 if (sc->bios.r.eax == ((APM_BIOS << 8) | APM_DRVVERSION))
203 return (0);
204
205 return (1);
206}
207
208/* engage/disengage power management (APM 1.1 or later) */
209static int
210apm_engage_disengage_pm(int engage)
211{
212 struct apm_softc *sc = &apm_softc;
213
214 sc->bios.r.eax = (APM_BIOS << 8) | APM_ENGAGEDISENGAGEPM;
215 sc->bios.r.ebx = PMDV_ALLDEV;
216 sc->bios.r.ecx = engage;
217 sc->bios.r.edx = 0;
218 return (apm_bioscall());
219}
220
221/* get PM event */
222static u_int
223apm_getevent(void)
224{
225 struct apm_softc *sc = &apm_softc;
226
227 sc->bios.r.eax = (APM_BIOS << 8) | APM_GETPMEVENT;
228
229 sc->bios.r.ebx = 0;
230 sc->bios.r.ecx = 0;
231 sc->bios.r.edx = 0;
232 if (apm_bioscall())
233 return (PMEV_NOEVENT);
234 return (sc->bios.r.ebx & 0xffff);
235}
236
237/* suspend entire system */
238static int
239apm_suspend_system(int state)
240{
241 struct apm_softc *sc = &apm_softc;
242
243 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
244 sc->bios.r.ebx = PMDV_ALLDEV;
245 sc->bios.r.ecx = state;
246 sc->bios.r.edx = 0;
247
248 if (apm_bioscall()) {
26be20a0 249 kprintf("Entire system suspend failure: errcode = %d\n",
984263bc
MD
250 0xff & (sc->bios.r.eax >> 8));
251 return 1;
252 }
253 return 0;
254}
255
256/* Display control */
257/*
258 * Experimental implementation: My laptop machine can't handle this function
259 * If your laptop can control the display via APM, please inform me.
260 * HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
261 */
262int
263apm_display(int newstate)
264{
265 struct apm_softc *sc = &apm_softc;
266
267 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
268 sc->bios.r.ebx = PMDV_DISP0;
269 sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND;
270 sc->bios.r.edx = 0;
271 if (apm_bioscall() == 0) {
272 return 0;
273 }
274
275 /* If failed, then try to blank all display devices instead. */
276 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
277 sc->bios.r.ebx = PMDV_DISPALL; /* all display devices */
278 sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND;
279 sc->bios.r.edx = 0;
280 if (apm_bioscall() == 0) {
281 return 0;
282 }
26be20a0 283 kprintf("Display off failure: errcode = %d\n",
984263bc
MD
284 0xff & (sc->bios.r.eax >> 8));
285 return 1;
286}
287
288/*
289 * Turn off the entire system.
290 */
291static void
292apm_power_off(void *junk, int howto)
293{
294 struct apm_softc *sc = &apm_softc;
295
296 /* Not halting powering off, or not active */
297 if (!(howto & RB_POWEROFF) || !apm_softc.active)
298 return;
299 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
300 sc->bios.r.ebx = PMDV_ALLDEV;
301 sc->bios.r.ecx = PMST_OFF;
302 sc->bios.r.edx = 0;
09e6e929 303 apm_bioscall();
984263bc
MD
304}
305
306/* APM Battery low handler */
307static void
308apm_battery_low(void)
309{
26be20a0 310 kprintf("\007\007 * * * BATTERY IS LOW * * * \007\007");
984263bc
MD
311}
312
313/* APM hook manager */
314static struct apmhook *
315apm_add_hook(struct apmhook **list, struct apmhook *ah)
316{
984263bc
MD
317 struct apmhook *p, *prev;
318
319 APM_DPRINT("Add hook \"%s\"\n", ah->ah_name);
320
9acd5bbb 321 crit_enter();
984263bc
MD
322 if (ah == NULL)
323 panic("illegal apm_hook!");
324 prev = NULL;
325 for (p = *list; p != NULL; prev = p, p = p->ah_next)
326 if (p->ah_order > ah->ah_order)
327 break;
328
329 if (prev == NULL) {
330 ah->ah_next = *list;
331 *list = ah;
332 } else {
333 ah->ah_next = prev->ah_next;
334 prev->ah_next = ah;
335 }
9acd5bbb 336 crit_exit();
984263bc
MD
337 return ah;
338}
339
340static void
341apm_del_hook(struct apmhook **list, struct apmhook *ah)
342{
984263bc
MD
343 struct apmhook *p, *prev;
344
9acd5bbb 345 crit_enter();
984263bc
MD
346 prev = NULL;
347 for (p = *list; p != NULL; prev = p, p = p->ah_next)
348 if (p == ah)
349 goto deleteit;
350 panic("Tried to delete unregistered apm_hook.");
351 goto nosuchnode;
352deleteit:
353 if (prev != NULL)
354 prev->ah_next = p->ah_next;
355 else
356 *list = p->ah_next;
357nosuchnode:
9acd5bbb 358 crit_exit();
984263bc
MD
359}
360
361
362/* APM driver calls some functions automatically */
363static void
364apm_execute_hook(struct apmhook *list)
365{
366 struct apmhook *p;
367
368 for (p = list; p != NULL; p = p->ah_next) {
369 APM_DPRINT("Execute APM hook \"%s.\"\n", p->ah_name);
370 if ((*(p->ah_fun))(p->ah_arg))
26be20a0 371 kprintf("Warning: APM hook \"%s\" failed", p->ah_name);
984263bc
MD
372 }
373}
374
375
376/* establish an apm hook */
377struct apmhook *
378apm_hook_establish(int apmh, struct apmhook *ah)
379{
380 if (apmh < 0 || apmh >= NAPM_HOOK)
381 return NULL;
382
383 return apm_add_hook(&hook[apmh], ah);
384}
385
386/* disestablish an apm hook */
387void
388apm_hook_disestablish(int apmh, struct apmhook *ah)
389{
390 if (apmh < 0 || apmh >= NAPM_HOOK)
391 return;
392
393 apm_del_hook(&hook[apmh], ah);
394}
395
396
397static struct timeval suspend_time;
398static struct timeval diff_time;
399
400static int
401apm_default_resume(void *arg)
402{
984263bc
MD
403 u_int second, minute, hour;
404 struct timeval resume_time, tmp_time;
405
406 /* modified for adjkerntz */
9acd5bbb 407 crit_enter();
984263bc
MD
408 timer_restore(); /* restore the all timers */
409 inittodr(0); /* adjust time to RTC */
410 microtime(&resume_time);
411 getmicrotime(&tmp_time);
412 timevaladd(&tmp_time, &diff_time);
413
414#ifdef FIXME
415 /* XXX THIS DOESN'T WORK!!! */
416 time = tmp_time;
417#endif
418
419#ifdef APM_FIXUP_CALLTODO
420 /* Calculate the delta time suspended */
421 timevalsub(&resume_time, &suspend_time);
422 /* Fixup the calltodo list with the delta time. */
423 adjust_timeout_calltodo(&resume_time);
424#endif /* APM_FIXUP_CALLTODOK */
9acd5bbb 425 crit_exit();
984263bc
MD
426#ifndef APM_FIXUP_CALLTODO
427 second = resume_time.tv_sec - suspend_time.tv_sec;
428#else /* APM_FIXUP_CALLTODO */
429 /*
430 * We've already calculated resume_time to be the delta between
431 * the suspend and the resume.
432 */
433 second = resume_time.tv_sec;
434#endif /* APM_FIXUP_CALLTODO */
435 hour = second / 3600;
436 second %= 3600;
437 minute = second / 60;
438 second %= 60;
439 log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n",
440 hour, minute, second);
441 return 0;
442}
443
444static int
445apm_default_suspend(void *arg)
446{
9acd5bbb 447 crit_enter();
984263bc
MD
448 microtime(&diff_time);
449 inittodr(0);
450 microtime(&suspend_time);
451 timevalsub(&diff_time, &suspend_time);
9acd5bbb 452 crit_exit();
984263bc
MD
453 return 0;
454}
455
3ae0cd58 456static int apm_record_event (struct apm_softc *, u_int);
984263bc
MD
457static void apm_processevent(void);
458
459static u_int apm_op_inprog = 0;
460
461static void
462apm_do_suspend(void)
463{
464 struct apm_softc *sc = &apm_softc;
465 int error;
466
467 if (!sc)
468 return;
469
470 apm_op_inprog = 0;
471 sc->suspends = sc->suspend_countdown = 0;
472
473 if (sc->initialized) {
474 error = DEVICE_SUSPEND(root_bus);
475 if (error) {
476 DEVICE_RESUME(root_bus);
477 } else {
478 apm_execute_hook(hook[APM_HOOK_SUSPEND]);
479 if (apm_suspend_system(PMST_SUSPEND) == 0) {
480 apm_processevent();
481 } else {
482 /* Failure, 'resume' the system again */
483 apm_execute_hook(hook[APM_HOOK_RESUME]);
484 DEVICE_RESUME(root_bus);
485 }
486 }
487 }
488}
489
490static void
491apm_do_standby(void)
492{
493 struct apm_softc *sc = &apm_softc;
494
495 if (!sc)
496 return;
497
498 apm_op_inprog = 0;
499 sc->standbys = sc->standby_countdown = 0;
500
501 if (sc->initialized) {
502 /*
503 * As far as standby, we don't need to execute
504 * all of suspend hooks.
505 */
506 apm_default_suspend(&apm_softc);
507 if (apm_suspend_system(PMST_STANDBY) == 0)
508 apm_processevent();
509 }
510}
511
512static void
513apm_lastreq_notify(void)
514{
515 struct apm_softc *sc = &apm_softc;
516
517 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
518 sc->bios.r.ebx = PMDV_ALLDEV;
519 sc->bios.r.ecx = PMST_LASTREQNOTIFY;
520 sc->bios.r.edx = 0;
521 apm_bioscall();
522}
523
524static int
525apm_lastreq_rejected(void)
526{
527 struct apm_softc *sc = &apm_softc;
528
529 if (apm_op_inprog == 0) {
530 return 1; /* no operation in progress */
531 }
532
533 sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
534 sc->bios.r.ebx = PMDV_ALLDEV;
535 sc->bios.r.ecx = PMST_LASTREQREJECT;
536 sc->bios.r.edx = 0;
537
538 if (apm_bioscall()) {
539 APM_DPRINT("apm_lastreq_rejected: failed\n");
540 return 1;
541 }
542 apm_op_inprog = 0;
543 return 0;
544}
545
546/*
547 * Public interface to the suspend/resume:
548 *
549 * Execute suspend and resume hook before and after sleep, respectively.
550 *
551 */
552
553void
554apm_suspend(int state)
555{
556 struct apm_softc *sc = &apm_softc;
557
558 if (!sc->initialized)
559 return;
560
561 switch (state) {
562 case PMST_SUSPEND:
563 if (sc->suspends)
564 return;
565 sc->suspends++;
566 sc->suspend_countdown = apm_suspend_delay;
567 break;
568 case PMST_STANDBY:
569 if (sc->standbys)
570 return;
571 sc->standbys++;
572 sc->standby_countdown = apm_standby_delay;
573 break;
574 default:
26be20a0 575 kprintf("apm_suspend: Unknown Suspend state 0x%x\n", state);
984263bc
MD
576 return;
577 }
578
579 apm_op_inprog++;
580 apm_lastreq_notify();
581}
582
583void
584apm_resume(void)
585{
586 struct apm_softc *sc = &apm_softc;
587
588 if (!sc)
589 return;
590
591 if (sc->initialized) {
592 apm_execute_hook(hook[APM_HOOK_RESUME]);
593 DEVICE_RESUME(root_bus);
594 }
595}
596
597
598/* get power status per battery */
599static int
600apm_get_pwstatus(apm_pwstatus_t app)
601{
602 struct apm_softc *sc = &apm_softc;
603
604 if (app->ap_device != PMDV_ALLDEV &&
605 (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
606 return 1;
607
608 sc->bios.r.eax = (APM_BIOS << 8) | APM_GETPWSTATUS;
609 sc->bios.r.ebx = app->ap_device;
610 sc->bios.r.ecx = 0;
611 sc->bios.r.edx = 0xffff; /* default to unknown battery time */
612
613 if (apm_bioscall())
614 return 1;
615
616 app->ap_acline = (sc->bios.r.ebx >> 8) & 0xff;
617 app->ap_batt_stat = sc->bios.r.ebx & 0xff;
618 app->ap_batt_flag = (sc->bios.r.ecx >> 8) & 0xff;
619 app->ap_batt_life = sc->bios.r.ecx & 0xff;
620 sc->bios.r.edx &= 0xffff;
621 if (sc->bios.r.edx == 0xffff) /* Time is unknown */
622 app->ap_batt_time = -1;
623 else if (sc->bios.r.edx & 0x8000) /* Time is in minutes */
624 app->ap_batt_time = (sc->bios.r.edx & 0x7fff) * 60;
625 else /* Time is in seconds */
626 app->ap_batt_time = sc->bios.r.edx;
627
628 return 0;
629}
630
631
632/* get APM information */
633static int
634apm_get_info(apm_info_t aip)
635{
636 struct apm_softc *sc = &apm_softc;
637 struct apm_pwstatus aps;
638
639 bzero(&aps, sizeof(aps));
640 aps.ap_device = PMDV_ALLDEV;
641 if (apm_get_pwstatus(&aps))
642 return 1;
643
644 aip->ai_infoversion = 1;
645 aip->ai_acline = aps.ap_acline;
646 aip->ai_batt_stat = aps.ap_batt_stat;
647 aip->ai_batt_life = aps.ap_batt_life;
648 aip->ai_batt_time = aps.ap_batt_time;
649 aip->ai_major = (u_int)sc->majorversion;
650 aip->ai_minor = (u_int)sc->minorversion;
651 aip->ai_status = (u_int)sc->active;
652
653 sc->bios.r.eax = (APM_BIOS << 8) | APM_GETCAPABILITIES;
654 sc->bios.r.ebx = 0;
655 sc->bios.r.ecx = 0;
656 sc->bios.r.edx = 0;
657 if (apm_bioscall()) {
658 aip->ai_batteries = -1; /* Unknown */
659 aip->ai_capabilities = 0xff00; /* Unknown, with no bits set */
660 } else {
661 aip->ai_batteries = sc->bios.r.ebx & 0xff;
662 aip->ai_capabilities = sc->bios.r.ecx & 0xf;
663 }
664
665 bzero(aip->ai_spare, sizeof aip->ai_spare);
666
667 return 0;
668}
669
670
671/* inform APM BIOS that CPU is idle */
672void
673apm_cpu_idle(void)
674{
675 struct apm_softc *sc = &apm_softc;
676
677 if (sc->active) {
678
679 sc->bios.r.eax = (APM_BIOS <<8) | APM_CPUIDLE;
680 sc->bios.r.edx = sc->bios.r.ecx = sc->bios.r.ebx = 0;
09e6e929 681 apm_bioscall();
984263bc
MD
682 }
683 /*
684 * Some APM implementation halts CPU in BIOS, whenever
685 * "CPU-idle" function are invoked, but swtch() of
686 * FreeBSD halts CPU, therefore, CPU is halted twice
687 * in the sched loop. It makes the interrupt latency
688 * terribly long and be able to cause a serious problem
689 * in interrupt processing. We prevent it by removing
690 * "hlt" operation from swtch() and managed it under
691 * APM driver.
692 */
693 if (!sc->active || sc->always_halt_cpu)
694 __asm("hlt"); /* wait for interrupt */
695}
696
697/* inform APM BIOS that CPU is busy */
698void
699apm_cpu_busy(void)
700{
701 struct apm_softc *sc = &apm_softc;
702
703 /*
704 * The APM specification says this is only necessary if your BIOS
705 * slows down the processor in the idle task, otherwise it's not
706 * necessary.
707 */
708 if (sc->slow_idle_cpu && sc->active) {
709
710 sc->bios.r.eax = (APM_BIOS <<8) | APM_CPUBUSY;
711 sc->bios.r.edx = sc->bios.r.ecx = sc->bios.r.ebx = 0;
712 apm_bioscall();
713 }
714}
715
716
717/*
718 * APM timeout routine:
719 *
720 * This routine is automatically called by timer once per second.
721 */
722
723static void
724apm_timeout(void *dummy)
725{
726 struct apm_softc *sc = &apm_softc;
727
728 if (apm_op_inprog)
729 apm_lastreq_notify();
730
731 if (sc->standbys && sc->standby_countdown-- <= 0)
732 apm_do_standby();
733
734 if (sc->suspends && sc->suspend_countdown-- <= 0)
735 apm_do_suspend();
736
737 if (!sc->bios_busy)
738 apm_processevent();
739
b02bbab0 740 if (sc->active == 1) {
984263bc 741 /* Run slightly more oftan than 1 Hz */
b02bbab0
JS
742 callout_reset(&apm_timeout_ch, hz - 1, apm_timeout, NULL);
743 }
984263bc
MD
744}
745
746/* enable APM BIOS */
747static void
748apm_event_enable(void)
749{
750 struct apm_softc *sc = &apm_softc;
751
752 APM_DPRINT("called apm_event_enable()\n");
753 if (sc->initialized) {
754 sc->active = 1;
b02bbab0 755 callout_init(&apm_timeout_ch);
984263bc
MD
756 apm_timeout(sc);
757 }
758}
759
760/* disable APM BIOS */
761static void
762apm_event_disable(void)
763{
764 struct apm_softc *sc = &apm_softc;
765
766 APM_DPRINT("called apm_event_disable()\n");
767 if (sc->initialized) {
b02bbab0 768 callout_stop(&apm_timeout_ch);
984263bc
MD
769 sc->active = 0;
770 }
771}
772
773/* halt CPU in scheduling loop */
774static void
775apm_halt_cpu(void)
776{
777 struct apm_softc *sc = &apm_softc;
778
779 if (sc->initialized)
780 sc->always_halt_cpu = 1;
781}
782
783/* don't halt CPU in scheduling loop */
784static void
785apm_not_halt_cpu(void)
786{
787 struct apm_softc *sc = &apm_softc;
788
789 if (sc->initialized)
790 sc->always_halt_cpu = 0;
791}
792
793/* device driver definitions */
794
795/*
984263bc
MD
796 * probe for APM BIOS
797 */
798static int
799apm_probe(device_t dev)
800{
801#define APM_KERNBASE KERNBASE
802 struct vm86frame vmf;
803 struct apm_softc *sc = &apm_softc;
804 int disabled, flags;
805
806 if (resource_int_value("apm", 0, "disabled", &disabled) == 0
807 && disabled != 0)
808 return ENXIO;
809
810 device_set_desc(dev, "APM BIOS");
811
812 if ( device_get_unit(dev) > 0 ) {
26be20a0 813 kprintf("apm: Only one APM driver supported.\n");
984263bc
MD
814 return ENXIO;
815 }
816
817 if (resource_int_value("apm", 0, "flags", &flags) != 0)
818 flags = 0;
819
820 bzero(&vmf, sizeof(struct vm86frame)); /* safety */
821 bzero(&apm_softc, sizeof(apm_softc));
822 vmf.vmf_ah = APM_BIOS;
823 vmf.vmf_al = APM_INSTCHECK;
824 vmf.vmf_bx = 0;
825 if (vm86_intcall(APM_INT, &vmf))
826 return ENXIO; /* APM not found */
827 if (vmf.vmf_bx != 0x504d) {
26be20a0 828 kprintf("apm: incorrect signature (0x%x)\n", vmf.vmf_bx);
984263bc
MD
829 return ENXIO;
830 }
831 if ((vmf.vmf_cx & (APM_32BIT_SUPPORT | APM_16BIT_SUPPORT)) == 0) {
26be20a0 832 kprintf("apm: protected mode connections are not supported\n");
984263bc
MD
833 return ENXIO;
834 }
835
836 apm_version = vmf.vmf_ax;
837 sc->slow_idle_cpu = ((vmf.vmf_cx & APM_CPUIDLE_SLOW) != 0);
838 sc->disabled = ((vmf.vmf_cx & APM_DISABLED) != 0);
839 sc->disengaged = ((vmf.vmf_cx & APM_DISENGAGED) != 0);
840
841 vmf.vmf_ah = APM_BIOS;
842 vmf.vmf_al = APM_DISCONNECT;
843 vmf.vmf_bx = 0;
844 vm86_intcall(APM_INT, &vmf); /* disconnect, just in case */
845
846 if ((vmf.vmf_cx & APM_32BIT_SUPPORT) != 0) {
847 vmf.vmf_ah = APM_BIOS;
848 vmf.vmf_al = APM_PROT32CONNECT;
849 vmf.vmf_bx = 0;
850 if (vm86_intcall(APM_INT, &vmf)) {
26be20a0 851 kprintf("apm: 32-bit connection error.\n");
984263bc
MD
852 return (ENXIO);
853 }
854 sc->bios.seg.code32.base = (vmf.vmf_ax << 4) + APM_KERNBASE;
855 sc->bios.seg.code32.limit = 0xffff;
856 sc->bios.seg.code16.base = (vmf.vmf_cx << 4) + APM_KERNBASE;
857 sc->bios.seg.code16.limit = 0xffff;
858 sc->bios.seg.data.base = (vmf.vmf_dx << 4) + APM_KERNBASE;
859 sc->bios.seg.data.limit = 0xffff;
860 sc->bios.entry = vmf.vmf_ebx;
861 sc->connectmode = APM_PROT32CONNECT;
862 } else {
863 /* use 16-bit connection */
864 vmf.vmf_ah = APM_BIOS;
865 vmf.vmf_al = APM_PROT16CONNECT;
866 vmf.vmf_bx = 0;
867 if (vm86_intcall(APM_INT, &vmf)) {
26be20a0 868 kprintf("apm: 16-bit connection error.\n");
984263bc
MD
869 return (ENXIO);
870 }
871 sc->bios.seg.code16.base = (vmf.vmf_ax << 4) + APM_KERNBASE;
872 sc->bios.seg.code16.limit = 0xffff;
873 sc->bios.seg.data.base = (vmf.vmf_cx << 4) + APM_KERNBASE;
874 sc->bios.seg.data.limit = 0xffff;
875 sc->bios.entry = vmf.vmf_bx;
876 sc->connectmode = APM_PROT16CONNECT;
877 }
878 return(0);
879}
880
881
882/*
883 * return 0 if the user will notice and handle the event,
884 * return 1 if the kernel driver should do so.
885 */
886static int
887apm_record_event(struct apm_softc *sc, u_int event_type)
888{
889 struct apm_event_info *evp;
890
891 if ((sc->sc_flags & SCFLAG_OPEN) == 0)
892 return 1; /* no user waiting */
893 if (sc->event_count == APM_NEVENTS)
894 return 1; /* overflow */
895 if (sc->event_filter[event_type] == 0)
896 return 1; /* not registered */
897 evp = &sc->event_list[sc->event_ptr];
898 sc->event_count++;
899 sc->event_ptr++;
900 sc->event_ptr %= APM_NEVENTS;
901 evp->type = event_type;
902 evp->index = ++apm_evindex;
903 selwakeup(&sc->sc_rsel);
904 return (sc->sc_flags & SCFLAG_OCTL) ? 0 : 1; /* user may handle */
905}
906
907/* Process APM event */
908static void
909apm_processevent(void)
910{
911 int apm_event;
912 struct apm_softc *sc = &apm_softc;
913
914#define OPMEV_DEBUGMESSAGE(symbol) case symbol: \
915 APM_DPRINT("Received APM Event: " #symbol "\n");
916
917 do {
918 apm_event = apm_getevent();
919 switch (apm_event) {
920 OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
921 if (apm_op_inprog == 0) {
922 apm_op_inprog++;
923 if (apm_record_event(sc, apm_event)) {
924 apm_suspend(PMST_STANDBY);
925 }
926 }
927 break;
928 OPMEV_DEBUGMESSAGE(PMEV_USERSTANDBYREQ);
929 if (apm_op_inprog == 0) {
930 apm_op_inprog++;
931 if (apm_record_event(sc, apm_event)) {
932 apm_suspend(PMST_STANDBY);
933 }
934 }
935 break;
936 OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
937 apm_lastreq_notify();
938 if (apm_op_inprog == 0) {
939 apm_op_inprog++;
940 if (apm_record_event(sc, apm_event)) {
941 apm_do_suspend();
942 }
943 }
944 return; /* XXX skip the rest */
945 OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
946 apm_lastreq_notify();
947 if (apm_op_inprog == 0) {
948 apm_op_inprog++;
949 if (apm_record_event(sc, apm_event)) {
950 apm_do_suspend();
951 }
952 }
953 return; /* XXX skip the rest */
954 OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
955 apm_do_suspend();
956 break;
957 OPMEV_DEBUGMESSAGE(PMEV_NORMRESUME);
958 apm_record_event(sc, apm_event);
959 apm_resume();
960 break;
961 OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME);
962 apm_record_event(sc, apm_event);
963 apm_resume();
964 break;
965 OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME);
966 apm_record_event(sc, apm_event);
967 apm_resume();
968 break;
969 OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW);
970 if (apm_record_event(sc, apm_event)) {
971 apm_battery_low();
972 apm_suspend(PMST_SUSPEND);
973 }
974 break;
975 OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE);
976 apm_record_event(sc, apm_event);
977 break;
978 OPMEV_DEBUGMESSAGE(PMEV_UPDATETIME);
979 apm_record_event(sc, apm_event);
980 inittodr(0); /* adjust time to RTC */
981 break;
982 OPMEV_DEBUGMESSAGE(PMEV_CAPABILITIESCHANGE);
983 apm_record_event(sc, apm_event);
984 break;
985 case PMEV_NOEVENT:
986 break;
987 default:
26be20a0 988 kprintf("Unknown Original APM Event 0x%x\n", apm_event);
984263bc
MD
989 break;
990 }
991 } while (apm_event != PMEV_NOEVENT);
992}
993
994/*
995 * Attach APM:
996 *
997 * Initialize APM driver
998 */
999
1000static int
1001apm_attach(device_t dev)
1002{
1003 struct apm_softc *sc = &apm_softc;
1004 int flags;
1005 int drv_version;
1006
1007 if (resource_int_value("apm", 0, "flags", &flags) != 0)
1008 flags = 0;
1009
984263bc
MD
1010 sc->initialized = 0;
1011
1012 /* Must be externally enabled */
1013 sc->active = 0;
1014
1015 /* Always call HLT in idle loop */
1016 sc->always_halt_cpu = 1;
1017
bc01a404 1018 kgetenv_int("debug.apm_debug", &apm_debug);
984263bc
MD
1019
1020 /* print bootstrap messages */
1021 APM_DPRINT("apm: APM BIOS version %04lx\n", apm_version);
1022 APM_DPRINT("apm: Code16 0x%08x, Data 0x%08x\n",
1023 sc->bios.seg.code16.base, sc->bios.seg.data.base);
1024 APM_DPRINT("apm: Code entry 0x%08x, Idling CPU %s, Management %s\n",
1025 sc->bios.entry, is_enabled(sc->slow_idle_cpu),
1026 is_enabled(!sc->disabled));
1027 APM_DPRINT("apm: CS_limit=0x%x, DS_limit=0x%x\n",
1028 sc->bios.seg.code16.limit, sc->bios.seg.data.limit);
1029
1030 /*
1031 * In one test, apm bios version was 1.02; an attempt to register
1032 * a 1.04 driver resulted in a 1.00 connection! Registering a
1033 * 1.02 driver resulted in a 1.02 connection.
1034 */
1035 drv_version = apm_version > 0x102 ? 0x102 : apm_version;
1036 for (; drv_version > 0x100; drv_version--)
1037 if (apm_driver_version(drv_version) == 0)
1038 break;
1039 sc->minorversion = ((drv_version & 0x00f0) >> 4) * 10 +
1040 ((drv_version & 0x000f) >> 0);
1041 sc->majorversion = ((drv_version & 0xf000) >> 12) * 10 +
1042 ((apm_version & 0x0f00) >> 8);
1043
1044 sc->intversion = INTVERSION(sc->majorversion, sc->minorversion);
1045
1046 if (sc->intversion >= INTVERSION(1, 1))
1047 APM_DPRINT("apm: Engaged control %s\n", is_enabled(!sc->disengaged));
1048 device_printf(dev, "found APM BIOS v%ld.%ld, connected at v%d.%d\n",
1049 ((apm_version & 0xf000) >> 12) * 10 + ((apm_version & 0x0f00) >> 8),
1050 ((apm_version & 0x00f0) >> 4) * 10 + ((apm_version & 0x000f) >> 0),
1051 sc->majorversion, sc->minorversion);
1052
1053
1054 APM_DPRINT("apm: Slow Idling CPU %s\n", is_enabled(sc->slow_idle_cpu));
1055 /* enable power management */
1056 if (sc->disabled) {
1057 if (apm_enable_disable_pm(1)) {
1058 APM_DPRINT("apm: *Warning* enable function failed! [%x]\n",
1059 (sc->bios.r.eax >> 8) & 0xff);
1060 }
1061 }
1062
1063 /* engage power managment (APM 1.1 or later) */
1064 if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) {
1065 if (apm_engage_disengage_pm(1)) {
1066 APM_DPRINT("apm: *Warning* engage function failed err=[%x]",
1067 (sc->bios.r.eax >> 8) & 0xff);
1068 APM_DPRINT(" (Docked or using external power?).\n");
1069 }
1070 }
1071
1072 /* default suspend hook */
1073 sc->sc_suspend.ah_fun = apm_default_suspend;
1074 sc->sc_suspend.ah_arg = sc;
1075 sc->sc_suspend.ah_name = "default suspend";
1076 sc->sc_suspend.ah_order = APM_MAX_ORDER;
1077
1078 /* default resume hook */
1079 sc->sc_resume.ah_fun = apm_default_resume;
1080 sc->sc_resume.ah_arg = sc;
1081 sc->sc_resume.ah_name = "default resume";
1082 sc->sc_resume.ah_order = APM_MIN_ORDER;
1083
1084 apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend);
1085 apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume);
1086
1087 /* Power the system off using APM */
1088 EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL,
1089 SHUTDOWN_PRI_LAST);
1090
1091 sc->initialized = 1;
1092
fef8985e
MD
1093 make_dev(&apm_ops, 0, UID_ROOT, GID_OPERATOR, 0660, "apm");
1094 make_dev(&apm_ops, 8, UID_ROOT, GID_OPERATOR, 0660, "apmctl");
984263bc
MD
1095 return 0;
1096}
1097
1098static int
fef8985e 1099apmopen(struct dev_open_args *ap)
984263bc 1100{
b13267a5 1101 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
1102 struct apm_softc *sc = &apm_softc;
1103 int ctl = APMDEV(dev);
1104
1105 if (!sc->initialized)
1106 return (ENXIO);
1107
1108 switch (ctl) {
1109 case APMDEV_CTL:
fef8985e 1110 if (!(ap->a_oflags & FWRITE))
984263bc
MD
1111 return EINVAL;
1112 if (sc->sc_flags & SCFLAG_OCTL)
1113 return EBUSY;
1114 sc->sc_flags |= SCFLAG_OCTL;
1115 bzero(sc->event_filter, sizeof sc->event_filter);
1116 break;
1117 case APMDEV_NORMAL:
1118 sc->sc_flags |= SCFLAG_ONORMAL;
1119 break;
1120 default:
1121 return ENXIO;
1122 break;
1123 }
1124 return 0;
1125}
1126
1127static int
fef8985e 1128apmclose(struct dev_close_args *ap)
984263bc 1129{
b13267a5 1130 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
1131 struct apm_softc *sc = &apm_softc;
1132 int ctl = APMDEV(dev);
1133
1134 switch (ctl) {
1135 case APMDEV_CTL:
1136 apm_lastreq_rejected();
1137 sc->sc_flags &= ~SCFLAG_OCTL;
1138 bzero(sc->event_filter, sizeof sc->event_filter);
1139 break;
1140 case APMDEV_NORMAL:
1141 sc->sc_flags &= ~SCFLAG_ONORMAL;
1142 break;
1143 }
1144 if ((sc->sc_flags & SCFLAG_OPEN) == 0) {
1145 sc->event_count = 0;
1146 sc->event_ptr = 0;
1147 }
1148 return 0;
1149}
1150
1151static int
fef8985e 1152apmioctl(struct dev_ioctl_args *ap)
984263bc 1153{
b13267a5 1154 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
1155 struct apm_softc *sc = &apm_softc;
1156 struct apm_bios_arg *args;
1157 int error = 0;
1158 int ret;
1159 int newstate;
1160
1161 if (!sc->initialized)
1162 return (ENXIO);
fef8985e
MD
1163 APM_DPRINT("APM ioctl: cmd = 0x%lx\n", ap->a_cmd);
1164
1165 switch (ap->a_cmd) {
984263bc 1166 case APMIO_SUSPEND:
fef8985e 1167 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1168 return (EPERM);
1169 if (sc->active)
1170 apm_suspend(PMST_SUSPEND);
1171 else
1172 error = EINVAL;
1173 break;
1174
1175 case APMIO_STANDBY:
fef8985e 1176 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1177 return (EPERM);
1178 if (sc->active)
1179 apm_suspend(PMST_STANDBY);
1180 else
1181 error = EINVAL;
1182 break;
1183
1184 case APMIO_GETINFO_OLD:
1185 {
1186 struct apm_info info;
1187 apm_info_old_t aiop;
1188
1189 if (apm_get_info(&info))
1190 error = ENXIO;
fef8985e 1191 aiop = (apm_info_old_t)ap->a_data;
984263bc
MD
1192 aiop->ai_major = info.ai_major;
1193 aiop->ai_minor = info.ai_minor;
1194 aiop->ai_acline = info.ai_acline;
1195 aiop->ai_batt_stat = info.ai_batt_stat;
1196 aiop->ai_batt_life = info.ai_batt_life;
1197 aiop->ai_status = info.ai_status;
1198 }
1199 break;
1200 case APMIO_GETINFO:
fef8985e 1201 if (apm_get_info((apm_info_t)ap->a_data))
984263bc
MD
1202 error = ENXIO;
1203 break;
1204 case APMIO_GETPWSTATUS:
fef8985e 1205 if (apm_get_pwstatus((apm_pwstatus_t)ap->a_data))
984263bc
MD
1206 error = ENXIO;
1207 break;
1208 case APMIO_ENABLE:
fef8985e 1209 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1210 return (EPERM);
1211 apm_event_enable();
1212 break;
1213 case APMIO_DISABLE:
fef8985e 1214 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1215 return (EPERM);
1216 apm_event_disable();
1217 break;
1218 case APMIO_HALTCPU:
fef8985e 1219 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1220 return (EPERM);
1221 apm_halt_cpu();
1222 break;
1223 case APMIO_NOTHALTCPU:
fef8985e 1224 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1225 return (EPERM);
1226 apm_not_halt_cpu();
1227 break;
1228 case APMIO_DISPLAY:
fef8985e 1229 if (!(ap->a_fflag & FWRITE))
984263bc 1230 return (EPERM);
fef8985e 1231 newstate = *(int *)ap->a_data;
984263bc
MD
1232 if (apm_display(newstate))
1233 error = ENXIO;
1234 break;
1235 case APMIO_BIOS:
fef8985e 1236 if (!(ap->a_fflag & FWRITE))
984263bc
MD
1237 return (EPERM);
1238 /* XXX compatibility with the old interface */
fef8985e 1239 args = (struct apm_bios_arg *)ap->a_data;
984263bc
MD
1240 sc->bios.r.eax = args->eax;
1241 sc->bios.r.ebx = args->ebx;
1242 sc->bios.r.ecx = args->ecx;
1243 sc->bios.r.edx = args->edx;
1244 sc->bios.r.esi = args->esi;
1245 sc->bios.r.edi = args->edi;
1246 if ((ret = apm_bioscall())) {
1247 /*
1248 * Return code 1 means bios call was unsuccessful.
1249 * Error code is stored in %ah.
1250 * Return code -1 means bios call was unsupported
1251 * in the APM BIOS version.
1252 */
1253 if (ret == -1) {
1254 error = EINVAL;
1255 }
1256 } else {
1257 /*
1258 * Return code 0 means bios call was successful.
1259 * We need only %al and can discard %ah.
1260 */
1261 sc->bios.r.eax &= 0xff;
1262 }
1263 args->eax = sc->bios.r.eax;
1264 args->ebx = sc->bios.r.ebx;
1265 args->ecx = sc->bios.r.ecx;
1266 args->edx = sc->bios.r.edx;
1267 args->esi = sc->bios.r.esi;
1268 args->edi = sc->bios.r.edi;
1269 break;
1270 default:
1271 error = EINVAL;
1272 break;
1273 }
1274
1275 /* for /dev/apmctl */
1276 if (APMDEV(dev) == APMDEV_CTL) {
1277 struct apm_event_info *evp;
1278 int i;
1279
1280 error = 0;
fef8985e 1281 switch (ap->a_cmd) {
984263bc
MD
1282 case APMIO_NEXTEVENT:
1283 if (!sc->event_count) {
1284 error = EAGAIN;
1285 } else {
fef8985e 1286 evp = (struct apm_event_info *)ap->a_data;
984263bc
MD
1287 i = sc->event_ptr + APM_NEVENTS - sc->event_count;
1288 i %= APM_NEVENTS;
1289 *evp = sc->event_list[i];
1290 sc->event_count--;
1291 }
1292 break;
1293 case APMIO_REJECTLASTREQ:
1294 if (apm_lastreq_rejected()) {
1295 error = EINVAL;
1296 }
1297 break;
1298 default:
1299 error = EINVAL;
1300 break;
1301 }
1302 }
1303
1304 return error;
1305}
1306
1307static int
fef8985e 1308apmwrite(struct dev_write_args *ap)
984263bc 1309{
b13267a5 1310 cdev_t dev = ap->a_head.a_dev;
fef8985e 1311 struct uio *uio = ap->a_uio;
984263bc
MD
1312 struct apm_softc *sc = &apm_softc;
1313 u_int event_type;
1314 int error;
1315 u_char enabled;
1316
1317 if (APMDEV(dev) != APMDEV_CTL)
1318 return(ENODEV);
1319 if (uio->uio_resid != sizeof(u_int))
1320 return(E2BIG);
1321
1322 if ((error = uiomove((caddr_t)&event_type, sizeof(u_int), uio)))
1323 return(error);
1324
1325 if (event_type < 0 || event_type >= APM_NPMEV)
1326 return(EINVAL);
1327
1328 if (sc->event_filter[event_type] == 0) {
1329 enabled = 1;
1330 } else {
1331 enabled = 0;
1332 }
1333 sc->event_filter[event_type] = enabled;
1334 APM_DPRINT("apmwrite: event 0x%x %s\n", event_type, is_enabled(enabled));
1335
1336 return uio->uio_resid;
1337}
1338
1339static int
fef8985e 1340apmpoll(struct dev_poll_args *ap)
984263bc
MD
1341{
1342 struct apm_softc *sc = &apm_softc;
1343 int revents = 0;
1344
fef8985e 1345 if (ap->a_events & (POLLIN | POLLRDNORM)) {
984263bc 1346 if (sc->event_count) {
fef8985e 1347 revents |= ap->a_events & (POLLIN | POLLRDNORM);
984263bc 1348 } else {
fef8985e 1349 selrecord(curthread, &sc->sc_rsel);
984263bc
MD
1350 }
1351 }
fef8985e
MD
1352 ap->a_events = revents;
1353 return (0);
984263bc
MD
1354}
1355
39b5d600
MD
1356/*
1357 * Because apm is a static device that always exists under any attached
1358 * isa device, and not scanned by the isa device, we need an identify
1359 * function to install the device so we can probe for it.
1360 */
984263bc
MD
1361static device_method_t apm_methods[] = {
1362 /* Device interface */
39b5d600 1363 DEVMETHOD(device_identify, bus_generic_identify),
984263bc
MD
1364 DEVMETHOD(device_probe, apm_probe),
1365 DEVMETHOD(device_attach, apm_attach),
1366
1367 { 0, 0 }
1368};
1369
1370static driver_t apm_driver = {
1371 "apm",
1372 apm_methods,
1373 1, /* no softc (XXX) */
1374};
1375
1376static devclass_t apm_devclass;
1377
1378DRIVER_MODULE(apm, nexus, apm_driver, apm_devclass, 0, 0);
39b5d600 1379