2 * arch/s390/kernel/cpcmd.c
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),
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>
20 static DEFINE_SPINLOCK(cpcmd_lock);
21 static char cpcmd_buf[241];
24 * the caller of __cpcmd has to ensure that the response buffer is below 2 GB
26 int __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
28 unsigned long flags, cmdlen;
29 int return_code, return_len;
31 spin_lock_irqsave(&cpcmd_lock, flags);
34 memcpy(cpcmd_buf, cmd, cmdlen);
35 ASCEBC(cpcmd_buf, cmdlen);
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;
43 memset(response, 0, rlen);
49 #else /* CONFIG_64BIT */
55 #endif /* CONFIG_64BIT */
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);
63 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
64 register unsigned long reg3 asm ("3") = cmdlen;
69 #else /* CONFIG_64BIT */
73 #endif /* CONFIG_64BIT */
74 : "+d" (reg3) : "d" (reg2) : "cc");
75 return_code = (int) reg3;
77 spin_unlock_irqrestore(&cpcmd_lock, flags);
78 if (response_code != NULL)
79 *response_code = return_code;
83 EXPORT_SYMBOL(__cpcmd);
86 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
91 if ((rlen == 0) || (response == NULL)
92 || !((unsigned long)response >> 31))
93 len = __cpcmd(cmd, response, rlen, response_code);
95 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
98 "cpcmd: could not allocate response buffer\n");
101 len = __cpcmd(cmd, lowbuf, rlen, response_code);
102 memcpy(response, lowbuf, rlen);
108 EXPORT_SYMBOL(cpcmd);
109 #endif /* CONFIG_64BIT */