[CPUFREQ] Fix up merge conflicts with recent ACPI changes.
[linux-2.6] / arch / s390 / kernel / cpcmd.c
1 /*
2  *  arch/s390/kernel/cpcmd.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7  *               Christian Borntraeger (cborntra@de.ibm.com),
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/stddef.h>
15 #include <linux/string.h>
16 #include <asm/ebcdic.h>
17 #include <asm/cpcmd.h>
18 #include <asm/system.h>
19 #include <asm/io.h>
20
21 static DEFINE_SPINLOCK(cpcmd_lock);
22 static char cpcmd_buf[241];
23
24 /*
25  * __cpcmd has some restrictions over cpcmd
26  *  - the response buffer must reside below 2GB (if any)
27  *  - __cpcmd is unlocked and therefore not SMP-safe
28  */
29 int  __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
30 {
31         unsigned cmdlen;
32         int return_code, return_len;
33
34         cmdlen = strlen(cmd);
35         BUG_ON(cmdlen > 240);
36         memcpy(cpcmd_buf, cmd, cmdlen);
37         ASCEBC(cpcmd_buf, cmdlen);
38
39         if (response != NULL && rlen > 0) {
40                 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
41                 register unsigned long reg3 asm ("3") = (addr_t) response;
42                 register unsigned long reg4 asm ("4") = cmdlen | 0x40000000L;
43                 register unsigned long reg5 asm ("5") = rlen;
44
45                 memset(response, 0, rlen);
46                 asm volatile(
47 #ifndef CONFIG_64BIT
48                         "       diag    %2,%0,0x8\n"
49                         "       brc     8,1f\n"
50                         "       ar      %1,%4\n"
51 #else /* CONFIG_64BIT */
52                         "       sam31\n"
53                         "       diag    %2,%0,0x8\n"
54                         "       sam64\n"
55                         "       brc     8,1f\n"
56                         "       agr     %1,%4\n"
57 #endif /* CONFIG_64BIT */
58                         "1:\n"
59                         : "+d" (reg4), "+d" (reg5)
60                         : "d" (reg2), "d" (reg3), "d" (rlen) : "cc");
61                 return_code = (int) reg4;
62                 return_len = (int) reg5;
63                 EBCASC(response, rlen);
64         } else {
65                 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
66                 register unsigned long reg3 asm ("3") = cmdlen;
67                 return_len = 0;
68                 asm volatile(
69 #ifndef CONFIG_64BIT
70                         "       diag    %1,%0,0x8\n"
71 #else /* CONFIG_64BIT */
72                         "       sam31\n"
73                         "       diag    %1,%0,0x8\n"
74                         "       sam64\n"
75 #endif /* CONFIG_64BIT */
76                         : "+d" (reg3) : "d" (reg2) : "cc");
77                 return_code = (int) reg3;
78         }
79         if (response_code != NULL)
80                 *response_code = return_code;
81         return return_len;
82 }
83
84 EXPORT_SYMBOL(__cpcmd);
85
86 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
87 {
88         char *lowbuf;
89         int len;
90         unsigned long flags;
91
92         if ((virt_to_phys(response) != (unsigned long) response) ||
93                         (((unsigned long)response + rlen) >> 31)) {
94                 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
95                 if (!lowbuf) {
96                         printk(KERN_WARNING
97                                 "cpcmd: could not allocate response buffer\n");
98                         return -ENOMEM;
99                 }
100                 spin_lock_irqsave(&cpcmd_lock, flags);
101                 len = __cpcmd(cmd, lowbuf, rlen, response_code);
102                 spin_unlock_irqrestore(&cpcmd_lock, flags);
103                 memcpy(response, lowbuf, rlen);
104                 kfree(lowbuf);
105         } else {
106                 spin_lock_irqsave(&cpcmd_lock, flags);
107                 len = __cpcmd(cmd, response, rlen, response_code);
108                 spin_unlock_irqrestore(&cpcmd_lock, flags);
109         }
110         return len;
111 }
112
113 EXPORT_SYMBOL(cpcmd);