io.h 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. /* Generic I/O port emulation.
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef __ASM_GENERIC_IO_H
  12. #define __ASM_GENERIC_IO_H
  13. #include <asm/page.h> /* I/O is all done through memory accesses */
  14. #include <linux/string.h> /* for memset() and memcpy() */
  15. #include <linux/types.h>
  16. #ifdef CONFIG_GENERIC_IOMAP
  17. #include <asm-generic/iomap.h>
  18. #endif
  19. #include <asm-generic/pci_iomap.h>
  20. #ifndef mmiowb
  21. #define mmiowb() do {} while (0)
  22. #endif
  23. #ifndef __io_br
  24. #define __io_br() barrier()
  25. #endif
  26. /* prevent prefetching of coherent DMA data ahead of a dma-complete */
  27. #ifndef __io_ar
  28. #ifdef rmb
  29. #define __io_ar() rmb()
  30. #else
  31. #define __io_ar() barrier()
  32. #endif
  33. #endif
  34. /* flush writes to coherent DMA data before possibly triggering a DMA read */
  35. #ifndef __io_bw
  36. #ifdef wmb
  37. #define __io_bw() wmb()
  38. #else
  39. #define __io_bw() barrier()
  40. #endif
  41. #endif
  42. /* serialize device access against a spin_unlock, usually handled there. */
  43. #ifndef __io_aw
  44. #define __io_aw() barrier()
  45. #endif
  46. #ifndef __io_pbw
  47. #define __io_pbw() __io_bw()
  48. #endif
  49. #ifndef __io_paw
  50. #define __io_paw() __io_aw()
  51. #endif
  52. #ifndef __io_pbr
  53. #define __io_pbr() __io_br()
  54. #endif
  55. #ifndef __io_par
  56. #define __io_par() __io_ar()
  57. #endif
  58. /*
  59. * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
  60. *
  61. * On some architectures memory mapped IO needs to be accessed differently.
  62. * On the simple architectures, we just read/write the memory location
  63. * directly.
  64. */
  65. #ifndef __raw_readb
  66. #define __raw_readb __raw_readb
  67. static inline u8 __raw_readb(const volatile void __iomem *addr)
  68. {
  69. return *(const volatile u8 __force *)addr;
  70. }
  71. #endif
  72. #ifndef __raw_readw
  73. #define __raw_readw __raw_readw
  74. static inline u16 __raw_readw(const volatile void __iomem *addr)
  75. {
  76. return *(const volatile u16 __force *)addr;
  77. }
  78. #endif
  79. #ifndef __raw_readl
  80. #define __raw_readl __raw_readl
  81. static inline u32 __raw_readl(const volatile void __iomem *addr)
  82. {
  83. return *(const volatile u32 __force *)addr;
  84. }
  85. #endif
  86. #ifdef CONFIG_64BIT
  87. #ifndef __raw_readq
  88. #define __raw_readq __raw_readq
  89. static inline u64 __raw_readq(const volatile void __iomem *addr)
  90. {
  91. return *(const volatile u64 __force *)addr;
  92. }
  93. #endif
  94. #endif /* CONFIG_64BIT */
  95. #ifndef __raw_writeb
  96. #define __raw_writeb __raw_writeb
  97. static inline void __raw_writeb(u8 value, volatile void __iomem *addr)
  98. {
  99. *(volatile u8 __force *)addr = value;
  100. }
  101. #endif
  102. #ifndef __raw_writew
  103. #define __raw_writew __raw_writew
  104. static inline void __raw_writew(u16 value, volatile void __iomem *addr)
  105. {
  106. *(volatile u16 __force *)addr = value;
  107. }
  108. #endif
  109. #ifndef __raw_writel
  110. #define __raw_writel __raw_writel
  111. static inline void __raw_writel(u32 value, volatile void __iomem *addr)
  112. {
  113. *(volatile u32 __force *)addr = value;
  114. }
  115. #endif
  116. #ifdef CONFIG_64BIT
  117. #ifndef __raw_writeq
  118. #define __raw_writeq __raw_writeq
  119. static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
  120. {
  121. *(volatile u64 __force *)addr = value;
  122. }
  123. #endif
  124. #endif /* CONFIG_64BIT */
  125. /*
  126. * {read,write}{b,w,l,q}() access little endian memory and return result in
  127. * native endianness.
  128. */
  129. #ifndef readb
  130. #define readb readb
  131. static inline u8 readb(const volatile void __iomem *addr)
  132. {
  133. u8 val;
  134. __io_br();
  135. val = __raw_readb(addr);
  136. __io_ar();
  137. return val;
  138. }
  139. #endif
  140. #ifndef readw
  141. #define readw readw
  142. static inline u16 readw(const volatile void __iomem *addr)
  143. {
  144. u16 val;
  145. __io_br();
  146. val = __le16_to_cpu(__raw_readw(addr));
  147. __io_ar();
  148. return val;
  149. }
  150. #endif
  151. #ifndef readl
  152. #define readl readl
  153. static inline u32 readl(const volatile void __iomem *addr)
  154. {
  155. u32 val;
  156. __io_br();
  157. val = __le32_to_cpu(__raw_readl(addr));
  158. __io_ar();
  159. return val;
  160. }
  161. #endif
  162. #ifdef CONFIG_64BIT
  163. #ifndef readq
  164. #define readq readq
  165. static inline u64 readq(const volatile void __iomem *addr)
  166. {
  167. u64 val;
  168. __io_br();
  169. val = __le64_to_cpu(__raw_readq(addr));
  170. __io_ar();
  171. return val;
  172. }
  173. #endif
  174. #endif /* CONFIG_64BIT */
  175. #ifndef writeb
  176. #define writeb writeb
  177. static inline void writeb(u8 value, volatile void __iomem *addr)
  178. {
  179. __io_bw();
  180. __raw_writeb(value, addr);
  181. __io_aw();
  182. }
  183. #endif
  184. #ifndef writew
  185. #define writew writew
  186. static inline void writew(u16 value, volatile void __iomem *addr)
  187. {
  188. __io_bw();
  189. __raw_writew(cpu_to_le16(value), addr);
  190. __io_aw();
  191. }
  192. #endif
  193. #ifndef writel
  194. #define writel writel
  195. static inline void writel(u32 value, volatile void __iomem *addr)
  196. {
  197. __io_bw();
  198. __raw_writel(__cpu_to_le32(value), addr);
  199. __io_aw();
  200. }
  201. #endif
  202. #ifdef CONFIG_64BIT
  203. #ifndef writeq
  204. #define writeq writeq
  205. static inline void writeq(u64 value, volatile void __iomem *addr)
  206. {
  207. __io_bw();
  208. __raw_writeq(__cpu_to_le64(value), addr);
  209. __io_aw();
  210. }
  211. #endif
  212. #endif /* CONFIG_64BIT */
  213. /*
  214. * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
  215. * are not guaranteed to provide ordering against spinlocks or memory
  216. * accesses.
  217. */
  218. #ifndef readb_relaxed
  219. #define readb_relaxed readb_relaxed
  220. static inline u8 readb_relaxed(const volatile void __iomem *addr)
  221. {
  222. return __raw_readb(addr);
  223. }
  224. #endif
  225. #ifndef readw_relaxed
  226. #define readw_relaxed readw_relaxed
  227. static inline u16 readw_relaxed(const volatile void __iomem *addr)
  228. {
  229. return __le16_to_cpu(__raw_readw(addr));
  230. }
  231. #endif
  232. #ifndef readl_relaxed
  233. #define readl_relaxed readl_relaxed
  234. static inline u32 readl_relaxed(const volatile void __iomem *addr)
  235. {
  236. return __le32_to_cpu(__raw_readl(addr));
  237. }
  238. #endif
  239. #if defined(readq) && !defined(readq_relaxed)
  240. #define readq_relaxed readq_relaxed
  241. static inline u64 readq_relaxed(const volatile void __iomem *addr)
  242. {
  243. return __le64_to_cpu(__raw_readq(addr));
  244. }
  245. #endif
  246. #ifndef writeb_relaxed
  247. #define writeb_relaxed writeb_relaxed
  248. static inline void writeb_relaxed(u8 value, volatile void __iomem *addr)
  249. {
  250. __raw_writeb(value, addr);
  251. }
  252. #endif
  253. #ifndef writew_relaxed
  254. #define writew_relaxed writew_relaxed
  255. static inline void writew_relaxed(u16 value, volatile void __iomem *addr)
  256. {
  257. __raw_writew(cpu_to_le16(value), addr);
  258. }
  259. #endif
  260. #ifndef writel_relaxed
  261. #define writel_relaxed writel_relaxed
  262. static inline void writel_relaxed(u32 value, volatile void __iomem *addr)
  263. {
  264. __raw_writel(__cpu_to_le32(value), addr);
  265. }
  266. #endif
  267. #if defined(writeq) && !defined(writeq_relaxed)
  268. #define writeq_relaxed writeq_relaxed
  269. static inline void writeq_relaxed(u64 value, volatile void __iomem *addr)
  270. {
  271. __raw_writeq(__cpu_to_le64(value), addr);
  272. }
  273. #endif
  274. /*
  275. * {read,write}s{b,w,l,q}() repeatedly access the same memory address in
  276. * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times).
  277. */
  278. #ifndef readsb
  279. #define readsb readsb
  280. static inline void readsb(const volatile void __iomem *addr, void *buffer,
  281. unsigned int count)
  282. {
  283. if (count) {
  284. u8 *buf = buffer;
  285. do {
  286. u8 x = __raw_readb(addr);
  287. *buf++ = x;
  288. } while (--count);
  289. }
  290. }
  291. #endif
  292. #ifndef readsw
  293. #define readsw readsw
  294. static inline void readsw(const volatile void __iomem *addr, void *buffer,
  295. unsigned int count)
  296. {
  297. if (count) {
  298. u16 *buf = buffer;
  299. do {
  300. u16 x = __raw_readw(addr);
  301. *buf++ = x;
  302. } while (--count);
  303. }
  304. }
  305. #endif
  306. #ifndef readsl
  307. #define readsl readsl
  308. static inline void readsl(const volatile void __iomem *addr, void *buffer,
  309. unsigned int count)
  310. {
  311. if (count) {
  312. u32 *buf = buffer;
  313. do {
  314. u32 x = __raw_readl(addr);
  315. *buf++ = x;
  316. } while (--count);
  317. }
  318. }
  319. #endif
  320. #ifdef CONFIG_64BIT
  321. #ifndef readsq
  322. #define readsq readsq
  323. static inline void readsq(const volatile void __iomem *addr, void *buffer,
  324. unsigned int count)
  325. {
  326. if (count) {
  327. u64 *buf = buffer;
  328. do {
  329. u64 x = __raw_readq(addr);
  330. *buf++ = x;
  331. } while (--count);
  332. }
  333. }
  334. #endif
  335. #endif /* CONFIG_64BIT */
  336. #ifndef writesb
  337. #define writesb writesb
  338. static inline void writesb(volatile void __iomem *addr, const void *buffer,
  339. unsigned int count)
  340. {
  341. if (count) {
  342. const u8 *buf = buffer;
  343. do {
  344. __raw_writeb(*buf++, addr);
  345. } while (--count);
  346. }
  347. }
  348. #endif
  349. #ifndef writesw
  350. #define writesw writesw
  351. static inline void writesw(volatile void __iomem *addr, const void *buffer,
  352. unsigned int count)
  353. {
  354. if (count) {
  355. const u16 *buf = buffer;
  356. do {
  357. __raw_writew(*buf++, addr);
  358. } while (--count);
  359. }
  360. }
  361. #endif
  362. #ifndef writesl
  363. #define writesl writesl
  364. static inline void writesl(volatile void __iomem *addr, const void *buffer,
  365. unsigned int count)
  366. {
  367. if (count) {
  368. const u32 *buf = buffer;
  369. do {
  370. __raw_writel(*buf++, addr);
  371. } while (--count);
  372. }
  373. }
  374. #endif
  375. #ifdef CONFIG_64BIT
  376. #ifndef writesq
  377. #define writesq writesq
  378. static inline void writesq(volatile void __iomem *addr, const void *buffer,
  379. unsigned int count)
  380. {
  381. if (count) {
  382. const u64 *buf = buffer;
  383. do {
  384. __raw_writeq(*buf++, addr);
  385. } while (--count);
  386. }
  387. }
  388. #endif
  389. #endif /* CONFIG_64BIT */
  390. #ifndef PCI_IOBASE
  391. #define PCI_IOBASE ((void __iomem *)0)
  392. #endif
  393. #ifndef IO_SPACE_LIMIT
  394. #define IO_SPACE_LIMIT 0xffff
  395. #endif
  396. #include <linux/logic_pio.h>
  397. /*
  398. * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be
  399. * implemented on hardware that needs an additional delay for I/O accesses to
  400. * take effect.
  401. */
  402. #ifndef inb
  403. #define inb inb
  404. static inline u8 inb(unsigned long addr)
  405. {
  406. u8 val;
  407. __io_pbr();
  408. val = __raw_readb(PCI_IOBASE + addr);
  409. __io_par();
  410. return val;
  411. }
  412. #endif
  413. #ifndef inw
  414. #define inw inw
  415. static inline u16 inw(unsigned long addr)
  416. {
  417. u16 val;
  418. __io_pbr();
  419. val = __le16_to_cpu(__raw_readw(PCI_IOBASE + addr));
  420. __io_par();
  421. return val;
  422. }
  423. #endif
  424. #ifndef inl
  425. #define inl inl
  426. static inline u32 inl(unsigned long addr)
  427. {
  428. u32 val;
  429. __io_pbr();
  430. val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
  431. __io_par();
  432. return val;
  433. }
  434. #endif
  435. #ifndef outb
  436. #define outb outb
  437. static inline void outb(u8 value, unsigned long addr)
  438. {
  439. __io_pbw();
  440. __raw_writeb(value, PCI_IOBASE + addr);
  441. __io_paw();
  442. }
  443. #endif
  444. #ifndef outw
  445. #define outw outw
  446. static inline void outw(u16 value, unsigned long addr)
  447. {
  448. __io_pbw();
  449. __raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
  450. __io_paw();
  451. }
  452. #endif
  453. #ifndef outl
  454. #define outl outl
  455. static inline void outl(u32 value, unsigned long addr)
  456. {
  457. __io_pbw();
  458. __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
  459. __io_paw();
  460. }
  461. #endif
  462. #ifndef inb_p
  463. #define inb_p inb_p
  464. static inline u8 inb_p(unsigned long addr)
  465. {
  466. return inb(addr);
  467. }
  468. #endif
  469. #ifndef inw_p
  470. #define inw_p inw_p
  471. static inline u16 inw_p(unsigned long addr)
  472. {
  473. return inw(addr);
  474. }
  475. #endif
  476. #ifndef inl_p
  477. #define inl_p inl_p
  478. static inline u32 inl_p(unsigned long addr)
  479. {
  480. return inl(addr);
  481. }
  482. #endif
  483. #ifndef outb_p
  484. #define outb_p outb_p
  485. static inline void outb_p(u8 value, unsigned long addr)
  486. {
  487. outb(value, addr);
  488. }
  489. #endif
  490. #ifndef outw_p
  491. #define outw_p outw_p
  492. static inline void outw_p(u16 value, unsigned long addr)
  493. {
  494. outw(value, addr);
  495. }
  496. #endif
  497. #ifndef outl_p
  498. #define outl_p outl_p
  499. static inline void outl_p(u32 value, unsigned long addr)
  500. {
  501. outl(value, addr);
  502. }
  503. #endif
  504. /*
  505. * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a
  506. * single I/O port multiple times.
  507. */
  508. #ifndef insb
  509. #define insb insb
  510. static inline void insb(unsigned long addr, void *buffer, unsigned int count)
  511. {
  512. readsb(PCI_IOBASE + addr, buffer, count);
  513. }
  514. #endif
  515. #ifndef insw
  516. #define insw insw
  517. static inline void insw(unsigned long addr, void *buffer, unsigned int count)
  518. {
  519. readsw(PCI_IOBASE + addr, buffer, count);
  520. }
  521. #endif
  522. #ifndef insl
  523. #define insl insl
  524. static inline void insl(unsigned long addr, void *buffer, unsigned int count)
  525. {
  526. readsl(PCI_IOBASE + addr, buffer, count);
  527. }
  528. #endif
  529. #ifndef outsb
  530. #define outsb outsb
  531. static inline void outsb(unsigned long addr, const void *buffer,
  532. unsigned int count)
  533. {
  534. writesb(PCI_IOBASE + addr, buffer, count);
  535. }
  536. #endif
  537. #ifndef outsw
  538. #define outsw outsw
  539. static inline void outsw(unsigned long addr, const void *buffer,
  540. unsigned int count)
  541. {
  542. writesw(PCI_IOBASE + addr, buffer, count);
  543. }
  544. #endif
  545. #ifndef outsl
  546. #define outsl outsl
  547. static inline void outsl(unsigned long addr, const void *buffer,
  548. unsigned int count)
  549. {
  550. writesl(PCI_IOBASE + addr, buffer, count);
  551. }
  552. #endif
  553. #ifndef insb_p
  554. #define insb_p insb_p
  555. static inline void insb_p(unsigned long addr, void *buffer, unsigned int count)
  556. {
  557. insb(addr, buffer, count);
  558. }
  559. #endif
  560. #ifndef insw_p
  561. #define insw_p insw_p
  562. static inline void insw_p(unsigned long addr, void *buffer, unsigned int count)
  563. {
  564. insw(addr, buffer, count);
  565. }
  566. #endif
  567. #ifndef insl_p
  568. #define insl_p insl_p
  569. static inline void insl_p(unsigned long addr, void *buffer, unsigned int count)
  570. {
  571. insl(addr, buffer, count);
  572. }
  573. #endif
  574. #ifndef outsb_p
  575. #define outsb_p outsb_p
  576. static inline void outsb_p(unsigned long addr, const void *buffer,
  577. unsigned int count)
  578. {
  579. outsb(addr, buffer, count);
  580. }
  581. #endif
  582. #ifndef outsw_p
  583. #define outsw_p outsw_p
  584. static inline void outsw_p(unsigned long addr, const void *buffer,
  585. unsigned int count)
  586. {
  587. outsw(addr, buffer, count);
  588. }
  589. #endif
  590. #ifndef outsl_p
  591. #define outsl_p outsl_p
  592. static inline void outsl_p(unsigned long addr, const void *buffer,
  593. unsigned int count)
  594. {
  595. outsl(addr, buffer, count);
  596. }
  597. #endif
  598. #ifndef CONFIG_GENERIC_IOMAP
  599. #ifndef ioread8
  600. #define ioread8 ioread8
  601. static inline u8 ioread8(const volatile void __iomem *addr)
  602. {
  603. return readb(addr);
  604. }
  605. #endif
  606. #ifndef ioread16
  607. #define ioread16 ioread16
  608. static inline u16 ioread16(const volatile void __iomem *addr)
  609. {
  610. return readw(addr);
  611. }
  612. #endif
  613. #ifndef ioread32
  614. #define ioread32 ioread32
  615. static inline u32 ioread32(const volatile void __iomem *addr)
  616. {
  617. return readl(addr);
  618. }
  619. #endif
  620. #ifdef CONFIG_64BIT
  621. #ifndef ioread64
  622. #define ioread64 ioread64
  623. static inline u64 ioread64(const volatile void __iomem *addr)
  624. {
  625. return readq(addr);
  626. }
  627. #endif
  628. #endif /* CONFIG_64BIT */
  629. #ifndef iowrite8
  630. #define iowrite8 iowrite8
  631. static inline void iowrite8(u8 value, volatile void __iomem *addr)
  632. {
  633. writeb(value, addr);
  634. }
  635. #endif
  636. #ifndef iowrite16
  637. #define iowrite16 iowrite16
  638. static inline void iowrite16(u16 value, volatile void __iomem *addr)
  639. {
  640. writew(value, addr);
  641. }
  642. #endif
  643. #ifndef iowrite32
  644. #define iowrite32 iowrite32
  645. static inline void iowrite32(u32 value, volatile void __iomem *addr)
  646. {
  647. writel(value, addr);
  648. }
  649. #endif
  650. #ifdef CONFIG_64BIT
  651. #ifndef iowrite64
  652. #define iowrite64 iowrite64
  653. static inline void iowrite64(u64 value, volatile void __iomem *addr)
  654. {
  655. writeq(value, addr);
  656. }
  657. #endif
  658. #endif /* CONFIG_64BIT */
  659. #ifndef ioread16be
  660. #define ioread16be ioread16be
  661. static inline u16 ioread16be(const volatile void __iomem *addr)
  662. {
  663. return swab16(readw(addr));
  664. }
  665. #endif
  666. #ifndef ioread32be
  667. #define ioread32be ioread32be
  668. static inline u32 ioread32be(const volatile void __iomem *addr)
  669. {
  670. return swab32(readl(addr));
  671. }
  672. #endif
  673. #ifdef CONFIG_64BIT
  674. #ifndef ioread64be
  675. #define ioread64be ioread64be
  676. static inline u64 ioread64be(const volatile void __iomem *addr)
  677. {
  678. return swab64(readq(addr));
  679. }
  680. #endif
  681. #endif /* CONFIG_64BIT */
  682. #ifndef iowrite16be
  683. #define iowrite16be iowrite16be
  684. static inline void iowrite16be(u16 value, void volatile __iomem *addr)
  685. {
  686. writew(swab16(value), addr);
  687. }
  688. #endif
  689. #ifndef iowrite32be
  690. #define iowrite32be iowrite32be
  691. static inline void iowrite32be(u32 value, volatile void __iomem *addr)
  692. {
  693. writel(swab32(value), addr);
  694. }
  695. #endif
  696. #ifdef CONFIG_64BIT
  697. #ifndef iowrite64be
  698. #define iowrite64be iowrite64be
  699. static inline void iowrite64be(u64 value, volatile void __iomem *addr)
  700. {
  701. writeq(swab64(value), addr);
  702. }
  703. #endif
  704. #endif /* CONFIG_64BIT */
  705. #ifndef ioread8_rep
  706. #define ioread8_rep ioread8_rep
  707. static inline void ioread8_rep(const volatile void __iomem *addr, void *buffer,
  708. unsigned int count)
  709. {
  710. readsb(addr, buffer, count);
  711. }
  712. #endif
  713. #ifndef ioread16_rep
  714. #define ioread16_rep ioread16_rep
  715. static inline void ioread16_rep(const volatile void __iomem *addr,
  716. void *buffer, unsigned int count)
  717. {
  718. readsw(addr, buffer, count);
  719. }
  720. #endif
  721. #ifndef ioread32_rep
  722. #define ioread32_rep ioread32_rep
  723. static inline void ioread32_rep(const volatile void __iomem *addr,
  724. void *buffer, unsigned int count)
  725. {
  726. readsl(addr, buffer, count);
  727. }
  728. #endif
  729. #ifdef CONFIG_64BIT
  730. #ifndef ioread64_rep
  731. #define ioread64_rep ioread64_rep
  732. static inline void ioread64_rep(const volatile void __iomem *addr,
  733. void *buffer, unsigned int count)
  734. {
  735. readsq(addr, buffer, count);
  736. }
  737. #endif
  738. #endif /* CONFIG_64BIT */
  739. #ifndef iowrite8_rep
  740. #define iowrite8_rep iowrite8_rep
  741. static inline void iowrite8_rep(volatile void __iomem *addr,
  742. const void *buffer,
  743. unsigned int count)
  744. {
  745. writesb(addr, buffer, count);
  746. }
  747. #endif
  748. #ifndef iowrite16_rep
  749. #define iowrite16_rep iowrite16_rep
  750. static inline void iowrite16_rep(volatile void __iomem *addr,
  751. const void *buffer,
  752. unsigned int count)
  753. {
  754. writesw(addr, buffer, count);
  755. }
  756. #endif
  757. #ifndef iowrite32_rep
  758. #define iowrite32_rep iowrite32_rep
  759. static inline void iowrite32_rep(volatile void __iomem *addr,
  760. const void *buffer,
  761. unsigned int count)
  762. {
  763. writesl(addr, buffer, count);
  764. }
  765. #endif
  766. #ifdef CONFIG_64BIT
  767. #ifndef iowrite64_rep
  768. #define iowrite64_rep iowrite64_rep
  769. static inline void iowrite64_rep(volatile void __iomem *addr,
  770. const void *buffer,
  771. unsigned int count)
  772. {
  773. writesq(addr, buffer, count);
  774. }
  775. #endif
  776. #endif /* CONFIG_64BIT */
  777. #endif /* CONFIG_GENERIC_IOMAP */
  778. #ifdef __KERNEL__
  779. #include <linux/vmalloc.h>
  780. #define __io_virt(x) ((void __force *)(x))
  781. #ifndef CONFIG_GENERIC_IOMAP
  782. struct pci_dev;
  783. extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
  784. #ifndef pci_iounmap
  785. #define pci_iounmap pci_iounmap
  786. static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
  787. {
  788. }
  789. #endif
  790. #endif /* CONFIG_GENERIC_IOMAP */
  791. /*
  792. * Change virtual addresses to physical addresses and vv.
  793. * These are pretty trivial
  794. */
  795. #ifndef virt_to_phys
  796. #define virt_to_phys virt_to_phys
  797. static inline unsigned long virt_to_phys(volatile void *address)
  798. {
  799. return __pa((unsigned long)address);
  800. }
  801. #endif
  802. #ifndef phys_to_virt
  803. #define phys_to_virt phys_to_virt
  804. static inline void *phys_to_virt(unsigned long address)
  805. {
  806. return __va(address);
  807. }
  808. #endif
  809. /**
  810. * DOC: ioremap() and ioremap_*() variants
  811. *
  812. * If you have an IOMMU your architecture is expected to have both ioremap()
  813. * and iounmap() implemented otherwise the asm-generic helpers will provide a
  814. * direct mapping.
  815. *
  816. * There are ioremap_*() call variants, if you have no IOMMU we naturally will
  817. * default to direct mapping for all of them, you can override these defaults.
  818. * If you have an IOMMU you are highly encouraged to provide your own
  819. * ioremap variant implementation as there currently is no safe architecture
  820. * agnostic default. To avoid possible improper behaviour default asm-generic
  821. * ioremap_*() variants all return NULL when an IOMMU is available. If you've
  822. * defined your own ioremap_*() variant you must then declare your own
  823. * ioremap_*() variant as defined to itself to avoid the default NULL return.
  824. */
  825. #ifdef CONFIG_MMU
  826. #ifndef ioremap_uc
  827. #define ioremap_uc ioremap_uc
  828. static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size)
  829. {
  830. return NULL;
  831. }
  832. #endif
  833. #else /* !CONFIG_MMU */
  834. /*
  835. * Change "struct page" to physical address.
  836. *
  837. * This implementation is for the no-MMU case only... if you have an MMU
  838. * you'll need to provide your own definitions.
  839. */
  840. #ifndef ioremap
  841. #define ioremap ioremap
  842. static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
  843. {
  844. return (void __iomem *)(unsigned long)offset;
  845. }
  846. #endif
  847. #ifndef __ioremap
  848. #define __ioremap __ioremap
  849. static inline void __iomem *__ioremap(phys_addr_t offset, size_t size,
  850. unsigned long flags)
  851. {
  852. return ioremap(offset, size);
  853. }
  854. #endif
  855. #ifndef iounmap
  856. #define iounmap iounmap
  857. static inline void iounmap(void __iomem *addr)
  858. {
  859. }
  860. #endif
  861. #endif /* CONFIG_MMU */
  862. #ifndef ioremap_nocache
  863. void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
  864. #define ioremap_nocache ioremap_nocache
  865. static inline void __iomem *ioremap_nocache(phys_addr_t offset, size_t size)
  866. {
  867. return ioremap(offset, size);
  868. }
  869. #endif
  870. #ifndef ioremap_uc
  871. #define ioremap_uc ioremap_uc
  872. static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size)
  873. {
  874. return ioremap_nocache(offset, size);
  875. }
  876. #endif
  877. #ifndef ioremap_wc
  878. #define ioremap_wc ioremap_wc
  879. static inline void __iomem *ioremap_wc(phys_addr_t offset, size_t size)
  880. {
  881. return ioremap_nocache(offset, size);
  882. }
  883. #endif
  884. #ifndef ioremap_wt
  885. #define ioremap_wt ioremap_wt
  886. static inline void __iomem *ioremap_wt(phys_addr_t offset, size_t size)
  887. {
  888. return ioremap_nocache(offset, size);
  889. }
  890. #endif
  891. #ifdef CONFIG_HAS_IOPORT_MAP
  892. #ifndef CONFIG_GENERIC_IOMAP
  893. #ifndef ioport_map
  894. #define ioport_map ioport_map
  895. static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
  896. {
  897. port &= IO_SPACE_LIMIT;
  898. return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
  899. }
  900. #endif
  901. #ifndef ioport_unmap
  902. #define ioport_unmap ioport_unmap
  903. static inline void ioport_unmap(void __iomem *p)
  904. {
  905. }
  906. #endif
  907. #else /* CONFIG_GENERIC_IOMAP */
  908. extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
  909. extern void ioport_unmap(void __iomem *p);
  910. #endif /* CONFIG_GENERIC_IOMAP */
  911. #endif /* CONFIG_HAS_IOPORT_MAP */
  912. /*
  913. * Convert a virtual cached pointer to an uncached pointer
  914. */
  915. #ifndef xlate_dev_kmem_ptr
  916. #define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
  917. static inline void *xlate_dev_kmem_ptr(void *addr)
  918. {
  919. return addr;
  920. }
  921. #endif
  922. #ifndef xlate_dev_mem_ptr
  923. #define xlate_dev_mem_ptr xlate_dev_mem_ptr
  924. static inline void *xlate_dev_mem_ptr(phys_addr_t addr)
  925. {
  926. return __va(addr);
  927. }
  928. #endif
  929. #ifndef unxlate_dev_mem_ptr
  930. #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
  931. static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
  932. {
  933. }
  934. #endif
  935. #ifdef CONFIG_VIRT_TO_BUS
  936. #ifndef virt_to_bus
  937. static inline unsigned long virt_to_bus(void *address)
  938. {
  939. return (unsigned long)address;
  940. }
  941. static inline void *bus_to_virt(unsigned long address)
  942. {
  943. return (void *)address;
  944. }
  945. #endif
  946. #endif
  947. #ifndef memset_io
  948. #define memset_io memset_io
  949. /**
  950. * memset_io Set a range of I/O memory to a constant value
  951. * @addr: The beginning of the I/O-memory range to set
  952. * @val: The value to set the memory to
  953. * @count: The number of bytes to set
  954. *
  955. * Set a range of I/O memory to a given value.
  956. */
  957. static inline void memset_io(volatile void __iomem *addr, int value,
  958. size_t size)
  959. {
  960. memset(__io_virt(addr), value, size);
  961. }
  962. #endif
  963. #ifndef memcpy_fromio
  964. #define memcpy_fromio memcpy_fromio
  965. /**
  966. * memcpy_fromio Copy a block of data from I/O memory
  967. * @dst: The (RAM) destination for the copy
  968. * @src: The (I/O memory) source for the data
  969. * @count: The number of bytes to copy
  970. *
  971. * Copy a block of data from I/O memory.
  972. */
  973. static inline void memcpy_fromio(void *buffer,
  974. const volatile void __iomem *addr,
  975. size_t size)
  976. {
  977. memcpy(buffer, __io_virt(addr), size);
  978. }
  979. #endif
  980. #ifndef memcpy_toio
  981. #define memcpy_toio memcpy_toio
  982. /**
  983. * memcpy_toio Copy a block of data into I/O memory
  984. * @dst: The (I/O memory) destination for the copy
  985. * @src: The (RAM) source for the data
  986. * @count: The number of bytes to copy
  987. *
  988. * Copy a block of data to I/O memory.
  989. */
  990. static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
  991. size_t size)
  992. {
  993. memcpy(__io_virt(addr), buffer, size);
  994. }
  995. #endif
  996. #endif /* __KERNEL__ */
  997. #endif /* __ASM_GENERIC_IO_H */