linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / arch / i386 / kernel / apm.c
index e7f943f..558d2d2 100644 (file)
  *    http://www.microsoft.com/hwdev/busbios/amp_12.htm]
  */
 
+#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/poll.h>
@@ -373,14 +374,14 @@ static struct {
        unsigned short  segment;
 }                              apm_bios_entry;
 static int                     clock_slowed;
-static int                     idle_threshold __read_mostly = DEFAULT_IDLE_THRESHOLD;
-static int                     idle_period __read_mostly = DEFAULT_IDLE_PERIOD;
+static int                     idle_threshold = DEFAULT_IDLE_THRESHOLD;
+static int                     idle_period = DEFAULT_IDLE_PERIOD;
 static int                     set_pm_idle;
 static int                     suspends_pending;
 static int                     standbys_pending;
 static int                     ignore_sys_suspend;
 static int                     ignore_normal_resume;
-static int                     bounce_interval __read_mostly = DEFAULT_BOUNCE_INTERVAL;
+static int                     bounce_interval = DEFAULT_BOUNCE_INTERVAL;
 
 #ifdef CONFIG_APM_RTC_IS_GMT
 #      define  clock_cmos_diff 0
@@ -389,8 +390,8 @@ static int                  bounce_interval __read_mostly = DEFAULT_BOUNCE_INTERVAL;
 static long                    clock_cmos_diff;
 static int                     got_clock_diff;
 #endif
-static int                     debug __read_mostly;
-static int                     smp __read_mostly;
+static int                     debug;
+static int                     smp;
 static int                     apm_disabled = -1;
 #ifdef CONFIG_SMP
 static int                     power_off;
@@ -402,8 +403,8 @@ static int                  realmode_power_off = 1;
 #else
 static int                     realmode_power_off;
 #endif
-static int                     exit_kapmd __read_mostly;
-static int                     kapmd_running __read_mostly;
+static int                     exit_kapmd;
+static int                     kapmd_running;
 #ifdef CONFIG_APM_ALLOW_INTS
 static int                     allow_ints = 1;
 #else
@@ -415,15 +416,15 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
 static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
 static struct apm_user *       user_list;
 static DEFINE_SPINLOCK(user_list_lock);
-static const struct desc_struct        bad_bios_desc = { 0, 0x00409200 };
+static struct desc_struct      bad_bios_desc = { 0, 0x00409200 };
 
-static const char              driver_version[] = "1.16ac";    /* no spaces */
+static char                    driver_version[] = "1.16ac";    /* no spaces */
 
 /*
  *     APM event names taken from the APM 1.2 specification. These are
  *     the message codes that the BIOS uses to tell us about events
  */
