iommu.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. };
  45. struct cr_regs {
  46. union {
  47. struct {
  48. u16 cam_l;
  49. u16 cam_h;
  50. };
  51. u32 cam;
  52. };
  53. union {
  54. struct {
  55. u16 ram_l;
  56. u16 ram_h;
  57. };
  58. u32 ram;
  59. };
  60. };
  61. struct iotlb_lock {
  62. short base;
  63. short vict;
  64. };
  65. /* architecture specific functions */
  66. struct iommu_functions {
  67. unsigned long version;
  68. int (*enable)(struct iommu *obj);
  69. void (*disable)(struct iommu *obj);
  70. u32 (*fault_isr)(struct iommu *obj, u32 *ra);
  71. void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
  72. void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
  73. struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
  74. int (*cr_valid)(struct cr_regs *cr);
  75. u32 (*cr_to_virt)(struct cr_regs *cr);
  76. void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
  77. ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
  78. u32 (*get_pte_attr)(struct iotlb_entry *e);
  79. void (*save_ctx)(struct iommu *obj);
  80. void (*restore_ctx)(struct iommu *obj);
  81. ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
  82. };
  83. struct iommu_platform_data {
  84. const char *name;
  85. const char *clk_name;
  86. const int nr_tlb_entries;
  87. };
  88. #if defined(CONFIG_ARCH_OMAP1)
  89. #error "iommu for this processor not implemented yet"
  90. #else
  91. #include <mach/iommu2.h>
  92. #endif
  93. /*
  94. * utilities for super page(16MB, 1MB, 64KB and 4KB)
  95. */
  96. #define iopgsz_max(bytes) \
  97. (((bytes) >= SZ_16M) ? SZ_16M : \
  98. ((bytes) >= SZ_1M) ? SZ_1M : \
  99. ((bytes) >= SZ_64K) ? SZ_64K : \
  100. ((bytes) >= SZ_4K) ? SZ_4K : 0)
  101. #define bytes_to_iopgsz(bytes) \
  102. (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \
  103. ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \
  104. ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \
  105. ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1)
  106. #define iopgsz_to_bytes(iopgsz) \
  107. (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \
  108. ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \
  109. ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \
  110. ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0)
  111. #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0)
  112. /*
  113. * global functions
  114. */
  115. extern u32 iommu_arch_version(void);
  116. extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
  117. extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
  118. extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
  119. extern void flush_iotlb_page(struct iommu *obj, u32 da);
  120. extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
  121. extern void flush_iotlb_all(struct iommu *obj);
  122. extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
  123. extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
  124. extern struct iommu *iommu_get(const char *name);
  125. extern void iommu_put(struct iommu *obj);
  126. extern void iommu_save_ctx(struct iommu *obj);
  127. extern void iommu_restore_ctx(struct iommu *obj);
  128. extern int install_iommu_arch(const struct iommu_functions *ops);
  129. extern void uninstall_iommu_arch(const struct iommu_functions *ops);
  130. extern int foreach_iommu_device(void *data,
  131. int (*fn)(struct device *, void *));
  132. extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
  133. extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
  134. #endif /* __MACH_IOMMU_H */