io-mapping.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright © 2008 Keith Packard <keithp@keithp.com>
  3. *
  4. * This file is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef _LINUX_IO_MAPPING_H
  18. #define _LINUX_IO_MAPPING_H
  19. #include <linux/types.h>
  20. #include <asm/io.h>
  21. #include <asm/page.h>
  22. #include <asm/iomap.h>
  23. /*
  24. * The io_mapping mechanism provides an abstraction for mapping
  25. * individual pages from an io device to the CPU in an efficient fashion.
  26. *
  27. * See Documentation/io_mapping.txt
  28. */
  29. /* this struct isn't actually defined anywhere */
  30. struct io_mapping;
  31. #ifdef CONFIG_HAVE_ATOMIC_IOMAP
  32. /*
  33. * For small address space machines, mapping large objects
  34. * into the kernel virtual space isn't practical. Where
  35. * available, use fixmap support to dynamically map pages
  36. * of the object at run time.
  37. */
  38. static inline struct io_mapping *
  39. io_mapping_create_wc(unsigned long base, unsigned long size)
  40. {
  41. return (struct io_mapping *) base;
  42. }
  43. static inline void
  44. io_mapping_free(struct io_mapping *mapping)
  45. {
  46. }
  47. /* Atomic map/unmap */
  48. static inline void *
  49. io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset)
  50. {
  51. offset += (unsigned long) mapping;
  52. return iomap_atomic_prot_pfn(offset >> PAGE_SHIFT, KM_USER0,
  53. __pgprot(__PAGE_KERNEL_WC));
  54. }
  55. static inline void
  56. io_mapping_unmap_atomic(void *vaddr)
  57. {
  58. iounmap_atomic(vaddr, KM_USER0);
  59. }
  60. static inline void *
  61. io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
  62. {
  63. offset += (unsigned long) mapping;
  64. return ioremap_wc(offset, PAGE_SIZE);
  65. }
  66. static inline void
  67. io_mapping_unmap(void *vaddr)
  68. {
  69. iounmap(vaddr);
  70. }
  71. #else
  72. /* Create the io_mapping object*/
  73. static inline struct io_mapping *
  74. io_mapping_create_wc(unsigned long base, unsigned long size)
  75. {
  76. return (struct io_mapping *) ioremap_wc(base, size);
  77. }
  78. static inline void
  79. io_mapping_free(struct io_mapping *mapping)
  80. {
  81. iounmap(mapping);
  82. }
  83. /* Atomic map/unmap */
  84. static inline void *
  85. io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset)
  86. {
  87. return ((char *) mapping) + offset;
  88. }
  89. static inline void
  90. io_mapping_unmap_atomic(void *vaddr)
  91. {
  92. }
  93. /* Non-atomic map/unmap */
  94. static inline void *
  95. io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset)
  96. {
  97. return ((char *) mapping) + offset;
  98. }
  99. static inline void
  100. io_mapping_unmap(void *vaddr)
  101. {
  102. }
  103. #endif /* HAVE_ATOMIC_IOMAP */
  104. #endif /* _LINUX_IO_MAPPING_H */