-static const char *    const apm_event_name[] = {
+static char *  apm_event_name[] = {
        "system standby",
        "system suspend",
        "normal resume",
@@ -539,22 +540,11 @@ static inline void apm_restore_cpus(cpumask_t mask)
  * Also, we KNOW that for the non error case of apm_bios_call, there
  * is no useful data returned in the low order 8 bits of eax.
  */
-#define APM_DO_CLI \
-       do { \
-               if (apm_info.allow_ints) { \
-                       if (irqs_disabled_flags(flags)) \
-                               local_irq_enable(); \
-               } else \
-                       local_irq_disable(); \
-       } while (0)
-
-#define APM_DO_STI \
-       do { \
-               if (irqs_disabled_flags(flags)) \
-                       local_irq_disable(); \
-               else if (irqs_disabled()) \
-                       local_irq_enable(); \
-       } while (0)
+#define APM_DO_CLI     \
+       if (apm_info.allow_ints) \
+               local_irq_enable(); \
+       else \
+               local_irq_disable();
 
 #ifdef APM_ZERO_SEGS
 #      define APM_DECL_SEGS \
@@ -611,7 +601,7 @@ static u8 apm_bios_call(u32 func, u32 ebx_in, u32 ecx_in,
        APM_DO_SAVE_SEGS;
        apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
        APM_DO_RESTORE_SEGS;
-       APM_DO_STI;
+       local_irq_restore(flags);
        gdt[0x40 / 8] = save_desc_40;
        put_cpu();
        apm_restore_cpus(cpus);
@@ -626,7 +616,7 @@ static u8 apm_bios_call(u32 func, u32 ebx_in, u32 ecx_in,
  *     @ecx_in: ECX register value for BIOS call
  *     @eax: EAX register on return from the BIOS call
  *
- *     Make a BIOS call that returns one value only, or just status.
+ *     Make a BIOS call that does only returns one value, or just status.
  *     If there is an error, then the error code is returned in AH
  *     (bits 8-15 of eax) and this function returns non-zero. This is
  *     used for simpler BIOS operations. This call may hold interrupts
@@ -655,7 +645,7 @@ static u8 apm_bios_call_simple(u32 func, u32 ebx_in, u32 ecx_in, u32 *eax)
        APM_DO_SAVE_SEGS;
        error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
        APM_DO_RESTORE_SEGS;
-       APM_DO_STI;
+       local_irq_restore(flags);
        gdt[0x40 / 8] = save_desc_40;
        put_cpu();
        apm_restore_cpus(cpus);
@@ -774,9 +764,9 @@ static int apm_do_idle(void)
        int     idled = 0;
        int     polling;
 
-       polling = !!(current_thread_info()->status & TS_POLLING);
+       polling = test_thread_flag(TIF_POLLING_NRFLAG);
        if (polling) {
-               current_thread_info()->status &= ~TS_POLLING;
+               clear_thread_flag(TIF_POLLING_NRFLAG);
                smp_mb__after_clear_bit();
        }
        if (!need_resched()) {
@@ -784,7 +774,7 @@ static int apm_do_idle(void)
                ret = apm_bios_call_simple(APM_FUNC_IDLE, 0, 0, &eax);
        }
        if (polling)
-               current_thread_info()->status |= TS_POLLING;
+               set_thread_flag(TIF_POLLING_NRFLAG);
 
        if (!idled)
                return 0;
@@ -832,7 +822,9 @@ static void apm_do_busy(void)
 #define IDLE_CALC_LIMIT   (HZ * 100)
 #define IDLE_LEAKY_MAX    16
 
-static void (*original_pm_idle)(void) __read_mostly;
+static void (*original_pm_idle)(void);
+
+extern void default_idle(void);
 
 /**
  * apm_cpu_idle                -       cpu idling for APM capable Linux
@@ -1073,8 +1065,7 @@ static int apm_engage_power_management(u_short device, int enable)
  
 static int apm_console_blank(int blank)
 {
-       int error = APM_NOT_ENGAGED; /* silence gcc */
-       int i;
+       int error, i;
        u_short state;
        static const u_short dev[3] = { 0x100, 0x1FF, 0x101 };
 
@@ -1115,8 +1106,7 @@ static int queue_empty(struct apm_user *as)
 
 static apm_event_t get_queued_event(struct apm_user *as)
 {
-       if (++as->event_tail >= APM_MAX_EVENTS)
-               as->event_tail = 0;
+       as->event_tail = (as->event_tail + 1) % APM_MAX_EVENTS;
        return as->events[as->event_tail];
 }
 
@@ -1130,16 +1120,13 @@ static void queue_event(apm_event_t event, struct apm_user *sender)
        for (as = user_list; as != NULL; as = as->next) {
                if ((as == sender) || (!as->reader))
                        continue;
-               if (++as->event_head >= APM_MAX_EVENTS)
-                       as->event_head = 0;
-
+               as->event_head = (as->event_head + 1) % APM_MAX_EVENTS;
                if (as->event_head == as->event_tail) {
                        static int notified;
 
                        if (notified++ == 0)
                            printk(KERN_ERR "apm: an event queue overflowed\n");
-                       if (++as->event_tail >= APM_MAX_EVENTS)
-                               as->event_tail = 0;
+                       as->event_tail = (as->event_tail + 1) % APM_MAX_EVENTS;
                }
                as->events[as->event_head] = event;
                if ((!as->suser) || (!as->writer))
@@ -1297,7 +1284,7 @@ static void standby(void)
 static apm_event_t get_event(void)
 {
        int             error;
-       apm_event_t     event = APM_NO_EVENTS; /* silence gcc */
+       apm_event_t     event;
        apm_eventinfo_t info;
 
        static int notified;