2 * arch/s390/kernel/cpcmd.c
5 * Copyright IBM Corp. 1999,2007
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Christian Borntraeger (cborntra@de.ibm.com),
10 #define KMSG_COMPONENT "cpcmd"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/spinlock.h>
17 #include <linux/stddef.h>
18 #include <linux/string.h>
19 #include <asm/ebcdic.h>
20 #include <asm/cpcmd.h>
21 #include <asm/system.h>
24 static DEFINE_SPINLOCK(cpcmd_lock
);
25 static char cpcmd_buf
[241];
27 static int diag8_noresponse(int cmdlen
)
29 register unsigned long reg2
asm ("2") = (addr_t
) cpcmd_buf
;
30 register unsigned long reg3
asm ("3") = cmdlen
;
35 #else /* CONFIG_64BIT */
39 #endif /* CONFIG_64BIT */
40 : "+d" (reg3
) : "d" (reg2
) : "cc");
44 static int diag8_response(int cmdlen
, char *response
, int *rlen
)
46 register unsigned long reg2
asm ("2") = (addr_t
) cpcmd_buf
;
47 register unsigned long reg3
asm ("3") = (addr_t
) response
;
48 register unsigned long reg4
asm ("4") = cmdlen
| 0x40000000L
;
49 register unsigned long reg5
asm ("5") = *rlen
;
56 #else /* CONFIG_64BIT */
62 #endif /* CONFIG_64BIT */
64 : "+d" (reg4
), "+d" (reg5
)
65 : "d" (reg2
), "d" (reg3
), "d" (*rlen
) : "cc");
71 * __cpcmd has some restrictions over cpcmd
72 * - the response buffer must reside below 2GB (if any)
73 * - __cpcmd is unlocked and therefore not SMP-safe
75 int __cpcmd(const char *cmd
, char *response
, int rlen
, int *response_code
)
83 memcpy(cpcmd_buf
, cmd
, cmdlen
);
84 ASCEBC(cpcmd_buf
, cmdlen
);
87 memset(response
, 0, rlen
);
89 rc
= diag8_response(cmdlen
, response
, &rlen
);
90 EBCASC(response
, response_len
);
92 rc
= diag8_noresponse(cmdlen
);
98 EXPORT_SYMBOL(__cpcmd
);
100 int cpcmd(const char *cmd
, char *response
, int rlen
, int *response_code
)
106 if ((virt_to_phys(response
) != (unsigned long) response
) ||
107 (((unsigned long)response
+ rlen
) >> 31)) {
108 lowbuf
= kmalloc(rlen
, GFP_KERNEL
| GFP_DMA
);
110 pr_warning("The cpcmd kernel function failed to "
111 "allocate a response buffer\n");
114 spin_lock_irqsave(&cpcmd_lock
, flags
);
115 len
= __cpcmd(cmd
, lowbuf
, rlen
, response_code
);
116 spin_unlock_irqrestore(&cpcmd_lock
, flags
);
117 memcpy(response
, lowbuf
, rlen
);
120 spin_lock_irqsave(&cpcmd_lock
, flags
);
121 len
= __cpcmd(cmd
, response
, rlen
, response_code
);
122 spin_unlock_irqrestore(&cpcmd_lock
, flags
);
126 EXPORT_SYMBOL(cpcmd
);