iommu.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /* IOMMU errors */
  97. #define OMAP_IOMMU_ERR_TLB_MISS (1 << 0)
  98. #define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1)
  99. #define OMAP_IOMMU_ERR_EMU_MISS (1 << 2)
  100. #define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3)
  101. #define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4)
  102. #if defined(CONFIG_ARCH_OMAP1)
  103. #error "iommu for this processor not implemented yet"
  104. #else
  105. #include <plat/iommu2.h>
  106. #endif
  107. /*
  108. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  109. */
  110. #define iopgsz_max(bytes) \
  111. (((bytes) >= SZ_16M) ? SZ_16M : \
  112. ((bytes) >= SZ_1M) ? SZ_1M : \
  113. ((bytes) >= SZ_64K) ? SZ_64K : \
  114. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  115. #define bytes_to_iopgsz(bytes) \
  116. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  117. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  118. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  119. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  120. #define iopgsz_to_bytes(iopgsz) \
  121. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  122. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  123. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  124. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  125. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  126. /*
  127. * global functions
  128. */
  129. extern u32 omap_iommu_arch_version(void);
  130. extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  131. extern int
  132. omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
  133. extern int omap_iommu_set_isr(const char *name,
  134. int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
  135. void *priv),
  136. void *isr_priv);
  137. extern void omap_iommu_save_ctx(struct omap_iommu *obj);
  138. extern void omap_iommu_restore_ctx(struct omap_iommu *obj);
  139. extern int omap_install_iommu_arch(const struct iommu_functions *ops);
  140. extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
  141. extern int omap_foreach_iommu_device(void *data,
  142. int (*fn)(struct device *, void *));
  143. extern ssize_t
  144. omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
  145. extern size_t
  146. omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
  147. struct device *omap_find_iommu_device(const char *name);
  148. #endif /* __MACH_IOMMU_H */