io.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. #ifndef __ALPHA_IO_H
  2. #define __ALPHA_IO_H
  3. #ifdef __KERNEL__
  4. #include <linux/kernel.h>
  5. #include <asm/compiler.h>
  6. #include <asm/system.h>
  7. #include <asm/pgtable.h>
  8. #include <asm/machvec.h>
  9. #include <asm/hwrpb.h>
  10. /* The generic header contains only prototypes. Including it ensures that
  11. the implementation we have here matches that interface. */
  12. #include <asm-generic/iomap.h>
  13. /* We don't use IO slowdowns on the Alpha, but.. */
  14. #define __SLOW_DOWN_IO do { } while (0)
  15. #define SLOW_DOWN_IO do { } while (0)
  16. /*
  17. * Virtual -> physical identity mapping starts at this offset
  18. */
  19. #ifdef USE_48_BIT_KSEG
  20. #define IDENT_ADDR 0xffff800000000000UL
  21. #else
  22. #define IDENT_ADDR 0xfffffc0000000000UL
  23. #endif
  24. /*
  25. * We try to avoid hae updates (thus the cache), but when we
  26. * do need to update the hae, we need to do it atomically, so
  27. * that any interrupts wouldn't get confused with the hae
  28. * register not being up-to-date with respect to the hardware
  29. * value.
  30. */
  31. static inline void __set_hae(unsigned long new_hae)
  32. {
  33. unsigned long flags;
  34. local_irq_save(flags);
  35. alpha_mv.hae_cache = new_hae;
  36. *alpha_mv.hae_register = new_hae;
  37. mb();
  38. /* Re-read to make sure it was written. */
  39. new_hae = *alpha_mv.hae_register;
  40. local_irq_restore(flags);
  41. }
  42. static inline void set_hae(unsigned long new_hae)
  43. {
  44. if (new_hae != alpha_mv.hae_cache)
  45. __set_hae(new_hae);
  46. }
  47. /*
  48. * Change virtual addresses to physical addresses and vv.
  49. */
  50. #ifdef USE_48_BIT_KSEG
  51. static inline unsigned long virt_to_phys(void *address)
  52. {
  53. return (unsigned long)address - IDENT_ADDR;
  54. }
  55. static inline void * phys_to_virt(unsigned long address)
  56. {
  57. return (void *) (address + IDENT_ADDR);
  58. }
  59. #else
  60. static inline unsigned long virt_to_phys(void *address)
  61. {
  62. unsigned long phys = (unsigned long)address;
  63. /* Sign-extend from bit 41. */
  64. phys <<= (64 - 41);
  65. phys = (long)phys >> (64 - 41);
  66. /* Crop to the physical address width of the processor. */
  67. phys &= (1ul << hwrpb->pa_bits) - 1;
  68. return phys;
  69. }
  70. static inline void * phys_to_virt(unsigned long address)
  71. {
  72. return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
  73. }
  74. #endif
  75. #define page_to_phys(page) page_to_pa(page)
  76. /* This depends on working iommu. */
  77. #define BIO_VMERGE_BOUNDARY (alpha_mv.mv_pci_tbi ? PAGE_SIZE : 0)
  78. /* Maximum PIO space address supported? */
  79. #define IO_SPACE_LIMIT 0xffff
  80. /*
  81. * Change addresses as seen by the kernel (virtual) to addresses as
  82. * seen by a device (bus), and vice versa.
  83. *
  84. * Note that this only works for a limited range of kernel addresses,
  85. * and very well may not span all memory. Consider this interface
  86. * deprecated in favour of the mapping functions in <asm/pci.h>.
  87. */
  88. extern unsigned long __direct_map_base;
  89. extern unsigned long __direct_map_size;
  90. static inline unsigned long virt_to_bus(void *address)
  91. {
  92. unsigned long phys = virt_to_phys(address);
  93. unsigned long bus = phys + __direct_map_base;
  94. return phys <= __direct_map_size ? bus : 0;
  95. }
  96. static inline void *bus_to_virt(unsigned long address)
  97. {
  98. void *virt;
  99. /* This check is a sanity check but also ensures that bus address 0
  100. maps to virtual address 0 which is useful to detect null pointers
  101. (the NCR driver is much simpler if NULL pointers are preserved). */
  102. address -= __direct_map_base;
  103. virt = phys_to_virt(address);
  104. return (long)address <= 0 ? NULL : virt;
  105. }
  106. /*
  107. * There are different chipsets to interface the Alpha CPUs to the world.
  108. */
  109. #define IO_CONCAT(a,b) _IO_CONCAT(a,b)
  110. #define _IO_CONCAT(a,b) a ## _ ## b
  111. #ifdef CONFIG_ALPHA_GENERIC
  112. /* In a generic kernel, we always go through the machine vector. */
  113. #define REMAP1(TYPE, NAME, QUAL) \
  114. static inline TYPE generic_##NAME(QUAL void __iomem *addr) \
  115. { \
  116. return alpha_mv.mv_##NAME(addr); \
  117. }
  118. #define REMAP2(TYPE, NAME, QUAL) \
  119. static inline void generic_##NAME(TYPE b, QUAL void __iomem *addr) \
  120. { \
  121. alpha_mv.mv_##NAME(b, addr); \
  122. }
  123. REMAP1(unsigned int, ioread8, /**/)
  124. REMAP1(unsigned int, ioread16, /**/)
  125. REMAP1(unsigned int, ioread32, /**/)
  126. REMAP1(u8, readb, const volatile)
  127. REMAP1(u16, readw, const volatile)
  128. REMAP1(u32, readl, const volatile)
  129. REMAP1(u64, readq, const volatile)
  130. REMAP2(u8, iowrite8, /**/)
  131. REMAP2(u16, iowrite16, /**/)
  132. REMAP2(u32, iowrite32, /**/)
  133. REMAP2(u8, writeb, volatile)
  134. REMAP2(u16, writew, volatile)
  135. REMAP2(u32, writel, volatile)
  136. REMAP2(u64, writeq, volatile)
  137. #undef REMAP1
  138. #undef REMAP2
  139. static inline void __iomem *generic_ioportmap(unsigned long a)
  140. {
  141. return alpha_mv.mv_ioportmap(a);
  142. }
  143. static inline void __iomem *generic_ioremap(unsigned long a, unsigned long s)
  144. {
  145. return alpha_mv.mv_ioremap(a, s);
  146. }
  147. static inline void generic_iounmap(volatile void __iomem *a)
  148. {
  149. return alpha_mv.mv_iounmap(a);
  150. }
  151. static inline int generic_is_ioaddr(unsigned long a)
  152. {
  153. return alpha_mv.mv_is_ioaddr(a);
  154. }
  155. static inline int generic_is_mmio(const volatile void __iomem *a)
  156. {
  157. return alpha_mv.mv_is_mmio(a);
  158. }
  159. #define __IO_PREFIX generic
  160. #define generic_trivial_rw_bw 0
  161. #define generic_trivial_rw_lq 0
  162. #define generic_trivial_io_bw 0
  163. #define generic_trivial_io_lq 0
  164. #define generic_trivial_iounmap 0
  165. #else
  166. #if defined(CONFIG_ALPHA_APECS)
  167. # include <asm/core_apecs.h>
  168. #elif defined(CONFIG_ALPHA_CIA)
  169. # include <asm/core_cia.h>
  170. #elif defined(CONFIG_ALPHA_IRONGATE)
  171. # include <asm/core_irongate.h>
  172. #elif defined(CONFIG_ALPHA_JENSEN)
  173. # include <asm/jensen.h>
  174. #elif defined(CONFIG_ALPHA_LCA)
  175. # include <asm/core_lca.h>
  176. #elif defined(CONFIG_ALPHA_MARVEL)
  177. # include <asm/core_marvel.h>
  178. #elif defined(CONFIG_ALPHA_MCPCIA)
  179. # include <asm/core_mcpcia.h>
  180. #elif defined(CONFIG_ALPHA_POLARIS)
  181. # include <asm/core_polaris.h>
  182. #elif defined(CONFIG_ALPHA_T2)
  183. # include <asm/core_t2.h>
  184. #elif defined(CONFIG_ALPHA_TSUNAMI)
  185. # include <asm/core_tsunami.h>
  186. #elif defined(CONFIG_ALPHA_TITAN)
  187. # include <asm/core_titan.h>
  188. #elif defined(CONFIG_ALPHA_WILDFIRE)
  189. # include <asm/core_wildfire.h>
  190. #else
  191. #error "What system is this?"
  192. #endif
  193. #endif /* GENERIC */
  194. /*
  195. * We always have external versions of these routines.
  196. */
  197. extern u8 inb(unsigned long port);
  198. extern u16 inw(unsigned long port);
  199. extern u32 inl(unsigned long port);
  200. extern void outb(u8 b, unsigned long port);
  201. extern void outw(u16 b, unsigned long port);
  202. extern void outl(u32 b, unsigned long port);
  203. extern u8 readb(const volatile void __iomem *addr);
  204. extern u16 readw(const volatile void __iomem *addr);
  205. extern u32 readl(const volatile void __iomem *addr);
  206. extern u64 readq(const volatile void __iomem *addr);
  207. extern void writeb(u8 b, volatile void __iomem *addr);
  208. extern void writew(u16 b, volatile void __iomem *addr);
  209. extern void writel(u32 b, volatile void __iomem *addr);
  210. extern void writeq(u64 b, volatile void __iomem *addr);
  211. extern u8 __raw_readb(const volatile void __iomem *addr);
  212. extern u16 __raw_readw(const volatile void __iomem *addr);
  213. extern u32 __raw_readl(const volatile void __iomem *addr);
  214. extern u64 __raw_readq(const volatile void __iomem *addr);
  215. extern void __raw_writeb(u8 b, volatile void __iomem *addr);
  216. extern void __raw_writew(u16 b, volatile void __iomem *addr);
  217. extern void __raw_writel(u32 b, volatile void __iomem *addr);
  218. extern void __raw_writeq(u64 b, volatile void __iomem *addr);
  219. /*
  220. * Mapping from port numbers to __iomem space is pretty easy.
  221. */
  222. /* These two have to be extern inline because of the extern prototype from
  223. <asm-generic/iomap.h>. It is not legal to mix "extern" and "static" for
  224. the same declaration. */
  225. extern inline void __iomem *ioport_map(unsigned long port, unsigned int size)
  226. {
  227. return IO_CONCAT(__IO_PREFIX,ioportmap) (port);
  228. }
  229. extern inline void ioport_unmap(void __iomem *addr)
  230. {
  231. }
  232. static inline void __iomem *ioremap(unsigned long port, unsigned long size)
  233. {
  234. return IO_CONCAT(__IO_PREFIX,ioremap) (port, size);
  235. }
  236. static inline void __iomem *__ioremap(unsigned long port, unsigned long size,
  237. unsigned long flags)
  238. {
  239. return ioremap(port, size);
  240. }
  241. static inline void __iomem * ioremap_nocache(unsigned long offset,
  242. unsigned long size)
  243. {
  244. return ioremap(offset, size);
  245. }
  246. static inline void iounmap(volatile void __iomem *addr)
  247. {
  248. IO_CONCAT(__IO_PREFIX,iounmap)(addr);
  249. }
  250. static inline int __is_ioaddr(unsigned long addr)
  251. {
  252. return IO_CONCAT(__IO_PREFIX,is_ioaddr)(addr);
  253. }
  254. #define __is_ioaddr(a) __is_ioaddr((unsigned long)(a))
  255. static inline int __is_mmio(const volatile void __iomem *addr)
  256. {
  257. return IO_CONCAT(__IO_PREFIX,is_mmio)(addr);
  258. }
  259. /*
  260. * If the actual I/O bits are sufficiently trivial, then expand inline.
  261. */
  262. #if IO_CONCAT(__IO_PREFIX,trivial_io_bw)
  263. extern inline unsigned int ioread8(void __iomem *addr)
  264. {
  265. unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread8)(addr);
  266. mb();
  267. return ret;
  268. }
  269. extern inline unsigned int ioread16(void __iomem *addr)
  270. {
  271. unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread16)(addr);
  272. mb();
  273. return ret;
  274. }
  275. extern inline void iowrite8(u8 b, void __iomem *addr)
  276. {
  277. IO_CONCAT(__IO_PREFIX,iowrite8)(b, addr);
  278. mb();
  279. }
  280. extern inline void iowrite16(u16 b, void __iomem *addr)
  281. {
  282. IO_CONCAT(__IO_PREFIX,iowrite16)(b, addr);
  283. mb();
  284. }
  285. extern inline u8 inb(unsigned long port)
  286. {
  287. return ioread8(ioport_map(port, 1));
  288. }
  289. extern inline u16 inw(unsigned long port)
  290. {
  291. return ioread16(ioport_map(port, 2));
  292. }
  293. extern inline void outb(u8 b, unsigned long port)
  294. {
  295. iowrite8(b, ioport_map(port, 1));
  296. }
  297. extern inline void outw(u16 b, unsigned long port)
  298. {
  299. iowrite16(b, ioport_map(port, 2));
  300. }
  301. #endif
  302. #if IO_CONCAT(__IO_PREFIX,trivial_io_lq)
  303. extern inline unsigned int ioread32(void __iomem *addr)
  304. {
  305. unsigned int ret = IO_CONCAT(__IO_PREFIX,ioread32)(addr);
  306. mb();
  307. return ret;
  308. }
  309. extern inline void iowrite32(u32 b, void __iomem *addr)
  310. {
  311. IO_CONCAT(__IO_PREFIX,iowrite32)(b, addr);
  312. mb();
  313. }
  314. extern inline u32 inl(unsigned long port)
  315. {
  316. return ioread32(ioport_map(port, 4));
  317. }
  318. extern inline void outl(u32 b, unsigned long port)
  319. {
  320. iowrite32(b, ioport_map(port, 4));
  321. }
  322. #endif
  323. #if IO_CONCAT(__IO_PREFIX,trivial_rw_bw) == 1
  324. extern inline u8 __raw_readb(const volatile void __iomem *addr)
  325. {
  326. return IO_CONCAT(__IO_PREFIX,readb)(addr);
  327. }
  328. extern inline u16 __raw_readw(const volatile void __iomem *addr)
  329. {
  330. return IO_CONCAT(__IO_PREFIX,readw)(addr);
  331. }
  332. extern inline void __raw_writeb(u8 b, volatile void __iomem *addr)
  333. {
  334. IO_CONCAT(__IO_PREFIX,writeb)(b, addr);
  335. }
  336. extern inline void __raw_writew(u16 b, volatile void __iomem *addr)
  337. {
  338. IO_CONCAT(__IO_PREFIX,writew)(b, addr);
  339. }
  340. extern inline u8 readb(const volatile void __iomem *addr)
  341. {
  342. u8 ret = __raw_readb(addr);
  343. mb();
  344. return ret;
  345. }
  346. extern inline u16 readw(const volatile void __iomem *addr)
  347. {
  348. u16 ret = __raw_readw(addr);
  349. mb();
  350. return ret;
  351. }
  352. extern inline void writeb(u8 b, volatile void __iomem *addr)
  353. {
  354. __raw_writeb(b, addr);
  355. mb();
  356. }
  357. extern inline void writew(u16 b, volatile void __iomem *addr)
  358. {
  359. __raw_writew(b, addr);
  360. mb();
  361. }
  362. #endif
  363. #if IO_CONCAT(__IO_PREFIX,trivial_rw_lq) == 1
  364. extern inline u32 __raw_readl(const volatile void __iomem *addr)
  365. {
  366. return IO_CONCAT(__IO_PREFIX,readl)(addr);
  367. }
  368. extern inline u64 __raw_readq(const volatile void __iomem *addr)
  369. {
  370. return IO_CONCAT(__IO_PREFIX,readq)(addr);
  371. }
  372. extern inline void __raw_writel(u32 b, volatile void __iomem *addr)
  373. {
  374. IO_CONCAT(__IO_PREFIX,writel)(b, addr);
  375. }
  376. extern inline void __raw_writeq(u64 b, volatile void __iomem *addr)
  377. {
  378. IO_CONCAT(__IO_PREFIX,writeq)(b, addr);
  379. }
  380. extern inline u32 readl(const volatile void __iomem *addr)
  381. {
  382. u32 ret = __raw_readl(addr);
  383. mb();
  384. return ret;
  385. }
  386. extern inline u64 readq(const volatile void __iomem *addr)
  387. {
  388. u64 ret = __raw_readq(addr);
  389. mb();
  390. return ret;
  391. }
  392. extern inline void writel(u32 b, volatile void __iomem *addr)
  393. {
  394. __raw_writel(b, addr);
  395. mb();
  396. }
  397. extern inline void writeq(u64 b, volatile void __iomem *addr)
  398. {
  399. __raw_writeq(b, addr);
  400. mb();
  401. }
  402. #endif
  403. #define inb_p inb
  404. #define inw_p inw
  405. #define inl_p inl
  406. #define outb_p outb
  407. #define outw_p outw
  408. #define outl_p outl
  409. #define readb_relaxed(addr) __raw_readb(addr)
  410. #define readw_relaxed(addr) __raw_readw(addr)
  411. #define readl_relaxed(addr) __raw_readl(addr)
  412. #define readq_relaxed(addr) __raw_readq(addr)
  413. #define mmiowb()
  414. /*
  415. * String version of IO memory access ops:
  416. */
  417. extern void memcpy_fromio(void *, const volatile void __iomem *, long);
  418. extern void memcpy_toio(volatile void __iomem *, const void *, long);
  419. extern void _memset_c_io(volatile void __iomem *, unsigned long, long);
  420. static inline void memset_io(volatile void __iomem *addr, u8 c, long len)
  421. {
  422. _memset_c_io(addr, 0x0101010101010101UL * c, len);
  423. }
  424. #define __HAVE_ARCH_MEMSETW_IO
  425. static inline void memsetw_io(volatile void __iomem *addr, u16 c, long len)
  426. {
  427. _memset_c_io(addr, 0x0001000100010001UL * c, len);
  428. }
  429. /*
  430. * String versions of in/out ops:
  431. */
  432. extern void insb (unsigned long port, void *dst, unsigned long count);
  433. extern void insw (unsigned long port, void *dst, unsigned long count);
  434. extern void insl (unsigned long port, void *dst, unsigned long count);
  435. extern void outsb (unsigned long port, const void *src, unsigned long count);
  436. extern void outsw (unsigned long port, const void *src, unsigned long count);
  437. extern void outsl (unsigned long port, const void *src, unsigned long count);
  438. /*
  439. * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
  440. * just copy it. The net code will then do the checksum later. Presently
  441. * only used by some shared memory 8390 Ethernet cards anyway.
  442. */
  443. #define eth_io_copy_and_sum(skb,src,len,unused) \
  444. memcpy_fromio((skb)->data,src,len)
  445. static inline int
  446. check_signature(const volatile void __iomem *io_addr,
  447. const unsigned char *signature, int length)
  448. {
  449. do {
  450. if (readb(io_addr) != *signature)
  451. return 0;
  452. io_addr++;
  453. signature++;
  454. } while (--length);
  455. return 1;
  456. }
  457. /*
  458. * The Alpha Jensen hardware for some rather strange reason puts
  459. * the RTC clock at 0x170 instead of 0x70. Probably due to some
  460. * misguided idea about using 0x70 for NMI stuff.
  461. *
  462. * These defines will override the defaults when doing RTC queries
  463. */
  464. #ifdef CONFIG_ALPHA_GENERIC
  465. # define RTC_PORT(x) ((x) + alpha_mv.rtc_port)
  466. #else
  467. # ifdef CONFIG_ALPHA_JENSEN
  468. # define RTC_PORT(x) (0x170+(x))
  469. # else
  470. # define RTC_PORT(x) (0x70 + (x))
  471. # endif
  472. #endif
  473. #define RTC_ALWAYS_BCD 0
  474. /* Nothing to do */
  475. #define dma_cache_inv(_start,_size) do { } while (0)
  476. #define dma_cache_wback(_start,_size) do { } while (0)
  477. #define dma_cache_wback_inv(_start,_size) do { } while (0)
  478. /*
  479. * Some mucking forons use if[n]def writeq to check if platform has it.
  480. * It's a bloody bad idea and we probably want ARCH_HAS_WRITEQ for them
  481. * to play with; for now just use cpp anti-recursion logics and make sure
  482. * that damn thing is defined and expands to itself.
  483. */
  484. #define writeq writeq
  485. #define readq readq
  486. /*
  487. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  488. * access
  489. */
  490. #define xlate_dev_mem_ptr(p) __va(p)
  491. /*
  492. * Convert a virtual cached pointer to an uncached pointer
  493. */
  494. #define xlate_dev_kmem_ptr(p) p
  495. #endif /* __KERNEL__ */
  496. #endif /* __ALPHA_IO_H */