iommu.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 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. unsigned int refcount;
  33. struct mutex iommu_lock; /* global for this whole object */
  34. /*
  35. * We don't change iopgd for a situation like pgd for a task,
  36. * but share it globally for each iommu.
  37. */
  38. u32 *iopgd;
  39. spinlock_t page_table_lock; /* protect iopgd */
  40. int nr_tlb_entries;
  41. struct list_head mmap;
  42. struct mutex mmap_lock; /* protect mmap */
  43. int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs, void *priv);
  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 iommu *obj);
  72. void (*disable)(struct iommu *obj);
  73. void (*set_twl)(struct iommu *obj, bool on);
  74. u32 (*fault_isr)(struct iommu *obj, u32 *ra);
  75. void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
  76. void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
  77. struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
  78. int (*cr_valid)(struct cr_regs *cr);
  79. u32 (*cr_to_virt)(struct cr_regs *cr);
  80. void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
  81. ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
  82. u32 (*get_pte_attr)(struct iotlb_entry *e);
  83. void (*save_ctx)(struct iommu *obj);
  84. void (*restore_ctx)(struct iommu *obj);
  85. ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
  86. };
  87. struct iommu_platform_data {
  88. const char *name;
  89. const char *clk_name;
  90. const int nr_tlb_entries;
  91. u32 da_start;
  92. u32 da_end;
  93. };
  94. /* IOMMU errors */
  95. #define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
  96. #define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
  97. #define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
  98. #define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
  99. #define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
  100. #if defined(CONFIG_ARCH_OMAP1)
  101. #error "iommu for this processor not implemented yet"
  102. #else
  103. #include <plat/iommu2.h>
  104. #endif
  105. /*
  106. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  107. */
  108. #define iopgsz_max(bytes) \
  109. (((bytes) >= SZ_16M) ? SZ_16M : \
  110. ((bytes) >= SZ_1M) ? SZ_1M : \
  111. ((bytes) >= SZ_64K) ? SZ_64K : \
  112. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  113. #define bytes_to_iopgsz(bytes) \
  114. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  115. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  116. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  117. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  118. #define iopgsz_to_bytes(iopgsz) \
  119. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  120. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  121. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  122. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  123. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  124. /*
  125. * global functions
  126. */
  127. extern u32 iommu_arch_version(void);
  128. extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  129. extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
  130. extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
  131. extern void iommu_set_twl(struct iommu *obj, bool on);
  132. extern void flush_iotlb_page(struct iommu *obj, u32 da);
  133. extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
  134. extern void flush_iotlb_all(struct iommu *obj);
  135. extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
  136. extern void iopgtable_lookup_entry(struct iommu *obj, u32 da, u32 **ppgd,
  137. u32 **ppte);
  138. extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
  139. extern int iommu_set_da_range(struct iommu *obj, u32 start, u32 end);
  140. extern struct iommu *iommu_get(const char *name);
  141. extern void iommu_put(struct iommu *obj);
  142. extern int iommu_set_isr(const char *name,
  143. int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs,
  144. void *priv),
  145. void *isr_priv);
  146. extern void iommu_save_ctx(struct iommu *obj);
  147. extern void iommu_restore_ctx(struct iommu *obj);
  148. extern int install_iommu_arch(const struct iommu_functions *ops);
  149. extern void uninstall_iommu_arch(const struct iommu_functions *ops);
  150. extern int foreach_iommu_device(void *data,
  151. int (*fn)(struct device *, void *));
  152. extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
  153. extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
  154. #endif /* __MACH_IOMMU_H */