Remove all inclusions of <linux/config.h>
[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
20 static DEFINE_SPINLOCK(cpcmd_lock);
21 static char cpcmd_buf[241];
22
23 /*
24  * the caller of __cpcmd has to ensure that the response buffer is below 2 GB
25  */
26 int  __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
27 {
28         unsigned long flags, cmdlen;
29         int return_code, return_len;
30
31         spin_lock_irqsave(&cpcmd_lock, flags);
32         cmdlen = strlen(cmd);
33         BUG_ON(cmdlen > 240);
34         memcpy(cpcmd_buf, cmd, cmdlen);
35         ASCEBC(cpcmd_buf, cmdlen);
36
37         if (response != NULL && rlen > 0) {
38                 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
39                 register unsigned long reg3 asm ("3") = (addr_t) response;
40                 register unsigned long reg4 asm ("4") = cmdlen | 0x40000000L;
41                 register unsigned long reg5 asm ("5") = rlen;
42
43                 memset(response, 0, rlen);
44                 asm volatile(
45 #ifndef CONFIG_64BIT
46                         "       diag    %2,%0,0x8\n"
47                         "       brc     8,1f\n"
48                         "       ar      %1,%4\n"
49 #else /* CONFIG_64BIT */
50                         "       sam31\n"
51                         "       diag    %2,%0,0x8\n"
52                         "       sam64\n"
53                         "       brc     8,1f\n"
54                         "       agr     %1,%4\n"
55 #endif /* CONFIG_64BIT */
56                         "1:\n"
57                         : "+d" (reg4), "+d" (reg5)
58                         : "d" (reg2), "d" (reg3), "d" (rlen) : "cc");
59                 return_code = (int) reg4;
60                 return_len = (int) reg5;
61                 EBCASC(response, rlen);
62         } else {
63                 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
64                 register unsigned long reg3 asm ("3") = cmdlen;
65                 return_len = 0;
66                 asm volatile(
67 #ifndef CONFIG_64BIT
68                         "       diag    %1,%0,0x8\n"
69 #else /* CONFIG_64BIT */
70                         "       sam31\n"
71                         "       diag    %1,%0,0x8\n"
72                         "       sam64\n"
73 #endif /* CONFIG_64BIT */
74                         : "+d" (reg3) : "d" (reg2) : "cc");
75                 return_code = (int) reg3;
76         }
77         spin_unlock_irqrestore(&cpcmd_lock, flags);
78         if (response_code != NULL)
79                 *response_code = return_code;
80         return return_len;
81 }
82
83 EXPORT_SYMBOL(__cpcmd);
84
85 #ifdef CONFIG_64BIT
86 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
87 {
88         char *lowbuf;
89         int len;
90
91         if ((rlen == 0) || (response == NULL)
92             || !((unsigned long)response >> 31))
93                 len = __cpcmd(cmd, response, rlen, response_code);
94         else {
95                 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
96                 if (!lowbuf) {
97                         printk(KERN_WARNING
98                                 "cpcmd: could not allocate response buffer\n");
99                         return -ENOMEM;
100                 }
101                 len = __cpcmd(cmd, lowbuf, rlen, response_code);
102                 memcpy(response, lowbuf, rlen);
103                 kfree(lowbuf);
104         }
105         return len;
106 }
107
108 EXPORT_SYMBOL(cpcmd);
109 #endif          /* CONFIG_64BIT */