1828b35f6SJan Glauber #ifndef _ASM_S390_PCI_DMA_H 2828b35f6SJan Glauber #define _ASM_S390_PCI_DMA_H 3828b35f6SJan Glauber 4828b35f6SJan Glauber /* I/O Translation Anchor (IOTA) */ 5828b35f6SJan Glauber enum zpci_ioat_dtype { 6828b35f6SJan Glauber ZPCI_IOTA_STO = 0, 7828b35f6SJan Glauber ZPCI_IOTA_RTTO = 1, 8828b35f6SJan Glauber ZPCI_IOTA_RSTO = 2, 9828b35f6SJan Glauber ZPCI_IOTA_RFTO = 3, 10828b35f6SJan Glauber ZPCI_IOTA_PFAA = 4, 11828b35f6SJan Glauber ZPCI_IOTA_IOPFAA = 5, 12828b35f6SJan Glauber ZPCI_IOTA_IOPTO = 7 13828b35f6SJan Glauber }; 14828b35f6SJan Glauber 15828b35f6SJan Glauber #define ZPCI_IOTA_IOT_ENABLED 0x800UL 16828b35f6SJan Glauber #define ZPCI_IOTA_DT_ST (ZPCI_IOTA_STO << 2) 17828b35f6SJan Glauber #define ZPCI_IOTA_DT_RT (ZPCI_IOTA_RTTO << 2) 18828b35f6SJan Glauber #define ZPCI_IOTA_DT_RS (ZPCI_IOTA_RSTO << 2) 19828b35f6SJan Glauber #define ZPCI_IOTA_DT_RF (ZPCI_IOTA_RFTO << 2) 20828b35f6SJan Glauber #define ZPCI_IOTA_DT_PF (ZPCI_IOTA_PFAA << 2) 21828b35f6SJan Glauber #define ZPCI_IOTA_FS_4K 0 22828b35f6SJan Glauber #define ZPCI_IOTA_FS_1M 1 23828b35f6SJan Glauber #define ZPCI_IOTA_FS_2G 2 24828b35f6SJan Glauber #define ZPCI_KEY (PAGE_DEFAULT_KEY << 5) 25828b35f6SJan Glauber 26*69eea95cSGerald Schaefer #define ZPCI_TABLE_SIZE_RT (1UL << 42) 27*69eea95cSGerald Schaefer 28828b35f6SJan Glauber #define ZPCI_IOTA_STO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_ST) 29828b35f6SJan Glauber #define ZPCI_IOTA_RTTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RT) 30828b35f6SJan Glauber #define ZPCI_IOTA_RSTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RS) 31828b35f6SJan Glauber #define ZPCI_IOTA_RFTO_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_RF) 32828b35f6SJan Glauber #define ZPCI_IOTA_RFAA_FLAG (ZPCI_IOTA_IOT_ENABLED | ZPCI_KEY | ZPCI_IOTA_DT_PF | ZPCI_IOTA_FS_2G) 33828b35f6SJan Glauber 34828b35f6SJan Glauber /* I/O Region and segment tables */ 35828b35f6SJan Glauber #define ZPCI_INDEX_MASK 0x7ffUL 36828b35f6SJan Glauber 37828b35f6SJan Glauber #define ZPCI_TABLE_TYPE_MASK 0xc 38828b35f6SJan Glauber #define ZPCI_TABLE_TYPE_RFX 0xc 39828b35f6SJan Glauber #define ZPCI_TABLE_TYPE_RSX 0x8 40828b35f6SJan Glauber #define ZPCI_TABLE_TYPE_RTX 0x4 41828b35f6SJan Glauber #define ZPCI_TABLE_TYPE_SX 0x0 42828b35f6SJan Glauber 43828b35f6SJan Glauber #define ZPCI_TABLE_LEN_RFX 0x3 44828b35f6SJan Glauber #define ZPCI_TABLE_LEN_RSX 0x3 45828b35f6SJan Glauber #define ZPCI_TABLE_LEN_RTX 0x3 46828b35f6SJan Glauber 47828b35f6SJan Glauber #define ZPCI_TABLE_OFFSET_MASK 0xc0 48828b35f6SJan Glauber #define ZPCI_TABLE_SIZE 0x4000 49828b35f6SJan Glauber #define ZPCI_TABLE_ALIGN ZPCI_TABLE_SIZE 50828b35f6SJan Glauber #define ZPCI_TABLE_ENTRY_SIZE (sizeof(unsigned long)) 51828b35f6SJan Glauber #define ZPCI_TABLE_ENTRIES (ZPCI_TABLE_SIZE / ZPCI_TABLE_ENTRY_SIZE) 52828b35f6SJan Glauber 53828b35f6SJan Glauber #define ZPCI_TABLE_BITS 11 54828b35f6SJan Glauber #define ZPCI_PT_BITS 8 55828b35f6SJan Glauber #define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT) 56828b35f6SJan Glauber #define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS) 57828b35f6SJan Glauber 58828b35f6SJan Glauber #define ZPCI_RTE_FLAG_MASK 0x3fffUL 59828b35f6SJan Glauber #define ZPCI_RTE_ADDR_MASK (~ZPCI_RTE_FLAG_MASK) 60828b35f6SJan Glauber #define ZPCI_STE_FLAG_MASK 0x7ffUL 61828b35f6SJan Glauber #define ZPCI_STE_ADDR_MASK (~ZPCI_STE_FLAG_MASK) 62828b35f6SJan Glauber 63828b35f6SJan Glauber /* I/O Page tables */ 64828b35f6SJan Glauber #define ZPCI_PTE_VALID_MASK 0x400 65828b35f6SJan Glauber #define ZPCI_PTE_INVALID 0x400 66828b35f6SJan Glauber #define ZPCI_PTE_VALID 0x000 67828b35f6SJan Glauber #define ZPCI_PT_SIZE 0x800 68828b35f6SJan Glauber #define ZPCI_PT_ALIGN ZPCI_PT_SIZE 69828b35f6SJan Glauber #define ZPCI_PT_ENTRIES (ZPCI_PT_SIZE / ZPCI_TABLE_ENTRY_SIZE) 70828b35f6SJan Glauber #define ZPCI_PT_MASK (ZPCI_PT_ENTRIES - 1) 71828b35f6SJan Glauber 72828b35f6SJan Glauber #define ZPCI_PTE_FLAG_MASK 0xfffUL 73828b35f6SJan Glauber #define ZPCI_PTE_ADDR_MASK (~ZPCI_PTE_FLAG_MASK) 74828b35f6SJan Glauber 75828b35f6SJan Glauber /* Shared bits */ 76828b35f6SJan Glauber #define ZPCI_TABLE_VALID 0x00 77828b35f6SJan Glauber #define ZPCI_TABLE_INVALID 0x20 78828b35f6SJan Glauber #define ZPCI_TABLE_PROTECTED 0x200 79828b35f6SJan Glauber #define ZPCI_TABLE_UNPROTECTED 0x000 80828b35f6SJan Glauber 81828b35f6SJan Glauber #define ZPCI_TABLE_VALID_MASK 0x20 82828b35f6SJan Glauber #define ZPCI_TABLE_PROT_MASK 0x200 83828b35f6SJan Glauber 84828b35f6SJan Glauber static inline unsigned int calc_rtx(dma_addr_t ptr) 85828b35f6SJan Glauber { 86828b35f6SJan Glauber return ((unsigned long) ptr >> ZPCI_RT_SHIFT) & ZPCI_INDEX_MASK; 87828b35f6SJan Glauber } 88828b35f6SJan Glauber 89828b35f6SJan Glauber static inline unsigned int calc_sx(dma_addr_t ptr) 90828b35f6SJan Glauber { 91828b35f6SJan Glauber return ((unsigned long) ptr >> ZPCI_ST_SHIFT) & ZPCI_INDEX_MASK; 92828b35f6SJan Glauber } 93828b35f6SJan Glauber 94828b35f6SJan Glauber static inline unsigned int calc_px(dma_addr_t ptr) 95828b35f6SJan Glauber { 96828b35f6SJan Glauber return ((unsigned long) ptr >> PAGE_SHIFT) & ZPCI_PT_MASK; 97828b35f6SJan Glauber } 98828b35f6SJan Glauber 99828b35f6SJan Glauber static inline void set_pt_pfaa(unsigned long *entry, void *pfaa) 100828b35f6SJan Glauber { 101828b35f6SJan Glauber *entry &= ZPCI_PTE_FLAG_MASK; 102828b35f6SJan Glauber *entry |= ((unsigned long) pfaa & ZPCI_PTE_ADDR_MASK); 103828b35f6SJan Glauber } 104828b35f6SJan Glauber 105828b35f6SJan Glauber static inline void set_rt_sto(unsigned long *entry, void *sto) 106828b35f6SJan Glauber { 107828b35f6SJan Glauber *entry &= ZPCI_RTE_FLAG_MASK; 108828b35f6SJan Glauber *entry |= ((unsigned long) sto & ZPCI_RTE_ADDR_MASK); 109828b35f6SJan Glauber *entry |= ZPCI_TABLE_TYPE_RTX; 110828b35f6SJan Glauber } 111828b35f6SJan Glauber 112828b35f6SJan Glauber static inline void set_st_pto(unsigned long *entry, void *pto) 113828b35f6SJan Glauber { 114828b35f6SJan Glauber *entry &= ZPCI_STE_FLAG_MASK; 115828b35f6SJan Glauber *entry |= ((unsigned long) pto & ZPCI_STE_ADDR_MASK); 116828b35f6SJan Glauber *entry |= ZPCI_TABLE_TYPE_SX; 117828b35f6SJan Glauber } 118828b35f6SJan Glauber 119828b35f6SJan Glauber static inline void validate_rt_entry(unsigned long *entry) 120828b35f6SJan Glauber { 121828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_VALID_MASK; 122828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_OFFSET_MASK; 123828b35f6SJan Glauber *entry |= ZPCI_TABLE_VALID; 124828b35f6SJan Glauber *entry |= ZPCI_TABLE_LEN_RTX; 125828b35f6SJan Glauber } 126828b35f6SJan Glauber 127828b35f6SJan Glauber static inline void validate_st_entry(unsigned long *entry) 128828b35f6SJan Glauber { 129828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_VALID_MASK; 130828b35f6SJan Glauber *entry |= ZPCI_TABLE_VALID; 131828b35f6SJan Glauber } 132828b35f6SJan Glauber 133828b35f6SJan Glauber static inline void invalidate_table_entry(unsigned long *entry) 134828b35f6SJan Glauber { 135828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_VALID_MASK; 136828b35f6SJan Glauber *entry |= ZPCI_TABLE_INVALID; 137828b35f6SJan Glauber } 138828b35f6SJan Glauber 139828b35f6SJan Glauber static inline void invalidate_pt_entry(unsigned long *entry) 140828b35f6SJan Glauber { 141828b35f6SJan Glauber WARN_ON_ONCE((*entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_INVALID); 142828b35f6SJan Glauber *entry &= ~ZPCI_PTE_VALID_MASK; 143828b35f6SJan Glauber *entry |= ZPCI_PTE_INVALID; 144828b35f6SJan Glauber } 145828b35f6SJan Glauber 146828b35f6SJan Glauber static inline void validate_pt_entry(unsigned long *entry) 147828b35f6SJan Glauber { 148828b35f6SJan Glauber WARN_ON_ONCE((*entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID); 149828b35f6SJan Glauber *entry &= ~ZPCI_PTE_VALID_MASK; 150828b35f6SJan Glauber *entry |= ZPCI_PTE_VALID; 151828b35f6SJan Glauber } 152828b35f6SJan Glauber 153828b35f6SJan Glauber static inline void entry_set_protected(unsigned long *entry) 154828b35f6SJan Glauber { 155828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_PROT_MASK; 156828b35f6SJan Glauber *entry |= ZPCI_TABLE_PROTECTED; 157828b35f6SJan Glauber } 158828b35f6SJan Glauber 159828b35f6SJan Glauber static inline void entry_clr_protected(unsigned long *entry) 160828b35f6SJan Glauber { 161828b35f6SJan Glauber *entry &= ~ZPCI_TABLE_PROT_MASK; 162828b35f6SJan Glauber *entry |= ZPCI_TABLE_UNPROTECTED; 163828b35f6SJan Glauber } 164828b35f6SJan Glauber 165828b35f6SJan Glauber static inline int reg_entry_isvalid(unsigned long entry) 166828b35f6SJan Glauber { 167828b35f6SJan Glauber return (entry & ZPCI_TABLE_VALID_MASK) == ZPCI_TABLE_VALID; 168828b35f6SJan Glauber } 169828b35f6SJan Glauber 170828b35f6SJan Glauber static inline int pt_entry_isvalid(unsigned long entry) 171828b35f6SJan Glauber { 172828b35f6SJan Glauber return (entry & ZPCI_PTE_VALID_MASK) == ZPCI_PTE_VALID; 173828b35f6SJan Glauber } 174828b35f6SJan Glauber 175828b35f6SJan Glauber static inline int entry_isprotected(unsigned long entry) 176828b35f6SJan Glauber { 177828b35f6SJan Glauber return (entry & ZPCI_TABLE_PROT_MASK) == ZPCI_TABLE_PROTECTED; 178828b35f6SJan Glauber } 179828b35f6SJan Glauber 180828b35f6SJan Glauber static inline unsigned long *get_rt_sto(unsigned long entry) 181828b35f6SJan Glauber { 182828b35f6SJan Glauber return ((entry & ZPCI_TABLE_TYPE_MASK) == ZPCI_TABLE_TYPE_RTX) 183828b35f6SJan Glauber ? (unsigned long *) (entry & ZPCI_RTE_ADDR_MASK) 184828b35f6SJan Glauber : NULL; 185828b35f6SJan Glauber } 186828b35f6SJan Glauber 187828b35f6SJan Glauber static inline unsigned long *get_st_pto(unsigned long entry) 188828b35f6SJan Glauber { 189828b35f6SJan Glauber return ((entry & ZPCI_TABLE_TYPE_MASK) == ZPCI_TABLE_TYPE_SX) 190828b35f6SJan Glauber ? (unsigned long *) (entry & ZPCI_STE_ADDR_MASK) 191828b35f6SJan Glauber : NULL; 192828b35f6SJan Glauber } 193828b35f6SJan Glauber 194828b35f6SJan Glauber /* Prototypes */ 195828b35f6SJan Glauber int zpci_dma_init_device(struct zpci_dev *); 196828b35f6SJan Glauber void zpci_dma_exit_device(struct zpci_dev *); 1978128f23cSGerald Schaefer void dma_free_seg_table(unsigned long); 1988128f23cSGerald Schaefer unsigned long *dma_alloc_cpu_table(void); 1998128f23cSGerald Schaefer void dma_cleanup_tables(unsigned long *); 20066728eeeSSebastian Ott unsigned long *dma_walk_cpu_trans(unsigned long *rto, dma_addr_t dma_addr); 20166728eeeSSebastian Ott void dma_update_cpu_trans(unsigned long *entry, void *page_addr, int flags); 20266728eeeSSebastian Ott 203828b35f6SJan Glauber #endif 204