]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/s390/kernel/cpcmd.c
Merge branch 'upstream-jgarzik' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-omap-h63xx.git] / arch / s390 / kernel / cpcmd.c
index 1eae74e72f9525f91a11f56a012f815582157500..6c89f30c8e31ea39f181fe610dffada543254129 100644 (file)
 #include <asm/ebcdic.h>
 #include <asm/cpcmd.h>
 #include <asm/system.h>
+#include <asm/io.h>
 
 static DEFINE_SPINLOCK(cpcmd_lock);
 static char cpcmd_buf[241];
 
 /*
- * the caller of __cpcmd has to ensure that the response buffer is below 2 GB
+ * __cpcmd has some restrictions over cpcmd
+ *  - the response buffer must reside below 2GB (if any)
+ *  - __cpcmd is unlocked and therefore not SMP-safe
  */
 int  __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
 {
-       unsigned long flags, cmdlen;
+       unsigned cmdlen;
        int return_code, return_len;
 
-       spin_lock_irqsave(&cpcmd_lock, flags);
        cmdlen = strlen(cmd);
        BUG_ON(cmdlen > 240);
        memcpy(cpcmd_buf, cmd, cmdlen);
@@ -74,7 +76,6 @@ int  __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
                        : "+d" (reg3) : "d" (reg2) : "cc");
                return_code = (int) reg3;
         }
-       spin_unlock_irqrestore(&cpcmd_lock, flags);
        if (response_code != NULL)
                *response_code = return_code;
        return return_len;
@@ -82,28 +83,31 @@ int  __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
 
 EXPORT_SYMBOL(__cpcmd);
 
-#ifdef CONFIG_64BIT
 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
 {
        char *lowbuf;
        int len;
+       unsigned long flags;
 
-       if ((rlen == 0) || (response == NULL)
-           || !((unsigned long)response >> 31))
-               len = __cpcmd(cmd, response, rlen, response_code);
-       else {
+       if ((virt_to_phys(response) != (unsigned long) response) ||
+                       (((unsigned long)response + rlen) >> 31)) {
                lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
                if (!lowbuf) {
                        printk(KERN_WARNING
                                "cpcmd: could not allocate response buffer\n");
                        return -ENOMEM;
                }
+               spin_lock_irqsave(&cpcmd_lock, flags);
                len = __cpcmd(cmd, lowbuf, rlen, response_code);
+               spin_unlock_irqrestore(&cpcmd_lock, flags);
                memcpy(response, lowbuf, rlen);
                kfree(lowbuf);
+       } else {
+               spin_lock_irqsave(&cpcmd_lock, flags);
+               len = __cpcmd(cmd, response, rlen, response_code);
+               spin_unlock_irqrestore(&cpcmd_lock, flags);
        }
        return len;
 }
 
 EXPORT_SYMBOL(cpcmd);
-#endif         /* CONFIG_64BIT */