2 * arch/s390/kernel/cpcmd.c
5 * Copyright (C) 1999,2000 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[240];
24 * the caller of __cpcmd has to ensure that the response buffer is below 2 GB
26 void __cpcmd(char *cmd, char *response, int rlen)
28 const int mask = 0x40000000L;
32 spin_lock_irqsave(&cpcmd_lock, flags);
35 strcpy(cpcmd_buf, cmd);
36 ASCEBC(cpcmd_buf, cmdlen);
38 if (response != NULL && rlen > 0) {
39 memset(response, 0, rlen);
40 #ifndef CONFIG_ARCH_S390X
41 asm volatile ("LRA 2,0(%0)\n\t"
46 ".long 0x83240008 # Diagnose X'08'\n\t"
48 : "a" (cpcmd_buf), "d" (cmdlen),
49 "a" (response), "d" (rlen), "m" (mask)
50 : "cc", "2", "3", "4", "5" );
51 #else /* CONFIG_ARCH_S390X */
52 asm volatile (" lrag 2,0(%0)\n"
58 " .long 0x83240008 # Diagnose X'08'\n"
61 : "a" (cpcmd_buf), "d" (cmdlen),
62 "a" (response), "d" (rlen), "m" (mask)
63 : "cc", "2", "3", "4", "5" );
64 #endif /* CONFIG_ARCH_S390X */
65 EBCASC(response, rlen);
67 #ifndef CONFIG_ARCH_S390X
68 asm volatile ("LRA 2,0(%0)\n\t"
70 ".long 0x83230008 # Diagnose X'08'\n\t"
72 : "a" (cpcmd_buf), "d" (cmdlen)
74 #else /* CONFIG_ARCH_S390X */
75 asm volatile (" lrag 2,0(%0)\n"
78 " .long 0x83230008 # Diagnose X'08'\n"
81 : "a" (cpcmd_buf), "d" (cmdlen)
83 #endif /* CONFIG_ARCH_S390X */
85 spin_unlock_irqrestore(&cpcmd_lock, flags);
88 EXPORT_SYMBOL(__cpcmd);
90 #ifdef CONFIG_ARCH_S390X
91 void cpcmd(char *cmd, char *response, int rlen)
94 if ((rlen == 0) || (response == NULL)
95 || !((unsigned long)response >> 31))
96 __cpcmd(cmd, response, rlen);
98 lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
101 "cpcmd: could not allocate response buffer\n");
104 __cpcmd(cmd, lowbuf, rlen);
105 memcpy(response, lowbuf, rlen);
110 EXPORT_SYMBOL(cpcmd);
111 #endif /* CONFIG_ARCH_S390X */