hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/arch/s390/include/asm/pci_io.h
....@@ -8,14 +8,19 @@
88 #include <linux/slab.h>
99 #include <asm/pci_insn.h>
1010
11
+/* I/O size constraints */
12
+#define ZPCI_MAX_READ_SIZE 8
13
+#define ZPCI_MAX_WRITE_SIZE 128
14
+
1115 /* I/O Map */
1216 #define ZPCI_IOMAP_SHIFT 48
13
-#define ZPCI_IOMAP_ADDR_BASE 0x8000000000000000UL
17
+#define ZPCI_IOMAP_ADDR_SHIFT 62
18
+#define ZPCI_IOMAP_ADDR_BASE (1UL << ZPCI_IOMAP_ADDR_SHIFT)
1419 #define ZPCI_IOMAP_ADDR_OFF_MASK ((1UL << ZPCI_IOMAP_SHIFT) - 1)
1520 #define ZPCI_IOMAP_MAX_ENTRIES \
16
- ((ULONG_MAX - ZPCI_IOMAP_ADDR_BASE + 1) / (1UL << ZPCI_IOMAP_SHIFT))
21
+ (1UL << (ZPCI_IOMAP_ADDR_SHIFT - ZPCI_IOMAP_SHIFT))
1722 #define ZPCI_IOMAP_ADDR_IDX_MASK \
18
- (~ZPCI_IOMAP_ADDR_OFF_MASK - ZPCI_IOMAP_ADDR_BASE)
23
+ ((ZPCI_IOMAP_ADDR_BASE - 1) & ~ZPCI_IOMAP_ADDR_OFF_MASK)
1924
2025 struct zpci_iomap_entry {
2126 u32 fh;
....@@ -37,12 +42,10 @@
3742 #define zpci_read(LENGTH, RETTYPE) \
3843 static inline RETTYPE zpci_read_##RETTYPE(const volatile void __iomem *addr) \
3944 { \
40
- struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)]; \
41
- u64 req = ZPCI_CREATE_REQ(entry->fh, entry->bar, LENGTH); \
4245 u64 data; \
4346 int rc; \
4447 \
45
- rc = zpci_load(&data, req, ZPCI_OFFSET(addr)); \
48
+ rc = zpci_load(&data, addr, LENGTH); \
4649 if (rc) \
4750 data = -1ULL; \
4851 return (RETTYPE) data; \
....@@ -52,11 +55,9 @@
5255 static inline void zpci_write_##VALTYPE(VALTYPE val, \
5356 const volatile void __iomem *addr) \
5457 { \
55
- struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)]; \
56
- u64 req = ZPCI_CREATE_REQ(entry->fh, entry->bar, LENGTH); \
5758 u64 data = (VALTYPE) val; \
5859 \
59
- zpci_store(data, req, ZPCI_OFFSET(addr)); \
60
+ zpci_store(addr, data, LENGTH); \
6061 }
6162
6263 zpci_read(8, u64)
....@@ -68,36 +69,38 @@
6869 zpci_write(2, u16)
6970 zpci_write(1, u8)
7071
71
-static inline int zpci_write_single(u64 req, const u64 *data, u64 offset, u8 len)
72
+static inline int zpci_write_single(volatile void __iomem *dst, const void *src,
73
+ unsigned long len)
7274 {
7375 u64 val;
7476
7577 switch (len) {
7678 case 1:
77
- val = (u64) *((u8 *) data);
79
+ val = (u64) *((u8 *) src);
7880 break;
7981 case 2:
80
- val = (u64) *((u16 *) data);
82
+ val = (u64) *((u16 *) src);
8183 break;
8284 case 4:
83
- val = (u64) *((u32 *) data);
85
+ val = (u64) *((u32 *) src);
8486 break;
8587 case 8:
86
- val = (u64) *((u64 *) data);
88
+ val = (u64) *((u64 *) src);
8789 break;
8890 default:
8991 val = 0; /* let FW report error */
9092 break;
9193 }
92
- return zpci_store(val, req, offset);
94
+ return zpci_store(dst, val, len);
9395 }
9496
95
-static inline int zpci_read_single(u64 req, u64 *dst, u64 offset, u8 len)
97
+static inline int zpci_read_single(void *dst, const volatile void __iomem *src,
98
+ unsigned long len)
9699 {
97100 u64 data;
98101 int cc;
99102
100
- cc = zpci_load(&data, req, offset);
103
+ cc = zpci_load(&data, src, len);
101104 if (cc)
102105 goto out;
103106
....@@ -119,10 +122,8 @@
119122 return cc;
120123 }
121124
122
-static inline int zpci_write_block(u64 req, const u64 *data, u64 offset)
123
-{
124
- return zpci_store_block(data, req, offset);
125
-}
125
+int zpci_write_block(volatile void __iomem *dst, const void *src,
126
+ unsigned long len);
126127
127128 static inline u8 zpci_get_max_write_size(u64 src, u64 dst, int len, int max)
128129 {
....@@ -140,18 +141,16 @@
140141 const volatile void __iomem *src,
141142 unsigned long n)
142143 {
143
- struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(src)];
144
- u64 req, offset = ZPCI_OFFSET(src);
145144 int size, rc = 0;
146145
147146 while (n > 0) {
148147 size = zpci_get_max_write_size((u64 __force) src,
149
- (u64) dst, n, 8);
150
- req = ZPCI_CREATE_REQ(entry->fh, entry->bar, size);
151
- rc = zpci_read_single(req, dst, offset, size);
148
+ (u64) dst, n,
149
+ ZPCI_MAX_READ_SIZE);
150
+ rc = zpci_read_single(dst, src, size);
152151 if (rc)
153152 break;
154
- offset += size;
153
+ src += size;
155154 dst += size;
156155 n -= size;
157156 }
....@@ -161,8 +160,6 @@
161160 static inline int zpci_memcpy_toio(volatile void __iomem *dst,
162161 const void *src, unsigned long n)
163162 {
164
- struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(dst)];
165
- u64 req, offset = ZPCI_OFFSET(dst);
166163 int size, rc = 0;
167164
168165 if (!src)
....@@ -170,17 +167,16 @@
170167
171168 while (n > 0) {
172169 size = zpci_get_max_write_size((u64 __force) dst,
173
- (u64) src, n, 128);
174
- req = ZPCI_CREATE_REQ(entry->fh, entry->bar, size);
175
-
170
+ (u64) src, n,
171
+ ZPCI_MAX_WRITE_SIZE);
176172 if (size > 8) /* main path */
177
- rc = zpci_write_block(req, src, offset);
173
+ rc = zpci_write_block(dst, src, size);
178174 else
179
- rc = zpci_write_single(req, src, offset, size);
175
+ rc = zpci_write_single(dst, src, size);
180176 if (rc)
181177 break;
182
- offset += size;
183178 src += size;
179
+ dst += size;
184180 n -= size;
185181 }
186182 return rc;