kernel.org linux-2.6.10
[linux-2.6.git] / arch / s390 / kernel / cpcmd.c
1 /*
2  *  arch/s390/kernel/cpcmd.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7  */
8
9 #include <linux/stddef.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <asm/ebcdic.h>
13 #include <linux/spinlock.h>
14 #include <asm/cpcmd.h>
15 #include <asm/system.h>
16
17 static spinlock_t cpcmd_lock = SPIN_LOCK_UNLOCKED;
18 static char cpcmd_buf[240];
19
20 void cpcmd(char *cmd, char *response, int rlen)
21 {
22         const int mask = 0x40000000L;
23         unsigned long flags;
24         int cmdlen;
25
26         spin_lock_irqsave(&cpcmd_lock, flags);
27         cmdlen = strlen(cmd);
28         BUG_ON(cmdlen>240);
29         strcpy(cpcmd_buf, cmd);
30         ASCEBC(cpcmd_buf, cmdlen);
31
32         if (response != NULL && rlen > 0) {
33 #ifndef CONFIG_ARCH_S390X
34                 asm volatile ("LRA   2,0(%0)\n\t"
35                               "LR    4,%1\n\t"
36                               "O     4,%4\n\t"
37                               "LRA   3,0(%2)\n\t"
38                               "LR    5,%3\n\t"
39                               ".long 0x83240008 # Diagnose X'08'\n\t"
40                               : /* no output */
41                               : "a" (cpcmd_buf), "d" (cmdlen),
42                                 "a" (response), "d" (rlen), "m" (mask)
43                               : "cc", "2", "3", "4", "5" );
44 #else /* CONFIG_ARCH_S390X */
45                 asm volatile ("   lrag  2,0(%0)\n"
46                               "   lgr   4,%1\n"
47                               "   o     4,%4\n"
48                               "   lrag  3,0(%2)\n"
49                               "   lgr   5,%3\n"
50                               "   sam31\n"
51                               "   .long 0x83240008 # Diagnose X'08'\n"
52                               "   sam64"
53                               : /* no output */
54                               : "a" (cpcmd_buf), "d" (cmdlen),
55                                 "a" (response), "d" (rlen), "m" (mask)
56                               : "cc", "2", "3", "4", "5" );
57 #endif /* CONFIG_ARCH_S390X */
58                 EBCASC(response, rlen);
59         } else {
60 #ifndef CONFIG_ARCH_S390X
61                 asm volatile ("LRA   2,0(%0)\n\t"
62                               "LR    3,%1\n\t"
63                               ".long 0x83230008 # Diagnose X'08'\n\t"
64                               : /* no output */
65                               : "a" (cpcmd_buf), "d" (cmdlen)
66                               : "2", "3"  );
67 #else /* CONFIG_ARCH_S390X */
68                 asm volatile ("   lrag  2,0(%0)\n"
69                               "   lgr   3,%1\n"
70                               "   sam31\n"
71                               "   .long 0x83230008 # Diagnose X'08'\n"
72                               "   sam64"
73                               : /* no output */
74                               : "a" (cpcmd_buf), "d" (cmdlen)
75                               : "2", "3"  );
76 #endif /* CONFIG_ARCH_S390X */
77         }
78         spin_unlock_irqrestore(&cpcmd_lock, flags);
79 }
80