io.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995 Waldorf GmbH
  7. * Copyright (C) 1994 - 2000, 06 Ralf Baechle
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. * Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
  10. * Author: Maciej W. Rozycki <macro@mips.com>
  11. */
  12. #ifndef _ASM_IO_H
  13. #define _ASM_IO_H
  14. #define ARCH_HAS_IOREMAP_WC
  15. #include <linux/compiler.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/irqflags.h>
  19. #include <asm/addrspace.h>
  20. #include <asm/bug.h>
  21. #include <asm/byteorder.h>
  22. #include <asm/cpu.h>
  23. #include <asm/cpu-features.h>
  24. #include <asm-generic/iomap.h>
  25. #include <asm/page.h>
  26. #include <asm/pgtable-bits.h>
  27. #include <asm/processor.h>
  28. #include <asm/string.h>
  29. #include <ioremap.h>
  30. #include <mangle-port.h>
  31. /*
  32. * Slowdown I/O port space accesses for antique hardware.
  33. */
  34. #undef CONF_SLOWDOWN_IO
  35. /*
  36. * Raw operations are never swapped in software. OTOH values that raw
  37. * operations are working on may or may not have been swapped by the bus
  38. * hardware. An example use would be for flash memory that's used for
  39. * execute in place.
  40. */
  41. # define __raw_ioswabb(a, x) (x)
  42. # define __raw_ioswabw(a, x) (x)
  43. # define __raw_ioswabl(a, x) (x)
  44. # define __raw_ioswabq(a, x) (x)
  45. # define ____raw_ioswabq(a, x) (x)
  46. /* ioswab[bwlq], __mem_ioswab[bwlq] are defined in mangle-port.h */
  47. #define IO_SPACE_LIMIT 0xffff
  48. /*
  49. * On MIPS I/O ports are memory mapped, so we access them using normal
  50. * load/store instructions. mips_io_port_base is the virtual address to
  51. * which all ports are being mapped. For sake of efficiency some code
  52. * assumes that this is an address that can be loaded with a single lui
  53. * instruction, so the lower 16 bits must be zero. Should be true on
  54. * on any sane architecture; generic code does not use this assumption.
  55. */
  56. extern const unsigned long mips_io_port_base;
  57. /*
  58. * Gcc will generate code to load the value of mips_io_port_base after each
  59. * function call which may be fairly wasteful in some cases. So we don't
  60. * play quite by the book. We tell gcc mips_io_port_base is a long variable
  61. * which solves the code generation issue. Now we need to violate the
  62. * aliasing rules a little to make initialization possible and finally we
  63. * will need the barrier() to fight side effects of the aliasing chat.
  64. * This trickery will eventually collapse under gcc's optimizer. Oh well.
  65. */
  66. static inline void set_io_port_base(unsigned long base)
  67. {
  68. * (unsigned long *) &mips_io_port_base = base;
  69. barrier();
  70. }
  71. /*
  72. * Thanks to James van Artsdalen for a better timing-fix than
  73. * the two short jumps: using outb's to a nonexistent port seems
  74. * to guarantee better timings even on fast machines.
  75. *
  76. * On the other hand, I'd like to be sure of a non-existent port:
  77. * I feel a bit unsafe about using 0x80 (should be safe, though)
  78. *
  79. * Linus
  80. *
  81. */
  82. #define __SLOW_DOWN_IO \
  83. __asm__ __volatile__( \
  84. "sb\t$0,0x80(%0)" \
  85. : : "r" (mips_io_port_base));
  86. #ifdef CONF_SLOWDOWN_IO
  87. #ifdef REALLY_SLOW_IO
  88. #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
  89. #else
  90. #define SLOW_DOWN_IO __SLOW_DOWN_IO
  91. #endif
  92. #else
  93. #define SLOW_DOWN_IO
  94. #endif
  95. /*
  96. * virt_to_phys - map virtual addresses to physical
  97. * @address: address to remap
  98. *
  99. * The returned physical address is the physical (CPU) mapping for
  100. * the memory address given. It is only valid to use this function on
  101. * addresses directly mapped or allocated via kmalloc.
  102. *
  103. * This function does not give bus mappings for DMA transfers. In
  104. * almost all conceivable cases a device driver should not be using
  105. * this function
  106. */
  107. static inline unsigned long virt_to_phys(volatile const void *address)
  108. {
  109. return __pa(address);
  110. }
  111. /*
  112. * phys_to_virt - map physical address to virtual
  113. * @address: address to remap
  114. *
  115. * The returned virtual address is a current CPU mapping for
  116. * the memory address given. It is only valid to use this function on
  117. * addresses that have a kernel mapping
  118. *
  119. * This function does not handle bus mappings for DMA transfers. In
  120. * almost all conceivable cases a device driver should not be using
  121. * this function
  122. */
  123. static inline void * phys_to_virt(unsigned long address)
  124. {
  125. return (void *)(address + PAGE_OFFSET - PHYS_OFFSET);
  126. }
  127. /*
  128. * ISA I/O bus memory addresses are 1:1 with the physical address.
  129. */
  130. static inline unsigned long isa_virt_to_bus(volatile void *address)
  131. {
  132. return virt_to_phys(address);
  133. }
  134. static inline void *isa_bus_to_virt(unsigned long address)
  135. {
  136. return phys_to_virt(address);
  137. }
  138. #define isa_page_to_bus page_to_phys
  139. /*
  140. * However PCI ones are not necessarily 1:1 and therefore these interfaces
  141. * are forbidden in portable PCI drivers.
  142. *
  143. * Allow them for x86 for legacy drivers, though.
  144. */
  145. #define virt_to_bus virt_to_phys
  146. #define bus_to_virt phys_to_virt
  147. /*
  148. * Change "struct page" to physical address.
  149. */
  150. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  151. extern void __iomem * __ioremap(phys_addr_t offset, phys_addr_t size, unsigned long flags);
  152. extern void __iounmap(const volatile void __iomem *addr);
  153. #ifndef CONFIG_PCI
  154. struct pci_dev;
  155. static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
  156. #endif
  157. static inline void __iomem * __ioremap_mode(phys_addr_t offset, unsigned long size,
  158. unsigned long flags)
  159. {
  160. void __iomem *addr = plat_ioremap(offset, size, flags);
  161. if (addr)
  162. return addr;
  163. #define __IS_LOW512(addr) (!((phys_addr_t)(addr) & (phys_addr_t) ~0x1fffffffULL))
  164. if (cpu_has_64bit_addresses) {
  165. u64 base = UNCAC_BASE;
  166. /*
  167. * R10000 supports a 2 bit uncached attribute therefore
  168. * UNCAC_BASE may not equal IO_BASE.
  169. */
  170. if (flags == _CACHE_UNCACHED)
  171. base = (u64) IO_BASE;
  172. return (void __iomem *) (unsigned long) (base + offset);
  173. } else if (__builtin_constant_p(offset) &&
  174. __builtin_constant_p(size) && __builtin_constant_p(flags)) {
  175. phys_addr_t phys_addr, last_addr;
  176. phys_addr = fixup_bigphys_addr(offset, size);
  177. /* Don't allow wraparound or zero size. */
  178. last_addr = phys_addr + size - 1;
  179. if (!size || last_addr < phys_addr)
  180. return NULL;
  181. /*
  182. * Map uncached objects in the low 512MB of address
  183. * space using KSEG1.
  184. */
  185. if (__IS_LOW512(phys_addr) && __IS_LOW512(last_addr) &&
  186. flags == _CACHE_UNCACHED)
  187. return (void __iomem *)
  188. (unsigned long)CKSEG1ADDR(phys_addr);
  189. }
  190. return __ioremap(offset, size, flags);
  191. #undef __IS_LOW512
  192. }
  193. /*
  194. * ioremap - map bus memory into CPU space
  195. * @offset: bus address of the memory
  196. * @size: size of the resource to map
  197. *
  198. * ioremap performs a platform specific sequence of operations to
  199. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  200. * writew/writel functions and the other mmio helpers. The returned
  201. * address is not guaranteed to be usable directly as a virtual
  202. * address.
  203. */
  204. #define ioremap(offset, size) \
  205. __ioremap_mode((offset), (size), _CACHE_UNCACHED)
  206. /*
  207. * ioremap_nocache - map bus memory into CPU space
  208. * @offset: bus address of the memory
  209. * @size: size of the resource to map
  210. *
  211. * ioremap_nocache performs a platform specific sequence of operations to
  212. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  213. * writew/writel functions and the other mmio helpers. The returned
  214. * address is not guaranteed to be usable directly as a virtual
  215. * address.
  216. *
  217. * This version of ioremap ensures that the memory is marked uncachable
  218. * on the CPU as well as honouring existing caching rules from things like
  219. * the PCI bus. Note that there are other caches and buffers on many
  220. * busses. In particular driver authors should read up on PCI writes
  221. *
  222. * It's useful if some control registers are in such an area and
  223. * write combining or read caching is not desirable:
  224. */
  225. #define ioremap_nocache(offset, size) \
  226. __ioremap_mode((offset), (size), _CACHE_UNCACHED)
  227. #define ioremap_uc ioremap_nocache
  228. /*
  229. * ioremap_cachable - map bus memory into CPU space
  230. * @offset: bus address of the memory
  231. * @size: size of the resource to map
  232. *
  233. * ioremap_nocache performs a platform specific sequence of operations to
  234. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  235. * writew/writel functions and the other mmio helpers. The returned
  236. * address is not guaranteed to be usable directly as a virtual
  237. * address.
  238. *
  239. * This version of ioremap ensures that the memory is marked cachable by
  240. * the CPU. Also enables full write-combining. Useful for some
  241. * memory-like regions on I/O busses.
  242. */
  243. #define ioremap_cachable(offset, size) \
  244. __ioremap_mode((offset), (size), _page_cachable_default)
  245. #define ioremap_cache ioremap_cachable
  246. /*
  247. * ioremap_wc - map bus memory into CPU space
  248. * @offset: bus address of the memory
  249. * @size: size of the resource to map
  250. *
  251. * ioremap_wc performs a platform specific sequence of operations to
  252. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  253. * writew/writel functions and the other mmio helpers. The returned
  254. * address is not guaranteed to be usable directly as a virtual
  255. * address.
  256. *
  257. * This version of ioremap ensures that the memory is marked uncachable
  258. * but accelerated by means of write-combining feature. It is specifically
  259. * useful for PCIe prefetchable windows, which may vastly improve a
  260. * communications performance. If it was determined on boot stage, what
  261. * CPU CCA doesn't support UCA, the method shall fall-back to the
  262. * _CACHE_UNCACHED option (see cpu_probe() method).
  263. */
  264. #define ioremap_wc(offset, size) \
  265. __ioremap_mode((offset), (size), boot_cpu_data.writecombine)
  266. static inline void iounmap(const volatile void __iomem *addr)
  267. {
  268. if (plat_iounmap(addr))
  269. return;
  270. #define __IS_KSEG1(addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1)
  271. if (cpu_has_64bit_addresses ||
  272. (__builtin_constant_p(addr) && __IS_KSEG1(addr)))
  273. return;
  274. __iounmap(addr);
  275. #undef __IS_KSEG1
  276. }
  277. #if defined(CONFIG_CPU_CAVIUM_OCTEON) || defined(CONFIG_LOONGSON3_ENHANCEMENT)
  278. #define war_io_reorder_wmb() wmb()
  279. #else
  280. #define war_io_reorder_wmb() barrier()
  281. #endif
  282. #define __BUILD_MEMORY_SINGLE(pfx, bwlq, type, irq) \
  283. \
  284. static inline void pfx##write##bwlq(type val, \
  285. volatile void __iomem *mem) \
  286. { \
  287. volatile type *__mem; \
  288. type __val; \
  289. \
  290. war_io_reorder_wmb(); \
  291. \
  292. __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \
  293. \
  294. __val = pfx##ioswab##bwlq(__mem, val); \
  295. \
  296. if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \
  297. *__mem = __val; \
  298. else if (cpu_has_64bits) { \
  299. unsigned long __flags; \
  300. type __tmp; \
  301. \
  302. if (irq) \
  303. local_irq_save(__flags); \
  304. __asm__ __volatile__( \
  305. ".set arch=r4000" "\t\t# __writeq""\n\t" \
  306. "dsll32 %L0, %L0, 0" "\n\t" \
  307. "dsrl32 %L0, %L0, 0" "\n\t" \
  308. "dsll32 %M0, %M0, 0" "\n\t" \
  309. "or %L0, %L0, %M0" "\n\t" \
  310. "sd %L0, %2" "\n\t" \
  311. ".set mips0" "\n" \
  312. : "=r" (__tmp) \
  313. : "0" (__val), "m" (*__mem)); \
  314. if (irq) \
  315. local_irq_restore(__flags); \
  316. } else \
  317. BUG(); \
  318. } \
  319. \
  320. static inline type pfx##read##bwlq(const volatile void __iomem *mem) \
  321. { \
  322. volatile type *__mem; \
  323. type __val; \
  324. \
  325. __mem = (void *)__swizzle_addr_##bwlq((unsigned long)(mem)); \
  326. \
  327. if (sizeof(type) != sizeof(u64) || sizeof(u64) == sizeof(long)) \
  328. __val = *__mem; \
  329. else if (cpu_has_64bits) { \
  330. unsigned long __flags; \
  331. \
  332. if (irq) \
  333. local_irq_save(__flags); \
  334. __asm__ __volatile__( \
  335. ".set arch=r4000" "\t\t# __readq" "\n\t" \
  336. "ld %L0, %1" "\n\t" \
  337. "dsra32 %M0, %L0, 0" "\n\t" \
  338. "sll %L0, %L0, 0" "\n\t" \
  339. ".set mips0" "\n" \
  340. : "=r" (__val) \
  341. : "m" (*__mem)); \
  342. if (irq) \
  343. local_irq_restore(__flags); \
  344. } else { \
  345. __val = 0; \
  346. BUG(); \
  347. } \
  348. \
  349. /* prevent prefetching of coherent DMA data prematurely */ \
  350. rmb(); \
  351. return pfx##ioswab##bwlq(__mem, __val); \
  352. }
  353. #define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, p, slow) \
  354. \
  355. static inline void pfx##out##bwlq##p(type val, unsigned long port) \
  356. { \
  357. volatile type *__addr; \
  358. type __val; \
  359. \
  360. war_io_reorder_wmb(); \
  361. \
  362. __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
  363. \
  364. __val = pfx##ioswab##bwlq(__addr, val); \
  365. \
  366. /* Really, we want this to be atomic */ \
  367. BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \
  368. \
  369. *__addr = __val; \
  370. slow; \
  371. } \
  372. \
  373. static inline type pfx##in##bwlq##p(unsigned long port) \
  374. { \
  375. volatile type *__addr; \
  376. type __val; \
  377. \
  378. __addr = (void *)__swizzle_addr_##bwlq(mips_io_port_base + port); \
  379. \
  380. BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long)); \
  381. \
  382. __val = *__addr; \
  383. slow; \
  384. \
  385. /* prevent prefetching of coherent DMA data prematurely */ \
  386. rmb(); \
  387. return pfx##ioswab##bwlq(__addr, __val); \
  388. }
  389. #define __BUILD_MEMORY_PFX(bus, bwlq, type) \
  390. \
  391. __BUILD_MEMORY_SINGLE(bus, bwlq, type, 1)
  392. #define BUILDIO_MEM(bwlq, type) \
  393. \
  394. __BUILD_MEMORY_PFX(__raw_, bwlq, type) \
  395. __BUILD_MEMORY_PFX(, bwlq, type) \
  396. __BUILD_MEMORY_PFX(__mem_, bwlq, type) \
  397. BUILDIO_MEM(b, u8)
  398. BUILDIO_MEM(w, u16)
  399. BUILDIO_MEM(l, u32)
  400. BUILDIO_MEM(q, u64)
  401. #define __BUILD_IOPORT_PFX(bus, bwlq, type) \
  402. __BUILD_IOPORT_SINGLE(bus, bwlq, type, ,) \
  403. __BUILD_IOPORT_SINGLE(bus, bwlq, type, _p, SLOW_DOWN_IO)
  404. #define BUILDIO_IOPORT(bwlq, type) \
  405. __BUILD_IOPORT_PFX(, bwlq, type) \
  406. __BUILD_IOPORT_PFX(__mem_, bwlq, type)
  407. BUILDIO_IOPORT(b, u8)
  408. BUILDIO_IOPORT(w, u16)
  409. BUILDIO_IOPORT(l, u32)
  410. #ifdef CONFIG_64BIT
  411. BUILDIO_IOPORT(q, u64)
  412. #endif
  413. #define __BUILDIO(bwlq, type) \
  414. \
  415. __BUILD_MEMORY_SINGLE(____raw_, bwlq, type, 0)
  416. __BUILDIO(q, u64)
  417. #define readb_relaxed readb
  418. #define readw_relaxed readw
  419. #define readl_relaxed readl
  420. #define readq_relaxed readq
  421. #define writeb_relaxed writeb
  422. #define writew_relaxed writew
  423. #define writel_relaxed writel
  424. #define writeq_relaxed writeq
  425. #define readb_be(addr) \
  426. __raw_readb((__force unsigned *)(addr))
  427. #define readw_be(addr) \
  428. be16_to_cpu(__raw_readw((__force unsigned *)(addr)))
  429. #define readl_be(addr) \
  430. be32_to_cpu(__raw_readl((__force unsigned *)(addr)))
  431. #define readq_be(addr) \
  432. be64_to_cpu(__raw_readq((__force unsigned *)(addr)))
  433. #define writeb_be(val, addr) \
  434. __raw_writeb((val), (__force unsigned *)(addr))
  435. #define writew_be(val, addr) \
  436. __raw_writew(cpu_to_be16((val)), (__force unsigned *)(addr))
  437. #define writel_be(val, addr) \
  438. __raw_writel(cpu_to_be32((val)), (__force unsigned *)(addr))
  439. #define writeq_be(val, addr) \
  440. __raw_writeq(cpu_to_be64((val)), (__force unsigned *)(addr))
  441. /*
  442. * Some code tests for these symbols
  443. */
  444. #define readq readq
  445. #define writeq writeq
  446. #define __BUILD_MEMORY_STRING(bwlq, type) \
  447. \
  448. static inline void writes##bwlq(volatile void __iomem *mem, \
  449. const void *addr, unsigned int count) \
  450. { \
  451. const volatile type *__addr = addr; \
  452. \
  453. while (count--) { \
  454. __mem_write##bwlq(*__addr, mem); \
  455. __addr++; \
  456. } \
  457. } \
  458. \
  459. static inline void reads##bwlq(volatile void __iomem *mem, void *addr, \
  460. unsigned int count) \
  461. { \
  462. volatile type *__addr = addr; \
  463. \
  464. while (count--) { \
  465. *__addr = __mem_read##bwlq(mem); \
  466. __addr++; \
  467. } \
  468. }
  469. #define __BUILD_IOPORT_STRING(bwlq, type) \
  470. \
  471. static inline void outs##bwlq(unsigned long port, const void *addr, \
  472. unsigned int count) \
  473. { \
  474. const volatile type *__addr = addr; \
  475. \
  476. while (count--) { \
  477. __mem_out##bwlq(*__addr, port); \
  478. __addr++; \
  479. } \
  480. } \
  481. \
  482. static inline void ins##bwlq(unsigned long port, void *addr, \
  483. unsigned int count) \
  484. { \
  485. volatile type *__addr = addr; \
  486. \
  487. while (count--) { \
  488. *__addr = __mem_in##bwlq(port); \
  489. __addr++; \
  490. } \
  491. }
  492. #define BUILDSTRING(bwlq, type) \
  493. \
  494. __BUILD_MEMORY_STRING(bwlq, type) \
  495. __BUILD_IOPORT_STRING(bwlq, type)
  496. BUILDSTRING(b, u8)
  497. BUILDSTRING(w, u16)
  498. BUILDSTRING(l, u32)
  499. #ifdef CONFIG_64BIT
  500. BUILDSTRING(q, u64)
  501. #endif
  502. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  503. #define mmiowb() wmb()
  504. #else
  505. /* Depends on MIPS II instruction set */
  506. #define mmiowb() asm volatile ("sync" ::: "memory")
  507. #endif
  508. static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
  509. {
  510. memset((void __force *) addr, val, count);
  511. }
  512. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  513. {
  514. memcpy(dst, (void __force *) src, count);
  515. }
  516. static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  517. {
  518. memcpy((void __force *) dst, src, count);
  519. }
  520. /*
  521. * The caches on some architectures aren't dma-coherent and have need to
  522. * handle this in software. There are three types of operations that
  523. * can be applied to dma buffers.
  524. *
  525. * - dma_cache_wback_inv(start, size) makes caches and coherent by
  526. * writing the content of the caches back to memory, if necessary.
  527. * The function also invalidates the affected part of the caches as
  528. * necessary before DMA transfers from outside to memory.
  529. * - dma_cache_wback(start, size) makes caches and coherent by
  530. * writing the content of the caches back to memory, if necessary.
  531. * The function also invalidates the affected part of the caches as
  532. * necessary before DMA transfers from outside to memory.
  533. * - dma_cache_inv(start, size) invalidates the affected parts of the
  534. * caches. Dirty lines of the caches may be written back or simply
  535. * be discarded. This operation is necessary before dma operations
  536. * to the memory.
  537. *
  538. * This API used to be exported; it now is for arch code internal use only.
  539. */
  540. #ifdef CONFIG_DMA_NONCOHERENT
  541. extern void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
  542. extern void (*_dma_cache_wback)(unsigned long start, unsigned long size);
  543. extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);
  544. #define dma_cache_wback_inv(start, size) _dma_cache_wback_inv(start, size)
  545. #define dma_cache_wback(start, size) _dma_cache_wback(start, size)
  546. #define dma_cache_inv(start, size) _dma_cache_inv(start, size)
  547. #else /* Sane hardware */
  548. #define dma_cache_wback_inv(start,size) \
  549. do { (void) (start); (void) (size); } while (0)
  550. #define dma_cache_wback(start,size) \
  551. do { (void) (start); (void) (size); } while (0)
  552. #define dma_cache_inv(start,size) \
  553. do { (void) (start); (void) (size); } while (0)
  554. #endif /* CONFIG_DMA_NONCOHERENT */
  555. /*
  556. * Read a 32-bit register that requires a 64-bit read cycle on the bus.
  557. * Avoid interrupt mucking, just adjust the address for 4-byte access.
  558. * Assume the addresses are 8-byte aligned.
  559. */
  560. #ifdef __MIPSEB__
  561. #define __CSR_32_ADJUST 4
  562. #else
  563. #define __CSR_32_ADJUST 0
  564. #endif
  565. #define csr_out32(v, a) (*(volatile u32 *)((unsigned long)(a) + __CSR_32_ADJUST) = (v))
  566. #define csr_in32(a) (*(volatile u32 *)((unsigned long)(a) + __CSR_32_ADJUST))
  567. /*
  568. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  569. * access
  570. */
  571. #define xlate_dev_mem_ptr(p) __va(p)
  572. /*
  573. * Convert a virtual cached pointer to an uncached pointer
  574. */
  575. #define xlate_dev_kmem_ptr(p) p
  576. void __ioread64_copy(void *to, const void __iomem *from, size_t count);
  577. #endif /* _ASM_IO_H */