io.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. #ifndef _ASM_POWERPC_IO_H
  2. #define _ASM_POWERPC_IO_H
  3. #ifdef __KERNEL__
  4. /*
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. /* Check of existence of legacy devices */
  11. extern int check_legacy_ioport(unsigned long base_port);
  12. #define I8042_DATA_REG 0x60
  13. #define FDC_BASE 0x3f0
  14. /* only relevant for PReP */
  15. #define _PIDXR 0x279
  16. #define _PNPWRP 0xa79
  17. #define PNPBIOS_BASE 0xf000
  18. #include <linux/compiler.h>
  19. #include <asm/page.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/synch.h>
  22. #include <asm/delay.h>
  23. #include <asm/mmu.h>
  24. #include <asm-generic/iomap.h>
  25. #ifdef CONFIG_PPC64
  26. #include <asm/paca.h>
  27. #endif
  28. #define SIO_CONFIG_RA 0x398
  29. #define SIO_CONFIG_RD 0x399
  30. #define SLOW_DOWN_IO
  31. /* 32 bits uses slightly different variables for the various IO
  32. * bases. Most of this file only uses _IO_BASE though which we
  33. * define properly based on the platform
  34. */
  35. #ifndef CONFIG_PCI
  36. #define _IO_BASE 0
  37. #define _ISA_MEM_BASE 0
  38. #define PCI_DRAM_OFFSET 0
  39. #elif defined(CONFIG_PPC32)
  40. #define _IO_BASE isa_io_base
  41. #define _ISA_MEM_BASE isa_mem_base
  42. #define PCI_DRAM_OFFSET pci_dram_offset
  43. #else
  44. #define _IO_BASE pci_io_base
  45. #define _ISA_MEM_BASE 0
  46. #define PCI_DRAM_OFFSET 0
  47. #endif
  48. extern unsigned long isa_io_base;
  49. extern unsigned long isa_mem_base;
  50. extern unsigned long pci_io_base;
  51. extern unsigned long pci_dram_offset;
  52. #if defined(CONFIG_PPC32) && defined(CONFIG_PPC_INDIRECT_IO)
  53. #error CONFIG_PPC_INDIRECT_IO is not yet supported on 32 bits
  54. #endif
  55. /*
  56. *
  57. * Low level MMIO accessors
  58. *
  59. * This provides the non-bus specific accessors to MMIO. Those are PowerPC
  60. * specific and thus shouldn't be used in generic code. The accessors
  61. * provided here are:
  62. *
  63. * in_8, in_le16, in_be16, in_le32, in_be32, in_le64, in_be64
  64. * out_8, out_le16, out_be16, out_le32, out_be32, out_le64, out_be64
  65. * _insb, _insw_ns, _insl_ns, _outsb, _outsw_ns, _outsl_ns
  66. *
  67. * Those operate directly on a kernel virtual address. Note that the prototype
  68. * for the out_* accessors has the arguments in opposite order from the usual
  69. * linux PCI accessors. Unlike those, they take the address first and the value
  70. * next.
  71. *
  72. * Note: I might drop the _ns suffix on the stream operations soon as it is
  73. * simply normal for stream operations to not swap in the first place.
  74. *
  75. */
  76. #ifdef CONFIG_PPC64
  77. #define IO_SET_SYNC_FLAG() do { local_paca->io_sync = 1; } while(0)
  78. #else
  79. #define IO_SET_SYNC_FLAG()
  80. #endif
  81. #define DEF_MMIO_IN(name, type, insn) \
  82. static inline type name(const volatile type __iomem *addr) \
  83. { \
  84. type ret; \
  85. __asm__ __volatile__("sync;" insn ";twi 0,%0,0;isync" \
  86. : "=r" (ret) : "r" (addr), "m" (*addr)); \
  87. return ret; \
  88. }
  89. #define DEF_MMIO_OUT(name, type, insn) \
  90. static inline void name(volatile type __iomem *addr, type val) \
  91. { \
  92. __asm__ __volatile__("sync;" insn \
  93. : "=m" (*addr) : "r" (val), "r" (addr)); \
  94. IO_SET_SYNC_FLAG(); \
  95. }
  96. #define DEF_MMIO_IN_BE(name, size, insn) \
  97. DEF_MMIO_IN(name, u##size, __stringify(insn)"%U2%X2 %0,%2")
  98. #define DEF_MMIO_IN_LE(name, size, insn) \
  99. DEF_MMIO_IN(name, u##size, __stringify(insn)" %0,0,%1")
  100. #define DEF_MMIO_OUT_BE(name, size, insn) \
  101. DEF_MMIO_OUT(name, u##size, __stringify(insn)"%U0%X0 %1,%0")
  102. #define DEF_MMIO_OUT_LE(name, size, insn) \
  103. DEF_MMIO_OUT(name, u##size, __stringify(insn)" %1,0,%2")
  104. DEF_MMIO_IN_BE(in_8, 8, lbz);
  105. DEF_MMIO_IN_BE(in_be16, 16, lhz);
  106. DEF_MMIO_IN_BE(in_be32, 32, lwz);
  107. DEF_MMIO_IN_LE(in_le16, 16, lhbrx);
  108. DEF_MMIO_IN_LE(in_le32, 32, lwbrx);
  109. DEF_MMIO_OUT_BE(out_8, 8, stb);
  110. DEF_MMIO_OUT_BE(out_be16, 16, sth);
  111. DEF_MMIO_OUT_BE(out_be32, 32, stw);
  112. DEF_MMIO_OUT_LE(out_le16, 16, sthbrx);
  113. DEF_MMIO_OUT_LE(out_le32, 32, stwbrx);
  114. #ifdef __powerpc64__
  115. DEF_MMIO_OUT_BE(out_be64, 64, std);
  116. DEF_MMIO_IN_BE(in_be64, 64, ld);
  117. /* There is no asm instructions for 64 bits reverse loads and stores */
  118. static inline u64 in_le64(const volatile u64 __iomem *addr)
  119. {
  120. return swab64(in_be64(addr));
  121. }
  122. static inline void out_le64(volatile u64 __iomem *addr, u64 val)
  123. {
  124. out_be64(addr, swab64(val));
  125. }
  126. #endif /* __powerpc64__ */
  127. /*
  128. * Low level IO stream instructions are defined out of line for now
  129. */
  130. extern void _insb(const volatile u8 __iomem *addr, void *buf, long count);
  131. extern void _outsb(volatile u8 __iomem *addr,const void *buf,long count);
  132. extern void _insw_ns(const volatile u16 __iomem *addr, void *buf, long count);
  133. extern void _outsw_ns(volatile u16 __iomem *addr, const void *buf, long count);
  134. extern void _insl_ns(const volatile u32 __iomem *addr, void *buf, long count);
  135. extern void _outsl_ns(volatile u32 __iomem *addr, const void *buf, long count);
  136. /* The _ns naming is historical and will be removed. For now, just #define
  137. * the non _ns equivalent names
  138. */
  139. #define _insw _insw_ns
  140. #define _insl _insl_ns
  141. #define _outsw _outsw_ns
  142. #define _outsl _outsl_ns
  143. /*
  144. * memset_io, memcpy_toio, memcpy_fromio base implementations are out of line
  145. */
  146. extern void _memset_io(volatile void __iomem *addr, int c, unsigned long n);
  147. extern void _memcpy_fromio(void *dest, const volatile void __iomem *src,
  148. unsigned long n);
  149. extern void _memcpy_toio(volatile void __iomem *dest, const void *src,
  150. unsigned long n);
  151. /*
  152. *
  153. * PCI and standard ISA accessors
  154. *
  155. * Those are globally defined linux accessors for devices on PCI or ISA
  156. * busses. They follow the Linux defined semantics. The current implementation
  157. * for PowerPC is as close as possible to the x86 version of these, and thus
  158. * provides fairly heavy weight barriers for the non-raw versions
  159. *
  160. * In addition, they support a hook mechanism when CONFIG_PPC_INDIRECT_IO
  161. * allowing the platform to provide its own implementation of some or all
  162. * of the accessors.
  163. */
  164. /*
  165. * Include the EEH definitions when EEH is enabled only so they don't get
  166. * in the way when building for 32 bits
  167. */
  168. #ifdef CONFIG_EEH
  169. #include <asm/eeh.h>
  170. #endif
  171. /* Shortcut to the MMIO argument pointer */
  172. #define PCI_IO_ADDR volatile void __iomem *
  173. /* Indirect IO address tokens:
  174. *
  175. * When CONFIG_PPC_INDIRECT_IO is set, the platform can provide hooks
  176. * on all IOs. (Note that this is all 64 bits only for now)
  177. *
  178. * To help platforms who may need to differenciate MMIO addresses in
  179. * their hooks, a bitfield is reserved for use by the platform near the
  180. * top of MMIO addresses (not PIO, those have to cope the hard way).
  181. *
  182. * This bit field is 12 bits and is at the top of the IO virtual
  183. * addresses PCI_IO_INDIRECT_TOKEN_MASK.
  184. *
  185. * The kernel virtual space is thus:
  186. *
  187. * 0xD000000000000000 : vmalloc
  188. * 0xD000080000000000 : PCI PHB IO space
  189. * 0xD000080080000000 : ioremap
  190. * 0xD0000fffffffffff : end of ioremap region
  191. *
  192. * Since the top 4 bits are reserved as the region ID, we use thus
  193. * the next 12 bits and keep 4 bits available for the future if the
  194. * virtual address space is ever to be extended.
  195. *
  196. * The direct IO mapping operations will then mask off those bits
  197. * before doing the actual access, though that only happen when
  198. * CONFIG_PPC_INDIRECT_IO is set, thus be careful when you use that
  199. * mechanism
  200. */
  201. #ifdef CONFIG_PPC_INDIRECT_IO
  202. #define PCI_IO_IND_TOKEN_MASK 0x0fff000000000000ul
  203. #define PCI_IO_IND_TOKEN_SHIFT 48
  204. #define PCI_FIX_ADDR(addr) \
  205. ((PCI_IO_ADDR)(((unsigned long)(addr)) & ~PCI_IO_IND_TOKEN_MASK))
  206. #define PCI_GET_ADDR_TOKEN(addr) \
  207. (((unsigned long)(addr) & PCI_IO_IND_TOKEN_MASK) >> \
  208. PCI_IO_IND_TOKEN_SHIFT)
  209. #define PCI_SET_ADDR_TOKEN(addr, token) \
  210. do { \
  211. unsigned long __a = (unsigned long)(addr); \
  212. __a &= ~PCI_IO_IND_TOKEN_MASK; \
  213. __a |= ((unsigned long)(token)) << PCI_IO_IND_TOKEN_SHIFT; \
  214. (addr) = (void __iomem *)__a; \
  215. } while(0)
  216. #else
  217. #define PCI_FIX_ADDR(addr) (addr)
  218. #endif
  219. /*
  220. * Non ordered and non-swapping "raw" accessors
  221. */
  222. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  223. {
  224. return *(volatile unsigned char __force *)PCI_FIX_ADDR(addr);
  225. }
  226. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  227. {
  228. return *(volatile unsigned short __force *)PCI_FIX_ADDR(addr);
  229. }
  230. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  231. {
  232. return *(volatile unsigned int __force *)PCI_FIX_ADDR(addr);
  233. }
  234. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  235. {
  236. *(volatile unsigned char __force *)PCI_FIX_ADDR(addr) = v;
  237. }
  238. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  239. {
  240. *(volatile unsigned short __force *)PCI_FIX_ADDR(addr) = v;
  241. }
  242. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  243. {
  244. *(volatile unsigned int __force *)PCI_FIX_ADDR(addr) = v;
  245. }
  246. #ifdef __powerpc64__
  247. static inline unsigned long __raw_readq(const volatile void __iomem *addr)
  248. {
  249. return *(volatile unsigned long __force *)PCI_FIX_ADDR(addr);
  250. }
  251. static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
  252. {
  253. *(volatile unsigned long __force *)PCI_FIX_ADDR(addr) = v;
  254. }
  255. #endif /* __powerpc64__ */
  256. /*
  257. *
  258. * PCI PIO and MMIO accessors.
  259. *
  260. *
  261. * On 32 bits, PIO operations have a recovery mechanism in case they trigger
  262. * machine checks (which they occasionally do when probing non existing
  263. * IO ports on some platforms, like PowerMac and 8xx).
  264. * I always found it to be of dubious reliability and I am tempted to get
  265. * rid of it one of these days. So if you think it's important to keep it,
  266. * please voice up asap. We never had it for 64 bits and I do not intend
  267. * to port it over
  268. */
  269. #ifdef CONFIG_PPC32
  270. #define __do_in_asm(name, op) \
  271. static inline unsigned int name(unsigned int port) \
  272. { \
  273. unsigned int x; \
  274. __asm__ __volatile__( \
  275. "sync\n" \
  276. "0:" op " %0,0,%1\n" \
  277. "1: twi 0,%0,0\n" \
  278. "2: isync\n" \
  279. "3: nop\n" \
  280. "4:\n" \
  281. ".section .fixup,\"ax\"\n" \
  282. "5: li %0,-1\n" \
  283. " b 4b\n" \
  284. ".previous\n" \
  285. ".section __ex_table,\"a\"\n" \
  286. " .align 2\n" \
  287. " .long 0b,5b\n" \
  288. " .long 1b,5b\n" \
  289. " .long 2b,5b\n" \
  290. " .long 3b,5b\n" \
  291. ".previous" \
  292. : "=&r" (x) \
  293. : "r" (port + _IO_BASE)); \
  294. return x; \
  295. }
  296. #define __do_out_asm(name, op) \
  297. static inline void name(unsigned int val, unsigned int port) \
  298. { \
  299. __asm__ __volatile__( \
  300. "sync\n" \
  301. "0:" op " %0,0,%1\n" \
  302. "1: sync\n" \
  303. "2:\n" \
  304. ".section __ex_table,\"a\"\n" \
  305. " .align 2\n" \
  306. " .long 0b,2b\n" \
  307. " .long 1b,2b\n" \
  308. ".previous" \
  309. : : "r" (val), "r" (port + _IO_BASE)); \
  310. }
  311. __do_in_asm(_rec_inb, "lbzx")
  312. __do_in_asm(_rec_inw, "lhbrx")
  313. __do_in_asm(_rec_inl, "lwbrx")
  314. __do_out_asm(_rec_outb, "stbx")
  315. __do_out_asm(_rec_outw, "sthbrx")
  316. __do_out_asm(_rec_outl, "stwbrx")
  317. #endif /* CONFIG_PPC32 */
  318. /* The "__do_*" operations below provide the actual "base" implementation
  319. * for each of the defined acccessor. Some of them use the out_* functions
  320. * directly, some of them still use EEH, though we might change that in the
  321. * future. Those macros below provide the necessary argument swapping and
  322. * handling of the IO base for PIO.
  323. *
  324. * They are themselves used by the macros that define the actual accessors
  325. * and can be used by the hooks if any.
  326. *
  327. * Note that PIO operations are always defined in terms of their corresonding
  328. * MMIO operations. That allows platforms like iSeries who want to modify the
  329. * behaviour of both to only hook on the MMIO version and get both. It's also
  330. * possible to hook directly at the toplevel PIO operation if they have to
  331. * be handled differently
  332. */
  333. #define __do_writeb(val, addr) out_8(PCI_FIX_ADDR(addr), val)
  334. #define __do_writew(val, addr) out_le16(PCI_FIX_ADDR(addr), val)
  335. #define __do_writel(val, addr) out_le32(PCI_FIX_ADDR(addr), val)
  336. #define __do_writeq(val, addr) out_le64(PCI_FIX_ADDR(addr), val)
  337. #define __do_writew_be(val, addr) out_be16(PCI_FIX_ADDR(addr), val)
  338. #define __do_writel_be(val, addr) out_be32(PCI_FIX_ADDR(addr), val)
  339. #define __do_writeq_be(val, addr) out_be64(PCI_FIX_ADDR(addr), val)
  340. #ifdef CONFIG_EEH
  341. #define __do_readb(addr) eeh_readb(PCI_FIX_ADDR(addr))
  342. #define __do_readw(addr) eeh_readw(PCI_FIX_ADDR(addr))
  343. #define __do_readl(addr) eeh_readl(PCI_FIX_ADDR(addr))
  344. #define __do_readq(addr) eeh_readq(PCI_FIX_ADDR(addr))
  345. #define __do_readw_be(addr) eeh_readw_be(PCI_FIX_ADDR(addr))
  346. #define __do_readl_be(addr) eeh_readl_be(PCI_FIX_ADDR(addr))
  347. #define __do_readq_be(addr) eeh_readq_be(PCI_FIX_ADDR(addr))
  348. #else /* CONFIG_EEH */
  349. #define __do_readb(addr) in_8(PCI_FIX_ADDR(addr))
  350. #define __do_readw(addr) in_le16(PCI_FIX_ADDR(addr))
  351. #define __do_readl(addr) in_le32(PCI_FIX_ADDR(addr))
  352. #define __do_readq(addr) in_le64(PCI_FIX_ADDR(addr))
  353. #define __do_readw_be(addr) in_be16(PCI_FIX_ADDR(addr))
  354. #define __do_readl_be(addr) in_be32(PCI_FIX_ADDR(addr))
  355. #define __do_readq_be(addr) in_be64(PCI_FIX_ADDR(addr))
  356. #endif /* !defined(CONFIG_EEH) */
  357. #ifdef CONFIG_PPC32
  358. #define __do_outb(val, port) _rec_outb(val, port)
  359. #define __do_outw(val, port) _rec_outw(val, port)
  360. #define __do_outl(val, port) _rec_outl(val, port)
  361. #define __do_inb(port) _rec_inb(port)
  362. #define __do_inw(port) _rec_inw(port)
  363. #define __do_inl(port) _rec_inl(port)
  364. #else /* CONFIG_PPC32 */
  365. #define __do_outb(val, port) writeb(val,(PCI_IO_ADDR)_IO_BASE+port);
  366. #define __do_outw(val, port) writew(val,(PCI_IO_ADDR)_IO_BASE+port);
  367. #define __do_outl(val, port) writel(val,(PCI_IO_ADDR)_IO_BASE+port);
  368. #define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port);
  369. #define __do_inw(port) readw((PCI_IO_ADDR)_IO_BASE + port);
  370. #define __do_inl(port) readl((PCI_IO_ADDR)_IO_BASE + port);
  371. #endif /* !CONFIG_PPC32 */
  372. #ifdef CONFIG_EEH
  373. #define __do_readsb(a, b, n) eeh_readsb(PCI_FIX_ADDR(a), (b), (n))
  374. #define __do_readsw(a, b, n) eeh_readsw(PCI_FIX_ADDR(a), (b), (n))
  375. #define __do_readsl(a, b, n) eeh_readsl(PCI_FIX_ADDR(a), (b), (n))
  376. #else /* CONFIG_EEH */
  377. #define __do_readsb(a, b, n) _insb(PCI_FIX_ADDR(a), (b), (n))
  378. #define __do_readsw(a, b, n) _insw(PCI_FIX_ADDR(a), (b), (n))
  379. #define __do_readsl(a, b, n) _insl(PCI_FIX_ADDR(a), (b), (n))
  380. #endif /* !CONFIG_EEH */
  381. #define __do_writesb(a, b, n) _outsb(PCI_FIX_ADDR(a),(b),(n))
  382. #define __do_writesw(a, b, n) _outsw(PCI_FIX_ADDR(a),(b),(n))
  383. #define __do_writesl(a, b, n) _outsl(PCI_FIX_ADDR(a),(b),(n))
  384. #define __do_insb(p, b, n) readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  385. #define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  386. #define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  387. #define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
  388. #define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
  389. #define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
  390. #define __do_memset_io(addr, c, n) \
  391. _memset_io(PCI_FIX_ADDR(addr), c, n)
  392. #define __do_memcpy_toio(dst, src, n) \
  393. _memcpy_toio(PCI_FIX_ADDR(dst), src, n)
  394. #ifdef CONFIG_EEH
  395. #define __do_memcpy_fromio(dst, src, n) \
  396. eeh_memcpy_fromio(dst, PCI_FIX_ADDR(src), n)
  397. #else /* CONFIG_EEH */
  398. #define __do_memcpy_fromio(dst, src, n) \
  399. _memcpy_fromio(dst,PCI_FIX_ADDR(src),n)
  400. #endif /* !CONFIG_EEH */
  401. #ifdef CONFIG_PPC_INDIRECT_IO
  402. #define DEF_PCI_HOOK(x) x
  403. #else
  404. #define DEF_PCI_HOOK(x) NULL
  405. #endif
  406. /* Structure containing all the hooks */
  407. extern struct ppc_pci_io {
  408. #define DEF_PCI_AC_RET(name, ret, at, al) ret (*name) at;
  409. #define DEF_PCI_AC_NORET(name, at, al) void (*name) at;
  410. #include <asm/io-defs.h>
  411. #undef DEF_PCI_AC_RET
  412. #undef DEF_PCI_AC_NORET
  413. } ppc_pci_io;
  414. /* The inline wrappers */
  415. #define DEF_PCI_AC_RET(name, ret, at, al) \
  416. static inline ret name at \
  417. { \
  418. if (DEF_PCI_HOOK(ppc_pci_io.name) != NULL) \
  419. return ppc_pci_io.name al; \
  420. return __do_##name al; \
  421. }
  422. #define DEF_PCI_AC_NORET(name, at, al) \
  423. static inline void name at \
  424. { \
  425. if (DEF_PCI_HOOK(ppc_pci_io.name) != NULL) \
  426. ppc_pci_io.name al; \
  427. else \
  428. __do_##name al; \
  429. }
  430. #include <asm/io-defs.h>
  431. #undef DEF_PCI_AC_RET
  432. #undef DEF_PCI_AC_NORET
  433. /* Some drivers check for the presence of readq & writeq with
  434. * a #ifdef, so we make them happy here.
  435. */
  436. #ifdef __powerpc64__
  437. #define readq readq
  438. #define writeq writeq
  439. #endif
  440. #ifdef CONFIG_NOT_COHERENT_CACHE
  441. #define dma_cache_inv(_start,_size) \
  442. invalidate_dcache_range(_start, (_start + _size))
  443. #define dma_cache_wback(_start,_size) \
  444. clean_dcache_range(_start, (_start + _size))
  445. #define dma_cache_wback_inv(_start,_size) \
  446. flush_dcache_range(_start, (_start + _size))
  447. #else /* CONFIG_NOT_COHERENT_CACHE */
  448. #define dma_cache_inv(_start,_size) do { } while (0)
  449. #define dma_cache_wback(_start,_size) do { } while (0)
  450. #define dma_cache_wback_inv(_start,_size) do { } while (0)
  451. #endif /* !CONFIG_NOT_COHERENT_CACHE */
  452. /*
  453. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  454. * access
  455. */
  456. #define xlate_dev_mem_ptr(p) __va(p)
  457. /*
  458. * Convert a virtual cached pointer to an uncached pointer
  459. */
  460. #define xlate_dev_kmem_ptr(p) p
  461. /*
  462. * We don't do relaxed operations yet, at least not with this semantic
  463. */
  464. #define readb_relaxed(addr) readb(addr)
  465. #define readw_relaxed(addr) readw(addr)
  466. #define readl_relaxed(addr) readl(addr)
  467. #define readq_relaxed(addr) readq(addr)
  468. #ifdef CONFIG_PPC32
  469. #define mmiowb()
  470. #else
  471. /*
  472. * Enforce synchronisation of stores vs. spin_unlock
  473. * (this does it explicitely, though our implementation of spin_unlock
  474. * does it implicitely too)
  475. */
  476. static inline void mmiowb(void)
  477. {
  478. unsigned long tmp;
  479. __asm__ __volatile__("sync; li %0,0; stb %0,%1(13)"
  480. : "=&r" (tmp) : "i" (offsetof(struct paca_struct, io_sync))
  481. : "memory");
  482. }
  483. #endif /* !CONFIG_PPC32 */
  484. static inline void iosync(void)
  485. {
  486. __asm__ __volatile__ ("sync" : : : "memory");
  487. }
  488. /* Enforce in-order execution of data I/O.
  489. * No distinction between read/write on PPC; use eieio for all three.
  490. * Those are fairly week though. They don't provide a barrier between
  491. * MMIO and cacheable storage nor do they provide a barrier vs. locks,
  492. * they only provide barriers between 2 __raw MMIO operations and
  493. * possibly break write combining.
  494. */
  495. #define iobarrier_rw() eieio()
  496. #define iobarrier_r() eieio()
  497. #define iobarrier_w() eieio()
  498. /*
  499. * output pause versions need a delay at least for the
  500. * w83c105 ide controller in a p610.
  501. */
  502. #define inb_p(port) inb(port)
  503. #define outb_p(val, port) (udelay(1), outb((val), (port)))
  504. #define inw_p(port) inw(port)
  505. #define outw_p(val, port) (udelay(1), outw((val), (port)))
  506. #define inl_p(port) inl(port)
  507. #define outl_p(val, port) (udelay(1), outl((val), (port)))
  508. #define IO_SPACE_LIMIT ~(0UL)
  509. /**
  510. * ioremap - map bus memory into CPU space
  511. * @address: bus address of the memory
  512. * @size: size of the resource to map
  513. *
  514. * ioremap performs a platform specific sequence of operations to
  515. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  516. * writew/writel functions and the other mmio helpers. The returned
  517. * address is not guaranteed to be usable directly as a virtual
  518. * address.
  519. *
  520. * We provide a few variations of it:
  521. *
  522. * * ioremap is the standard one and provides non-cacheable guarded mappings
  523. * and can be hooked by the platform via ppc_md
  524. *
  525. * * ioremap_flags allows to specify the page flags as an argument and can
  526. * also be hooked by the platform via ppc_md
  527. *
  528. * * ioremap_nocache is identical to ioremap
  529. *
  530. * * iounmap undoes such a mapping and can be hooked
  531. *
  532. * * __ioremap_at (and the pending __iounmap_at) are low level functions to
  533. * create hand-made mappings for use only by the PCI code and cannot
  534. * currently be hooked. Must be page aligned.
  535. *
  536. * * __ioremap is the low level implementation used by ioremap and
  537. * ioremap_flags and cannot be hooked (but can be used by a hook on one
  538. * of the previous ones)
  539. *
  540. * * __iounmap, is the low level implementation used by iounmap and cannot
  541. * be hooked (but can be used by a hook on iounmap)
  542. *
  543. */
  544. extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
  545. extern void __iomem *ioremap_flags(phys_addr_t address, unsigned long size,
  546. unsigned long flags);
  547. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  548. extern void iounmap(volatile void __iomem *addr);
  549. extern void __iomem *__ioremap(phys_addr_t, unsigned long size,
  550. unsigned long flags);
  551. extern void __iounmap(volatile void __iomem *addr);
  552. extern void __iomem * __ioremap_at(phys_addr_t pa, void *ea,
  553. unsigned long size, unsigned long flags);
  554. extern void __iounmap_at(void *ea, unsigned long size);
  555. /*
  556. * When CONFIG_PPC_INDIRECT_IO is set, we use the generic iomap implementation
  557. * which needs some additional definitions here. They basically allow PIO
  558. * space overall to be 1GB. This will work as long as we never try to use
  559. * iomap to map MMIO below 1GB which should be fine on ppc64
  560. */
  561. #define HAVE_ARCH_PIO_SIZE 1
  562. #define PIO_OFFSET 0x00000000UL
  563. #define PIO_MASK (FULL_IO_SIZE - 1)
  564. #define PIO_RESERVED (FULL_IO_SIZE)
  565. #define mmio_read16be(addr) readw_be(addr)
  566. #define mmio_read32be(addr) readl_be(addr)
  567. #define mmio_write16be(val, addr) writew_be(val, addr)
  568. #define mmio_write32be(val, addr) writel_be(val, addr)
  569. #define mmio_insb(addr, dst, count) readsb(addr, dst, count)
  570. #define mmio_insw(addr, dst, count) readsw(addr, dst, count)
  571. #define mmio_insl(addr, dst, count) readsl(addr, dst, count)
  572. #define mmio_outsb(addr, src, count) writesb(addr, src, count)
  573. #define mmio_outsw(addr, src, count) writesw(addr, src, count)
  574. #define mmio_outsl(addr, src, count) writesl(addr, src, count)
  575. /**
  576. * virt_to_phys - map virtual addresses to physical
  577. * @address: address to remap
  578. *
  579. * The returned physical address is the physical (CPU) mapping for
  580. * the memory address given. It is only valid to use this function on
  581. * addresses directly mapped or allocated via kmalloc.
  582. *
  583. * This function does not give bus mappings for DMA transfers. In
  584. * almost all conceivable cases a device driver should not be using
  585. * this function
  586. */
  587. static inline unsigned long virt_to_phys(volatile void * address)
  588. {
  589. return __pa((unsigned long)address);
  590. }
  591. /**
  592. * phys_to_virt - map physical address to virtual
  593. * @address: address to remap
  594. *
  595. * The returned virtual address is a current CPU mapping for
  596. * the memory address given. It is only valid to use this function on
  597. * addresses that have a kernel mapping
  598. *
  599. * This function does not handle bus mappings for DMA transfers. In
  600. * almost all conceivable cases a device driver should not be using
  601. * this function
  602. */
  603. static inline void * phys_to_virt(unsigned long address)
  604. {
  605. return (void *)__va(address);
  606. }
  607. /*
  608. * Change "struct page" to physical address.
  609. */
  610. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  611. /* We do NOT want virtual merging, it would put too much pressure on
  612. * our iommu allocator. Instead, we want drivers to be smart enough
  613. * to coalesce sglists that happen to have been mapped in a contiguous
  614. * way by the iommu
  615. */
  616. #define BIO_VMERGE_BOUNDARY 0
  617. /*
  618. * 32 bits still uses virt_to_bus() for it's implementation of DMA
  619. * mappings se we have to keep it defined here. We also have some old
  620. * drivers (shame shame shame) that use bus_to_virt() and haven't been
  621. * fixed yet so I need to define it here.
  622. */
  623. #ifdef CONFIG_PPC32
  624. static inline unsigned long virt_to_bus(volatile void * address)
  625. {
  626. if (address == NULL)
  627. return 0;
  628. return __pa(address) + PCI_DRAM_OFFSET;
  629. }
  630. static inline void * bus_to_virt(unsigned long address)
  631. {
  632. if (address == 0)
  633. return NULL;
  634. return __va(address - PCI_DRAM_OFFSET);
  635. }
  636. #define page_to_bus(page) (page_to_phys(page) + PCI_DRAM_OFFSET)
  637. #endif /* CONFIG_PPC32 */
  638. /* access ports */
  639. #define setbits32(_addr, _v) out_be32((_addr), in_be32(_addr) | (_v))
  640. #define clrbits32(_addr, _v) out_be32((_addr), in_be32(_addr) & ~(_v))
  641. #define setbits16(_addr, _v) out_be16((_addr), in_be16(_addr) | (_v))
  642. #define clrbits16(_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v))
  643. #define setbits8(_addr, _v) out_8((_addr), in_8(_addr) | (_v))
  644. #define clrbits8(_addr, _v) out_8((_addr), in_8(_addr) & ~(_v))
  645. /* Clear and set bits in one shot. These macros can be used to clear and
  646. * set multiple bits in a register using a single read-modify-write. These
  647. * macros can also be used to set a multiple-bit bit pattern using a mask,
  648. * by specifying the mask in the 'clear' parameter and the new bit pattern
  649. * in the 'set' parameter.
  650. */
  651. #define clrsetbits(type, addr, clear, set) \
  652. out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
  653. #ifdef __powerpc64__
  654. #define clrsetbits_be64(addr, clear, set) clrsetbits(be64, addr, clear, set)
  655. #define clrsetbits_le64(addr, clear, set) clrsetbits(le64, addr, clear, set)
  656. #endif
  657. #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
  658. #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
  659. #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
  660. #define clrsetbits_le16(addr, clear, set) clrsetbits(le32, addr, clear, set)
  661. #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
  662. #endif /* __KERNEL__ */
  663. #endif /* _ASM_POWERPC_IO_H */