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 const int mask = 0x40000000L;
34 spin_lock_irqsave(&cpcmd_lock, flags);
37 memcpy(cpcmd_buf, cmd, cmdlen);
38 ASCEBC(cpcmd_buf, cmdlen);
40 if (response != NULL && rlen > 0) {
41 memset(response, 0, rlen);
43 asm volatile ( "lra 2,0(%2)\n"
54 : "=d" (return_code), "=d" (return_len)
55 : "a" (cpcmd_buf), "d" (cmdlen),
56 "a" (response), "d" (rlen), "m" (mask)
57 : "cc", "2", "3", "4", "5" );
58 #else /* CONFIG_64BIT */
59 asm volatile ( "lrag 2,0(%2)\n"
72 : "=d" (return_code), "=d" (return_len)
73 : "a" (cpcmd_buf), "d" (cmdlen),
74 "a" (response), "d" (rlen), "m" (mask)
75 : "cc", "2", "3", "4", "5" );
76 #endif /* CONFIG_64BIT */
77 EBCASC(response, rlen);
81 asm volatile ( "lra 2,0(%1)\n"
86 : "a" (cpcmd_buf), "d" (cmdlen)
88 #else /* CONFIG_64BIT */
89 asm volatile ( "lrag 2,0(%1)\n"
96 : "a" (cpcmd_buf), "d" (cmdlen)
98 #endif /* CONFIG_64BIT */
100 spin_unlock_irqrestore(&cpcmd_lock, flags);
101 if (response_code != NULL)
102 *response_code = return_code;
106 EXPORT_SYMBOL(__cpcmd);
109 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
114 if ((rlen == 0) || (response == NULL)
115 || !((unsigned long)response >> 31))
116 len = __cpcmd(cmd, response, rlen, response_code);
118 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
121 "cpcmd: could not allocate response buffer\n");
124 len = __cpcmd(cmd, lowbuf, rlen, response_code);
125 memcpy(response, lowbuf, rlen);
131 EXPORT_SYMBOL(cpcmd);
132 #endif /* CONFIG_64BIT */