bitops: rename for_each_bit() to for_each_set_bit()
[safe/jmp/linux-2.6] / arch / x86 / kernel / apm_32.c
index b5e841b..031aa88 100644 (file)
 #include <linux/module.h>
 
 #include <linux/poll.h>
-#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <linux/timer.h>
@@ -403,7 +402,16 @@ 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 struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
+static DEFINE_MUTEX(apm_mutex);
+
+/*
+ * Set up a segment that references the real mode segment 0x40
+ * that extends up to the end of page zero (that we have reserved).
+ * This is for buggy BIOS's that refer to (real mode) segment 0x40
+ * even though they are called in protected mode.
+ */
+static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
+                       (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
 
 static const char driver_version[] = "1.16ac"; /* no spaces */
 
@@ -811,7 +819,7 @@ static int apm_do_idle(void)
        u8 ret = 0;
        int idled = 0;
        int polling;
-       int err;
+       int err = 0;
 
        polling = !!(current_thread_info()->status & TS_POLLING);
        if (polling) {
@@ -1523,7 +1531,7 @@ static long do_ioctl(struct file *filp, u_int cmd, u_long arg)
                return -EPERM;
        switch (cmd) {
        case APM_IOC_STANDBY:
-               lock_kernel();
+               mutex_lock(&apm_mutex);
                if (as->standbys_read > 0) {
                        as->standbys_read--;
                        as->standbys_pending--;
@@ -1532,10 +1540,10 @@ static long do_ioctl(struct file *filp, u_int cmd, u_long arg)
                        queue_event(APM_USER_STANDBY, as);
                if (standbys_pending <= 0)
                        standby();
-               unlock_kernel();
+               mutex_unlock(&apm_mutex);
                break;
        case APM_IOC_SUSPEND:
-               lock_kernel();
+               mutex_lock(&apm_mutex);
                if (as->suspends_read > 0) {
                        as->suspends_read--;
                        as->suspends_pending--;
@@ -1544,13 +1552,14 @@ static long do_ioctl(struct file *filp, u_int cmd, u_long arg)
                        queue_event(APM_USER_SUSPEND, as);
                if (suspends_pending <= 0) {
                        ret = suspend(1);
+                       mutex_unlock(&apm_mutex);
                } else {
                        as->suspend_wait = 1;
+                       mutex_unlock(&apm_mutex);
                        wait_event_interruptible(apm_suspend_waitqueue,
                                        as->suspend_wait == 0);
                        ret = as->suspend_result;
                }
-               unlock_kernel();
                return ret;
        default:
                return -ENOTTY;
@@ -1600,12 +1609,10 @@ static int do_open(struct inode *inode, struct file *filp)
 {
        struct apm_user *as;
 
-       lock_kernel();
        as = kmalloc(sizeof(*as), GFP_KERNEL);
        if (as == NULL) {
                printk(KERN_ERR "apm: cannot allocate struct of size %d bytes\n",
                       sizeof(*as));
-                      unlock_kernel();
                return -ENOMEM;
        }
        as->magic = APM_BIOS_MAGIC;
@@ -1627,7 +1634,6 @@ static int do_open(struct inode *inode, struct file *filp)
        user_list = as;
        spin_unlock(&user_list_lock);
        filp->private_data = as;
-       unlock_kernel();
        return 0;
 }
 
@@ -1986,8 +1992,8 @@ static int __init apm_is_horked_d850md(const struct dmi_system_id *d)
                apm_info.disabled = 1;
                printk(KERN_INFO "%s machine detected. "
                       "Disabling APM.\n", d->ident);
-               printk(KERN_INFO "This bug is fixed in bios P15 which is available for \n");
-               printk(KERN_INFO "download from support.intel.com \n");
+               printk(KERN_INFO "This bug is fixed in bios P15 which is available for\n");
+               printk(KERN_INFO "download from support.intel.com\n");
        }
        return 0;
 }
@@ -2332,15 +2338,6 @@ static int __init apm_init(void)
        pm_flags |= PM_APM;
 
        /*
-        * Set up a segment that references the real mode segment 0x40
-        * that extends up to the end of page zero (that we have reserved).
-        * This is for buggy BIOS's that refer to (real mode) segment 0x40
-        * even though they are called in protected mode.
-        */
-       set_desc_base(&bad_bios_desc, (unsigned long)__va(0x40UL << 4));
-       set_desc_limit(&bad_bios_desc, 4095 - (0x40 << 4));
-
-       /*
         * Set up the long jump entry point to the APM BIOS, which is called
         * from inline assembly.
         */