iommu.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. unsigned int refcount;
  32. struct mutex iommu_lock; /* global for this whole object */
  33. /*
  34. * We don't change iopgd for a situation like pgd for a task,
  35. * but share it globally for each iommu.
  36. */
  37. u32 *iopgd;
  38. spinlock_t page_table_lock; /* protect iopgd */
  39. int nr_tlb_entries;
  40. struct list_head mmap;
  41. struct mutex mmap_lock; /* protect mmap */
  42. int (*isr)(struct iommu *obj);
  43. void *ctx; /* iommu context: registres saved area */
  44. u32 da_start;
  45. u32 da_end;
  46. };
  47. struct cr_regs {
  48. union {
  49. struct {
  50. u16 cam_l;
  51. u16 cam_h;
  52. };
  53. u32 cam;
  54. };
  55. union {
  56. struct {
  57. u16 ram_l;
  58. u16 ram_h;
  59. };
  60. u32 ram;
  61. };
  62. };
  63. struct iotlb_lock {
  64. short base;
  65. short vict;
  66. };
  67. /* architecture specific functions */
  68. struct iommu_functions {
  69. unsigned long version;
  70. int (*enable)(struct iommu *obj);
  71. void (*disable)(struct iommu *obj);
  72. void (*set_twl)(struct iommu *obj, bool on);
  73. u32 (*fault_isr)(struct iommu *obj, u32 *ra);
  74. void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
  75. void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
  76. struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
  77. int (*cr_valid)(struct cr_regs *cr);
  78. u32 (*cr_to_virt)(struct cr_regs *cr);
  79. void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
  80. ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
  81. u32 (*get_pte_attr)(struct iotlb_entry *e);
  82. void (*save_ctx)(struct iommu *obj);
  83. void (*restore_ctx)(struct iommu *obj);
  84. ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
  85. };
  86. struct iommu_platform_data {
  87. const char *name;
  88. const char *clk_name;
  89. const int nr_tlb_entries;
  90. u32 da_start;
  91. u32 da_end;
  92. };
  93. #if defined(CONFIG_ARCH_OMAP1)
  94. #error "iommu for this processor not implemented yet"
  95. #else
  96. #include <plat/iommu2.h>
  97. #endif
  98. /*
  99. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  100. */
  101. #define iopgsz_max(bytes) \
  102. (((bytes) >= SZ_16M) ? SZ_16M : \
  103. ((bytes) >= SZ_1M) ? SZ_1M : \
  104. ((bytes) >= SZ_64K) ? SZ_64K : \
  105. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  106. #define bytes_to_iopgsz(bytes) \
  107. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  108. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  109. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  110. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  111. #define iopgsz_to_bytes(iopgsz) \
  112. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  113. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  114. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  115. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  116. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  117. /*
  118. * global functions
  119. */
  120. extern u32 iommu_arch_version(void);
  121. extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  122. extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
  123. extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
  124. extern void iommu_set_twl(struct iommu *obj, bool on);
  125. extern void flush_iotlb_page(struct iommu *obj, u32 da);
  126. extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
  127. extern void flush_iotlb_all(struct iommu *obj);
  128. extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
  129. extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
  130. extern int iommu_set_da_range(struct iommu *obj, u32 start, u32 end);
  131. extern struct iommu *iommu_get(const char *name);
  132. extern void iommu_put(struct iommu *obj);
  133. extern void iommu_save_ctx(struct iommu *obj);
  134. extern void iommu_restore_ctx(struct iommu *obj);
  135. extern int install_iommu_arch(const struct iommu_functions *ops);
  136. extern void uninstall_iommu_arch(const struct iommu_functions *ops);
  137. extern int foreach_iommu_device(void *data,
  138. int (*fn)(struct device *, void *));
  139. extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
  140. extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
  141. #endif /* __MACH_IOMMU_H */