]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - arch/i386/kernel/apm.c
[PATCH] x86: GDT alignment fix
[net-next-2.6.git] / arch / i386 / kernel / apm.c
index d2ef0c2aa93e462df516ec6e78c8473bed7c56b7..6c8e483ce9e40af033e3cbc063db9442c90b3a75 100644 (file)
 #include <linux/time.h>
 #include <linux/sched.h>
 #include <linux/pm.h>
+#include <linux/pm_legacy.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/smp.h>
@@ -447,8 +448,7 @@ static char *       apm_event_name[] = {
        "system standby resume",
        "capabilities change"
 };
-#define NR_APM_EVENT_NAME      \
-               (sizeof(apm_event_name) / sizeof(apm_event_name[0]))
+#define NR_APM_EVENT_NAME ARRAY_SIZE(apm_event_name)
 
 typedef struct lookup_t {
        int     key;
@@ -479,7 +479,7 @@ static const lookup_t error_table[] = {
        { APM_NO_ERROR,         "BIOS did not set a return code" },
        { APM_NOT_PRESENT,      "No APM present" }
 };
-#define ERROR_COUNT    (sizeof(error_table)/sizeof(lookup_t))
+#define ERROR_COUNT    ARRAY_SIZE(error_table)
 
 /**
  *     apm_error       -       display an APM error
@@ -770,8 +770,26 @@ static int set_system_power_state(u_short state)
 static int apm_do_idle(void)
 {
        u32     eax;
+       u8      ret = 0;
+       int     idled = 0;
+       int     polling;
+
+       polling = test_thread_flag(TIF_POLLING_NRFLAG);
+       if (polling) {
+               clear_thread_flag(TIF_POLLING_NRFLAG);
+               smp_mb__after_clear_bit();
+       }
+       if (!need_resched()) {
+               idled = 1;
+               ret = apm_bios_call_simple(APM_FUNC_IDLE, 0, 0, &eax);
+       }
+       if (polling)
+               set_thread_flag(TIF_POLLING_NRFLAG);
+
+       if (!idled)
+               return 0;
 
-       if (apm_bios_call_simple(APM_FUNC_IDLE, 0, 0, &eax)) {
+       if (ret) {
                static unsigned long t;
 
                /* This always fails on some SMP boards running UP kernels.
@@ -2299,6 +2317,8 @@ static int __init apm_init(void)
 
        for (i = 0; i < NR_CPUS; i++) {
                struct desc_struct *gdt = get_cpu_gdt_table(i);
+               if (!gdt)
+                       continue;
                set_base(gdt[APM_CS >> 3],
                         __va((unsigned long)apm_info.bios.cseg << 4));
                set_base(gdt[APM_CS_16 >> 3],