1
0

io.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ALPHA_IO_H
  3. #define __ALPHA_IO_H
  4. #ifdef __KERNEL__
  5. #include <linux/kernel.h>
  6. #include <linux/mm.h>
  7. #include <asm/compiler.h>
  8. #include <asm/machvec.h>
  9. #include <asm/hwrpb.h>
  10. /*
  11. * Virtual -> physical identity mapping starts at this offset
  12. */
  13. #ifdef USE_48_BIT_KSEG
  14. #define IDENT_ADDR 0xffff800000000000UL
  15. #else
  16. #define IDENT_ADDR 0xfffffc0000000000UL
  17. #endif
  18. /*
  19. * We try to avoid hae updates (thus the cache), but when we
  20. * do need to update the hae, we need to do it atomically, so
  21. * that any interrupts wouldn't get confused with the hae
  22. * register not being up-to-date with respect to the hardware
  23. * value.
  24. */
  25. extern inline void __set_hae(unsigned long new_hae)
  26. {
  27. unsigned long flags = swpipl(IPL_MAX);
  28. barrier();
  29. alpha_mv.hae_cache = new_hae;
  30. *alpha_mv.hae_register = new_hae;
  31. mb();
  32. /* Re-read to make sure it was written. */
  33. new_hae = *alpha_mv.hae_register;
  34. setipl(flags);
  35. barrier();
  36. }
  37. extern inline void set_hae(unsigned long new_hae)
  38. {
  39. if (new_hae != alpha_mv.hae_cache)
  40. __set_hae(new_hae);
  41. }
  42. /*
  43. * Change virtual addresses to physical addresses and vv.
  44. */
  45. #ifdef USE_48_BIT_KSEG
  46. static inline unsigned long virt_to_phys(volatile void *address)
  47. {
  48. return (unsigned long)address - IDENT_ADDR;
  49. }
  50. static inline void * phys_to_virt(unsigned long address)
  51. {
  52. return (void *) (address + IDENT_ADDR);
  53. }
  54. #else
  55. static inline unsigned long virt_to_phys(volatile void *address)
  56. {
  57. unsigned long phys = (unsigned long)address;
  58. /* Sign-extend from bit 41. */
  59. phys <<= (64 - 41);
  60. phys = (long)phys >> (64 - 41);
  61. /* Crop to the physical address width of the processor. */
  62. phys &= (1ul << hwrpb->pa_bits) - 1;
  63. return phys;
  64. }
  65. static inline void * phys_to_virt(unsigned long address)
  66. {
  67. return (void *)(IDENT_ADDR + (address & ((1ul << 41) - 1)));
  68. }
  69. #endif
  70. #define virt_to_phys virt_to_phys
  71. #define phys_to_virt phys_to_virt
  72. /* Maximum PIO space address supported? */
  73. #define IO_SPACE_LIMIT 0xffff
  74. /*
  75. * Change addresses as seen by the kernel (virtual) to addresses as
  76. * seen by a device (bus), and vice versa.
  77. *
  78. * Note that this only works for a limited range of kernel addresses,
  79. * and very well may not span all memory. Consider this interface
  80. * deprecated in favour of the DMA-mapping API.
  81. */
  82. extern unsigned long __direct_map_base;
  83. extern unsigned long __direct_map_size;
  84. static inline unsigned long __deprecated isa_virt_to_bus(volatile void *address)
  85. {
  86. unsigned long phys = virt_to_phys(address);
  87. unsigned long bus = phys + __direct_map_base;
  88. return phys <= __direct_map_size ? bus : 0;
  89. }
  90. #define isa_virt_to_bus isa_virt_to_bus
  91. static inline void * __deprecated isa_bus_to_virt(unsigned long address)
  92. {
  93. void *virt;
  94. /* This check is a sanity check but also ensures that bus address 0
  95. maps to virtual address 0 which is useful to detect null pointers
  96. (the NCR driver is much simpler if NULL pointers are preserved). */
  97. address -= __direct_map_base;
  98. virt = phys_to_virt(address);
  99. return (long)address <= 0 ? NULL : virt;
  100. }
  101. #define isa_bus_to_virt isa_bus_to_virt
  102. /*
  103. * There are different chipsets to interface the Alpha CPUs to the world.
  104. */
  105. #define IO_CONCAT(a,b) _IO_CONCAT(a,b)
  106. #define _IO_CONCAT(a,b) a ## _ ## b
  107. #ifdef CONFIG_ALPHA_GENERIC
  108. /* In a generic kernel, we always go through the machine vector. */
  109. #define REMAP1(TYPE, NAME, QUAL) \
  110. static inline TYPE generic_##NAME(QUAL void __iomem *addr) \
  111. { \
  112. return alpha_mv.mv_##NAME(addr); \
  113. }
  114. #define REMAP2(TYPE, NAME, QUAL) \
  115. static inline void generic_##NAME(TYPE b, QUAL void __iomem *addr) \
  116. { \
  117. alpha_mv.mv_##NAME(b, addr); \
  118. }
  119. REMAP1(unsigned int, ioread8, const)
  120. REMAP1(unsigned int, ioread16, const)
  121. REMAP1(unsigned int, ioread32, const)
  122. REMAP1(u64, ioread64, const)
  123. REMAP1(u8, readb, const volatile)
  124. REMAP1(u16, readw, const volatile)
  125. REMAP1(u32, readl, const volatile)
  126. REMAP1(u64, readq, const volatile)
  127. REMAP2(u8, iowrite8, /**/)
  128. REMAP2(u16, iowrite16, /**/)
  129. REMAP2(u32, iowrite32, /**/)
  130. REMAP2(u64, iowrite64, /**/)
  131. REMAP2(u8, writeb, volatile)
  132. REMAP2(u16, writew, volatile)
  133. REMAP2(u32, writel, volatile)
  134. REMAP2(u64, writeq, volatile)
  135. #undef REMAP1
  136. #undef REMAP2
  137. extern inline void __iomem *generic_ioportmap(unsigned long a)
  138. {
  139. return alpha_mv.mv_ioportmap(a);
  140. }
  141. static inline void __iomem *generic_ioremap(unsigned long a, unsigned long s)
  142. {
  143. return alpha_mv.mv_ioremap(a, s);
  144. }
  145. static inline void generic_iounmap(volatile void __iomem *a)
  146. {
  147. return alpha_mv.mv_iounmap(a);
  148. }
  149. static inline int generic_is_ioaddr(unsigned long a)
  150. {
  151. return alpha_mv.mv_is_ioaddr(a);
  152. }
  153. static inline int generic_is_mmio(const volatile void __iomem *a)
  154. {
  155. return alpha_mv.mv_is_mmio(a);
  156. }
  157. #define __IO_PREFIX generic
  158. #define generic_trivial_rw_bw 0
  159. #define generic_trivial_rw_lq 0
  160. #define generic_trivial_io_bw 0
  161. #define generic_trivial_io_lq 0
  162. #define generic_trivial_iounmap 0
  163. #else
  164. #if defined(CONFIG_ALPHA_CIA)
  165. # include <asm/core_cia.h>
  166. #elif defined(CONFIG_ALPHA_IRONGATE)
  167. # include <asm/core_irongate.h>
  168. #elif defined(CONFIG_ALPHA_MARVEL)
  169. # include <asm/core_marvel.h>
  170. #elif defined(CONFIG_ALPHA_MCPCIA)
  171. # include <asm/core_mcpcia.h>
  172. #elif defined(CONFIG_ALPHA_POLARIS)
  173. # include <asm/core_polaris.h>
  174. #elif defined(CONFIG_ALPHA_T2)
  175. # include <asm/core_t2.h>
  176. #elif defined(CONFIG_ALPHA_TSUNAMI)
  177. # include <asm/core_tsunami.h>
  178. #elif defined(CONFIG_ALPHA_TITAN)
  179. # include <asm/core_titan.h>
  180. #elif defined(CONFIG_ALPHA_WILDFIRE)
  181. # include <asm/core_wildfire.h>
  182. #else
  183. #error "What system is this?"
  184. #endif
  185. #endif /* GENERIC */
  186. /*
  187. * We always have external versions of these routines.
  188. */
  189. extern u8 inb(unsigned long port);
  190. extern u16 inw(unsigned long port);
  191. extern u32 inl(unsigned long port);
  192. extern void outb(u8 b, unsigned long port);
  193. extern void outw(u16 b, unsigned long port);
  194. extern void outl(u32 b, unsigned long port);
  195. #define inb inb
  196. #define inw inw
  197. #define inl inl
  198. #define outb outb
  199. #define outw outw
  200. #define outl outl
  201. extern u8 readb(const volatile void __iomem *addr);
  202. extern u16 readw(const volatile void __iomem *addr);
  203. extern u32 readl(const volatile void __iomem *addr);
  204. extern u64 readq(const volatile void __iomem *addr);
  205. extern void writeb(u8 b, volatile void __iomem *addr);
  206. extern void writew(u16 b, volatile void __iomem *addr);
  207. extern void writel(u32 b, volatile void __iomem *addr);
  208. extern void writeq(u64 b, volatile void __iomem *addr);
  209. #define readb readb
  210. #define readw readw
  211. #define readl readl
  212. #define readq readq
  213. #define writeb writeb
  214. #define writew writew
  215. #define writel writel
  216. #define writeq writeq
  217. extern u8 __raw_readb(const volatile void __iomem *addr);
  218. extern u16 __raw_readw(const volatile void __iomem *addr);
  219. extern u32 __raw_readl(const volatile void __iomem *addr);
  220. extern u64 __raw_readq(const volatile void __iomem *addr);
  221. extern void __raw_writeb(u8 b, volatile void __iomem *addr);
  222. extern void __raw_writew(u16 b, volatile void __iomem *addr);
  223. extern void __raw_writel(u32 b, volatile void __iomem *addr);
  224. extern void __raw_writeq(u64 b, volatile void __iomem *addr);
  225. #define __raw_readb __raw_readb
  226. #define __raw_readw __raw_readw
  227. #define __raw_readl __raw_readl
  228. #define __raw_readq __raw_readq
  229. #define __raw_writeb __raw_writeb
  230. #define __raw_writew __raw_writew
  231. #define __raw_writel __raw_writel
  232. #define __raw_writeq __raw_writeq
  233. extern unsigned int ioread8(const void __iomem *);
  234. extern unsigned int ioread16(const void __iomem *);
  235. extern unsigned int ioread32(const void __iomem *);
  236. extern u64 ioread64(const void __iomem *);
  237. extern void iowrite8(u8, void __iomem *);
  238. extern void iowrite16(u16, void __iomem *);
  239. extern void iowrite32(u32, void __iomem *);
  240. extern void iowrite64(u64, void __iomem *);
  241. extern void ioread8_rep(const void __iomem *port, void *buf, unsigned long count);
  242. extern void ioread16_rep(const void __iomem *port, void *buf, unsigned long count);
  243. extern void ioread32_rep(const void __iomem *port, void *buf, unsigned long count);
  244. extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
  245. extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
  246. extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
  247. extern inline void __iomem *ioport_map(unsigned long port, unsigned int size)
  248. {
  249. return IO_CONCAT(__IO_PREFIX,ioportmap) (port);
  250. }
  251. extern inline void ioport_unmap(void __iomem *addr)
  252. {
  253. }
  254. #define ioport_map ioport_map
  255. #define ioport_unmap ioport_unmap
  256. static inline void __iomem *ioremap(unsigned long port, unsigned long size)
  257. {
  258. return IO_CONCAT(__IO_PREFIX,ioremap) (port, size);
  259. }
  260. #define ioremap_wc ioremap
  261. static inline void iounmap(volatile void __iomem *addr)
  262. {
  263. IO_CONCAT(__IO_PREFIX,iounmap)(addr);
  264. }
  265. static inline int __is_ioaddr(unsigned long addr)
  266. {
  267. return IO_CONCAT(__IO_PREFIX,is_ioaddr)(addr);
  268. }
  269. #define __is_ioaddr(a) __is_ioaddr((unsigned long)(a))
  270. static inline int __is_mmio(const volatile void __iomem *addr)
  271. {
  272. return IO_CONCAT(__IO_PREFIX,is_mmio)(addr);
  273. }
  274. /*
  275. * If the actual I/O bits are sufficiently trivial, then expand inline.
  276. */
  277. #if IO_CONCAT(__IO_PREFIX,trivial_io_bw)
  278. extern inline unsigned int ioread8(const void __iomem *addr)
  279. {
  280. unsigned int ret;
  281. mb();
  282. ret = IO_CONCAT(__IO_PREFIX,ioread8)(addr);
  283. mb();
  284. return ret;
  285. }
  286. extern inline unsigned int ioread16(const void __iomem *addr)
  287. {
  288. unsigned int ret;
  289. mb();
  290. ret = IO_CONCAT(__IO_PREFIX,ioread16)(addr);
  291. mb();
  292. return ret;
  293. }
  294. extern inline void iowrite8(u8 b, void __iomem *addr)
  295. {
  296. mb();
  297. IO_CONCAT(__IO_PREFIX, iowrite8)(b, addr);
  298. }
  299. extern inline void iowrite16(u16 b, void __iomem *addr)
  300. {
  301. mb();
  302. IO_CONCAT(__IO_PREFIX, iowrite16)(b, addr);
  303. }
  304. extern inline u8 inb(unsigned long port)
  305. {
  306. return ioread8(ioport_map(port, 1));
  307. }
  308. extern inline u16 inw(unsigned long port)
  309. {
  310. return ioread16(ioport_map(port, 2));
  311. }
  312. extern inline void outb(u8 b, unsigned long port)
  313. {
  314. iowrite8(b, ioport_map(port, 1));
  315. }
  316. extern inline void outw(u16 b, unsigned long port)
  317. {
  318. iowrite16(b, ioport_map(port, 2));
  319. }
  320. #endif
  321. #define ioread8 ioread8
  322. #define ioread16 ioread16
  323. #define iowrite8 iowrite8
  324. #define iowrite16 iowrite16
  325. #if IO_CONCAT(__IO_PREFIX,trivial_io_lq)
  326. extern inline unsigned int ioread32(const void __iomem *addr)
  327. {
  328. unsigned int ret;
  329. mb();
  330. ret = IO_CONCAT(__IO_PREFIX,ioread32)(addr);
  331. mb();
  332. return ret;
  333. }
  334. extern inline u64 ioread64(const void __iomem *addr)
  335. {
  336. unsigned int ret;
  337. mb();
  338. ret = IO_CONCAT(__IO_PREFIX,ioread64)(addr);
  339. mb();
  340. return ret;
  341. }
  342. extern inline void iowrite32(u32 b, void __iomem *addr)
  343. {
  344. mb();
  345. IO_CONCAT(__IO_PREFIX, iowrite32)(b, addr);
  346. }
  347. extern inline void iowrite64(u64 b, void __iomem *addr)
  348. {
  349. mb();
  350. IO_CONCAT(__IO_PREFIX, iowrite64)(b, addr);
  351. }
  352. extern inline u32 inl(unsigned long port)
  353. {
  354. return ioread32(ioport_map(port, 4));
  355. }
  356. extern inline void outl(u32 b, unsigned long port)
  357. {
  358. iowrite32(b, ioport_map(port, 4));
  359. }
  360. #endif
  361. #define ioread32 ioread32
  362. #define ioread64 ioread64
  363. #define iowrite32 iowrite32
  364. #define iowrite64 iowrite64
  365. #if IO_CONCAT(__IO_PREFIX,trivial_rw_bw) == 1
  366. extern inline u8 __raw_readb(const volatile void __iomem *addr)
  367. {
  368. return IO_CONCAT(__IO_PREFIX,readb)(addr);
  369. }
  370. extern inline u16 __raw_readw(const volatile void __iomem *addr)
  371. {
  372. return IO_CONCAT(__IO_PREFIX,readw)(addr);
  373. }
  374. extern inline void __raw_writeb(u8 b, volatile void __iomem *addr)
  375. {
  376. IO_CONCAT(__IO_PREFIX,writeb)(b, addr);
  377. }
  378. extern inline void __raw_writew(u16 b, volatile void __iomem *addr)
  379. {
  380. IO_CONCAT(__IO_PREFIX,writew)(b, addr);
  381. }
  382. extern inline u8 readb(const volatile void __iomem *addr)
  383. {
  384. u8 ret;
  385. mb();
  386. ret = __raw_readb(addr);
  387. mb();
  388. return ret;
  389. }
  390. extern inline u16 readw(const volatile void __iomem *addr)
  391. {
  392. u16 ret;
  393. mb();
  394. ret = __raw_readw(addr);
  395. mb();
  396. return ret;
  397. }
  398. extern inline void writeb(u8 b, volatile void __iomem *addr)
  399. {
  400. mb();
  401. __raw_writeb(b, addr);
  402. }
  403. extern inline void writew(u16 b, volatile void __iomem *addr)
  404. {
  405. mb();
  406. __raw_writew(b, addr);
  407. }
  408. #endif
  409. #if IO_CONCAT(__IO_PREFIX,trivial_rw_lq) == 1
  410. extern inline u32 __raw_readl(const volatile void __iomem *addr)
  411. {
  412. return IO_CONCAT(__IO_PREFIX,readl)(addr);
  413. }
  414. extern inline u64 __raw_readq(const volatile void __iomem *addr)
  415. {
  416. return IO_CONCAT(__IO_PREFIX,readq)(addr);
  417. }
  418. extern inline void __raw_writel(u32 b, volatile void __iomem *addr)
  419. {
  420. IO_CONCAT(__IO_PREFIX,writel)(b, addr);
  421. }
  422. extern inline void __raw_writeq(u64 b, volatile void __iomem *addr)
  423. {
  424. IO_CONCAT(__IO_PREFIX,writeq)(b, addr);
  425. }
  426. extern inline u32 readl(const volatile void __iomem *addr)
  427. {
  428. u32 ret;
  429. mb();
  430. ret = __raw_readl(addr);
  431. mb();
  432. return ret;
  433. }
  434. extern inline u64 readq(const volatile void __iomem *addr)
  435. {
  436. u64 ret;
  437. mb();
  438. ret = __raw_readq(addr);
  439. mb();
  440. return ret;
  441. }
  442. extern inline void writel(u32 b, volatile void __iomem *addr)
  443. {
  444. mb();
  445. __raw_writel(b, addr);
  446. }
  447. extern inline void writeq(u64 b, volatile void __iomem *addr)
  448. {
  449. mb();
  450. __raw_writeq(b, addr);
  451. }
  452. #endif
  453. #define ioread16be(p) swab16(ioread16(p))
  454. #define ioread32be(p) swab32(ioread32(p))
  455. #define ioread64be(p) swab64(ioread64(p))
  456. #define iowrite16be(v,p) iowrite16(swab16(v), (p))
  457. #define iowrite32be(v,p) iowrite32(swab32(v), (p))
  458. #define iowrite64be(v,p) iowrite64(swab64(v), (p))
  459. #define inb_p inb
  460. #define inw_p inw
  461. #define inl_p inl
  462. #define outb_p outb
  463. #define outw_p outw
  464. #define outl_p outl
  465. extern u8 readb_relaxed(const volatile void __iomem *addr);
  466. extern u16 readw_relaxed(const volatile void __iomem *addr);
  467. extern u32 readl_relaxed(const volatile void __iomem *addr);
  468. extern u64 readq_relaxed(const volatile void __iomem *addr);
  469. #define readb_relaxed readb_relaxed
  470. #define readw_relaxed readw_relaxed
  471. #define readl_relaxed readl_relaxed
  472. #define readq_relaxed readq_relaxed
  473. #if IO_CONCAT(__IO_PREFIX,trivial_io_bw)
  474. extern inline u8 readb_relaxed(const volatile void __iomem *addr)
  475. {
  476. mb();
  477. return __raw_readb(addr);
  478. }
  479. extern inline u16 readw_relaxed(const volatile void __iomem *addr)
  480. {
  481. mb();
  482. return __raw_readw(addr);
  483. }
  484. #endif
  485. #if IO_CONCAT(__IO_PREFIX,trivial_io_lq)
  486. extern inline u32 readl_relaxed(const volatile void __iomem *addr)
  487. {
  488. mb();
  489. return __raw_readl(addr);
  490. }
  491. extern inline u64 readq_relaxed(const volatile void __iomem *addr)
  492. {
  493. mb();
  494. return __raw_readq(addr);
  495. }
  496. #endif
  497. #define writeb_relaxed writeb
  498. #define writew_relaxed writew
  499. #define writel_relaxed writel
  500. #define writeq_relaxed writeq
  501. /*
  502. * String version of IO memory access ops:
  503. */
  504. extern void memcpy_fromio(void *, const volatile void __iomem *, long);
  505. extern void memcpy_toio(volatile void __iomem *, const void *, long);
  506. extern void _memset_c_io(volatile void __iomem *, unsigned long, long);
  507. static inline void memset_io(volatile void __iomem *addr, u8 c, long len)
  508. {
  509. _memset_c_io(addr, 0x0101010101010101UL * c, len);
  510. }
  511. #define __HAVE_ARCH_MEMSETW_IO
  512. static inline void memsetw_io(volatile void __iomem *addr, u16 c, long len)
  513. {
  514. _memset_c_io(addr, 0x0001000100010001UL * c, len);
  515. }
  516. #define memset_io memset_io
  517. #define memcpy_fromio memcpy_fromio
  518. #define memcpy_toio memcpy_toio
  519. /*
  520. * String versions of in/out ops:
  521. */
  522. extern void insb (unsigned long port, void *dst, unsigned long count);
  523. extern void insw (unsigned long port, void *dst, unsigned long count);
  524. extern void insl (unsigned long port, void *dst, unsigned long count);
  525. extern void outsb (unsigned long port, const void *src, unsigned long count);
  526. extern void outsw (unsigned long port, const void *src, unsigned long count);
  527. extern void outsl (unsigned long port, const void *src, unsigned long count);
  528. #define insb insb
  529. #define insw insw
  530. #define insl insl
  531. #define outsb outsb
  532. #define outsw outsw
  533. #define outsl outsl
  534. #define RTC_PORT(x) (0x70 + (x))
  535. #define RTC_ALWAYS_BCD 0
  536. #define ioread64 ioread64
  537. #define iowrite64 iowrite64
  538. #define ioread8_rep ioread8_rep
  539. #define ioread16_rep ioread16_rep
  540. #define ioread32_rep ioread32_rep
  541. #define iowrite8_rep iowrite8_rep
  542. #define iowrite16_rep iowrite16_rep
  543. #define iowrite32_rep iowrite32_rep
  544. #define pci_iounmap pci_iounmap
  545. #include <asm-generic/io.h>
  546. #endif /* __KERNEL__ */
  547. #endif /* __ALPHA_IO_H */