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>
21 static DEFINE_SPINLOCK(cpcmd_lock);
22 static char cpcmd_buf[241];
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
29 int __cpcmd(const char *cmd, char *response, int rlen, int *response_code)
32 int return_code, return_len;
36 memcpy(cpcmd_buf, cmd, cmdlen);
37 ASCEBC(cpcmd_buf, cmdlen);
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;
45 memset(response, 0, rlen);
51 #else /* CONFIG_64BIT */
57 #endif /* CONFIG_64BIT */
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);
65 register unsigned long reg2 asm ("2") = (addr_t) cpcmd_buf;
66 register unsigned long reg3 asm ("3") = cmdlen;
71 #else /* CONFIG_64BIT */
75 #endif /* CONFIG_64BIT */
76 : "+d" (reg3) : "d" (reg2) : "cc");
77 return_code = (int) reg3;
79 if (response_code != NULL)
80 *response_code = return_code;
84 EXPORT_SYMBOL(__cpcmd);
86 int cpcmd(const char *cmd, char *response, int rlen, int *response_code)
92 if ((virt_to_phys(response) != (unsigned long) response) ||
93 (((unsigned long)response + rlen) >> 31)) {
94 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
97 "cpcmd: could not allocate response buffer\n");
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);
106 spin_lock_irqsave(&cpcmd_lock, flags);
107 len = __cpcmd(cmd, response, rlen, response_code);
108 spin_unlock_irqrestore(&cpcmd_lock, flags);
113 EXPORT_SYMBOL(cpcmd);