icswx.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * ICSWX api
  3. *
  4. * Copyright (C) 2015 IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * This provides the Initiate Coprocessor Store Word Indexed (ICSWX)
  12. * instruction. This instruction is used to communicate with PowerPC
  13. * coprocessors. This also provides definitions of the structures used
  14. * to communicate with the coprocessor.
  15. *
  16. * The RFC02130: Coprocessor Architecture document is the reference for
  17. * everything in this file unless otherwise noted.
  18. */
  19. #ifndef _ARCH_POWERPC_INCLUDE_ASM_ICSWX_H_
  20. #define _ARCH_POWERPC_INCLUDE_ASM_ICSWX_H_
  21. #include <asm/ppc-opcode.h> /* for PPC_ICSWX */
  22. /* Chapter 6.5.8 Coprocessor-Completion Block (CCB) */
  23. #define CCB_VALUE (0x3fffffffffffffff)
  24. #define CCB_ADDRESS (0xfffffffffffffff8)
  25. #define CCB_CM (0x0000000000000007)
  26. #define CCB_CM0 (0x0000000000000004)
  27. #define CCB_CM12 (0x0000000000000003)
  28. #define CCB_CM0_ALL_COMPLETIONS (0x0)
  29. #define CCB_CM0_LAST_IN_CHAIN (0x4)
  30. #define CCB_CM12_STORE (0x0)
  31. #define CCB_CM12_INTERRUPT (0x1)
  32. #define CCB_SIZE (0x10)
  33. #define CCB_ALIGN CCB_SIZE
  34. struct coprocessor_completion_block {
  35. __be64 value;
  36. __be64 address;
  37. } __packed __aligned(CCB_ALIGN);
  38. /* Chapter 6.5.7 Coprocessor-Status Block (CSB) */
  39. #define CSB_V (0x80)
  40. #define CSB_F (0x04)
  41. #define CSB_CH (0x03)
  42. #define CSB_CE_INCOMPLETE (0x80)
  43. #define CSB_CE_TERMINATION (0x40)
  44. #define CSB_CE_TPBC (0x20)
  45. #define CSB_CC_SUCCESS (0)
  46. #define CSB_CC_INVALID_ALIGN (1)
  47. #define CSB_CC_OPERAND_OVERLAP (2)
  48. #define CSB_CC_DATA_LENGTH (3)
  49. #define CSB_CC_TRANSLATION (5)
  50. #define CSB_CC_PROTECTION (6)
  51. #define CSB_CC_RD_EXTERNAL (7)
  52. #define CSB_CC_INVALID_OPERAND (8)
  53. #define CSB_CC_PRIVILEGE (9)
  54. #define CSB_CC_INTERNAL (10)
  55. #define CSB_CC_WR_EXTERNAL (12)
  56. #define CSB_CC_NOSPC (13)
  57. #define CSB_CC_EXCESSIVE_DDE (14)
  58. #define CSB_CC_WR_TRANSLATION (15)
  59. #define CSB_CC_WR_PROTECTION (16)
  60. #define CSB_CC_UNKNOWN_CODE (17)
  61. #define CSB_CC_ABORT (18)
  62. #define CSB_CC_TRANSPORT (20)
  63. #define CSB_CC_SEGMENTED_DDL (31)
  64. #define CSB_CC_PROGRESS_POINT (32)
  65. #define CSB_CC_DDE_OVERFLOW (33)
  66. #define CSB_CC_SESSION (34)
  67. #define CSB_CC_PROVISION (36)
  68. #define CSB_CC_CHAIN (37)
  69. #define CSB_CC_SEQUENCE (38)
  70. #define CSB_CC_HW (39)
  71. #define CSB_SIZE (0x10)
  72. #define CSB_ALIGN CSB_SIZE
  73. struct coprocessor_status_block {
  74. u8 flags;
  75. u8 cs;
  76. u8 cc;
  77. u8 ce;
  78. __be32 count;
  79. __be64 address;
  80. } __packed __aligned(CSB_ALIGN);
  81. /* Chapter 6.5.10 Data-Descriptor List (DDL)
  82. * each list contains one or more Data-Descriptor Entries (DDE)
  83. */
  84. #define DDE_P (0x8000)
  85. #define DDE_SIZE (0x10)
  86. #define DDE_ALIGN DDE_SIZE
  87. struct data_descriptor_entry {
  88. __be16 flags;
  89. u8 count;
  90. u8 index;
  91. __be32 length;
  92. __be64 address;
  93. } __packed __aligned(DDE_ALIGN);
  94. /* Chapter 6.5.2 Coprocessor-Request Block (CRB) */
  95. #define CRB_SIZE (0x80)
  96. #define CRB_ALIGN (0x100) /* Errata: requires 256 alignment */
  97. /* Coprocessor Status Block field
  98. * ADDRESS address of CSB
  99. * C CCB is valid
  100. * AT 0 = addrs are virtual, 1 = addrs are phys
  101. * M enable perf monitor
  102. */
  103. #define CRB_CSB_ADDRESS (0xfffffffffffffff0)
  104. #define CRB_CSB_C (0x0000000000000008)
  105. #define CRB_CSB_AT (0x0000000000000002)
  106. #define CRB_CSB_M (0x0000000000000001)
  107. struct coprocessor_request_block {
  108. __be32 ccw;
  109. __be32 flags;
  110. __be64 csb_addr;
  111. struct data_descriptor_entry source;
  112. struct data_descriptor_entry target;
  113. struct coprocessor_completion_block ccb;
  114. u8 reserved[48];
  115. struct coprocessor_status_block csb;
  116. } __packed __aligned(CRB_ALIGN);
  117. /* RFC02167 Initiate Coprocessor Instructions document
  118. * Chapter 8.2.1.1.1 RS
  119. * Chapter 8.2.3 Coprocessor Directive
  120. * Chapter 8.2.4 Execution
  121. *
  122. * The CCW must be converted to BE before passing to icswx()
  123. */
  124. #define CCW_PS (0xff000000)
  125. #define CCW_CT (0x00ff0000)
  126. #define CCW_CD (0x0000ffff)
  127. #define CCW_CL (0x0000c000)
  128. /* RFC02167 Initiate Coprocessor Instructions document
  129. * Chapter 8.2.1 Initiate Coprocessor Store Word Indexed (ICSWX)
  130. * Chapter 8.2.4.1 Condition Register 0
  131. */
  132. #define ICSWX_INITIATED (0x8)
  133. #define ICSWX_BUSY (0x4)
  134. #define ICSWX_REJECTED (0x2)
  135. #define ICSWX_XERS0 (0x1) /* undefined or set from XERSO. */
  136. static inline int icswx(__be32 ccw, struct coprocessor_request_block *crb)
  137. {
  138. __be64 ccw_reg = ccw;
  139. u32 cr;
  140. __asm__ __volatile__(
  141. PPC_ICSWX(%1,0,%2) "\n"
  142. "mfcr %0\n"
  143. : "=r" (cr)
  144. : "r" (ccw_reg), "r" (crb)
  145. : "cr0", "memory");
  146. return (int)((cr >> 28) & 0xf);
  147. }
  148. #endif /* _ARCH_POWERPC_INCLUDE_ASM_ICSWX_H_ */