1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright 2019 IBM Corp.
3 #include <linux/sched/mm.h>
5 #include "ocxl_internal.h"
7 int ocxl_global_mmio_read32(struct ocxl_afu
*afu
, size_t offset
,
8 enum ocxl_endian endian
, u32
*val
)
10 if (offset
> afu
->config
.global_mmio_size
- 4)
14 if (endian
== OCXL_HOST_ENDIAN
)
15 endian
= OCXL_BIG_ENDIAN
;
20 *val
= readl_be((char *)afu
->global_mmio_ptr
+ offset
);
24 *val
= readl((char *)afu
->global_mmio_ptr
+ offset
);
30 EXPORT_SYMBOL_GPL(ocxl_global_mmio_read32
);
32 int ocxl_global_mmio_read64(struct ocxl_afu
*afu
, size_t offset
,
33 enum ocxl_endian endian
, u64
*val
)
35 if (offset
> afu
->config
.global_mmio_size
- 8)
39 if (endian
== OCXL_HOST_ENDIAN
)
40 endian
= OCXL_BIG_ENDIAN
;
45 *val
= readq_be((char *)afu
->global_mmio_ptr
+ offset
);
49 *val
= readq((char *)afu
->global_mmio_ptr
+ offset
);
55 EXPORT_SYMBOL_GPL(ocxl_global_mmio_read64
);
57 int ocxl_global_mmio_write32(struct ocxl_afu
*afu
, size_t offset
,
58 enum ocxl_endian endian
, u32 val
)
60 if (offset
> afu
->config
.global_mmio_size
- 4)
64 if (endian
== OCXL_HOST_ENDIAN
)
65 endian
= OCXL_BIG_ENDIAN
;
70 writel_be(val
, (char *)afu
->global_mmio_ptr
+ offset
);
74 writel(val
, (char *)afu
->global_mmio_ptr
+ offset
);
81 EXPORT_SYMBOL_GPL(ocxl_global_mmio_write32
);
83 int ocxl_global_mmio_write64(struct ocxl_afu
*afu
, size_t offset
,
84 enum ocxl_endian endian
, u64 val
)
86 if (offset
> afu
->config
.global_mmio_size
- 8)
90 if (endian
== OCXL_HOST_ENDIAN
)
91 endian
= OCXL_BIG_ENDIAN
;
96 writeq_be(val
, (char *)afu
->global_mmio_ptr
+ offset
);
100 writeq(val
, (char *)afu
->global_mmio_ptr
+ offset
);
107 EXPORT_SYMBOL_GPL(ocxl_global_mmio_write64
);
109 int ocxl_global_mmio_set32(struct ocxl_afu
*afu
, size_t offset
,
110 enum ocxl_endian endian
, u32 mask
)
114 if (offset
> afu
->config
.global_mmio_size
- 4)
117 #ifdef __BIG_ENDIAN__
118 if (endian
== OCXL_HOST_ENDIAN
)
119 endian
= OCXL_BIG_ENDIAN
;
123 case OCXL_BIG_ENDIAN
:
124 tmp
= readl_be((char *)afu
->global_mmio_ptr
+ offset
);
126 writel_be(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
130 tmp
= readl((char *)afu
->global_mmio_ptr
+ offset
);
132 writel(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
138 EXPORT_SYMBOL_GPL(ocxl_global_mmio_set32
);
140 int ocxl_global_mmio_set64(struct ocxl_afu
*afu
, size_t offset
,
141 enum ocxl_endian endian
, u64 mask
)
145 if (offset
> afu
->config
.global_mmio_size
- 8)
148 #ifdef __BIG_ENDIAN__
149 if (endian
== OCXL_HOST_ENDIAN
)
150 endian
= OCXL_BIG_ENDIAN
;
154 case OCXL_BIG_ENDIAN
:
155 tmp
= readq_be((char *)afu
->global_mmio_ptr
+ offset
);
157 writeq_be(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
161 tmp
= readq((char *)afu
->global_mmio_ptr
+ offset
);
163 writeq(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
169 EXPORT_SYMBOL_GPL(ocxl_global_mmio_set64
);
171 int ocxl_global_mmio_clear32(struct ocxl_afu
*afu
, size_t offset
,
172 enum ocxl_endian endian
, u32 mask
)
176 if (offset
> afu
->config
.global_mmio_size
- 4)
179 #ifdef __BIG_ENDIAN__
180 if (endian
== OCXL_HOST_ENDIAN
)
181 endian
= OCXL_BIG_ENDIAN
;
185 case OCXL_BIG_ENDIAN
:
186 tmp
= readl_be((char *)afu
->global_mmio_ptr
+ offset
);
188 writel_be(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
192 tmp
= readl((char *)afu
->global_mmio_ptr
+ offset
);
194 writel(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
201 EXPORT_SYMBOL_GPL(ocxl_global_mmio_clear32
);
203 int ocxl_global_mmio_clear64(struct ocxl_afu
*afu
, size_t offset
,
204 enum ocxl_endian endian
, u64 mask
)
208 if (offset
> afu
->config
.global_mmio_size
- 8)
211 #ifdef __BIG_ENDIAN__
212 if (endian
== OCXL_HOST_ENDIAN
)
213 endian
= OCXL_BIG_ENDIAN
;
217 case OCXL_BIG_ENDIAN
:
218 tmp
= readq_be((char *)afu
->global_mmio_ptr
+ offset
);
220 writeq_be(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
224 tmp
= readq((char *)afu
->global_mmio_ptr
+ offset
);
226 writeq(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
230 writeq(tmp
, (char *)afu
->global_mmio_ptr
+ offset
);
234 EXPORT_SYMBOL_GPL(ocxl_global_mmio_clear64
);