Skip to content

Commit dae409a

Browse files
James BottomleyLinus Torvalds
authored andcommitted
[PATCH] add Big Endian variants of ioread/iowrite
In the new io infrastructure, all of our operators are expecting the underlying device to be little endian (because the PCI bus, their main consumer, is LE). However, there are a fair few devices and busses in the world that are actually Big Endian. There's even evidence that some of these BE bus and chip types are attached to LE systems. Thus, there's a need for a BE equivalent of our io{read,write}{16,32} operations. The attached patch adds this as io{read,write}{16,32}be. When it's in, I'll add the first consume (the 53c700 SCSI chip driver). Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent c41f5eb commit dae409a

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎arch/parisc/lib/iomap.c‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@
4343
struct iomap_ops {
4444
unsigned int (*read8)(void __iomem *);
4545
unsigned int (*read16)(void __iomem *);
46+
unsigned int (*read16be)(void __iomem *);
4647
unsigned int (*read32)(void __iomem *);
48+
unsigned int (*read32be)(void __iomem *);
4749
void (*write8)(u8, void __iomem *);
4850
void (*write16)(u16, void __iomem *);
51+
void (*write16be)(u16, void __iomem *);
4952
void (*write32)(u32, void __iomem *);
53+
void (*write32be)(u32, void __iomem *);
5054
void (*read8r)(void __iomem *, void *, unsigned long);
5155
void (*read16r)(void __iomem *, void *, unsigned long);
5256
void (*read32r)(void __iomem *, void *, unsigned long);
@@ -122,9 +126,13 @@ static void ioport_write32r(void __iomem *addr, const void *s, unsigned long n)
122126
static const struct iomap_ops ioport_ops = {
123127
ioport_read8,
124128
ioport_read16,
129+
ioport_read16,
130+
ioport_read32,
125131
ioport_read32,
126132
ioport_write8,
127133
ioport_write16,
134+
ioport_write16,
135+
ioport_write32,
128136
ioport_write32,
129137
ioport_read8r,
130138
ioport_read16r,
@@ -146,11 +154,21 @@ static unsigned int iomem_read16(void __iomem *addr)
146154
return readw(addr);
147155
}
148156

157+
static unsigned int iomem_read16be(void __iomem *addr)
158+
{
159+
return __raw_readw(addr);
160+
}
161+
149162
static unsigned int iomem_read32(void __iomem *addr)
150163
{
151164
return readl(addr);
152165
}
153166

167+
static unsigned int iomem_read32be(void __iomem *addr)
168+
{
169+
return __raw_readl(addr);
170+
}
171+
154172
static void iomem_write8(u8 datum, void __iomem *addr)
155173
{
156174
writeb(datum, addr);
@@ -161,11 +179,21 @@ static void iomem_write16(u16 datum, void __iomem *addr)
161179
writew(datum, addr);
162180
}
163181

182+
static void iomem_write16be(u16 datum, void __iomem *addr)
183+
{
184+
__raw_writew(datum, addr);
185+
}
186+
164187
static void iomem_write32(u32 datum, void __iomem *addr)
165188
{
166189
writel(datum, addr);
167190
}
168191

192+
static void iomem_write32be(u32 datum, void __iomem *addr)
193+
{
194+
__raw_writel(datum, addr);
195+
}
196+
169197
static void iomem_read8r(void __iomem *addr, void *dst, unsigned long count)
170198
{
171199
while (count--) {
@@ -217,10 +245,14 @@ static void iomem_write32r(void __iomem *addr, const void *s, unsigned long n)
217245
static const struct iomap_ops iomem_ops = {
218246
iomem_read8,
219247
iomem_read16,
248+
iomem_read16be,
220249
iomem_read32,
250+
iomem_read32be,
221251
iomem_write8,
222252
iomem_write16,
253+
iomem_write16be,
223254
iomem_write32,
255+
iomem_write32be,
224256
iomem_read8r,
225257
iomem_read16r,
226258
iomem_read32r,
@@ -253,13 +285,27 @@ unsigned int ioread16(void __iomem *addr)
253285
return le16_to_cpup((u16 *)addr);
254286
}
255287

288+
unsigned int ioread16be(void __iomem *addr)
289+
{
290+
if (unlikely(INDIRECT_ADDR(addr)))
291+
return iomap_ops[ADDR_TO_REGION(addr)]->read16be(addr);
292+
return *((u16 *)addr);
293+
}
294+
256295
unsigned int ioread32(void __iomem *addr)
257296
{
258297
if (unlikely(INDIRECT_ADDR(addr)))
259298
return iomap_ops[ADDR_TO_REGION(addr)]->read32(addr);
260299
return le32_to_cpup((u32 *)addr);
261300
}
262301

302+
unsigned int ioread32be(void __iomem *addr)
303+
{
304+
if (unlikely(INDIRECT_ADDR(addr)))
305+
return iomap_ops[ADDR_TO_REGION(addr)]->read32be(addr);
306+
return *((u32 *)addr);
307+
}
308+
263309
void iowrite8(u8 datum, void __iomem *addr)
264310
{
265311
if (unlikely(INDIRECT_ADDR(addr))) {
@@ -278,6 +324,15 @@ void iowrite16(u16 datum, void __iomem *addr)
278324
}
279325
}
280326

327+
void iowrite16be(u16 datum, void __iomem *addr)
328+
{
329+
if (unlikely(INDIRECT_ADDR(addr))) {
330+
iomap_ops[ADDR_TO_REGION(addr)]->write16be(datum, addr);
331+
} else {
332+
*((u16 *)addr) = datum;
333+
}
334+
}
335+
281336
void iowrite32(u32 datum, void __iomem *addr)
282337
{
283338
if (unlikely(INDIRECT_ADDR(addr))) {
@@ -287,6 +342,15 @@ void iowrite32(u32 datum, void __iomem *addr)
287342
}
288343
}
289344

345+
void iowrite32be(u32 datum, void __iomem *addr)
346+
{
347+
if (unlikely(INDIRECT_ADDR(addr))) {
348+
iomap_ops[ADDR_TO_REGION(addr)]->write32be(datum, addr);
349+
} else {
350+
*((u32 *)addr) = datum;
351+
}
352+
}
353+
290354
/* Repeating interfaces */
291355

292356
void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
@@ -406,10 +470,14 @@ void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
406470

407471
EXPORT_SYMBOL(ioread8);
408472
EXPORT_SYMBOL(ioread16);
473+
EXPORT_SYMBOL(ioread16be);
409474
EXPORT_SYMBOL(ioread32);
475+
EXPORT_SYMBOL(ioread32be);
410476
EXPORT_SYMBOL(iowrite8);
411477
EXPORT_SYMBOL(iowrite16);
478+
EXPORT_SYMBOL(iowrite16be);
412479
EXPORT_SYMBOL(iowrite32);
480+
EXPORT_SYMBOL(iowrite32be);
413481
EXPORT_SYMBOL(ioread8_rep);
414482
EXPORT_SYMBOL(ioread16_rep);
415483
EXPORT_SYMBOL(ioread32_rep);

‎include/asm-generic/iomap.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __GENERIC_IO_H
33

44
#include <linux/linkage.h>
5+
#include <asm/byteorder.h>
56

67
/*
78
* These are the "generic" interfaces for doing new-style
@@ -26,11 +27,15 @@
2627
*/
2728
extern unsigned int fastcall ioread8(void __iomem *);
2829
extern unsigned int fastcall ioread16(void __iomem *);
30+
extern unsigned int fastcall ioread16be(void __iomem *);
2931
extern unsigned int fastcall ioread32(void __iomem *);
32+
extern unsigned int fastcall ioread32be(void __iomem *);
3033

3134
extern void fastcall iowrite8(u8, void __iomem *);
3235
extern void fastcall iowrite16(u16, void __iomem *);
36+
extern void fastcall iowrite16be(u16, void __iomem *);
3337
extern void fastcall iowrite32(u32, void __iomem *);
38+
extern void fastcall iowrite32be(u32, void __iomem *);
3439

3540
/*
3641
* "string" versions of the above. Note that they

‎lib/iomap.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,23 @@ unsigned int fastcall ioread16(void __iomem *addr)
5858
{
5959
IO_COND(addr, return inw(port), return readw(addr));
6060
}
61+
unsigned int fastcall ioread16be(void __iomem *addr)
62+
{
63+
IO_COND(addr, return inw(port), return be16_to_cpu(__raw_readw(addr)));
64+
}
6165
unsigned int fastcall ioread32(void __iomem *addr)
6266
{
6367
IO_COND(addr, return inl(port), return readl(addr));
6468
}
69+
unsigned int fastcall ioread32be(void __iomem *addr)
70+
{
71+
IO_COND(addr, return inl(port), return be32_to_cpu(__raw_readl(addr)));
72+
}
6573
EXPORT_SYMBOL(ioread8);
6674
EXPORT_SYMBOL(ioread16);
75+
EXPORT_SYMBOL(ioread16be);
6776
EXPORT_SYMBOL(ioread32);
77+
EXPORT_SYMBOL(ioread32be);
6878

6979
void fastcall iowrite8(u8 val, void __iomem *addr)
7080
{
@@ -74,13 +84,23 @@ void fastcall iowrite16(u16 val, void __iomem *addr)
7484
{
7585
IO_COND(addr, outw(val,port), writew(val, addr));
7686
}
87+
void fastcall iowrite16be(u16 val, void __iomem *addr)
88+
{
89+
IO_COND(addr, outw(val,port), __raw_writew(cpu_to_be16(val), addr));
90+
}
7791
void fastcall iowrite32(u32 val, void __iomem *addr)
7892
{
7993
IO_COND(addr, outl(val,port), writel(val, addr));
8094
}
95+
void fastcall iowrite32be(u32 val, void __iomem *addr)
96+
{
97+
IO_COND(addr, outl(val,port), __raw_writel(cpu_to_be32(val), addr));
98+
}
8199
EXPORT_SYMBOL(iowrite8);
82100
EXPORT_SYMBOL(iowrite16);
101+
EXPORT_SYMBOL(iowrite16be);
83102
EXPORT_SYMBOL(iowrite32);
103+
EXPORT_SYMBOL(iowrite32be);
84104

85105
/*
86106
* These are the "repeat MMIO read/write" functions.

0 commit comments

Comments
 (0)