iommu.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. struct iommu_platform_data {
  90. const char *name;
  91. const char *clk_name;
  92. const int nr_tlb_entries;
  93. u32 da_start;
  94. u32 da_end;
  95. };
  96. /**
  97. * struct iommu_arch_data - omap iommu private data
  98. * @name: name of the iommu device
  99. * @iommu_dev: handle of the iommu device
  100. *
  101. * This is an omap iommu private data object, which binds an iommu user
  102. * to its iommu device. This object should be placed at the iommu user's
  103. * dev_archdata so generic IOMMU API can be used without having to
  104. * utilize omap-specific plumbing anymore.
  105. */
  106. struct omap_iommu_arch_data {
  107. const char *name;
  108. struct omap_iommu *iommu_dev;
  109. };
  110. /**
  111. * dev_to_omap_iommu() - retrieves an omap iommu object from a user device
  112. * @dev: iommu client device
  113. */
  114. static inline struct omap_iommu *dev_to_omap_iommu(struct device *dev)
  115. {
  116. struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
  117. return arch_data->iommu_dev;
  118. }
  119. /* IOMMU errors */
  120. #define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
  121. #define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
  122. #define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
  123. #define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
  124. #define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
  125. #if defined(CONFIG_ARCH_OMAP1)
  126. #error "iommu for this processor not implemented yet"
  127. #else
  128. #include <plat/iommu2.h>
  129. #endif
  130. /*
  131. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  132. */
  133. #define iopgsz_max(bytes) \
  134. (((bytes) >= SZ_16M) ? SZ_16M : \
  135. ((bytes) >= SZ_1M) ? SZ_1M : \
  136. ((bytes) >= SZ_64K) ? SZ_64K : \
  137. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  138. #define bytes_to_iopgsz(bytes) \
  139. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  140. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  141. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  142. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  143. #define iopgsz_to_bytes(iopgsz) \
  144. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  145. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  146. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  147. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  148. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  149. /*
  150. * global functions
  151. */
  152. extern u32 omap_iommu_arch_version(void);
  153. extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  154. extern int
  155. omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
  156. extern int omap_iommu_set_isr(const char *name,
  157. int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
  158. void *priv),
  159. void *isr_priv);
  160. extern void omap_iommu_save_ctx(struct device *dev);
  161. extern void omap_iommu_restore_ctx(struct device *dev);
  162. extern int omap_install_iommu_arch(const struct iommu_functions *ops);
  163. extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
  164. extern int omap_foreach_iommu_device(void *data,
  165. int (*fn)(struct device *, void *));
  166. extern ssize_t
  167. omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
  168. extern size_t
  169. omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
  170. #endif /* __MACH_IOMMU_H */