1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/include/asm-m68k/raw_io.h
5 * 10/20/00 RZ: - created from bits of io.h and ide.h to cleanup namespace
14 #include <asm/byteorder.h>
17 /* Values for nocacheflag and cmode */
18 #define IOMAP_FULL_CACHING 0
19 #define IOMAP_NOCACHE_SER 1
20 #define IOMAP_NOCACHE_NONSER 2
21 #define IOMAP_WRITETHROUGH 3
23 extern void iounmap(void __iomem
*addr
);
25 extern void __iomem
*__ioremap(unsigned long physaddr
, unsigned long size
,
27 extern void __iounmap(void *addr
, unsigned long size
);
30 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
31 * two accesses to memory, which may be undesirable for some devices.
34 ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
35 #define in_be16(addr) \
36 ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
37 #define in_be32(addr) \
38 ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
39 #define in_le16(addr) \
40 ({ u16 __v = le16_to_cpu(*(__force volatile __le16 *) (addr)); __v; })
41 #define in_le32(addr) \
42 ({ u32 __v = le32_to_cpu(*(__force volatile __le32 *) (addr)); __v; })
44 #define out_8(addr,b) (void)((*(__force volatile u8 *) (addr)) = (b))
45 #define out_be16(addr,w) (void)((*(__force volatile u16 *) (addr)) = (w))
46 #define out_be32(addr,l) (void)((*(__force volatile u32 *) (addr)) = (l))
47 #define out_le16(addr,w) (void)((*(__force volatile __le16 *) (addr)) = cpu_to_le16(w))
48 #define out_le32(addr,l) (void)((*(__force volatile __le32 *) (addr)) = cpu_to_le32(l))
51 #define raw_inw in_be16
52 #define raw_inl in_be32
53 #define __raw_readb in_8
54 #define __raw_readw in_be16
55 #define __raw_readl in_be32
57 #define raw_outb(val,port) out_8((port),(val))
58 #define raw_outw(val,port) out_be16((port),(val))
59 #define raw_outl(val,port) out_be32((port),(val))
60 #define __raw_writeb(val,addr) out_8((addr),(val))
61 #define __raw_writew(val,addr) out_be16((addr),(val))
62 #define __raw_writel(val,addr) out_be32((addr),(val))
65 * Atari ROM port (cartridge port) ISA adapter, used for the EtherNEC NE2000
66 * network card driver.
67 * The ISA adapter connects address lines A9-A13 to ISA address lines A0-A4,
68 * and hardwires the rest of the ISA addresses for a base address of 0x300.
70 * Data lines D8-D15 are connected to ISA data lines D0-D7 for reading.
71 * For writes, address lines A1-A8 are latched to ISA data lines D0-D7
72 * (meaning the bit pattern on A1-A8 can be read back as byte).
74 * Read and write operations are distinguished by the base address used:
75 * reads are from the ROM A side range, writes are through the B side range
76 * addresses (A side base + 0x10000).
78 * Reads and writes are byte only.
80 * 16 bit reads and writes are necessary for the NetUSBee adapter's USB
81 * chipset - 16 bit words are read straight off the ROM port while 16 bit
82 * reads are split into two byte writes. The low byte is latched to the
83 * NetUSBee buffer by a read from the _read_ window (with the data pattern
84 * asserted as A1-A8 address pattern). The high byte is then written to the
85 * write range as usual, completing the write cycle.
88 #if defined(CONFIG_ATARI_ROM_ISA)
89 #define rom_in_8(addr) \
90 ({ u16 __v = (*(__force volatile u16 *) (addr)); __v >>= 8; __v; })
91 #define rom_in_be16(addr) \
92 ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
93 #define rom_in_le16(addr) \
94 ({ u16 __v = le16_to_cpu(*(__force volatile u16 *) (addr)); __v; })
96 #define rom_out_8(addr, b) \
97 ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
98 __w = ((*(__force volatile u8 *) ((_addr | 0x10000) + (__v<<1)))); })
99 #define rom_out_be16(addr, w) \
100 ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
101 __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v & 0xFF)<<1)))); \
102 __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v >> 8)<<1)))); })
103 #define rom_out_le16(addr, w) \
104 ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
105 __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v >> 8)<<1)))); \
106 __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v & 0xFF)<<1)))); })
108 #define raw_rom_inb rom_in_8
109 #define raw_rom_inw rom_in_be16
111 #define raw_rom_outb(val, port) rom_out_8((port), (val))
112 #define raw_rom_outw(val, port) rom_out_be16((port), (val))
113 #endif /* CONFIG_ATARI_ROM_ISA */
115 static inline void raw_insb(volatile u8 __iomem
*port
, u8
*buf
, unsigned int len
)
119 for (i
= 0; i
< len
; i
++)
123 static inline void raw_outsb(volatile u8 __iomem
*port
, const u8
*buf
,
128 for (i
= 0; i
< len
; i
++)
132 static inline void raw_insw(volatile u16 __iomem
*port
, u16
*buf
, unsigned int nr
)
139 "1: movew %2@,%0@+; dbra %1,1b"
140 : "=a" (buf
), "=d" (tmp
)
141 : "a" (port
), "0" (buf
),
165 : "=a" (buf
), "=d" (tmp
)
166 : "a" (port
), "0" (buf
),
171 static inline void raw_outsw(volatile u16 __iomem
*port
, const u16
*buf
,
179 "1: movew %0@+,%2@; dbra %1,1b"
180 : "=a" (buf
), "=d" (tmp
)
181 : "a" (port
), "0" (buf
),
205 : "=a" (buf
), "=d" (tmp
)
206 : "a" (port
), "0" (buf
),
211 static inline void raw_insl(volatile u32 __iomem
*port
, u32
*buf
, unsigned int nr
)
218 "1: movel %2@,%0@+; dbra %1,1b"
219 : "=a" (buf
), "=d" (tmp
)
220 : "a" (port
), "0" (buf
),
244 : "=a" (buf
), "=d" (tmp
)
245 : "a" (port
), "0" (buf
),
250 static inline void raw_outsl(volatile u32 __iomem
*port
, const u32
*buf
,
258 "1: movel %0@+,%2@; dbra %1,1b"
259 : "=a" (buf
), "=d" (tmp
)
260 : "a" (port
), "0" (buf
),
284 : "=a" (buf
), "=d" (tmp
)
285 : "a" (port
), "0" (buf
),
291 static inline void raw_insw_swapw(volatile u16 __iomem
*port
, u16
*buf
,
296 ("\tmovel %0,%/a0\n\t"
300 "1:\tmovew %/a0@,%/d0\n\t"
302 "movew %/d0,%/a1@+\n\t"
305 : "g" (port
), "g" (buf
), "g" (nr
)
306 : "d0", "a0", "a1", "d6");
314 "1:\tmovew %/a0@,%/d0\n\t"
316 "movew %/d0,%/a1@+\n\t"
317 "movew %/a0@,%/d0\n\t"
319 "movew %/d0,%/a1@+\n\t"
320 "movew %/a0@,%/d0\n\t"
322 "movew %/d0,%/a1@+\n\t"
323 "movew %/a0@,%/d0\n\t"
325 "movew %/d0,%/a1@+\n\t"
326 "movew %/a0@,%/d0\n\t"
328 "movew %/d0,%/a1@+\n\t"
329 "movew %/a0@,%/d0\n\t"
331 "movew %/d0,%/a1@+\n\t"
332 "movew %/a0@,%/d0\n\t"
334 "movew %/d0,%/a1@+\n\t"
335 "movew %/a0@,%/d0\n\t"
337 "movew %/d0,%/a1@+\n\t"
340 : "g" (port
), "g" (buf
), "g" (nr
)
341 : "d0", "a0", "a1", "d6");
344 static inline void raw_outsw_swapw(volatile u16 __iomem
*port
, const u16
*buf
,
353 "1:\tmovew %/a1@+,%/d0\n\t"
355 "movew %/d0,%/a0@\n\t"
358 : "g" (port
), "g" (buf
), "g" (nr
)
359 : "d0", "a0", "a1", "d6");
367 "1:\tmovew %/a1@+,%/d0\n\t"
369 "movew %/d0,%/a0@\n\t"
370 "movew %/a1@+,%/d0\n\t"
372 "movew %/d0,%/a0@\n\t"
373 "movew %/a1@+,%/d0\n\t"
375 "movew %/d0,%/a0@\n\t"
376 "movew %/a1@+,%/d0\n\t"
378 "movew %/d0,%/a0@\n\t"
379 "movew %/a1@+,%/d0\n\t"
381 "movew %/d0,%/a0@\n\t"
382 "movew %/a1@+,%/d0\n\t"
384 "movew %/d0,%/a0@\n\t"
385 "movew %/a1@+,%/d0\n\t"
387 "movew %/d0,%/a0@\n\t"
388 "movew %/a1@+,%/d0\n\t"
390 "movew %/d0,%/a0@\n\t"
393 : "g" (port
), "g" (buf
), "g" (nr
)
394 : "d0", "a0", "a1", "d6");
398 #if defined(CONFIG_ATARI_ROM_ISA)
399 static inline void raw_rom_insb(volatile u8 __iomem
*port
, u8
*buf
, unsigned int len
)
403 for (i
= 0; i
< len
; i
++)
404 *buf
++ = rom_in_8(port
);
407 static inline void raw_rom_outsb(volatile u8 __iomem
*port
, const u8
*buf
,
412 for (i
= 0; i
< len
; i
++)
413 rom_out_8(port
, *buf
++);
416 static inline void raw_rom_insw(volatile u16 __iomem
*port
, u16
*buf
,
421 for (i
= 0; i
< nr
; i
++)
422 *buf
++ = rom_in_be16(port
);
425 static inline void raw_rom_outsw(volatile u16 __iomem
*port
, const u16
*buf
,
430 for (i
= 0; i
< nr
; i
++)
431 rom_out_be16(port
, *buf
++);
434 static inline void raw_rom_insw_swapw(volatile u16 __iomem
*port
, u16
*buf
,
439 for (i
= 0; i
< nr
; i
++)
440 *buf
++ = rom_in_le16(port
);
443 static inline void raw_rom_outsw_swapw(volatile u16 __iomem
*port
, const u16
*buf
,
448 for (i
= 0; i
< nr
; i
++)
449 rom_out_le16(port
, *buf
++);
451 #endif /* CONFIG_ATARI_ROM_ISA */
453 #endif /* __KERNEL__ */
455 #endif /* _RAW_IO_H */