pci_dma.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef _ASM_S390_PCI_DMA_H
  2. #define _ASM_S390_PCI_DMA_H
  3. /* I/O Translation Anchor (IOTA) */
  4. enum zpci_ioat_dtype {
  5. ZPCI_IOTA_STO = 0,
  6. ZPCI_IOTA_RTTO = 1,
  7. ZPCI_IOTA_RSTO = 2,
  8. ZPCI_IOTA_RFTO = 3,
  9. ZPCI_IOTA_PFAA = 4,
  10. ZPCI_IOTA_IOPFAA = 5,
  11. ZPCI_IOTA_IOPTO = 7
  12. };
  13. #define ZPCI_IOTA_IOT_ENABLED 0x800UL
  14. #define ZPCI_IOTA_DT_ST (ZPCI_IOTA_STO << 2)
  15. #define ZPCI_IOTA_DT_RT (ZPCI_IOTA_RTTO << 2)
  16. #define ZPCI_IOTA_DT_RS (ZPCI_IOTA_RSTO << 2)
  17. #define ZPCI_IOTA_DT_RF (ZPCI_IOTA_RFTO << 2)
  18. #define ZPCI_IOTA_DT_PF (ZPCI_IOTA_PFAA << 2)
  19. #define ZPCI_IOTA_FS_4K 0
  20. #define ZPCI_IOTA_FS_1M 1
  21. #define ZPCI_IOTA_FS_2G 2
  22. #define ZPCI_KEY (PAGE_DEFAULT_KEY << 5)
  23. #define ZPCI_TABLE_SIZE_RT (1UL << 42)
  24. #define ZPCI_IOTA_STO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST)
  25. #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT)
  26. #define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS)
  27. #define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF)
  28. #define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G)
  29. /* I/O Region and segment tables */
  30. #define ZPCI_INDEX_MASK 0x7ffUL
  31. #define ZPCI_TABLE_TYPE_MASK 0xc
  32. #define ZPCI_TABLE_TYPE_RFX 0xc
  33. #define ZPCI_TABLE_TYPE_RSX 0x8
  34. #define ZPCI_TABLE_TYPE_RTX 0x4
  35. #define ZPCI_TABLE_TYPE_SX 0x0
  36. #define ZPCI_TABLE_LEN_RFX 0x3
  37. #define ZPCI_TABLE_LEN_RSX 0x3
  38. #define ZPCI_TABLE_LEN_RTX 0x3
  39. #define ZPCI_TABLE_OFFSET_MASK 0xc0
  40. #define ZPCI_TABLE_SIZE 0x4000
  41. #define ZPCI_TABLE_ALIGN ZPCI_TABLE_SIZE
  42. #define ZPCI_TABLE_ENTRY_SIZE (sizeof(unsigned long))
  43. #define ZPCI_TABLE_ENTRIES (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
  44. #define ZPCI_TABLE_BITS 11
  45. #define ZPCI_PT_BITS 8
  46. #define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT)
  47. #define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS)
  48. #define ZPCI_RTE_FLAG_MASK 0x3fffUL
  49. #define ZPCI_RTE_ADDR_MASK (~ZPCI_RTE_FLAG_MASK)
  50. #define ZPCI_STE_FLAG_MASK 0x7ffUL
  51. #define ZPCI_STE_ADDR_MASK (~ZPCI_STE_FLAG_MASK)
  52. /* I/O Page tables */
  53. #define ZPCI_PTE_VALID_MASK 0x400
  54. #define ZPCI_PTE_INVALID 0x400
  55. #define ZPCI_PTE_VALID 0x000
  56. #define ZPCI_PT_SIZE 0x800
  57. #define ZPCI_PT_ALIGN ZPCI_PT_SIZE
  58. #define ZPCI_PT_ENTRIES (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE)
  59. #define ZPCI_PT_MASK (ZPCI_PT_ENTRIES - 1)
  60. #define ZPCI_PTE_FLAG_MASK 0xfffUL
  61. #define ZPCI_PTE_ADDR_MASK (~ZPCI_PTE_FLAG_MASK)
  62. /* Shared bits */
  63. #define ZPCI_TABLE_VALID 0x00
  64. #define ZPCI_TABLE_INVALID 0x20
  65. #define ZPCI_TABLE_PROTECTED 0x200
  66. #define ZPCI_TABLE_UNPROTECTED 0x000
  67. #define ZPCI_TABLE_VALID_MASK 0x20
  68. #define ZPCI_TABLE_PROT_MASK 0x200
  69. static inline unsigned int calc_rtx(dma_addr_t ptr)
  70. {
  71. return ((unsigned long) ptr >> ZPCI_RT_SHIFT) & ZPCI_INDEX_MASK;
  72. }
  73. static inline unsigned int calc_sx(dma_addr_t ptr)
  74. {
  75. return ((unsigned long) ptr >> ZPCI_ST_SHIFT) & ZPCI_INDEX_MASK;
  76. }
  77. static inline unsigned int calc_px(dma_addr_t ptr)
  78. {
  79. return ((unsigned long) ptr >> PAGE_SHIFT) & ZPCI_PT_MASK;
  80. }
  81. static inline void set_pt_pfaa(unsigned long *entry, void *pfaa)
  82. {
  83. *entry &= ZPCI_PTE_FLAG_MASK;
  84. *entry |= ((unsigned long) pfaa & ZPCI_PTE_ADDR_MASK);
  85. }
  86. static inline void set_rt_sto(unsigned long *entry, void *sto)
  87. {
  88. *entry &= ZPCI_RTE_FLAG_MASK;
  89. *entry |= ((unsigned long) sto & ZPCI_RTE_ADDR_MASK);
  90. *entry |= ZPCI_TABLE_TYPE_RTX;
  91. }
  92. static inline void set_st_pto(unsigned long *entry, void *pto)
  93. {
  94. *entry &= ZPCI_STE_FLAG_MASK;
  95. *entry |= ((unsigned long) pto & ZPCI_STE_ADDR_MASK);
  96. *entry |= ZPCI_TABLE_TYPE_SX;
  97. }
  98. static inline void validate_rt_entry(unsigned long *entry)
  99. {
  100. *entry &= ~ZPCI_TABLE_VALID_MASK;
  101. *entry &= ~ZPCI_TABLE_OFFSET_MASK;
  102. *entry |= ZPCI_TABLE_VALID;
  103. *entry |= ZPCI_TABLE_LEN_RTX;
  104. }
  105. static inline void validate_st_entry(unsigned long *entry)
  106. {
  107. *entry &= ~ZPCI_TABLE_VALID_MASK;
  108. *entry |= ZPCI_TABLE_VALID;
  109. }
  110. static inline void invalidate_table_entry(unsigned long *entry)
  111. {
  112. *entry &= ~ZPCI_TABLE_VALID_MASK;
  113. *entry |= ZPCI_TABLE_INVALID;
  114. }
  115. static inline void invalidate_pt_entry(unsigned long *entry)
  116. {
  117. WARN_ON_ONCE((*entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_INVALID);
  118. *entry &= ~ZPCI_PTE_VALID_MASK;
  119. *entry |= ZPCI_PTE_INVALID;
  120. }
  121. static inline void validate_pt_entry(unsigned long *entry)
  122. {
  123. WARN_ON_ONCE((*entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID);
  124. *entry &= ~ZPCI_PTE_VALID_MASK;
  125. *entry |= ZPCI_PTE_VALID;
  126. }
  127. static inline void entry_set_protected(unsigned long *entry)
  128. {
  129. *entry &= ~ZPCI_TABLE_PROT_MASK;
  130. *entry |= ZPCI_TABLE_PROTECTED;
  131. }
  132. static inline void entry_clr_protected(unsigned long *entry)
  133. {
  134. *entry &= ~ZPCI_TABLE_PROT_MASK;
  135. *entry |= ZPCI_TABLE_UNPROTECTED;
  136. }
  137. static inline int reg_entry_isvalid(unsigned long entry)
  138. {
  139. return (entry & ZPCI_TABLE_VALID_MASK) == ZPCI_TABLE_VALID;
  140. }
  141. static inline int pt_entry_isvalid(unsigned long entry)
  142. {
  143. return (entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID;
  144. }
  145. static inline int entry_isprotected(unsigned long entry)
  146. {
  147. return (entry & ZPCI_TABLE_PROT_MASK) == ZPCI_TABLE_PROTECTED;
  148. }
  149. static inline unsigned long *get_rt_sto(unsigned long entry)
  150. {
  151. return ((entry & ZPCI_TABLE_TYPE_MASK) == ZPCI_TABLE_TYPE_RTX)
  152. ? (unsigned long *) (entry & ZPCI_RTE_ADDR_MASK)
  153. : NULL;
  154. }
  155. static inline unsigned long *get_st_pto(unsigned long entry)
  156. {
  157. return ((entry & ZPCI_TABLE_TYPE_MASK) == ZPCI_TABLE_TYPE_SX)
  158. ? (unsigned long *) (entry & ZPCI_STE_ADDR_MASK)
  159. : NULL;
  160. }
  161. /* Prototypes */
  162. int zpci_dma_init_device(struct zpci_dev *);
  163. void zpci_dma_exit_device(struct zpci_dev *);
  164. void dma_free_seg_table(unsigned long);
  165. unsigned long *dma_alloc_cpu_table(void);
  166. void dma_cleanup_tables(unsigned long *);
  167. unsigned long *dma_walk_cpu_trans(unsigned long *rto, dma_addr_t dma_addr);
  168. void dma_update_cpu_trans(unsigned long *entry, void *page_addr, int flags);
  169. #endif