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>
16 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
17 * two accesses to memory, which may be undesirable for some devices.
20 ({ u8 __v = (*(__force const volatile u8 *) (unsigned long)(addr)); __v; })
21 #define in_be16(addr) \
22 ({ u16 __v = (*(__force const volatile u16 *) (unsigned long)(addr)); __v; })
23 #define in_be32(addr) \
24 ({ u32 __v = (*(__force const volatile u32 *) (unsigned long)(addr)); __v; })
25 #define in_le16(addr) \
26 ({ u16 __v = le16_to_cpu(*(__force const volatile __le16 *) (unsigned long)(addr)); __v; })
27 #define in_le32(addr) \
28 ({ u32 __v = le32_to_cpu(*(__force const volatile __le32 *) (unsigned long)(addr)); __v; })
30 #define out_8(addr,b) (void)((*(__force volatile u8 *) (unsigned long)(addr)) = (b))
31 #define out_be16(addr,w) (void)((*(__force volatile u16 *) (unsigned long)(addr)) = (w))
32 #define out_be32(addr,l) (void)((*(__force volatile u32 *) (unsigned long)(addr)) = (l))
33 #define out_le16(addr,w) (void)((*(__force volatile __le16 *) (unsigned long)(addr)) = cpu_to_le16(w))
34 #define out_le32(addr,l) (void)((*(__force volatile __le32 *) (unsigned long)(addr)) = cpu_to_le32(l))
37 #define raw_inw in_be16
38 #define raw_inl in_be32
39 #define __raw_readb in_8
40 #define __raw_readw in_be16
41 #define __raw_readl in_be32
43 #define raw_outb(val,port) out_8((port),(val))
44 #define raw_outw(val,port) out_be16((port),(val))
45 #define raw_outl(val,port) out_be32((port),(val))
46 #define __raw_writeb(val,addr) out_8((addr),(val))
47 #define __raw_writew(val,addr) out_be16((addr),(val))
48 #define __raw_writel(val,addr) out_be32((addr),(val))
51 * Atari ROM port (cartridge port) ISA adapter, used for the EtherNEC NE2000
52 * network card driver.
53 * The ISA adapter connects address lines A9-A13 to ISA address lines A0-A4,
54 * and hardwires the rest of the ISA addresses for a base address of 0x300.
56 * Data lines D8-D15 are connected to ISA data lines D0-D7 for reading.
57 * For writes, address lines A1-A8 are latched to ISA data lines D0-D7
58 * (meaning the bit pattern on A1-A8 can be read back as byte).
60 * Read and write operations are distinguished by the base address used:
61 * reads are from the ROM A side range, writes are through the B side range
62 * addresses (A side base + 0x10000).
64 * Reads and writes are byte only.
66 * 16 bit reads and writes are necessary for the NetUSBee adapter's USB
67 * chipset - 16 bit words are read straight off the ROM port while 16 bit
68 * reads are split into two byte writes. The low byte is latched to the
69 * NetUSBee buffer by a read from the _read_ window (with the data pattern
70 * asserted as A1-A8 address pattern). The high byte is then written to the
71 * write range as usual, completing the write cycle.
74 #if defined(CONFIG_ATARI_ROM_ISA)
75 #define rom_in_8(addr) \
76 ({ u16 __v = (*(__force const volatile u16 *) (addr)); __v >>= 8; __v; })
77 #define rom_in_be16(addr) \
78 ({ u16 __v = (*(__force const volatile u16 *) (addr)); __v; })
79 #define rom_in_le16(addr) \
80 ({ u16 __v = le16_to_cpu(*(__force const volatile u16 *) (addr)); __v; })
82 #define rom_out_8(addr, b) \
83 (void)({u8 __maybe_unused __w, __v = (b); u32 _addr = ((u32) (addr)); \
84 __w = ((*(__force volatile u8 *) ((_addr | 0x10000) + (__v<<1)))); })
85 #define rom_out_be16(addr, w) \
86 (void)({u16 __maybe_unused __w, __v = (w); u32 _addr = ((u32) (addr)); \
87 __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v & 0xFF)<<1)))); \
88 __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v >> 8)<<1)))); })
89 #define rom_out_le16(addr, w) \
90 (void)({u16 __maybe_unused __w, __v = (w); u32 _addr = ((u32) (addr)); \
91 __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v >> 8)<<1)))); \
92 __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v & 0xFF)<<1)))); })
94 #define raw_rom_inb rom_in_8
95 #define raw_rom_inw rom_in_be16
97 #define raw_rom_outb(val, port) rom_out_8((port), (val))
98 #define raw_rom_outw(val, port) rom_out_be16((port), (val))
99 #endif /* CONFIG_ATARI_ROM_ISA */
101 static inline void raw_insb(const volatile u8 __iomem *port, u8 *buf,
106 for (i = 0; i < len; i++)
110 static inline void raw_outsb(volatile u8 __iomem *port, const u8 *buf,
118 "1: moveb %0@+,%2@; dbra %1,1b"
119 : "=a" (buf), "=d" (tmp)
120 : "a" (port), "0" (buf),
144 : "=a" (buf), "=d" (tmp)
145 : "a" (port), "0" (buf),
150 static inline void raw_insw(volatile const u16 __iomem *port, u16 *buf, unsigned int nr)
157 "1: movew %2@,%0@+; dbra %1,1b"
158 : "=a" (buf), "=d" (tmp)
159 : "a" (port), "0" (buf),
183 : "=a" (buf), "=d" (tmp)
184 : "a" (port), "0" (buf),
189 static inline void raw_outsw(volatile u16 __iomem *port, const u16 *buf,
197 "1: movew %0@+,%2@; dbra %1,1b"
198 : "=a" (buf), "=d" (tmp)
199 : "a" (port), "0" (buf),
223 : "=a" (buf), "=d" (tmp)
224 : "a" (port), "0" (buf),
229 static inline void raw_insl(const volatile u32 __iomem *port, u32 *buf, unsigned int nr)
236 "1: movel %2@,%0@+; dbra %1,1b"
237 : "=a" (buf), "=d" (tmp)
238 : "a" (port), "0" (buf),
262 : "=a" (buf), "=d" (tmp)
263 : "a" (port), "0" (buf),
268 static inline void raw_outsl(volatile u32 __iomem *port, const u32 *buf,
276 "1: movel %0@+,%2@; dbra %1,1b"
277 : "=a" (buf), "=d" (tmp)
278 : "a" (port), "0" (buf),
302 : "=a" (buf), "=d" (tmp)
303 : "a" (port), "0" (buf),
309 static inline void raw_insw_swapw(const volatile u16 __iomem *port, u16 *buf,
314 ("\tmovel %0,%/a0\n\t"
318 "1:\tmovew %/a0@,%/d0\n\t"
320 "movew %/d0,%/a1@+\n\t"
323 : "g" (port), "g" (buf), "g" (nr)
324 : "d0", "a0", "a1", "d6");
332 "1:\tmovew %/a0@,%/d0\n\t"
334 "movew %/d0,%/a1@+\n\t"
335 "movew %/a0@,%/d0\n\t"
337 "movew %/d0,%/a1@+\n\t"
338 "movew %/a0@,%/d0\n\t"
340 "movew %/d0,%/a1@+\n\t"
341 "movew %/a0@,%/d0\n\t"
343 "movew %/d0,%/a1@+\n\t"
344 "movew %/a0@,%/d0\n\t"
346 "movew %/d0,%/a1@+\n\t"
347 "movew %/a0@,%/d0\n\t"
349 "movew %/d0,%/a1@+\n\t"
350 "movew %/a0@,%/d0\n\t"
352 "movew %/d0,%/a1@+\n\t"
353 "movew %/a0@,%/d0\n\t"
355 "movew %/d0,%/a1@+\n\t"
358 : "g" (port), "g" (buf), "g" (nr)
359 : "d0", "a0", "a1", "d6");
362 static inline void raw_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
371 "1:\tmovew %/a1@+,%/d0\n\t"
373 "movew %/d0,%/a0@\n\t"
376 : "g" (port), "g" (buf), "g" (nr)
377 : "d0", "a0", "a1", "d6");
385 "1:\tmovew %/a1@+,%/d0\n\t"
387 "movew %/d0,%/a0@\n\t"
388 "movew %/a1@+,%/d0\n\t"
390 "movew %/d0,%/a0@\n\t"
391 "movew %/a1@+,%/d0\n\t"
393 "movew %/d0,%/a0@\n\t"
394 "movew %/a1@+,%/d0\n\t"
396 "movew %/d0,%/a0@\n\t"
397 "movew %/a1@+,%/d0\n\t"
399 "movew %/d0,%/a0@\n\t"
400 "movew %/a1@+,%/d0\n\t"
402 "movew %/d0,%/a0@\n\t"
403 "movew %/a1@+,%/d0\n\t"
405 "movew %/d0,%/a0@\n\t"
406 "movew %/a1@+,%/d0\n\t"
408 "movew %/d0,%/a0@\n\t"
411 : "g" (port), "g" (buf), "g" (nr)
412 : "d0", "a0", "a1", "d6");
416 #if defined(CONFIG_ATARI_ROM_ISA)
417 static inline void raw_rom_insb(const volatile u8 __iomem *port, u8 *buf,
422 for (i = 0; i < len; i++)
423 *buf++ = rom_in_8(port);
426 static inline void raw_rom_outsb(volatile u8 __iomem *port, const u8 *buf,
431 for (i = 0; i < len; i++)
432 rom_out_8(port, *buf++);
435 static inline void raw_rom_insw(const volatile u16 __iomem *port, u16 *buf,
440 for (i = 0; i < nr; i++)
441 *buf++ = rom_in_be16(port);
444 static inline void raw_rom_outsw(volatile u16 __iomem *port, const u16 *buf,
449 for (i = 0; i < nr; i++)
450 rom_out_be16(port, *buf++);
453 static inline void raw_rom_insw_swapw(const volatile u16 __iomem *port, u16 *buf,
458 for (i = 0; i < nr; i++)
459 *buf++ = rom_in_le16(port);
462 static inline void raw_rom_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
467 for (i = 0; i < nr; i++)
468 rom_out_le16(port, *buf++);
470 #endif /* CONFIG_ATARI_ROM_ISA */
472 #endif /* __KERNEL__ */
474 #endif /* _RAW_IO_H */