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 * __cpcmd has some restrictions over cpcmd
25 * - the response buffer must reside below 2GB (if any)
26 * - __cpcmd is unlocked and therefore not SMP-safe
28 int __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
31 int return_code, return_len;
35 memcpy(cpcmd_buf, cmd, cmdlen);
36 ASCEBC(cpcmd_buf, cmdlen);
38 if (response != NULL && rlen > 0) {
39 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
40 register unsigned long reg3 asm ("3") = (addr_t) response;
41 register unsigned long reg4 asm ("4") = cmdlen | 0x40000000L;
42 register unsigned long reg5 asm ("5") = rlen;
44 memset(response, 0, rlen);
50 #else /* CONFIG_64BIT */
56 #endif /* CONFIG_64BIT */
58 : "+d" (reg4), "+d" (reg5)
59 : "d" (reg2), "d" (reg3), "d" (rlen) : "cc");
60 return_code = (int) reg4;
61 return_len = (int) reg5;
62 EBCASC(response, rlen);
64 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
65 register unsigned long reg3 asm ("3") = cmdlen;
70 #else /* CONFIG_64BIT */
74 #endif /* CONFIG_64BIT */
75 : "+d" (reg3) : "d" (reg2) : "cc");
76 return_code = (int) reg3;
78 if (response_code != NULL)
79 *response_code = return_code;
83 EXPORT_SYMBOL(__cpcmd);
85 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
91 if ((rlen == 0) || (response == NULL)
92 || !((unsigned long)response >> 31)) {
93 spin_lock_irqsave(&cpcmd_lock, flags);
94 len = __cpcmd(cmd, response, rlen, response_code);
95 spin_unlock_irqrestore(&cpcmd_lock, flags);
98 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
101 "cpcmd: could not allocate response buffer\n");
104 spin_lock_irqsave(&cpcmd_lock, flags);
105 len = __cpcmd(cmd, lowbuf, rlen, response_code);
106 spin_unlock_irqrestore(&cpcmd_lock, flags);
107 memcpy(response, lowbuf, rlen);
113 EXPORT_SYMBOL(cpcmd);