1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_PCI_IO_H
3 #define _ASM_S390_PCI_IO_H
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <asm/pci_insn.h>
12 #define ZPCI_IOMAP_SHIFT 48
13 #define ZPCI_IOMAP_ADDR_BASE 0x8000000000000000UL
14 #define ZPCI_IOMAP_ADDR_OFF_MASK ((1UL << ZPCI_IOMAP_SHIFT) - 1)
15 #define ZPCI_IOMAP_MAX_ENTRIES \
16 ((ULONG_MAX - ZPCI_IOMAP_ADDR_BASE + 1) / (1UL << ZPCI_IOMAP_SHIFT))
17 #define ZPCI_IOMAP_ADDR_IDX_MASK \
18 (~ZPCI_IOMAP_ADDR_OFF_MASK - ZPCI_IOMAP_ADDR_BASE)
20 struct zpci_iomap_entry
{
26 extern struct zpci_iomap_entry
*zpci_iomap_start
;
28 #define ZPCI_ADDR(idx) (ZPCI_IOMAP_ADDR_BASE | ((u64) idx << ZPCI_IOMAP_SHIFT))
29 #define ZPCI_IDX(addr) \
30 (((__force u64) addr & ZPCI_IOMAP_ADDR_IDX_MASK) >> ZPCI_IOMAP_SHIFT)
31 #define ZPCI_OFFSET(addr) \
32 ((__force u64) addr & ZPCI_IOMAP_ADDR_OFF_MASK)
34 #define ZPCI_CREATE_REQ(handle, space, len) \
35 ((u64) handle << 32 | space << 16 | len)
37 #define zpci_read(LENGTH, RETTYPE) \
38 static inline RETTYPE zpci_read_##RETTYPE(const volatile void __iomem *addr) \
43 rc = zpci_load(&data, addr, LENGTH); \
46 return (RETTYPE) data; \
49 #define zpci_write(LENGTH, VALTYPE) \
50 static inline void zpci_write_##VALTYPE(VALTYPE val, \
51 const volatile void __iomem *addr) \
53 u64 data = (VALTYPE) val; \
55 zpci_store(addr, data, LENGTH); \
67 static inline int zpci_write_single(volatile void __iomem
*dst
, const void *src
,
74 val
= (u64
) *((u8
*) src
);
77 val
= (u64
) *((u16
*) src
);
80 val
= (u64
) *((u32
*) src
);
83 val
= (u64
) *((u64
*) src
);
86 val
= 0; /* let FW report error */
89 return zpci_store(dst
, val
, len
);
92 static inline int zpci_read_single(void *dst
, const volatile void __iomem
*src
,
98 cc
= zpci_load(&data
, src
, len
);
104 *((u8
*) dst
) = (u8
) data
;
107 *((u16
*) dst
) = (u16
) data
;
110 *((u32
*) dst
) = (u32
) data
;
113 *((u64
*) dst
) = (u64
) data
;
120 int zpci_write_block(volatile void __iomem
*dst
, const void *src
,
123 static inline u8
zpci_get_max_write_size(u64 src
, u64 dst
, int len
, int max
)
125 int count
= len
> max
? max
: len
, size
= 1;
127 while (!(src
& 0x1) && !(dst
& 0x1) && ((size
<< 1) <= count
)) {
135 static inline int zpci_memcpy_fromio(void *dst
,
136 const volatile void __iomem
*src
,
142 size
= zpci_get_max_write_size((u64 __force
) src
,
144 rc
= zpci_read_single(dst
, src
, size
);
154 static inline int zpci_memcpy_toio(volatile void __iomem
*dst
,
155 const void *src
, unsigned long n
)
163 size
= zpci_get_max_write_size((u64 __force
) dst
,
165 if (size
> 8) /* main path */
166 rc
= zpci_write_block(dst
, src
, size
);
168 rc
= zpci_write_single(dst
, src
, size
);
178 static inline int zpci_memset_io(volatile void __iomem
*dst
,
179 unsigned char val
, size_t count
)
181 u8
*src
= kmalloc(count
, GFP_KERNEL
);
186 memset(src
, val
, count
);
188 rc
= zpci_memcpy_toio(dst
, src
, count
);
193 #endif /* CONFIG_PCI */
195 #endif /* _ASM_S390_PCI_IO_H */