io.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * linux/include/asm-arm/arch-ixp4xx/io.h
  3. *
  4. * Author: Deepak Saxena <dsaxena@plexity.net>
  5. *
  6. * Copyright (C) 2002-2005 MontaVista Software, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __ASM_ARM_ARCH_IO_H
  13. #define __ASM_ARM_ARCH_IO_H
  14. #include <asm/hardware.h>
  15. #define IO_SPACE_LIMIT 0xffff0000
  16. #define BIT(x) ((1)<<(x))
  17. extern int (*ixp4xx_pci_read)(u32 addr, u32 cmd, u32* data);
  18. extern int ixp4xx_pci_write(u32 addr, u32 cmd, u32 data);
  19. /*
  20. * IXP4xx provides two methods of accessing PCI memory space:
  21. *
  22. * 1) A direct mapped window from 0x48000000 to 0x4bffffff (64MB).
  23. * To access PCI via this space, we simply ioremap() the BAR
  24. * into the kernel and we can use the standard read[bwl]/write[bwl]
  25. * macros. This is the preffered method due to speed but it
  26. * limits the system to just 64MB of PCI memory. This can be
  27. * problamatic if using video cards and other memory-heavy
  28. * targets.
  29. *
  30. * 2) If > 64MB of memory space is required, the IXP4xx can be configured
  31. * to use indirect registers to access PCI (as we do below for I/O
  32. * transactions). This allows for up to 128MB (0x48000000 to 0x4fffffff)
  33. * of memory on the bus. The disadvantadge of this is that every
  34. * PCI access requires three local register accesses plus a spinlock,
  35. * but in some cases the performance hit is acceptable. In addition,
  36. * you cannot mmap() PCI devices in this case.
  37. *
  38. */
  39. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  40. #define __mem_pci(a) (a)
  41. #else
  42. #include <linux/mm.h>
  43. /*
  44. * In the case of using indirect PCI, we simply return the actual PCI
  45. * address and our read/write implementation use that to drive the
  46. * access registers. If something outside of PCI is ioremap'd, we
  47. * fallback to the default.
  48. */
  49. static inline void __iomem *
  50. __ixp4xx_ioremap(unsigned long addr, size_t size, unsigned long flags, unsigned long align)
  51. {
  52. extern void __iomem * __ioremap(unsigned long, size_t, unsigned long, unsigned long);
  53. if((addr < 0x48000000) || (addr > 0x4fffffff))
  54. return __ioremap(addr, size, flags, align);
  55. return (void *)addr;
  56. }
  57. static inline void
  58. __ixp4xx_iounmap(void __iomem *addr)
  59. {
  60. extern void __iounmap(void __iomem *addr);
  61. if ((u32)addr >= VMALLOC_START)
  62. __iounmap(addr);
  63. }
  64. #define __arch_ioremap(a, s, f, x) __ixp4xx_ioremap(a, s, f, x)
  65. #define __arch_iounmap(a) __ixp4xx_iounmap(a)
  66. #define writeb(p, v) __ixp4xx_writeb(p, v)
  67. #define writew(p, v) __ixp4xx_writew(p, v)
  68. #define writel(p, v) __ixp4xx_writel(p, v)
  69. #define writesb(p, v, l) __ixp4xx_writesb(p, v, l)
  70. #define writesw(p, v, l) __ixp4xx_writesw(p, v, l)
  71. #define writesl(p, v, l) __ixp4xx_writesl(p, v, l)
  72. #define readb(p) __ixp4xx_readb(p)
  73. #define readw(p) __ixp4xx_readw(p)
  74. #define readl(p) __ixp4xx_readl(p)
  75. #define readsb(p, v, l) __ixp4xx_readsb(p, v, l)
  76. #define readsw(p, v, l) __ixp4xx_readsw(p, v, l)
  77. #define readsl(p, v, l) __ixp4xx_readsl(p, v, l)
  78. static inline void
  79. __ixp4xx_writeb(u8 value, u32 addr)
  80. {
  81. u32 n, byte_enables, data;
  82. if (addr >= VMALLOC_START) {
  83. __raw_writeb(value, addr);
  84. return;
  85. }
  86. n = addr % 4;
  87. byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;
  88. data = value << (8*n);
  89. ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data);
  90. }
  91. static inline void
  92. __ixp4xx_writesb(u32 bus_addr, u8 *vaddr, int count)
  93. {
  94. while (count--)
  95. writeb(*vaddr++, bus_addr);
  96. }
  97. static inline void
  98. __ixp4xx_writew(u16 value, u32 addr)
  99. {
  100. u32 n, byte_enables, data;
  101. if (addr >= VMALLOC_START) {
  102. __raw_writew(value, addr);
  103. return;
  104. }
  105. n = addr % 4;
  106. byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;
  107. data = value << (8*n);
  108. ixp4xx_pci_write(addr, byte_enables | NP_CMD_MEMWRITE, data);
  109. }
  110. static inline void
  111. __ixp4xx_writesw(u32 bus_addr, u16 *vaddr, int count)
  112. {
  113. while (count--)
  114. writew(*vaddr++, bus_addr);
  115. }
  116. static inline void
  117. __ixp4xx_writel(u32 value, u32 addr)
  118. {
  119. if (addr >= VMALLOC_START) {
  120. __raw_writel(value, addr);
  121. return;
  122. }
  123. ixp4xx_pci_write(addr, NP_CMD_MEMWRITE, value);
  124. }
  125. static inline void
  126. __ixp4xx_writesl(u32 bus_addr, u32 *vaddr, int count)
  127. {
  128. while (count--)
  129. writel(*vaddr++, bus_addr);
  130. }
  131. static inline unsigned char
  132. __ixp4xx_readb(u32 addr)
  133. {
  134. u32 n, byte_enables, data;
  135. if (addr >= VMALLOC_START)
  136. return __raw_readb(addr);
  137. n = addr % 4;
  138. byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;
  139. if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data))
  140. return 0xff;
  141. return data >> (8*n);
  142. }
  143. static inline void
  144. __ixp4xx_readsb(u32 bus_addr, u8 *vaddr, u32 count)
  145. {
  146. while (count--)
  147. *vaddr++ = readb(bus_addr);
  148. }
  149. static inline unsigned short
  150. __ixp4xx_readw(u32 addr)
  151. {
  152. u32 n, byte_enables, data;
  153. if (addr >= VMALLOC_START)
  154. return __raw_readw(addr);
  155. n = addr % 4;
  156. byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;
  157. if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_MEMREAD, &data))
  158. return 0xffff;
  159. return data>>(8*n);
  160. }
  161. static inline void
  162. __ixp4xx_readsw(u32 bus_addr, u16 *vaddr, u32 count)
  163. {
  164. while (count--)
  165. *vaddr++ = readw(bus_addr);
  166. }
  167. static inline unsigned long
  168. __ixp4xx_readl(u32 addr)
  169. {
  170. u32 data;
  171. if (addr >= VMALLOC_START)
  172. return __raw_readl(addr);
  173. if (ixp4xx_pci_read(addr, NP_CMD_MEMREAD, &data))
  174. return 0xffffffff;
  175. return data;
  176. }
  177. static inline void
  178. __ixp4xx_readsl(u32 bus_addr, u32 *vaddr, u32 count)
  179. {
  180. while (count--)
  181. *vaddr++ = readl(bus_addr);
  182. }
  183. /*
  184. * We can use the built-in functions b/c they end up calling writeb/readb
  185. */
  186. #define memset_io(c,v,l) _memset_io((c),(v),(l))
  187. #define memcpy_fromio(a,c,l) _memcpy_fromio((a),(c),(l))
  188. #define memcpy_toio(c,a,l) _memcpy_toio((c),(a),(l))
  189. #define eth_io_copy_and_sum(s,c,l,b) \
  190. eth_copy_and_sum((s),__mem_pci(c),(l),(b))
  191. static inline int
  192. check_signature(unsigned long bus_addr, const unsigned char *signature,
  193. int length)
  194. {
  195. int retval = 0;
  196. do {
  197. if (readb(bus_addr) != *signature)
  198. goto out;
  199. bus_addr++;
  200. signature++;
  201. length--;
  202. } while (length);
  203. retval = 1;
  204. out:
  205. return retval;
  206. }
  207. #endif
  208. /*
  209. * IXP4xx does not have a transparent cpu -> PCI I/O translation
  210. * window. Instead, it has a set of registers that must be tweaked
  211. * with the proper byte lanes, command types, and address for the
  212. * transaction. This means that we need to override the default
  213. * I/O functions.
  214. */
  215. #define outb(p, v) __ixp4xx_outb(p, v)
  216. #define outw(p, v) __ixp4xx_outw(p, v)
  217. #define outl(p, v) __ixp4xx_outl(p, v)
  218. #define outsb(p, v, l) __ixp4xx_outsb(p, v, l)
  219. #define outsw(p, v, l) __ixp4xx_outsw(p, v, l)
  220. #define outsl(p, v, l) __ixp4xx_outsl(p, v, l)
  221. #define inb(p) __ixp4xx_inb(p)
  222. #define inw(p) __ixp4xx_inw(p)
  223. #define inl(p) __ixp4xx_inl(p)
  224. #define insb(p, v, l) __ixp4xx_insb(p, v, l)
  225. #define insw(p, v, l) __ixp4xx_insw(p, v, l)
  226. #define insl(p, v, l) __ixp4xx_insl(p, v, l)
  227. static inline void
  228. __ixp4xx_outb(u8 value, u32 addr)
  229. {
  230. u32 n, byte_enables, data;
  231. n = addr % 4;
  232. byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;
  233. data = value << (8*n);
  234. ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data);
  235. }
  236. static inline void
  237. __ixp4xx_outsb(u32 io_addr, const u8 *vaddr, u32 count)
  238. {
  239. while (count--)
  240. outb(*vaddr++, io_addr);
  241. }
  242. static inline void
  243. __ixp4xx_outw(u16 value, u32 addr)
  244. {
  245. u32 n, byte_enables, data;
  246. n = addr % 4;
  247. byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;
  248. data = value << (8*n);
  249. ixp4xx_pci_write(addr, byte_enables | NP_CMD_IOWRITE, data);
  250. }
  251. static inline void
  252. __ixp4xx_outsw(u32 io_addr, const u16 *vaddr, u32 count)
  253. {
  254. while (count--)
  255. outw(cpu_to_le16(*vaddr++), io_addr);
  256. }
  257. static inline void
  258. __ixp4xx_outl(u32 value, u32 addr)
  259. {
  260. ixp4xx_pci_write(addr, NP_CMD_IOWRITE, value);
  261. }
  262. static inline void
  263. __ixp4xx_outsl(u32 io_addr, const u32 *vaddr, u32 count)
  264. {
  265. while (count--)
  266. outl(*vaddr++, io_addr);
  267. }
  268. static inline u8
  269. __ixp4xx_inb(u32 addr)
  270. {
  271. u32 n, byte_enables, data;
  272. n = addr % 4;
  273. byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;
  274. if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data))
  275. return 0xff;
  276. return data >> (8*n);
  277. }
  278. static inline void
  279. __ixp4xx_insb(u32 io_addr, u8 *vaddr, u32 count)
  280. {
  281. while (count--)
  282. *vaddr++ = inb(io_addr);
  283. }
  284. static inline u16
  285. __ixp4xx_inw(u32 addr)
  286. {
  287. u32 n, byte_enables, data;
  288. n = addr % 4;
  289. byte_enables = (0xf & ~(BIT(n) | BIT(n+1))) << IXP4XX_PCI_NP_CBE_BESL;
  290. if (ixp4xx_pci_read(addr, byte_enables | NP_CMD_IOREAD, &data))
  291. return 0xffff;
  292. return data>>(8*n);
  293. }
  294. static inline void
  295. __ixp4xx_insw(u32 io_addr, u16 *vaddr, u32 count)
  296. {
  297. while (count--)
  298. *vaddr++ = le16_to_cpu(inw(io_addr));
  299. }
  300. static inline u32
  301. __ixp4xx_inl(u32 addr)
  302. {
  303. u32 data;
  304. if (ixp4xx_pci_read(addr, NP_CMD_IOREAD, &data))
  305. return 0xffffffff;
  306. return data;
  307. }
  308. static inline void
  309. __ixp4xx_insl(u32 io_addr, u32 *vaddr, u32 count)
  310. {
  311. while (count--)
  312. *vaddr++ = inl(io_addr);
  313. }
  314. #define __is_io_address(p) (((unsigned long)p >= 0x0) && \
  315. ((unsigned long)p <= 0x0000ffff))
  316. static inline unsigned int
  317. __ixp4xx_ioread8(void __iomem *port)
  318. {
  319. if (__is_io_address(port))
  320. return (unsigned int)__ixp4xx_inb((unsigned int)port);
  321. else
  322. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  323. return (unsigned int)__raw_readb((u32)port);
  324. #else
  325. return (unsigned int)__ixp4xx_readb((u32)port);
  326. #endif
  327. }
  328. static inline void
  329. __ixp4xx_ioread8_rep(u32 port, u8 *vaddr, u32 count)
  330. {
  331. if (__is_io_address(port))
  332. __ixp4xx_insb(port, vaddr, count);
  333. else
  334. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  335. __raw_readsb((void __iomem *)port, vaddr, count);
  336. #else
  337. __ixp4xx_readsb(port, vaddr, count);
  338. #endif
  339. }
  340. static inline unsigned int
  341. __ixp4xx_ioread16(void __iomem *port)
  342. {
  343. if (__is_io_address(port))
  344. return (unsigned int)__ixp4xx_inw((unsigned int)port);
  345. else
  346. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  347. return le16_to_cpu(__raw_readw((u32)port));
  348. #else
  349. return (unsigned int)__ixp4xx_readw((u32)port);
  350. #endif
  351. }
  352. static inline void
  353. __ixp4xx_ioread16_rep(u32 port, u16 *vaddr, u32 count)
  354. {
  355. if (__is_io_address(port))
  356. __ixp4xx_insw(port, vaddr, count);
  357. else
  358. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  359. __raw_readsw((void __iomem *)port, vaddr, count);
  360. #else
  361. __ixp4xx_readsw(port, vaddr, count);
  362. #endif
  363. }
  364. static inline unsigned int
  365. __ixp4xx_ioread32(void __iomem *port)
  366. {
  367. if (__is_io_address(port))
  368. return (unsigned int)__ixp4xx_inl((unsigned int)port);
  369. else {
  370. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  371. return le32_to_cpu(__raw_readl((u32)port));
  372. #else
  373. return (unsigned int)__ixp4xx_readl((u32)port);
  374. #endif
  375. }
  376. }
  377. static inline void
  378. __ixp4xx_ioread32_rep(u32 port, u32 *vaddr, u32 count)
  379. {
  380. if (__is_io_address(port))
  381. __ixp4xx_insl(port, vaddr, count);
  382. else
  383. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  384. __raw_readsl((void __iomem *)port, vaddr, count);
  385. #else
  386. __ixp4xx_readsl(port, vaddr, count);
  387. #endif
  388. }
  389. static inline void
  390. __ixp4xx_iowrite8(u8 value, void __iomem *port)
  391. {
  392. if (__is_io_address(port))
  393. __ixp4xx_outb(value, (unsigned int)port);
  394. else
  395. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  396. __raw_writeb(value, (u32)port);
  397. #else
  398. __ixp4xx_writeb(value, (u32)port);
  399. #endif
  400. }
  401. static inline void
  402. __ixp4xx_iowrite8_rep(u32 port, u8 *vaddr, u32 count)
  403. {
  404. if (__is_io_address(port))
  405. __ixp4xx_outsb(port, vaddr, count);
  406. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  407. __raw_writesb((void __iomem *)port, vaddr, count);
  408. #else
  409. __ixp4xx_writesb(port, vaddr, count);
  410. #endif
  411. }
  412. static inline void
  413. __ixp4xx_iowrite16(u16 value, void __iomem *port)
  414. {
  415. if (__is_io_address(port))
  416. __ixp4xx_outw(value, (unsigned int)port);
  417. else
  418. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  419. __raw_writew(cpu_to_le16(value), (u32)port);
  420. #else
  421. __ixp4xx_writew(value, (u32)port);
  422. #endif
  423. }
  424. static inline void
  425. __ixp4xx_iowrite16_rep(u32 port, u16 *vaddr, u32 count)
  426. {
  427. if (__is_io_address(port))
  428. __ixp4xx_outsw(port, vaddr, count);
  429. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  430. __raw_readsw((void __iomem *)port, vaddr, count);
  431. #else
  432. __ixp4xx_writesw(port, vaddr, count);
  433. #endif
  434. }
  435. static inline void
  436. __ixp4xx_iowrite32(u32 value, void __iomem *port)
  437. {
  438. if (__is_io_address(port))
  439. __ixp4xx_outl(value, (unsigned int)port);
  440. else
  441. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  442. __raw_writel(cpu_to_le32(value), (u32)port);
  443. #else
  444. __ixp4xx_writel(value, (u32)port);
  445. #endif
  446. }
  447. static inline void
  448. __ixp4xx_iowrite32_rep(u32 port, u32 *vaddr, u32 count)
  449. {
  450. if (__is_io_address(port))
  451. __ixp4xx_outsl(port, vaddr, count);
  452. #ifndef CONFIG_IXP4XX_INDIRECT_PCI
  453. __raw_readsl((void __iomem *)port, vaddr, count);
  454. #else
  455. __ixp4xx_outsl(port, vaddr, count);
  456. #endif
  457. }
  458. #define ioread8(p) __ixp4xx_ioread8(p)
  459. #define ioread16(p) __ixp4xx_ioread16(p)
  460. #define ioread32(p) __ixp4xx_ioread32(p)
  461. #define ioread8_rep(p, v, c) __ixp4xx_ioread8_rep(p, v, c)
  462. #define ioread16_rep(p, v, c) __ixp4xx_ioread16_rep(p, v, c)
  463. #define ioread32_rep(p, v, c) __ixp4xx_ioread32_rep(p, v, c)
  464. #define iowrite8(v,p) __ixp4xx_iowrite8(v,p)
  465. #define iowrite16(v,p) __ixp4xx_iowrite16(v,p)
  466. #define iowrite32(v,p) __ixp4xx_iowrite32(v,p)
  467. #define iowrite8_rep(p, v, c) __ixp4xx_iowrite8_rep(p, v, c)
  468. #define iowrite16_rep(p, v, c) __ixp4xx_iowrite16_rep(p, v, c)
  469. #define iowrite32_rep(p, v, c) __ixp4xx_iowrite32_rep(p, v, c)
  470. #define ioport_map(port, nr) ((void __iomem*)port)
  471. #define ioport_unmap(addr)
  472. #endif // __ASM_ARM_ARCH_IO_H