omap-iommu.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #if defined(CONFIG_ARCH_OMAP1)
  13. #error "iommu for this processor not implemented yet"
  14. #endif
  15. struct iotlb_entry {
  16. u32 da;
  17. u32 pa;
  18. u32 pgsz, prsvd, valid;
  19. union {
  20. u16 ap;
  21. struct {
  22. u32 endian, elsz, mixed;
  23. };
  24. };
  25. };
  26. struct omap_iommu {
  27. const char *name;
  28. struct module *owner;
  29. struct clk *clk;
  30. void __iomem *regbase;
  31. struct device *dev;
  32. void *isr_priv;
  33. struct iommu_domain *domain;
  34. unsigned int refcount;
  35. spinlock_t iommu_lock; /* global for this whole object */
  36. /*
  37. * We don't change iopgd for a situation like pgd for a task,
  38. * but share it globally for each iommu.
  39. */
  40. u32 *iopgd;
  41. spinlock_t page_table_lock; /* protect iopgd */
  42. int nr_tlb_entries;
  43. struct list_head mmap;
  44. struct mutex mmap_lock; /* protect mmap */
  45. void *ctx; /* iommu context: registres saved area */
  46. u32 da_start;
  47. u32 da_end;
  48. };
  49. struct cr_regs {
  50. union {
  51. struct {
  52. u16 cam_l;
  53. u16 cam_h;
  54. };
  55. u32 cam;
  56. };
  57. union {
  58. struct {
  59. u16 ram_l;
  60. u16 ram_h;
  61. };
  62. u32 ram;
  63. };
  64. };
  65. /* architecture specific functions */
  66. struct iommu_functions {
  67. unsigned long version;
  68. int (*enable)(struct omap_iommu *obj);
  69. void (*disable)(struct omap_iommu *obj);
  70. void (*set_twl)(struct omap_iommu *obj, bool on);
  71. u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
  72. void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
  73. void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
  74. struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
  75. struct iotlb_entry *e);
  76. int (*cr_valid)(struct cr_regs *cr);
  77. u32 (*cr_to_virt)(struct cr_regs *cr);
  78. void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
  79. ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
  80. char *buf);
  81. u32 (*get_pte_attr)(struct iotlb_entry *e);
  82. void (*save_ctx)(struct omap_iommu *obj);
  83. void (*restore_ctx)(struct omap_iommu *obj);
  84. ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
  85. };
  86. #ifdef CONFIG_IOMMU_API
  87. /**
  88. * dev_to_omap_iommu() - retrieves an omap iommu object from a user device
  89. * @dev: iommu client device
  90. */
  91. static inline struct omap_iommu *dev_to_omap_iommu(struct device *dev)
  92. {
  93. struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
  94. return arch_data->iommu_dev;
  95. }
  96. #endif
  97. /*
  98. * MMU Register offsets
  99. */
  100. #define MMU_REVISION 0x00
  101. #define MMU_SYSCONFIG 0x10
  102. #define MMU_SYSSTATUS 0x14
  103. #define MMU_IRQSTATUS 0x18
  104. #define MMU_IRQENABLE 0x1c
  105. #define MMU_WALKING_ST 0x40
  106. #define MMU_CNTL 0x44
  107. #define MMU_FAULT_AD 0x48
  108. #define MMU_TTB 0x4c
  109. #define MMU_LOCK 0x50
  110. #define MMU_LD_TLB 0x54
  111. #define MMU_CAM 0x58
  112. #define MMU_RAM 0x5c
  113. #define MMU_GFLUSH 0x60
  114. #define MMU_FLUSH_ENTRY 0x64
  115. #define MMU_READ_CAM 0x68
  116. #define MMU_READ_RAM 0x6c
  117. #define MMU_EMU_FAULT_AD 0x70
  118. #define MMU_REG_SIZE 256
  119. /*
  120. * MMU Register bit definitions
  121. */
  122. #define MMU_CAM_VATAG_SHIFT 12
  123. #define MMU_CAM_VATAG_MASK \
  124. ((~0UL >> MMU_CAM_VATAG_SHIFT) << MMU_CAM_VATAG_SHIFT)
  125. #define MMU_CAM_P (1 << 3)
  126. #define MMU_CAM_V (1 << 2)
  127. #define MMU_CAM_PGSZ_MASK 3
  128. #define MMU_CAM_PGSZ_1M (0 << 0)
  129. #define MMU_CAM_PGSZ_64K (1 << 0)
  130. #define MMU_CAM_PGSZ_4K (2 << 0)
  131. #define MMU_CAM_PGSZ_16M (3 << 0)
  132. #define MMU_RAM_PADDR_SHIFT 12
  133. #define MMU_RAM_PADDR_MASK \
  134. ((~0UL >> MMU_RAM_PADDR_SHIFT) << MMU_RAM_PADDR_SHIFT)
  135. #define MMU_RAM_ENDIAN_MASK (1 << MMU_RAM_ENDIAN_SHIFT)
  136. #define MMU_RAM_ENDIAN_BIG (1 << MMU_RAM_ENDIAN_SHIFT)
  137. #define MMU_RAM_ELSZ_MASK (3 << MMU_RAM_ELSZ_SHIFT)
  138. #define MMU_RAM_ELSZ_8 (0 << MMU_RAM_ELSZ_SHIFT)
  139. #define MMU_RAM_ELSZ_16 (1 << MMU_RAM_ELSZ_SHIFT)
  140. #define MMU_RAM_ELSZ_32 (2 << MMU_RAM_ELSZ_SHIFT)
  141. #define MMU_RAM_ELSZ_NONE (3 << MMU_RAM_ELSZ_SHIFT)
  142. #define MMU_RAM_MIXED_SHIFT 6
  143. #define MMU_RAM_MIXED_MASK (1 << MMU_RAM_MIXED_SHIFT)
  144. #define MMU_RAM_MIXED MMU_RAM_MIXED_MASK
  145. /*
  146. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  147. */
  148. #define iopgsz_max(bytes) \
  149. (((bytes) >= SZ_16M) ? SZ_16M : \
  150. ((bytes) >= SZ_1M) ? SZ_1M : \
  151. ((bytes) >= SZ_64K) ? SZ_64K : \
  152. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  153. #define bytes_to_iopgsz(bytes) \
  154. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  155. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  156. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  157. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  158. #define iopgsz_to_bytes(iopgsz) \
  159. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  160. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  161. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  162. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  163. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  164. /*
  165. * global functions
  166. */
  167. extern u32 omap_iommu_arch_version(void);
  168. extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  169. extern int
  170. omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
  171. extern void omap_iommu_save_ctx(struct device *dev);
  172. extern void omap_iommu_restore_ctx(struct device *dev);
  173. extern int omap_foreach_iommu_device(void *data,
  174. int (*fn)(struct device *, void *));
  175. extern int omap_install_iommu_arch(const struct iommu_functions *ops);
  176. extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
  177. extern ssize_t
  178. omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
  179. extern size_t
  180. omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
  181. /*
  182. * register accessors
  183. */
  184. static inline u32 iommu_read_reg(struct omap_iommu *obj, size_t offs)
  185. {
  186. return __raw_readl(obj->regbase + offs);
  187. }
  188. static inline void iommu_write_reg(struct omap_iommu *obj, u32 val, size_t offs)
  189. {
  190. __raw_writel(val, obj->regbase + offs);
  191. }