icswx.h 5.0 KB

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