io.h 14 KB

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