cpcmd.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * Christian Borntraeger (cborntra@de.ibm.com),
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/stddef.h>
  14. #include <linux/string.h>
  15. #include <asm/ebcdic.h>
  16. #include <asm/cpcmd.h>
  17. #include <asm/system.h>
  18. static DEFINE_SPINLOCK(cpcmd_lock);
  19. static char cpcmd_buf[240];
  20. /*
  21. * the caller of __cpcmd has to ensure that the response buffer is below 2 GB
  22. */
  23. void __cpcmd(char *cmd, char *response, int rlen)
  24. {
  25. const int mask = 0x40000000L;
  26. unsigned long flags;
  27. int cmdlen;
  28. spin_lock_irqsave(&cpcmd_lock, flags);
  29. cmdlen = strlen(cmd);
  30. BUG_ON(cmdlen > 240);
  31. strcpy(cpcmd_buf, cmd);
  32. ASCEBC(cpcmd_buf, cmdlen);
  33. if (response != NULL && rlen > 0) {
  34. memset(response, 0, rlen);
  35. #ifndef CONFIG_ARCH_S390X
  36. asm volatile ("LRA 2,0(%0)\n\t"
  37. "LR 4,%1\n\t"
  38. "O 4,%4\n\t"
  39. "LRA 3,0(%2)\n\t"
  40. "LR 5,%3\n\t"
  41. ".long 0x83240008 # Diagnose X'08'\n\t"
  42. : /* no output */
  43. : "a" (cpcmd_buf), "d" (cmdlen),
  44. "a" (response), "d" (rlen), "m" (mask)
  45. : "cc", "2", "3", "4", "5" );
  46. #else /* CONFIG_ARCH_S390X */
  47. asm volatile (" lrag 2,0(%0)\n"
  48. " lgr 4,%1\n"
  49. " o 4,%4\n"
  50. " lrag 3,0(%2)\n"
  51. " lgr 5,%3\n"
  52. " sam31\n"
  53. " .long 0x83240008 # Diagnose X'08'\n"
  54. " sam64"
  55. : /* no output */
  56. : "a" (cpcmd_buf), "d" (cmdlen),
  57. "a" (response), "d" (rlen), "m" (mask)
  58. : "cc", "2", "3", "4", "5" );
  59. #endif /* CONFIG_ARCH_S390X */
  60. EBCASC(response, rlen);
  61. } else {
  62. #ifndef CONFIG_ARCH_S390X
  63. asm volatile ("LRA 2,0(%0)\n\t"
  64. "LR 3,%1\n\t"
  65. ".long 0x83230008 # Diagnose X'08'\n\t"
  66. : /* no output */
  67. : "a" (cpcmd_buf), "d" (cmdlen)
  68. : "2", "3" );
  69. #else /* CONFIG_ARCH_S390X */
  70. asm volatile (" lrag 2,0(%0)\n"
  71. " lgr 3,%1\n"
  72. " sam31\n"
  73. " .long 0x83230008 # Diagnose X'08'\n"
  74. " sam64"
  75. : /* no output */
  76. : "a" (cpcmd_buf), "d" (cmdlen)
  77. : "2", "3" );
  78. #endif /* CONFIG_ARCH_S390X */
  79. }
  80. spin_unlock_irqrestore(&cpcmd_lock, flags);
  81. }
  82. EXPORT_SYMBOL(__cpcmd);
  83. #ifdef CONFIG_ARCH_S390X
  84. void cpcmd(char *cmd, char *response, int rlen)
  85. {
  86. char *lowbuf;
  87. if ((rlen == 0) || (response == NULL)
  88. || !((unsigned long)response >> 31))
  89. __cpcmd(cmd, response, rlen);
  90. else {
  91. lowbuf = kmalloc(rlen, GFP_KERNEL | GFP_DMA);
  92. if (!lowbuf) {
  93. printk(KERN_WARNING
  94. "cpcmd: could not allocate response buffer\n");
  95. return;
  96. }
  97. __cpcmd(cmd, lowbuf, rlen);
  98. memcpy(response, lowbuf, rlen);
  99. kfree(lowbuf);
  100. }
  101. }
  102. EXPORT_SYMBOL(cpcmd);
  103. #endif /* CONFIG_ARCH_S390X */