diff options
Diffstat (limited to 'arch/s390/kernel/cpcmd.c')
-rw-r--r-- | arch/s390/kernel/cpcmd.c | 109 |
1 files changed, 65 insertions, 44 deletions
diff --git a/arch/s390/kernel/cpcmd.c b/arch/s390/kernel/cpcmd.c index 44df8dc07c59..20062145e84e 100644 --- a/arch/s390/kernel/cpcmd.c +++ b/arch/s390/kernel/cpcmd.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * arch/s390/kernel/cpcmd.c | 2 | * arch/s390/kernel/cpcmd.c |
3 | * | 3 | * |
4 | * S390 version | 4 | * S390 version |
5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation | 5 | * Copyright (C) 1999,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation |
6 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), | 6 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), |
7 | * Christian Borntraeger (cborntra@de.ibm.com), | 7 | * Christian Borntraeger (cborntra@de.ibm.com), |
8 | */ | 8 | */ |
@@ -18,93 +18,114 @@ | |||
18 | #include <asm/system.h> | 18 | #include <asm/system.h> |
19 | 19 | ||
20 | static DEFINE_SPINLOCK(cpcmd_lock); | 20 | static DEFINE_SPINLOCK(cpcmd_lock); |
21 | static char cpcmd_buf[240]; | 21 | static char cpcmd_buf[241]; |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * the caller of __cpcmd has to ensure that the response buffer is below 2 GB | 24 | * the caller of __cpcmd has to ensure that the response buffer is below 2 GB |
25 | */ | 25 | */ |
26 | void __cpcmd(char *cmd, char *response, int rlen) | 26 | int __cpcmd(const char *cmd, char *response, int rlen, int *response_code) |
27 | { | 27 | { |
28 | const int mask = 0x40000000L; | 28 | const int mask = 0x40000000L; |
29 | unsigned long flags; | 29 | unsigned long flags; |
30 | int return_code; | ||
31 | int return_len; | ||
30 | int cmdlen; | 32 | int cmdlen; |
31 | 33 | ||
32 | spin_lock_irqsave(&cpcmd_lock, flags); | 34 | spin_lock_irqsave(&cpcmd_lock, flags); |
33 | cmdlen = strlen(cmd); | 35 | cmdlen = strlen(cmd); |
34 | BUG_ON(cmdlen > 240); | 36 | BUG_ON(cmdlen > 240); |
35 | strcpy(cpcmd_buf, cmd); | 37 | memcpy(cpcmd_buf, cmd, cmdlen); |
36 | ASCEBC(cpcmd_buf, cmdlen); | 38 | ASCEBC(cpcmd_buf, cmdlen); |
37 | 39 | ||
38 | if (response != NULL && rlen > 0) { | 40 | if (response != NULL && rlen > 0) { |
39 | memset(response, 0, rlen); | 41 | memset(response, 0, rlen); |
40 | #ifndef CONFIG_ARCH_S390X | 42 | #ifndef CONFIG_ARCH_S390X |
41 | asm volatile ("LRA 2,0(%0)\n\t" | 43 | asm volatile ( "lra 2,0(%2)\n" |
42 | "LR 4,%1\n\t" | 44 | "lr 4,%3\n" |
43 | "O 4,%4\n\t" | 45 | "o 4,%6\n" |
44 | "LRA 3,0(%2)\n\t" | 46 | "lra 3,0(%4)\n" |
45 | "LR 5,%3\n\t" | 47 | "lr 5,%5\n" |
46 | ".long 0x83240008 # Diagnose X'08'\n\t" | 48 | "diag 2,4,0x8\n" |
47 | : /* no output */ | 49 | "brc 8, .Litfits\n" |
48 | : "a" (cpcmd_buf), "d" (cmdlen), | 50 | "ar 5, %5\n" |
49 | "a" (response), "d" (rlen), "m" (mask) | 51 | ".Litfits: \n" |
50 | : "cc", "2", "3", "4", "5" ); | 52 | "lr %0,4\n" |
53 | "lr %1,5\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" ); | ||
51 | #else /* CONFIG_ARCH_S390X */ | 58 | #else /* CONFIG_ARCH_S390X */ |
52 | asm volatile (" lrag 2,0(%0)\n" | 59 | asm volatile ( "lrag 2,0(%2)\n" |
53 | " lgr 4,%1\n" | 60 | "lgr 4,%3\n" |
54 | " o 4,%4\n" | 61 | "o 4,%6\n" |
55 | " lrag 3,0(%2)\n" | 62 | "lrag 3,0(%4)\n" |
56 | " lgr 5,%3\n" | 63 | "lgr 5,%5\n" |
57 | " sam31\n" | 64 | "sam31\n" |
58 | " .long 0x83240008 # Diagnose X'08'\n" | 65 | "diag 2,4,0x8\n" |
59 | " sam64" | 66 | "sam64\n" |
60 | : /* no output */ | 67 | "brc 8, .Litfits\n" |
61 | : "a" (cpcmd_buf), "d" (cmdlen), | 68 | "agr 5, %5\n" |
62 | "a" (response), "d" (rlen), "m" (mask) | 69 | ".Litfits: \n" |
63 | : "cc", "2", "3", "4", "5" ); | 70 | "lgr %0,4\n" |
71 | "lgr %1,5\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" ); | ||
64 | #endif /* CONFIG_ARCH_S390X */ | 76 | #endif /* CONFIG_ARCH_S390X */ |
65 | EBCASC(response, rlen); | 77 | EBCASC(response, rlen); |
66 | } else { | 78 | } else { |
79 | return_len = 0; | ||
67 | #ifndef CONFIG_ARCH_S390X | 80 | #ifndef CONFIG_ARCH_S390X |
68 | asm volatile ("LRA 2,0(%0)\n\t" | 81 | asm volatile ( "lra 2,0(%1)\n" |
69 | "LR 3,%1\n\t" | 82 | "lr 3,%2\n" |
70 | ".long 0x83230008 # Diagnose X'08'\n\t" | 83 | "diag 2,3,0x8\n" |
71 | : /* no output */ | 84 | "lr %0,3\n" |
72 | : "a" (cpcmd_buf), "d" (cmdlen) | 85 | : "=d" (return_code) |
73 | : "2", "3" ); | 86 | : "a" (cpcmd_buf), "d" (cmdlen) |
87 | : "2", "3" ); | ||
74 | #else /* CONFIG_ARCH_S390X */ | 88 | #else /* CONFIG_ARCH_S390X */ |
75 | asm volatile (" lrag 2,0(%0)\n" | 89 | asm volatile ( "lrag 2,0(%1)\n" |
76 | " lgr 3,%1\n" | 90 | "lgr 3,%2\n" |
77 | " sam31\n" | 91 | "sam31\n" |
78 | " .long 0x83230008 # Diagnose X'08'\n" | 92 | "diag 2,3,0x8\n" |
79 | " sam64" | 93 | "sam64\n" |
80 | : /* no output */ | 94 | "lgr %0,3\n" |
81 | : "a" (cpcmd_buf), "d" (cmdlen) | 95 | : "=d" (return_code) |
82 | : "2", "3" ); | 96 | : "a" (cpcmd_buf), "d" (cmdlen) |
97 | : "2", "3" ); | ||
83 | #endif /* CONFIG_ARCH_S390X */ | 98 | #endif /* CONFIG_ARCH_S390X */ |
84 | } | 99 | } |
85 | spin_unlock_irqrestore(&cpcmd_lock, flags); | 100 | spin_unlock_irqrestore(&cpcmd_lock, flags); |
101 | if (response_code != NULL) | ||
102 | *response_code = return_code; | ||
103 | return return_len; | ||
86 | } | 104 | } |
87 | 105 | ||
88 | EXPORT_SYMBOL(__cpcmd); | 106 | EXPORT_SYMBOL(__cpcmd); |
89 | 107 | ||
90 | #ifdef CONFIG_ARCH_S390X | 108 | #ifdef CONFIG_ARCH_S390X |
91 | void cpcmd(char *cmd, char *response, int rlen) | 109 | int cpcmd(const char *cmd, char *response, int rlen, int *response_code) |
92 | { | 110 | { |
93 | char *lowbuf; | 111 | char *lowbuf; |
112 | int len; | ||
113 | |||
94 | if ((rlen == 0) || (response == NULL) | 114 | if ((rlen == 0) || (response == NULL) |
95 | || !((unsigned long)response >> 31)) | 115 | || !((unsigned long)response >> 31)) |
96 | __cpcmd(cmd, response, rlen); | 116 | len = __cpcmd(cmd, response, rlen, response_code); |
97 | else { | 117 | else { |
98 | lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA); | 118 | lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA); |
99 | if (!lowbuf) { | 119 | if (!lowbuf) { |
100 | printk(KERN_WARNING | 120 | printk(KERN_WARNING |
101 | "cpcmd: could not allocate response buffer\n"); | 121 | "cpcmd: could not allocate response buffer\n"); |
102 | return; | 122 | return -ENOMEM; |
103 | } | 123 | } |
104 | __cpcmd(cmd, lowbuf, rlen); | 124 | len = __cpcmd(cmd, lowbuf, rlen, response_code); |
105 | memcpy(response, lowbuf, rlen); | 125 | memcpy(response, lowbuf, rlen); |
106 | kfree(lowbuf); | 126 | kfree(lowbuf); |
107 | } | 127 | } |
128 | return len; | ||
108 | } | 129 | } |
109 | 130 | ||
110 | EXPORT_SYMBOL(cpcmd); | 131 | EXPORT_SYMBOL(cpcmd); |