1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_PCI_DMA_H
3 #define _ASM_S390_PCI_DMA_H
5 /* I/O Translation Anchor (IOTA) */
16 #define ZPCI_IOTA_IOT_ENABLED 0x800UL
17 #define ZPCI_IOTA_DT_ST (ZPCI_IOTA_STO << 2)
18 #define ZPCI_IOTA_DT_RT (ZPCI_IOTA_RTTO << 2)
19 #define ZPCI_IOTA_DT_RS (ZPCI_IOTA_RSTO << 2)
20 #define ZPCI_IOTA_DT_RF (ZPCI_IOTA_RFTO << 2)
21 #define ZPCI_IOTA_DT_PF (ZPCI_IOTA_PFAA << 2)
22 #define ZPCI_IOTA_FS_4K 0
23 #define ZPCI_IOTA_FS_1M 1
24 #define ZPCI_IOTA_FS_2G 2
25 #define ZPCI_KEY (PAGE_DEFAULT_KEY << 5)
27 #define ZPCI_TABLE_SIZE_RT (1UL << 42)
29 #define ZPCI_IOTA_STO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST)
30 #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT)
31 #define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS)
32 #define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF)
33 #define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G)
35 /* I/O Region and segment tables */
36 #define ZPCI_INDEX_MASK 0x7ffUL
38 #define ZPCI_TABLE_TYPE_MASK 0xc
39 #define ZPCI_TABLE_TYPE_RFX 0xc
40 #define ZPCI_TABLE_TYPE_RSX 0x8
41 #define ZPCI_TABLE_TYPE_RTX 0x4
42 #define ZPCI_TABLE_TYPE_SX 0x0
44 #define ZPCI_TABLE_LEN_RFX 0x3
45 #define ZPCI_TABLE_LEN_RSX 0x3
46 #define ZPCI_TABLE_LEN_RTX 0x3
48 #define ZPCI_TABLE_OFFSET_MASK 0xc0
49 #define ZPCI_TABLE_SIZE 0x4000
50 #define ZPCI_TABLE_ALIGN ZPCI_TABLE_SIZE
51 #define ZPCI_TABLE_ENTRY_SIZE (sizeof(unsigned long))
52 #define ZPCI_TABLE_ENTRIES (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE)
54 #define ZPCI_TABLE_BITS 11
55 #define ZPCI_PT_BITS 8
56 #define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT)
57 #define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS)
59 #define ZPCI_RTE_FLAG_MASK 0x3fffUL
60 #define ZPCI_RTE_ADDR_MASK (~ZPCI_RTE_FLAG_MASK)
61 #define ZPCI_STE_FLAG_MASK 0x7ffUL
62 #define ZPCI_STE_ADDR_MASK (~ZPCI_STE_FLAG_MASK)
65 #define ZPCI_PTE_VALID_MASK 0x400
66 #define ZPCI_PTE_INVALID 0x400
67 #define ZPCI_PTE_VALID 0x000
68 #define ZPCI_PT_SIZE 0x800
69 #define ZPCI_PT_ALIGN ZPCI_PT_SIZE
70 #define ZPCI_PT_ENTRIES (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE)
71 #define ZPCI_PT_MASK (ZPCI_PT_ENTRIES - 1)
73 #define ZPCI_PTE_FLAG_MASK 0xfffUL
74 #define ZPCI_PTE_ADDR_MASK (~ZPCI_PTE_FLAG_MASK)
77 #define ZPCI_TABLE_VALID 0x00
78 #define ZPCI_TABLE_INVALID 0x20
79 #define ZPCI_TABLE_PROTECTED 0x200
80 #define ZPCI_TABLE_UNPROTECTED 0x000
82 #define ZPCI_TABLE_VALID_MASK 0x20
83 #define ZPCI_TABLE_PROT_MASK 0x200
85 static inline unsigned int calc_rtx(dma_addr_t ptr
)
87 return ((unsigned long) ptr
>> ZPCI_RT_SHIFT
) & ZPCI_INDEX_MASK
;
90 static inline unsigned int calc_sx(dma_addr_t ptr
)
92 return ((unsigned long) ptr
>> ZPCI_ST_SHIFT
) & ZPCI_INDEX_MASK
;
95 static inline unsigned int calc_px(dma_addr_t ptr
)
97 return ((unsigned long) ptr
>> PAGE_SHIFT
) & ZPCI_PT_MASK
;
100 static inline void set_pt_pfaa(unsigned long *entry
, void *pfaa
)
102 *entry
&= ZPCI_PTE_FLAG_MASK
;
103 *entry
|= ((unsigned long) pfaa
& ZPCI_PTE_ADDR_MASK
);
106 static inline void set_rt_sto(unsigned long *entry
, void *sto
)
108 *entry
&= ZPCI_RTE_FLAG_MASK
;
109 *entry
|= ((unsigned long) sto
& ZPCI_RTE_ADDR_MASK
);
110 *entry
|= ZPCI_TABLE_TYPE_RTX
;
113 static inline void set_st_pto(unsigned long *entry
, void *pto
)
115 *entry
&= ZPCI_STE_FLAG_MASK
;
116 *entry
|= ((unsigned long) pto
& ZPCI_STE_ADDR_MASK
);
117 *entry
|= ZPCI_TABLE_TYPE_SX
;
120 static inline void validate_rt_entry(unsigned long *entry
)
122 *entry
&= ~ZPCI_TABLE_VALID_MASK
;
123 *entry
&= ~ZPCI_TABLE_OFFSET_MASK
;
124 *entry
|= ZPCI_TABLE_VALID
;
125 *entry
|= ZPCI_TABLE_LEN_RTX
;
128 static inline void validate_st_entry(unsigned long *entry
)
130 *entry
&= ~ZPCI_TABLE_VALID_MASK
;
131 *entry
|= ZPCI_TABLE_VALID
;
134 static inline void invalidate_table_entry(unsigned long *entry
)
136 *entry
&= ~ZPCI_TABLE_VALID_MASK
;
137 *entry
|= ZPCI_TABLE_INVALID
;
140 static inline void invalidate_pt_entry(unsigned long *entry
)
142 WARN_ON_ONCE((*entry
& ZPCI_PTE_VALID_MASK
) == ZPCI_PTE_INVALID
);
143 *entry
&= ~ZPCI_PTE_VALID_MASK
;
144 *entry
|= ZPCI_PTE_INVALID
;
147 static inline void validate_pt_entry(unsigned long *entry
)
149 WARN_ON_ONCE((*entry
& ZPCI_PTE_VALID_MASK
) == ZPCI_PTE_VALID
);
150 *entry
&= ~ZPCI_PTE_VALID_MASK
;
151 *entry
|= ZPCI_PTE_VALID
;
154 static inline void entry_set_protected(unsigned long *entry
)
156 *entry
&= ~ZPCI_TABLE_PROT_MASK
;
157 *entry
|= ZPCI_TABLE_PROTECTED
;
160 static inline void entry_clr_protected(unsigned long *entry
)
162 *entry
&= ~ZPCI_TABLE_PROT_MASK
;
163 *entry
|= ZPCI_TABLE_UNPROTECTED
;
166 static inline int reg_entry_isvalid(unsigned long entry
)
168 return (entry
& ZPCI_TABLE_VALID_MASK
) == ZPCI_TABLE_VALID
;
171 static inline int pt_entry_isvalid(unsigned long entry
)
173 return (entry
& ZPCI_PTE_VALID_MASK
) == ZPCI_PTE_VALID
;
176 static inline int entry_isprotected(unsigned long entry
)
178 return (entry
& ZPCI_TABLE_PROT_MASK
) == ZPCI_TABLE_PROTECTED
;
181 static inline unsigned long *get_rt_sto(unsigned long entry
)
183 return ((entry
& ZPCI_TABLE_TYPE_MASK
) == ZPCI_TABLE_TYPE_RTX
)
184 ? (unsigned long *) (entry
& ZPCI_RTE_ADDR_MASK
)
188 static inline unsigned long *get_st_pto(unsigned long entry
)
190 return ((entry
& ZPCI_TABLE_TYPE_MASK
) == ZPCI_TABLE_TYPE_SX
)
191 ? (unsigned long *) (entry
& ZPCI_STE_ADDR_MASK
)
196 int zpci_dma_init_device(struct zpci_dev
*);
197 void zpci_dma_exit_device(struct zpci_dev
*);
198 void dma_free_seg_table(unsigned long);
199 unsigned long *dma_alloc_cpu_table(void);
200 void dma_cleanup_tables(unsigned long *);
201 unsigned long *dma_walk_cpu_trans(unsigned long *rto
, dma_addr_t dma_addr
);
202 void dma_update_cpu_trans(unsigned long *entry
, void *page_addr
, int flags
);
204 extern const struct dma_map_ops s390_pci_dma_ops
;