2 * APM BIOS driver for Linux
3 * Copyright 1994-2000 Stephen Rothwell (sfr@linuxcare.com)
5 * Initial development of this driver was funded by NEC Australia P/L
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * October 1995, Rik Faith (faith@cs.unc.edu):
19 * Minor enhancements and updates (to the patch set) for 1.3.x
21 * January 1996, Rik Faith (faith@cs.unc.edu):
22 * Make /proc/apm easy to format (bump driver version)
23 * March 1996, Rik Faith (faith@cs.unc.edu):
24 * Prohibit APM BIOS calls unless apm_enabled.
25 * (Thanks to Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>)
26 * April 1996, Stephen Rothwell (Stephen.Rothwell@canb.auug.org.au)
28 * May 1996, Version 1.2
29 * Feb 1998, Version 1.3
30 * Feb 1998, Version 1.4
31 * Aug 1998, Version 1.5
32 * Sep 1998, Version 1.6
33 * Nov 1998, Version 1.7
34 * Jan 1999, Version 1.8
35 * Jan 1999, Version 1.9
36 * Oct 1999, Version 1.10
37 * Nov 1999, Version 1.11
38 * Jan 2000, Version 1.12
39 * Feb 2000, Version 1.13
42 * 0.6b: first version in official kernel, Linux 1.3.46
43 * 0.7: changed /proc/apm format, Linux 1.3.58
44 * 0.8: fixed gcc 2.7.[12] compilation problems, Linux 1.3.59
45 * 0.9: only call bios if bios is present, Linux 1.3.72
46 * 1.0: use fixed device number, consolidate /proc/apm into this file,
48 * 1.1: support user-space standby and suspend, power off after system
49 * halted, Linux 1.3.98
50 * 1.2: When resetting RTC after resume, take care so that the time
51 * is only incorrect by 30-60mS (vs. 1S previously) (Gabor J. Toth
52 * <jtoth@princeton.edu>); improve interaction between
53 * screen-blanking and gpm (Stephen Rothwell); Linux 1.99.4
54 * 1.2a:Simple change to stop mysterious bug reports with SMP also added
55 * levels to the printk calls. APM is not defined for SMP machines.
56 * The new replacment for it is, but Linux doesn't yet support this.
57 * Alan Cox Linux 2.1.55
58 * 1.3: Set up a valid data descriptor 0x40 for buggy BIOS's
59 * 1.4: Upgraded to support APM 1.2. Integrated ThinkPad suspend patch by
60 * Dean Gaudet <dgaudet@arctic.org>.
61 * C. Scott Ananian <cananian@alumni.princeton.edu> Linux 2.1.87
62 * 1.5: Fix segment register reloading (in case of bad segments saved
65 * 1.6: Cope with complier/assembler differences.
66 * Only try to turn off the first display device.
67 * Fix OOPS at power off with no APM BIOS by Jan Echternach
68 * <echter@informatik.uni-rostock.de>
70 * 1.7: Modify driver's cached copy of the disabled/disengaged flags
71 * to reflect current state of APM BIOS.
72 * Chris Rankin <rankinc@bellsouth.net>
73 * Reset interrupt 0 timer to 100Hz after suspend
74 * Chad Miller <cmiller@surfsouth.com>
75 * Add CONFIG_APM_IGNORE_SUSPEND_BOUNCE
76 * Richard Gooch <rgooch@atnf.csiro.au>
77 * Allow boot time disabling of APM
78 * Make boot messages far less verbose by default
81 * 1.8: Add CONFIG_APM_RTC_IS_GMT
82 * Richard Gooch <rgooch@atnf.csiro.au>
83 * change APM_NOINTS to CONFIG_APM_ALLOW_INTS
84 * remove dependency on CONFIG_PROC_FS
86 * 1.9: Fix small typo. <laslo@ilo.opole.pl>
87 * Try to cope with BIOS's that need to have all display
88 * devices blanked and not just the first one.
89 * Ross Paterson <ross@soi.city.ac.uk>
90 * Fix segment limit setting it has always been wrong as
91 * the segments needed to have byte granularity.
92 * Mark a few things __init.
93 * Add hack to allow power off of SMP systems by popular request.
94 * Use CONFIG_SMP instead of __SMP__
95 * Ignore BOUNCES for three seconds.
97 * 1.10: Fix for Thinkpad return code.
98 * Merge 2.2 and 2.3 drivers.
99 * Remove APM dependencies in arch/i386/kernel/process.c
100 * Remove APM dependencies in drivers/char/sysrq.c
101 * Reset time across standby.
102 * Allow more inititialisation on SMP.
103 * Remove CONFIG_APM_POWER_OFF and make it boot time
104 * configurable (default on).
105 * Make debug only a boot time parameter (remove APM_DEBUG).
106 * Try to blank all devices on any error.
107 * 1.11: Remove APM dependencies in drivers/char/console.c
108 * Check nr_running to detect if we are idle (from
109 * Borislav Deianov <borislav@lix.polytechnique.fr>)
110 * Fix for bioses that don't zero the top part of the
111 * entrypoint offset (Mario Sitta <sitta@al.unipmn.it>)
112 * (reported by Panos Katsaloulis <teras@writeme.com>).
113 * Real mode power off patch (Walter Hofmann
114 * <Walter.Hofmann@physik.stud.uni-erlangen.de>).
115 * 1.12: Remove CONFIG_SMP as the compiler will optimize
116 * the code away anyway (smp_num_cpus == 1 in UP)
117 * noted by Artur Skawina <skawina@geocities.com>.
118 * Make power off under SMP work again.
119 * Fix thinko with initial engaging of BIOS.
120 * Make sure power off only happens on CPU 0
121 * (Paul "Rusty" Russell <rusty@linuxcare.com>).
122 * Do error notification to user mode if BIOS calls fail.
123 * Move entrypoint offset fix to ...boot/setup.S
124 * where it belongs (Cosmos <gis88564@cis.nctu.edu.tw>).
125 * Remove smp-power-off. SMP users must now specify
126 * "apm=power-off" on the kernel command line. Suggested
127 * by Jim Avera <jima@hal.com>, modified by Alan Cox
128 * <alan@lxorguk.ukuu.org.uk>.
129 * Register the /proc/apm entry even on SMP so that
130 * scripts that check for it before doing power off
131 * work (Jim Avera <jima@hal.com>).
132 * 1.13: Changes for new pm_ interfaces (Andy Henroid
133 * <andy_henroid@yahoo.com>).
134 * Modularize the code.
135 * Fix the Thinkpad (again) :-( (CONFIG_APM_IGNORE_MULTIPLE_SUSPENDS
136 * is now the way life works).
137 * Fix thinko in suspend() (wrong return).
138 * Notify drivers on critical suspend.
139 * Make kapmd absorb more idle time (Pavel Machek <pavel@suse.cz>
141 * Disable interrupts while we are suspended (Andy Henroid
142 * <andy_henroid@yahoo.com> fixed by sfr).
143 * Make power off work on SMP again (Tony Hoyle
144 * <tmh@magenta-logic.com> and <zlatko@iskon.hr>) modified by sfr.
145 * Remove CONFIG_APM_SUSPEND_BOUNCE. The bounce ignore
146 * interval is now configurable.
150 * Intel Corporation, Microsoft Corporation. Advanced Power Management
151 * (APM) BIOS Interface Specification, Revision 1.1, September 1993.
152 * Intel Order Number 241704-001. Microsoft Part Number 781-110-X01.
154 * [This document is available free from Intel by calling 800.628.8686 (fax
155 * 916.356.6100) or 800.548.4725; or via anonymous ftp from
156 * ftp://ftp.intel.com/pub/IAL/software_specs/apmv11.doc. It is also
157 * available from Microsoft by calling 206.882.8080.]
160 * Intel Corporation, Microsoft Corporation. Advanced Power Management
161 * (APM) BIOS Interface Specification, Revision 1.2, February 1996.
163 * [This document is available from Microsoft at:
164 * http://www.microsoft.com/hwdev/busbios/amp_12.htm]
167 #include <linux/config.h>
168 #include <linux/module.h>
170 #include <linux/poll.h>
171 #include <linux/types.h>
172 #include <linux/stddef.h>
173 #include <linux/timer.h>
174 #include <linux/fcntl.h>
175 #include <linux/malloc.h>
176 #include <linux/stat.h>
177 #include <linux/proc_fs.h>
178 #include <linux/miscdevice.h>
179 #include <linux/apm_bios.h>
180 #include <linux/init.h>
181 #include <linux/sched.h>
182 #include <linux/pm.h>
183 #include <linux/kernel.h>
184 #include <linux/smp_lock.h>
186 #include <asm/system.h>
187 #include <asm/uaccess.h>
188 #include <asm/desc.h>
190 extern unsigned long get_cmos_time(void);
191 extern void machine_real_restart(unsigned char *, int);
193 #ifdef CONFIG_MAGIC_SYSRQ
194 extern void (*sysrq_power_off
)(void);
196 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
197 extern int (*console_blank_hook
)(int);
201 * The apm_bios device is one of the misc char devices.
202 * This is its minor number.
204 #define APM_MINOR_DEV 134
207 * See Documentation/Config.help for the configuration options.
209 * Various options can be changed at boot time as follows:
210 * (We allow underscores for compatibility with the modules code)
211 * apm=on/off enable/disable APM
212 * [no-]debug log some debugging messages
213 * [no-]power[-_]off power off on shutdown
216 /* KNOWN PROBLEM MACHINES:
218 * U: TI 4000M TravelMate: BIOS is *NOT* APM compliant
219 * [Confirmed by TI representative]
220 * ?: ACER 486DX4/75: uses dseg 0040, in violation of APM specification
221 * [Confirmed by BIOS disassembly]
222 * [This may work now ...]
223 * P: Toshiba 1950S: battery life information only gets updated after resume
224 * P: Midwest Micro Soundbook Elite DX2/66 monochrome: screen blanking
225 * broken in BIOS [Reported by Garst R. Reese <reese@isn.net>]
227 * Legend: U = unusable with APM patches
228 * P = partially usable with APM patches
232 * Define to always call the APM BIOS busy routine even if the clock was
233 * not slowed by the idle routine.
235 #define ALWAYS_CALL_BUSY
238 * Define to make the APM BIOS calls zero all data segment registers (so
239 * that an incorrect BIOS implementation will cause a kernel panic if it
240 * tries to write to arbitrary memory).
242 #define APM_ZERO_SEGS
245 * Define to make all _set_limit calls use 64k limits. The APM 1.1 BIOS is
246 * supposed to provide limit information that it recognizes. Many machines
247 * do this correctly, but many others do not restrict themselves to their
248 * claimed limit. When this happens, they will cause a segmentation
249 * violation in the kernel at boot time. Most BIOS's, however, will
250 * respect a 64k limit, so we use that. If you want to be pedantic and
251 * hold your BIOS to its claims, then undefine this.
253 #define APM_RELAX_SEGMENTS
256 * Define to re-initialize the interrupt 0 timer to 100 Hz after a suspend.
257 * This patched by Chad Miller <cmiller@surfsouth.com>, original code by
258 * David Chen <chen@ctpa04.mit.edu>
260 #undef INIT_TIMER_AFTER_SUSPEND
262 #ifdef INIT_TIMER_AFTER_SUSPEND
263 #include <linux/timex.h>
265 #include <linux/delay.h>
269 * Need to poll the APM BIOS every second
271 #define APM_CHECK_TIMEOUT (HZ)
274 * Ignore suspend events for this amount of time after a resume
276 #define DEFAULT_BOUNCE_INTERVAL (3 * HZ)
279 * Save a segment register away
281 #define savesegment(seg, where) \
282 __asm__ __volatile__("movl %%" #seg ",%0" : "=m" (where))
285 * Maximum number of events stored
287 #define APM_MAX_EVENTS 20
290 * The per-file APM data
294 struct apm_user
* next
;
298 int suspends_pending
;
299 int standbys_pending
;
304 apm_event_t events
[APM_MAX_EVENTS
];
308 * The magic number in apm_user
310 #define APM_BIOS_MAGIC 0x4101
316 unsigned long offset
;
317 unsigned short segment
;
319 #ifdef CONFIG_APM_CPU_IDLE
320 static int clock_slowed
;
322 static int suspends_pending
;
323 static int standbys_pending
;
324 static int waiting_for_resume
;
325 static int ignore_normal_resume
;
326 static int bounce_interval
= DEFAULT_BOUNCE_INTERVAL
;
328 #ifdef CONFIG_APM_RTC_IS_GMT
329 # define clock_cmos_diff 0
330 # define got_clock_diff 1
332 static long clock_cmos_diff
;
333 static int got_clock_diff
;
336 static int apm_disabled
;
338 static int power_off
;
340 static int power_off
= 1;
342 static int exit_kapmd
;
343 static int kapmd_running
;
345 static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue
);
346 static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue
);
347 static struct apm_user
* user_list
= NULL
;
349 static char driver_version
[] = "1.13"; /* no spaces */
351 static char * apm_event_name
[] = {
357 "power status change",
362 "system standby resume",
363 "capabilities change"
365 #define NR_APM_EVENT_NAME \
366 (sizeof(apm_event_name) / sizeof(apm_event_name[0]))
368 typedef struct lookup_t
{
373 static const lookup_t error_table
[] = {
374 /* N/A { APM_SUCCESS, "Operation succeeded" }, */
375 { APM_DISABLED
, "Power management disabled" },
376 { APM_CONNECTED
, "Real mode interface already connected" },
377 { APM_NOT_CONNECTED
, "Interface not connected" },
378 { APM_16_CONNECTED
, "16 bit interface already connected" },
379 /* N/A { APM_16_UNSUPPORTED, "16 bit interface not supported" }, */
380 { APM_32_CONNECTED
, "32 bit interface already connected" },
381 { APM_32_UNSUPPORTED
, "32 bit interface not supported" },
382 { APM_BAD_DEVICE
, "Unrecognized device ID" },
383 { APM_BAD_PARAM
, "Parameter out of range" },
384 { APM_NOT_ENGAGED
, "Interface not engaged" },
385 { APM_BAD_FUNCTION
, "Function not supported" },
386 { APM_RESUME_DISABLED
, "Resume timer disabled" },
387 { APM_BAD_STATE
, "Unable to enter requested state" },
388 /* N/A { APM_NO_EVENTS, "No events pending" }, */
389 { APM_NO_ERROR
, "BIOS did not set a return code" },
390 { APM_NOT_PRESENT
, "No APM present" }
392 #define ERROR_COUNT (sizeof(error_table)/sizeof(lookup_t))
395 * These are the actual BIOS calls. Depending on APM_ZERO_SEGS and
396 * CONFIG_APM_ALLOW_INTS, we are being really paranoid here! Not only
397 * are interrupts disabled, but all the segment registers (except SS)
398 * are saved and zeroed this means that if the BIOS tries to reference
399 * any data without explicitly loading the segment registers, the kernel
400 * will fault immediately rather than have some unforeseen circumstances
401 * for the rest of the kernel. And it will be very obvious! :-) Doing
402 * this depends on CS referring to the same physical memory as DS so that
403 * DS can be zeroed before the call. Unfortunately, we can't do anything
404 * about the stack segment/pointer. Also, we tell the compiler that
405 * everything could change.
407 * Also, we KNOW that for the non error case of apm_bios_call, there
408 * is no useful data returned in the low order 8 bits of eax.
410 #ifndef CONFIG_APM_ALLOW_INTS
411 # define APM_DO_CLI __cli()
416 # define APM_DECL_SEGS \
417 unsigned int saved_fs; unsigned int saved_gs;
418 # define APM_DO_SAVE_SEGS \
419 savesegment(fs, saved_fs); savesegment(gs, saved_gs)
420 # define APM_DO_ZERO_SEGS \
423 "xorl %%edx, %%edx\n\t" \
424 "mov %%dx, %%ds\n\t" \
425 "mov %%dx, %%es\n\t" \
426 "mov %%dx, %%fs\n\t" \
428 # define APM_DO_POP_SEGS \
431 # define APM_DO_RESTORE_SEGS \
432 loadsegment(fs, saved_fs); loadsegment(gs, saved_gs)
434 # define APM_DECL_SEGS
435 # define APM_DO_SAVE_SEGS
436 # define APM_DO_ZERO_SEGS
437 # define APM_DO_POP_SEGS
438 # define APM_DO_RESTORE_SEGS
441 static u8
apm_bios_call(u32 func
, u32 ebx_in
, u32 ecx_in
,
442 u32
*eax
, u32
*ebx
, u32
*ecx
, u32
*edx
, u32
*esi
)
451 * N.B. We do NOT need a cld after the BIOS call
452 * because we always save and restore the flags.
454 __asm__
__volatile__(APM_DO_ZERO_SEGS
457 "lcall %%cs:" SYMBOL_NAME_STR(apm_bios_entry
) "\n\t"
462 : "=a" (*eax
), "=b" (*ebx
), "=c" (*ecx
), "=d" (*edx
),
464 : "a" (func
), "b" (ebx_in
), "c" (ecx_in
)
467 __restore_flags(flags
);
472 * This version only returns one value (usually an error code)
475 static u8
apm_bios_call_simple(u32 func
, u32 ebx_in
, u32 ecx_in
, u32
*eax
)
488 * N.B. We do NOT need a cld after the BIOS call
489 * because we always save and restore the flags.
491 __asm__
__volatile__(APM_DO_ZERO_SEGS
494 "lcall %%cs:" SYMBOL_NAME_STR(apm_bios_entry
) "\n\t"
499 : "=a" (*eax
), "=b" (error
), "=c" (cx
), "=d" (dx
),
501 : "a" (func
), "b" (ebx_in
), "c" (ecx_in
)
505 __restore_flags(flags
);
509 static int __init
apm_driver_version(u_short
*val
)
513 if (apm_bios_call_simple(APM_FUNC_VERSION
, 0, *val
, &eax
))
514 return (eax
>> 8) & 0xff;
519 static int apm_get_event(apm_event_t
*event
, apm_eventinfo_t
*info
)
526 if (apm_bios_call(APM_FUNC_GET_EVENT
, 0, 0, &eax
, &ebx
, &ecx
,
528 return (eax
>> 8) & 0xff;
530 if (apm_bios_info
.version
< 0x0102)
531 *info
= ~0; /* indicate info not valid */
537 static int set_power_state(u_short what
, u_short state
)
541 if (apm_bios_call_simple(APM_FUNC_SET_STATE
, what
, state
, &eax
))
542 return (eax
>> 8) & 0xff;
546 static int apm_set_power_state(u_short state
)
548 return set_power_state(APM_DEVICE_ALL
, state
);
551 #ifdef CONFIG_APM_CPU_IDLE
552 static int apm_do_idle(void)
556 if (apm_bios_call_simple(APM_FUNC_IDLE
, 0, 0, &dummy
))
559 #ifdef ALWAYS_CALL_BUSY
562 clock_slowed
= (apm_bios_info
.flags
& APM_IDLE_SLOWS_CLOCK
) != 0;
567 static void apm_do_busy(void)
572 (void) apm_bios_call_simple(APM_FUNC_BUSY
, 0, 0, &dummy
);
578 extern int hlt_counter
;
581 * If no process has been interested in this
582 * CPU for some time, we want to wake up the
583 * power management thread - we probably want
586 #define HARD_IDLE_TIMEOUT (HZ/3)
588 /* This should wake up kapmd and ask it to slow the CPU */
589 #define powermanagement_idle() do { } while (0)
592 * This is the idle thing.
594 static void apm_cpu_idle(void)
596 unsigned int start_idle
;
598 start_idle
= jiffies
;
600 if (!current
->need_resched
) {
601 if (jiffies
- start_idle
< HARD_IDLE_TIMEOUT
) {
602 if (!current_cpu_data
.hlt_works_ok
)
607 if (!current
->need_resched
)
615 * Ok, do some power management - we've been idle for too long
617 powermanagement_idle();
622 start_idle
= jiffies
;
629 static int apm_magic(void * unused
)
636 static void apm_power_off(void)
638 #ifdef CONFIG_APM_REAL_MODE_POWER_OFF
639 unsigned char po_bios_call
[] = {
640 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
641 0x8e, 0xd0, /* movw ax,ss */
642 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
643 0xb8, 0x07, 0x53, /* movw $0x5307,ax */
644 0xbb, 0x01, 0x00, /* movw $0x0001,bx */
645 0xb9, 0x03, 0x00, /* movw $0x0003,cx */
646 0xcd, 0x15 /* int $0x15 */
651 * This may be called on an SMP machine.
654 /* Some bioses don't like being called from CPU != 0 */
655 while (cpu_number_map(smp_processor_id()) != 0) {
656 kernel_thread(apm_magic
, NULL
,
657 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
| SIGCHLD
);
661 #ifdef CONFIG_APM_REAL_MODE_POWER_OFF
662 machine_real_restart(po_bios_call
, sizeof(po_bios_call
));
664 (void) apm_set_power_state(APM_STATE_OFF
);
668 #ifdef CONFIG_APM_DO_ENABLE
669 static int apm_enable_power_management(int enable
)
673 if ((enable
== 0) && (apm_bios_info
.flags
& APM_BIOS_DISENGAGED
))
674 return APM_NOT_ENGAGED
;
675 if (apm_bios_call_simple(APM_FUNC_ENABLE_PM
, APM_DEVICE_BALL
,
677 return (eax
>> 8) & 0xff;
679 apm_bios_info
.flags
&= ~APM_BIOS_DISABLED
;
681 apm_bios_info
.flags
|= APM_BIOS_DISABLED
;
686 static int apm_get_power_status(u_short
*status
, u_short
*bat
, u_short
*life
)
694 if (apm_bios_call(APM_FUNC_GET_STATUS
, APM_DEVICE_ALL
, 0,
695 &eax
, &ebx
, &ecx
, &edx
, &dummy
))
696 return (eax
>> 8) & 0xff;
704 static int apm_get_battery_status(u_short which
, u_short
*status
,
705 u_short
*bat
, u_short
*life
, u_short
*nbat
)
713 if (apm_bios_info
.version
< 0x0102) {
714 /* pretend we only have one battery. */
716 return APM_BAD_DEVICE
;
718 return apm_get_power_status(status
, bat
, life
);
721 if (apm_bios_call(APM_FUNC_GET_STATUS
, (0x8000 | (which
)), 0, &eax
,
722 &ebx
, &ecx
, &edx
, &esi
))
723 return (eax
>> 8) & 0xff;
732 static int apm_engage_power_management(u_short device
, int enable
)
736 if ((enable
== 0) && (device
== APM_DEVICE_ALL
)
737 && (apm_bios_info
.flags
& APM_BIOS_DISABLED
))
739 if (apm_bios_call_simple(APM_FUNC_ENGAGE_PM
, device
, enable
, &eax
))
740 return (eax
>> 8) & 0xff;
741 if (device
== APM_DEVICE_ALL
) {
743 apm_bios_info
.flags
&= ~APM_BIOS_DISENGAGED
;
745 apm_bios_info
.flags
|= APM_BIOS_DISENGAGED
;
750 static void apm_error(char *str
, int err
)
754 for (i
= 0; i
< ERROR_COUNT
; i
++)
755 if (error_table
[i
].key
== err
) break;
757 printk(KERN_NOTICE
"apm: %s: %s\n", str
, error_table
[i
].msg
);
759 printk(KERN_NOTICE
"apm: %s: unknown error code %#2.2x\n",
763 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
764 static int apm_console_blank(int blank
)
769 state
= blank
? APM_STATE_STANDBY
: APM_STATE_READY
;
770 /* Blank the first display device */
771 error
= set_power_state(0x100, state
);
772 if ((error
!= APM_SUCCESS
) && (error
!= APM_NO_ERROR
)) {
773 /* try to blank them all instead */
774 error
= set_power_state(0x1ff, state
);
775 if ((error
!= APM_SUCCESS
) && (error
!= APM_NO_ERROR
))
776 /* try to blank device one instead */
777 error
= set_power_state(0x101, state
);
779 if ((error
== APM_SUCCESS
) || (error
== APM_NO_ERROR
))
781 apm_error("set display", error
);
786 static int queue_empty(struct apm_user
*as
)
788 return as
->event_head
== as
->event_tail
;
791 static apm_event_t
get_queued_event(struct apm_user
*as
)
793 as
->event_tail
= (as
->event_tail
+ 1) % APM_MAX_EVENTS
;
794 return as
->events
[as
->event_tail
];
797 static void queue_event(apm_event_t event
, struct apm_user
*sender
)
799 struct apm_user
* as
;
801 if (user_list
== NULL
)
803 for (as
= user_list
; as
!= NULL
; as
= as
->next
) {
806 as
->event_head
= (as
->event_head
+ 1) % APM_MAX_EVENTS
;
807 if (as
->event_head
== as
->event_tail
) {
811 printk(KERN_ERR
"apm: an event queue overflowed\n");
812 as
->event_tail
= (as
->event_tail
+ 1) % APM_MAX_EVENTS
;
814 as
->events
[as
->event_head
] = event
;
818 case APM_SYS_SUSPEND
:
819 case APM_USER_SUSPEND
:
820 as
->suspends_pending
++;
824 case APM_SYS_STANDBY
:
825 case APM_USER_STANDBY
:
826 as
->standbys_pending
++;
831 wake_up_interruptible(&apm_waitqueue
);
834 static void set_time(void)
838 if (got_clock_diff
) { /* Must know time zone in order to set clock */
841 CURRENT_TIME
= get_cmos_time() + clock_cmos_diff
;
842 restore_flags(flags
);
846 static void get_time_diff(void)
848 #ifndef CONFIG_APM_RTC_IS_GMT
852 * Estimate time zone so that set_time can update the clock
855 clock_cmos_diff
= -get_cmos_time();
857 clock_cmos_diff
+= CURRENT_TIME
;
859 restore_flags(flags
);
863 static void reinit_timer(void)
865 #ifdef INIT_TIMER_AFTER_SUSPEND
870 /* set the clock to 100 Hz */
871 outb_p(0x34,0x43); /* binary, mode 2, LSB/MSB, ch 0 */
873 outb_p(LATCH
& 0xff , 0x40); /* LSB */
875 outb(LATCH
>> 8 , 0x40); /* MSB */
877 restore_flags(flags
);
881 static int send_event(apm_event_t event
)
884 case APM_SYS_SUSPEND
:
885 case APM_CRITICAL_SUSPEND
:
886 case APM_USER_SUSPEND
:
887 /* map all suspends to ACPI D3 */
888 if (pm_send_all(PM_SUSPEND
, (void *)3)) {
889 if (event
== APM_CRITICAL_SUSPEND
) {
890 printk(KERN_CRIT
"apm: Critical suspend was vetoed, expect armageddon\n" );
893 if (apm_bios_info
.version
> 0x100)
894 apm_set_power_state(APM_STATE_REJECT
);
898 case APM_NORMAL_RESUME
:
899 case APM_CRITICAL_RESUME
:
900 /* map all resumes to ACPI D0 */
901 (void) pm_send_all(PM_RESUME
, (void *)0);
908 static int suspend(void)
915 err
= apm_set_power_state(APM_STATE_SUSPEND
);
918 if (err
== APM_NO_ERROR
)
920 if (err
!= APM_SUCCESS
)
921 apm_error("suspend", err
);
922 send_event(APM_NORMAL_RESUME
);
924 queue_event(APM_NORMAL_RESUME
, NULL
);
925 for (as
= user_list
; as
!= NULL
; as
= as
->next
) {
926 as
->suspend_wait
= 0;
927 as
->suspend_result
= ((err
== APM_SUCCESS
) ? 0 : -EIO
);
929 ignore_normal_resume
= 1;
930 wake_up_interruptible(&apm_suspend_waitqueue
);
934 static void standby(void)
939 err
= apm_set_power_state(APM_STATE_STANDBY
);
940 if ((err
!= APM_SUCCESS
) && (err
!= APM_NO_ERROR
))
941 apm_error("standby", err
);
944 static apm_event_t
get_event(void)
948 apm_eventinfo_t info
;
952 /* we don't use the eventinfo */
953 error
= apm_get_event(&event
, &info
);
954 if (error
== APM_SUCCESS
)
957 if ((error
!= APM_NO_EVENTS
) && (notified
++ == 0))
958 apm_error("get_event", error
);
963 static void check_events(void)
966 static unsigned long last_resume
;
967 static int ignore_bounce
;
969 while ((event
= get_event()) != 0) {
971 if (event
<= NR_APM_EVENT_NAME
)
972 printk(KERN_DEBUG
"apm: received %s notify\n",
973 apm_event_name
[event
- 1]);
975 printk(KERN_DEBUG
"apm: received unknown "
976 "event 0x%02x\n", event
);
979 && ((jiffies
- last_resume
) > bounce_interval
))
981 if (ignore_normal_resume
&& (event
!= APM_NORMAL_RESUME
))
982 ignore_normal_resume
= 0;
985 case APM_SYS_STANDBY
:
986 case APM_USER_STANDBY
:
987 if (send_event(event
)) {
988 queue_event(event
, NULL
);
989 if (standbys_pending
<= 0)
994 case APM_USER_SUSPEND
:
995 #ifdef CONFIG_APM_IGNORE_USER_SUSPEND
996 if (apm_bios_info
.version
> 0x100)
997 apm_set_power_state(APM_STATE_REJECT
);
1000 case APM_SYS_SUSPEND
:
1001 if (ignore_bounce
) {
1002 if (apm_bios_info
.version
> 0x100)
1003 apm_set_power_state(APM_STATE_REJECT
);
1007 * If we are already processing a SUSPEND,
1008 * then further SUSPEND events from the BIOS
1009 * will be ignored. We also return here to
1010 * cope with the fact that the Thinkpads keep
1011 * sending a SUSPEND event until something else
1014 if (waiting_for_resume
)
1016 if (send_event(event
)) {
1017 queue_event(event
, NULL
);
1018 waiting_for_resume
= 1;
1019 if (suspends_pending
<= 0)
1024 case APM_NORMAL_RESUME
:
1025 case APM_CRITICAL_RESUME
:
1026 case APM_STANDBY_RESUME
:
1027 waiting_for_resume
= 0;
1028 last_resume
= jiffies
;
1030 if ((event
!= APM_NORMAL_RESUME
)
1031 || (ignore_normal_resume
== 0)) {
1034 queue_event(event
, NULL
);
1038 case APM_CAPABILITY_CHANGE
:
1039 case APM_LOW_BATTERY
:
1040 case APM_POWER_STATUS_CHANGE
:
1042 queue_event(event
, NULL
);
1045 case APM_UPDATE_TIME
:
1049 case APM_CRITICAL_SUSPEND
:
1052 * We can only hope it worked - we are not allowed
1053 * to reject a critical suspend.
1061 static void apm_event_handler(void)
1063 static int pending_count
= 4;
1066 if ((standbys_pending
> 0) || (suspends_pending
> 0)) {
1067 if ((apm_bios_info
.version
> 0x100) && (pending_count
-- <= 0)) {
1070 printk(KERN_DEBUG
"apm: setting state busy\n");
1071 err
= apm_set_power_state(APM_STATE_BUSY
);
1073 apm_error("busy", err
);
1081 * This is the APM thread main loop.
1083 * Check whether we're the only running process to
1084 * decide if we should just power down.
1087 #define system_idle() (nr_running == 1)
1089 static void apm_mainloop(void)
1092 DECLARE_WAITQUEUE(wait
, current
);
1094 add_wait_queue(&apm_waitqueue
, &wait
);
1095 set_current_state(TASK_INTERRUPTIBLE
);
1097 /* Nothing to do, just sleep for the timeout */
1098 timeout
= 2*timeout
;
1099 if (timeout
> APM_CHECK_TIMEOUT
)
1100 timeout
= APM_CHECK_TIMEOUT
;
1101 schedule_timeout(timeout
);
1106 * Ok, check all events, check for idle (and mark us sleeping
1107 * so as not to count towards the load average)..
1109 set_current_state(TASK_INTERRUPTIBLE
);
1110 apm_event_handler();
1111 #ifdef CONFIG_APM_CPU_IDLE
1114 if (apm_do_idle()) {
1115 unsigned long start
= jiffies
;
1116 while ((!exit_kapmd
) && system_idle()) {
1118 if ((jiffies
- start
) > APM_CHECK_TIMEOUT
) {
1119 apm_event_handler();
1124 apm_event_handler();
1131 static int check_apm_user(struct apm_user
*as
, const char *func
)
1133 if ((as
== NULL
) || (as
->magic
!= APM_BIOS_MAGIC
)) {
1134 printk(KERN_ERR
"apm: %s passed bad filp\n", func
);
1140 static ssize_t
do_read(struct file
*fp
, char *buf
, size_t count
, loff_t
*ppos
)
1142 struct apm_user
* as
;
1145 DECLARE_WAITQUEUE(wait
, current
);
1147 as
= fp
->private_data
;
1148 if (check_apm_user(as
, "read"))
1150 if (count
< sizeof(apm_event_t
))
1152 if (queue_empty(as
)) {
1153 if (fp
->f_flags
& O_NONBLOCK
)
1155 add_wait_queue(&apm_waitqueue
, &wait
);
1157 set_current_state(TASK_INTERRUPTIBLE
);
1158 if (queue_empty(as
) && !signal_pending(current
)) {
1162 set_current_state(TASK_RUNNING
);
1163 remove_wait_queue(&apm_waitqueue
, &wait
);
1166 while ((i
>= sizeof(event
)) && !queue_empty(as
)) {
1167 event
= get_queued_event(as
);
1168 if (copy_to_user(buf
, &event
, sizeof(event
))) {
1174 case APM_SYS_SUSPEND
:
1175 case APM_USER_SUSPEND
:
1176 as
->suspends_read
++;
1179 case APM_SYS_STANDBY
:
1180 case APM_USER_STANDBY
:
1181 as
->standbys_read
++;
1184 buf
+= sizeof(event
);
1189 if (signal_pending(current
))
1190 return -ERESTARTSYS
;
1194 static unsigned int do_poll(struct file
*fp
, poll_table
* wait
)
1196 struct apm_user
* as
;
1198 as
= fp
->private_data
;
1199 if (check_apm_user(as
, "poll"))
1201 poll_wait(fp
, &apm_waitqueue
, wait
);
1202 if (!queue_empty(as
))
1203 return POLLIN
| POLLRDNORM
;
1207 static int do_ioctl(struct inode
* inode
, struct file
*filp
,
1208 u_int cmd
, u_long arg
)
1210 struct apm_user
* as
;
1211 DECLARE_WAITQUEUE(wait
, current
);
1213 as
= filp
->private_data
;
1214 if (check_apm_user(as
, "ioctl"))
1219 case APM_IOC_STANDBY
:
1220 if (as
->standbys_read
> 0) {
1221 as
->standbys_read
--;
1222 as
->standbys_pending
--;
1224 } else if (!send_event(APM_USER_STANDBY
))
1227 queue_event(APM_USER_STANDBY
, as
);
1228 if (standbys_pending
<= 0)
1231 case APM_IOC_SUSPEND
:
1232 if (as
->suspends_read
> 0) {
1233 as
->suspends_read
--;
1234 as
->suspends_pending
--;
1236 } else if (!send_event(APM_USER_SUSPEND
))
1239 queue_event(APM_USER_SUSPEND
, as
);
1240 if (suspends_pending
<= 0) {
1241 if (suspend() != APM_SUCCESS
)
1244 as
->suspend_wait
= 1;
1245 add_wait_queue(&apm_suspend_waitqueue
, &wait
);
1247 set_current_state(TASK_INTERRUPTIBLE
);
1248 if ((as
->suspend_wait
== 0)
1249 || signal_pending(current
))
1253 set_current_state(TASK_RUNNING
);
1254 remove_wait_queue(&apm_suspend_waitqueue
, &wait
);
1255 return as
->suspend_result
;
1264 static int do_release(struct inode
* inode
, struct file
* filp
)
1266 struct apm_user
* as
;
1268 as
= filp
->private_data
;
1269 if (check_apm_user(as
, "release"))
1271 filp
->private_data
= NULL
;
1273 if (as
->standbys_pending
> 0) {
1274 standbys_pending
-= as
->standbys_pending
;
1275 if (standbys_pending
<= 0)
1278 if (as
->suspends_pending
> 0) {
1279 suspends_pending
-= as
->suspends_pending
;
1280 if (suspends_pending
<= 0)
1283 if (user_list
== as
)
1284 user_list
= as
->next
;
1286 struct apm_user
* as1
;
1288 for (as1
= user_list
;
1289 (as1
!= NULL
) && (as1
->next
!= as
);
1293 printk(KERN_ERR
"apm: filp not in user list\n");
1295 as1
->next
= as
->next
;
1302 static int do_open(struct inode
* inode
, struct file
* filp
)
1304 struct apm_user
* as
;
1306 as
= (struct apm_user
*)kmalloc(sizeof(*as
), GFP_KERNEL
);
1308 printk(KERN_ERR
"apm: cannot allocate struct of size %d bytes\n",
1312 as
->magic
= APM_BIOS_MAGIC
;
1313 as
->event_tail
= as
->event_head
= 0;
1314 as
->suspends_pending
= as
->standbys_pending
= 0;
1315 as
->suspends_read
= as
->standbys_read
= 0;
1317 * XXX - this is a tiny bit broken, when we consider BSD
1318 * process accounting. If the device is opened by root, we
1319 * instantly flag that we used superuser privs. Who knows,
1320 * we might close the device immediately without doing a
1321 * privileged operation -- cevans
1323 as
->suser
= capable(CAP_SYS_ADMIN
);
1324 as
->next
= user_list
;
1326 filp
->private_data
= as
;
1330 static int apm_get_info(char *buf
, char **start
, off_t fpos
, int length
)
1336 unsigned short error
;
1337 unsigned short ac_line_status
= 0xff;
1338 unsigned short battery_status
= 0xff;
1339 unsigned short battery_flag
= 0xff;
1340 int percentage
= -1;
1341 int time_units
= -1;
1346 if ((smp_num_cpus
== 1) &&
1347 !(error
= apm_get_power_status(&bx
, &cx
, &dx
))) {
1348 ac_line_status
= (bx
>> 8) & 0xff;
1349 battery_status
= bx
& 0xff;
1350 if ((cx
& 0xff) != 0xff)
1351 percentage
= cx
& 0xff;
1353 if (apm_bios_info
.version
> 0x100) {
1354 battery_flag
= (cx
>> 8) & 0xff;
1356 units
= (dx
& 0x8000) ? "min" : "sec";
1357 time_units
= dx
& 0x7fff;
1361 /* Arguments, with symbols from linux/apm_bios.h. Information is
1362 from the Get Power Status (0x0a) call unless otherwise noted.
1364 0) Linux driver version (this will change if format changes)
1365 1) APM BIOS Version. Usually 1.0, 1.1 or 1.2.
1366 2) APM flags from APM Installation Check (0x00):
1367 bit 0: APM_16_BIT_SUPPORT
1368 bit 1: APM_32_BIT_SUPPORT
1369 bit 2: APM_IDLE_SLOWS_CLOCK
1370 bit 3: APM_BIOS_DISABLED
1371 bit 4: APM_BIOS_DISENGAGED
1375 0x02: On backup power (BIOS >= 1.1 only)
1382 0x04: Selected battery not present (BIOS >= 1.2 only)
1389 bit 7: No system battery
1391 6) Remaining battery life (percentage of charge):
1394 7) Remaining battery life (time units):
1395 Number of remaining minutes or seconds
1397 8) min = minutes; sec = seconds */
1399 p
+= sprintf(p
, "%s %d.%d 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
1401 (apm_bios_info
.version
>> 8) & 0xff,
1402 apm_bios_info
.version
& 0xff,
1403 apm_bios_info
.flags
,
1414 static int apm(void *unused
)
1419 unsigned short error
;
1425 exit_files(current
); /* daemonize doesn't do exit_files */
1428 strcpy(current
->comm
, "kapmd");
1429 sigfillset(¤t
->blocked
);
1430 current
->tty
= NULL
; /* get rid of controlling tty */
1432 if (apm_bios_info
.version
> 0x100) {
1434 * We only support BIOSs up to version 1.2
1436 if (apm_bios_info
.version
> 0x0102)
1437 apm_bios_info
.version
= 0x0102;
1438 if (apm_driver_version(&apm_bios_info
.version
) != APM_SUCCESS
) {
1439 /* Fall back to an APM 1.0 connection. */
1440 apm_bios_info
.version
= 0x100;
1443 if (debug
&& (smp_num_cpus
== 1)) {
1444 printk(KERN_INFO
"apm: Connection version %d.%d\n",
1445 (apm_bios_info
.version
>> 8) & 0xff,
1446 apm_bios_info
.version
& 0xff);
1448 error
= apm_get_power_status(&bx
, &cx
, &dx
);
1450 printk(KERN_INFO
"apm: power status not available\n");
1452 switch ((bx
>> 8) & 0xff) {
1453 case 0: power_stat
= "off line"; break;
1454 case 1: power_stat
= "on line"; break;
1455 case 2: power_stat
= "on backup power"; break;
1456 default: power_stat
= "unknown"; break;
1458 switch (bx
& 0xff) {
1459 case 0: bat_stat
= "high"; break;
1460 case 1: bat_stat
= "low"; break;
1461 case 2: bat_stat
= "critical"; break;
1462 case 3: bat_stat
= "charging"; break;
1463 default: bat_stat
= "unknown"; break;
1466 "apm: AC %s, battery status %s, battery life ",
1467 power_stat
, bat_stat
);
1468 if ((cx
& 0xff) == 0xff)
1469 printk("unknown\n");
1471 printk("%d%%\n", cx
& 0xff);
1472 if (apm_bios_info
.version
> 0x100) {
1474 "apm: battery flag 0x%02x, battery life ",
1477 printk("unknown\n");
1479 printk("%d %s\n", dx
& 0x7fff,
1481 "minutes" : "seconds");
1486 #ifdef CONFIG_APM_DO_ENABLE
1487 if (apm_bios_info
.flags
& APM_BIOS_DISABLED
) {
1489 * This call causes my NEC UltraLite Versa 33/C to hang if it
1490 * is booted with PM disabled but not in the docking station.
1493 error
= apm_enable_power_management(1);
1495 apm_error("enable power management", error
);
1500 if ((apm_bios_info
.flags
& APM_BIOS_DISENGAGED
)
1501 && (apm_bios_info
.version
> 0x0100)) {
1502 error
= apm_engage_power_management(APM_DEVICE_ALL
, 1);
1504 apm_error("engage power management", error
);
1509 /* Install our power off handler.. */
1511 pm_power_off
= apm_power_off
;
1512 #ifdef CONFIG_MAGIC_SYSRQ
1513 sysrq_power_off
= apm_power_off
;
1515 if (smp_num_cpus
== 1) {
1516 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
1517 console_blank_hook
= apm_console_blank
;
1520 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
1521 console_blank_hook
= NULL
;
1530 static int __init
apm_setup(char *str
)
1534 while ((str
!= NULL
) && (*str
!= '\0')) {
1535 if (strncmp(str
, "off", 3) == 0)
1537 if (strncmp(str
, "on", 2) == 0)
1539 invert
= (strncmp(str
, "no-", 3) == 0);
1542 if (strncmp(str
, "debug", 5) == 0)
1544 if ((strncmp(str
, "power-off", 9) == 0) ||
1545 (strncmp(str
, "power_off", 9) == 0))
1546 power_off
= !invert
;
1547 if ((strncmp(str
, "bounce-interval=", 16) == 0) ||
1548 (strncmp(str
, "bounce_interval=", 16) == 0))
1549 bounce_interval
= simple_strtol(str
+ 16, NULL
, 0);
1550 str
= strchr(str
, ',');
1552 str
+= strspn(str
, ", \t");
1557 __setup("apm=", apm_setup
);
1560 static struct file_operations apm_bios_fops
= {
1566 release
: do_release
,
1569 static struct miscdevice apm_device
= {
1575 #define APM_INIT_ERROR_RETURN return -1
1578 * Just start the APM thread. We do NOT want to do APM BIOS
1579 * calls from anything but the APM thread, if for no other reason
1580 * than the fact that we don't trust the APM BIOS. This way,
1581 * most common APM BIOS problems that lead to protection errors
1582 * etc will have at least some level of being contained...
1584 * In short, if something bad happens, at least we have a choice
1585 * of just killing the apm thread..
1587 static int __init
apm_init(void)
1589 if (apm_bios_info
.version
== 0) {
1590 printk(KERN_INFO
"apm: BIOS not found.\n");
1591 APM_INIT_ERROR_RETURN
;
1594 "apm: BIOS version %d.%d Flags 0x%02x (Driver version %s)\n",
1595 ((apm_bios_info
.version
>> 8) & 0xff),
1596 (apm_bios_info
.version
& 0xff),
1597 apm_bios_info
.flags
,
1599 if ((apm_bios_info
.flags
& APM_32_BIT_SUPPORT
) == 0) {
1600 printk(KERN_INFO
"apm: no 32 bit BIOS support\n");
1601 APM_INIT_ERROR_RETURN
;
1605 * Fix for the Compaq Contura 3/25c which reports BIOS version 0.1
1606 * but is reportedly a 1.0 BIOS.
1608 if (apm_bios_info
.version
== 0x001)
1609 apm_bios_info
.version
= 0x100;
1611 /* BIOS < 1.2 doesn't set cseg_16_len */
1612 if (apm_bios_info
.version
< 0x102)
1613 apm_bios_info
.cseg_16_len
= 0; /* 64k */
1616 printk(KERN_INFO
"apm: entry %x:%lx cseg16 %x dseg %x",
1617 apm_bios_info
.cseg
, apm_bios_info
.offset
,
1618 apm_bios_info
.cseg_16
, apm_bios_info
.dseg
);
1619 if (apm_bios_info
.version
> 0x100)
1620 printk(" cseg len %x, dseg len %x",
1621 apm_bios_info
.cseg_len
,
1622 apm_bios_info
.dseg_len
);
1623 if (apm_bios_info
.version
> 0x101)
1624 printk(" cseg16 len %x", apm_bios_info
.cseg_16_len
);
1629 printk(KERN_NOTICE
"apm: disabled on user request.\n");
1630 APM_INIT_ERROR_RETURN
;
1632 if ((smp_num_cpus
> 1) && !power_off
) {
1633 printk(KERN_NOTICE
"apm: disabled - APM is not SMP safe.\n");
1634 APM_INIT_ERROR_RETURN
;
1636 if (PM_IS_ACTIVE()) {
1637 printk(KERN_NOTICE
"apm: overridden by ACPI.\n");
1638 APM_INIT_ERROR_RETURN
;
1643 * Set up a segment that references the real mode segment 0x40
1644 * that extends up to the end of page zero (that we have reserved).
1645 * This is for buggy BIOS's that refer to (real mode) segment 0x40
1646 * even though they are called in protected mode.
1648 set_base(gdt
[APM_40
>> 3],
1649 __va((unsigned long)0x40 << 4));
1650 _set_limit((char *)&gdt
[APM_40
>> 3], 4095 - (0x40 << 4));
1652 apm_bios_entry
.offset
= apm_bios_info
.offset
;
1653 apm_bios_entry
.segment
= APM_CS
;
1654 set_base(gdt
[APM_CS
>> 3],
1655 __va((unsigned long)apm_bios_info
.cseg
<< 4));
1656 set_base(gdt
[APM_CS_16
>> 3],
1657 __va((unsigned long)apm_bios_info
.cseg_16
<< 4));
1658 set_base(gdt
[APM_DS
>> 3],
1659 __va((unsigned long)apm_bios_info
.dseg
<< 4));
1660 #ifndef APM_RELAX_SEGMENTS
1661 if (apm_bios_info
.version
== 0x100) {
1663 /* For ASUS motherboard, Award BIOS rev 110 (and others?) */
1664 _set_limit((char *)&gdt
[APM_CS
>> 3], 64 * 1024 - 1);
1665 /* For some unknown machine. */
1666 _set_limit((char *)&gdt
[APM_CS_16
>> 3], 64 * 1024 - 1);
1667 /* For the DEC Hinote Ultra CT475 (and others?) */
1668 _set_limit((char *)&gdt
[APM_DS
>> 3], 64 * 1024 - 1);
1669 #ifndef APM_RELAX_SEGMENTS
1671 _set_limit((char *)&gdt
[APM_CS
>> 3],
1672 (apm_bios_info
.cseg_len
- 1) & 0xffff);
1673 _set_limit((char *)&gdt
[APM_CS_16
>> 3],
1674 (apm_bios_info
.cseg_16_len
- 1) & 0xffff);
1675 _set_limit((char *)&gdt
[APM_DS
>> 3],
1676 (apm_bios_info
.dseg_len
- 1) & 0xffff);
1680 create_proc_info_entry("apm", 0, NULL
, apm_get_info
);
1682 kernel_thread(apm
, NULL
, CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
| SIGCHLD
);
1684 if (smp_num_cpus
> 1) {
1686 "apm: disabled - APM is not SMP safe (power off active).\n");
1687 APM_INIT_ERROR_RETURN
;
1690 misc_register(&apm_device
);
1695 static void __exit
apm_exit(void)
1697 misc_deregister(&apm_device
);
1698 remove_proc_entry("apm", NULL
);
1699 #ifdef CONFIG_MAGIC_SYSRQ
1700 sysrq_power_off
= NULL
;
1703 pm_power_off
= NULL
;
1705 while (kapmd_running
)
1710 module_init(apm_init
);
1711 module_exit(apm_exit
);
1713 MODULE_AUTHOR("Stephen Rothwell");
1714 MODULE_DESCRIPTION("Advanced Power Management");
1715 MODULE_PARM(debug
, "i");
1716 MODULE_PARM_DESC(debug
, "Enable debug mode");
1717 MODULE_PARM(power_off
, "i");
1718 MODULE_PARM_DESC(power_off
, "Enable power off");
1719 MODULE_PARM(bounce_interval
, "i");
1720 MODULE_PARM_DESC(bounce_interval
, "Set the number of ticks to ignore suspend bounces");