Merge branch 'misc' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc...
[pandora-kernel.git] / arch / i386 / kernel / apm.c
index 0d29811..df0e174 100644 (file)
 #include <linux/sched.h>
 #include <linux/pm.h>
 #include <linux/pm_legacy.h>
+#include <linux/capability.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/smp.h>
@@ -823,8 +824,6 @@ static void apm_do_busy(void)
 
 static void (*original_pm_idle)(void);
 
-extern void default_idle(void);
-
 /**
  * apm_cpu_idle                -       cpu idling for APM capable Linux
  *
@@ -1064,21 +1063,22 @@ static int apm_engage_power_management(u_short device, int enable)
  
 static int apm_console_blank(int blank)
 {
-       int     error;
-       u_short state;
+       int error, i;
+       u_short state;
+       static const u_short dev[3] = { 0x100, 0x1FF, 0x101 };
 
        state = blank ? APM_STATE_STANDBY : APM_STATE_READY;
-       /* Blank the first display device */
-       error = set_power_state(0x100, state);
-       if ((error != APM_SUCCESS) && (error != APM_NO_ERROR)) {
-               /* try to blank them all instead */
-               error = set_power_state(0x1ff, state);
-               if ((error != APM_SUCCESS) && (error != APM_NO_ERROR))
-                       /* try to blank device one instead */
-                       error = set_power_state(0x101, state);
+
+       for (i = 0; i < ARRAY_SIZE(dev); i++) {
+               error = set_power_state(dev[i], state);
+
+               if ((error == APM_SUCCESS) || (error == APM_NO_ERROR))
+                       return 1;
+
+               if (error == APM_NOT_ENGAGED)
+                       break;
        }
-       if ((error == APM_SUCCESS) || (error == APM_NO_ERROR))
-               return 1;
+
        if (error == APM_NOT_ENGAGED) {
                static int tried;
                int eng_error;
@@ -2222,8 +2222,8 @@ static struct dmi_system_id __initdata apm_dmi_table[] = {
 static int __init apm_init(void)
 {
        struct proc_dir_entry *apm_proc;
+       struct desc_struct *gdt;
        int ret;
-       int i;
 
        dmi_check_system(apm_dmi_table);
 
@@ -2290,7 +2290,9 @@ static int __init apm_init(void)
                apm_info.disabled = 1;
                return -ENODEV;
        }
+#ifdef CONFIG_PM_LEGACY
        pm_active = 1;
+#endif
 
        /*
         * Set up a segment that references the real mode segment 0x40
@@ -2314,24 +2316,17 @@ static int __init apm_init(void)
         * not restrict themselves to their claimed limit.  When this happens,
         * they will cause a segmentation violation in the kernel at boot time.
         * Most BIOS's, however, will respect a 64k limit, so we use that.
+        *
+        * Note we only set APM segments on CPU zero, since we pin the APM
+        * code to that CPU.
         */
-       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],
-                        __va((unsigned long)apm_info.bios.cseg_16 << 4));
-               set_base(gdt[APM_DS >> 3],
-                        __va((unsigned long)apm_info.bios.dseg << 4));
-               /* For ASUS motherboard, Award BIOS rev 110 (and others?) */
-               _set_limit((char *)&gdt[APM_CS >> 3], 64 * 1024 - 1);
-               /* For some unknown machine. */
-               _set_limit((char *)&gdt[APM_CS_16 >> 3], 64 * 1024 - 1);
-               /* For the DEC Hinote Ultra CT475 (and others?) */
-               _set_limit((char *)&gdt[APM_DS >> 3], 64 * 1024 - 1);
-       }
+       gdt = get_cpu_gdt_table(0);
+       set_base(gdt[APM_CS >> 3],
+                __va((unsigned long)apm_info.bios.cseg << 4));
+       set_base(gdt[APM_CS_16 >> 3],
+                __va((unsigned long)apm_info.bios.cseg_16 << 4));
+       set_base(gdt[APM_DS >> 3],
+                __va((unsigned long)apm_info.bios.dseg << 4));
 
        apm_proc = create_proc_info_entry("apm", 0, NULL, apm_get_info);
        if (apm_proc)
@@ -2388,7 +2383,9 @@ static void __exit apm_exit(void)
        exit_kapmd = 1;
        while (kapmd_running)
                schedule();
+#ifdef CONFIG_PM_LEGACY
        pm_active = 0;
+#endif
 }
 
 module_init(apm_init);