raw_io.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * linux/include/asm-m68k/raw_io.h
  3. *
  4. * 10/20/00 RZ: - created from bits of io.h and ide.h to cleanup namespace
  5. *
  6. */
  7. #ifndef _RAW_IO_H
  8. #define _RAW_IO_H
  9. #ifdef __KERNEL__
  10. #include <asm/byteorder.h>
  11. /* Values for nocacheflag and cmode */
  12. #define IOMAP_FULL_CACHING 0
  13. #define IOMAP_NOCACHE_SER 1
  14. #define IOMAP_NOCACHE_NONSER 2
  15. #define IOMAP_WRITETHROUGH 3
  16. extern void iounmap(void __iomem *addr);
  17. extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size,
  18. int cacheflag);
  19. extern void __iounmap(void *addr, unsigned long size);
  20. /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
  21. * two accesses to memory, which may be undesirable for some devices.
  22. */
  23. #define in_8(addr) \
  24. ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
  25. #define in_be16(addr) \
  26. ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
  27. #define in_be32(addr) \
  28. ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
  29. #define in_le16(addr) \
  30. ({ u16 __v = le16_to_cpu(*(__force volatile __le16 *) (addr)); __v; })
  31. #define in_le32(addr) \
  32. ({ u32 __v = le32_to_cpu(*(__force volatile __le32 *) (addr)); __v; })
  33. #define out_8(addr,b) (void)((*(__force volatile u8 *) (addr)) = (b))
  34. #define out_be16(addr,w) (void)((*(__force volatile u16 *) (addr)) = (w))
  35. #define out_be32(addr,l) (void)((*(__force volatile u32 *) (addr)) = (l))
  36. #define out_le16(addr,w) (void)((*(__force volatile __le16 *) (addr)) = cpu_to_le16(w))
  37. #define out_le32(addr,l) (void)((*(__force volatile __le32 *) (addr)) = cpu_to_le32(l))
  38. #define raw_inb in_8
  39. #define raw_inw in_be16
  40. #define raw_inl in_be32
  41. #define __raw_readb in_8
  42. #define __raw_readw in_be16
  43. #define __raw_readl in_be32
  44. #define raw_outb(val,port) out_8((port),(val))
  45. #define raw_outw(val,port) out_be16((port),(val))
  46. #define raw_outl(val,port) out_be32((port),(val))
  47. #define __raw_writeb(val,addr) out_8((addr),(val))
  48. #define __raw_writew(val,addr) out_be16((addr),(val))
  49. #define __raw_writel(val,addr) out_be32((addr),(val))
  50. /*
  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.
  55. *
  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).
  59. *
  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).
  63. *
  64. * Reads and writes are byte only.
  65. *
  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.
  72. */
  73. #if defined(CONFIG_ATARI_ROM_ISA)
  74. #define rom_in_8(addr) \
  75. ({ u16 __v = (*(__force volatile u16 *) (addr)); __v >>= 8; __v; })
  76. #define rom_in_be16(addr) \
  77. ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
  78. #define rom_in_le16(addr) \
  79. ({ u16 __v = le16_to_cpu(*(__force volatile u16 *) (addr)); __v; })
  80. #define rom_out_8(addr, b) \
  81. ({u8 __w, __v = (b); u32 _addr = ((u32) (addr)); \
  82. __w = ((*(__force volatile u8 *) ((_addr | 0x10000) + (__v<<1)))); })
  83. #define rom_out_be16(addr, w) \
  84. ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
  85. __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v & 0xFF)<<1)))); \
  86. __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v >> 8)<<1)))); })
  87. #define rom_out_le16(addr, w) \
  88. ({u16 __w, __v = (w); u32 _addr = ((u32) (addr)); \
  89. __w = ((*(__force volatile u16 *) ((_addr & 0xFFFF0000UL) + ((__v >> 8)<<1)))); \
  90. __w = ((*(__force volatile u16 *) ((_addr | 0x10000) + ((__v & 0xFF)<<1)))); })
  91. #define raw_rom_inb rom_in_8
  92. #define raw_rom_inw rom_in_be16
  93. #define raw_rom_outb(val, port) rom_out_8((port), (val))
  94. #define raw_rom_outw(val, port) rom_out_be16((port), (val))
  95. #endif /* CONFIG_ATARI_ROM_ISA */
  96. static inline void raw_insb(volatile u8 __iomem *port, u8 *buf, unsigned int len)
  97. {
  98. unsigned int i;
  99. for (i = 0; i < len; i++)
  100. *buf++ = in_8(port);
  101. }
  102. static inline void raw_outsb(volatile u8 __iomem *port, const u8 *buf,
  103. unsigned int len)
  104. {
  105. unsigned int i;
  106. for (i = 0; i < len; i++)
  107. out_8(port, *buf++);
  108. }
  109. static inline void raw_insw(volatile u16 __iomem *port, u16 *buf, unsigned int nr)
  110. {
  111. unsigned int tmp;
  112. if (nr & 15) {
  113. tmp = (nr & 15) - 1;
  114. asm volatile (
  115. "1: movew %2@,%0@+; dbra %1,1b"
  116. : "=a" (buf), "=d" (tmp)
  117. : "a" (port), "0" (buf),
  118. "1" (tmp));
  119. }
  120. if (nr >> 4) {
  121. tmp = (nr >> 4) - 1;
  122. asm volatile (
  123. "1: "
  124. "movew %2@,%0@+; "
  125. "movew %2@,%0@+; "
  126. "movew %2@,%0@+; "
  127. "movew %2@,%0@+; "
  128. "movew %2@,%0@+; "
  129. "movew %2@,%0@+; "
  130. "movew %2@,%0@+; "
  131. "movew %2@,%0@+; "
  132. "movew %2@,%0@+; "
  133. "movew %2@,%0@+; "
  134. "movew %2@,%0@+; "
  135. "movew %2@,%0@+; "
  136. "movew %2@,%0@+; "
  137. "movew %2@,%0@+; "
  138. "movew %2@,%0@+; "
  139. "movew %2@,%0@+; "
  140. "dbra %1,1b"
  141. : "=a" (buf), "=d" (tmp)
  142. : "a" (port), "0" (buf),
  143. "1" (tmp));
  144. }
  145. }
  146. static inline void raw_outsw(volatile u16 __iomem *port, const u16 *buf,
  147. unsigned int nr)
  148. {
  149. unsigned int tmp;
  150. if (nr & 15) {
  151. tmp = (nr & 15) - 1;
  152. asm volatile (
  153. "1: movew %0@+,%2@; dbra %1,1b"
  154. : "=a" (buf), "=d" (tmp)
  155. : "a" (port), "0" (buf),
  156. "1" (tmp));
  157. }
  158. if (nr >> 4) {
  159. tmp = (nr >> 4) - 1;
  160. asm volatile (
  161. "1: "
  162. "movew %0@+,%2@; "
  163. "movew %0@+,%2@; "
  164. "movew %0@+,%2@; "
  165. "movew %0@+,%2@; "
  166. "movew %0@+,%2@; "
  167. "movew %0@+,%2@; "
  168. "movew %0@+,%2@; "
  169. "movew %0@+,%2@; "
  170. "movew %0@+,%2@; "
  171. "movew %0@+,%2@; "
  172. "movew %0@+,%2@; "
  173. "movew %0@+,%2@; "
  174. "movew %0@+,%2@; "
  175. "movew %0@+,%2@; "
  176. "movew %0@+,%2@; "
  177. "movew %0@+,%2@; "
  178. "dbra %1,1b"
  179. : "=a" (buf), "=d" (tmp)
  180. : "a" (port), "0" (buf),
  181. "1" (tmp));
  182. }
  183. }
  184. static inline void raw_insl(volatile u32 __iomem *port, u32 *buf, unsigned int nr)
  185. {
  186. unsigned int tmp;
  187. if (nr & 15) {
  188. tmp = (nr & 15) - 1;
  189. asm volatile (
  190. "1: movel %2@,%0@+; dbra %1,1b"
  191. : "=a" (buf), "=d" (tmp)
  192. : "a" (port), "0" (buf),
  193. "1" (tmp));
  194. }
  195. if (nr >> 4) {
  196. tmp = (nr >> 4) - 1;
  197. asm volatile (
  198. "1: "
  199. "movel %2@,%0@+; "
  200. "movel %2@,%0@+; "
  201. "movel %2@,%0@+; "
  202. "movel %2@,%0@+; "
  203. "movel %2@,%0@+; "
  204. "movel %2@,%0@+; "
  205. "movel %2@,%0@+; "
  206. "movel %2@,%0@+; "
  207. "movel %2@,%0@+; "
  208. "movel %2@,%0@+; "
  209. "movel %2@,%0@+; "
  210. "movel %2@,%0@+; "
  211. "movel %2@,%0@+; "
  212. "movel %2@,%0@+; "
  213. "movel %2@,%0@+; "
  214. "movel %2@,%0@+; "
  215. "dbra %1,1b"
  216. : "=a" (buf), "=d" (tmp)
  217. : "a" (port), "0" (buf),
  218. "1" (tmp));
  219. }
  220. }
  221. static inline void raw_outsl(volatile u32 __iomem *port, const u32 *buf,
  222. unsigned int nr)
  223. {
  224. unsigned int tmp;
  225. if (nr & 15) {
  226. tmp = (nr & 15) - 1;
  227. asm volatile (
  228. "1: movel %0@+,%2@; dbra %1,1b"
  229. : "=a" (buf), "=d" (tmp)
  230. : "a" (port), "0" (buf),
  231. "1" (tmp));
  232. }
  233. if (nr >> 4) {
  234. tmp = (nr >> 4) - 1;
  235. asm volatile (
  236. "1: "
  237. "movel %0@+,%2@; "
  238. "movel %0@+,%2@; "
  239. "movel %0@+,%2@; "
  240. "movel %0@+,%2@; "
  241. "movel %0@+,%2@; "
  242. "movel %0@+,%2@; "
  243. "movel %0@+,%2@; "
  244. "movel %0@+,%2@; "
  245. "movel %0@+,%2@; "
  246. "movel %0@+,%2@; "
  247. "movel %0@+,%2@; "
  248. "movel %0@+,%2@; "
  249. "movel %0@+,%2@; "
  250. "movel %0@+,%2@; "
  251. "movel %0@+,%2@; "
  252. "movel %0@+,%2@; "
  253. "dbra %1,1b"
  254. : "=a" (buf), "=d" (tmp)
  255. : "a" (port), "0" (buf),
  256. "1" (tmp));
  257. }
  258. }
  259. static inline void raw_insw_swapw(volatile u16 __iomem *port, u16 *buf,
  260. unsigned int nr)
  261. {
  262. if ((nr) % 8)
  263. __asm__ __volatile__
  264. ("\tmovel %0,%/a0\n\t"
  265. "movel %1,%/a1\n\t"
  266. "movel %2,%/d6\n\t"
  267. "subql #1,%/d6\n"
  268. "1:\tmovew %/a0@,%/d0\n\t"
  269. "rolw #8,%/d0\n\t"
  270. "movew %/d0,%/a1@+\n\t"
  271. "dbra %/d6,1b"
  272. :
  273. : "g" (port), "g" (buf), "g" (nr)
  274. : "d0", "a0", "a1", "d6");
  275. else
  276. __asm__ __volatile__
  277. ("movel %0,%/a0\n\t"
  278. "movel %1,%/a1\n\t"
  279. "movel %2,%/d6\n\t"
  280. "lsrl #3,%/d6\n\t"
  281. "subql #1,%/d6\n"
  282. "1:\tmovew %/a0@,%/d0\n\t"
  283. "rolw #8,%/d0\n\t"
  284. "movew %/d0,%/a1@+\n\t"
  285. "movew %/a0@,%/d0\n\t"
  286. "rolw #8,%/d0\n\t"
  287. "movew %/d0,%/a1@+\n\t"
  288. "movew %/a0@,%/d0\n\t"
  289. "rolw #8,%/d0\n\t"
  290. "movew %/d0,%/a1@+\n\t"
  291. "movew %/a0@,%/d0\n\t"
  292. "rolw #8,%/d0\n\t"
  293. "movew %/d0,%/a1@+\n\t"
  294. "movew %/a0@,%/d0\n\t"
  295. "rolw #8,%/d0\n\t"
  296. "movew %/d0,%/a1@+\n\t"
  297. "movew %/a0@,%/d0\n\t"
  298. "rolw #8,%/d0\n\t"
  299. "movew %/d0,%/a1@+\n\t"
  300. "movew %/a0@,%/d0\n\t"
  301. "rolw #8,%/d0\n\t"
  302. "movew %/d0,%/a1@+\n\t"
  303. "movew %/a0@,%/d0\n\t"
  304. "rolw #8,%/d0\n\t"
  305. "movew %/d0,%/a1@+\n\t"
  306. "dbra %/d6,1b"
  307. :
  308. : "g" (port), "g" (buf), "g" (nr)
  309. : "d0", "a0", "a1", "d6");
  310. }
  311. static inline void raw_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
  312. unsigned int nr)
  313. {
  314. if ((nr) % 8)
  315. __asm__ __volatile__
  316. ("movel %0,%/a0\n\t"
  317. "movel %1,%/a1\n\t"
  318. "movel %2,%/d6\n\t"
  319. "subql #1,%/d6\n"
  320. "1:\tmovew %/a1@+,%/d0\n\t"
  321. "rolw #8,%/d0\n\t"
  322. "movew %/d0,%/a0@\n\t"
  323. "dbra %/d6,1b"
  324. :
  325. : "g" (port), "g" (buf), "g" (nr)
  326. : "d0", "a0", "a1", "d6");
  327. else
  328. __asm__ __volatile__
  329. ("movel %0,%/a0\n\t"
  330. "movel %1,%/a1\n\t"
  331. "movel %2,%/d6\n\t"
  332. "lsrl #3,%/d6\n\t"
  333. "subql #1,%/d6\n"
  334. "1:\tmovew %/a1@+,%/d0\n\t"
  335. "rolw #8,%/d0\n\t"
  336. "movew %/d0,%/a0@\n\t"
  337. "movew %/a1@+,%/d0\n\t"
  338. "rolw #8,%/d0\n\t"
  339. "movew %/d0,%/a0@\n\t"
  340. "movew %/a1@+,%/d0\n\t"
  341. "rolw #8,%/d0\n\t"
  342. "movew %/d0,%/a0@\n\t"
  343. "movew %/a1@+,%/d0\n\t"
  344. "rolw #8,%/d0\n\t"
  345. "movew %/d0,%/a0@\n\t"
  346. "movew %/a1@+,%/d0\n\t"
  347. "rolw #8,%/d0\n\t"
  348. "movew %/d0,%/a0@\n\t"
  349. "movew %/a1@+,%/d0\n\t"
  350. "rolw #8,%/d0\n\t"
  351. "movew %/d0,%/a0@\n\t"
  352. "movew %/a1@+,%/d0\n\t"
  353. "rolw #8,%/d0\n\t"
  354. "movew %/d0,%/a0@\n\t"
  355. "movew %/a1@+,%/d0\n\t"
  356. "rolw #8,%/d0\n\t"
  357. "movew %/d0,%/a0@\n\t"
  358. "dbra %/d6,1b"
  359. :
  360. : "g" (port), "g" (buf), "g" (nr)
  361. : "d0", "a0", "a1", "d6");
  362. }
  363. #if defined(CONFIG_ATARI_ROM_ISA)
  364. static inline void raw_rom_insb(volatile u8 __iomem *port, u8 *buf, unsigned int len)
  365. {
  366. unsigned int i;
  367. for (i = 0; i < len; i++)
  368. *buf++ = rom_in_8(port);
  369. }
  370. static inline void raw_rom_outsb(volatile u8 __iomem *port, const u8 *buf,
  371. unsigned int len)
  372. {
  373. unsigned int i;
  374. for (i = 0; i < len; i++)
  375. rom_out_8(port, *buf++);
  376. }
  377. static inline void raw_rom_insw(volatile u16 __iomem *port, u16 *buf,
  378. unsigned int nr)
  379. {
  380. unsigned int i;
  381. for (i = 0; i < nr; i++)
  382. *buf++ = rom_in_be16(port);
  383. }
  384. static inline void raw_rom_outsw(volatile u16 __iomem *port, const u16 *buf,
  385. unsigned int nr)
  386. {
  387. unsigned int i;
  388. for (i = 0; i < nr; i++)
  389. rom_out_be16(port, *buf++);
  390. }
  391. static inline void raw_rom_insw_swapw(volatile u16 __iomem *port, u16 *buf,
  392. unsigned int nr)
  393. {
  394. unsigned int i;
  395. for (i = 0; i < nr; i++)
  396. *buf++ = rom_in_le16(port);
  397. }
  398. static inline void raw_rom_outsw_swapw(volatile u16 __iomem *port, const u16 *buf,
  399. unsigned int nr)
  400. {
  401. unsigned int i;
  402. for (i = 0; i < nr; i++)
  403. rom_out_le16(port, *buf++);
  404. }
  405. #endif /* CONFIG_ATARI_ROM_ISA */
  406. #endif /* __KERNEL__ */
  407. #endif /* _RAW_IO_H */