iommu.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * omap iommu: main structures
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __MACH_IOMMU_H
  13. #define __MACH_IOMMU_H
  14. struct iotlb_entry {
  15. u32 da;
  16. u32 pa;
  17. u32 pgsz, prsvd, valid;
  18. union {
  19. u16 ap;
  20. struct {
  21. u32 endian, elsz, mixed;
  22. };
  23. };
  24. };
  25. struct omap_iommu {
  26. const char *name;
  27. struct module *owner;
  28. struct clk *clk;
  29. void __iomem *regbase;
  30. struct device *dev;
  31. void *isr_priv;
  32. struct iommu_domain *domain;
  33. unsigned int refcount;
  34. spinlock_t iommu_lock; /* global for this whole object */
  35. /*
  36. * We don't change iopgd for a situation like pgd for a task,
  37. * but share it globally for each iommu.
  38. */
  39. u32 *iopgd;
  40. spinlock_t page_table_lock; /* protect iopgd */
  41. int nr_tlb_entries;
  42. struct list_head mmap;
  43. struct mutex mmap_lock; /* protect mmap */
  44. void *ctx; /* iommu context: registres saved area */
  45. u32 da_start;
  46. u32 da_end;
  47. };
  48. struct cr_regs {
  49. union {
  50. struct {
  51. u16 cam_l;
  52. u16 cam_h;
  53. };
  54. u32 cam;
  55. };
  56. union {
  57. struct {
  58. u16 ram_l;
  59. u16 ram_h;
  60. };
  61. u32 ram;
  62. };
  63. };
  64. struct iotlb_lock {
  65. short base;
  66. short vict;
  67. };
  68. /* architecture specific functions */
  69. struct iommu_functions {
  70. unsigned long version;
  71. int (*enable)(struct omap_iommu *obj);
  72. void (*disable)(struct omap_iommu *obj);
  73. void (*set_twl)(struct omap_iommu *obj, bool on);
  74. u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
  75. void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
  76. void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
  77. struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
  78. struct iotlb_entry *e);
  79. int (*cr_valid)(struct cr_regs *cr);
  80. u32 (*cr_to_virt)(struct cr_regs *cr);
  81. void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
  82. ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
  83. char *buf);
  84. u32 (*get_pte_attr)(struct iotlb_entry *e);
  85. void (*save_ctx)(struct omap_iommu *obj);
  86. void (*restore_ctx)(struct omap_iommu *obj);
  87. ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
  88. };
  89. /**
  90. * struct omap_mmu_dev_attr - OMAP mmu device attributes for omap_hwmod
  91. * @da_start: device address where the va space starts.
  92. * @da_end: device address where the va space ends.
  93. * @nr_tlb_entries: number of entries supported by the translation
  94. * look-aside buffer (TLB).
  95. */
  96. struct omap_mmu_dev_attr {
  97. u32 da_start;
  98. u32 da_end;
  99. int nr_tlb_entries;
  100. };
  101. struct iommu_platform_data {
  102. const char *name;
  103. const char *clk_name;
  104. const int nr_tlb_entries;
  105. u32 da_start;
  106. u32 da_end;
  107. };
  108. /**
  109. * struct iommu_arch_data - omap iommu private data
  110. * @name: name of the iommu device
  111. * @iommu_dev: handle of the iommu device
  112. *
  113. * This is an omap iommu private data object, which binds an iommu user
  114. * to its iommu device. This object should be placed at the iommu user's
  115. * dev_archdata so generic IOMMU API can be used without having to
  116. * utilize omap-specific plumbing anymore.
  117. */
  118. struct omap_iommu_arch_data {
  119. const char *name;
  120. struct omap_iommu *iommu_dev;
  121. };
  122. #ifdef CONFIG_IOMMU_API
  123. /**
  124. * dev_to_omap_iommu() - retrieves an omap iommu object from a user device
  125. * @dev: iommu client device
  126. */
  127. static inline struct omap_iommu *dev_to_omap_iommu(struct device *dev)
  128. {
  129. struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
  130. return arch_data->iommu_dev;
  131. }
  132. #endif
  133. /* IOMMU errors */
  134. #define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
  135. #define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
  136. #define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
  137. #define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
  138. #define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
  139. #if defined(CONFIG_ARCH_OMAP1)
  140. #error "iommu for this processor not implemented yet"
  141. #else
  142. #include <plat/iommu2.h>
  143. #endif
  144. /*
  145. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  146. */
  147. #define iopgsz_max(bytes) \
  148. (((bytes) >= SZ_16M) ? SZ_16M : \
  149. ((bytes) >= SZ_1M) ? SZ_1M : \
  150. ((bytes) >= SZ_64K) ? SZ_64K : \
  151. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  152. #define bytes_to_iopgsz(bytes) \
  153. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  154. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  155. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  156. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  157. #define iopgsz_to_bytes(iopgsz) \
  158. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  159. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  160. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  161. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  162. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  163. /*
  164. * global functions
  165. */
  166. extern u32 omap_iommu_arch_version(void);
  167. extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  168. extern int
  169. omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
  170. extern int omap_iommu_set_isr(const char *name,
  171. int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
  172. void *priv),
  173. void *isr_priv);
  174. extern void omap_iommu_save_ctx(struct device *dev);
  175. extern void omap_iommu_restore_ctx(struct device *dev);
  176. extern int omap_install_iommu_arch(const struct iommu_functions *ops);
  177. extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
  178. extern int omap_foreach_iommu_device(void *data,
  179. int (*fn)(struct device *, void *));
  180. extern ssize_t
  181. omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
  182. extern size_t
  183. omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
  184. #endif /* __MACH_IOMMU_H */